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