/** * Init form */ protected function initForm() { $this->setFormAction($this->ctrl->getFormAction($this->parent_gui)); $title = $this->isNew ? $this->pl->txt('add_new_type') : $this->pl->txt('edit_type'); $this->setTitle($title); $item = new ilTextInputGUI($this->lng->txt('title'), 'title'); $item->setRequired(true); $item->setValue($this->type->getTitle()); $this->addItem($item); $item = new ilTextAreaInputGUI($this->lng->txt('description'), 'description'); $item->setValue($this->type->getDescription()); $this->addItem($item); $item = new ilMultiSelectInputGUI($this->lng->txt('languages'), 'languages'); $item->setWidth(self::WIDTH_MULTISELECT_INPUT); $langs = $this->lng->getInstalledLanguages(); $options = array(); foreach ($langs as $lang_code) { $options[$lang_code] = $this->lng->txt("meta_l_{$lang_code}"); } $item->setOptions($options); $item->setValue($this->type->getLanguages()); $item->setRequired(true); $this->addItem($item); $item = new ilMultiSelectInputGUI($this->lng->txt('roles'), 'roles'); $item->setWidth(self::WIDTH_MULTISELECT_INPUT); $roles = $this->rbac->getRolesByFilter(ilRbacReview::FILTER_ALL, 0, ''); $options = array(); $hide_roles = array(14, 5); foreach ($roles as $role) { if (strpos($role['title'], 'il_') === 0 || in_array($role['obj_id'], $hide_roles)) { // Don't show auto-generated roles. If this takes to much performance, write query... continue; } $options[$role['obj_id']] = $role['title']; } $item->setOptions($options); $item->setValue($this->type->getRoles()); $item->setInfo($this->pl->txt('roles_info')); $this->addItem($item); $item = new ilMultiSelectInputGUI($this->pl->txt('available_objects'), 'available_objects'); $item->setWidth(self::WIDTH_MULTISELECT_INPUT); $options = array(); foreach (srCertificateType::getAllAvailableObjectTypes() as $type) { $options[$type] = $type; } $item->setOptions($options); $item->setValue($this->type->getAvailableObjects()); $item->setRequired(true); $item->setInfo($this->pl->txt('available_objects_info')); $this->addItem($item); $this->addCommandButton('saveType', $this->lng->txt('save')); }
/** * Check if a given user is allowed to select a given certificate type to create a new definition for the given ref_id. * This method checks the following steps: * 1) Is the type restricted to certain object types, e.g. is the object type of the given ref_id valid? * 2) Is the type restricted to certain roles, e.g. check if the a user has at least one role * * @param srCertificateType $type * @param $ref_id * @param int $user_id If empty, the current user is used * @return bool */ public static function isSelectable(srCertificateType $type, $ref_id, $user_id = 0) { global $ilUser, $rbacreview; $user_id = $user_id ? $user_id : $ilUser->getId(); $pl = ilCertificatePlugin::getInstance(); $object_type = $pl->isCourseTemplate($ref_id) ? 'crs-tpl' : ilObject::_lookupType($ref_id, true); if (!in_array($object_type, $type->getAvailableObjects())) { return false; } // Access restricted by roles. Check if current user has a role to choose the type if (count($type->getRoles()) && !$rbacreview->isAssignedToAtLeastOneGivenRole($user_id, $type->getRoles())) { return false; } return true; }