/** * Get list of registered objects (names only) * @return array */ public function getRegisteredObjects() { if (is_null(self::$_objects)) { $paths = File::scanFiles(Db_Object_Config::getConfigPath(), array('.php'), false, File::Files_Only); self::$_objects = array(); if (!empty($paths)) { foreach ($paths as $path) { self::$_objects[] = substr(basename($path), 0, -4); } } /* * Scan for External objects */ if (self::$_externalsExpert) { $objects = self::$_externalsExpert->getObjects(); if (!empty($objects)) { self::$_objects = array_merge(self::$_objects, array_keys($objects)); } } } return self::$_objects; }
/** * Create Db_Object * @param string $name - object name * @param array $data - object config */ protected function _createObject($name, array $data) { $usePrefix = $data['use_db_prefix']; $connectionManager = new Db_Manager($this->_configMain); $connection = $connectionManager->getDbConnection($data['connection']); $connectionCfg = $connectionManager->getDbConfig($data['connection']); //$db = Model::getGlobalDbConnection(); $db = $connection; $tables = $db->listTables(); $oConfigPath = Db_Object_Config::getConfigPath(); $tableName = $data['table']; if ($usePrefix) { $tableName = $connectionCfg->get('prefix') . $tableName; } if (in_array($tableName, $tables, true)) { Response::jsonError($this->_lang->FILL_FORM, array(array('id' => 'table', 'msg' => $this->_lang->SB_UNIQUE))); } if (file_exists($oConfigPath . strtolower($name) . '.php')) { Response::jsonError($this->_lang->FILL_FORM, array(array('id' => 'name', 'msg' => $this->_lang->SB_UNIQUE))); } /* * Write object config */ if (!Config_File_Array::create($oConfigPath . $name . '.php')) { Response::jsonError($this->_lang->CANT_WRITE_FS); } $cfg = Config::factory(Config::File_Array, $oConfigPath . strtolower($name) . '.php'); /* * Add fields config */ $data['fields'] = array(); $cfg->setData($data); $cfg->save(); try { $cfg = Db_Object_Config::getInstance($name); $cfg->setObjectTitle($data['title']); if (!$cfg->save()) { Response::jsonError($this->_lang->CANT_WRITE_FS); } /* * Build database */ $builder = new Db_Object_Builder($name); $builder->build(); } catch (Exception $e) { Response::jsonError($this->_lang->CANT_EXEC . 'code 2'); } Response::jsonSuccess(); }