/** * test preconditions * @param * @return */ public function testConditions() { include_once './Services/AccessControl/classes/class.ilConditionHandler.php'; ilConditionHandler::_getDistinctTargetRefIds(); ilConditionHandler::_deleteTargetConditionsByRefId(1); $handler = new ilConditionHandler(); $handler->setTargetRefId(99999); $handler->setTargetObjId(99998); $handler->setTargetType('xxx'); $handler->setTriggerRefId(99997); $handler->setTriggerObjId(99996); $handler->setTriggerType('yyy'); $handler->setReferenceHandlingType(0); $handler->enableAutomaticValidation(false); $suc = $handler->storeCondition(); $this->assertEquals($suc, true); $suc = $handler->checkExists(); $this->assertEquals($suc, false); $suc = $handler->delete(99999); $this->assertEquals($suc, true); // syntax check $handler->deleteByObjId(-1); $handler->deleteCondition(-1); ilConditionHandler::_getConditionsOfTrigger(-1, -1); ilConditionHandler::_getConditionsOfTarget(-1, -1); ilConditionHandler::_getCondition(-1); }
/** * checks wether a single condition is fulfilled * every trigger object type must implement a static method * _checkCondition($a_operator, $a_value) */ function _checkCondition($a_id, $a_usr_id = 0) { global $ilUser; $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId(); $condition = ilConditionHandler::_getCondition($a_id); switch ($condition['trigger_type']) { case "tst": include_once './Modules/Test/classes/class.ilObjTestAccess.php'; return ilObjTestAccess::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id); case "crs": include_once './Modules/Course/classes/class.ilObjCourse.php'; return ilObjCourse::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id); case 'exc': include_once './Modules/Exercise/classes/class.ilObjExercise.php'; return ilObjExercise::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id); case 'crsg': include_once './Modules/Course/classes/class.ilObjCourseGrouping.php'; return ilObjCourseGrouping::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id); case 'sahs': include_once './Services/Tracking/classes/class.ilLPStatus.php'; return ilLPStatus::_lookupStatus($condition['trigger_obj_id'], $a_usr_id) == LP_STATUS_COMPLETED_NUM; case 'svy': include_once './Modules/Survey/classes/class.ilObjSurvey.php'; return ilObjSurvey::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id); default: return false; } }
/** * Init form for condition table * * @access private * @param * */ private function initFormCondition($a_source_id, $a_condition_id = 0, $a_mode = 'add') { $trigger_obj_id = ilObject::_lookupObjId($a_source_id); $trigger_type = ilObject::_lookupType($trigger_obj_id); $condition = ilConditionHandler::_getCondition($a_condition_id); if (is_object($this->form)) { return true; } include_once 'Services/Form/classes/class.ilPropertyFormGUI.php'; $this->form = new ilPropertyFormGUI(); $this->ctrl->setParameter($this, 'source_id', $a_source_id); $this->form->setFormAction($this->ctrl->getFormAction($this)); $info_source = new ilNonEditableValueGUI($this->lng->txt("rbac_precondition_source")); $info_source->setValue(ilObject::_lookupTitle(ilObject::_lookupObjId($a_source_id))); $this->form->addItem($info_source); $info_target = new ilNonEditableValueGUI($this->lng->txt("rbac_precondition_target")); $info_target->setValue($this->getTargetTitle()); $this->form->addItem($info_target); /* moved to list $obl = new ilCheckboxInputGUI($this->lng->txt('precondition_obligatory'), 'obligatory'); $obl->setInfo($this->lng->txt('precondition_obligatory_info')); $obl->setValue(1); if($a_condition_id) { $obl->setChecked($condition['obligatory']); } else { $obl->setChecked(true); } $this->form->addItem($obl); */ $obl = new ilHiddenInputGUI('obligatory'); if ($a_condition_id) { $obl->setValue($condition['obligatory']); } else { $obl->setValue(1); } $this->form->addItem($obl); $sel = new ilSelectInputGUI($this->lng->txt('condition'), 'operator'); include_once "./Services/AccessControl/classes/class.ilConditionHandler.php"; $ch_obj = new ilConditionHandler(); if ($a_mode == 'add') { $operators[0] = $this->lng->txt('select_one'); } foreach ($ch_obj->getOperatorsByTargetType($trigger_type) as $operator) { $operators[$operator] = $this->lng->txt('condition_' . $operator); } $sel->setValue(isset($condition['operator']) ? $condition['operator'] : 0); $sel->setOptions($operators); $sel->setRequired(true); $this->form->addItem($sel); if (ilConditionHandler::_isReferenceHandlingOptional($this->getTargetType())) { $rad_opt = new ilRadioGroupInputGUI($this->lng->txt('cond_ref_handling'), 'ref_handling'); $rad_opt->setValue(isset($condition['ref_handling']) ? $condition['ref_handling'] : ilConditionHandler::SHARED_CONDITIONS); $opt2 = new ilRadioOption($this->lng->txt('cond_ref_shared'), ilConditionHandler::SHARED_CONDITIONS); $rad_opt->addOption($opt2); $opt1 = new ilRadioOption($this->lng->txt('cond_ref_unique'), ilConditionHandler::UNIQUE_CONDITIONS); $rad_opt->addOption($opt1); $this->form->addItem($rad_opt); } // Additional settings for SCO's if ($trigger_type == 'sahs') { $this->lng->loadLanguageModule('trac'); $cus = new ilCustomInputGUI($this->lng->txt('trac_sahs_relevant_items'), 'item_ids[]'); $cus->setRequired(true); $tpl = new ilTemplate('tpl.condition_handler_sco_row.html', true, true, "Services/AccessControl"); $counter = 0; include_once 'Services/Object/classes/class.ilObjectLP.php'; $olp = ilObjectLP::getInstance($trigger_obj_id); $collection = $olp->getCollectionInstance(); if ($collection) { foreach ($collection->getPossibleItems() as $item_id => $sahs_item) { $tpl->setCurrentBlock("sco_row"); $tpl->setVariable('SCO_ID', $item_id); $tpl->setVariable('SCO_TITLE', $sahs_item['title']); $tpl->setVariable('CHECKED', $collection->isAssignedEntry($item_id) ? 'checked="checked"' : ''); $tpl->parseCurrentBlock(); $counter++; } } $tpl->setVariable('INFO_SEL', $this->lng->txt('trac_lp_determination_info_sco')); $cus->setHTML($tpl->get()); $this->form->addItem($cus); } switch ($a_mode) { case 'edit': $this->form->setTitleIcon(ilUtil::getImagePath('icon_' . $this->getTargetType() . '.svg')); $this->form->setTitle($this->lng->txt('rbac_edit_condition')); $this->form->addCommandButton('updateCondition', $this->lng->txt('save')); $this->form->addCommandButton('listConditions', $this->lng->txt('cancel')); break; case 'add': $this->form->setTitleIcon(ilUtil::getImagePath('icon_' . $this->getTargetType() . '.svg')); $this->form->setTitle($this->lng->txt('add_condition')); $this->form->addCommandButton('assign', $this->lng->txt('save')); $this->form->addCommandButton('selector', $this->lng->txt('back')); break; } return true; }
/** * checks wether a single condition is fulfilled * every trigger object type must implement a static method * _checkCondition($a_operator, $a_value) */ function _checkCondition($a_id, $a_usr_id = 0) { global $ilUser, $objDefinition; $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId(); $condition = ilConditionHandler::_getCondition($a_id); // check lp if ($condition['operator'] == self::OPERATOR_LP) { include_once './Services/Tracking/classes/class.ilLPStatus.php'; return ilLPStatus::_hasUserCompleted($condition['trigger_obj_id'], $a_usr_id); } switch ($condition['trigger_type']) { case 'crsg': include_once './Modules/Course/classes/class.ilObjCourseGrouping.php'; return ilObjCourseGrouping::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id); } $class = $objDefinition->getClassName($condition['trigger_type']); $location = $objDefinition->getLocation($condition['trigger_type']); $full_class = "ilObj" . $class . "Access"; include_once $location . "/class." . $full_class . ".php"; $fullfilled = call_user_func(array($full_class, 'checkCondition'), $condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id); return $fullfilled; }