function __construct($sid, $variables = array(), $options = array()) { $model = new Z_Model_Mails(); $mail = $model->fetchRow(array('sid=?' => $sid)); if (!$mail) { throw new Exception('Для ключа "' . $sid . '" не найден наблон письма.'); } $this->set($mail->toArray()); foreach ($this->get() as $key => $val) { $tpl = new Z_View_Template($val, $variables); $this->set($key, $tpl->render()); unset($tpl); } $this->set($options); }
/** * Устанавливает все настройки контроллера на основании информации о ресурсе */ 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; } }
public function template($template = "", $values = array()) { $renderer = new Z_View_Template($template, $values); return $renderer->render(); }