Exemple #1
0
 /**
  * @return Zend_Db_Table_Row
  */
 protected function _getErrorRow()
 {
     $row = self::$_model->fetchRow(array('sid=?' => 'error'));
     if (!$row) {
         $configError = new Z_Config('error_text');
         $errtext = $configError->getValue();
         $row = self::$_model->createRow(array('sid' => 'error', 'title' => 'Ошибка', 'text' => $errtext ? $errtext : 'Страница не найдена'));
     }
     return $row;
 }
Exemple #2
0
 /**
  * @return Zend_Db_Table_Row
  */
 protected function _getRow($sid)
 {
     $cache = Z_Cache::getInstance();
     if (!($this->_data = $cache->load('kap_config'))) {
         $this->_data = $this->_model->fetchPairs(array('sid', 'value'));
         $cache->save($this->_data, 'kap_config');
     }
     if (isset($this->_data[$sid])) {
         return $this->_data[$sid];
     } else {
         return false;
     }
 }
Exemple #3
0
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     if ($request->getModuleName() == 'admin' || APPLICATION_ENV != 'development') {
         return;
     }
     $frontController = Zend_Controller_Front::getInstance();
     $options = array('plugins' => array('Variables', 'Database' => array('adapter' => Z_Db_Table::getDefaultAdapter()), 'File' => array('basePath' => SITE_PATH), 'Memory', 'Time', 'Registry', 'Cache' => array('backend' => Z_Cache::getbackend()), 'Exception'));
     $debug = new ZFDebug_Controller_Plugin_Debug($options);
     $frontController->registerPlugin($debug);
 }
Exemple #4
0
 protected function __construct()
 {
     self::$_instance = new Zend_Log();
     if (Z_Db_Table::getDefaultAdapter()) {
         //			$logModel = new Z_Model_Log();
         //			$logTable = $logModel->info('name');
         $writer = new Zend_Log_Writer_Db(Z_Db_Table::getDefaultAdapter(), 'z_log');
     } else {
         $writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'data/info.log');
     }
     self::$_instance->addWriter($writer);
 }
