/** * Creating an interface. */ public function actionTable() { if(!$this->module->authMode || $this->module->openMode || (Yii::app()->user->isGuest || !in_array(Yii::app()->user->level, array('root')))) throw new CHttpException(403, Yii::t('AutoAdmin.access', 'You do not have permissions to access')); $generator = new AAGenerator($this->module->dbSchema); $table = Yii::app()->request->getParam('table'); if(!$table) throw new CHttpException(400, Yii::t('AutoAdmin.generator', 'Table has not been selected')); elseif(strpos($table, '.')!==false || !in_array($table, $generator->getTableNames())) //don't allow to add schemas ans DB names in table names throw new CHttpException(400, Yii::t('AutoAdmin.generator', 'Incorrect table "{table}"', array('{table}'=>$table))); $this->pageTitle = Yii::t('AutoAdmin.generator', 'Creation interface for the table "{table}"', array('{table}'=>$table)); $this->breadcrumbs[Yii::t('AutoAdmin.generator', 'SQL table selection')] = $this->createUrl('aagenerator/index'); $this->breadcrumbs[] = $this->pageTitle; $this->render($this->module->viewsPath.'generatorTableForm', array( 'tableName'=>$table, 'construction'=>$generator->generate($table), )); }
/** * Generates default (befor user's editing) columns settings */ public function loadDefaultColumns() { $this->fieldsConf = array(); $fieldRowI = 0; foreach($this->_table->columns as $columnName=>$column) { if($column->isPrimaryKey) continue; $fieldRowI++; $field = array($columnName, 'string', ucfirst(str_replace('_', ' ', $columnName)), array()); //default type is string $ftype =& $field[1]; $foptions =& $field[3]; if($column->allowNull) $foptions[] = 'null'; if($fieldRowI <= 4) //in the List mode show the first 4 columns $foptions[] = 'show'; if(!is_null($column->defaultValue)) $foptions['default'] = $column->defaultValue; if($column->isForeignKey) { if(isset($this->_table->foreignKeys[$column->name])) { //we can find out the ForeignKey data $ftype = 'foreign'; $fkey =& $this->_table->foreignKeys[$column->name]; $foptions['foreign'] = array( 'table'=>$fkey[0], 'pk'=>$fkey[1], 'select'=>array(), ); $foreignTableData = AAGenerator::getTable($fkey[0]); $j = 0; foreach($foreignTableData->columns as $fColumnName=>$fColumn) { if($j <= 1 && !$fColumn->isPrimaryKey && !$fColumn->isForeignKey) $foptions['foreign']['select'][$j++] = $fColumnName; } } } else { if(preg_match('/char/i', $column->dbType)) { $ftype = 'string'; $foptions['maxlength'] = $column->size; } elseif(preg_match('/(int)|(numeric)|(decimal)|(double)|(float)/i', $column->dbType)) { //numeric $ftype = 'num'; } elseif(preg_match('/text/i', $column->dbType)) { $ftype = 'tinytext'; } elseif(preg_match('/^date$/i', $column->dbType)) { $ftype = 'date'; } elseif(preg_match('/^time$/i', $column->dbType)) { $ftype = 'time'; } elseif(preg_match('/(timestamp)|(datetime)/i', $column->dbType)) { $ftype = 'datetime'; } elseif(preg_match('/enum\(([^\)]*)\)/i', $column->dbType, $matches)) { $ftype = 'enum'; $row = trim($matches[1], "'"); $foptions['enum'] = array(); if($row) { $values = explode("','", $row); if($values) $foptions['enum'] = array_combine($values, $values); } } elseif(preg_match('/boolean/', $column->dbType)) { $ftype = 'boolean'; $foptions['default'] = (bool)$column->defaultValue; } } $this->fieldsConf[] = $field; } }