Exemple #1
0
 /**
  * 
  * @param type $bundlename
  * @param type $tables
  * @param type $update
  */
 public function __construct($bundlename, $tables = array(), $update = 0)
 {
     $dir = $bundlename . "Bundle";
     $this->name = $bundlename;
     $this->namespace = "CMS\\" . $dir;
     $dir = $_SERVER["DOCUMENT_ROOT"] . "\\" . $dir;
     if (!file_exists($dir)) {
         mkdir($dir, 0755);
         foreach ($tables as $nome => $campi) {
             if (is_array($campi) && !Tab::exists($nome)) {
                 $result = Tab::create($nome, $campi);
             } else {
                 $result = true;
             }
             if ($result) {
                 $this->createController($nome);
                 $this->createEntity($nome);
             }
         }
     } else {
         if ($update == 1) {
             foreach ($tables as $name) {
                 $keys = Config::getDB()->getAllKeys($name);
                 $creator = new EntityCreator($name, $keys, "", $this->name);
                 $creator->updateFromDatabase();
                 if (!file_exists($_SERVER["DOCUMENT_ROOT"] . "\\" . $this->name . "Bundle" . "\\Controller\\" . $name . "Controller")) {
                     $this->createController($name);
                 }
             }
         }
         if ($update == 2) {
             foreach ($tables as $name) {
                 $keys = Config::getDB()->getAllKeys($name);
                 $creator = new EntityCreator($name, $keys, "", $this->name);
                 $creator->updateToDatabase();
             }
         }
     }
 }
Exemple #2
0
 /**
  * Finds records by attributes
  * @param type $where
  */
 public function findBy($where, $cacheable = true, $fields = "*", $limit_from = "", $limit_to = "")
 {
     $find = $this->isInController($where);
     if ($find !== false) {
         return $this->rows[$find];
     }
     $this->wheredone[] = $where;
     if ($where == "*") {
         $where = "";
     }
     $associative = parent::findBy($where, $cacheable, $fields, $limit_from, $limit_to);
     //print_r($associative);
     $new_arr = $associative;
     /*foreach($associative as $key => $val){
           $nome_id = ucwords($val->getKeyName());
           $nome_metodo="get".str_replace(" ","",ucwords(str_replace("_"," ",$nome_id)));
           $new_arr[$val->$nome_metodo()] = $val;
       }*/
     $this->rows[] = $new_arr;
     return $new_arr;
     //print_r($this->rows);
 }
Exemple #3
0
 /**
  * [checkCampiTable description]
  * @return [type] [description]
  */
 public function checkCampiTable()
 {
     if (!$this->table) {
         return false;
     }
     $ct = new Table($this->table, true, false);
     if ($this->where) {
         $where = $this->where;
     } elseif ($this->where_object) {
         $where = $this->object_to_array(json_decode($this->where_object));
     }
     $find = $ct->findBy($where, false, "*");
     return $find;
 }
Exemple #4
0
 /**
  * 
  */
 private function getDbContents()
 {
     if (Table::exists($this->name)) {
         $names = Config::getDB()->GetColumnNames($this->name);
         foreach ($names as $chiave => $nome) {
             $valori_var = $this->getDbVarInfoByDB($nome);
             $field_tmp = new Field($valori_var["type"]);
             $field_tmp->setNullable($valori_var["nullable"]);
             $field_tmp->setDefault($valori_var["default"]);
             $field_tmp->setName($nome);
             if ($valori_var["key"]) {
                 $field_tmp->setKey($valori_var["key"]);
             }
             $field_tmp->setExtra($valori_var["extra"]);
             $this->fieldsindb[$nome] = $field_tmp;
         }
     }
 }
Exemple #5
0
 /**
  * Creates a bundle
  */
 public static function createBundle($bundlename = "Data", $tables = array())
 {
     $dirname = $_SERVER["DOCUMENT_ROOT"] . "\\" . $bundlename . "Bundle";
     if (!file_exists($dirname)) {
         mkdir($dirname, 0755);
     }
     if (count($tables) > 0) {
         foreach ($tables as $key => $val) {
             if (\CMS\DbWorkers\Table::exists($val)) {
                 \CMS\Conf\Config::createBundle($bundlename, $tables);
             }
         }
     }
 }