ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseItems.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
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);
38 
40 {
42  var $ilErr;
43  var $ilDB;
44  var $tree;
45  var $lng;
46 
47  var $items;
48  var $parent; // ID OF PARENT CONTAINER e.g course_id, folder_id, group_id
49 
53 
54 
55  function ilCourseItems(&$course_obj,$a_parent = 0,$user_id = 0)
56  {
57  global $ilErr,$ilDB,$lng,$tree;
58 
59  $this->ilErr =& $ilErr;
60  $this->ilDB =& $ilDB;
61  $this->lng =& $lng;
62  $this->tree =& $tree;
63 
64  $this->course_obj =& $course_obj;
65  $this->user_id = $user_id;
66 
67 
68  $this->setParentId($a_parent); // this implicitly calls __read
69  //$this->__read();
70  }
71 
80  public function cloneDependencies($a_target_id,$a_copy_id)
81  {
82  global $ilObjDataCache,$ilLog;
83 
84  $ilLog->write(__METHOD__.': Begin course items...');
85 
86  $target_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
87 
88  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
89  $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
90  $mappings = $cp_options->getMappings();
91 
92  $query = "SELECT * FROM crs_items WHERE ".
93  "parent_id = ".$this->ilDB->quote($this->getParentId(),'integer')." ";
94  $res = $this->ilDB->query($query);
95 
96  if(!$res->numRows())
97  {
98  $ilLog->write(__METHOD__.': No course items found.');
99  return true;
100  }
101 
102  // new course item object
103  if(!is_object($new_container = ilObjectFactory::getInstanceByRefId($a_target_id,false)))
104  {
105  $ilLog->write(__METHOD__.': Cannot create target object.');
106  return false;
107  }
108  $new_items = new ilCourseItems($this->course_obj,$a_target_id);
109  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
110  {
111  if(!isset($mappings[$row->parent_id]) or !$mappings[$row->parent_id])
112  {
113  $ilLog->write(__METHOD__.': No mapping for parent nr. '.$row->parent_id);
114  continue;
115  }
116  if(!isset($mappings[$row->obj_id]) or !$mappings[$row->obj_id])
117  {
118  $ilLog->write(__METHOD__.': No mapping for item nr. '.$row->obj_id);
119  continue;
120  }
121  $new_item_id = $mappings[$row->obj_id];
122  $new_parent = $mappings[$row->parent_id];
123 
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);
137  }
138  $ilLog->write(__METHOD__.': Finished course items.');
139  }
140 
141  public function setItemId($a_item_id)
142  {
143  $this->item_id = $a_item_id;
144  }
145 
146  public function getItemId()
147  {
148  return $this->item_id;
149  }
150  function getUserId()
151  {
152  global $ilUser;
153 
154  return $this->user_id ? $this->user_id : $ilUser->getId();
155  }
156 
157  function _hasCollectionTimings($a_ref_id)
158  {
159  global $tree,$ilDB,$ilObjDataCache;
160 
161  // get all collections
162  include_once 'Services/Tracking/classes/class.ilLPObjSettings.php';
163 
164  $obj_id = $ilObjDataCache->lookupObjId($a_ref_id);
165  switch(ilLPObjSettings::_lookupMode($obj_id))
166  {
168  case LP_MODE_COLLECTION:
169  include_once 'Services/Tracking/classes/class.ilLPCollectionCache.php';
170  $ids = ilLPCollectionCache::_getItems($obj_id);
171  break;
172  default:
173  $ids = array($a_ref_id);
174  break;
175  }
176  if(!$ids)
177  {
178  return false;
179  }
180 
181  $query = "SELECT * FROM crs_items ".
182  "WHERE timing_type = ".$ilDB->quote(IL_CRS_TIMINGS_PRESETTING,'integer')." ".
183  "AND ".$ilDB->in('obj_id',$ids,false,'integer');
184 
185  $res = $ilDB->query($query);
186  return $res->numRows() ? true :false;
187  }
188 
196  public function _hasTimings($a_ref_id)
197  {
198  global $tree,$ilDB;
199 
200  $subtree = $tree->getSubTree($tree->getNodeData($a_ref_id));
201 
202  foreach($subtree as $node)
203  {
204  $ref_ids[] = $node['ref_id'];
205  }
206 
207  $query = "SELECT * FROM crs_items ".
208  "WHERE timing_type = ".$ilDB->quote(IL_CRS_TIMINGS_PRESETTING,'integer')." ".
209  "AND ".$ilDB->in('obj_id',$ref_ids,false,'integer')." ".
210  "AND ".$ilDB->in('parent_id',$ref_ids,false,'integer')." ";
211 
212  $res = $ilDB->query($query);
213  return $res->numRows() ? true :false;
214  }
215 
216  function _hasChangeableTimings($a_ref_id)
217  {
218  global $tree,$ilDB;
219 
220  $subtree = $tree->getSubTree($tree->getNodeData($a_ref_id));
221 
222  foreach($subtree as $node)
223  {
224  $ref_ids[] = $node['ref_id'];
225  }
226 
227  $query = "SELECT * FROM crs_items ".
228  "WHERE timing_type = ".$ilDB->quote(IL_CRS_TIMINGS_PRESETTING,'integer')." ".
229  "AND changeable = ".$ilDB->quote(1,'integer')." ".
230  "AND ".$ilDB->in('obj_id',$ref_ids,false,'integer')." ".
231  "AND ".$ilDB->in('parent_id',$ref_ids,false,'integer')." ";
232 
233  $res = $ilDB->query($query);
234  return $res->numRows() ? true :false;
235  }
236 
237  function setParentId($a_parent = 0)
238  {
239  $this->parent = $a_parent ? $a_parent : $this->course_obj->getRefId();
240 
241  $this->__read();
242 
243  return true;
244  }
245  function getParentId()
246  {
247  return $this->parent;
248  }
249 
250  function setTimingType($a_type)
251  {
252  $this->timing_type = $a_type;
253  }
254  function getTimingType()
255  {
256  return $this->timing_type;
257  }
258 
259  function setTimingStart($a_start)
260  {
261  $this->timing_start = $a_start;
262  }
263  function getTimingStart()
264  {
265  return $this->timing_start;
266  }
267  function setTimingEnd($a_end)
268  {
269  $this->timing_end = $a_end;
270  }
271  function getTimingEnd()
272  {
273  return $this->timing_end;
274  }
275  function setSuggestionStart($a_start)
276  {
277  $this->suggestion_start = $a_start;
278  }
280  {
281  return $this->suggestion_start ? $this->suggestion_start : mktime(0,0,1,date('n',time()),date('j',time()),date('Y',time()));
282  }
283  function setSuggestionEnd($a_end)
284  {
285  $this->suggestion_end = $a_end;
286  }
287  function getSuggestionEnd()
288  {
289  return $this->suggestion_end ? $this->suggestion_end : mktime(23,55,00,date('n',time()),date('j',time()),date('Y',time()));
290  }
291  function setEarliestStart($a_start)
292  {
293  $this->earliest_start = $a_start;
294  }
295  function getEarliestStart()
296  {
297  return $this->earliest_start ? $this->earliest_start : mktime(0,0,1,date('n',time()),date('j',time()),date('Y',time()));
298  }
299  function setLatestEnd($a_end)
300  {
301  $this->latest_end = $a_end;
302  }
303  function getLatestEnd()
304  {
305  return $this->latest_end ? $this->latest_end : mktime(23,55,00,date('n',time()),date('j',time()),date('Y',time()));
306  }
307  function toggleVisible($a_status)
308  {
309  $this->visible = (int) $a_status;
310  }
311  function enabledVisible()
312  {
313  return (bool) $this->visible;
314  }
315  function toggleChangeable($a_status)
316  {
317  $this->changeable = (int) $a_status;
318  }
319  function enabledChangeable()
320  {
321  return (bool) $this->changeable;
322  }
323 
324  function setPosition($a_pos)
325  {
326  $this->position = $a_pos;
327  }
328 
329  function getAllItems()
330  {
331  return $this->items ? $this->items : array();
332  }
333 
337  function getFilteredItems($a_container_ref_id)
338  {
339  global $objDefinition;
340 
341  include_once 'Modules/Session/classes/class.ilEventItems.php';
342 
343  $event_items = ilEventItems::_getItemsOfContainer($a_container_ref_id);
344  foreach($this->items as $item)
345  {
346  if(!in_array($item['ref_id'],$event_items) &&
347  !$objDefinition->isSideBlock($item['type']))
348  {
349  $filtered[] = $item;
350  }
351  }
352  return $filtered ? $filtered : array();
353  }
354 
355  function getItemsByEvent($a_event_id)
356  {
357  include_once 'Modules/Session/classes/class.ilEventItems.php';
358 
359  $event_items_obj = new ilEventItems($a_event_id);
360  $event_items = $event_items_obj->getItems();
361  foreach($event_items as $item)
362  {
363  if($this->tree->isDeleted($item))
364  {
365  continue;
366  }
367  $node = $this->tree->getNodeData($item);
368  $items[] = $this->__getItemData($node);
369  }
370  return $items ? $items : array();
371  }
372 
373  function getItemsByObjective($a_objective_id)
374  {
375  include_once('./Modules/Course/classes/class.ilCourseObjectiveMaterials.php');
376 
378  {
379  if($this->tree->isDeleted($ref_id))
380  {
381  continue;
382  }
383  $node = $this->tree->getNodeData($ref_id);
384  $items[] = $this->__getItemData($node);
385  }
386  return $items ? $items : array();
387  }
388 
389 
390  function getItems()
391  {
392  global $rbacsystem;
393 
394  foreach($this->items as $item)
395  {
396  if($item["type"] != "rolf" and
397  ($item["timing_type"] or
398  ($item["timing_start"] <= time() and $item["timing_end"] >= time())))
399  {
400  if($rbacsystem->checkAccess('visible',$item['ref_id']))
401  {
402  $filtered[] = $item;
403  }
404  }
405  }
406  return $filtered ? $filtered : array();
407  }
408  function getItem($a_item_id)
409  {
410  foreach($this->items as $item)
411  {
412  if($item["child"] == $a_item_id)
413  {
414  return $item;
415  }
416  }
417  return array();
418  }
419 
421  {
422  global $ilErr;
423 
424  $ilErr->setMessage('');
425 
427  {
428  if($this->getTimingStart() > $this->getTimingEnd())
429  {
430  $ilErr->appendMessage($this->lng->txt("crs_activation_start_invalid"));
431  }
432  }
434  {
435  if($this->getSuggestionStart() > $this->getSuggestionEnd())
436  {
437  $ilErr->appendMessage($this->lng->txt('crs_latest_end_not_valid'));
438  }
439  }
440  // Disabled
441  #if($this->getTimingType() == IL_CRS_TIMINGS_PRESETTING and
442  # $this->enabledChangeable())
443  #{
444  # if($this->getSuggestionStart() < $this->getEarliestStart() or
445  # $this->getSuggestionEnd() > $this->getLatestEnd() or
446  # $this->getSuggestionStart() > $this->getLatestEnd() or
447  # $this->getSuggestionEnd() < $this->getEarliestStart())
448  # {
449  # $ilErr->appendMessage($this->lng->txt("crs_suggestion_not_within_activation"));
450  # }
451  #}
452 
453  if($ilErr->getMessage())
454  {
455  return false;
456  }
457  return true;
458  }
459 
466  public function save()
467  {
468  global $ilLog,$ilDB;
469 
470  $query = "INSERT INTO crs_items (timing_type,timing_start,timing_end,".
471  "suggestion_start,suggestion_end, ".
472  "changeable,earliest_start,latest_end,visible,parent_id,obj_id) ".
473  "VALUES( ".
474  $ilDB->quote($this->getTimingType(),'integer').", ".
475  $ilDB->quote($this->getTimingStart(),'integer').", ".
476  $ilDB->quote($this->getTimingEnd(),'integer').", ".
477  $ilDB->quote($this->getSuggestionStart(),'integer').", ".
478  $ilDB->quote($this->getSuggestionEnd(),'integer').", ".
479  $ilDB->quote($this->enabledChangeable(),'integer').", ".
480  $ilDB->quote($this->getEarliestStart(),'integer').", ".
481  $ilDB->quote($this->getLatestEnd(),'integer').", ".
482  $ilDB->quote($this->enabledVisible(),'integer').", ".
483  $ilDB->quote($this->getParentId(),'integer').", ".
484  $ilDB->quote($this->getItemId(),'integer')." ".
485  ")";
486  $res = $ilDB->manipulate($query);
487  }
488 
489 
490  function update($a_item_id)
491  {
492  global $ilDB;
493 
494  $query = "UPDATE crs_items SET ".
495  "timing_type = ".$ilDB->quote($this->getTimingType(),'integer').", ".
496  "timing_start = ".$ilDB->quote($this->getTimingStart(),'integer').", ".
497  "timing_end = ".$ilDB->quote($this->getTimingEnd(),'integer').", ".
498  "suggestion_start = ".$ilDB->quote($this->getSuggestionStart(),'integer').", ".
499  "suggestion_end = ".$ilDB->quote($this->getSuggestionEnd(),'integer').", ".
500  "changeable = ".$ilDB->quote($this->enabledChangeable(),'integer').", ".
501  "earliest_start = ".$ilDB->quote($this->getEarliestStart(),'integer').", ".
502  "latest_end = ".$ilDB->quote($this->getLatestEnd(),'integer').", ".
503  "visible = ".$ilDB->quote($this->enabledVisible(),'integer')." ".
504  "WHERE parent_id = ".$ilDB->quote($this->getParentId(),'integer')." ".
505  "AND obj_id = ".$ilDB->quote($a_item_id,'integer')."";
506  $res = $ilDB->manipulate($query);
507  $this->__read();
508 
509  return true;
510  }
511 
512 
513  function moveUp($item_id)
514  {
515  $this->__read();
516 
517  return true;
518  }
519  function moveDown($item_id)
520  {
521  $this->__read();
522 
523  return true;
524  }
525 
526  function deleteAllEntries()
527  {
528  global $ilDB;
529 
530  $all_items = $this->tree->getChilds($this->parent);
531 
532  foreach($all_items as $item)
533  {
534  $query = "DELETE FROM crs_items ".
535  "WHERE parent_id = ".$ilDB->quote($item["child"],'integer')."";
536  $res = $ilDB->manipulate($query);
537  }
538  $query = "DELETE FROM crs_items ".
539  "WHERE parent_id = ".$ilDB->quote($this->course_obj->getRefId(),'integer')." ";
540  $res = $ilDB->manipulate($query);
541 
542  return true;
543  }
544 
545  // PRIVATE
546  function __read()
547  {
548  global $ilBench, $test;
549 
550  $this->items = array();
551 
552  $ilBench->start("Course", "ilCouseItems_read - getChilds");
553  $all_items = $this->tree->getChilds($this->parent);
554  $ilBench->stop("Course", "ilCouseItems_read - getChilds");
555 
556  foreach($all_items as $item)
557  {
558  if($item["type"] != 'rolf')
559  {
560  $this->items[] = $item;
561  }
562  }
563  $ilBench->start("Course", "ilCouseItems_read - getItemData");
564  for($i = 0;$i < count($this->items); ++$i)
565  {
566  if($this->items[$i]["type"] == 'rolf')
567  {
568  unset($this->items[$i]);
569  continue;
570  }
571  $this->items[$i] = $this->__getItemData($this->items[$i]);
572  }
573  $ilBench->stop("Course", "ilCouseItems_read - getItemData");
574 
575  $ilBench->start("Course", "ilCouseItems_read - purge and sort");
576  $this->__purgeDeleted();
577  $this->__sort();
578  $ilBench->stop("Course", "ilCouseItems_read - purge and sort");
579 
580  // one array for items per child id
581  $this->items_per_child = array();
582  foreach($this->items as $item)
583  {
584  $this->items_per_child[$item["child"]] = $item;
585  }
586 
587  return true;
588  }
589 
590  function __purgeDeleted()
591  {
592  global $tree,$ilDB;
593 
594  $all = array();
595 
596  $query = "SELECT obj_id FROM crs_items ".
597  "WHERE parent_id = ".$ilDB->quote($this->getParentId(),'integer')." ";
598 
599  $res = $this->ilDB->query($query);
600  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
601  {
602  if($tree->getParentId($row->obj_id) != $this->getParentId())
603  {
604  $this->__delete($row->obj_id);
605  }
606  }
607  }
608 
609  function __delete($a_obj_id)
610  {
611  global $ilDB;
612 
613  // DELETE ENTRY
614  $query = "DELETE FROM crs_items ".
615  "WHERE parent_id = ".$ilDB->quote($this->getParentId(),'integer')." ".
616  "AND obj_id = ".$ilDB->quote($a_obj_id,'integer')." ";
617  $res = $ilDB->manipulate($query);
618 
619  return true;
620  }
621 
622  function __getItemData($a_item)
623  {
624  global $ilDB,$ilUser,$ilObjDataCache, $ilBench;
625 
626  $ilBench->start("Course", "ilCourseItems_getItemData - 1");
627  $query = "SELECT * FROM crs_items ".
628  "WHERE obj_id = ".$ilDB->quote($a_item['child'],'integer')." ".
629  "AND parent_id = ".$ilDB->quote($a_item['parent'],'integer')." ";
630  $res = $this->ilDB->query($query);
631  $ilBench->stop("Course", "ilCourseItems_getItemData - 1");
632  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
633  {
634  $ilBench->start("Course", "ilCourseItems_getItemData - 2");
635  $a_item["timing_type"] = $row->timing_type;
636  $a_item["timing_start"] = $row->timing_start;
637  $a_item["timing_end"] = $row->timing_end;
638  $a_item["suggestion_start"] = $row->suggestion_start ? $row->suggestion_start :
639  mktime(0,0,1,date('n',time()),date('j',time()),date('Y',time()));
640  $a_item["suggestion_end"] = $row->suggestion_end ? $row->suggestion_end :
641  mktime(23,55,00,date('n',time()),date('j',time()),date('Y',time()));
642  $a_item['changeable'] = $row->changeable;
643  $a_item['earliest_start'] = $row->earliest_start ? $row->earliest_start :
644  mktime(0,0,1,date('n',time()),date('j',time()),date('Y',time()));
645  $a_item['latest_end'] = $row->latest_end ? $row->latest_end :
646  mktime(23,55,00,date('n',time()),date('j',time()),date('Y',time()));
647  $a_item['visible'] = $row->visible;
648 
649  include_once 'Modules/Course/classes/Timings/class.ilTimingPlaned.php';
650  $data = ilTimingPlaned::_getPlanedTimings($this->getUserId(),$a_item['child']);
651  $ilBench->stop("Course", "ilCourseItems_getItemData - 2");
652 
653  $ilBench->start("Course", "ilCourseItems_getItemData - 3");
654 
655  // changed for performance reasons
656  $obj_id = ($a_item['obj_id'] > 0)
657  ? $a_item['obj_id']
658  : $ilObjDataCache->lookupObjId($row->obj_id);
659  $obj_type = ($a_item['type'] != "")
660  ? $a_item['type']
661  : $ilObjDataCache->lookupType($obj_id);
662 
663 
664  $ilBench->stop("Course", "ilCourseItems_getItemData - 3");
665 
666  //if($ilObjDataCache->lookupType($obj_id = $ilObjDataCache->lookupObjId($row->obj_id)) == 'sess')
667 
668  // Check for user entry
669  $ilBench->start("Course", "ilCourseItems_getItemData - 4");
670  if($a_item['changeable'] and
671  $a_item['timing_type'] == IL_CRS_TIMINGS_PRESETTING)
672  {
673  if($data['planed_start'])
674  {
675  $a_item['start'] = $data['planed_start'];
676  $a_item['end'] = $data['planed_end'];
677  $a_item['activation_info'] = 'crs_timings_planed_info';
678  }
679  else
680  {
681  $a_item['start'] = $row->suggestion_start;
682  $a_item['end'] = $row->suggestion_end;
683  $a_item['activation_info'] = 'crs_timings_suggested_info';
684  }
685  }
686  elseif($a_item['timing_type'] == IL_CRS_TIMINGS_PRESETTING)
687  {
688  $a_item['start'] = $row->suggestion_start;
689  $a_item['end'] = $row->suggestion_end;
690  $a_item['activation_info'] = 'crs_timings_suggested_info';
691  }
692  elseif($a_item['timing_type'] == IL_CRS_TIMINGS_ACTIVATION)
693  {
694  $a_item['start'] = $row->timing_start;
695  $a_item['end'] = $row->timing_end;
696  $a_item['activation_info'] = 'activation';
697  }
698  elseif($obj_type == 'sess')
699  {
700  include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
701 
702  $ilBench->start("Course", "ilCourseItems_getItemData - lookupAppointment");
704  $ilBench->stop("Course", "ilCourseItems_getItemData - lookupAppointment");
705 
706  $a_item['timing_type'] = IL_CRS_TIMINGS_FIXED;
707  $a_item['start'] = $info['start'];
708  $a_item['end'] = $info['end'];
709  $a_item['fullday'] = $info['fullday'];
710  $a_item['activation_info'] = 'crs_timings_suggested_info';
711  }
712  else
713  {
714  $a_item['start'] = 999999999;
715  }
716  $ilBench->stop("Course", "ilCourseItems_getItemData - 4");
717  }
718 
719  $ilBench->start("Course", "ilCourseItems_getItemData - 5");
720  if(!isset($a_item["timing_start"]))
721  {
722  $a_item = $this->createDefaultEntry($a_item);
723  }
724  $ilBench->stop("Course", "ilCourseItems_getItemData - 5");
725 
726  return $a_item;
727  }
728 
729  function createDefaultEntry($a_item)
730  {
731  global $ilDB, $objDefinition;
732 
733  $a_item["timing_type"] = IL_CRS_TIMINGS_DEACTIVATED;
734  $a_item["timing_start"] = time();
735  $a_item["timing_end"] = time();
736  $a_item["suggestion_start"] = time();
737  $a_item["suggestion_end"] = time();
738  $a_item['visible'] = 0;
739  $a_item['changeable'] = 0;
740  $a_item['earliest_start'] = time();
741  $a_item['latest_end'] = mktime(23,55,00,date('n',time()),date('j',time()),date('Y',time()));
742  $a_item['visible'] = 0;
743  $a_item['changeable'] = 0;
744 
745 
746  $query = "INSERT INTO crs_items (parent_id,obj_id,timing_type,timing_start,timing_end," .
747  "suggestion_start,suggestion_end, ".
748  "changeable,earliest_start,latest_end,visible,position) ".
749  "VALUES( ".
750  $ilDB->quote($a_item['parent'],'integer').",".
751  $ilDB->quote($a_item["child"],'integer').",".
752  $ilDB->quote($a_item["timing_type"],'integer').",".
753  $ilDB->quote($a_item["timing_start"],'integer').",".
754  $ilDB->quote($a_item["timing_end"],'integer').",".
755  $ilDB->quote($a_item["suggestion_start"],'integer').",".
756  $ilDB->quote($a_item["suggestion_end"],'integer').",".
757  $ilDB->quote($a_item["changeable"],'integer').",".
758  $ilDB->quote($a_item['earliest_start'],'integer').", ".
759  $ilDB->quote($a_item['latest_end'],'integer').", ".
760  $ilDB->quote($a_item["visible"],'integer').", ".
761  $ilDB->quote(0,'integer').")";
762  $res = $ilDB->manipulate($query);
763 
764  return $a_item;
765  }
766 
767  // methods for manual sortation
768  function __getLastPosition()
769  {
770  global $ilDB;
771 
772  $query = "SELECT MAX(position) last_position FROM crs_items ".
773  "WHERE parent_id = ".$ilDB->quote($this->getParentId(),'integer')." ";
774 
775  $res = $this->ilDB->query($query);
776  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
777  {
778  $max = $row->last_position;
779  }
780  return $max ? $max : 0;
781  }
782 
783 
784 
785  function __isMovable($a_ref_id)
786  {
787  include_once 'Modules/Session/classes/class.ilEventItems.php';
788 
789  global $ilObjDataCache;
790 
791  if($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($a_ref_id)) != 'crs')
792  {
793  return true;
794  }
795  if(ilEventItems::_isAssigned($a_ref_id))
796  {
797  return false;
798  }
799  return true;
800  }
801 
802  function __switchNodes($node_a,$node_b)
803  {
804  global $ilDB;
805 
806  if(!$node_b["obj_id"])
807  {
808  return false;
809  }
810 
811  $query = "UPDATE crs_items SET ".
812  "position = ".$ilDB->quote($node_a["position"],'integer')." ".
813  "WHERE obj_id = ".$ilDB->quote($node_b["obj_id"],'integer')." ".
814  "AND parent_id = ".$ilDB->quote($this->getParentId(),'integer')."";
815  $res = $ilDB->manipulate($query);
816 
817  $query = "UPDATE crs_items SET ".
818  "position = ".$ilDB->quote($node_b["position"],'integer')." ".
819  "WHERE obj_id = ".$ilDB->quote($node_a["obj_id"],'integer')." ".
820  "AND parent_id = ".$ilDB->quote($this->getParentId(),'integer')."";
821  $res = $ilDB->manipulate($query);
822 
823  return true;
824  }
825 
834  public static function _sort($a_sort_mode,$a_items)
835  {
836  switch($a_sort_mode)
837  {
839  // Sort by starting time. If mode is IL_CRS_TIMINGS_DEACTIVATED then sort these items by title and append
840  // them to the array.
841  $inactive = $active = array();
842  foreach($a_items as $item)
843  {
844  if($item['timing_type'] == IL_CRS_TIMINGS_DEACTIVATED)
845  {
846  $inactive[] = $item;
847  }
848  else
849  {
850  $active[] = $item;
851  }
852  }
853  $sorted_active = ilUtil::sortArray($active,"start","asc");
854  $sorted_inactive = ilUtil::sortArray($inactive,'title','asc');
855 
856  return array_merge($sorted_active,$sorted_inactive);
857  break;
858 
859  default:
860  return $a_items;
861  }
862  return true;
863 
864  }
865 
866 
867  function __sort()
868  {
869  switch($this->course_obj->getOrderType())
870  {
872  // Sort by starting time. If mode is IL_CRS_TIMINGS_DEACTIVATED then sort these items by title and append
873  // them to the array.
874  list($active,$inactive) = $this->__splitByActivation();
875 
876  $sorted_active = ilUtil::sortArray($active,"start","asc");
877  $sorted_inactive = ilUtil::sortArray($inactive,'title','asc');
878 
879  $this->items = array_merge($sorted_active,$sorted_inactive);
880  break;
881 
882  default:
883  return true;
884  }
885  return true;
886  }
887 
889  {
890  $inactive = $active = array();
891  foreach($this->items as $item)
892  {
893  if($item['timing_type'] == IL_CRS_TIMINGS_DEACTIVATED)
894  {
895  $inactive[] = $item;
896  }
897  else
898  {
899  $active[] = $item;
900  }
901  }
902  return array($active,$inactive);
903  }
904  // STATIC
909  function _getItem($a_item_id)
910  {
911  include_once 'Modules/Course/classes/class.ilObjCourse.php';
912 
913  global $ilDB,$ilUser;
914 
915  $query = "SELECT * FROM crs_items ".
916  "WHERE obj_id = ".$ilDB->quote($a_item_id,'integer');
917  $res = $ilDB->query($query);
918  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
919  {
920  $data['parent_id'] = $row->parent_id;
921  $data['obj_id'] = $row->obj_id;
922  $data['ref_id'] = $row->obj_id;
923  $data['child'] = $row->obj_id;
924  $data['timing_type'] = $row->timing_type;
925  $data['timing_start'] = $row->timing_start;
926  $data['timing_end'] = $row->timing_end;
927  $data["suggestion_start"] = $row->suggestion_start ? $row->suggestion_start :
928  mktime(0,0,1,date('n',time()),date('j',time()),date('Y',time()));
929  $data["suggestion_end"] = $row->suggestion_end ? $row->suggestion_end :
930  mktime(23,55,00,date('n',time()),date('j',time()),date('Y',time()));
931  $data['changeable'] = $row->changeable;
932  $data['earliest_start'] = $row->earliest_start ? $row->earliest_start :
933  mktime(0,0,1,date('n',time()),date('j',time()),date('Y',time()));
934  $data['latest_end'] = $row->latest_end ? $row->latest_end :
935  mktime(23,55,00,date('n',time()),date('j',time()),date('Y',time()));
936  $data['visible'] = $row->visible;
937 
938 
939  include_once 'Modules/Course/classes/Timings/class.ilTimingPlaned.php';
940  $user_data = ilTimingPlaned::_getPlanedTimings($ilUser->getId(),$data['child']);
941 
942  // Check for user entry
943  if($data['changeable'] and
944  $data['timing_type'] == IL_CRS_TIMINGS_PRESETTING)
945  {
946  if($user_data['planed_start'])
947  {
948  $data['start'] = $user_data['planed_start'];
949  $data['end'] = $user_data['planed_end'];
950  $data['activation_info'] = 'crs_timings_planed_info';
951  }
952  else
953  {
954  $data['start'] = $row->suggestion_start;
955  $data['end'] = $row->suggestion_end;
956  $data['activation_info'] = 'crs_timings_suggested_info';
957  }
958  }
959  elseif($data['timing_type'] == IL_CRS_TIMINGS_PRESETTING)
960  {
961  $data['start'] = $row->suggestion_start;
962  $data['end'] = $row->suggestion_end;
963  $data['activation_info'] = 'crs_timings_suggested_info';
964  }
965  elseif($data['timing_type'] == IL_CRS_TIMINGS_ACTIVATION)
966  {
967  $data['start'] = $row->timing_start;
968  $data['end'] = $row->timing_end;
969  $data['activation_info'] = 'activation';
970  }
971  else
972  {
973  $data['start'] = 999999999;
974  }
975  }
976  return $data ? $data : array();
977  }
978 
979  function _isActivated($a_item_id)
980  {
981  global $ilDB;
982 
983  $query = "SELECT * FROM crs_items ".
984  "WHERE obj_id = ".$ilDB->quote($a_item_id,'integer')." ";
985 
986  $res = $ilDB->query($query);
987  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
988  {
989  if($row->activation_unlimited)
990  {
991  return true;
992  }
993  if(time() > $row->activation_start and time() < $row->activation_end)
994  {
995  return true;
996  }
997  }
998  return false;
999  }
1000 
1008  public static function _readActivationTimes($a_ref_ids)
1009  {
1010  global $ilDB;
1011 
1012  if(!is_array($a_ref_ids) or !$a_ref_ids)
1013  {
1014  return array();
1015  }
1016 
1017  $query = "SELECT obj_id,timing_type,timing_start,timing_end,visible FROM crs_items ".
1018  "WHERE ".$ilDB->in('obj_id',$a_ref_ids,false,'integer');
1019 
1020  $res = $ilDB->query($query);
1021  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1022  {
1023  $ac_times[(string) $row->obj_id]['obj_id'] = $row->obj_id;
1024  $ac_times[(string) $row->obj_id]['timing_type'] = $row->timing_type;
1025  $ac_times[(string) $row->obj_id]['timing_start'] = $row->timing_start;
1026  $ac_times[(string) $row->obj_id]['timing_end'] = $row->timing_end;
1027  $ac_times[(string) $row->obj_id]['visible'] = $row->visible;
1028  }
1029 
1030  return $ac_times ? $ac_times : array();
1031  }
1032 
1037  {
1038  if (is_array($this->items_per_child[$a_item["child"]]))
1039  {
1040  $a_item = array_merge($a_item, $this->items_per_child[$a_item["child"]]);
1041  }
1042  }
1043 }
1044 ?>