ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilConditionHandler.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
67 {
68  const OPERATOR_PASSED = 'passed';
69  const OPERATOR_FINISHED = 'finished';
70  const OPERATOR_NOT_FINISHED = 'not_finished';
71  const OPERATOR_NOT_MEMBER = 'not_member';
72  const OPERATOR_FAILED = 'failed';
73  const OPERATOR_LP = 'learning_progress';
74  const OPERATOR_ACCREDITED_OR_PASSED = 'accredited_or_passed';
75 
76  const UNIQUE_CONDITIONS = 1;
77  const SHARED_CONDITIONS = 0;
78 
79  public $db;
80  public $lng;
81 
82 
84 
87  public $target_type;
90  public $trigger_type;
91  public $operator;
92  public $value;
93  public $validation;
94 
95 
96  private $obligatory = true;
97  private $hidden_status = false;
98 
99  public $conditions;
100  public static $cond_for_target_cache = array();
101  public static $cond_target_rows = array();
102 
103 
108  public function __construct()
109  {
110  global $ilDB,$lng;
111 
112  $this->db =&$ilDB;
113  $this->lng =&$lng;
114  $this->validation = true;
115  }
116 
125  public static function _isReferenceHandlingOptional($a_type)
126  {
127  switch ($a_type) {
128  case 'st':
129  return true;
130 
131  default:
132  return false;
133  }
134  }
135 
141  public static function lookupHiddenStatusByTarget($a_target_ref_id)
142  {
143  global $ilDB;
144 
145  $query = 'SELECT hidden_status FROM conditions ' .
146  'WHERE target_ref_id = ' . $ilDB->quote($a_target_ref_id, 'integer');
147  $res = $ilDB->query($query);
148  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
149  return $row->hidden_status;
150  }
151  return false;
152  }
153 
164  public static function _adjustMovedObjectConditions($a_ref_id)
165  {
166  global $tree;
167 
168  if ($tree->checkForParentType($a_ref_id, 'crs')) {
169  // Nothing to do
170  return true;
171  }
172 
173  // Need another implementation that has better performance
174  $childs = $tree->getSubTree($tree->getNodeData($a_ref_id), false);
175  $conditions = self::_getDistinctTargetRefIds();
176 
177  foreach (array_intersect($conditions, $childs) as $target_ref) {
178  if (!$tree->checkForParentType($target_ref, 'crs')) {
179  self::_deleteTargetConditionsByRefId($target_ref);
180  }
181  }
182  return true;
183  }
184 
192  public static function _getDistinctTargetRefIds()
193  {
194  global $ilDB;
195 
196  $query = "SELECT DISTINCT target_ref_id ref FROM conditions ";
197  $res = $ilDB->query($query);
198  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
199  $ref_ids[] = $row->ref;
200  }
201  return $ref_ids ? $ref_ids : array();
202  }
203 
214  public static function _deleteTargetConditionsByRefId($a_target_ref_id)
215  {
216  global $ilDB;
217 
218  $query = "DELETE FROM conditions " .
219  "WHERE target_ref_id = " . $ilDB->quote($a_target_ref_id, 'integer') . " " .
220  "AND target_type != 'st' ";
221  $res = $ilDB->manipulate($query);
222  return true;
223  }
224 
233  {
234  return $this->condition_reference_type = $a_type;
235  }
236 
243  public function getReferenceHandlingType()
244  {
245  return (int) $this->condition_reference_type;
246  }
247 
248  // SET GET
249  public function setErrorMessage($a_msg)
250  {
251  $this->error_message = $a_msg;
252  }
253  public function getErrorMessage()
254  {
255  return $this->error_message;
256  }
257 
261  public function setTargetRefId($a_target_ref_id)
262  {
263  return $this->target_ref_id = $a_target_ref_id;
264  }
265 
269  public function getTargetRefId()
270  {
271  return $this->target_ref_id;
272  }
273 
277  public function setTargetObjId($a_target_obj_id)
278  {
279  return $this->target_obj_id = $a_target_obj_id;
280  }
281 
285  public function getTargetObjId()
286  {
287  return $this->target_obj_id;
288  }
289 
293  public function setTargetType($a_target_type)
294  {
295  return $this->target_type = $a_target_type;
296  }
297 
301  public function getTargetType()
302  {
303  return $this->target_type;
304  }
305 
309  public function setTriggerRefId($a_trigger_ref_id)
310  {
311  return $this->trigger_ref_id = $a_trigger_ref_id;
312  }
313 
317  public function getTriggerRefId()
318  {
319  return $this->trigger_ref_id;
320  }
321 
325  public function setTriggerObjId($a_trigger_obj_id)
326  {
327  return $this->trigger_obj_id = $a_trigger_obj_id;
328  }
329 
333  public function getTriggerObjId()
334  {
335  return $this->trigger_obj_id;
336  }
337 
341  public function setTriggerType($a_trigger_type)
342  {
343  return $this->trigger_type = $a_trigger_type;
344  }
345 
349  public function getTriggerType()
350  {
351  return $this->trigger_type;
352  }
353 
357  public function setOperator($a_operator)
358  {
359  return $this->operator = $a_operator;
360  }
361 
365  public function getOperator()
366  {
367  return $this->operator;
368  }
369 
373  public function setValue($a_value)
374  {
375  return $this->value = $a_value;
376  }
377 
381  public function getValue()
382  {
383  return $this->value;
384  }
385 
390  public function setObligatory($a_obl)
391  {
392  $this->obligatory = $a_obl;
393  }
394 
399  public function getObligatory()
400  {
401  return (bool) $this->obligatory;
402  }
403 
404  public function setHiddenStatus($a_status)
405  {
406  $this->hidden_status = $a_status;
407  }
408 
409  public function getHiddenStatus()
410  {
411  return $this->hidden_status;
412  }
413 
414 
418  public function enableAutomaticValidation($a_validate = true)
419  {
420  $this->validation = $a_validate;
421  }
422 
428  public function getTriggerTypes()
429  {
430  global $objDefinition;
431 
432  $trigger_types = array('crs','exc','tst','sahs', 'svy', 'lm', 'iass', 'prg');
433 
434  foreach ($objDefinition->getPlugins() as $p_type => $p_info) {
435  if (@include_once $p_info['location'] . '/class.ilObj' . $p_info['class_name'] . 'Access.php') {
436  include_once './Services/AccessControl/interfaces/interface.ilConditionHandling.php';
437  $name = 'ilObj' . $p_info['class_name'] . 'Access';
438  $reflection = new ReflectionClass($name);
439  if ($reflection->implementsInterface('ilConditionHandling')) {
440  $trigger_types[] = $p_type;
441  }
442  }
443  }
444 
445 
446  $active_triggers = array();
447  foreach ($trigger_types as $type) {
448  if (count($this->getOperatorsByTargetType($type))) {
449  $active_triggers[] = $type;
450  }
451  }
452 
453 
454 
455 
456  return $active_triggers;
457  }
458 
459 
466  {
467  global $objDefinition;
468 
469  switch ($a_type) {
470  case 'crsg':
471  return array('not_member');
472  }
473 
474  $class = $objDefinition->getClassName($a_type);
475  $location = $objDefinition->getLocation($a_type);
476  $full_class = "ilObj" . $class . "Access";
477  include_once($location . "/class." . $full_class . ".php");
478 
479  include_once './Services/AccessControl/interfaces/interface.ilConditionHandling.php';
480 
481  $reflection = new ReflectionClass($full_class);
482  if (!$reflection->implementsInterface('ilConditionHandling')) {
483  return array();
484  }
485 
486 
487  $operators = call_user_func(
488  array($full_class, 'getConditionOperators'),
489  $a_type
490  );
491 
492  // Add operator lp
493  include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
495  // only if object type has lp
496  include_once("Services/Object/classes/class.ilObjectLP.php");
498  array_unshift($operators, self::OPERATOR_LP);
499  }
500  }
501  return $operators;
502  }
503 
509  public function storeCondition()
510  {
511  global $ilDB;
512 
513  // first insert, then validate: it's easier to check for circles if the new condition is in the db table
514  $next_id = $ilDB->nextId('conditions');
515  $query = 'INSERT INTO conditions (condition_id,target_ref_id,target_obj_id,target_type,' .
516  'trigger_ref_id,trigger_obj_id,trigger_type,operator,value,ref_handling,obligatory,hidden_status) ' .
517  'VALUES (' .
518  $ilDB->quote($next_id, 'integer') . ',' .
519  $ilDB->quote($this->getTargetRefId(), 'integer') . "," .
520  $ilDB->quote($this->getTargetObjId(), 'integer') . "," .
521  $ilDB->quote($this->getTargetType(), 'text') . "," .
522  $ilDB->quote($this->getTriggerRefId(), 'integer') . "," .
523  $ilDB->quote($this->getTriggerObjId(), 'integer') . "," .
524  $ilDB->quote($this->getTriggerType(), 'text') . "," .
525  $ilDB->quote($this->getOperator(), 'text') . "," .
526  $ilDB->quote($this->getValue(), 'text') . ", " .
527  $ilDB->quote($this->getReferenceHandlingType(), 'integer') . ', ' .
528  $ilDB->quote($this->getObligatory(), 'integer') . ', ' .
529  $ilDB->quote($this->getHiddenStatus(), 'integer') . ' ' .
530  ')';
531 
532  $res = $ilDB->manipulate($query);
533 
534  if ($this->validation && !$this->validate()) {
535  $this->deleteCondition($next_id);
536  return false;
537  }
538  return true;
539  }
540 
541  public function checkExists()
542  {
543  global $ilDB;
544 
545  $query = "SELECT * FROM conditions " .
546  "WHERE target_ref_id = " . $ilDB->quote($this->getTargetRefId(), 'integer') . " " .
547  "AND target_obj_id = " . $ilDB->quote($this->getTargetObjId(), 'integer') . " " .
548  "AND trigger_ref_id = " . $ilDB->quote($this->getTriggerRefId(), 'integer') . " " .
549  "AND trigger_obj_id = " . $ilDB->quote($this->getTriggerObjId(), 'integer') . " " .
550  "AND operator = " . $ilDB->quote($this->getOperator(), 'text');
551  $res = $ilDB->query($query);
552 
553  return $res->numRows() ? true : false;
554  }
558  public function updateCondition($a_id)
559  {
560  global $ilDB;
561 
562  $query = "UPDATE conditions SET " .
563  "target_ref_id = " . $ilDB->quote($this->getTargetRefId(), 'integer') . ", " .
564  "operator = " . $ilDB->quote($this->getOperator(), 'text') . ", " .
565  "value = " . $ilDB->quote($this->getValue(), 'text') . ", " .
566  "ref_handling = " . $this->db->quote($this->getReferenceHandlingType(), 'integer') . ", " .
567  'obligatory = ' . $this->db->quote($this->getObligatory(), 'integer') . ' ' .
568  "WHERE condition_id = " . $ilDB->quote($a_id, 'integer');
569  $res = $ilDB->manipulate($query);
570 
571  return true;
572  }
573 
581  public function updateHiddenStatus($a_status)
582  {
583  global $ilDB;
584 
585  $query = 'UPDATE conditions SET ' .
586  'hidden_status = ' . $ilDB->quote($a_status, 'integer') . ' ' .
587  'WHERE target_ref_id = ' . $ilDB->quote($this->getTargetRefId(), 'integer');
588  $ilDB->manipulate($query);
589  return true;
590  }
591 
598  public static function updateObligatory($a_id, $a_status)
599  {
600  global $ilDB;
601 
602  $query = "UPDATE conditions SET " .
603  'obligatory = ' . $ilDB->quote($a_status, 'integer') . ' ' .
604  "WHERE condition_id = " . $ilDB->quote($a_id, 'integer');
605  $res = $ilDB->manipulate($query);
606 
607  return true;
608  }
609 
614  public function delete($a_ref_id)
615  {
616  global $ilDB;
617 
618  $query = "DELETE FROM conditions WHERE " .
619  "target_ref_id = " . $ilDB->quote($a_ref_id, 'integer') . " " .
620  "OR trigger_ref_id = " . $ilDB->quote($a_ref_id, 'integer');
621  $res = $ilDB->manipulate($query);
622 
623  return true;
624  }
629  public function deleteByObjId($a_obj_id)
630  {
631  global $ilDB;
632 
633  $query = "DELETE FROM conditions WHERE " .
634  "target_obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
635  "OR trigger_obj_id = " . $ilDB->quote($a_obj_id, 'integer');
636  $res = $ilDB->manipulate($query);
637 
638  return true;
639  }
640 
644  public function deleteCondition($a_id)
645  {
646  global $ilDB;
647 
648  $query = "DELETE FROM conditions " .
649  "WHERE condition_id = " . $ilDB->quote($a_id, 'integer');
650  $res = $ilDB->manipulate($query);
651 
652  return true;
653  }
654 
661  public static function getNumberOfConditionsOfTrigger($a_trigger_obj_type, $a_trigger_id)
662  {
663  global $DIC;
664  $db = $DIC->database();
665 
666  $query = 'select count(*) num from conditions ' .
667  'where trigger_obj_id = ' . $db->quote($a_trigger_id, ilDBConstants::T_INTEGER) . ' ' .
668  'and trigger_type = ' . $db->quote($a_trigger_obj_type, ilDBConstants::T_TEXT);
669  $res = $db->query($query);
671  return (int) $row->num;
672  }
673 
678  public static function _getConditionsOfTrigger($a_trigger_obj_type, $a_trigger_id)
679  {
680  global $ilDB;
681 
682  $query = "SELECT * FROM conditions " .
683  "WHERE trigger_obj_id = " . $ilDB->quote($a_trigger_id, 'integer') . " " .
684  " AND trigger_type = " . $ilDB->quote($a_trigger_obj_type, 'text');
685 
686  $res = $ilDB->query($query);
687  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
688  $tmp_array['id'] = $row->condition_id;
689  $tmp_array['target_ref_id'] = $row->target_ref_id;
690  $tmp_array['target_obj_id'] = $row->target_obj_id;
691  $tmp_array['target_type'] = $row->target_type;
692  $tmp_array['trigger_ref_id'] = $row->trigger_ref_id;
693  $tmp_array['trigger_obj_id'] = $row->trigger_obj_id;
694  $tmp_array['trigger_type'] = $row->trigger_type;
695  $tmp_array['operator'] = $row->operator;
696  $tmp_array['value'] = $row->value;
697  $tmp_array['ref_handling'] = $row->ref_handling;
698  $tmp_array['obligatory'] = $row->obligatory;
699  $tmp_array['hidden_status'] = $row->hidden_status;
700 
701  $conditions[] = $tmp_array;
702  unset($tmp_array);
703  }
704 
705  return $conditions ? $conditions : array();
706  }
707 
718  public static function _getConditionsOfTarget($a_target_ref_id, $a_target_obj_id, $a_target_type = "")
719  {
720  global $ilDB, $ilBench;
721 
722  // get type if no type given
723  if ($a_target_type == "") {
724  $a_target_type = ilObject::_lookupType($a_target_obj_id);
725  }
726 
727  // check conditions for target cache
728  if (isset(self::$cond_for_target_cache[$a_target_ref_id . ":" . $a_target_obj_id . ":" .
729  $a_target_type])) {
730  return self::$cond_for_target_cache[$a_target_ref_id . ":" . $a_target_obj_id . ":" .
731  $a_target_type];
732  }
733 
734  // check rows cache
735  if (isset(self::$cond_target_rows[$a_target_type . ":" . $a_target_obj_id])) {
736  $rows = self::$cond_target_rows[$a_target_type . ":" . $a_target_obj_id];
737  } else {
738  // query data from db
739  $query = "SELECT * FROM conditions " .
740  "WHERE target_obj_id = " . $ilDB->quote($a_target_obj_id, 'integer') . " " .
741  " AND target_type = " . $ilDB->quote($a_target_type, 'text');
742 
743  $res = $ilDB->query($query);
744  $rows = array();
745  while ($row = $ilDB->fetchAssoc($res)) {
746  $rows[] = $row;
747  }
748  }
749 
750  reset($rows);
751  $conditions = array();
752  foreach ($rows as $row) {
753  if ($row["ref_handling"] == self::UNIQUE_CONDITIONS) {
754  if ($row["target_ref_id"] != $a_target_ref_id) {
755  continue;
756  }
757  }
758 
759  $row["id"] = $row["condition_id"];
760  $conditions[] = $row;
761  }
762 
763  // write conditions for target cache
764  self::$cond_for_target_cache[$a_target_ref_id . ":" . $a_target_obj_id . ":" .
765  $a_target_type] = $conditions;
766 
767  return $conditions;
768  }
769 
776  public static function preloadConditionsForTargetRecords($a_type, $a_obj_ids)
777  {
778  global $ilDB;
779 
780  if (is_array($a_obj_ids) && count($a_obj_ids) > 0) {
781  $res = $ilDB->query("SELECT * FROM conditions " .
782  "WHERE " . $ilDB->in("target_obj_id", $a_obj_ids, false, "integer") .
783  " AND target_type = " . $ilDB->quote($a_type, 'text'));
784  $rows = array();
785  while ($row = $ilDB->fetchAssoc($res)) {
786  self::$cond_target_rows[$a_type . ":" . $row["target_obj_id"]][]
787  = $row;
788  }
789  // init obj ids without any record
790  foreach ($a_obj_ids as $obj_id) {
791  if (!is_array(self::$cond_target_rows[$a_type . ":" . $obj_id])) {
792  self::$cond_target_rows[$a_type . ":" . $obj_id] = array();
793  }
794  }
795  }
796  }
797 
798  public static function _getCondition($a_id)
799  {
800  global $ilDB;
801 
802  $query = "SELECT * FROM conditions " .
803  "WHERE condition_id = " . $ilDB->quote($a_id, 'integer');
804 
805  $res = $ilDB->query($query);
806  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
807  $tmp_array['id'] = $row->condition_id;
808  $tmp_array['target_ref_id'] = $row->target_ref_id;
809  $tmp_array['target_obj_id'] = $row->target_obj_id;
810  $tmp_array['target_type'] = $row->target_type;
811  $tmp_array['trigger_ref_id'] = $row->trigger_ref_id;
812  $tmp_array['trigger_obj_id'] = $row->trigger_obj_id;
813  $tmp_array['trigger_type'] = $row->trigger_type;
814  $tmp_array['operator'] = $row->operator;
815  $tmp_array['value'] = $row->value;
816  $tmp_array['ref_handling'] = $row->ref_handling;
817  $tmp_array['obligatory'] = $row->obligatory;
818  $tmp_array['hidden_status'] = $row->hidden_status;
819 
820  return $tmp_array;
821  }
822  return false;
823  }
824 
825 
826 
832  public static function _checkCondition($a_id, $a_usr_id = 0)
833  {
834  global $ilUser, $objDefinition;
835 
836  $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
837 
838  $condition = ilConditionHandler::_getCondition($a_id);
839 
840  // check lp
841  if ($condition['operator'] == self::OPERATOR_LP) {
842  include_once './Services/Tracking/classes/class.ilLPStatus.php';
843  return ilLPStatus::_hasUserCompleted($condition['trigger_obj_id'], $a_usr_id);
844  }
845 
846  switch ($condition['trigger_type']) {
847  case 'crsg':
848  include_once './Modules/Course/classes/class.ilObjCourseGrouping.php';
849  return ilObjCourseGrouping::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id);
850  }
851 
852  $class = $objDefinition->getClassName($condition['trigger_type']);
853  $location = $objDefinition->getLocation($condition['trigger_type']);
854  $full_class = "ilObj" . $class . "Access";
855  include_once($location . "/class." . $full_class . ".php");
856 
857  $fullfilled = call_user_func(
858  array($full_class, 'checkCondition'),
859  $condition['trigger_obj_id'],
860  $condition['operator'],
861  $condition['value'],
862  $a_usr_id
863  );
864  return $fullfilled;
865  }
866 
872  public static function getOptionalConditionsOfTarget($a_target_ref_id, $a_target_obj_id, $a_obj_type = '')
873  {
874  $conditions = self::_getConditionsOfTarget($a_target_ref_id, $a_target_obj_id);
875 
876  $opt = array();
877  foreach ($conditions as $con) {
878  if ($con['obligatory']) {
879  continue;
880  }
881 
882  $opt[] = $con;
883  }
884  return $opt;
885  }
886 
892  public static function lookupObligatoryConditionsOfTarget($a_target_ref_id, $a_target_obj_id)
893  {
894  global $ilDB;
895 
896  $query = 'SELECT max(num_obligatory) obl from conditions WHERE ' .
897  'target_ref_id = ' . $ilDB->quote($a_target_ref_id, 'integer') . ' ' .
898  'AND target_obj_id = ' . $ilDB->quote($a_target_obj_id, 'integer') . ' ' .
899  'GROUP BY (num_obligatory)';
900  $res = $ilDB->query($query);
901 
902  $obl = 0;
903  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
904  $obl = $row->obl;
905  }
906  return $obl;
907  }
908 
915  public static function calculateRequiredTriggers($a_target_ref_id, $a_target_obj_id, $a_target_obj_type = '', $a_force_update = false)
916  {
917  global $ilDB;
918 
919  // Get all conditions
920  $all = self::_getConditionsOfTarget($a_target_ref_id, $a_target_obj_id, $a_target_obj_type);
921  $opt = self::getOptionalConditionsOfTarget($a_target_ref_id, $a_target_obj_id, $a_target_obj_type);
922 
923  $set_obl = 0;
924  if (isset($all[0])) {
925  $set_obl = $all[0]['num_obligatory'];
926  }
927 
928  // existing value is valid
929  if ($set_obl > 0 and
930  $set_obl < count($all) and
931  $set_obl > (count($all) - count($opt) + 1)) {
932  return $set_obl;
933  }
934 
935  if (count($opt)) {
936  $result = count($all) - count($opt) + 1;
937  } else {
938  $result = count($all);
939  }
940  if ($a_force_update) {
941  self::saveNumberOfRequiredTriggers($a_target_ref_id, $a_target_obj_id, $result);
942  }
943  return $result;
944  }
945 
951  public static function saveNumberOfRequiredTriggers($a_target_ref_id, $a_target_obj_id, $a_num)
952  {
953  global $ilDB;
954 
955  $query = 'UPDATE conditions ' .
956  'SET num_obligatory = ' . $ilDB->quote($a_num, 'integer') . ' ' .
957  'WHERE target_ref_id = ' . $ilDB->quote($a_target_ref_id, 'integer') . ' ' .
958  'AND target_obj_id = ' . $ilDB->quote($a_target_obj_id, 'integer');
959  $ilDB->manipulate($query);
960  return;
961  }
962 
966  public static function _checkAllConditionsOfTarget($a_target_ref_id, $a_target_id, $a_target_type = "", $a_usr_id = 0)
967  {
968  global $ilBench,$ilUser,$tree;
969 
970  $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
971 
972  $conditions = ilConditionHandler::_getConditionsOfTarget($a_target_ref_id, $a_target_id, $a_target_type);
973 
974  if (!count($conditions)) {
975  return true;
976  }
977 
978  // @todo check this
979  include_once './Services/Container/classes/class.ilMemberViewSettings.php';
980  if (ilMemberViewSettings::getInstance()->isActive()) {
981  return true;
982  }
983 
984  // First check obligatory conditions
985  $optional = self::getOptionalConditionsOfTarget($a_target_ref_id, $a_target_id, $a_target_type);
986  $num_required = self::calculateRequiredTriggers($a_target_ref_id, $a_target_id, $a_target_type);
987  $passed = 0;
988  foreach ($conditions as $condition) {
989  if ($tree->isDeleted($condition['trigger_ref_id'])) {
990  continue;
991  }
992  $check = ilConditionHandler::_checkCondition($condition['id'], $a_usr_id);
993 
994  if ($check) {
995  ++$passed;
996  if ($passed >= $num_required) {
997  return true;
998  }
999  } else {
1000  if (!count($optional)) {
1001  return false;
1002  }
1003  }
1004  }
1005  // not all optional conditions passed
1006  return false;
1007  }
1008 
1009  // PRIVATE
1010  public function validate()
1011  {
1012  global $ilDB;
1013 
1014  // check if obj_id is already assigned
1015  $trigger_obj =&ilObjectFactory::getInstanceByRefId($this->getTriggerRefId());
1016  $target_obj =&ilObjectFactory::getInstanceByRefId($this->getTargetRefId());
1017 
1018 
1019  $query = "SELECT * FROM conditions WHERE " .
1020  "trigger_ref_id = " . $ilDB->quote($trigger_obj->getRefId(), 'integer') . " " .
1021  "AND target_ref_id = " . $ilDB->quote($target_obj->getRefId(), 'integer');
1022 
1023  $res = $this->db->query($query);
1024  if ($res->numRows() > 1) {
1025  $this->setErrorMessage($this->lng->txt('condition_already_assigned'));
1026 
1027  unset($trigger_obj);
1028  unset($target_obj);
1029  return false;
1030  }
1031 
1032  // check for circle
1033  $this->target_obj_id = $target_obj->getId();
1034  if ($this->checkCircle($this->getTargetRefId(), $target_obj->getId())) {
1035  $this->setErrorMessage($this->lng->txt('condition_circle_created'));
1036 
1037  unset($trigger_obj);
1038  unset($target_obj);
1039  return false;
1040  }
1041  return true;
1042  }
1043 
1044  public function checkCircle($a_ref_id, $a_obj_id)
1045  {
1046  foreach (ilConditionHandler::_getConditionsOfTarget($a_ref_id, $a_obj_id) as $condition) {
1047  if ($condition['trigger_obj_id'] == $this->target_obj_id and $condition['operator'] == $this->getOperator()) {
1048  $this->circle = true;
1049  break;
1050  } else {
1051  $this->checkCircle($condition['trigger_ref_id'], $condition['trigger_obj_id']);
1052  }
1053  }
1054  return $this->circle;
1055  }
1056 
1057  public static function cloneDependencies($a_src_ref_id, $a_target_ref_id, $a_copy_id)
1058  {
1059  include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
1060  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
1061  $mappings = $cwo->getMappings();
1062 
1063  $valid = 0;
1065  foreach ($conditions as $con) {
1066  if ($mappings[$con['trigger_ref_id']]) {
1067  $newCondition = new ilConditionHandler();
1068 
1069  $target_obj = ilObject::_lookupObjId($a_target_ref_id);
1070  $target_typ = ilObject::_lookupType($target_obj);
1071 
1072  $newCondition->setTargetRefId($a_target_ref_id);
1073  $newCondition->setTargetObjId($target_obj);
1074  $newCondition->setTargetType($target_typ);
1075 
1076  $trigger_ref = $mappings[$con['trigger_ref_id']];
1077  $trigger_obj = ilObject::_lookupObjId($trigger_ref);
1078  $trigger_typ = ilObject::_lookupType($trigger_obj);
1079 
1080  $newCondition->setTriggerRefId($trigger_ref);
1081  $newCondition->setTriggerObjId($trigger_obj);
1082  $newCondition->setTriggerType($trigger_typ);
1083  $newCondition->setOperator($con['operator']);
1084  $newCondition->setValue($con['value']);
1085  $newCondition->setReferenceHandlingType($con['ref_handling']);
1086  $newCondition->setObligatory($con['obligatory']);
1087 
1088  // :TODO: not sure about this
1089  $newCondition->setHiddenStatus(self::lookupHiddenStatusByTarget($a_src_ref_id));
1090 
1091  if ($newCondition->storeCondition()) {
1092  $valid++;
1093  }
1094  }
1095  }
1096  if ($valid) {
1097  $tgt_obj_id = ilObject::_lookupObjId($a_target_ref_id);
1098 
1099  // num_obligatory
1100  self::calculateRequiredTriggers($a_target_ref_id, $tgt_obj_id, ilObject::_lookupType($tgt_obj_id), true);
1101  }
1102  }
1103 }
static _checkCondition($a_id, $a_usr_id=0)
checks wether a single condition is fulfilled every trigger object type must implement a static metho...
storeCondition()
store new condition in database NOT STATIC public
static saveNumberOfRequiredTriggers($a_target_ref_id, $a_target_obj_id, $a_num)
Save number of obigatory triggers.
static _getConditionsOfTarget($a_target_ref_id, $a_target_obj_id, $a_target_type="")
get all conditions of target object
deleteByObjId($a_obj_id)
delete all trigger and target entries This method is called from ilObject::delete() if an object is r...
Set data validation
$result
$type
global $DIC
Definition: saml.php:7
setValue($a_value)
set value
$location
Definition: buildRTE.php:44
setTargetType($a_target_type)
set target object type
static lookupHiddenStatusByTarget($a_target_ref_id)
Lookup hidden status type $ilDB.
static isSupportedObjectType($a_type)
$valid
static _getConditionsOfTrigger($a_trigger_obj_type, $a_trigger_id)
get all conditions of trigger object
setTargetRefId($a_target_ref_id)
set target ref id
getTriggerRefId()
get target ref id
getObligatory()
Get obligatory status.
getReferenceHandlingType()
get reference handling type
static lookupObligatoryConditionsOfTarget($a_target_ref_id, $a_target_obj_id)
Lookup obligatory conditions of target.
setTriggerObjId($a_trigger_obj_id)
set trigger object id
static calculateRequiredTriggers($a_target_ref_id, $a_target_obj_id, $a_target_obj_type='', $a_force_update=false)
calculate number of obligatory items
getTargetRefId()
get target ref id
__construct()
constructor public
getTriggerTypes()
get all possible trigger types NOT STATIC public
static _checkCondition($trigger_obj_id, $operator, $value, $a_usr_id=0)
$a_type
Definition: workflow.php:92
getTargetObjId()
get target obj id
static preloadConditionsForTargetRecords($a_type, $a_obj_ids)
Preload conditions for target records.
static _enabledLearningProgress()
check wether learing progress is enabled or not
if($format !==null) $name
Definition: metadata.php:146
static _getInstance($a_copy_id)
Get instance of copy wizard options.
foreach($_POST as $key=> $value) $res
static _hasUserCompleted($a_obj_id, $a_user_id)
Lookup user object completion.
static _lookupObjId($a_id)
static getOptionalConditionsOfTarget($a_target_ref_id, $a_target_obj_id, $a_obj_type='')
Get optional conditions.
$ilUser
Definition: imgupload.php:18
static _getDistinctTargetRefIds()
Get all target ref ids.
static _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
getTriggerObjId()
get trigger obj id
static _deleteTargetConditionsByRefId($a_target_ref_id)
Delete conditions by target ref id Note: only conditions on the target type are deleted Conditions on...
$query
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
checkCircle($a_ref_id, $a_obj_id)
setTriggerType($a_trigger_type)
set trigger object type
Handles conditions for accesses to different ILIAS objects.
$rows
Definition: xhr_table.php:10
setTriggerRefId($a_trigger_ref_id)
set trigger ref id
getTriggerType()
get trigger obj type
setTargetObjId($a_target_obj_id)
set target object id
static _isReferenceHandlingOptional($a_type)
is reference handling optional
setOperator($a_operator)
set operator
static updateObligatory($a_id, $a_status)
Toggle condition obligatory status.
static _adjustMovedObjectConditions($a_ref_id)
In the moment it is not allowed to create preconditions on objects that are located outside of a cour...
static getInstance()
Get instance.
updateHiddenStatus($a_status)
Update hidden status type $ilDB.
setReferenceHandlingType($a_type)
set reference handling type
global $ilBench
Definition: ilias.php:18
setObligatory($a_obl)
Set obligatory status.
global $ilDB
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static cloneDependencies($a_src_ref_id, $a_target_ref_id, $a_copy_id)
deleteCondition($a_id)
delete condition
updateCondition($a_id)
update condition
getOperatorsByTargetType($a_type)
Get operators by target type.
static getNumberOfConditionsOfTrigger($a_trigger_obj_type, $a_trigger_id)
getTargetType()
get target obj type
enableAutomaticValidation($a_validate=true)
enable automated validation