/** * Should handle execution of the task, taking as much (optional) parameters as needed * * The parameters should be optional and failing to provide them should be handled by * the task */ public function execute() { $role = \Gems_Roles::getInstance(); $parents = $this->db->fetchPairs("SELECT grl_id_role, grl_parents FROM gems__roles"); // \MUtil_Echo::track($parents); if ($parents) { foreach ($parents as $id => $priv) { $values['grl_parents'] = implode(',', $role->translateToRoleIds($priv)); $this->db->update('gems__roles', $values, $this->db->quoteInto('grl_id_role = ?', $id)); } } }
/** * Perform some actions to the data before it is saved to the database */ protected function beforeSave() { if (isset($this->formData['grl_parents']) && !is_array($this->formData['grl_parents'])) { $this->formData['grl_parents'] = explode(',', $this->formData['grl_parents']); } if (isset($this->formData['grl_parents']) && is_array($this->formData['grl_parents'])) { $this->formData['grl_parents'] = implode(',', \Gems_Roles::getInstance()->translateToRoleIds($this->formData['grl_parents'])); } //Always add nologin privilege to 'nologin' role if (isset($this->formData['grl_name']) && $this->formData['grl_name'] == 'nologin') { $this->formData['grl_privileges'][] = 'pr.nologin'; } elseif (isset($this->formData['grl_name']) && $this->formData['grl_name'] !== 'nologin') { //Assign islogin to all other roles $this->formData['grl_privileges'][] = 'pr.islogin'; } if (isset($this->formData['grl_privileges'])) { $this->formData['grl_privileges'] = implode(',', $this->formData['grl_privileges']); } }
/** * Static acces function * * @return \Gems_Roles */ public static function getInstance() { if (!isset(self::$_instanceOfSelf)) { $c = __CLASS__; self::$_instanceOfSelf = new $c(); } return self::$_instanceOfSelf; }
/** * Output of not allowed for viewing rols * * @param strong $data parents tab privileges * @return \MUtil_Html_ListElement */ public function formatNotAllowed($data) { list($parents_string, $privileges_string) = explode("\t", $data, 2); $parents = explode(',', $parents_string); $privileges = explode(',', $privileges_string); if (count($privileges) > 0) { $privileges = array_combine($privileges, $privileges); } // Concatenated field, we can not use onload so handle translation here $parents = \Gems_Roles::getInstance()->translateToRoleNames($parents); $notAllowed = $this->getUsedPrivileges(); $notAllowed = array_diff_key($notAllowed, $this->getInheritedPrivileges($parents), $privileges); $output = $this->formatPrivileges(array_keys($notAllowed)); $output->class = 'notallowed deleted'; return $output; }