Ubiquity  2.0.0
php rapid development framework
DatabaseTrait.php
Go to the documentation of this file.
1 <?php
3 
4 use Ajax\JsUtils;
15 
21  abstract public function _getAdminData();
22  abstract public function _getAdminViewer();
23  abstract public function _getAdminFiles();
24  abstract public function loadView($viewName, $pData=NULL, $asString=false);
25  abstract protected function showSimpleMessage($content,$type,$icon="info",$timeout=NULL,$staticName=null);
26 
27  protected function getModels(){
28  $config=Startup::getConfig();
29  $models=CacheManager::getModels($config,true);
30  $result=[];
31  foreach ($models as $model){
32  $table=OrmUtils::getTableName($model);
33  $simpleM=ClassUtils::getClassSimpleName($model);
34  if($simpleM!==$table)
35  $result[$table]=$simpleM."[".$table."]";
36  else
37  $result[$table]=$simpleM;
38  }
39  return $result;
40  }
41 
42  public function createSQLScript(){
43  if(URequest::isPost()){
44  $db=$_POST["dbName"];
45  if(DAO::isConnected()){
46  $actualDb=DAO::$db->getDbName();
47  }
48  $generator=new DatabaseReversor(new DbGenerator());
49  $generator->createDatabase($db);
50  $frm=$this->jquery->semantic()->htmlForm("form-sql");
51  $text=$frm->addElement("sql", $generator->__toString(),"SQL script","div","ui segment editor");
52  $text->getField()->setProperty("style", "background-color: #002B36;");
53  $bts=$this->jquery->semantic()->htmlButtonGroups("buttons");
54  $bts->addElement("Generate database")->addClass("green");
55  if(isset($actualDb) && $actualDb!==$db){
56  $btExport=$bts->addElement("Export datas script : ".$actualDb." => ".$db);
57  $btExport->addIcon("exchange");
58  $btExport->postOnClick($this->_getAdminFiles()->getAdminBaseRoute()."/exportDatasScript","{}","#div-datas");
59  }
60  $frm->addDivider();
61  $this->jquery->exec("setAceEditor('sql');",true);
62  $this->jquery->compile($this->view);
63  $this->loadView($this->_getAdminFiles()->getViewDatabaseCreate());
64  }
65  }
66 
67  public function exportDatasScript(){
68  $dbExport=new DbExport();
69  $frm=$this->jquery->semantic()->htmlForm("form-sql-datas");
70  $text=$frm->addElement("datas-sql", $dbExport->exports(),"Datas export script","div","ui segment editor");
71  $text->getField()->setProperty("style", "background-color: #002B36;");
72  $this->jquery->exec("setAceEditor('datas-sql');",true);
73  $this->jquery->compile($this->view);
74  $this->loadView($this->_getAdminFiles()->getViewDatasExport());
75  }
76 }
static isPost()
Returns true if the request is sent by the POST method.
Definition: URequest.php:91
loadView($viewName, $pData=NULL, $asString=false)
static getModels(&$config, $silent=false)
static $db
Definition: DAO.php:22
static isConnected()
Returns true if the connection to the database is estabished.
Definition: DAO.php:390
static getTableName($class)
Definition: OrmUtils.php:61
showSimpleMessage($content, $type, $icon="info", $timeout=NULL, $staticName=null)
static getClassSimpleName($classnameWithNamespace)
Definition: ClassUtils.php:129