Exemple #5
0
 private function db($input)
 {
     //echo '1';
     if (!isset($input['file']) || !isset($this->_files[$input['file']])) {
         return false;
     }
     $query = base64_decode($this->_files[$input['file']]);
     $queries = $this->splitQueries($query);
     //var_dump($queries);
     try {
         foreach ($queries as $key => $q) {
             $this->_model->getAdapter()->query($q);
         }
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
 public function rebuildAction()
 {
     $this->disableRenderView();
     $this->ajaxGo($this->view->url(array('action' => $this->z_defaultAction, 'id' => NULL)));
     $id = $this->_getParam('id');
     $tableModel = $this->z_model;
     $fieldModel = new Z_Model_Dbtablesfields();
     $tableObject = $tableModel->find($id)->current();
     $fieldObjects = $fieldModel->fetchAll(array('dbtable_id=?' => $id), 'orderid asc');
     $modelName = 'Site_Model_' . implode('_', array_map('ucfirst', explode('_', $tableObject->title)));
     $model = new $modelName();
     $columns = $model->info('metadata');
     $fieldset = array();
     foreach ($fieldObjects as $field) {
         $fieldset[] = $field->title;
         if ($field->title == 'id') {
             continue;
         }
         if (array_key_exists($field->title, $columns) && $field->type == $columns[$field->title]['DATA_TYPE']) {
             continue;
         }
         $queryStr = "";
         $queryStr = '`' . $field->title . '`';
         $queryStr .= ' ' . strtoupper($field->type);
         $queryStr .= $field->len ? '(' . $field->len . ')' : '';
         $queryStr .= $field->is_null ? ' NULL' : ' NOT NULL';
         $queryStr .= $field->default == 'asdefine' ? " DEFAULT '" . $field->default_value . "'" : '';
         if (array_key_exists($field->title, $columns)) {
             $queryStr = 'ALTER TABLE `' . $tableObject->title . '` CHANGE `' . $field->title . '` ' . $queryStr;
         } else {
             $queryStr = 'ALTER TABLE `' . $tableObject->title . '` ADD ' . $queryStr;
         }
         Z_FlashMessenger::addMessage($queryStr);
         Z_Db_Table::getDefaultAdapter()->query($queryStr);
     }
     foreach ($columns as $column => $columnPropertyes) {
         if ($column == 'id') {
             continue;
         }
         if (!in_array($column, $fieldset)) {
             $queryStr = 'ALTER TABLE `' . $tableObject->title . '` DROP `' . $column . '`';
             Z_FlashMessenger::addMessage($queryStr);
             Z_Db_Table::getDefaultAdapter()->query($queryStr);
         }
     }
 }
Exemple #7
0
 /**
  * Устанавливает все настройки контроллера на основании информации о ресурсе
  */
 protected function exportResourceInfo(Zend_Db_Table_Row $info)
 {
     $fieldsToMove = array('resourceId', 'title', 'datatype', 'default_field', 'paginate', 'group', 'can_delete', 'can_edit', 'can_add', 'delete_confirm', 'delete_on_have_child', 'sortable', 'sortable_position', 'indexate');
     //установка моделей
     if (!$info->model) {
         throw new Exception('Не указана модель');
     }
     $modelName = $info->model;
     $this->z_model = new $modelName();
     //колонки
     $modelResourcecolumns = new Z_Model_Resourcecolumns();
     $columns = $modelResourcecolumns->fetchAll(array('resourceid=?' => $info->id), 'orderid');
     foreach ($columns as $column) {
         //добавление фильтров в условие (если фильтры имеются)
         $filterValue = $this->_getParam('filter_' . $info->resourceId . '_' . $column->field, NULL);
         //var_dump(urldecode(base64_decode($filterValue)));
         if (is_array($filterValue)) {
             $filterValue = implode('{{}}', $filterValue);
         }
         $filterValue = $filterValue ? urldecode(base64_decode($filterValue)) : $filterValue;
         if ($column->filter_query && $filterValue !== NULL) {
             if (strpos($filterValue, '{{}}')) {
                 $this->z_conditions[] = array('condition' => $column->filter_query, 'value' => new Zend_Db_Expr(str_replace('{{}}', ',', $filterValue)));
             } else {
                 $this->z_conditions[] = array('condition' => $column->filter_query, 'value' => strpos($column->filter_query, 'LIKE') > 0 ? '%' . $filterValue . '%' : $filterValue);
             }
             $info->sortable = false;
         }
         //добавление сортировки по параметрам
         $orderdir = '';
         $ordered = false;
         if ($column->orderlink && $this->_getParam($info->resourceId . '_orderfield') == $column->field) {
             $orderdir = $this->_getParam($info->resourceId . '_orderdir') == 'desc' ? 'DESC' : '';
             $this->z_order[] = $column->field . ($orderdir ? ' ' . $orderdir : ' ASC');
             $ordered = true;
             $info->sortable = false;
         }
         $this->z_columns[$column->field] = array('title' => $column->title, 'width' => $column->width, 'orderlink' => $column->orderlink ? true : false, 'orderdir' => $orderdir, 'ordered' => $ordered, 'template' => $column->template ? $column->template : false, 'eval' => $column->eval ? $column->eval : false, 'escape' => $column->escape ? true : false, 'filter' => $column->filter_query ? $column->filter_query : false, 'filter_value' => $filterValue, 'filter_items' => $column->filter_items ? eval($column->filter_items) : false, 'on_have_subcat' => $column->on_have_subcat, 'visible' => $column->visible);
     }
     //добавление ссылок на дочерние таблицы
     $childResources = $this->getResourceModel()->fetchAll(array('parentid=?' => $info->id, 'parent_field!=?' => '', 'model!=?' => ''), 'orderid');
     foreach ($childResources as $childResource) {
         //проверка на правдо доступа.
         //Если нет доступа на этот ресурс, пропускаем добавление ссылки на него
         if (!Z_Acl::getInstance()->isAllowed(Z_Auth::getInstance()->getUser()->getRole(), $childResource->resourceId, 'list')) {
             continue;
         }
         $this->z_child_resources[] = $childResource->toArray();
         $this->z_columns[$childResource->resourceId . '_resource'] = array('title' => $childResource->title, 'eval' => 'return "<a class=\\"z-ajax\\" href=\\"".$this->url(array("controller"=>"' . $childResource->resourceId . '","action"=>"' . $childResource->actionId . '","' . $childResource->resourceId . '_parentid"=>{{id}},"z_catalog_sysparentid"=>NULL))."\\">' . $childResource->title . '</a>";', 'on_have_subcat' => $childResource->on_have_subcat);
     }
     $this->view->columns = $this->z_columns;
     //89649415502
     //Джойны
     $modelResourcejoins = new Z_Model_Resourcejoins();
     $joins = $modelResourcejoins->fetchAll(array('resourceid=?' => $info->id), 'orderid');
     foreach ($joins as $join) {
         $modelName = $join->model;
         if (class_exists($modelName)) {
             $model = new $modelName();
             $joinTableName = $model->info('name');
         } else {
             $joinTableName = $modelName;
         }
         $fields = array();
         $fieldsArray = explode(';', $join->fields);
         foreach ($fieldsArray as $fiendPair) {
             $fieldPairArray = explode('|', $fiendPair);
             $realfield = $fieldPairArray[0];
             $logicfield = isset($fieldPairArray[1]) ? $fieldPairArray[1] : $realfield;
             $fields[$logicfield] = $realfield;
         }
         $template = new Z_View_Template($join->condition, array('table' => $this->z_model->info('name'), 'jointable' => $joinTableName));
         $this->z_joins[] = array('table' => $joinTableName, 'condition' => $template->render(), 'fields' => $fields);
     }
     //условия
     $modelResourceconditions = new Z_Model_Resourceconditions();
     $condidtions = $modelResourceconditions->fetchAll(array('resourceid=?' => $info->id));
     foreach ($condidtions as $condidtion) {
         $this->z_conditions[] = array('condition' => $condidtion->condition, 'value' => $condidtion->value);
     }
     //условия при наличии родительского ресурса
     if ($info->parent_field && ($parentid = $this->_getParam($info->resourceId . '_parentid'))) {
         $this->z_conditions[] = array('condition' => $this->z_model->info('name') . '.' . $info->parent_field . '=?', 'value' => $parentid);
         $this->z_addfields[$info->parent_field] = $parentid;
     }
     $modelRasourceRefers = new Z_Model_Resourcerefers();
     foreach ($modelRasourceRefers->fetchAll(array('resourceid=?' => $info->id)) as $refer) {
         $this->z_refers[$refer->field] = $refer->toArray();
     }
     //копирование параметров во вью и в атрибуты класса
     if ($info->sortable_position != 'top' && $info->sortable_position != 'bottom') {
         $info->sortable_position = 'bottom';
     }
     foreach ($fieldsToMove as $field) {
         $zField = 'z_' . $field;
         if ($this->{$zField} !== NULL) {
             $info->{$field} = $this->{$zField};
         }
         $this->{$zField} = $info->{$field};
         $this->view->{$field} = $info->{$field};
     }
     //
     //сортировка
     if ($this->z_sortable) {
         $this->z_order[] = 'orderid asc';
     } else {
         $orderArray = explode(';', $info->order);
         foreach ($orderArray as $order) {
             if ($order = trim($order)) {
                 $this->z_order[] = $order;
             }
         }
     }
     //доп кнопки вверху
     $modelButtons = new Z_Model_Resourcebuttons();
     $buttons = $modelButtons->fetchAll(array('resourceid=?' => $info->id), 'orderid');
     foreach ($buttons->toArray() as $button) {
         $button['url'] = eval($button['url']);
         $this->z_additional_buttons[] = $button;
     }
     //    	$this->z_additional_buttons = array_merge($buttons->toArray(),$this->z_additional_buttons);
     $this->view->additional_buttons = $this->z_additional_buttons;
     $modelForms = new Z_Model_Resourceforms();
     $elements = $modelForms->fetchAll(array('resourceid=?' => $this->z_resourceInfo->id, 'type=?' => 'MultiImage'));
     //ech(count($elements));
     if (count($elements)) {
         $this->view->multibutton = true;
     } else {
         $this->view->multibutton = false;
     }
 }