ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
77
78 var $db;
79 var $lng;
80
81
83
91 var $value;
93
94
95 private $obligatory = true;
96 private $hidden_status = FALSE;
97
99 static $cond_for_target_cache = array();
100 static $cond_target_rows = array();
101
102
107 public function __construct()
108 {
109 global $ilDB,$lng;
110
111 $this->db =& $ilDB;
112 $this->lng =& $lng;
113 $this->validation = true;
114 }
115
124 public static function _isReferenceHandlingOptional($a_type)
125 {
126 switch($a_type)
127 {
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(DB_FETCHMODE_OBJECT))
149 {
150 return $row->hidden_status;
151 }
152 return FALSE;
153 }
154
165 public static function _adjustMovedObjectConditions($a_ref_id)
166 {
167 global $tree;
168
169 if($tree->checkForParentType($a_ref_id,'crs'))
170 {
171 // Nothing to do
172 return true;
173 }
174
175 // Need another implementation that has better performance
176 $childs = $tree->getSubTree($tree->getNodeData($a_ref_id),false);
178
179 foreach(array_intersect($conditions,$childs) as $target_ref)
180 {
181 if(!$tree->checkForParentType($target_ref,'crs'))
182 {
184 }
185 }
186 return true;
187 }
188
196 public static function _getDistinctTargetRefIds()
197 {
198 global $ilDB;
199
200 $query = "SELECT DISTINCT target_ref_id ref FROM conditions ";
201 $res = $ilDB->query($query);
202 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
203 {
204 $ref_ids[] = $row->ref;
205 }
206 return $ref_ids ? $ref_ids : array();
207 }
208
219 public static function _deleteTargetConditionsByRefId($a_target_ref_id)
220 {
221 global $ilDB;
222
223 $query = "DELETE FROM conditions ".
224 "WHERE target_ref_id = ".$ilDB->quote($a_target_ref_id,'integer')." ".
225 "AND target_type != 'st' ";
226 $res = $ilDB->manipulate($query);
227 return true;
228 }
229
237 public function setReferenceHandlingType($a_type)
238 {
239 return $this->condition_reference_type = $a_type;
240 }
241
248 public function getReferenceHandlingType()
249 {
250 return (int) $this->condition_reference_type;
251 }
252
253 // SET GET
254 function setErrorMessage($a_msg)
255 {
256 $this->error_message = $a_msg;
257 }
259 {
261 }
262
266 function setTargetRefId($a_target_ref_id)
267 {
268 return $this->target_ref_id = $a_target_ref_id;
269 }
270
274 function getTargetRefId()
275 {
277 }
278
282 function setTargetObjId($a_target_obj_id)
283 {
284 return $this->target_obj_id = $a_target_obj_id;
285 }
286
290 function getTargetObjId()
291 {
293 }
294
298 function setTargetType($a_target_type)
299 {
300 return $this->target_type = $a_target_type;
301 }
302
306 function getTargetType()
307 {
308 return $this->target_type;
309 }
310
314 function setTriggerRefId($a_trigger_ref_id)
315 {
316 return $this->trigger_ref_id = $a_trigger_ref_id;
317 }
318
323 {
325 }
326
330 function setTriggerObjId($a_trigger_obj_id)
331 {
332 return $this->trigger_obj_id = $a_trigger_obj_id;
333 }
334
339 {
341 }
342
346 function setTriggerType($a_trigger_type)
347 {
348 return $this->trigger_type = $a_trigger_type;
349 }
350
354 function getTriggerType()
355 {
356 return $this->trigger_type;
357 }
358
362 function setOperator($a_operator)
363 {
364 return $this->operator = $a_operator;
365 }
366
370 function getOperator()
371 {
372 return $this->operator;
373 }
374
378 function setValue($a_value)
379 {
380 return $this->value = $a_value;
381 }
382
386 function getValue()
387 {
388 return $this->value;
389 }
390
395 public function setObligatory($a_obl)
396 {
397 $this->obligatory = $a_obl;
398 }
399
404 public function getObligatory()
405 {
406 return (bool) $this->obligatory;
407 }
408
409 public function setHiddenStatus($a_status)
410 {
411 $this->hidden_status = $a_status;
412 }
413
414 public function getHiddenStatus()
415 {
417 }
418
419
423 function enableAutomaticValidation($a_validate = true)
424 {
425 $this->validation = $a_validate;
426 }
427
434 {
435 global $objDefinition;
436
437 $trigger_types = array('crs','exc','tst','sahs', 'svy', 'lm');
438
439 foreach($objDefinition->getPlugins() as $p_type => $p_info)
440 {
441 if(@include_once $p_info['location'].'/class.ilObj'.$p_info['class_name'].'Access.php')
442 {
443 include_once './Services/AccessControl/interfaces/interface.ilConditionHandling.php';
444 $name = 'ilObj'.$p_info['class_name'].'Access';
445 $refection = new ReflectionClass($name);
446 if($refection->implementsInterface('ilConditionHandling'))
447 {
448 $trigger_types[] = $p_type;
449 }
450 }
451 }
452
453
454 $active_triggers = array();
455 foreach($trigger_types as $type)
456 {
457 if(count($this->getOperatorsByTargetType($type)))
458 {
459 $active_triggers[] = $type;
460 }
461 }
462
463
464
465
466 return $active_triggers;
467 }
468
469
475 public function getOperatorsByTargetType($a_type)
476 {
477 global $objDefinition;
478
479 switch($a_type)
480 {
481 case 'crsg':
482 return array('not_member');
483 }
484
485 $class = $objDefinition->getClassName($a_type);
486 $location = $objDefinition->getLocation($a_type);
487 $full_class = "ilObj".$class."Access";
488 include_once($location."/class.".$full_class.".php");
489
490 include_once './Services/AccessControl/interfaces/interface.ilConditionHandling.php';
491
492 $reflection = new ReflectionClass($full_class);
493 if(!$reflection->implementsInterface('ilConditionHandling'))
494 {
495 return array();
496 }
497
498
499 $operators = call_user_func(
500 array($full_class, 'getConditionOperators'),
501 $a_type
502 );
503
504 // Add operator lp
505 include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
507 {
508 // only if object type has lp
509 include_once("Services/Object/classes/class.ilObjectLP.php");
511 {
512 array_unshift($operators,self::OPERATOR_LP);
513 }
514 }
515 return $operators;
516 }
517
523 function storeCondition()
524 {
525 global $ilDB;
526
527 // first insert, then validate: it's easier to check for circles if the new condition is in the db table
528 $next_id = $ilDB->nextId('conditions');
529 $query = 'INSERT INTO conditions (condition_id,target_ref_id,target_obj_id,target_type,'.
530 'trigger_ref_id,trigger_obj_id,trigger_type,operator,value,ref_handling,obligatory,hidden_status) '.
531 'VALUES ('.
532 $ilDB->quote($next_id,'integer').','.
533 $ilDB->quote($this->getTargetRefId(),'integer').",".
534 $ilDB->quote($this->getTargetObjId(),'integer').",".
535 $ilDB->quote($this->getTargetType(),'text').",".
536 $ilDB->quote($this->getTriggerRefId(),'integer').",".
537 $ilDB->quote($this->getTriggerObjId(),'integer').",".
538 $ilDB->quote($this->getTriggerType(),'text').",".
539 $ilDB->quote($this->getOperator(),'text').",".
540 $ilDB->quote($this->getValue(),'text').", ".
541 $ilDB->quote($this->getReferenceHandlingType(),'integer').', '.
542 $ilDB->quote($this->getObligatory(),'integer').', '.
543 $ilDB->quote($this->getHiddenStatus(),'integer').' '.
544 ')';
545
546 $res = $ilDB->manipulate($query);
547
548 if ($this->validation && !$this->validate())
549 {
550 $this->deleteCondition($next_id);
551 return false;
552 }
553 return true;
554 }
555
556 function checkExists()
557 {
558 global $ilDB;
559
560 $query = "SELECT * FROM conditions ".
561 "WHERE target_ref_id = ".$ilDB->quote($this->getTargetRefId(),'integer')." ".
562 "AND target_obj_id = ".$ilDB->quote($this->getTargetObjId(),'integer')." ".
563 "AND trigger_ref_id = ".$ilDB->quote($this->getTriggerRefId(),'integer')." ".
564 "AND trigger_obj_id = ".$ilDB->quote($this->getTriggerObjId(),'integer')." ".
565 "AND operator = ".$ilDB->quote($this->getOperator(),'text');
566 $res = $ilDB->query($query);
567
568 return $res->numRows() ? true : false;
569 }
573 function updateCondition($a_id)
574 {
575 global $ilDB;
576
577 $query = "UPDATE conditions SET ".
578 "target_ref_id = ".$ilDB->quote($this->getTargetRefId(),'integer').", ".
579 "operator = ".$ilDB->quote($this->getOperator(),'text').", ".
580 "value = ".$ilDB->quote($this->getValue(),'text').", ".
581 "ref_handling = ".$this->db->quote($this->getReferenceHandlingType(),'integer').", ".
582 'obligatory = '.$this->db->quote($this->getObligatory(),'integer').' '.
583 "WHERE condition_id = ".$ilDB->quote($a_id,'integer');
584 $res = $ilDB->manipulate($query);
585
586 return true;
587 }
588
596 public function updateHiddenStatus($a_status)
597 {
598 global $ilDB;
599
600 $query = 'UPDATE conditions SET '.
601 'hidden_status = '.$ilDB->quote($a_status,'integer').' '.
602 'WHERE target_ref_id = '.$ilDB->quote($this->getTargetRefId(),'integer');
603 $ilDB->manipulate($query);
604 return TRUE;
605 }
606
613 static function updateObligatory($a_id, $a_status)
614 {
615 global $ilDB;
616
617 $query = "UPDATE conditions SET ".
618 'obligatory = '.$ilDB->quote($a_status,'integer').' '.
619 "WHERE condition_id = ".$ilDB->quote($a_id,'integer');
620 $res = $ilDB->manipulate($query);
621
622 return true;
623 }
624
629 function delete($a_ref_id)
630 {
631 global $ilDB;
632
633 $query = "DELETE FROM conditions WHERE ".
634 "target_ref_id = ".$ilDB->quote($a_ref_id,'integer')." ".
635 "OR trigger_ref_id = ".$ilDB->quote($a_ref_id,'integer');
636 $res = $ilDB->manipulate($query);
637
638 return true;
639 }
644 function deleteByObjId($a_obj_id)
645 {
646 global $ilDB;
647
648 $query = "DELETE FROM conditions WHERE ".
649 "target_obj_id = ".$ilDB->quote($a_obj_id,'integer')." ".
650 "OR trigger_obj_id = ".$ilDB->quote($a_obj_id,'integer');
651 $res = $ilDB->manipulate($query);
652
653 return true;
654 }
655
659 function deleteCondition($a_id)
660 {
661 global $ilDB;
662
663 $query = "DELETE FROM conditions ".
664 "WHERE condition_id = ".$ilDB->quote($a_id,'integer');
665 $res = $ilDB->manipulate($query);
666
667 return true;
668 }
669
674 function _getConditionsOfTrigger($a_trigger_obj_type, $a_trigger_id)
675 {
676 global $ilDB;
677
678 $query = "SELECT * FROM conditions ".
679 "WHERE trigger_obj_id = ".$ilDB->quote($a_trigger_id,'integer')." ".
680 " AND trigger_type = ".$ilDB->quote($a_trigger_obj_type,'text');
681
682 $res = $ilDB->query($query);
683 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
684 {
685 $tmp_array['id'] = $row->condition_id;
686 $tmp_array['target_ref_id'] = $row->target_ref_id;
687 $tmp_array['target_obj_id'] = $row->target_obj_id;
688 $tmp_array['target_type'] = $row->target_type;
689 $tmp_array['trigger_ref_id'] = $row->trigger_ref_id;
690 $tmp_array['trigger_obj_id'] = $row->trigger_obj_id;
691 $tmp_array['trigger_type'] = $row->trigger_type;
692 $tmp_array['operator'] = $row->operator;
693 $tmp_array['value'] = $row->value;
694 $tmp_array['ref_handling'] = $row->ref_handling;
695 $tmp_array['obligatory'] = $row->obligatory;
696 $tmp_array['hidden_status'] = $row->hidden_status;
697
698 $conditions[] = $tmp_array;
699 unset($tmp_array);
700 }
701
702 return $conditions ? $conditions : array();
703 }
704
715 public static function _getConditionsOfTarget($a_target_ref_id,$a_target_obj_id, $a_target_type = "")
716 {
717 global $ilDB, $ilBench;
718
719 // get type if no type given
720 if ($a_target_type == "")
721 {
722 $a_target_type = ilObject::_lookupType($a_target_obj_id);
723 }
724
725 // check conditions for target cache
726 if (isset(self::$cond_for_target_cache[$a_target_ref_id.":".$a_target_obj_id.":".
727 $a_target_type]))
728 {
729 return self::$cond_for_target_cache[$a_target_ref_id.":".$a_target_obj_id.":".
730 $a_target_type];
731 }
732
733 // check rows cache
734 if (isset(self::$cond_target_rows[$a_target_type.":".$a_target_obj_id]))
735 {
736 $rows = self::$cond_target_rows[$a_target_type.":".$a_target_obj_id];
737 }
738 else
739 {
740 // query data from db
741 $query = "SELECT * FROM conditions ".
742 "WHERE target_obj_id = ".$ilDB->quote($a_target_obj_id,'integer')." ".
743 " AND target_type = ".$ilDB->quote($a_target_type,'text');
744
745 $res = $ilDB->query($query);
746 $rows = array();
747 while ($row = $ilDB->fetchAssoc($res))
748 {
749 $rows[] = $row;
750 }
751 }
752
753 reset($rows);
754 $conditions = array();
755 foreach ($rows as $row)
756 {
757 if ($row["ref_handling"] == self::UNIQUE_CONDITIONS)
758 {
759 if ($row["target_ref_id"] != $a_target_ref_id)
760 {
761 continue;
762 }
763 }
764
765 $row["id"] = $row["condition_id"];
766 $conditions[] = $row;
767 }
768
769 // write conditions for target cache
770 self::$cond_for_target_cache[$a_target_ref_id.":".$a_target_obj_id.":".
771 $a_target_type] = $conditions;
772
773 return $conditions;
774 }
775
782 function preloadConditionsForTargetRecords($a_type, $a_obj_ids)
783 {
784 global $ilDB;
785
786 if (is_array($a_obj_ids) && count($a_obj_ids) > 0)
787 {
788 $res = $ilDB->query("SELECT * FROM conditions ".
789 "WHERE ".$ilDB->in("target_obj_id", $a_obj_ids, false, "integer").
790 " AND target_type = ".$ilDB->quote($a_type,'text'));
791 $rows = array();
792 while ($row = $ilDB->fetchAssoc($res))
793 {
794 self::$cond_target_rows[$a_type.":".$row["target_obj_id"]][]
795 = $row;
796 }
797 // init obj ids without any record
798 foreach ($a_obj_ids as $obj_id)
799 {
800 if (!is_array(self::$cond_target_rows[$a_type.":".$obj_id]))
801 {
802 self::$cond_target_rows[$a_type.":".$obj_id] = array();
803 }
804 }
805 }
806 }
807
808 function _getCondition($a_id)
809 {
810 global $ilDB;
811
812 $query = "SELECT * FROM conditions ".
813 "WHERE condition_id = ".$ilDB->quote($a_id,'integer');
814
815 $res = $ilDB->query($query);
816 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
817 {
818 $tmp_array['id'] = $row->condition_id;
819 $tmp_array['target_ref_id'] = $row->target_ref_id;
820 $tmp_array['target_obj_id'] = $row->target_obj_id;
821 $tmp_array['target_type'] = $row->target_type;
822 $tmp_array['trigger_ref_id'] = $row->trigger_ref_id;
823 $tmp_array['trigger_obj_id'] = $row->trigger_obj_id;
824 $tmp_array['trigger_type'] = $row->trigger_type;
825 $tmp_array['operator'] = $row->operator;
826 $tmp_array['value'] = $row->value;
827 $tmp_array['ref_handling'] = $row->ref_handling;
828 $tmp_array['obligatory'] = $row->obligatory;
829 $tmp_array['hidden_status'] = $row->hidden_status;
830
831 return $tmp_array;
832 }
833 return false;
834 }
835
836
837
843 function _checkCondition($a_id,$a_usr_id = 0)
844 {
845 global $ilUser, $objDefinition;
846
847 $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
848
849 $condition = ilConditionHandler::_getCondition($a_id);
850
851 // check lp
852 if($condition['operator'] == self::OPERATOR_LP)
853 {
854 include_once './Services/Tracking/classes/class.ilLPStatus.php';
855 return ilLPStatus::_hasUserCompleted($condition['trigger_obj_id'], $a_usr_id);
856 }
857
858 switch($condition['trigger_type'])
859 {
860 case 'crsg':
861 include_once './Modules/Course/classes/class.ilObjCourseGrouping.php';
862 return ilObjCourseGrouping::_checkCondition($condition['trigger_obj_id'],$condition['operator'],$condition['value'],$a_usr_id);
863 }
864
865 $class = $objDefinition->getClassName($condition['trigger_type']);
866 $location = $objDefinition->getLocation($condition['trigger_type']);
867 $full_class = "ilObj".$class."Access";
868 include_once($location."/class.".$full_class.".php");
869
870 $fullfilled = call_user_func(
871 array($full_class, 'checkCondition'),
872 $condition['trigger_obj_id'],
873 $condition['operator'],
874 $condition['value'],
875 $a_usr_id
876 );
877 return $fullfilled;
878 }
879
885 public static function getOptionalConditionsOfTarget($a_target_ref_id,$a_target_obj_id,$a_obj_type = '')
886 {
887 $conditions = self::_getConditionsOfTarget($a_target_ref_id,$a_target_obj_id);
888
889 $opt = array();
890 foreach($conditions as $con)
891 {
892 if($con['obligatory'])
893 {
894 continue;
895 }
896
897 $opt[] = $con;
898 }
899 return $opt;
900 }
901
908 public static function calculateRequiredTriggers($a_target_ref_id,$a_target_obj_id,$a_target_obj_type = '', $a_force_update = false)
909 {
910 global $ilDB;
911
912 // Get all conditions
913 $all = self::_getConditionsOfTarget($a_target_ref_id,$a_target_obj_id,$a_target_obj_type);
914 $opt = self::getOptionalConditionsOfTarget($a_target_ref_id, $a_target_obj_id,$a_target_obj_type);
915
916 $set_obl = 0;
917 if(isset($all[0]))
918 {
919 $set_obl = $all[0]['num_obligatory'];
920 }
921
922 // existing value is valid
923 if($set_obl > 0 and
924 $set_obl < count($all) and
925 $set_obl > (count($all) - count($opt) + 1))
926 {
927 return $set_obl;
928 }
929
930 if(count($opt))
931 {
932 $result = count($all) - count($opt) + 1;
933 }
934 else
935 {
936 $result = count($all);
937 }
938 if($a_force_update)
939 {
940 self::saveNumberOfRequiredTriggers($a_target_ref_id,$a_target_obj_id,$result);
941 }
942 return $result;
943 }
944
950 public static function saveNumberOfRequiredTriggers($a_target_ref_id,$a_target_obj_id,$a_num)
951 {
952 global $ilDB;
953
954 $query = 'UPDATE conditions '.
955 'SET num_obligatory = '.$ilDB->quote($a_num,'integer').' '.
956 'WHERE target_ref_id = '.$ilDB->quote($a_target_ref_id,'integer').' '.
957 'AND target_obj_id = '.$ilDB->quote($a_target_obj_id,'integer');
958 $ilDB->manipulate($query);
959 return;
960 }
961
965 function _checkAllConditionsOfTarget($a_target_ref_id,$a_target_id, $a_target_type = "",$a_usr_id = 0)
966 {
967 global $ilBench,$ilUser,$tree;
968
969 $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
970
971 $conditions = ilConditionHandler::_getConditionsOfTarget($a_target_ref_id,$a_target_id, $a_target_type);
972
973 if(!count($conditions))
974 {
975 return true;
976 }
977
978 // @todo check this
979 include_once './Services/Container/classes/class.ilMemberViewSettings.php';
980 if(ilMemberViewSettings::getInstance()->isActive())
981 {
982 return true;
983 }
984
985 // First check obligatory conditions
986 $optional = self::getOptionalConditionsOfTarget($a_target_ref_id, $a_target_id, $a_target_type);
987 $num_required = self::calculateRequiredTriggers($a_target_ref_id, $a_target_id, $a_target_type);
988 $passed = 0;
989 foreach($conditions as $condition)
990 {
991 if($tree->isDeleted($condition['trigger_ref_id']))
992 {
993 continue;
994 }
995 $check = ilConditionHandler::_checkCondition($condition['id'],$a_usr_id);
996
997 if($check)
998 {
999 ++$passed;
1000 if($passed >= $num_required)
1001 {
1002 return true;
1003 }
1004 }
1005 else
1006 {
1007 if(!count($optional))
1008 {
1009 return false;
1010 }
1011 }
1012 }
1013 // not all optional conditions passed
1014 return false;
1015 }
1016
1017 // PRIVATE
1018 function validate()
1019 {
1020 global $ilDB;
1021
1022 // check if obj_id is already assigned
1023 $trigger_obj =& ilObjectFactory::getInstanceByRefId($this->getTriggerRefId());
1024 $target_obj =& ilObjectFactory::getInstanceByRefId($this->getTargetRefId());
1025
1026
1027 $query = "SELECT * FROM conditions WHERE ".
1028 "trigger_ref_id = ".$ilDB->quote($trigger_obj->getRefId(),'integer')." ".
1029 "AND target_ref_id = ".$ilDB->quote($target_obj->getRefId(),'integer');
1030
1031 $res = $this->db->query($query);
1032 if($res->numRows() > 1)
1033 {
1034 $this->setErrorMessage($this->lng->txt('condition_already_assigned'));
1035
1036 unset($trigger_obj);
1037 unset($target_obj);
1038 return false;
1039 }
1040
1041 // check for circle
1042 $this->target_obj_id = $target_obj->getId();
1043 if($this->checkCircle($this->getTargetRefId(),$target_obj->getId()))
1044 {
1045 $this->setErrorMessage($this->lng->txt('condition_circle_created'));
1046
1047 unset($trigger_obj);
1048 unset($target_obj);
1049 return false;
1050 }
1051 return true;
1052 }
1053
1054 function checkCircle($a_ref_id,$a_obj_id)
1055 {
1056 foreach(ilConditionHandler::_getConditionsOfTarget($a_ref_id,$a_obj_id) as $condition)
1057 {
1058 if($condition['trigger_obj_id'] == $this->target_obj_id and $condition['operator'] == $this->getOperator())
1059 {
1060 $this->circle = true;
1061 break;
1062 }
1063 else
1064 {
1065 $this->checkCircle($condition['trigger_ref_id'],$condition['trigger_obj_id']);
1066 }
1067 }
1068 return $this->circle;
1069 }
1070
1071 public static function cloneDependencies($a_src_ref_id, $a_target_ref_id, $a_copy_id)
1072 {
1073 include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
1074 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
1075 $mappings = $cwo->getMappings();
1076
1077 $valid = 0;
1079 foreach($conditions as $con)
1080 {
1081 if($mappings[$con['trigger_ref_id']])
1082 {
1083 $newCondition = new ilConditionHandler();
1084
1085 $target_obj = ilObject::_lookupObjId($a_target_ref_id);
1086 $target_typ = ilObject::_lookupType($target_obj);
1087
1088 $newCondition->setTargetRefId($a_target_ref_id);
1089 $newCondition->setTargetObjId($target_obj);
1090 $newCondition->setTargetType($target_typ);
1091
1092 $trigger_ref = $mappings[$con['trigger_ref_id']];
1093 $trigger_obj = ilObject::_lookupObjId($trigger_ref);
1094 $trigger_typ = ilObject::_lookupType($trigger_obj);
1095
1096 $newCondition->setTriggerRefId($trigger_ref);
1097 $newCondition->setTriggerObjId($trigger_obj);
1098 $newCondition->setTriggerType($trigger_typ);
1099 $newCondition->setOperator($con['operator']);
1100 $newCondition->setValue($con['value']);
1101 $newCondition->setReferenceHandlingType($con['ref_handling']);
1102 $newCondition->setObligatory($con['obligatory']);
1103
1104 // :TODO: not sure about this
1105 $newCondition->setHiddenStatus(self::lookupHiddenStatusByTarget($a_src_ref_id));
1106
1107 if($newCondition->storeCondition())
1108 {
1109 $valid++;
1110 }
1111 }
1112 }
1113 if($valid)
1114 {
1115 $tgt_obj_id = ilObject::_lookupObjId($a_target_ref_id);
1116
1117 // num_obligatory
1118 self::calculateRequiredTriggers($a_target_ref_id, $tgt_obj_id, ilObject::_lookupType($tgt_obj_id), true);
1119 }
1120 }
1121}
1122
1123?>
$result
$location
Definition: buildRTE.php:44
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
Handles conditions for accesses to different ILIAS objects.
getTargetType()
get target obj type
setTargetType($a_target_type)
set target object type
setTargetObjId($a_target_obj_id)
set target object id
getTriggerRefId()
get target ref id
setTriggerRefId($a_trigger_ref_id)
set trigger ref id
getTriggerTypes()
get all possible trigger types NOT STATIC @access public
getTargetRefId()
get target ref id
_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
getTriggerType()
get trigger obj type
__construct()
constructor @access public
deleteCondition($a_id)
delete condition
static getOptionalConditionsOfTarget($a_target_ref_id, $a_target_obj_id, $a_obj_type='')
Get optional conditions.
getOperatorsByTargetType($a_type)
Get operators by target type.
getReferenceHandlingType()
get reference handling type
getObligatory()
Get obligatory status.
static _deleteTargetConditionsByRefId($a_target_ref_id)
Delete conditions by target ref id Note: only conditions on the target type are deleted Conditions on...
preloadConditionsForTargetRecords($a_type, $a_obj_ids)
Preload conditions for target records.
storeCondition()
store new condition in database NOT STATIC @access public
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 calculateRequiredTriggers($a_target_ref_id, $a_target_obj_id, $a_target_obj_type='', $a_force_update=false)
calculate number of obligatory items
setTargetRefId($a_target_ref_id)
set target ref id
setOperator($a_operator)
set operator
enableAutomaticValidation($a_validate=true)
enable automated validation
setReferenceHandlingType($a_type)
set reference handling type
static _getDistinctTargetRefIds()
Get all target ref ids.
setObligatory($a_obl)
Set obligatory status.
static cloneDependencies($a_src_ref_id, $a_target_ref_id, $a_copy_id)
_getConditionsOfTrigger($a_trigger_obj_type, $a_trigger_id)
get all conditions of trigger object
static saveNumberOfRequiredTriggers($a_target_ref_id, $a_target_obj_id, $a_num)
Save number of obigatory triggers.
setTriggerType($a_trigger_type)
set trigger object type
updateHiddenStatus($a_status)
Update hidden status @global type $ilDB.
checkCircle($a_ref_id, $a_obj_id)
getTargetObjId()
get target obj id
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...
static lookupHiddenStatusByTarget($a_target_ref_id)
Lookup hidden status @global type $ilDB.
updateCondition($a_id)
update condition
setTriggerObjId($a_trigger_obj_id)
set trigger object id
_checkCondition($a_id, $a_usr_id=0)
checks wether a single condition is fulfilled every trigger object type must implement a static metho...
getTriggerObjId()
get trigger obj id
static _isReferenceHandlingOptional($a_type)
is reference handling optional
static updateObligatory($a_id, $a_status)
Toggle condition obligatory status.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
static _hasUserCompleted($a_obj_id, $a_user_id)
Lookup user object completion.
static getInstance()
Get instance.
_checkCondition($trigger_obj_id, $operator, $value, $a_usr_id=0)
static _enabledLearningProgress()
check wether learing progress is enabled or not
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static isSupportedObjectType($a_type)
static _lookupObjId($a_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
$valid
global $ilBench
Definition: ilias.php:18
global $ilDB
global $ilUser
Definition: imgupload.php:15