/** * Get "single link" associations * when object has link as own property * @param integer $objectId * @param string $relatedObject - related object name * @param array $links - links config like * array( * 'field1'=>'object', * 'field2'=>'multy' * ... * 'fieldN'=>'object', * ) * @return array */ protected static function _getSingleLinks($objectId, $relatedObject, $links) { $relatedConfig = Db_Object_Config::getInstance($relatedObject); $relatedObjectModel = Model::factory($relatedObject); $fields = array(); $singleRelated = array(); foreach ($links as $field => $type) { if ($type !== 'object') { continue; } $fields[] = $field; } if (empty($fields)) { return array(); } $db = $relatedObjectModel->getDbConnection(); $sql = $db->select()->from($relatedObjectModel->table(), array($relatedConfig->getPrimaryKey())); $first = true; foreach ($fields as $field) { if ($first) { $sql->where($db->quoteIdentifier($field) . ' =?', $objectId); } else { $sql->orWhere($db->quoteIdentifier($field) . ' =?', $objectId); $first = false; } } $data = $db->fetchAll($sql); if (empty($data)) { return array(); } return Utils::fetchCol($relatedConfig->getPrimaryKey(), $data); }
public function getModule() { $dataObject = Request::post('d_object', 'string', false); if (!$dataObject || !Db_Object_Config::configExists($dataObject)) { Response::jsonError($this->_lang->WRONG_REQUEST); } return ucfirst($dataObject); }
/** * (non-PHPdoc) * @see Bgtask_Abstract::run() */ public function run() { $object = $this->_config['object']; $container = $this->_config['session_container']; /* * Save task ID into session for UI */ $session = Store_Session::getInstance(); $session->set($container, $this->_pid); $this->goBackground(); $objectConfig = Db_Object_Config::getInstance($object); $ivField = $objectConfig->getIvField(); $primaryKey = $objectConfig->getPrimaryKey(); if (!$objectConfig->hasEncrypted()) { $this->finish(); } $filter = array($ivField => new Db_Select_Filter($ivField, false, Db_Select_Filter::NOT_NULL)); $model = Model::factory($object); $count = Model::factory($object)->getCount($filter); $this->setTotalCount($count); if (!$count) { $this->finish(); } $data = $model->getList(array('limit' => $this->buckedSize), $filter, array($primaryKey)); $encryptedFields = $objectConfig->getEncryptedFields(); while (!empty($data)) { $ids = Utils::fetchCol($primaryKey, $data); $objectList = Db_Object::factory($object, $ids); $count = 0; foreach ($objectList as $dataObject) { $data = array(); foreach ($encryptedFields as $name) { $data[$name] = $dataObject->get($name); $model->logError($dataObject->getId() . ' ' . $name . ': ' . $data[$name]); } $data[$ivField] = null; try { $model->getDbConnection()->update($model->table(), $data, $primaryKey . ' = ' . $dataObject->getId()); $count++; } catch (Exception $e) { $errorText = 'Cannot decrypt ' . $dataObject->getName() . ' ' . $dataObject->getId() . ' ' . $e->getMessage(); $model->logError($errorText); $this->error($errorText); } } /* * Update task status and check for signals */ $this->incrementCompleted($count); $this->updateState(); $this->processSignals(); $data = $model->getList(array('limit' => $this->buckedSize), $filter, array($primaryKey)); } $this->finish(); }
public function refreshTableInfo() { $conName = $this->_objectConfig->get('connection'); $this->_db = $this->_dbManager->getDbConnection($conName); if ($this->_objectConfig->hasDbPrefix()) { $this->_dbPrefix = $this->_dbManager->getDbConfig($conName)->get('prefix'); } else { $this->_dbPrefix = ''; } $this->_table = $this->_objectConfig->get('table'); }
/** * Check Db_Object structure * @throws Exception */ public function checkOrmStructure() { if (!Db_Object_Config::configExists($this->_object)) { throw new Exception('Filestorage_Orm undefined Orm object'); } $cfg = Db_Object_Config::getInstance($this->_object); $fields = $cfg->getFieldsConfig(true); foreach ($this->_objectFields as $name) { if (!isset($fields[$name])) { throw new Exception('Filestorage_Orm invalid orm structure, field ' . $name . ' not found'); } } }
/** * (non-PHPdoc) * @see Bgtask_Abstract::run() */ public function run() { $object = $this->_config['object']; $container = $this->_config['session_container']; /* * Save task ID into session for UI */ $session = Store_Session::getInstance(); $session->set($container, $this->_pid); $this->goBackground(); $objectConfig = Db_Object_Config::getInstance($object); $ivField = $objectConfig->getIvField(); $primaryKey = $objectConfig->getPrimaryKey(); $model = Model::factory($object); $count = Model::factory($object)->getCount(array($ivField => null)); $this->setTotalCount($count); if (!$count) { $this->finish(); } $ignore = array(); $data = $model->getList(array('limit' => $this->buckedSize), array($ivField => null), array($primaryKey)); while (!empty($data)) { $ids = Utils::fetchCol($primaryKey, $data); $objectList = Db_Object::factory($object, $ids); $count = 0; foreach ($objectList as $dataObject) { if (!$dataObject->save()) { $ignore[] = $dataObject->getId(); $this->log('Cannot encrypt ' . $dataObject->getName() . ' ' . $dataObject->getId()); } else { $count++; } } /* * Update task status and check for signals */ $this->incrementCompleted($count); $this->updateState(); $this->processSignals(); if (!empty($ignore)) { $filters = array($ivField => null, $primaryKey => new Db_Select_Filter($primaryKey, $ignore, Db_Select_Filter::NOT_IN)); } else { $filters = array($ivField => null); } $data = $model->getList(array('limit' => $this->buckedSize), $filters, array($primaryKey)); } $this->finish(); }
/** * Import fields into the form object */ public function importfieldsAction() { $importObject = Request::post('importobject', 'string', false); $importFields = Request::post('importfields', 'array', array()); if (!$importObject || empty($importFields) || $this->_project->objectExists($importObject)) { Response::jsonError($this->_lang->WRONG_REQUEST); } $importObjectConfig = Db_Object_Config::getInstance($importObject); foreach ($importFields as $name) { if ($importObjectConfig->fieldExists($name)) { $this->_importOrmField($name, $importObjectConfig); } } $this->_storeProject(); Response::jsonSuccess(); }
/** * Save object as new version * @param boolean $log - log changes * @param boolean $useTransaction — using a transaction when changing data is optional. * @return boolean */ public function saveVersion($log = true, $useTransaction = true) { if (!$this->_config->isRevControl()) { return $this->save($log, $useTransaction); } if ($this->_config->hasEncrypted()) { $ivField = $this->_config->getIvField(); $ivData = $this->get($ivField); if (empty($ivData)) { $this->set($ivField, base64_encode($this->_config->createIv())); } } if ($this->_acl) { try { $this->_checkCanEdit(); } catch (Exception $e) { $this->_errors[] = $e->getMessage(); if (self::$_log) { self::$_log->log($e->getMessage()); } return false; } } if (!$this->getId()) { $this->published = false; $this->author_id = User::getInstance()->getId(); if (!$this->save(true, $useTransaction)) { return false; } } $this->date_updated = date('Y-m-d H:i:s'); $this->editor_id = User::getInstance()->getId(); $store = $this->_model->getStore(); if (self::$_log) { $store->setLog(self::$_log); } $vers = $store->addVersion($this, $log, $useTransaction); if ($vers) { $this->_version = $vers; $this->commitChanges(); return true; } else { return false; } }
/** * Set Object class for part selection * @param string $name */ public function setObject($name) { $config = Db_Object_Config::getInstance($name); $this->_object = $name; $this->_fields = array(); $cfgFields = $config->getFieldsConfig(true); foreach ($cfgFields as $k => $v) { /* * Ignore multylinks */ if ($config->isMultiLink($k)) { continue; } $title = ''; if (isset($v['title'])) { $title = $v['title']; } $this->_fields[$k] = array('alias' => '', 'title' => $title, 'select' => false, 'isLink' => $config->isLink($k), 'selectSub' => false); } }
/** * Check for broken object links * return array | boolean false */ public function hasBrokenLinks() { $links = $this->_objectConfig->getLinks(); $brokenFields = array(); if (!empty($links)) { $brokenFields = array(); foreach ($links as $o => $fieldList) { if (!Db_Object_Config::configExists($o)) { foreach ($fieldList as $field => $cfg) { $brokenFields[$field] = $o; } } } } if (empty($brokenFields)) { return false; } else { return $brokenFields; } }
public function testRenameTable() { $cfg = Db_Object_Config::getInstance('Page', true); $uniqName = uniqid(); $o = new Db_Object_Builder('Page', false); $renamed = $o->renameTable($uniqName); if (!$renamed) { echo implode("\n", $o->getErrors()); } $this->assertTrue($renamed); $cfg->getConfig()->set('table', $uniqName); Model::removeInstance('Page'); $o = new Db_Object_Builder('Page', false); $renamed = $o->renameTable('content'); if (!$renamed) { echo implode("\n", $o->getErrors()); } $this->assertTrue($renamed); $cfg->getConfig()->set('table', 'content'); }
/** * 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; }
/** * Get list of ORM object fields */ public function fieldsAction() { $objectName = Request::post('object', 'string', false); if (!$objectName) { Response::jsonError($this->_lang->WRONG_REQUEST); } try { $config = Db_Object_Config::getInstance($objectName); } catch (Exception $e) { Response::jsonError($this->_lang->WRONG_REQUEST); } $fields = $config->getFieldsConfig(); if (empty($fields)) { Response::jsonSuccess(array()); } $data = array(); foreach ($fields as $name => $cfg) { $type = $cfg['db_type']; if ($config->isLink($name)) { if ($config->isDictionaryLink($name)) { $type = $this->_lang->DICTIONARY_LINK . '"' . $config->getLinkedDictionary($name) . '"'; } else { $obj = $config->getLinkedObject($name); $oName = $obj . ''; try { $oCfg = Db_Object_Config::getInstance($obj); $oName .= ' (' . $oCfg->get('title') . ')'; } catch (Exception $e) { //empty on error } $type = $this->_lang->OBJECT_LINK . ' - ' . $oName; } } $data[] = array('name' => $name, 'title' => $cfg['title'], 'type' => $type); } Response::jsonSuccess($data); }
public function uploadAction() { $object = Request::post('object', 'string', false); if (!$object || !Db_Object_Config::configExists($object)) { Response::jsonError($this->_lang->get('FILL_FORM')); } $cfg = Db_Object_Config::getInstance($object); $fields = $cfg->getFieldsConfig(false); $expectedCols = array(); $expectedCols[] = array('id' => $cfg->getPrimaryKey(), 'text' => $this->_lang->get('PRIMARY_KEY'), 'columnIndex' => -1, 'required' => 1); foreach ($fields as $name => $fConfig) { $expectedCols[] = array('id' => $name, 'text' => $fConfig['title'], 'columnIndex' => -1, 'required' => $cfg->isRequired($name)); } $result = array('success' => true, 'expectedColumns' => $expectedCols, 'data' => array(), 'uploadId' => 1); if (!$cfg->isSystem()) { $result['importTypes'][] = array('name' => 'type', 'inputValue' => 'rewrite', 'boxLabel' => $this->_iLang->get('REWRITE')); } //echo json_encode(array('success'=>false,'msg'=>'Cannot upload file')); exit; for ($i = 0; $i < 30; $i++) { $result['data'][] = array('col0' => 'Data' . rand(0, 6), 'col1' => rand(1000, 9999), 'col2' => rand(1, 700), 'col3' => rand(1, 700), 'col4' => rand(1, 700), 'col5' => rand(1, 700), 'col6' => rand(1, 700)); } $result['col_count'] = sizeof($result['data'][0]); Response::jsonArray($result); }
/** * List permissions action */ public function permissionsAction() { $user = Request::post('user_id', 'int', 0); $group = Request::post('group_id', 'int', 0); if ($user && $group) { Response::jsonError($this->_lang->WRONG_REQUEST); } if ($group) { $data = Model::factory('acl_simple')->getGroupPermissions($group); } if (!empty($data)) { $data = Utils::rekey('object', $data); } $manager = new Db_Object_Manager(); $objects = $manager->getRegisteredObjects(); foreach ($objects as $name) { if (!isset($data[$name])) { $data[$name] = array('object' => $name, 'create' => false, 'view' => false, 'edit' => false, 'delete' => false, 'user_id' => null, 'publish' => false, 'group_id' => $group); } } foreach ($data as $k => &$v) { if (!Db_Object_Config::configExists($k)) { unset($data[$k]); continue; } $cfg = Db_Object_Config::getInstance($k); if ($cfg->isRevControl()) { $v['rc'] = true; } else { $v['rc'] = false; } $v['title'] = $cfg->getTitle(); } unset($v); Response::jsonSuccess(array_values($data)); }
public function otitleAction() { $object = Request::post('object', 'string', false); $id = Request::post('id', 'string', false); if (!$object || !Db_Object_Config::configExists($object)) { Response::jsonError($this->_lang->WRONG_REQUEST); } try { $o = Db_Object::factory($object, $id); Response::jsonSuccess(array('title' => $o->getTitle())); } catch (Exception $e) { Model::factory($object)->logError('Cannot get title for ' . $object . ':' . $id); Response::jsonError($this->_lang->get('CANT_EXEC')); } }
/** * Create new module */ public function createAction() { $this->_checkCanEdit(); $object = Request::post('object', 'string', false); if (!$object) { Response::jsonError($this->_lang->WRONG_REQUEST); } $object = Utils_String::formatClassName($object); $class = 'Backend_' . $object . '_Controller'; if (class_exists($class)) { Response::jsonError($this->_lang->FILL_FORM, array('id' => 'name', 'msg' => $this->_lang->SB_UNIQUE)); } $designerConfig = Config::factory(Config::File_Array, $this->_configMain['configs'] . 'designer.php'); $projectFile = $designerConfig->get('configs') . strtolower($object) . '.designer.dat'; if (file_exists($projectFile)) { Response::jsonError($this->_lang->FILE_EXISTS . '(' . $projectFile . ')'); } $actionFile = $designerConfig->get('actionjs_path') . strtolower($object) . '.js'; if (file_exists($actionFile)) { Response::jsonError($this->_lang->FILE_EXISTS . '(' . $actionFile . ')'); } $objectConfig = Db_Object_Config::getInstance($object); // Check ACL permissions $acl = $objectConfig->getAcl(); if ($acl) { if (!$acl->can(Db_Object_Acl::ACCESS_CREATE, $object) || !$acl->can(Db_Object_Acl::ACCESS_VIEW, $object)) { Response::jsonError($this->_lang->get('ACL_ACCESS_DENIED')); } } $manager = new Db_Object_Manager(); if (!$manager->objectExists($object)) { Response::jsonError($this->_lang->FILL_FORM, array('id' => 'object', 'msg' => $this->_lang->INVALID_VALUE)); } $codeGenadApter = $this->_configBackend->get('modules_codegen'); $codeGen = new $codeGenadApter(); try { if ($objectConfig->isRevControl()) { $codeGen->createVcModule($object, $projectFile, $actionFile); } else { $codeGen->createModule($object, $projectFile, $actionFile); } } catch (Exception $e) { Response::jsonError($e->getMessage()); } $userInfo = User::getInstance()->getInfo(); $per = Model::factory('Permissions'); if (!$per->setGroupPermissions($userInfo['group_id'], $object, 1, 1, 1, 1)) { Response::jsonError($this->_lang->CANT_EXEC); } Response::jsonSuccess(array('class' => $class, 'name' => $object, 'active' => true, 'dev' => false, 'title' => $objectConfig->getTitle(), 'designer' => $projectFile)); }
public function testGetTitle() { $cfg = Db_Object_Config::getInstance('Page'); $data = $cfg->getData(); $data['link_title'] = '/ {code} / {menu_title} /'; $cfg->setData($data); $page = new Db_Object('Page'); $page->set('code', 'pageCode'); $page->set('menu_title', 'pageTitle'); //echo $page->getTitle();exit; $this->assertEquals('/ pageCode / pageTitle /', $page->getTitle()); }
/** * Delete Db object * @param string $objectName * @param array $ids * @return boolean */ public function deleteObjects($objectName, array $ids) { $objectConfig = Db_Object_Config::getInstance($objectName); if ($objectConfig->isReadOnly()) { if ($this->_log) { $this->_log->log('ORM :: cannot delete readonly objects ' . $objectConfig->getName()); } return false; } $objectModel = Model::factory($objectName); $tableName = $objectModel->table(); if (empty($ids)) { return true; } $specialCase = Db_Object::factory($objectName); $db = $this->_getDbConnection($specialCase); $where = $db->quoteInto('`id` IN(?)', $ids); if ($this->_eventManager) { foreach ($ids as $id) { $specialCase->setId($id); $this->_eventManager->fireEvent(Db_Object_Event_Manager::BEFORE_DELETE, $specialCase); } } if (!$db->delete($tableName, $where)) { return false; } /* * Clear object liks (links from object) */ Model::factory($this->_linksObject)->clearLinksFor($objectName, $ids); $history = Model::factory($this->_historyObject); $userId = User::getInstance()->id; /* * Save history if required */ if ($objectConfig->hasHistory()) { foreach ($ids as $v) { $history->log($userId, $v, Model_Historylog::Delete, $tableName); } } if ($this->_eventManager) { /* * Fire "AFTER_DELETE" event for each deleted object */ foreach ($ids as $id) { $specialCase->setId($id); $this->_eventManager->fireEvent(Db_Object_Event_Manager::AFTER_DELETE, $specialCase); } } return true; }
public function createModule($object, $projectFile, $actionFile) { $lang = Lang::lang(); //prepare class name $name = Utils_String::formatClassName($object); $jsName = str_replace('_', '', $name); $runNamespace = 'app' . $jsName . 'Run'; $classNamespace = 'app' . $jsName . 'Classes'; $objectConfig = Db_Object_Config::getInstance($object); $primaryKey = $objectConfig->getPrimaryKey(); $appConfig = Registry::get('main', 'config'); $designerConfig = Config::factory(Config::File_Array, $appConfig->get('configs') . 'designer.php'); $objectFieldsConfig = $objectConfig->getFieldsConfig(false); $objectFields = array(); $searchFields = array(); $linkedObjects = array(); /* * Skip text fields */ foreach ($objectFieldsConfig as $key => $item) { if ($objectConfig->isObjectLink($key) || $objectConfig->isMultiLink($key)) { $linkedObjects[] = $objectConfig->getLinkedObject($key); } if (in_array($item['db_type'], Db_Object_Builder::$textTypes, true)) { continue; } $objectFields[] = $key; if (isset($item['is_search']) && $item['is_search']) { $searchFields[] = $key; } } $dataFields = array(); foreach ($objectConfig->getFieldsConfig(true) as $key => $item) { if (in_array($item['db_type'], Db_Object_Builder::$textTypes, true)) { continue; } $dataFields[] = $key; } array_unshift($objectFields, $primaryKey); $controllerContent = '<?php ' . "\n" . 'class Backend_' . $name . '_Controller extends Backend_Controller_Crud{' . "\n" . ' protected $_listFields = array("' . implode('","', $dataFields) . '");' . "\n" . ' protected $_canViewObjects = array("' . implode('","', $linkedObjects) . '");' . "\n" . '} '; /* * Create controller */ $controllerDir = $appConfig->get('backend_controllers') . str_replace('_', '/', $name); $this->_createControllerFile($controllerDir, $controllerContent); @chmod($controllerDir . DIRECTORY_SEPARATOR . 'Controller.php', $controllerContent, 0775); /* * Designer project */ $project = new Designer_Project(); $project->namespace = $classNamespace; $project->runnamespace = $runNamespace; /* * Project events */ $eventManager = $project->getEventManager(); $storeFields = Backend_Designer_Import::checkImportORMFields($object, $dataFields); $urlTemplates = $designerConfig->get('templates'); Request::setDelimiter($urlTemplates['urldelimiter']); $controllerUrl = Request::url(array($urlTemplates['adminpath'], $object, ''), false); $storeUrl = Request::url(array($urlTemplates['adminpath'], $object, 'list')); Request::setDelimiter($appConfig->get('urlDelimiter')); $dataStore = Ext_Factory::object('Data_Store'); $dataStore->setName('dataStore'); $dataStore->autoLoad = true; $dataStore->addFields($storeFields); $dataProxy = Ext_Factory::object('Data_Proxy_Ajax'); $dataProxy->type = 'ajax'; $dataReader = Ext_Factory::object('Data_Reader_Json'); $dataReader->root = 'data'; $dataReader->totalProperty = 'count'; $dataReader->idProperty = $primaryKey; $dataReader->type = 'json'; $dataProxy->reader = $dataReader; $dataProxy->url = $storeUrl; $dataProxy->startParam = 'pager[start]'; $dataProxy->limitParam = 'pager[limit]'; $dataProxy->sortParam = 'pager[sort]'; $dataProxy->directionParam = 'pager[dir]'; $dataProxy->simpleSortMode = true; $dataStore->proxy = $dataProxy; $dataStore->remoteSort = true; $project->addObject(0, $dataStore); /* * Data grid */ $dataGrid = Ext_Factory::object('Grid'); $dataGrid->setName('dataGrid'); $dataGrid->store = 'dataStore'; $dataGrid->columnLines = true; $dataGrid->title = $objectConfig->getTitle() . ' :: ' . $lang->HOME; $dataGrid->setAdvancedProperty('paging', true); $dataGrid->viewConfig = '{enableTextSelection: true}'; $eventManager->setEvent('dataGrid', 'itemdblclick', 'show' . $jsName . 'EditWindow(record.get("id"));'); $objectFieldList = Backend_Designer_Import::checkImportORMFields($object, $objectFields); if (!empty($objectFieldList)) { foreach ($objectFieldList as $fieldConfig) { switch ($fieldConfig->type) { case 'boolean': $column = Ext_Factory::object('Grid_Column_Boolean'); $column->renderer = 'Ext_Component_Renderer_System_Checkbox'; $column->width = 50; $column->align = 'center'; break; case 'integer': $column = Ext_Factory::object('Grid_Column'); break; case 'float': $column = Ext_Factory::object('Grid_Column_Number'); if (isset($objectFieldsConfig[$fieldConfig->name]['db_precision'])) { $column->format = '0,000.' . str_repeat('0', $objectFieldsConfig[$fieldConfig->name]['db_precision']); } break; case 'date': $column = Ext_Factory::object('Grid_Column_Date'); if ($objectFieldsConfig[$fieldConfig->name]['db_type'] == 'time') { $column->format = 'H:i:s'; } break; default: $column = Ext_Factory::object('Grid_Column'); } if ($objectConfig->fieldExists($fieldConfig->name)) { $cfg = $objectConfig->getFieldConfig($fieldConfig->name); $column->text = $cfg['title']; } else { $column->text = $fieldConfig->name; } $column->dataIndex = $fieldConfig->name; $column->setName($fieldConfig->name); $column->itemId = $column->getName(); $dataGrid->addColumn($column->getName(), $column, $parent = 0); } } $project->addObject(0, $dataGrid); /* * Top toolbar */ $dockObject = Ext_Factory::object('Docked'); $dockObject->setName($dataGrid->getName() . '__docked'); $project->addObject($dataGrid->getName(), $dockObject); $filters = Ext_Factory::object('Toolbar'); $filters->setName('filters'); $project->addObject($dockObject->getName(), $filters); /* * Top toolbar items */ $addButton = Ext_Factory::object('Button'); $addButton->setName('addButton'); $addButton->text = $lang->ADD_ITEM; $eventManager->setEvent('addButton', 'click', 'show' . $jsName . 'EditWindow(false);'); $project->addObject($filters->getName(), $addButton); $sep1 = Ext_Factory::object('Toolbar_Separator'); $sep1->setName('sep1'); $project->addObject($filters->getName(), $sep1); if (!empty($searchFields)) { $searchField = Ext_Factory::object('Component_Field_System_Searchfield'); $searchField->setName('searchField'); $searchField->width = 200; $searchField->store = $dataStore->getName(); $searchField->fieldNames = json_encode($searchFields); $fill = Ext_Factory::object('Toolbar_Fill'); $fill->setName('fill1'); $project->addObject($filters->getName(), $fill); $project->addObject($filters->getName(), $searchField); } /* * Editor window */ $editWindow = Ext_Factory::object('Component_Window_System_Crud'); $editWindow->setName('editWindow'); $editWindow->objectName = $object; $editWindow->controllerUrl = $controllerUrl; $editWindow->width = 800; $editWindow->height = 650; $editWindow->modal = true; $editWindow->resizable = true; $editWindow->extendedComponent(true); $eventManager->setEvent('editWindow', 'dataSaved', $runNamespace . '.dataStore.load();'); if (!$objectConfig->hasHistory()) { $editWindow->hideEastPanel = true; } $project->addObject(0, $editWindow); $tab = Ext_Factory::object('Panel'); $tab->setName($editWindow->getName() . '_generalTab'); $tab->frame = false; $tab->border = false; $tab->layout = 'anchor'; $tab->bodyPadding = 3; $tab->bodyCls = 'formBody'; $tab->anchor = '100%'; $tab->title = $lang->GENERAL; $tab->autoScroll = true; $tab->fieldDefaults = "{\n\t\t labelAlign: 'right',\n\t\t labelWidth: 160,\n\t\t anchor: '100%'\n\t\t }"; $project->addObject($editWindow->getName(), $tab); $objectFieldList = array_keys($objectConfig->getFieldsConfig(false)); foreach ($objectFieldList as $field) { if ($field == $primaryKey) { continue; } $newField = Backend_Designer_Import::convertOrmFieldToExtField($field, $objectConfig->getFieldConfig($field)); if ($newField === false) { continue; } $newField->setName($editWindow->getName() . '_' . $field); $fieldClass = $newField->getClass(); if ($fieldClass == 'Component_Field_System_Objectslist' || $fieldClass == 'Component_Field_System_Objectlink') { $newField->controllerUrl = $controllerUrl; } if (in_array($fieldClass, $this->tabTypes, true)) { $project->addObject($editWindow->getName(), $newField); } else { $project->addObject($tab->getName(), $newField); } } /* * Save designer project */ $designerStorage = Designer_Factory::getStorage($designerConfig); $project->actionjs = $actionFile; if (!$designerStorage->save($projectFile, $project)) { throw new Exception('Can`t create Designer project'); } /* * Create ActionJS file */ $this->_createActionJS($runNamespace, $classNamespace, $actionFile, $jsName); return true; }
protected function _initExternals() { $eExpert = $this->_getExternalsExpert(); if (!$eExpert->hasExternals()) { return; } /* * Register external classes */ $classes = $eExpert->getClasses(); if (!empty($classes)) { $this->_autoloader->addMap($classes); } /* * Register external objects */ $objects = $eExpert->getObjects(); if (!empty($objects)) { Db_Object_Config::registerConfigs($objects); } $curLang = $this->_config->get('language'); /* * Register external translations */ $translations = $eExpert->getTranslations($curLang); if (!empty($translations)) { Db_Object_Config::getTranslator()->addTranslations($translations); } $dictionaries = $eExpert->getDictionaries(); if (!empty($dictionaries)) { Dictionary::addExternal($dictionaries); } $langs = $eExpert->getLangs($curLang); if (!empty($langs)) { foreach ($langs as $name => $path) { Lang::addDictionaryLoader($name, $path, Config::File_Array); } } /* * Inject Externals Expert */ $page = Page::getInstance()->setExternalsExpert($eExpert); }
/** * Get object title */ public function otitleAction() { $object = Request::post('object', 'string', false); $id = Request::post('id', 'string', false); if (!$object || !Db_Object_Config::configExists($object)) { Response::jsonError($this->_lang->WRONG_REQUEST); } if (!in_array(strtolower($object), $this->_canViewObjects, true)) { Response::jsonError($this->_lang->CANT_VIEW); } $objectConfig = Db_Object_Config::getInstance($object); // Check ACL permissions $acl = $objectConfig->getAcl(); if ($acl) { if (!$acl->can(Db_Object_Acl::ACCESS_VIEW, $object)) { Response::jsonError($this->_lang->get('ACL_ACCESS_DENIED')); } } try { $o = Db_Object::factory($object, $id); Response::jsonSuccess(array('title' => $o->getTitle())); } catch (Exception $e) { Model::factory($object)->logError('Cannot get title for ' . $object . ':' . $id); Response::jsonError($this->_lang->get('CANT_EXEC')); } }
public function testGetLinkedDictionary() { $cfg = Db_Object_Config::getInstance('test'); $this->assertEquals('link_type', $cfg->getLinkedDictionary('dictionary')); }
/** * Get object fields */ public function fieldlistAction() { $object = Request::post('object', 'string', false); if (!$object) { Response::jsonSuccess(array()); } $this->_checkLoaded(); $query = $this->_session->get('query'); $result = array(); $fields = Db_Object_Config::getInstance($object)->getFieldsConfig(true); if (!empty($fields)) { foreach ($fields as $code => $config) { $result[] = array('id' => $code, 'title' => $config['title']); } } Response::jsonSuccess($result); }
protected function _addSqlPart(Db_Query_Part $part, $sql, Db_Query_Part $parenPart, $countOnly = false) { if ($countOnly) { $fields = array(); } else { $fields = $this->_extractFields($part); if (empty($fields)) { return; } } $parentTable = Db_Object_Config::getInstance($parenPart->getObject())->getTable(); $curTable = Db_Object_Config::getInstance($part->getObject())->getTable(); $condition = '`' . $parentTable . '`.`' . $part->parentField . '` = `' . $curTable . '`.`' . $part->childField . '`'; switch ($part->joinType) { case Db_Query_Part::JOIN_INNER: $sql->joinInner($curTable, $condition, $fields); break; case Db_Query_Part::JOIN_LEFT: $sql->joinLeft($curTable, $condition, $fields); break; case Db_Query_Part::JOIN_RIGHT: $sql->joinRight($curTable, $condition, $fields); break; } }
public function decryptDataAction() { $this->_checkCanEdit(); $object = Request::post('object', 'string', false); if (!$object || !Db_Object_Config::configExists($object)) { Response::jsonError($this->_lang->get('WRONG_REQUEST')); } $container = $this->decryptContainerPrefix . $object; $objectModel = Model::factory($object); $taskModel = Model::factory('bgtask'); $signalModel = Model::factory('Bgtask_Signal'); //disable profiling in dev mode if ($this->_configMain->get('development')) { $taskModel->getDbConnection()->getProfiler()->setEnabled(false); $signalModel->getDbConnection()->getProfiler()->setEnabled(false); $objectModel->getDbConnection()->getProfiler()->setEnabled(false); } $logger = new Bgtask_Log_File($this->_configMain['task_log_path'] . $container . '_' . date('d_m_Y__H_i_s')); $bgStorage = new Bgtask_Storage_Orm($taskModel, $signalModel); $tm = Bgtask_Manager::getInstance(); $tm->setStorage($bgStorage); $tm->setLogger($logger); // Start encryption task $tm->launch(Bgtask_Manager::LAUNCHER_SIMPLE, 'Task_Orm_Decrypt', array('object' => $object, 'session_container' => $container)); }
/** * Inject translation adapter * @param Db_Object_Config_Translator $translator */ public static function setTranslator(Db_Object_Config_Translator $translator) { self::$_translator = $translator; }