prepare() public method

public prepare ( )
 public function prepare()
 {
     parent::prepare();
     $generate_whole_db = false;
     $templatePath = $this->templatePath;
     if (($pos = strrpos($this->tableName, '.')) !== false) {
         $schema = substr($this->tableName, 0, $pos);
         $tableName = substr($this->tableName, $pos + 1);
     } else {
         $schema = '';
         $tableName = $this->tableName;
     }
     if ($tableName[strlen($tableName) - 1] === '*') {
         $generate_whole_db = true;
         $this->tables = Yii::app()->{$this->connectionId}->schema->getTables($schema);
         if ($this->tablePrefix != '') {
             foreach ($this->tables as $i => $table) {
                 if (strpos($table->name, $this->tablePrefix) !== 0) {
                     unset($this->tables[$i]);
                 }
             }
         }
     } else {
         $this->tables = array($this->getTableSchema($this->tableName));
     }
     $this->relations = $this->generateRelations();
     foreach ($this->tables as $table) {
         $tableName = $this->removePrefix($table->name);
         $className = $this->generateClassName($table->name);
         $params = array('tableName' => $schema === '' ? $tableName : $schema . '.' . $tableName, 'modelClass' => $className, 'columns' => $table->columns, 'labels' => $this->generateLabels($table), 'rules' => $this->generateRules($table), 'relations' => isset($this->relations[$className]) ? $this->relations[$className] : array());
         if ($this->template != 'singlefile') {
             $this->files[] = new CCodeFile(Yii::getPathOfAlias($this->modelPath) . '/' . 'Base' . $className . '.php', $this->render($templatePath . '/basemodel.php', $params));
         }
     }
 }
Ejemplo n.º 2
0
 public function prepare()
 {
     parent::prepare();
     // Make sure that the CAdvancedArBehavior is in the application components
     // Folder. if it is not, copy it over there
     $path = Yii::getPathOfAlias('application.components');
     if ($path === false) {
         mkdir($path);
     }
     if (!is_dir($path)) {
         die("Fatal Error: Your application components/ is not an directory!");
     }
     $names = scandir($path);
     if (!in_array('CAdvancedArBehavior.php', $names)) {
         $gtcpath = Yii::getPathOfAlias('ext.gtc.vendors');
         if (!copy($gtcpath . '/CAdvancedArBehavior.php', $path . '/CAdvancedArBehavior.php')) {
             die('CAdvancedArBehavior.php could not be copied over to your components directory');
         }
     }
 }
Ejemplo n.º 3
0
 public function prepare()
 {
     parent::prepare();
     $templatePath = $this->templatePath;
     if (($pos = strrpos($this->tableName, '.')) !== false) {
         $schema = substr($this->tableName, 0, $pos);
         $tableName = substr($this->tableName, $pos + 1);
     } else {
         $schema = '';
         $tableName = $this->tableName;
     }
     if ($tableName[strlen($tableName) - 1] === '*') {
         $this->tables = Yii::app()->db->schema->getTables($schema);
         if ($this->tablePrefix != '') {
             foreach ($this->tables as $i => $table) {
                 if (strpos($table->name, $this->tablePrefix) !== 0) {
                     unset($this->tables[$i]);
                 }
             }
         }
     } else {
         $this->tables = array($this->getTableSchema($this->tableName));
     }
     $this->relations = $this->generateRelations();
     $this->files = array();
     $this->files = array();
     foreach ($this->tables as $table) {
         foreach ($table->columns as $key => $column) {
             if (in_array($column->dbType, array('timestamp'))) {
                 unset($table->columns[$key]);
             }
         }
         $tableName = $this->removePrefix($table->name);
         $className = $this->generateClassName($table->name);
         $this->baseModelPath = $this->modelPath . '._base';
         $this->baseModelClass = 'Base' . $className;
         $params = array('tableName' => $schema === '' ? $tableName : $schema . '.' . $tableName, 'modelClass' => $className, 'columns' => $table->columns, 'labels' => $this->generateLabels($table), 'rules' => $this->generateRules($table), 'relations' => isset($this->relations[$className]) ? $this->relations[$className] : array());
         $this->files[] = new CCodeFile(Yii::getPathOfAlias($this->modelPath . '.' . $className) . '.php', $this->render($templatePath . DIRECTORY_SEPARATOR . 'model.php', $params));
         $this->files[] = new CCodeFile(Yii::getPathOfAlias($this->baseModelPath . '.' . $this->baseModelClass) . '.php', $this->render($templatePath . DIRECTORY_SEPARATOR . '_base' . DIRECTORY_SEPARATOR . 'basemodel.php', $params));
     }
 }
Ejemplo n.º 4
0
 public function prepare()
 {
     parent::prepare();
     $generate_whole_db = false;
     $templatePath = $this->templatePath;
     if (($pos = strrpos($this->tableName, '.')) !== false) {
         $schema = substr($this->tableName, 0, $pos);
         $tableName = substr($this->tableName, $pos + 1);
     } else {
         $schema = '';
         $tableName = $this->tableName;
     }
     if ($tableName[strlen($tableName) - 1] === '*') {
         $generate_whole_db = true;
         $this->tables = Yii::app()->db->schema->getTables($schema);
         if ($this->tablePrefix != '') {
             foreach ($this->tables as $i => $table) {
                 if (strpos($table->name, $this->tablePrefix) !== 0) {
                     unset($this->tables[$i]);
                 }
             }
         }
     } else {
         $this->tables = array($this->getTableSchema($this->tableName));
     }
     $this->relations = $this->generateRelations();
     foreach ($this->tables as $table) {
         $tableName = $this->removePrefix($table->name);
         $className = $this->generateClassName($table->name);
         if (!$this->identificationColumn) {
             $this->identificationColumn = $this->guessIdentificationColumn($table->columns);
         }
         if (!$generate_whole_db && !array_key_exists($this->identificationColumn, $table->columns)) {
             $this->addError('identificationColumn', 'The specified column can not be found in the models attributes. <br /> Please specify a valid attribute. If unsure, leave the field empty.');
         }
         $params = array('tableName' => $schema === '' ? $tableName : $schema . '.' . $tableName, 'modelClass' => $className, 'columns' => $table->columns, 'labels' => $this->generateLabels($table), 'rules' => $this->generateRules($table), 'relations' => isset($this->relations[$className]) ? $this->relations[$className] : array());
         if ($this->template != 'singlefile') {
             $this->files[] = new CCodeFile(Yii::getPathOfAlias($this->modelPath) . '/' . 'Base' . $className . '.php', $this->render($templatePath . '/basemodel.php', $params));
         }
     }
 }