ILIAS  Release_3_10_x_branch Revision 61812
 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())." ";
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)." ".
183  "AND obj_id IN(".implode(",",ilUtil::quoteArray($ids)).")";
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)." ".
209  "AND obj_id IN(".implode(",",ilUtil::quoteArray($ref_ids)).") ".
210  "AND parent_id IN(".implode(",",ilUtil::quoteArray($ref_ids)).")";
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)." ".
229  "AND changeable = '1' ".
230  "AND obj_id IN(".implode(",",ilUtil::quoteArray($ref_ids)).") ".
231  "AND parent_id IN(".implode(",",ilUtil::quoteArray($ref_ids)).")";
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;
469 
470  $query = "INSERT INTO crs_items SET ".
471  "timing_type = ".$ilDB->quote($this->getTimingType()).", ".
472  "timing_start = ".$ilDB->quote($this->getTimingStart()).", ".
473  "timing_end = ".$ilDB->quote($this->getTimingEnd()).", ".
474  "suggestion_start = ".$ilDB->quote($this->getSuggestionStart()).", ".
475  "suggestion_end = ".$ilDB->quote($this->getSuggestionEnd()).", ".
476  "changeable = ".$ilDB->quote($this->enabledChangeable()).", ".
477  "earliest_start = ".$ilDB->quote($this->getEarliestStart()).", ".
478  "latest_end = ".$ilDB->quote($this->getLatestEnd()).", ".
479  "visible = ".$ilDB->quote($this->enabledVisible()).", ".
480  "parent_id = ".$ilDB->quote($this->getParentId()).", ".
481  "obj_id = ".$ilDB->quote($this->getItemId())." ";
482  $ilLog->write(__METHOD__.': '.$query);
483 
484  $res = $this->ilDB->query($query);
485  }
486 
487 
488  function update($a_item_id)
489  {
490  global $ilDB;
491 
492  $query = "UPDATE crs_items SET ".
493  "timing_type = ".$ilDB->quote($this->getTimingType()).", ".
494  "timing_start = ".$ilDB->quote($this->getTimingStart()).", ".
495  "timing_end = ".$ilDB->quote($this->getTimingEnd()).", ".
496  "suggestion_start = ".$ilDB->quote($this->getSuggestionStart()).", ".
497  "suggestion_end = ".$ilDB->quote($this->getSuggestionEnd()).", ".
498  "changeable = ".$ilDB->quote($this->enabledChangeable()).", ".
499  "earliest_start = ".$ilDB->quote($this->getEarliestStart()).", ".
500  "latest_end = ".$ilDB->quote($this->getLatestEnd()).", ".
501  "visible = ".$ilDB->quote($this->enabledVisible())." ".
502  "WHERE parent_id = ".$ilDB->quote($this->getParentId())." ".
503  "AND obj_id = ".$ilDB->quote($a_item_id)."";
504 
505  $res = $this->ilDB->query($query);
506  $this->__read();
507 
508  return true;
509  }
510 
511 
512  function moveUp($item_id)
513  {
514  $this->__read();
515 
516  return true;
517  }
518  function moveDown($item_id)
519  {
520  $this->__read();
521 
522  return true;
523  }
524 
525  function deleteAllEntries()
526  {
527  global $ilDB;
528 
529  $all_items = $this->tree->getChilds($this->parent);
530 
531  foreach($all_items as $item)
532  {
533  $query = "DELETE FROM crs_items ".
534  "WHERE parent_id = ".$ilDB->quote($item["child"])."";
535 
536  $this->ilDB->query($query);
537  }
538  $query = "DELETE FROM crs_items ".
539  "WHERE parent_id = ".$ilDB->quote($this->course_obj->getRefId())." ";
540 
541  $this->ilDB->query($query);
542 
543  return true;
544  }
545 
546  // PRIVATE
547  function __read()
548  {
549  global $ilBench, $test;
550 
551  $this->items = array();
552 
553  $ilBench->start("Course", "ilCouseItems_read - getChilds");
554  $all_items = $this->tree->getChilds($this->parent);
555  $ilBench->stop("Course", "ilCouseItems_read - getChilds");
556 
557  foreach($all_items as $item)
558  {
559  if($item["type"] != 'rolf')
560  {
561  $this->items[] = $item;
562  }
563  }
564  $ilBench->start("Course", "ilCouseItems_read - getItemData");
565  for($i = 0;$i < count($this->items); ++$i)
566  {
567  if($this->items[$i]["type"] == 'rolf')
568  {
569  unset($this->items[$i]);
570  continue;
571  }
572  $this->items[$i] = $this->__getItemData($this->items[$i]);
573  }
574  $ilBench->stop("Course", "ilCouseItems_read - getItemData");
575 
576  $ilBench->start("Course", "ilCouseItems_read - purge and sort");
577  $this->__purgeDeleted();
578  $this->__sort();
579  $ilBench->stop("Course", "ilCouseItems_read - purge and sort");
580 
581  // one array for items per child id
582  $this->items_per_child = array();
583  foreach($this->items as $item)
584  {
585  $this->items_per_child[$item["child"]] = $item;
586  }
587 
588  return true;
589  }
590 
591  function __purgeDeleted()
592  {
593  global $tree,$ilDB;
594 
595  $all = array();
596 
597  $query = "SELECT obj_id FROM crs_items ".
598  "WHERE parent_id = ".$ilDB->quote($this->getParentId())." ";
599 
600  $res = $this->ilDB->query($query);
601  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
602  {
603  if($tree->getParentId($row->obj_id) != $this->getParentId())
604  {
605  $this->__delete($row->obj_id);
606  }
607  }
608  }
609 
610  function __delete($a_obj_id)
611  {
612  global $ilDB;
613 
614  // DELETE ENTRY
615  $query = "DELETE FROM crs_items ".
616  "WHERE parent_id = ".$ilDB->quote($this->getParentId())." ".
617  "AND obj_id = ".$ilDB->quote($a_obj_id)." ";
618 
619  $res = $this->ilDB->query($query);
620 
621  return true;
622  }
623 
624  function __getItemData($a_item)
625  {
626  global $ilDB,$ilUser,$ilObjDataCache, $ilBench;
627 
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");
634  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
635  {
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;
650 
651  include_once 'Modules/Course/classes/Timings/class.ilTimingPlaned.php';
652  $data = ilTimingPlaned::_getPlanedTimings($this->getUserId(),$a_item['child']);
653  $ilBench->stop("Course", "ilCourseItems_getItemData - 2");
654 
655  $ilBench->start("Course", "ilCourseItems_getItemData - 3");
656 
657  // changed for performance reasons
658  $obj_id = ($a_item['obj_id'] > 0)
659  ? $a_item['obj_id']
660  : $ilObjDataCache->lookupObjId($row->obj_id);
661  $obj_type = ($a_item['type'] != "")
662  ? $a_item['type']
663  : $ilObjDataCache->lookupType($obj_id);
664 
665 
666  $ilBench->stop("Course", "ilCourseItems_getItemData - 3");
667 
668  //if($ilObjDataCache->lookupType($obj_id = $ilObjDataCache->lookupObjId($row->obj_id)) == 'sess')
669 
670  // Check for user entry
671  $ilBench->start("Course", "ilCourseItems_getItemData - 4");
672  if($a_item['changeable'] and
673  $a_item['timing_type'] == IL_CRS_TIMINGS_PRESETTING)
674  {
675  if($data['planed_start'])
676  {
677  $a_item['start'] = $data['planed_start'];
678  $a_item['end'] = $data['planed_end'];
679  $a_item['activation_info'] = 'crs_timings_planed_info';
680  }
681  else
682  {
683  $a_item['start'] = $row->suggestion_start;
684  $a_item['end'] = $row->suggestion_end;
685  $a_item['activation_info'] = 'crs_timings_suggested_info';
686  }
687  }
688  elseif($a_item['timing_type'] == IL_CRS_TIMINGS_PRESETTING)
689  {
690  $a_item['start'] = $row->suggestion_start;
691  $a_item['end'] = $row->suggestion_end;
692  $a_item['activation_info'] = 'crs_timings_suggested_info';
693  }
694  elseif($a_item['timing_type'] == IL_CRS_TIMINGS_ACTIVATION)
695  {
696  $a_item['start'] = $row->timing_start;
697  $a_item['end'] = $row->timing_end;
698  $a_item['activation_info'] = 'activation';
699  }
700  elseif($obj_type == 'sess')
701  {
702  include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
703 
704  $ilBench->start("Course", "ilCourseItems_getItemData - lookupAppointment");
706  $ilBench->stop("Course", "ilCourseItems_getItemData - lookupAppointment");
707 
708  $a_item['timing_type'] = IL_CRS_TIMINGS_FIXED;
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';
713  }
714  else
715  {
716  $a_item['start'] = 999999999;
717  }
718  $ilBench->stop("Course", "ilCourseItems_getItemData - 4");
719  }
720 
721  $ilBench->start("Course", "ilCourseItems_getItemData - 5");
722  if(!isset($a_item["timing_start"]))
723  {
724  $a_item = $this->createDefaultEntry($a_item);
725  }
726  $ilBench->stop("Course", "ilCourseItems_getItemData - 5");
727 
728  return $a_item;
729  }
730 
731  function createDefaultEntry($a_item)
732  {
733  global $ilDB, $objDefinition;
734 
735  $a_item["timing_type"] = IL_CRS_TIMINGS_DEACTIVATED;
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;
746 
747 
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"]).", ".
760  $ilDB->quote(0).")";
761 
762  $res = $this->ilDB->query($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) as last_position FROM crs_items ".
773  "WHERE parent_id = ".$ilDB->quote($this->getParentId())." ";
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"])." ".
813  "WHERE obj_id = ".$ilDB->quote($node_b["obj_id"])." ".
814  "AND parent_id = ".$ilDB->quote($this->getParentId())."";
815 
816  $res = $this->ilDB->query($query);
817 
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())."";
822 
823  $res = $this->ilDB->query($query);
824 
825  return true;
826  }
827 
836  public static function _sort($a_sort_mode,$a_items)
837  {
838  switch($a_sort_mode)
839  {
841  // Sort by starting time. If mode is IL_CRS_TIMINGS_DEACTIVATED then sort these items by title and append
842  // them to the array.
843  $inactive = $active = array();
844  foreach($a_items as $item)
845  {
846  if($item['timing_type'] == IL_CRS_TIMINGS_DEACTIVATED)
847  {
848  $inactive[] = $item;
849  }
850  else
851  {
852  $active[] = $item;
853  }
854  }
855  $sorted_active = ilUtil::sortArray($active,"start","asc");
856  $sorted_inactive = ilUtil::sortArray($inactive,'title','asc');
857 
858  return array_merge($sorted_active,$sorted_inactive);
859  break;
860 
861  default:
862  return $a_items;
863  }
864  return true;
865 
866  }
867 
868 
869  function __sort()
870  {
871  switch($this->course_obj->getOrderType())
872  {
874  // Sort by starting time. If mode is IL_CRS_TIMINGS_DEACTIVATED then sort these items by title and append
875  // them to the array.
876  list($active,$inactive) = $this->__splitByActivation();
877 
878  $sorted_active = ilUtil::sortArray($active,"start","asc");
879  $sorted_inactive = ilUtil::sortArray($inactive,'title','asc');
880 
881  $this->items = array_merge($sorted_active,$sorted_inactive);
882  break;
883 
884  default:
885  return true;
886  }
887  return true;
888  }
889 
891  {
892  $inactive = $active = array();
893  foreach($this->items as $item)
894  {
895  if($item['timing_type'] == IL_CRS_TIMINGS_DEACTIVATED)
896  {
897  $inactive[] = $item;
898  }
899  else
900  {
901  $active[] = $item;
902  }
903  }
904  return array($active,$inactive);
905  }
906  // STATIC
907  function _getItem($a_item_id)
908  {
909  include_once 'Modules/Course/classes/class.ilObjCourse.php';
910 
911  global $ilDB,$ilUser;
912 
913  $query = "SELECT * FROM crs_items ".
914  "WHERE obj_id = ".$ilDB->quote($a_item_id)." ";
915  $res = $ilDB->query($query);
916  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
917  {
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;
933 
934  include_once 'Modules/Course/classes/Timings/class.ilTimingPlaned.php';
935  $user_data = ilTimingPlaned::_getPlanedTimings($ilUser->getId(),$data['child']);
936 
937  // Check for user entry
938  if($data['changeable'] and
939  $data['timing_type'] == IL_CRS_TIMINGS_PRESETTING)
940  {
941  if($user_data['planed_start'])
942  {
943  $data['start'] = $user_data['planed_start'];
944  $data['end'] = $user_data['planed_end'];
945  $data['activation_info'] = 'crs_timings_planed_info';
946  }
947  else
948  {
949  $data['start'] = $row->suggestion_start;
950  $data['end'] = $row->suggestion_end;
951  $data['activation_info'] = 'crs_timings_suggested_info';
952  }
953  }
954  elseif($data['timing_type'] == IL_CRS_TIMINGS_PRESETTING)
955  {
956  $data['start'] = $row->suggestion_start;
957  $data['end'] = $row->suggestion_end;
958  $data['activation_info'] = 'crs_timings_suggested_info';
959  }
960  elseif($data['timing_type'] == IL_CRS_TIMINGS_ACTIVATION)
961  {
962  $data['start'] = $row->timing_start;
963  $data['end'] = $row->timing_end;
964  $data['activation_info'] = 'activation';
965  }
966  else
967  {
968  $data['start'] = 999999999;
969  }
970  }
971  return $data ? $data : array();
972  }
973 
974  function _isActivated($a_item_id)
975  {
976  global $ilDB;
977 
978  $query = "SELECT * FROM crs_items ".
979  "WHERE obj_id = ".$ilDB->quote($a_item_id)." ";
980 
981  $res = $ilDB->query($query);
982  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
983  {
984  if($row->activation_unlimited)
985  {
986  return true;
987  }
988  if(time() > $row->activation_start and time() < $row->activation_end)
989  {
990  return true;
991  }
992  }
993  return false;
994  }
995 
1003  public static function _readActivationTimes($a_ref_ids)
1004  {
1005  global $ilDB;
1006 
1007  if(!is_array($a_ref_ids) or !$a_ref_ids)
1008  {
1009  return array();
1010  }
1011 
1012  $query = "SELECT obj_id,timing_type,timing_start,timing_end,visible FROM crs_items ".
1013  "WHERE obj_id IN (".implode(',',ilUtil::quoteArray($a_ref_ids)).")";
1014  $res = $ilDB->query($query);
1015  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1016  {
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;
1022  }
1023 
1024  return $ac_times ? $ac_times : array();
1025  }
1026 
1031  {
1032  if (is_array($this->items_per_child[$a_item["child"]]))
1033  {
1034  $a_item = array_merge($a_item, $this->items_per_child[$a_item["child"]]);
1035  }
1036  }
1037 }
1038 ?>