public function init() { $resources = new Model_Resources(); $resources->form_values['only_childs'] = 1; $result2 = $resources->getResources('resource_name', 'ASC'); $this->_list["page_name"][''] = "Select"; if ($result2) { foreach ($result2 as $row2) { $resource = $row2->getResourceName(); $arr_resources = explode("/", $resource); $second_name = !empty($arr_resources[1]) ? ucfirst($arr_resources[1]) . " - " : ""; $this->_list["page_name"][$row2->getPkId()] = ucfirst($arr_resources[0]) . " - " . $second_name . $row2->getDescription(); } } foreach ($this->_fields as $col => $name) { switch ($col) { case "description": $this->addElement("textarea", $col, array("attribs" => array("class" => "form-control", "rows" => "4"), "allowEmpty" => false, "filters" => array("StringTrim", "StripTags"), "validators" => array())); $this->getElement($col)->removeDecorator("Label")->removeDecorator("HtmlTag"); break; default: break; } if (in_array($col, array_keys($this->_list))) { $this->addElement("select", $col, array("attribs" => array("class" => "form-control"), "filters" => array("StringTrim", "StripTags"), "allowEmpty" => true, "required" => false, "registerInArrayValidator" => false, "multiOptions" => $this->_list[$col], "validators" => array())); $this->getElement($col)->removeDecorator("Label")->removeDecorator("HtmlTag"); } if (in_array($col, array_keys($this->_radio))) { $this->addElement("radio", $col, array("attribs" => array(), "allowEmpty" => true, 'separator' => '', "filters" => array("StringTrim", "StripTags"), "validators" => array(), "multiOptions" => $this->_radio[$col])); $this->getElement($col)->removeDecorator("Label")->removeDecorator("HtmlTag")->removeDecorator("<br>"); } } }
public function init() { $roles = new Model_Roles(); $result = $roles->getRoles(); if ($result) { foreach ($result as $row) { $this->_list["role"][$row->getPkId()] = $row->getRoleName(); } } $resources = new Model_Resources(); $result2 = $resources->getAllResources(); if ($result2) { foreach ($result2 as $row2) { $resource = $row2->getResourceName(); $arr_resources = explode("/", $resource); $second_name = !empty($arr_resources[1]) ? ucfirst($arr_resources[1]) . " - " : ""; $this->_list["resource"][$row2->getPkId()] = ucfirst($arr_resources[0]) . " - " . $second_name . $row2->getDescription(); } } foreach ($this->_fields as $col => $name) { if (in_array($col, array_keys($this->_list))) { $this->addElement("select", $col, array("attribs" => array("class" => "form-control"), "filters" => array("StringTrim", "StripTags"), "allowEmpty" => true, "required" => false, "registerInArrayValidator" => false, "multiOptions" => $this->_list[$col], "validators" => array())); $this->getElement($col)->removeDecorator("Label")->removeDecorator("HtmlTag"); } } }
public function load_resources() { $res_selects = array(); foreach (Model_Resources::getInstance()->find_all(Model_Resources::getInstance()->table()->idField()) as $res) { error_log(__METHOD__ . ': loading resource ' . $res->identity()); $spec = array('label' => $res->title); $res_name = 'resource_' . $res->identity(); $res_selects[] = $res_name; $spec['name'] = $res_name; $spec['multiOptions'] = self::$res_options; $select = new Zend_Form_Element_Select($spec); $domain = $this->get_domain(); if ($domain && $domain->isSaved()) { if ($value = Model_Acl::find_acl($res, $domain)) { error_log(__METHOD__ . ': value = ' . $value); $select->setValue($value); } else { error_log(__METHOD__ . ': no value for res = ' . $res->identity() . ', role = ' . $domain->identity()); } } else { error_log(__METHOD__ . ': domain not saved'); } $this->addElement($select); } }
private function _load(Administer_Model_Modules $m) { try { $load_data = $m->get_load(); if ($load_data) { foreach ($load_data as $class => $options) { switch ($class) { case 'resource': case 'resources': Model_Resources::getInstance()->add_resources($options, $m->folder, $m->is_active()); break; case 'route': case 'routes': Model_Zupalroutes::getInstance()->add_routes($options, $m->folder, $m->is_active()); break; default: throw new Exception("can't load resource {$class}"); } } } $m->resource_loaded = TRUE; $m->save(); } catch (Exception $e) { error_log(__METHOD__ . ': error loading ' . $m->folder); throw $e; } }
public function indexAction() { $form = new Form_Iadmin_ResourceSearch(); $form_add = new Form_Iadmin_Resources(); $params = array(); $resources = new Model_Resources(); if ($this->_request->isPost()) { if ($form->isValid($this->_request->getPost())) { $resource_name = $form->getValue('resource_name'); $resource_type = $form->getValue('resource_type'); if (!empty($resource_name)) { $params['resourceName'] = $resource_name; } if (!empty($resource_type)) { $params['resourceType'] = $resource_type; } } } else { $resource_name = $this->_getParam('resource_name'); $resource_type = $this->_getParam('resource_type'); if (!empty($resource_name)) { $params['resourceName'] = $resource_name; $form->resource_name->setValue($resource_name); } if (!empty($resource_type)) { $params['resourceType'] = $resource_type; $form->resource_type->setValue($resource_type); } } $sort = $this->_getParam("sort", "asc"); $order = $this->_getParam("order", "resource_name"); $resources->form_values = $params; $result = $resources->getResources($order, $sort); //Paginate the contest results $paginator = Zend_Paginator::factory($result); $page = $this->_getParam("page", 1); $counter = $this->_getParam("counter", 10); $paginator->setCurrentPageNumber((int) $page); $paginator->setItemCountPerPage((int) $counter); $this->view->form = $form; $this->view->form_add = $form_add; $this->view->paginator = $paginator; $this->view->sort = $sort; $this->view->order = $order; $this->view->counter = $counter; $this->view->pagination_params = $params; }
public function init() { $em = Zend_Registry::get("doctrine"); $result = $em->getRepository("ResourceTypes")->findAll(); $this->_list["resource_type"][''] = "Select"; foreach ($result as $rs) { $this->_list["resource_type"][$rs->getPkId()] = $rs->getResourceType(); } $resources = new Model_Resources(); $result2 = $resources->getResources('resource_name', 'ASC'); $this->_list["parent_id"][''] = "Select"; if ($result2) { foreach ($result2 as $row2) { $resource = $row2->getResourceName(); $arr_resources = explode("/", $resource); $second_name = !empty($arr_resources[1]) ? ucfirst($arr_resources[1]) . " - " : ""; $this->_list["parent_id"][$row2->getPkId()] = ucfirst($arr_resources[0]) . " - " . $second_name . $row2->getDescription(); } } for ($a = 1; $a <= 20; $a++) { $this->_list["rank"][$a] = $a; } for ($b = 1; $b <= 10; $b++) { $this->_list["level"][$b] = $b; } foreach ($this->_fields as $col => $name) { switch ($col) { case "resource_name": case "description": case "page_title": case "meta_title": $this->addElement("text", $col, array("attribs" => array("class" => "form-control"), "allowEmpty" => false, "filters" => array("StringTrim", "StripTags"), "validators" => array())); $this->getElement($col)->removeDecorator("Label")->removeDecorator("HtmlTag"); break; case "meta_desc": $this->addElement("textarea", $col, array("attribs" => array("class" => "form-control", "rows" => "4"), "allowEmpty" => false, "filters" => array("StringTrim", "StripTags"), "validators" => array())); $this->getElement($col)->removeDecorator("Label")->removeDecorator("HtmlTag"); break; default: break; } if (in_array($col, array_keys($this->_list))) { $this->addElement("select", $col, array("attribs" => array("class" => "form-control"), "filters" => array("StringTrim", "StripTags"), "allowEmpty" => true, "required" => false, "registerInArrayValidator" => false, "multiOptions" => $this->_list[$col], "validators" => array())); $this->getElement($col)->removeDecorator("Label")->removeDecorator("HtmlTag"); } } }
/** * * @param boolean $pReload * @return Model_Resources */ public static function getInstance($pReload = FALSE) { if ($pReload || is_null(self::$_Instance)) { // process self::$_Instance = new self(); } return self::$_Instance; }
/** * * @return <type> */ protected function _init_resources_menu() { foreach (Model_Resources::getInstance()->findAll('resource_id') as $resource) { $this->resource->addMultiOption($resource->identity(), $resource->title); } }
/** * * @param boolean $pReload * @return Zend_Acl */ public static function acl($pReload = FALSE) { if ($pReload || is_null(self::$_acl)) { $acl = new Zend_Acl(); foreach (Model_Resources::getInstance()->find_all() as $res) { $acl->add($res); } foreach (Model_Roles::getInstance()->find_all() as $role) { $acl->addRole($role); } foreach (self::getInstance()->find_all() as $grant) { if ($grant->allow) { $acl->allow($grant->role, $grant->resource); } else { $acl->deny($grant->role, $grant->resource); } } self::$_acl = $acl; } return self::$_acl; }
public function roleResourcesAction() { $form = new Form_Iadmin_RoleComboSearch(); $form_add = new Form_Iadmin_RoleResource(); $params = array(); $rr = new Model_Resources(); $roles = new Model_Roles(); if ($this->_request->isPost()) { if ($form->isValid($this->_request->getPost())) { $role_name = $form->getValue('role'); $description = $form->getValue('description'); $resource_name = $form->getValue('resource_name'); $resource_type = $form->getValue('resource_type'); if (!empty($role_name)) { $params['role'] = $role_name; } if (!empty($description)) { $params['description'] = $description; } if (!empty($resource_name)) { $params['resourceName'] = $resource_name; } if (!empty($resource_type)) { $params['resourceType'] = $resource_type; } } } else { $role_name = $this->_getParam('role', ''); $description = $this->_getParam('description'); $resource_name = $this->_getParam('resource_name'); $resource_type = $this->_getParam('resource_type'); if (!empty($role_name)) { $params['role'] = $role_name; $form->role->setValue($role_name); } if (!empty($description)) { $params['description'] = $description; $form->description->setValue($description); } if (!empty($resource_name)) { $params['resourceName'] = $resource_name; $form->resource_name->setValue($resource_name); } if (!empty($resource_type)) { $params['resourceType'] = $resource_type; $form->resource_type->setValue($resource_type); } } //App_Controller_Functions::pr($params); $rr->form_values = $params; // var_dump($params); $result = $rr->getAllResources(); $roles->form_values['role'] = $params['role']; $role_result = $roles->getAllRolesResources(); $this->view->roles = $role_result; $this->view->form = $form; $this->view->form_add = $form_add; $this->view->paginator = $result; $this->view->pagination_params = $params; }
/** * * * @return void */ public function load_resources() { $options = array(0 => '(none)'); foreach (Model_Resources::getInstance()->find_all() as $res) { $options[$res->identity()] = $res->title; } $this->resource->setMultiOptions($options); }
/** * */ public function roleseditexecuteAction() { $id = $this->_getParam('role_id'); $params = array('role_id' => $id); $form = new Administer_Form_Zupalroles($id); if ($form->isValid($this->_getAllParams())) { $form->save(); foreach (Model_Resources::getInstance()->findAll() as $res) { $resid = $res->identity(); if ($resvalue = $this->_getParam("resource_{$resid}")) { Model_Acl::getInstance()->set_acl($resid, $id, $resvalue); } } $params['message'] = 'Role Saved'; } else { $params['error'] = 'Cannot save form'; $params['reload'] = TRUE; $params = array_merge($this->_getAllParams(), $params); } $this->_forward('rolesedit', 'users', 'administer', $params); }
/** * * @return <type> */ protected function _init_resources_menu() { $options = Model_Resources::getInstance()->as_list('(none)'); $this->resource->set_data_source($options); }