protected function parseConditions($toggle_id, $conditions, $obligatory = true) { global $ilAccess, $lng, $objDefinition, $tree; $num_required = ilConditionHandler::calculateRequiredTriggers($this->ref_id, $this->obj_id); $num_optional_required = $num_required - count($conditions) + count(ilConditionHandler::getOptionalConditionsOfTarget($this->ref_id, $this->obj_id)); // Check if all conditions are fullfilled $visible_conditions = array(); $passed_optional = 0; foreach ($conditions as $condition) { if ($obligatory and !$condition['obligatory']) { continue; } if (!$obligatory and $condition['obligatory']) { continue; } if ($tree->isDeleted($condition['trigger_ref_id'])) { continue; } include_once 'Services/Container/classes/class.ilMemberViewSettings.php'; $ok = ilConditionHandler::_checkCondition($condition['id']) and !ilMemberViewSettings::getInstance()->isActive(); if (!$ok) { $visible_conditions[] = $condition['id']; } if (!$obligatory and $ok) { ++$passed_optional; // optional passed if ($passed_optional >= $num_optional_required) { return true; } } } foreach ($conditions as $condition) { if (!in_array($condition['id'], $visible_conditions)) { continue; } include_once './Services/AccessControl/classes/class.ilConditionHandlerGUI.php'; $cond_txt = ilConditionHandlerGUI::translateOperator($condition['trigger_obj_id'], $condition['operator']) . ' ' . $condition['value']; // display trigger item $class = $objDefinition->getClassName($condition["trigger_type"]); $location = $objDefinition->getLocation($condition["trigger_type"]); if ($class == "" && $location == "") { continue; } $missing_cond_exist = true; $full_class = "ilObj" . $class . "ListGUI"; include_once $location . "/class." . $full_class . ".php"; $item_list_gui = new $full_class($this); $item_list_gui->setMode(IL_LIST_AS_TRIGGER); $item_list_gui->enablePath(false); $item_list_gui->enableIcon(true); $item_list_gui->setConditionDepth($this->condition_depth + 1); $item_list_gui->setParentRefId($this->getUniqueItemId()); // yes we can $item_list_gui->addCustomProperty($this->lng->txt("precondition_required_itemlist"), $cond_txt, false, true); $item_list_gui->enableCommands($this->commands_enabled, $this->std_cmd_only); $item_list_gui->enableProperties($this->properties_enabled); $trigger_html = $item_list_gui->getListItemHTML($condition['trigger_ref_id'], $condition['trigger_obj_id'], ilObject::_lookupTitle($condition["trigger_obj_id"]), ""); $this->tpl->setCurrentBlock("precondition"); if ($trigger_html == "") { $trigger_html = $this->lng->txt("precondition_not_accessible"); } $this->tpl->setVariable("TXT_CONDITION", trim($cond_txt)); $this->tpl->setVariable("TRIGGER_ITEM", $trigger_html); $this->tpl->parseCurrentBlock(); } if ($missing_cond_exist and $obligatory) { $this->tpl->setCurrentBlock("preconditions"); $this->tpl->setVariable("CONDITION_TOGGLE_ID", "_obl_" . $toggle_id); $this->tpl->setVariable("TXT_PRECONDITIONS", $lng->txt("preconditions_obligatory_hint")); $this->tpl->parseCurrentBlock(); } elseif ($missing_cond_exist and !$obligatory) { $this->tpl->setCurrentBlock("preconditions"); $this->tpl->setVariable("CONDITION_TOGGLE_ID", "_opt_" . $toggle_id); $this->tpl->setVariable("TXT_PRECONDITIONS", sprintf($lng->txt("preconditions_optional_hint"), $num_optional_required)); $this->tpl->parseCurrentBlock(); } return !$missing_cond_exist; }
/** * get top chapter of page for that any precondition is missing */ function _getMissingPreconditionsTopChapter($cont_obj_ref_id, $cont_obj_id, $page_id) { $lm_tree = new ilTree($cont_obj_id); $lm_tree->setTableNames('lm_tree', 'lm_data'); $lm_tree->setTreeTablePK("lm_id"); $conds = array(); if ($lm_tree->isInTree($page_id)) { // get full path of page $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId()); foreach ($path as $node) { if ($node["type"] == "st") { // get all preconditions of upper chapters $tconds = ilConditionHandler::_getConditionsOfTarget($cont_obj_ref_id, $node["child"], "st"); foreach ($tconds as $tcond) { // look for missing precondition if (!ilConditionHandler::_checkCondition($tcond["id"])) { return $node["child"]; } } } } } return ""; }
/** * checks wether all conditions of a target object are fulfilled */ function _checkAllConditionsOfTarget($a_target_ref_id, $a_target_id, $a_target_type = "", $a_usr_id = 0) { global $ilBench, $ilUser, $tree; $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId(); $conditions = ilConditionHandler::_getConditionsOfTarget($a_target_ref_id, $a_target_id, $a_target_type); if (!count($conditions)) { return true; } // @todo check this include_once './Services/Container/classes/class.ilMemberViewSettings.php'; if (ilMemberViewSettings::getInstance()->isActive()) { return true; } // First check obligatory conditions $optional = self::getOptionalConditionsOfTarget($a_target_ref_id, $a_target_id, $a_target_type); $num_required = self::calculateRequiredTriggers($a_target_ref_id, $a_target_id, $a_target_type); $passed = 0; foreach ($conditions as $condition) { if ($tree->isDeleted($condition['trigger_ref_id'])) { continue; } $check = ilConditionHandler::_checkCondition($condition['id'], $a_usr_id); if ($check) { ++$passed; if ($passed >= $num_required) { return true; } } else { if (!count($optional)) { return false; } } } // not all optional conditions passed return false; }