34 define(
'IL_CRS_TIMINGS_ACTIVATION',0);
35 define(
'IL_CRS_TIMINGS_DEACTIVATED',1);
36 define(
'IL_CRS_TIMINGS_PRESETTING',2);
37 define(
'IL_CRS_TIMINGS_FIXED',3);
65 $this->user_id = $user_id;
82 global $ilObjDataCache,
$ilLog;
84 $ilLog->write(__METHOD__.
': Begin course items...');
86 $target_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
88 include_once(
'Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
90 $mappings = $cp_options->getMappings();
92 $query =
"SELECT * FROM crs_items WHERE ".
93 "parent_id = ".$this->ilDB->quote($this->
getParentId()).
" ";
94 $res = $this->ilDB->query($query);
98 $ilLog->write(__METHOD__.
': No course items found.');
105 $ilLog->write(__METHOD__.
': Cannot create target object.');
108 $new_items =
new ilCourseItems($this->course_obj,$a_target_id);
111 if(!isset($mappings[$row->parent_id]) or !$mappings[$row->parent_id])
113 $ilLog->write(__METHOD__.
': No mapping for parent nr. '.$row->parent_id);
116 if(!isset($mappings[$row->obj_id]) or !$mappings[$row->obj_id])
118 $ilLog->write(__METHOD__.
': No mapping for item nr. '.$row->obj_id);
121 $new_item_id = $mappings[$row->obj_id];
122 $new_parent = $mappings[$row->parent_id];
124 $new_items->setItemId($new_item_id);
125 $new_items->setParentId($new_parent);
126 $new_items->setTimingType($row->timing_type);
127 $new_items->setTimingStart($row->timing_start);
128 $new_items->setTimingEnd($row->timing_end);
129 $new_items->setSuggestionStart($row->suggestion_start);
130 $new_items->setSuggestionEnd($row->suggestion_end);
131 $new_items->toggleChangeable($row->changeable);
132 $new_items->setEarliestStart($row->earliest_start);
133 $new_items->setLatestEnd($row->latest_end);
134 $new_items->toggleVisible($row->visible);
135 $new_items->update($new_item_id);
136 $ilLog->write(__METHOD__.
': Added new entry for item nr. '.$row->obj_id);
138 $ilLog->write(__METHOD__.
': Finished course items.');
143 $this->item_id = $a_item_id;
148 return $this->item_id;
154 return $this->user_id ? $this->user_id : $ilUser->getId();
162 include_once
'Services/Tracking/classes/class.ilLPObjSettings.php';
164 $obj_id = $ilObjDataCache->lookupObjId($a_ref_id);
169 include_once
'Services/Tracking/classes/class.ilLPCollectionCache.php';
173 $ids = array($a_ref_id);
181 $query =
"SELECT * FROM crs_items ".
185 $res = $ilDB->query($query);
186 return $res->numRows() ?
true :
false;
200 $subtree = $tree->getSubTree($tree->getNodeData($a_ref_id));
202 foreach($subtree as $node)
204 $ref_ids[] = $node[
'ref_id'];
207 $query =
"SELECT * FROM crs_items ".
212 $res = $ilDB->query($query);
213 return $res->numRows() ?
true :
false;
220 $subtree = $tree->getSubTree($tree->getNodeData($a_ref_id));
222 foreach($subtree as $node)
224 $ref_ids[] = $node[
'ref_id'];
227 $query =
"SELECT * FROM crs_items ".
229 "AND changeable = '1' ".
233 $res = $ilDB->query($query);
234 return $res->numRows() ?
true :
false;
239 $this->parent = $a_parent ? $a_parent : $this->course_obj->getRefId();
252 $this->timing_type = $a_type;
261 $this->timing_start = $a_start;
269 $this->timing_end = $a_end;
277 $this->suggestion_start = $a_start;
281 return $this->suggestion_start ? $this->suggestion_start : mktime(0,0,1,date(
'n',time()),date(
'j',time()),date(
'Y',time()));
285 $this->suggestion_end = $a_end;
289 return $this->suggestion_end ? $this->suggestion_end : mktime(23,55,00,date(
'n',time()),date(
'j',time()),date(
'Y',time()));
293 $this->earliest_start = $a_start;
297 return $this->earliest_start ? $this->earliest_start : mktime(0,0,1,date(
'n',time()),date(
'j',time()),date(
'Y',time()));
301 $this->latest_end = $a_end;
305 return $this->latest_end ? $this->latest_end : mktime(23,55,00,date(
'n',time()),date(
'j',time()),date(
'Y',time()));
309 $this->visible = (int) $a_status;
313 return (
bool) $this->visible;
317 $this->changeable = (int) $a_status;
321 return (
bool) $this->changeable;
326 $this->position = $a_pos;
331 return $this->items ? $this->items : array();
339 global $objDefinition;
341 include_once
'Modules/Session/classes/class.ilEventItems.php';
344 foreach($this->items as $item)
346 if(!in_array($item[
'ref_id'],$event_items) &&
347 !$objDefinition->isSideBlock($item[
'type']))
352 return $filtered ? $filtered : array();
357 include_once
'Modules/Session/classes/class.ilEventItems.php';
360 $event_items = $event_items_obj->getItems();
361 foreach($event_items as $item)
363 if($this->tree->isDeleted($item))
367 $node = $this->tree->getNodeData($item);
375 include_once(
'./Modules/Course/classes/class.ilCourseObjectiveMaterials.php');
379 if($this->tree->isDeleted($ref_id))
383 $node = $this->tree->getNodeData($ref_id);
394 foreach($this->items as $item)
396 if($item[
"type"] !=
"rolf" and
397 ($item[
"timing_type"] or
398 ($item[
"timing_start"] <= time() and $item[
"timing_end"] >= time())))
400 if($rbacsystem->checkAccess(
'visible',$item[
'ref_id']))
406 return $filtered ? $filtered : array();
410 foreach($this->items as $item)
412 if($item[
"child"] == $a_item_id)
424 $ilErr->setMessage(
'');
430 $ilErr->appendMessage($this->lng->txt(
"crs_activation_start_invalid"));
437 $ilErr->appendMessage($this->lng->txt(
'crs_latest_end_not_valid'));
441 #if($this->getTimingType() == IL_CRS_TIMINGS_PRESETTING and
442 # $this->enabledChangeable())
444 # if($this->getSuggestionStart() < $this->getEarliestStart() or
445 # $this->getSuggestionEnd() > $this->getLatestEnd() or
446 # $this->getSuggestionStart() > $this->getLatestEnd() or
447 # $this->getSuggestionEnd() < $this->getEarliestStart())
449 # $ilErr->appendMessage($this->lng->txt("crs_suggestion_not_within_activation"));
453 if($ilErr->getMessage())
470 $query =
"INSERT INTO crs_items SET ".
473 "timing_end = ".$ilDB->quote($this->
getTimingEnd()).
", ".
478 "latest_end = ".$ilDB->quote($this->
getLatestEnd()).
", ".
480 "parent_id = ".$ilDB->quote($this->
getParentId()).
", ".
481 "obj_id = ".$ilDB->quote($this->
getItemId()).
" ";
482 $ilLog->write(__METHOD__.
': '.$query);
484 $res = $this->ilDB->query($query);
492 $query =
"UPDATE crs_items SET ".
495 "timing_end = ".$ilDB->quote($this->
getTimingEnd()).
", ".
500 "latest_end = ".$ilDB->quote($this->
getLatestEnd()).
", ".
502 "WHERE parent_id = ".$ilDB->quote($this->
getParentId()).
" ".
503 "AND obj_id = ".$ilDB->quote($a_item_id).
"";
505 $res = $this->ilDB->query($query);
529 $all_items = $this->tree->getChilds($this->parent);
531 foreach($all_items as $item)
533 $query =
"DELETE FROM crs_items ".
534 "WHERE parent_id = ".$ilDB->quote($item[
"child"]).
"";
536 $this->ilDB->query($query);
538 $query =
"DELETE FROM crs_items ".
539 "WHERE parent_id = ".$ilDB->quote($this->course_obj->getRefId()).
" ";
541 $this->ilDB->query($query);
551 $this->items = array();
553 $ilBench->start(
"Course",
"ilCouseItems_read - getChilds");
554 $all_items = $this->tree->getChilds($this->parent);
555 $ilBench->stop(
"Course",
"ilCouseItems_read - getChilds");
557 foreach($all_items as $item)
559 if($item[
"type"] !=
'rolf')
561 $this->items[] = $item;
564 $ilBench->start(
"Course",
"ilCouseItems_read - getItemData");
565 for($i = 0;$i < count($this->items); ++$i)
567 if($this->items[$i][
"type"] ==
'rolf')
569 unset($this->items[$i]);
574 $ilBench->stop(
"Course",
"ilCouseItems_read - getItemData");
576 $ilBench->start(
"Course",
"ilCouseItems_read - purge and sort");
579 $ilBench->stop(
"Course",
"ilCouseItems_read - purge and sort");
582 $this->items_per_child = array();
583 foreach($this->items as $item)
585 $this->items_per_child[$item[
"child"]] = $item;
597 $query =
"SELECT obj_id FROM crs_items ".
598 "WHERE parent_id = ".$ilDB->quote($this->
getParentId()).
" ";
600 $res = $this->ilDB->query($query);
603 if($tree->getParentId($row->obj_id) != $this->
getParentId())
615 $query =
"DELETE FROM crs_items ".
616 "WHERE parent_id = ".$ilDB->quote($this->
getParentId()).
" ".
617 "AND obj_id = ".$ilDB->quote($a_obj_id).
" ";
619 $res = $this->ilDB->query($query);
628 $ilBench->start(
"Course",
"ilCourseItems_getItemData - 1");
629 $query =
"SELECT * FROM crs_items ".
630 "WHERE obj_id = ".$ilDB->quote($a_item[
'child']).
" ".
631 "AND parent_id = ".$ilDB->quote($a_item[
'parent']).
" ";
632 $res = $this->ilDB->query($query);
633 $ilBench->stop(
"Course",
"ilCourseItems_getItemData - 1");
636 $ilBench->start(
"Course",
"ilCourseItems_getItemData - 2");
637 $a_item[
"timing_type"] = $row->timing_type;
638 $a_item[
"timing_start"] = $row->timing_start;
639 $a_item[
"timing_end"] = $row->timing_end;
640 $a_item[
"suggestion_start"] = $row->suggestion_start ? $row->suggestion_start :
641 mktime(0,0,1,date(
'n',time()),date(
'j',time()),date(
'Y',time()));
642 $a_item[
"suggestion_end"] = $row->suggestion_end ? $row->suggestion_end :
643 mktime(23,55,00,date(
'n',time()),date(
'j',time()),date(
'Y',time()));
644 $a_item[
'changeable'] = $row->changeable;
645 $a_item[
'earliest_start'] = $row->earliest_start ? $row->earliest_start :
646 mktime(0,0,1,date(
'n',time()),date(
'j',time()),date(
'Y',time()));
647 $a_item[
'latest_end'] = $row->latest_end ? $row->latest_end :
648 mktime(23,55,00,date(
'n',time()),date(
'j',time()),date(
'Y',time()));
649 $a_item[
'visible'] = $row->visible;
651 include_once
'Modules/Course/classes/Timings/class.ilTimingPlaned.php';
653 $ilBench->stop(
"Course",
"ilCourseItems_getItemData - 2");
655 $ilBench->start(
"Course",
"ilCourseItems_getItemData - 3");
658 $obj_id = ($a_item[
'obj_id'] > 0)
660 : $ilObjDataCache->lookupObjId($row->obj_id);
661 $obj_type = ($a_item[
'type'] !=
"")
663 : $ilObjDataCache->lookupType($obj_id);
666 $ilBench->stop(
"Course",
"ilCourseItems_getItemData - 3");
671 $ilBench->start(
"Course",
"ilCourseItems_getItemData - 4");
672 if($a_item[
'changeable'] and
675 if(
$data[
'planed_start'])
677 $a_item[
'start'] =
$data[
'planed_start'];
678 $a_item[
'end'] =
$data[
'planed_end'];
679 $a_item[
'activation_info'] =
'crs_timings_planed_info';
683 $a_item[
'start'] = $row->suggestion_start;
684 $a_item[
'end'] = $row->suggestion_end;
685 $a_item[
'activation_info'] =
'crs_timings_suggested_info';
690 $a_item[
'start'] = $row->suggestion_start;
691 $a_item[
'end'] = $row->suggestion_end;
692 $a_item[
'activation_info'] =
'crs_timings_suggested_info';
696 $a_item[
'start'] = $row->timing_start;
697 $a_item[
'end'] = $row->timing_end;
698 $a_item[
'activation_info'] =
'activation';
700 elseif($obj_type ==
'sess')
702 include_once(
'./Modules/Session/classes/class.ilSessionAppointment.php');
704 $ilBench->start(
"Course",
"ilCourseItems_getItemData - lookupAppointment");
706 $ilBench->stop(
"Course",
"ilCourseItems_getItemData - lookupAppointment");
709 $a_item[
'start'] = $info[
'start'];
710 $a_item[
'end'] = $info[
'end'];
711 $a_item[
'fullday'] = $info[
'fullday'];
712 $a_item[
'activation_info'] =
'crs_timings_suggested_info';
716 $a_item[
'start'] = 999999999;
718 $ilBench->stop(
"Course",
"ilCourseItems_getItemData - 4");
721 $ilBench->start(
"Course",
"ilCourseItems_getItemData - 5");
722 if(!isset($a_item[
"timing_start"]))
726 $ilBench->stop(
"Course",
"ilCourseItems_getItemData - 5");
733 global
$ilDB, $objDefinition;
736 $a_item[
"timing_start"] = time();
737 $a_item[
"timing_end"] = time();
738 $a_item[
"suggestion_start"] = time();
739 $a_item[
"suggestion_end"] = time();
740 $a_item[
'visible'] = 0;
741 $a_item[
'changeable'] = 0;
742 $a_item[
'earliest_start'] = time();
743 $a_item[
'latest_end'] = mktime(23,55,00,date(
'n',time()),date(
'j',time()),date(
'Y',time()));
744 $a_item[
'visible'] = 0;
745 $a_item[
'changeable'] = 0;
748 $query =
"INSERT INTO crs_items ".
749 "VALUES(".$ilDB->quote($a_item[
'parent']).
",".
750 $ilDB->quote($a_item[
"child"]).
",".
751 $ilDB->quote($a_item[
"timing_type"]).
",".
752 $ilDB->quote($a_item[
"timing_start"]).
",".
753 $ilDB->quote($a_item[
"timing_end"]).
",".
754 $ilDB->quote($a_item[
"suggestion_start"]).
",".
755 $ilDB->quote($a_item[
"suggestion_end"]).
",".
756 $ilDB->quote($a_item[
"changeable"]).
",".
757 $ilDB->quote($a_item[
'earliest_start']).
", ".
758 $ilDB->quote($a_item[
'latest_end']).
", ".
759 $ilDB->quote($a_item[
"visible"]).
", ".
762 $res = $this->ilDB->query($query);
772 $query =
"SELECT MAX(position) as last_position FROM crs_items ".
773 "WHERE parent_id = ".$ilDB->quote($this->
getParentId()).
" ";
775 $res = $this->ilDB->query($query);
778 $max = $row->last_position;
780 return $max ? $max : 0;
787 include_once
'Modules/Session/classes/class.ilEventItems.php';
789 global $ilObjDataCache;
791 if($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($a_ref_id)) !=
'crs')
806 if(!$node_b[
"obj_id"])
811 $query =
"UPDATE crs_items SET ".
812 "position = ".$ilDB->quote($node_a[
"position"]).
" ".
813 "WHERE obj_id = ".$ilDB->quote($node_b[
"obj_id"]).
" ".
814 "AND parent_id = ".$ilDB->quote($this->
getParentId()).
"";
816 $res = $this->ilDB->query($query);
818 $query =
"UPDATE crs_items SET ".
819 "position = ".$ilDB->quote($node_b[
"position"]).
" ".
820 "WHERE obj_id = ".$ilDB->quote($node_a[
"obj_id"]).
" ".
821 "AND parent_id = ".$ilDB->quote($this->
getParentId()).
"";
823 $res = $this->ilDB->query($query);
836 public static function _sort($a_sort_mode,$a_items)
843 $inactive = $active = array();
844 foreach($a_items as $item)
858 return array_merge($sorted_active,$sorted_inactive);
871 switch($this->course_obj->getOrderType())
881 $this->items = array_merge($sorted_active,$sorted_inactive);
892 $inactive = $active = array();
893 foreach($this->items as $item)
904 return array($active,$inactive);
909 include_once
'Modules/Course/classes/class.ilObjCourse.php';
911 global
$ilDB,$ilUser;
913 $query =
"SELECT * FROM crs_items ".
914 "WHERE obj_id = ".$ilDB->quote($a_item_id).
" ";
915 $res = $ilDB->query($query);
918 $data[
'parent_id'] = $row->parent_id;
919 $data[
'obj_id'] = $row->obj_id;
920 $data[
'timing_type'] = $row->timing_type;
921 $data[
'timing_start'] = $row->timing_start;
922 $data[
'timing_end'] = $row->timing_end;
923 $data[
"suggestion_start"] = $row->suggestion_start ? $row->suggestion_start :
924 mktime(0,0,1,date(
'n',time()),date(
'j',time()),date(
'Y',time()));
925 $data[
"suggestion_end"] = $row->suggestion_end ? $row->suggestion_end :
926 mktime(23,55,00,date(
'n',time()),date(
'j',time()),date(
'Y',time()));
927 $data[
'changeable'] = $row->changeable;
928 $data[
'earliest_start'] = $row->earliest_start ? $row->earliest_start :
929 mktime(0,0,1,date(
'n',time()),date(
'j',time()),date(
'Y',time()));
930 $data[
'latest_end'] = $row->latest_end ? $row->latest_end :
931 mktime(23,55,00,date(
'n',time()),date(
'j',time()),date(
'Y',time()));
932 $data[
'visible'] = $row->visible;
934 include_once
'Modules/Course/classes/Timings/class.ilTimingPlaned.php';
938 if(
$data[
'changeable'] and
941 if($user_data[
'planed_start'])
943 $data[
'start'] = $user_data[
'planed_start'];
944 $data[
'end'] = $user_data[
'planed_end'];
945 $data[
'activation_info'] =
'crs_timings_planed_info';
949 $data[
'start'] = $row->suggestion_start;
950 $data[
'end'] = $row->suggestion_end;
951 $data[
'activation_info'] =
'crs_timings_suggested_info';
956 $data[
'start'] = $row->suggestion_start;
957 $data[
'end'] = $row->suggestion_end;
958 $data[
'activation_info'] =
'crs_timings_suggested_info';
962 $data[
'start'] = $row->timing_start;
963 $data[
'end'] = $row->timing_end;
964 $data[
'activation_info'] =
'activation';
968 $data[
'start'] = 999999999;
978 $query =
"SELECT * FROM crs_items ".
979 "WHERE obj_id = ".$ilDB->quote($a_item_id).
" ";
981 $res = $ilDB->query($query);
984 if($row->activation_unlimited)
988 if(time() > $row->activation_start and time() < $row->activation_end)
1007 if(!is_array($a_ref_ids) or !$a_ref_ids)
1012 $query =
"SELECT obj_id,timing_type,timing_start,timing_end,visible FROM crs_items ".
1014 $res = $ilDB->query($query);
1017 $ac_times[(string) $row->obj_id][
'obj_id'] = $row->obj_id;
1018 $ac_times[(
string) $row->obj_id][
'timing_type'] = $row->timing_type;
1019 $ac_times[(string) $row->obj_id][
'timing_start'] = $row->timing_start;
1020 $ac_times[(
string) $row->obj_id][
'timing_end'] = $row->timing_end;
1021 $ac_times[(string) $row->obj_id][
'visible'] = $row->visible;
1024 return $ac_times ? $ac_times : array();
1032 if (is_array($this->items_per_child[$a_item[
"child"]]))
1034 $a_item = array_merge($a_item, $this->items_per_child[$a_item[
"child"]]);