ILIAS  release_4-4 Revision
ilConditionHandler Class Reference

Handles conditions for accesses to different ILIAS objects. More...

+ Collaboration diagram for ilConditionHandler:

Public Member Functions

 ilConditionHandler ()
 constructor public More...
 
 setReferenceHandlingType ($a_type)
 set reference handling type More...
 
 getReferenceHandlingType ()
 get reference handling type More...
 
 setErrorMessage ($a_msg)
 
 getErrorMessage ()
 
 setTargetRefId ($a_target_ref_id)
 set target ref id More...
 
 getTargetRefId ()
 get target ref id More...
 
 setTargetObjId ($a_target_obj_id)
 set target object id More...
 
 getTargetObjId ()
 get target obj id More...
 
 setTargetType ($a_target_type)
 set target object type More...
 
 getTargetType ()
 get target obj type More...
 
 setTriggerRefId ($a_trigger_ref_id)
 set trigger ref id More...
 
 getTriggerRefId ()
 get target ref id More...
 
 setTriggerObjId ($a_trigger_obj_id)
 set trigger object id More...
 
 getTriggerObjId ()
 get trigger obj id More...
 
 setTriggerType ($a_trigger_type)
 set trigger object type More...
 
 getTriggerType ()
 get trigger obj type More...
 
 setOperator ($a_operator)
 set operator More...
 
 getOperator ()
 get operator More...
 
 setValue ($a_value)
 set value More...
 
 getValue ()
 get value More...
 
 setObligatory ($a_obl)
 Set obligatory status. More...
 
 getObligatory ()
 Get obligatory status. More...
 
 enableAutomaticValidation ($a_validate=true)
 enable automated validation More...
 
 getTriggerTypes ()
 get all possible trigger types NOT STATIC public More...
 
 getOperatorsByTargetType ($a_type)
 
 storeCondition ()
 store new condition in database NOT STATIC public More...
 
 checkExists ()
 
 updateCondition ($a_id)
 update condition More...
 
 delete ($a_ref_id)
 delete all trigger and target entries This method is called from ilObject::delete() if an object os removed from trash More...
 
 deleteByObjId ($a_obj_id)
 delete all trigger and target entries This method is called from ilObject::delete() if an object is removed from trash More...
 
 deleteCondition ($a_id)
 delete condition More...
 
 preloadConditionsForTargetRecords ($a_type, $a_obj_ids)
 Preload conditions for target records. More...
 
 _getCondition ($a_id)
 
 _checkCondition ($a_id, $a_usr_id=0)
 checks wether a single condition is fulfilled every trigger object type must implement a static method _checkCondition($a_operator, $a_value) More...
 
 _checkAllConditionsOfTarget ($a_target_ref_id, $a_target_id, $a_target_type="", $a_usr_id=0)
 checks wether all conditions of a target object are fulfilled More...
 
 validate ()
 
 checkCircle ($a_ref_id, $a_obj_id)
 

Static Public Member Functions

static _isReferenceHandlingOptional ($a_type)
 is reference handling optional More...
 
static _adjustMovedObjectConditions ($a_ref_id)
 In the moment it is not allowed to create preconditions on objects that are located outside of a course. More...
 
static _getDistinctTargetRefIds ()
 Get all target ref ids. More...
 
static _deleteTargetConditionsByRefId ($a_target_ref_id)
 Delete conditions by target ref id Note: only conditions on the target type are deleted Conditions on e.g chapters are not handled. More...
 
static updateObligatory ($a_id, $a_status)
 Toggle condition obligatory status. More...
 
 _getConditionsOfTrigger ($a_trigger_obj_type, $a_trigger_id)
 get all conditions of trigger object More...
 
static _getConditionsOfTarget ($a_target_ref_id, $a_target_obj_id, $a_target_type="")
 get all conditions of target object More...
 
static getOptionalConditionsOfTarget ($a_target_ref_id, $a_target_obj_id, $a_obj_type='')
 Get optional conditions. More...
 
static calculateRequiredTriggers ($a_target_ref_id, $a_target_obj_id, $a_target_obj_type='', $a_force_update=false)
 calculate number of obligatory items More...
 
static saveNumberOfRequiredTriggers ($a_target_ref_id, $a_target_obj_id, $a_num)
 Save number of obigatory triggers. More...
 

Data Fields

const UNIQUE_CONDITIONS = 1
 
const SHARED_CONDITIONS = 0
 
 $db
 
 $lng
 
 $error_message
 
 $target_obj_id
 
 $target_ref_id
 
 $target_type
 
 $trigger_obj_id
 
 $trigger_ref_id
 
 $trigger_type
 
 $operator
 
 $value
 
 $validation
 
 $conditions
 

Static Public Attributes

static $cond_for_target_cache = array()
 
static $cond_target_rows = array()
 

Private Attributes

 $obligatory = true
 

Detailed Description

Handles conditions for accesses to different ILIAS objects.

A condition consists of four elements:

  • a trigger object, e.g. a test or a survey question
  • an operator, e.g. "=", "<", "passed"
  • an (optional) value, e.g. "5"
  • a target object, e.g. a learning module

If a condition is fulfilled for a certain user, (s)he may access the target object. This first implementation handles only one access type per object, which is usually "read" access. A possible future extension may implement different access types.

