/** * Определяем массив опций и дергаем родительский конструктор * * @param mixed $spec * @param array $options */ public function __construct($spec, $options = null) { require_once "Phorm/Widget.php"; $translate = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('Translate'); $Widget = new Phorm_Widget(); $Widgets = array(null => $translate->_('---Выберите---')) + $Widget->getWidgetsSetsList(); $options['multioptions'] = $Widgets; parent::__construct($spec, $options); }
/** * Returns the field as serialized HTML. * * @param mixed $value the form widget's value attribute * @param array $attributes key=>value pairs corresponding to HTML attributes' name=>value * @return string the serialized HTML */ protected function serialize($value, array $attributes = array()) { $attributes['type'] = 'radio'; if ($this->checked) { $attributes['checked'] = 'checked'; } return parent::serialize($value, $attributes); }
/** * Диалоговое окно для добавления/редактирования виджетов * * @return void */ public function dialogAction() { $this->_params['iframe'] = true; $this->_boot->jquery->addJavascriptFile($this->view->baseUrl() . '/ui/js/jquery.json.min.js'); if (isset($this->_params['layout'])) { /** * Если нам известен тип виджета, то добавляем форму редактирования виджета */ if (isset($this->_params['typeid']) && ($TypeInfo = $this->Widget->getWidgetTypeInfo($this->_params['typeid']))) { $form = $this->Widget->getWidgetForm('edit', $TypeInfo); $form->setDefaults(array('typeid' => $this->_params['typeid'])); if ($this->_request->isPost()) { if ($form->isValid($this->_request->getPost())) { $FormData = $form->getValues(); unset($FormData['separator']); // @todo Надо описать, что в виджетах запрещена опция separator /** * @todo Надо как-то абстрагироваться от имени js-переменной WidgetsLayouts либо как-то ее определять глобально * @see Phorm_JQuery_View_Helper_SelectWidgetsLayout */ $position = isset($this->_params['position']) ? $this->_params['position'] : -1; $js = "window.parent.frames[0].WidgetsLayouts.getWidgetValues('" . $this->_params['layout'] . "'," . $position . ",\"" . addslashes(Zend_Json_Encoder::encode($FormData)) . "\");"; $this->_boot->jquery->addOnLoad($js); } } elseif (isset($this->_params['position'])) { /** * @todo Надо как-то абстрагироваться от имени js-переменной WidgetsLayouts либо как-то ее определять глобально * @see Phorm_JQuery_View_Helper_SelectWidgetsLayout */ $js = "window.parent.frames[0].WidgetsLayouts.setWidgetValues('" . $this->_params['layout'] . "'," . $this->_params['position'] . ",\$('form:first'));"; $this->_boot->jquery->addOnLoad($js); } $this->view->assign('Form', $form); /** * Если тип виджета неизвестен, то добавляем форму создания виджета (селект типа виджета) */ } else { $form = $this->Widget->getWidgetForm('add'); $this->view->assign('Form', $form); } } else { $this->view->assign('Errors', array($this->_translate->_('Не выбран макет отображения'))); } }
/** * Returns the field as serialized HTML. * * @param mixed $value the form widget's value attribute * @param array $attributes key=>value pairs corresponding to HTML attributes' name=>value * @return string the serialized HTML */ protected function serialize($value, array $attributes = array()) { $attributes['type'] = 'text'; return parent::serialize($value, $attributes); }
/** * Returns the field as serialized HTML. * * @param mixed $value the form widget's value attribute * @param array $attributes key=>value pairs corresponding to HTML attributes' name=>value * @return string the serialized HTML */ protected function serialize($value, array $attributes = array()) { $attributes['type'] = 'file'; $attributes['accept'] = implode(',', $this->types); return parent::serialize($value, $attributes); }
/** * Returns the button as serialized HTML. * * @param mixed $value the form widget's value attribute * @param array $attributes key=>value pairs corresponding to HTML attributes' name=>value * @return string the serialized HTML */ protected function serialize($value, array $attributes = array()) { $attributes['type'] = 'button'; $attributes['onclick'] = 'window.location.href=\'' . str_replace("'", "\\'", $this->url) . '\''; return parent::serialize($value, $attributes); }
/** * Сохранение данных о группе * * @param array $data Массив данных для сохранения * * @return array Массив данных о группе */ public function saveRoleInfo($data) { /** * Выделяем из массива данных поля для вставки в основную таблицу pw_roles */ $maindata = $this->getFilteredValuesByTableCols('pw_roles', $data); /** * Сохранение данных */ $this->_db->beginTransaction(); try { /** * Гостевая, административная группа и группа по умолчанию должны быть в единственном кол-ве */ foreach (array('isdefault', 'isguest', 'isadmin') as $role) { if (isset($maindata[$role]) && $maindata[$role] == 'yes') { $this->_db->update('pw_roles', array($role => 'no')); } } /*if(isset($maindata['isdefault']) && $maindata['isdefault']=='yes') { $this->_db->update('pw_roles',array('isdefault'=>'no')); } if(isset($maindata['isguest']) && $maindata['isguest']=='yes') { $this->_db->update('pw_roles',array('isguest'=>'no')); } if(isset($maindata['isadmin']) && $maindata['isadmin']=='yes') { $this->_db->update('pw_roles',array('isadmin'=>'no')); }*/ /** * Сохранение данных */ if (isset($data['roleid'])) { // Обновление существующей записи $this->_db->update('pw_roles', $maindata, 'roleid=' . (int) $data['roleid']); $action = 'update'; } else { // Создание новой записи $this->_db->insert('pw_roles', $maindata); $data['roleid'] = $this->_db->lastInsertId(); $action = 'insert'; } /** * Права доступа к разделам */ if (isset($data['acl_categories']) && is_int($data['acl_categories'])) { $this->_db->delete('pw_categories_acl', 'roleid=' . (int) $data['roleid']); $Categories = new Phorm_Categories(); foreach ($Categories->getFullList() as $category) { $this->_db->insert('pw_categories_acl', array('categoryid' => $category['categoryid'], 'roleid' => $data['roleid'], 'accesslevel' => $data['acl_categories'])); } } /** * Права доступа к виджетам * @todo Сделать в виджетах методы типа pack и unpack */ if (isset($data['acl_widgets']) && in_array($data['acl_widgets'], array('yes', 'no'))) { $Widget = new Phorm_Widget(); foreach ($Widget->getWidgetsSetsFullList() as $set) { if (!empty($set['widgets']) && ($widgets = Zend_Json::decode($set['widgets']))) { foreach ($widgets as $layoutname => $layout) { foreach ($layout as $i => $widget) { $widget = Zend_Json::decode($widget); $aclid = array_search($data['roleid'], $widget['acl']); if ($aclid !== false) { unset($widget['acl'][$aclid]); } if ($data['acl_widgets'] == 'yes') { $widget['acl'][] = $data['roleid']; } $widget['acl'] = array_values($widget['acl']); $widgets[$layoutname][$i] = Zend_Json::encode($widget); } } $this->_db->update('pw_widgets_sets', array('widgets' => Zend_Json::encode($widgets)), 'setid=' . (int) $set['setid']); } } } /** * Логирование */ $this->setLog($action, array('url' => '/control/users/roleedit/roleid/' . (int) $data['roleid'] . '/', 'name' => $data['rolename'], 'tablename' => 'pw_roles', 'identity' => (int) $data['roleid'], 'fieldname' => 'roleid')); $this->_db->commit(); return $data; } catch (Exception $e) { $this->_db->rollBack(); $this->_errors[] = $e->getMessage(); } return false; }