/** * Sync action for resource controller */ public function syncAction() { $translate = Zend_Registry::get('Zend_Translate'); try { $mdlResource = new Acl_Model_Resource(); $registeredList = $mdlResource->getRegisteredList(); #print_r($registeredList); #die(); $resourcesAvailable = array(); $sxe = new SimpleXMLElement(APPLICATION_PATH . '/../.zfproject.xml', null, true); foreach ($sxe->projectDirectory->applicationDirectory->modulesDirectory->moduleDirectory as $module) { #echo "<h1>Modulo:".$module['moduleName']."</h1>"; foreach ($module->controllersDirectory->controllerFile as $controller) { #echo "<h2>controlador: ".$controller['controllerName']."<h2>"; foreach ($controller->actionMethod as $action) { #echo "<h3>action: ".$action['actionName']."<h3>"; $resourcesAvailable[] = $module['moduleName'] . '-' . $controller['controllerName'] . '-' . $action['actionName']; } } } foreach ($resourcesAvailable as $rsa) { $isRegistered = false; foreach ($registeredList as $rsRegistered) { $rsTemp = $rsRegistered->module . '-' . $rsRegistered->controller . '-' . $rsRegistered->actioncontroller; if (strcasecmp($rsa, $rsTemp) == 0) { $isRegistered = true; } } if (!$isRegistered) { $arrResource = explode('-', $rsa); $resource = $mdlResource->createRow(); $resource->module = $arrResource[0]; $resource->controller = $arrResource[1]; $resource->actioncontroller = $arrResource[2]; $resource->save(); } } /* @var $cache Zend_Cache_Backend_File */ $cache = Zend_Registry::get('cacheACL'); $mdlRole = new Acl_Model_Role(); $roles = $mdlRole->getRoles(); foreach ($roles as $role) { if ($cache->test('cacheACL_' . $role->id)) { $cache->remove('cacheACL_' . $role->id); } } $this->_helper->flashMessenger->addMessage(array('type' => 'info', 'header' => '', 'message' => $translate->translate("ACL_RESOURCES_SYNCD"))); return $this->_helper->redirector("list", "resource", "acl"); } catch (Exception $e) { $this->_helper->flashMessenger->addMessage(array('type' => 'error', 'header' => '', 'message' => $e->getMessage())); return $this->_helper->redirector("list", "resource", "acl"); } return; }
/** * (non-PHPdoc) * @see Zend_Form::init() */ public function init() { #$this->_addClassNames('well'); $this->setMethod(Zend_Form::METHOD_POST); $this->setTranslator(); $txtName = $this->createElement('text', 'name'); $txtName->setLabel('ACL_ROLE')->setRequired(TRUE)->setAttrib('size', '40')->addValidator(new Zend_Validate_NotEmpty()); $this->addElement($txtName); $mdlRole = new Acl_Model_Role(); $roles = $mdlRole->getRoles(); $cbRole = $this->createElement("select", "parent_id"); $cbRole->setLabel("ACL_ROLE_PARENT")->setRequired(FALSE); if ($roles->count() > 0) { foreach ($roles as $role) { $cbRole->addMultiOption($role->id, $role->name); } } $this->addElement($cbRole); $mdlSkin = new System_Model_Skin(); $skin = $mdlSkin->getSkinSelected(); $skinName = is_null($skin) ? 'default' : strtolower($skin->name); $layouts = new Zend_Config_Xml(APPLICATION_PATH . '/layouts/scripts/' . $skinName . '/layouts.xml'); $layouts = $layouts->files->layout->toArray(); $cbDesktopLayout = $this->createElement("select", "desktop_layout"); $cbDesktopLayout->setLabel('LBL_DESKTOP_LAYOUT'); $cbDesktopLayout->setRequired(true); $cbMobileLayout = $this->createElement("select", "mobile_layout"); $cbMobileLayout->setLabel('LBL_MOBILE_LAYOUT'); $cbMobileLayout->setRequired(true); foreach ($layouts as $layout) { $cbDesktopLayout->addMultiOption($layout, $layout); $cbMobileLayout->addMultiOption($layout, $layout); } $this->addElement($cbDesktopLayout); $this->addElement($cbMobileLayout); $txtPriority = $this->createElement('text', 'priority'); $txtPriority->setLabel('ACL_PRIORITY')->setRequired(TRUE)->setAttrib('size', 10)->setAttrib('maxlength', 2)->addValidator(new Zend_Validate_NotEmpty()); $this->addElement($txtPriority); $id = $this->createElement('hidden', 'id'); $id->setDecorators(array('ViewHelper')); $this->addElement($id); $token = new Zend_Form_Element_Hash('token'); $token->setSalt(md5(uniqid(rand(), TRUE))); $token->setTimeout(60); $token->setDecorators(array('ViewHelper')); $this->addElement($token); $submitOptions = array('buttonType' => Twitter_Bootstrap_Form_Element_Button::BUTTON_LINK, 'type' => 'submit', 'buttonType' => 'default'); $btnSubmit = new Twitter_Bootstrap_Form_Element_Button('submit', $submitOptions); $btnSubmit->setLabel('LBL_SAVE'); $btnSubmit->removeDecorator('Label'); $btnSubmit->setDecorators(array(array('FieldSize'), array('ViewHelper'), array('Addon'), array('ElementErrors'), array('Description', array('tag' => 'p', 'class' => 'help-block')), array('HtmlTag', array('tag' => 'div', 'class' => 'controls')), array('Wrapper'))); $btnSubmit->removeDecorator('Label'); $this->addElement($btnSubmit); }
/** * (non-PHPdoc) * * @see Zend_Form::init() */ public function init() { $this->setTranslator(); // this->_addClassNames('well'); $this->setMethod(Zend_Form::METHOD_POST); $txtFullname = $this->createElement('text', 'fullname')->setLabel("LBL_FULLNAME")->setRequired(true)->setAttrib('size', 40)->addFilters(array(new Zend_Filter_StringToLower(), new Zend_Filter_StringTrim(), new Zend_Filter_Alpha(true)))->addValidators(array(new Zend_Validate_Alpha(true), new Zend_Validate_StringLength(array('min' => 5, 'max' => 200)))); $this->addElement($txtFullname); $txtEmail = $this->createElement('text', 'email')->setLabel("ACL_EMAIL")->setRequired(TRUE)->setAttrib('size', 40)->addFilters(array(new Zend_Filter_StringToLower(), new Zend_Filter_StringTrim()))->addValidator(new Zend_Validate_EmailAddress()); $txtEmail->addValidator(new Zend_Validate_Db_NoRecordExists(array('table' => 'os_acl_account', 'field' => 'email'))); $this->addElement($txtEmail); $txtEmailAlternative = $this->createElement('text', 'email_alternative')->setLabel("ACL_EMAIL_ALTERNATIVE")->setRequired(TRUE)->setAttrib('size', 40)->addFilters(array(new Zend_Filter_StringToLower(), new Zend_Filter_StringTrim()))->addValidator(new Zend_Validate_EmailAddress()); $txtEmailAlternative->addValidator(new Zend_Validate_Db_NoRecordExists(array('table' => 'os_acl_account', 'field' => 'email_alternative'))); $this->addElement($txtEmailAlternative); $txtPassword = $this->createElement('password', 'password')->setLabel('ACL_PASSWORD')->setRequired(TRUE)->setAttrib('size', 40)->addValidator(new Zend_Validate_StringLength(array('min' => '6'))); $this->addElement($txtPassword); $txtPassword2 = $this->createElement('password', 'password2')->setLabel('ACL_REPEAT_PASSWORD')->setRequired(TRUE)->setAttrib('size', 40)->addValidator('Identical', false, array('password'))->addValidator(new Zend_Validate_StringLength(array('min' => '6'))); $this->addElement($txtPassword2); $mdlRole = new Acl_Model_Role(); $roles = $mdlRole->getRoles(); $cbRole = $this->createElement("select", "role_id")->setLabel("ACL_ROLE")->setRequired(TRUE); // >addMultiOption ( 0, "LABEL_SELECT_ROLE" ); if ($roles->count() > 0) { foreach ($roles as $role) { $cbRole->addMultiOption($role->id, $role->name); } } $this->addElement($cbRole); $id = $this->createElement('hidden', 'id'); $id->setDecorators(array('ViewHelper')); $this->addElement($id); $token = new Zend_Form_Element_Hash('token'); $token->setSalt(md5(uniqid(rand(), TRUE))); $token->setTimeout(60); $token->setDecorators(array('ViewHelper')); $this->addElement($token); $submitOptions = array('buttonType' => Twitter_Bootstrap_Form_Element_Button::BUTTON_LINK, 'type' => 'submit', 'buttonType' => 'default'); $btnSubmit = new Twitter_Bootstrap_Form_Element_Button('submit', $submitOptions); $btnSubmit->setLabel('LBL_SAVE'); $btnSubmit->removeDecorator('Label'); $btnSubmit->setDecorators(array(array('FieldSize'), array('ViewHelper'), array('Addon'), array('ElementErrors'), array('Description', array('tag' => 'p', 'class' => 'help-block')), array('HtmlTag', array('tag' => 'div', 'class' => 'controls')), array('Wrapper'))); $btnSubmit->removeDecorator('Label'); $this->addElement($btnSubmit); }