The condition data is stored in the database table "condition" (Note: This table must not be accessed directly from other classes. The data should be accessed via the interface of class ilCondition.) cond_id INT condition id trigger_obj_type VARCHAR(10) "crs" | "tst" | "qst", ... trigger_id INT obj id of trigger object operator varchar(10 "=", "<", ">", ">=", "<=", "passed", "contains", ... value VARCHAR(10) optional value target_obj_type VARCHAR(10) "lm" | "frm" | "st" | "pg", ... target_id object or reference id of target object

Trigger objects are always stored with their object id (if a test has been passed by a user, he doesn't need to repeat it in other contexts. But target objects are usually stored with their reference id if available, otherwise, if they are non-referenced objects (e.g. (survey) questions) they are stored with their object id.

Stefan Meyer 10-08-2004 In addition we store the ref_id of the trigger object to allow the target object to link to the triggered object. But it's not possible to assign two or more linked (same obj_id) triggered objects to a target object

Examples:

Learning module 5 may only be accessed, if test 6 has been passed: trigger_obj_type "tst" trigger_id 6 (object id) trigger_ref_id 117 operator "passed" value target_obj_type "lm" target_id 5 (reference id)

Survey question 10 should only be presented, if survey question 8 is answered with a value greater than 4. trigger_obj_type "qst" trigger_id 8 (question (instance) object id) trigger_ref_id 117 operator ">" value "4" target_obj_type "lm" target_id 10 (question (instance) object id)

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 66 of file class.ilConditionHandler.php.

Member Function Documentation

◆ _adjustMovedObjectConditions()

static ilConditionHandler::_adjustMovedObjectConditions (   $a_ref_id)
static

In the moment it is not allowed to create preconditions on objects that are located outside of a course.

Therefore, after moving an object: check for parent type 'crs'. if that fails delete preconditions

public

Parameters
intreference id of moved object

Definition at line 137 of file class.ilConditionHandler.php.

Referenced by ilSoapObjectAdministration\moveObject(), ilContainerGUI\pasteObject(), ilContainerGUI\performPasteIntoMultipleObjectsObject(), and ilChatroomInstaller\setChatroomSettings().

138  {
139  global $tree;
140 
141  if($tree->checkForParentType($a_ref_id,'crs'))
142  {
143  // Nothing to do
144  return true;
145  }
146 
147  // Need another implementation that has better performance
148  $childs = $tree->getSubTree($tree->getNodeData($a_ref_id),false);
149  $conditions = self::_getDistinctTargetRefIds();
150 
151  foreach(array_intersect($conditions,$childs) as $target_ref)
152  {
153  if(!$tree->checkForParentType($target_ref,'crs'))
154  {
155  self::_deleteTargetConditionsByRefId($target_ref);
156  }
157  }
158  return true;
159  }
+ Here is the caller graph for this function:

◆ _checkAllConditionsOfTarget()

ilConditionHandler::_checkAllConditionsOfTarget (   $a_target_ref_id,
  $a_target_id,
  $a_target_type = "",
  $a_usr_id = 0 
)

checks wether all conditions of a target object are fulfilled

Definition at line 856 of file class.ilConditionHandler.php.

References $ilBench, $ilUser, _checkCondition(), _getConditionsOfTarget(), and ilMemberViewSettings\getInstance().

Referenced by ilCourseObjectivePresentationGUI\__showLearningMaterials(), ilCourseObjectivePresentationGUI\__showOtherResources(), ilCourseObjectivePresentationGUI\__showTests(), ilObjContentObject\_checkPreconditionsOfPage(), ilAccessHandler\doConditionCheck(), ilRepositoryExplorerGUI\getChildsOfNode(), ilObjCourseListGUI\initItem(), ilObjCourseReferenceListGUI\initItem(), ilShopRepositoryExplorer\isClickable(), ilRepositoryExplorer\isClickable(), ilRepositoryExplorerGUI\isNodeClickable(), ilShopRepositoryExplorer\showChilds(), ilRepositoryExplorer\showChilds(), ilCourseContentGUI\showStartObjects(), and ilObjCourseGUI\showStartObjects().

857  {
858  global $ilBench,$ilUser,$tree;
859 
860  $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
861 
862  $conditions = ilConditionHandler::_getConditionsOfTarget($a_target_ref_id,$a_target_id, $a_target_type);
863 
864  if(!count($conditions))
865  {
866  return true;
867  }
868 
869  // @todo check this
870  include_once './Services/Container/classes/class.ilMemberViewSettings.php';
871  if(ilMemberViewSettings::getInstance()->isActive())
872  {
873  return true;
874  }
875 
876  // First check obligatory conditions
877  $optional = self::getOptionalConditionsOfTarget($a_target_ref_id, $a_target_id, $a_target_type);
878  $num_required = self::calculateRequiredTriggers($a_target_ref_id, $a_target_id, $a_target_type);
879  $passed = 0;
880  foreach($conditions as $condition)
881  {
882  if($tree->isDeleted($condition['trigger_ref_id']))
883  {
884  continue;
885  }
886  $check = ilConditionHandler::_checkCondition($condition['id'],$a_usr_id);
887 
888  if($check)
889  {
890  ++$passed;
891  if($passed >= $num_required)
892  {
893  return true;
894  }
895  }
896  else
897  {
898  if(!count($optional))
899  {
900  return false;
901  }
902  }
903  }
904  // not all optional conditions passed
905  return false;
906  }
static _getConditionsOfTarget($a_target_ref_id, $a_target_obj_id, $a_target_type="")
get all conditions of target object
_checkCondition($a_id, $a_usr_id=0)
checks wether a single condition is fulfilled every trigger object type must implement a static metho...
global $ilUser
Definition: imgupload.php:15
static getInstance()
Get instance.
global $ilBench
Definition: ilias.php:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _checkCondition()

ilConditionHandler::_checkCondition (   $a_id,
  $a_usr_id = 0 
)

checks wether a single condition is fulfilled every trigger object type must implement a static method _checkCondition($a_operator, $a_value)

Definition at line 730 of file class.ilConditionHandler.php.

References $ilUser, ilObjTestAccess\_checkCondition(), ilObjCourseGrouping\_checkCondition(), ilObjExercise\_checkCondition(), ilObjCourse\_checkCondition(), ilObjSurvey\_checkCondition(), _getCondition(), and ilLPStatus\_hasUserCompleted().

Referenced by _checkAllConditionsOfTarget(), ilObjContentObject\_getMissingPreconditionsOfPage(), ilObjContentObject\_getMissingPreconditionsTopChapter(), and ilObjectListGUI\parseConditions().

731  {
732  global $ilUser;
733 
734  $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
735 
736  $condition = ilConditionHandler::_getCondition($a_id);
737 
738  switch($condition['trigger_type'])
739  {
740  case "tst":
741  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
742  return ilObjTestAccess::_checkCondition($condition['trigger_obj_id'],$condition['operator'],$condition['value'],$a_usr_id);
743 
744  case "crs":
745  include_once './Modules/Course/classes/class.ilObjCourse.php';
746  return ilObjCourse::_checkCondition($condition['trigger_obj_id'],$condition['operator'],$condition['value'],$a_usr_id);
747 
748  case 'exc':
749  include_once './Modules/Exercise/classes/class.ilObjExercise.php';
750  return ilObjExercise::_checkCondition($condition['trigger_obj_id'],$condition['operator'],$condition['value'],$a_usr_id);
751 
752  case 'crsg':
753  include_once './Modules/Course/classes/class.ilObjCourseGrouping.php';
754  return ilObjCourseGrouping::_checkCondition($condition['trigger_obj_id'],$condition['operator'],$condition['value'],$a_usr_id);
755 
756  case 'sahs':
757  include_once './Services/Tracking/classes/class.ilLPStatus.php';
758  return ilLPStatus::_hasUserCompleted($condition['trigger_obj_id'], $a_usr_id);
759 
760  case 'svy':
761  include_once './Modules/Survey/classes/class.ilObjSurvey.php';
762  return ilObjSurvey::_checkCondition($condition['trigger_obj_id'],$condition['operator'],$condition['value'],$a_usr_id);
763 
764  default:
765  return false;
766 
767  }
768 
769  }
_checkCondition($trigger_obj_id, $operator,$value, $a_usr_id=0)
_checkCondition($a_obj_id, $a_operator, $a_value, $a_usr_id=0)
_checkCondition($a_exc_id, $a_operator, $a_value, $a_usr_id=0)
_checkCondition($a_svy_id, $a_operator, $a_value, $a_usr_id=0)
static _hasUserCompleted($a_obj_id, $a_user_id)
Lookup user object completion.
_checkCondition($a_obj_id, $a_operator, $a_value, $a_usr_id=0)
check condition
global $ilUser
Definition: imgupload.php:15
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _deleteTargetConditionsByRefId()

static ilConditionHandler::_deleteTargetConditionsByRefId (   $a_target_ref_id)
static

Delete conditions by target ref id Note: only conditions on the target type are deleted Conditions on e.g chapters are not handled.

public

Parameters
intref id of target

Definition at line 191 of file class.ilConditionHandler.php.

References $query, and $res.

Referenced by ilRBACTest\testConditions().

192  {
193  global $ilDB;
194 
195  $query = "DELETE FROM conditions ".
196  "WHERE target_ref_id = ".$ilDB->quote($a_target_ref_id,'integer')." ".
197  "AND target_type != 'st' ";
198  $res = $ilDB->manipulate($query);
199  return true;
200  }
+ Here is the caller graph for this function:

◆ _getCondition()

ilConditionHandler::_getCondition (   $a_id)

Definition at line 696 of file class.ilConditionHandler.php.

References $query, $res, $row, and DB_FETCHMODE_OBJECT.

Referenced by _checkCondition(), ilConditionHandlerInterface\askDelete(), ilConditionHandlerInterface\edit(), ilConditionHandlerInterface\initFormCondition(), ilRBACTest\testConditions(), and ilConditionHandlerInterface\updateCondition().

697  {
698  global $ilDB;
699 
700  $query = "SELECT * FROM conditions ".
701  "WHERE condition_id = ".$ilDB->quote($a_id,'integer');
702 
703  $res = $ilDB->query($query);
704  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
705  {
706  $tmp_array['id'] = $row->condition_id;
707  $tmp_array['target_ref_id'] = $row->target_ref_id;
708  $tmp_array['target_obj_id'] = $row->target_obj_id;
709  $tmp_array['target_type'] = $row->target_type;
710  $tmp_array['trigger_ref_id'] = $row->trigger_ref_id;
711  $tmp_array['trigger_obj_id'] = $row->trigger_obj_id;
712  $tmp_array['trigger_type'] = $row->trigger_type;
713  $tmp_array['operator'] = $row->operator;
714  $tmp_array['value'] = $row->value;
715  $tmp_array['ref_handling'] = $row->ref_handling;
716  $tmp_array['obligatory'] = $row->obligatory;
717 
718  return $tmp_array;
719  }
720  return false;
721  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
+ Here is the caller graph for this function:

◆ _getConditionsOfTarget()

static ilConditionHandler::_getConditionsOfTarget (   $a_target_ref_id,
  $a_target_obj_id,
  $a_target_type = "" 
)
static

get all conditions of target object

Parameters
$a_target_ref_idtarget reference id
$a_target_obj_idtarget object id
$a_target_typetarget object type (must be provided only if object is not derived from ilObject and therefore stored in object_data; this is e.g. the case for chapters (type = "st"))

Definition at line 603 of file class.ilConditionHandler.php.

References $conditions, $ilBench, $query, $res, $row, and ilObject\_lookupType().

Referenced by ilConditionHandlerInterface\__getConditionsOfTarget(), _checkAllConditionsOfTarget(), ilObjCourseGrouping\_checkGroupingDependencies(), ilObjCourseGrouping\_getGroupingCourseIds(), ilObjCourseGrouping\_getGroupingItems(), ilObjContentObject\_getMissingPreconditionsOfPage(), ilObjContentObject\_getMissingPreconditionsTopChapter(), checkCircle(), ilObject\cloneDependencies(), ilAccessHandler\doConditionCheck(), ilObjectListGUI\insertPreconditions(), ilConditionHandlerInterface\listConditions(), ilConditionHandlerInterface\saveObligatoryList(), ilConditionHandlerInterface\saveObligatorySettings(), ilConditionHandlerInterface\showObligatoryForm(), and ilRBACTest\testConditions().

604  {
605  global $ilDB, $ilBench;
606 
607  // get type if no type given
608  if ($a_target_type == "")
609  {
610  $a_target_type = ilObject::_lookupType($a_target_obj_id);
611  }
612 
613  // check conditions for target cache
614  if (isset(self::$cond_for_target_cache[$a_target_ref_id.":".$a_target_obj_id.":".
615  $a_target_type]))
616  {
617  return self::$cond_for_target_cache[$a_target_ref_id.":".$a_target_obj_id.":".
618  $a_target_type];
619  }
620 
621  // check rows cache
622  if (isset(self::$cond_target_rows[$a_target_type.":".$a_target_obj_id]))
623  {
624  $rows = self::$cond_target_rows[$a_target_type.":".$a_target_obj_id];
625  }
626  else
627  {
628  // query data from db
629  $query = "SELECT * FROM conditions ".
630  "WHERE target_obj_id = ".$ilDB->quote($a_target_obj_id,'integer')." ".
631  " AND target_type = ".$ilDB->quote($a_target_type,'text');
632 
633  $res = $ilDB->query($query);
634  $rows = array();
635  while ($row = $ilDB->fetchAssoc($res))
636  {
637  $rows[] = $row;
638  }
639  }
640 
641  reset($rows);
642  $conditions = array();
643  foreach ($rows as $row)
644  {
645  if ($row["ref_handling"] == self::UNIQUE_CONDITIONS)
646  {
647  if ($row["target_ref_id"] != $a_target_ref_id)
648  {
649  continue;
650  }
651  }
652 
653  $row["id"] = $row["condition_id"];
654  $conditions[] = $row;
655  }
656 
657  // write conditions for target cache
658  self::$cond_for_target_cache[$a_target_ref_id.":".$a_target_obj_id.":".
659  $a_target_type] = $conditions;
660 
661  return $conditions;
662  }
static _lookupType($a_id, $a_reference=false)
lookup object type
global $ilBench
Definition: ilias.php:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getConditionsOfTrigger()

ilConditionHandler::_getConditionsOfTrigger (   $a_trigger_obj_type,
  $a_trigger_id 
)
static

get all conditions of trigger object

Definition at line 563 of file class.ilConditionHandler.php.

References $conditions, $query, $res, $row, and DB_FETCHMODE_OBJECT.

Referenced by ilObjCourseGrouping\_checkGroupingDependencies(), ilObjCourseGrouping\_getGroupingCourseIds(), ilObjCourseGrouping\_getGroupingItems(), ilScormLP\checkSCORMPreconditions(), ilObjCourseGrouping\deassign(), ilObjCourseGrouping\getAssignedItems(), and ilRBACTest\testConditions().

564  {
565  global $ilDB;
566 
567  $query = "SELECT * FROM conditions ".
568  "WHERE trigger_obj_id = ".$ilDB->quote($a_trigger_id,'integer')." ".
569  " AND trigger_type = ".$ilDB->quote($a_trigger_obj_type,'text');
570 
571  $res = $ilDB->query($query);
572  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
573  {
574  $tmp_array['id'] = $row->condition_id;
575  $tmp_array['target_ref_id'] = $row->target_ref_id;
576  $tmp_array['target_obj_id'] = $row->target_obj_id;
577  $tmp_array['target_type'] = $row->target_type;
578  $tmp_array['trigger_ref_id'] = $row->trigger_ref_id;
579  $tmp_array['trigger_obj_id'] = $row->trigger_obj_id;
580  $tmp_array['trigger_type'] = $row->trigger_type;
581  $tmp_array['operator'] = $row->operator;
582  $tmp_array['value'] = $row->value;
583  $tmp_array['ref_handling'] = $row->ref_handling;
584  $tmp_array['obligatory'] = $row->obligatory;
585 
586  $conditions[] = $tmp_array;
587  unset($tmp_array);
588  }
589 
590  return $conditions ? $conditions : array();
591  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
+ Here is the caller graph for this function:

◆ _getDistinctTargetRefIds()

static ilConditionHandler::_getDistinctTargetRefIds ( )
static

Get all target ref ids.

public

Definition at line 168 of file class.ilConditionHandler.php.

References $query, $res, $row, and DB_FETCHMODE_OBJECT.

Referenced by ilRBACTest\testConditions().

169  {
170  global $ilDB;
171 
172  $query = "SELECT DISTINCT target_ref_id ref FROM conditions ";
173  $res = $ilDB->query($query);
174  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
175  {
176  $ref_ids[] = $row->ref;
177  }
178  return $ref_ids ? $ref_ids : array();
179  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
+ Here is the caller graph for this function:

◆ _isReferenceHandlingOptional()

static ilConditionHandler::_isReferenceHandlingOptional (   $a_type)
static

is reference handling optional

public

Parameters
stringtarget type ILIAS obj type

Definition at line 115 of file class.ilConditionHandler.php.

Referenced by ilConditionHandlerInterface\initFormCondition().

116  {
117  switch($a_type)
118  {
119  case 'st':
120  return true;
121 
122  default:
123  return false;
124  }
125  }
+ Here is the caller graph for this function:

◆ calculateRequiredTriggers()

static ilConditionHandler::calculateRequiredTriggers (   $a_target_ref_id,
  $a_target_obj_id,
  $a_target_obj_type = '',
  $a_force_update = false 
)
static

calculate number of obligatory items

Parameters
int$a_target_ref_id
int$a_target_obj_id
Returns
int

Definition at line 799 of file class.ilConditionHandler.php.

References $result.

Referenced by ilObjectListGUI\parseConditions(), ilConditionHandlerInterface\saveObligatoryList(), and ilConditionHandlerInterface\showObligatoryForm().

800  {
801  global $ilDB;
802 
803  // Get all conditions
804  $all = self::_getConditionsOfTarget($a_target_ref_id,$a_target_obj_id,$a_target_obj_type);
805  $opt = self::getOptionalConditionsOfTarget($a_target_ref_id, $a_target_obj_id,$a_target_obj_type);
806 
807  $set_obl = 0;
808  if(isset($all[0]))
809  {
810  $set_obl = $all[0]['num_obligatory'];
811  }
812 
813  // existing value is valid
814  if($set_obl > 0 and
815  $set_obl < count($all) and
816  $set_obl > (count($all) - count($opt) + 1))
817  {
818  return $set_obl;
819  }
820 
821  if(count($opt))
822  {
823  $result = count($all) - count($opt) + 1;
824  }
825  else
826  {
827  $result = count($all);
828  }
829  if($a_force_update)
830  {
831  self::saveNumberOfRequiredTriggers($a_target_ref_id,$a_target_obj_id,$result);
832  }
833  return $result;
834  }
$result
+ Here is the caller graph for this function:

◆ checkCircle()

ilConditionHandler::checkCircle (   $a_ref_id,
  $a_obj_id 
)

Definition at line 945 of file class.ilConditionHandler.php.

References _getConditionsOfTarget(), and getOperator().

Referenced by validate().

946  {
947  foreach(ilConditionHandler::_getConditionsOfTarget($a_ref_id,$a_obj_id) as $condition)
948  {
949  if($condition['trigger_obj_id'] == $this->target_obj_id and $condition['operator'] == $this->getOperator())
950  {
951  $this->circle = true;
952  break;
953  }
954  else
955  {
956  $this->checkCircle($condition['trigger_ref_id'],$condition['trigger_obj_id']);
957  }
958  }
959  return $this->circle;
960  }
static _getConditionsOfTarget($a_target_ref_id, $a_target_obj_id, $a_target_type="")
get all conditions of target object
checkCircle($a_ref_id, $a_obj_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkExists()

ilConditionHandler::checkExists ( )

Definition at line 463 of file class.ilConditionHandler.php.

References $query, $res, getOperator(), getTargetObjId(), getTargetRefId(), getTriggerObjId(), and getTriggerRefId().

464  {
465  global $ilDB;
466 
467  $query = "SELECT * FROM conditions ".
468  "WHERE target_ref_id = ".$ilDB->quote($this->getTargetRefId(),'integer')." ".
469  "AND target_obj_id = ".$ilDB->quote($this->getTargetObjId(),'integer')." ".
470  "AND trigger_ref_id = ".$ilDB->quote($this->getTriggerRefId(),'integer')." ".
471  "AND trigger_obj_id = ".$ilDB->quote($this->getTriggerObjId(),'integer')." ".
472  "AND operator = ".$ilDB->quote($this->getOperator(),'text');
473  $res = $ilDB->query($query);
474 
475  return $res->numRows() ? true : false;
476  }
getTriggerRefId()
get target ref id
getTargetRefId()
get target ref id
getTargetObjId()
get target obj id
getTriggerObjId()
get trigger obj id
+ Here is the call graph for this function:

◆ delete()

ilConditionHandler::delete (   $a_ref_id)

delete all trigger and target entries This method is called from ilObject::delete() if an object os removed from trash

Definition at line 518 of file class.ilConditionHandler.php.

References $query, and $res.

519  {
520  global $ilDB;
521 
522  $query = "DELETE FROM conditions WHERE ".
523  "target_ref_id = ".$ilDB->quote($a_ref_id,'integer')." ".
524  "OR trigger_ref_id = ".$ilDB->quote($a_ref_id,'integer');
525  $res = $ilDB->manipulate($query);
526 
527  return true;
528  }

◆ deleteByObjId()

ilConditionHandler::deleteByObjId (   $a_obj_id)

delete all trigger and target entries This method is called from ilObject::delete() if an object is removed from trash

Definition at line 533 of file class.ilConditionHandler.php.

References $query, and $res.

534  {
535  global $ilDB;
536 
537  $query = "DELETE FROM conditions WHERE ".
538  "target_obj_id = ".$ilDB->quote($a_obj_id,'integer')." ".
539  "OR trigger_obj_id = ".$ilDB->quote($a_obj_id,'integer');
540  $res = $ilDB->manipulate($query);
541 
542  return true;
543  }

◆ deleteCondition()

ilConditionHandler::deleteCondition (   $a_id)

delete condition

Definition at line 548 of file class.ilConditionHandler.php.

References $query, and $res.

Referenced by storeCondition().

549  {
550  global $ilDB;
551 
552  $query = "DELETE FROM conditions ".
553  "WHERE condition_id = ".$ilDB->quote($a_id,'integer');
554  $res = $ilDB->manipulate($query);
555 
556  return true;
557  }
+ Here is the caller graph for this function:

◆ enableAutomaticValidation()

ilConditionHandler::enableAutomaticValidation (   $a_validate = true)

enable automated validation

Definition at line 385 of file class.ilConditionHandler.php.

386  {
387  $this->validation = $a_validate;
388  }

◆ getErrorMessage()

ilConditionHandler::getErrorMessage ( )

Definition at line 230 of file class.ilConditionHandler.php.

References $error_message.

231  {
232  return $this->error_message;
233  }

◆ getObligatory()

ilConditionHandler::getObligatory ( )

Get obligatory status.

Returns
obligatory status

Definition at line 376 of file class.ilConditionHandler.php.

References $obligatory.

Referenced by storeCondition(), and updateCondition().

377  {
378  return (bool) $this->obligatory;
379  }
+ Here is the caller graph for this function:

◆ getOperator()

ilConditionHandler::getOperator ( )

get operator

Definition at line 342 of file class.ilConditionHandler.php.

References $operator.

Referenced by checkCircle(), checkExists(), storeCondition(), and updateCondition().

343  {
344  return $this->operator;
345  }
+ Here is the caller graph for this function:

◆ getOperatorsByTargetType()

ilConditionHandler::getOperatorsByTargetType (   $a_type)

Definition at line 401 of file class.ilConditionHandler.php.

402  {
403  switch($a_type)
404  {
405  case 'crs':
406  case 'exc':
407  return array('passed');
408 
409  case 'tst':
410  return array('passed','finished','not_finished');
411 
412  case 'crsg':
413  return array('not_member');
414 
415  case 'sahs':
416  return array('finished');
417 
418  case 'svy':
419  return array('finished');
420 
421  default:
422  return array();
423  }
424  }

◆ getOptionalConditionsOfTarget()

static ilConditionHandler::getOptionalConditionsOfTarget (   $a_target_ref_id,
  $a_target_obj_id,
  $a_obj_type = '' 
)
static

Get optional conditions.

Parameters
int$a_target_ref_id
int$a_target_obj_id

Definition at line 776 of file class.ilConditionHandler.php.

Referenced by ilConditionHandlerInterface\listConditions(), ilObjectListGUI\parseConditions(), ilConditionHandlerInterface\saveObligatorySettings(), and ilConditionHandlerInterface\showObligatoryForm().

777  {
778  $conditions = self::_getConditionsOfTarget($a_target_ref_id,$a_target_obj_id);
779 
780  $opt = array();
781  foreach($conditions as $con)
782  {
783  if($con['obligatory'])
784  {
785  continue;
786  }
787 
788  $opt[] = $con;
789  }
790  return $opt;
791  }
+ Here is the caller graph for this function:

◆ getReferenceHandlingType()

ilConditionHandler::getReferenceHandlingType ( )

get reference handling type

public

Definition at line 220 of file class.ilConditionHandler.php.

Referenced by storeCondition(), and updateCondition().

221  {
222  return (int) $this->condition_reference_type;
223  }
+ Here is the caller graph for this function:

◆ getTargetObjId()

ilConditionHandler::getTargetObjId ( )

get target obj id

Definition at line 262 of file class.ilConditionHandler.php.

References $target_obj_id.

Referenced by checkExists(), and storeCondition().

263  {
264  return $this->target_obj_id;
265  }
+ Here is the caller graph for this function:

◆ getTargetRefId()

ilConditionHandler::getTargetRefId ( )

get target ref id

Definition at line 246 of file class.ilConditionHandler.php.

References $target_ref_id.

Referenced by checkExists(), storeCondition(), updateCondition(), and validate().

247  {
248  return $this->target_ref_id;
249  }
+ Here is the caller graph for this function:

◆ getTargetType()

ilConditionHandler::getTargetType ( )

get target obj type

Definition at line 278 of file class.ilConditionHandler.php.

References $target_type.

Referenced by storeCondition().

279  {
280  return $this->target_type;
281  }
+ Here is the caller graph for this function:

◆ getTriggerObjId()

ilConditionHandler::getTriggerObjId ( )

get trigger obj id

Definition at line 310 of file class.ilConditionHandler.php.

References $trigger_obj_id.

Referenced by checkExists(), and storeCondition().

311  {
312  return $this->trigger_obj_id;
313  }
+ Here is the caller graph for this function:

◆ getTriggerRefId()

ilConditionHandler::getTriggerRefId ( )

get target ref id

Definition at line 294 of file class.ilConditionHandler.php.

References $trigger_ref_id.

Referenced by checkExists(), storeCondition(), and validate().

295  {
296  return $this->trigger_ref_id;
297  }
+ Here is the caller graph for this function:

◆ getTriggerType()

ilConditionHandler::getTriggerType ( )

get trigger obj type

Definition at line 326 of file class.ilConditionHandler.php.

References $trigger_type.

Referenced by storeCondition().

327  {
328  return $this->trigger_type;
329  }
+ Here is the caller graph for this function:

◆ getTriggerTypes()

ilConditionHandler::getTriggerTypes ( )

get all possible trigger types NOT STATIC public

Definition at line 395 of file class.ilConditionHandler.php.

396  {
397  return array('crs','exc','tst','sahs', 'svy');
398  }

◆ getValue()

ilConditionHandler::getValue ( )

get value

Definition at line 358 of file class.ilConditionHandler.php.

References $value.

Referenced by storeCondition(), and updateCondition().

359  {
360  return $this->value;
361  }
+ Here is the caller graph for this function:

◆ ilConditionHandler()

ilConditionHandler::ilConditionHandler ( )

constructor public

Definition at line 98 of file class.ilConditionHandler.php.

References $lng.

99  {
100  global $ilDB,$lng;
101 
102  $this->db =& $ilDB;
103  $this->lng =& $lng;
104  $this->validation = true;
105  }

◆ preloadConditionsForTargetRecords()

ilConditionHandler::preloadConditionsForTargetRecords (   $a_type,
  $a_obj_ids 
)

Preload conditions for target records.

Parameters

Definition at line 670 of file class.ilConditionHandler.php.

References $res, and $row.

Referenced by ilObjectListGUIPreloader\preload().

671  {
672  global $ilDB;
673 
674  if (is_array($a_obj_ids) && count($a_obj_ids) > 0)
675  {
676  $res = $ilDB->query("SELECT * FROM conditions ".
677  "WHERE ".$ilDB->in("target_obj_id", $a_obj_ids, false, "integer").
678  " AND target_type = ".$ilDB->quote($a_type,'text'));
679  $rows = array();
680  while ($row = $ilDB->fetchAssoc($res))
681  {
682  self::$cond_target_rows[$a_type.":".$row["target_obj_id"]][]
683  = $row;
684  }
685  // init obj ids without any record
686  foreach ($a_obj_ids as $obj_id)
687  {
688  if (!is_array(self::$cond_target_rows[$a_type.":".$obj_id]))
689  {
690  self::$cond_target_rows[$a_type.":".$obj_id] = array();
691  }
692  }
693  }
694  }
+ Here is the caller graph for this function:

◆ saveNumberOfRequiredTriggers()

static ilConditionHandler::saveNumberOfRequiredTriggers (   $a_target_ref_id,
  $a_target_obj_id,
  $a_num 
)
static

Save number of obigatory triggers.

Parameters
int$a_target_ref_id
int$a_target_obj_id

Definition at line 841 of file class.ilConditionHandler.php.

References $query.

Referenced by ilConditionHandlerInterface\saveObligatorySettings().

842  {
843  global $ilDB;
844 
845  $query = 'UPDATE conditions '.
846  'SET num_obligatory = '.$ilDB->quote($a_num,'integer').' '.
847  'WHERE target_ref_id = '.$ilDB->quote($a_target_ref_id,'integer').' '.
848  'AND target_obj_id = '.$ilDB->quote($a_target_obj_id,'integer');
849  $ilDB->manipulate($query);
850  return;
851  }
+ Here is the caller graph for this function:

◆ setErrorMessage()

ilConditionHandler::setErrorMessage (   $a_msg)

Definition at line 226 of file class.ilConditionHandler.php.

Referenced by validate().

227  {
228  $this->error_message = $a_msg;
229  }
+ Here is the caller graph for this function:

◆ setObligatory()

ilConditionHandler::setObligatory (   $a_obl)

Set obligatory status.

Parameters
bool$a_obl

Definition at line 367 of file class.ilConditionHandler.php.

368  {
369  $this->obligatory = $a_obl;
370  }

◆ setOperator()

ilConditionHandler::setOperator (   $a_operator)

set operator

Definition at line 334 of file class.ilConditionHandler.php.

335  {
336  return $this->operator = $a_operator;
337  }

◆ setReferenceHandlingType()

ilConditionHandler::setReferenceHandlingType (   $a_type)

set reference handling type

Parameters
intpublic

Definition at line 209 of file class.ilConditionHandler.php.

210  {
211  return $this->condition_reference_type = $a_type;
212  }

◆ setTargetObjId()

ilConditionHandler::setTargetObjId (   $a_target_obj_id)

set target object id

Definition at line 254 of file class.ilConditionHandler.php.

255  {
256  return $this->target_obj_id = $a_target_obj_id;
257  }

◆ setTargetRefId()

ilConditionHandler::setTargetRefId (   $a_target_ref_id)

set target ref id

Definition at line 238 of file class.ilConditionHandler.php.

239  {
240  return $this->target_ref_id = $a_target_ref_id;
241  }

◆ setTargetType()

ilConditionHandler::setTargetType (   $a_target_type)

set target object type

Definition at line 270 of file class.ilConditionHandler.php.

271  {
272  return $this->target_type = $a_target_type;
273  }

◆ setTriggerObjId()

ilConditionHandler::setTriggerObjId (   $a_trigger_obj_id)

set trigger object id

Definition at line 302 of file class.ilConditionHandler.php.

303  {
304  return $this->trigger_obj_id = $a_trigger_obj_id;
305  }

◆ setTriggerRefId()

ilConditionHandler::setTriggerRefId (   $a_trigger_ref_id)

set trigger ref id

Definition at line 286 of file class.ilConditionHandler.php.

287  {
288  return $this->trigger_ref_id = $a_trigger_ref_id;
289  }

◆ setTriggerType()

ilConditionHandler::setTriggerType (   $a_trigger_type)

set trigger object type

Definition at line 318 of file class.ilConditionHandler.php.

319  {
320  return $this->trigger_type = $a_trigger_type;
321  }

◆ setValue()

ilConditionHandler::setValue (   $a_value)

set value

Definition at line 350 of file class.ilConditionHandler.php.

351  {
352  return $this->value = $a_value;
353  }

◆ storeCondition()

ilConditionHandler::storeCondition ( )

store new condition in database NOT STATIC public

Definition at line 431 of file class.ilConditionHandler.php.

References $query, $res, deleteCondition(), getObligatory(), getOperator(), getReferenceHandlingType(), getTargetObjId(), getTargetRefId(), getTargetType(), getTriggerObjId(), getTriggerRefId(), getTriggerType(), getValue(), and validate().

432  {
433  global $ilDB;
434 
435  // first insert, then validate: it's easier to check for circles if the new condition is in the db table
436  $next_id = $ilDB->nextId('conditions');
437  $query = 'INSERT INTO conditions (condition_id,target_ref_id,target_obj_id,target_type,'.
438  'trigger_ref_id,trigger_obj_id,trigger_type,operator,value,ref_handling,obligatory) '.
439  'VALUES ('.
440  $ilDB->quote($next_id,'integer').','.
441  $ilDB->quote($this->getTargetRefId(),'integer').",".
442  $ilDB->quote($this->getTargetObjId(),'integer').",".
443  $ilDB->quote($this->getTargetType(),'text').",".
444  $ilDB->quote($this->getTriggerRefId(),'integer').",".
445  $ilDB->quote($this->getTriggerObjId(),'integer').",".
446  $ilDB->quote($this->getTriggerType(),'text').",".
447  $ilDB->quote($this->getOperator(),'text').",".
448  $ilDB->quote($this->getValue(),'text').", ".
449  $ilDB->quote($this->getReferenceHandlingType(),'integer').', '.
450  $ilDB->quote($this->getObligatory(),'integer').
451  ')';
452 
453  $res = $ilDB->manipulate($query);
454 
455  if ($this->validation && !$this->validate())
456  {
457  $this->deleteCondition($next_id);
458  return false;
459  }
460  return true;
461  }
getTriggerRefId()
get target ref id
getObligatory()
Get obligatory status.
getReferenceHandlingType()
get reference handling type
getTargetRefId()
get target ref id
getTargetObjId()
get target obj id
getTriggerObjId()
get trigger obj id
getTriggerType()
get trigger obj type
deleteCondition($a_id)
delete condition
getTargetType()
get target obj type
+ Here is the call graph for this function:

◆ updateCondition()

ilConditionHandler::updateCondition (   $a_id)

update condition

Definition at line 480 of file class.ilConditionHandler.php.

References $query, $res, getObligatory(), getOperator(), getReferenceHandlingType(), getTargetRefId(), and getValue().

481  {
482  global $ilDB;
483 
484  $query = "UPDATE conditions SET ".
485  "target_ref_id = ".$ilDB->quote($this->getTargetRefId(),'integer').", ".
486  "operator = ".$ilDB->quote($this->getOperator(),'text').", ".
487  "value = ".$ilDB->quote($this->getValue(),'text').", ".
488  "ref_handling = ".$this->db->quote($this->getReferenceHandlingType(),'integer').", ".
489  'obligatory = '.$this->db->quote($this->getObligatory(),'integer').' '.
490  "WHERE condition_id = ".$ilDB->quote($a_id,'integer');
491  $res = $ilDB->manipulate($query);
492 
493  return true;
494  }
getObligatory()
Get obligatory status.
getReferenceHandlingType()
get reference handling type
getTargetRefId()
get target ref id
+ Here is the call graph for this function:

◆ updateObligatory()

static ilConditionHandler::updateObligatory (   $a_id,
  $a_status 
)
static

Toggle condition obligatory status.

Parameters
int$a_id
bool$a_status

Definition at line 502 of file class.ilConditionHandler.php.

References $query, and $res.

Referenced by ilConditionHandlerInterface\saveObligatoryList(), and ilConditionHandlerInterface\saveObligatorySettings().

503  {
504  global $ilDB;
505 
506  $query = "UPDATE conditions SET ".
507  'obligatory = '.$ilDB->quote($a_status,'integer').' '.
508  "WHERE condition_id = ".$ilDB->quote($a_id,'integer');
509  $res = $ilDB->manipulate($query);
510 
511  return true;
512  }
+ Here is the caller graph for this function:

◆ validate()

ilConditionHandler::validate ( )

Definition at line 909 of file class.ilConditionHandler.php.

References $query, $res, checkCircle(), ilObjectFactory\getInstanceByRefId(), getTargetRefId(), getTriggerRefId(), and setErrorMessage().

Referenced by storeCondition().

910  {
911  global $ilDB;
912 
913  // check if obj_id is already assigned
914  $trigger_obj =& ilObjectFactory::getInstanceByRefId($this->getTriggerRefId());
915  $target_obj =& ilObjectFactory::getInstanceByRefId($this->getTargetRefId());
916 
917 
918  $query = "SELECT * FROM conditions WHERE ".
919  "trigger_ref_id = ".$ilDB->quote($trigger_obj->getId(),'integer')." ".
920  "AND target_ref_id = ".$ilDB->quote($target_obj->getId(),'integer');
921 
922  $res = $this->db->query($query);
923  if($res->numRows() > 1)
924  {
925  $this->setErrorMessage($this->lng->txt('condition_already_assigned'));
926 
927  unset($trigger_obj);
928  unset($target_obj);
929  return false;
930  }
931 
932  // check for circle
933  $this->target_obj_id = $target_obj->getId();
934  if($this->checkCircle($this->getTargetRefId(),$target_obj->getId()))
935  {
936  $this->setErrorMessage($this->lng->txt('condition_circle_created'));
937 
938  unset($trigger_obj);
939  unset($target_obj);
940  return false;
941  }
942  return true;
943  }
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
getTriggerRefId()
get target ref id
getTargetRefId()
get target ref id
checkCircle($a_ref_id, $a_obj_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $cond_for_target_cache

ilConditionHandler::$cond_for_target_cache = array()
static

Definition at line 90 of file class.ilConditionHandler.php.

◆ $cond_target_rows

ilConditionHandler::$cond_target_rows = array()
static

Definition at line 91 of file class.ilConditionHandler.php.

◆ $conditions

ilConditionHandler::$conditions

Definition at line 89 of file class.ilConditionHandler.php.

Referenced by _getConditionsOfTarget(), and _getConditionsOfTrigger().

◆ $db

ilConditionHandler::$db

Definition at line 71 of file class.ilConditionHandler.php.

◆ $error_message

ilConditionHandler::$error_message

Definition at line 75 of file class.ilConditionHandler.php.

Referenced by getErrorMessage().

◆ $lng

ilConditionHandler::$lng

Definition at line 72 of file class.ilConditionHandler.php.

Referenced by ilConditionHandler().

◆ $obligatory

ilConditionHandler::$obligatory = true
private

Definition at line 87 of file class.ilConditionHandler.php.

Referenced by getObligatory().

◆ $operator

ilConditionHandler::$operator

Definition at line 83 of file class.ilConditionHandler.php.

Referenced by getOperator().

◆ $target_obj_id

ilConditionHandler::$target_obj_id

Definition at line 77 of file class.ilConditionHandler.php.

Referenced by getTargetObjId().

◆ $target_ref_id

ilConditionHandler::$target_ref_id

Definition at line 78 of file class.ilConditionHandler.php.

Referenced by getTargetRefId().

◆ $target_type

ilConditionHandler::$target_type

Definition at line 79 of file class.ilConditionHandler.php.

Referenced by getTargetType().

◆ $trigger_obj_id

ilConditionHandler::$trigger_obj_id

Definition at line 80 of file class.ilConditionHandler.php.

Referenced by getTriggerObjId().

◆ $trigger_ref_id

ilConditionHandler::$trigger_ref_id

Definition at line 81 of file class.ilConditionHandler.php.

Referenced by getTriggerRefId().

◆ $trigger_type

ilConditionHandler::$trigger_type

Definition at line 82 of file class.ilConditionHandler.php.

Referenced by getTriggerType().

◆ $validation

ilConditionHandler::$validation

Definition at line 85 of file class.ilConditionHandler.php.

◆ $value

ilConditionHandler::$value

Definition at line 84 of file class.ilConditionHandler.php.

Referenced by getValue().

◆ SHARED_CONDITIONS

const ilConditionHandler::SHARED_CONDITIONS = 0

◆ UNIQUE_CONDITIONS


The documentation for this class was generated from the following file: