Exemplo n.º 1
0
 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;
 }