Exemple #1
0
 /**
  * 通过表Metadata生成Builders数据
  * @param string $tblName
  * @return void
  */
 public function gb($tblName)
 {
     Ap::getResponse()->contentType();
     $tableNames = $this->_metadata->getTableNames($tblName);
     if (!in_array($tblName, $tableNames)) {
         Log::errExit(__LINE__, 'Table Name Not Exists!');
     }
     Log::echoTrace('Generate Begin, Table Name "' . $tblName . '"');
     $tableSchema = $this->_metadata->getTableSchema($tblName);
     $comments = $this->_metadata->getComments($tableSchema->name);
     $tblPrefix = $this->getDbProxy()->getTblprefix();
     $tblPreLen = strlen($tblPrefix);
     Log::echoTrace('Import to builders Begin ...');
     $params = array('builder_name' => isset($comments['__table__']) ? $comments['__table__'] : $tableSchema->name, 'tbl_name' => substr($tableSchema->name, $tblPreLen), 'tbl_profile' => DataBuilders::TBL_PROFILE_N, 'tbl_engine' => DataBuilders::TBL_ENGINE_INNODB, 'tbl_charset' => DataBuilders::TBL_CHARSET_UTF8, 'tbl_comment' => isset($comments['__table__']) ? $comments['__table__'] : '', 'srv_type' => DataBuilders::SRV_TYPE_NORMAL, 'srv_name' => 'undefined', 'app_name' => 'administrator', 'mod_name' => 'undefined', 'ctrl_name' => substr($tableSchema->name, strrpos($tableSchema->name, '_') + 1), 'cls_name' => substr($tableSchema->name, strrpos($tableSchema->name, '_') + 1), 'fk_column' => '', 'act_index_name' => 'index', 'act_view_name' => 'view', 'act_create_name' => 'create', 'act_modify_name' => 'modify', 'act_remove_name' => 'remove', 'index_row_btns' => array(DataBuilders::INDEX_ROW_BTNS_PENCIL, DataBuilders::INDEX_ROW_BTNS_REMOVE), 'description' => '', 'author_name' => UserIdentity::getNick(), 'author_mail' => UserIdentity::getName());
     $mod = Service::getInstance('Builders', $this->_srvName);
     $builderId = $mod->create($params);
     if ($builderId > 0) {
         Log::echoTrace('Import to builders Successfully ...');
     } else {
         $errors = $mod->getErrors();
         Log::errExit(__LINE__, 'Import to builders Failed! ' . serialize($errors));
     }
     Log::echoTrace('Import to builder_fields Begin ...');
     $sort = 0;
     foreach ($tableSchema->columns as $columnSchema) {
         $sort++;
         if ($columnSchema->type === 'integer') {
             $columnLength = $columnSchema->size;
         } elseif (stripos($columnSchema->dbType, 'enum') !== false) {
             $columnLength = str_replace(array('\'', ','), array('', '|'), substr(substr($columnSchema->dbType, 5), 0, -1));
         } elseif (stripos($columnSchema->dbType, 'char') !== false) {
             $columnLength = $columnSchema->size;
         } else {
             $columnLength = '';
         }
         if ($columnSchema->isPrimaryKey) {
             $formRequired = DataFields::FORM_REQUIRED_N;
         } elseif (stripos($columnSchema->dbType, 'enum') !== false) {
             $formRequired = DataFields::FORM_REQUIRED_N;
         } else {
             $formRequired = DataFields::FORM_REQUIRED_Y;
         }
         if ($columnLength === 'y|n') {
             $typeId = 4;
         } elseif (stripos($columnSchema->dbType, 'enum') !== false) {
             $typeId = 5;
         } elseif ($columnSchema->isPrimaryKey) {
             $typeId = 9;
         } elseif ($columnSchema->type === 'integer') {
             $typeId = 2;
         } elseif (in_array($columnSchema->dbType, array('text', 'longtext'))) {
             $typeId = 10;
         } else {
             $typeId = 1;
         }
         $params = array('field_name' => $columnSchema->name, 'column_length' => $columnLength, 'column_auto_increment' => $columnSchema->isAutoIncrement ? DataFields::COLUMN_AUTO_INCREMENT_Y : DataFields::COLUMN_AUTO_INCREMENT_N, 'column_unsigned' => stripos($columnSchema->dbType, 'unsigned') !== false ? DataFields::COLUMN_UNSIGNED_Y : DataFields::COLUMN_UNSIGNED_N, 'column_comment' => isset($comments[$columnSchema->name]) ? $comments[$columnSchema->name] : '', 'builder_id' => $builderId, 'group_id' => 1, 'type_id' => $typeId, 'sort' => $sort, 'html_label' => isset($comments[$columnSchema->name]) ? $comments[$columnSchema->name] : $columnSchema->name, 'form_prompt' => '', 'form_required' => $formRequired, 'form_modifiable' => DataFields::FORM_MODIFIABLE_N, 'index_show' => DataFields::INDEX_SHOW_Y, 'index_sort' => $columnSchema->isPrimaryKey ? 1000 : $sort, 'form_create_show' => $columnSchema->isPrimaryKey ? DataFields::FORM_CREATE_SHOW_N : DataFields::FORM_CREATE_SHOW_Y, 'form_create_sort' => $sort, 'form_modify_show' => $columnSchema->isPrimaryKey ? DataFields::FORM_MODIFY_SHOW_N : DataFields::FORM_MODIFY_SHOW_Y, 'form_modify_sort' => $sort, 'form_search_show' => DataFields::FORM_SEARCH_SHOW_Y, 'form_search_sort' => $sort);
         $mod = Service::getInstance('Fields', $this->_srvName);
         $fieldId = $mod->create($params);
         if ($fieldId > 0) {
             Log::echoTrace('Import to builder_fields "' . $columnSchema->name . '" Successfully ...');
         } else {
             $errors = $mod->getErrors();
             Log::errExit(__LINE__, 'Import to builder_fields "' . $columnSchema->name . '" Failed! ' . serialize($errors));
         }
     }
     Log::echoTrace('Import to builder_fields Successfully ...');
     Log::echoTrace('Generate End, Table Name "' . $tblName . '"');
     exit;
 }
Exemple #2
0
 /**
  * 获取用户昵称
  * @return string
  */
 public static function getNickname()
 {
     return UserIdentity::getNick();
 }