Exemplo n.º 1
0
 static function getInstance()
 {
     if (!isset($instance)) {
         self::$instance = new CreateTemplate();
     }
     return self::$instance;
 }
Exemplo n.º 2
0
 /**
  * @access public
  */
 public function connect()
 {
     if ($this->debugmode) {
         echo "<br> Entity::connect for {$this->name} instance";
     }
     if (Settings::getModMode()) {
         $tableExists = $this->database->existsTable($this->name);
         $tableSchemaIsUpdated = true;
         if ($tableExists) {
             foreach ($this->fields as $k => $v) {
                 if (!$this->database->existsField($this->name, $v->name)) {
                     $tableSchemaIsUpdated = false;
                 }
             }
             $existingFields = $this->database->getTableFields($this->name);
             if (is_array($existingFields)) {
                 foreach ($existingFields as $k => $v) {
                     if (!$this->existsField($k)) {
                         $tableSchemaIsUpdated = false;
                     }
                 }
             }
         }
         if (!$tableExists || !$tableSchemaIsUpdated) {
             $query = "";
             if (!$tableSchemaIsUpdated) {
                 $query .= "DROP TABLE {$this->name}; ";
                 $oid = mysql_query($query);
             }
             $query = "CREATE TABLE {$this->name} (";
             /**
              *
              * L'insostenibile leggerezza dell'essere oggetto!
              */
             foreach ($this->fields as $k => $v) {
                 $query .= $v->connect($this->entityName);
             }
             if ($this->noKey) {
                 $query .= ")";
             } else {
                 $query .= ", primary key({$this->fields[0]->name}))";
             }
             $oid = mysql_query($query);
             if (!$oid) {
                 echo Message::getInstance()->getMessage(MSG_ERROR_DATABASE_QUERY) . " {$this->name} at line ", __LINE__;
                 echo "<hr>", $query;
                 exit;
             } else {
                 $this->database->updateTables();
             }
         }
     }
     if (!isset($this->presentation)) {
         $this->setPresentation("%{$this->fields[0]->name}");
     }
     /**
      * CREAZIONE DEL TEMPLATE
      * viene eseguita sia se la tabella � esistente sia se non presente nel DB
      * il controllo sulla creazione dei file � compito del metodo
      */
     CreateTemplate::createTemplateMultiple($this);
     CreateTemplate::createTemplateSingle($this);
     CreateTemplate::createTemplateReport($this);
     CreateTemplate::createTemplateSearch($this);
     /**
      * CREAZIONE DEL TEMPLATE
      * viene eseguita sia se la tabella � esistente sia se non presente nel DB
      * il controllo sulla creazione dei file � compito del metodo
      */
     $GLOBALS[] = $this;
     $this->register();
 }