Example #1
0
 public function importdbfieldsAction()
 {
     $connectionId = Request::post('connectionId', 'string', false);
     $table = Request::post('table', 'string', false);
     $conType = Request::post('type', 'integer', false);
     $fields = Request::post('fields', 'array', false);
     if ($connectionId === false || !$table || empty($fields) || $conType === false) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     $conManager = new Backend_Orm_Connections_Manager($this->_configMain->get('db_configs'));
     $cfg = $conManager->getConnection($conType, $connectionId);
     if (!$cfg) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     $cfg = $cfg->__toArray();
     $data = Backend_Designer_Import::checkImportDBFields($cfg, $fields, $table);
     if (!$data) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     if (!empty($data)) {
         foreach ($data as $field) {
             $this->_object->addField($field);
         }
     }
     $this->_storeProject();
     Response::jsonSuccess();
 }
Example #2
0
 /**
  * Conver field from ORM format and add to the project
  * @param string $name
  * @param Db_Object_Config $importObject
  */
 protected function _importOrmField($name, $importObjectConfig)
 {
     $tabName = $this->_object->getName() . '_generalTab';
     if (!$this->_project->objectExists($tabName)) {
         $tab = Ext_Factory::object('Panel');
         $tab->setName($tabName);
         $tab->frame = false;
         $tab->border = false;
         $tab->layout = 'anchor';
         $tab->bodyPadding = 3;
         $tab->bodyCls = 'formBody';
         $tab->anchor = '100%';
         $tab->autoScroll = true;
         $tab->title = Lang::lang()->GENERAL;
         $tab->fieldDefaults = "{\n\t\t\t            labelAlign: 'right',\n\t\t\t            labelWidth: 160,\n\t\t\t            anchor: '100%'\n\t\t\t     }";
         $this->_project->addObject($this->_object->getName(), $tab);
     }
     $tabsArray = array('Component_Field_System_Medialibhtml', 'Component_Field_System_Related', 'Component_Field_System_Objectslist');
     $newField = Backend_Designer_Import::convertOrmFieldToExtField($name, $importObjectConfig->getFieldConfig($name));
     if ($newField !== false) {
         $fieldClass = $newField->getClass();
         if ($fieldClass == 'Component_Field_System_Objectslist' || $fieldClass == 'Component_Field_System_Objectlink') {
             $newField->controllerUrl = $this->_object->controllerUrl;
         }
         $newField->setName($this->_object->getName() . '_' . $name);
         if (in_array($fieldClass, $tabsArray, true)) {
             $this->_project->addObject($this->_object->getName(), $newField);
         } else {
             $this->_project->addObject($tabName, $newField);
         }
     }
 }
Example #3
0
 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;
 }
Example #4
0
    public function editorconfigAction()
    {
        $object = Request::post('object', 'string', false);
        if (!$object || !Db_Object_Config::configExists($object)) {
            Response::jsonError($this->_lang->WRONG_REQUEST);
        }
        $objectConfig = Db_Object_Config::getInstance($object);
        $data = array();
        $tabs = array();
        $tab = Ext_Factory::object('Panel');
        $tab->setName('_generalTab');
        $tab->frame = false;
        $tab->border = false;
        $tab->layout = 'anchor';
        $tab->bodyPadding = 3;
        $tab->autoScroll = true;
        $tab->bodyCls = 'formBody';
        $tab->anchor = '100%';
        $tab->title = $this->_lang->get('GENERAL');
        $tab->fieldDefaults = "{\n\t\t            labelAlign: 'right',\n\t\t            labelWidth: 160,\n\t\t            anchor: '100%'\n\t\t     }";
        $tabs[] = $tab;
        $related = array();
        $objectFieldList = array_keys($objectConfig->getFieldsConfig(false));
        $backendCfg = Registry::get('main', 'config');
        $readOnly = $objectConfig->isReadOnly();
        foreach ($objectFieldList as $field) {
            if (is_string($field) && $field == 'id') {
                continue;
            }
            $fieldCfg = $objectConfig->getFieldConfig($field);
            if ($objectConfig->isMultiLink($field)) {
                $linkedObject = $objectConfig->getLinkedObject($field);
                $linkedCfg = Db_Object_Config::getInstance($linkedObject);
                $related[] = array('field' => $field, 'object' => $linkedObject, 'title' => $fieldCfg['title'], 'titleField' => $linkedCfg->getLinkTitle());
            } elseif ($objectConfig->isObjectLink($field)) {
                if ($objectConfig->getLinkedObject($field) === 'medialib') {
                    $data[] = '{
									xtype:"medialibitemfield",
									resourceType:"all",
									name:"' . $field . '",
									readOnly:' . intval($readOnly) . ',
									fieldLabel:"' . $fieldCfg['title'] . '"
								}';
                } else {
                    $data[] = '
						{
							xtype:"objectfield",
							objectName:"' . $objectConfig->getLinkedObject($field) . '",
							controllerUrl:"' . Request::url(array($backendCfg['adminPath'], 'orm', 'dataview', ''), false) . '",
							fieldLabel:"' . $fieldCfg['title'] . '",
							name:"' . $field . '",
							anchor:"100%",
							readOnly:' . intval($readOnly) . ',
							isVc:' . intval($objectConfig->isRevControl()) . '
						}
					';
                }
            } else {
                $newField = Backend_Designer_Import::convertOrmFieldToExtField($field, $fieldCfg);
                if ($newField !== false) {
                    $newField->setName($field);
                    $fieldClass = $newField->getClass();
                    if ($readOnly && $newField->getConfig()->isValidProperty('readOnly')) {
                        $newField->readOnly = true;
                    }
                    if ($objectConfig->isText($field) && $objectConfig->isHtml($field)) {
                        $tabs[] = $newField->__toString();
                    } else {
                        $data[] = $newField->__toString();
                    }
                }
            }
        }
        $tab->items = '[' . implode(',', $data) . ']';
        Response::jsonSuccess(array('related' => $related, 'fields' => str_replace(array("\n", "\t"), '', '[' . implode(',', $tabs) . ']'), 'readOnly' => intval($readOnly), 'primaryKey' => $objectConfig->getPrimaryKey()));
    }
Example #5
0
 /**
  * Conver DB column into Ext field
  * @param string $name
  * @param array $config
  */
 protected function _importDbField($name, $config)
 {
     $newField = Backend_Designer_Import::convertDbFieldToExtField($config);
     if ($newField !== false) {
         $newField->setName($this->_object->getName() . '_' . $name);
         $this->_project->addObject($this->_object->getName(), $newField);
     }
 }