ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjectActivation.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13{
17 protected $error;
18
22 protected $lng;
23
27 protected $db;
28
29 protected $timing_type;
30 protected $timing_start;
31 protected $timing_end;
33 protected $suggestion_end;
34 protected $earliest_start;
35 protected $latest_end;
36 protected $visible;
37 protected $changeable;
38
39 protected static $preloaded_data = array();
40
44 const TIMINGS_FIXED = 3; // session only => obsolete?
45
46 public function __construct()
47 {
48 global $DIC;
49
50 $this->error = $DIC["ilErr"];
51 $this->lng = $DIC->language();
52 $this->db = $DIC->database();
53 }
54
61 public function setTimingType($a_type)
62 {
63 $this->timing_type = $a_type;
64 }
65
72 public function getTimingType()
73 {
74 return $this->timing_type;
75 }
76
82 public function setTimingStart($a_start)
83 {
84 $this->timing_start = $a_start;
85 }
86
92 public function getTimingStart()
93 {
95 }
96
102 public function setTimingEnd($a_end)
103 {
104 $this->timing_end = $a_end;
105 }
106
112 public function getTimingEnd()
113 {
114 return $this->timing_end;
115 }
116
122 public function setSuggestionStart($a_start)
123 {
124 $this->suggestion_start = $a_start;
125 }
126
132 public function getSuggestionStart()
133 {
135 }
136
142 public function setSuggestionEnd($a_end)
143 {
144 $this->suggestion_end = $a_end;
145 }
146
152 public function getSuggestionEnd()
153 {
155 }
156
162 public function setEarliestStart($a_start)
163 {
164 $this->earliest_start = $a_start;
165 }
166
172 public function getEarliestStart()
173 {
175 }
176
182 public function setLatestEnd($a_end)
183 {
184 $this->latest_end = $a_end;
185 }
186
192 public function getLatestEnd()
193 {
194 return $this->latest_end;
195 }
196
202 public function toggleVisible($a_status)
203 {
204 $this->visible = (int) $a_status;
205 }
206
212 public function enabledVisible()
213 {
214 return (bool) $this->visible;
215 }
216
222 public function toggleChangeable($a_status)
223 {
224 $this->changeable = (int) $a_status;
225 }
226
232 public function enabledChangeable()
233 {
234 return (bool) $this->changeable;
235 }
236
242 public function validateActivation()
243 {
246
247 $ilErr->setMessage('');
248
249 if ($this->getTimingType() == self::TIMINGS_ACTIVATION) {
250 if ($this->getTimingStart() > $this->getTimingEnd()) {
251 $ilErr->appendMessage($lng->txt("crs_activation_start_invalid"));
252 }
253 } elseif ($this->getTimingType() == self::TIMINGS_PRESETTING) {
254 if ($this->getSuggestionStart() > $this->getSuggestionEnd()) {
255 $ilErr->appendMessage($lng->txt('crs_latest_end_not_valid'));
256 }
257 }
258
259 if ($ilErr->getMessage()) {
260 return false;
261 }
262 return true;
263 }
264
271 public function update($a_ref_id, $a_parent_id = null)
272 {
274
275 // #10110
276 $query = "UPDATE crs_items SET " .
277 "timing_type = " . $ilDB->quote($this->getTimingType(), 'integer') . ", " .
278 "timing_start = " . $ilDB->quote((int) $this->getTimingStart(), 'integer') . ", " .
279 "timing_end = " . $ilDB->quote((int) $this->getTimingEnd(), 'integer') . ", " .
280 "suggestion_start = " . $ilDB->quote((int) $this->getSuggestionStart(), 'integer') . ", " .
281 "suggestion_end = " . $ilDB->quote((int) $this->getSuggestionEnd(), 'integer') . ", " .
282 "changeable = " . $ilDB->quote($this->enabledChangeable(), 'integer') . ", " .
283 "earliest_start = " . $ilDB->quote((int) $this->getEarliestStart(), 'integer') . ", " .
284 "latest_end = " . $ilDB->quote((int) $this->getLatestEnd(), 'integer') . ", ";
285
286 if ($a_parent_id) {
287 $query .= "parent_id = " . $ilDB->quote($a_parent_id, 'integer') . ", ";
288 }
289
290 $query .= "visible = " . $ilDB->quote($this->enabledVisible(), 'integer') . " " .
291 "WHERE obj_id = " . $ilDB->quote($a_ref_id, 'integer');
292 $ilDB->manipulate($query);
293
294 unset(self::$preloaded_data[$a_ref_id]);
295
296 return true;
297 }
298
304 public static function preloadData(array $a_ref_ids)
305 {
306 global $DIC;
307
308 $ilDB = $DIC->database();
309
310 $sql = "SELECT * FROM crs_items" .
311 " WHERE " . $ilDB->in("obj_id", $a_ref_ids, "", "integer");
312 $set = $ilDB->query($sql);
313 while ($row = $ilDB->fetchAssoc($set)) {
314 self::$preloaded_data[$row["obj_id"]] = $row;
315 }
316 }
317
324 public static function getItem($a_ref_id)
325 {
326 global $DIC;
327
328 $ilDB = $DIC->database();
329
330 if (isset(self::$preloaded_data[$a_ref_id])) {
331 return self::$preloaded_data[$a_ref_id];
332 }
333
334 $sql = "SELECT * FROM crs_items" .
335 " WHERE obj_id = " . $ilDB->quote($a_ref_id, "integer");
336 $set = $ilDB->query($sql);
337 $row = $ilDB->fetchAssoc($set);
338
339 if (!isset($row["obj_id"])) {
340 $row = self::createDefaultEntry($a_ref_id);
341 }
342 if ($row["obj_id"]) {
343 self::$preloaded_data[$row["obj_id"]] = $row;
344 }
345 return $row;
346 }
347
353 public static function addAdditionalSubItemInformation(array &$a_item)
354 {
355 global $DIC;
356
357 $ilUser = $DIC->user();
358
359 $item = self::getItem($a_item['ref_id']);
360
361 $a_item['obj_id'] = ($a_item['obj_id'] > 0)
362 ? $a_item['obj_id']
363 : ilObject::_lookupObjId($a_item['ref_id']);
364 $a_item['type'] = ($a_item['type'] != '')
365 ? $a_item['type']
366 : ilObject::_lookupType($a_item['obj_id']);
367
368 $a_item['timing_type'] = $item['timing_type'];
369
370 if ($item['changeable'] &&
371 $item['timing_type'] == self::TIMINGS_PRESETTING) {
372 include_once 'Modules/Course/classes/Timings/class.ilTimingPlaned.php';
373 $user_data = ilTimingPlaned::_getPlanedTimings($ilUser->getId(), $a_item['ref_id']);
374 if ($user_data['planed_start']) {
375 $a_item['start'] = $user_data['planed_start'];
376 $a_item['end'] = $user_data['planed_end'];
377 $a_item['activation_info'] = 'crs_timings_planed_info';
378 } else {
379 $a_item['start'] = $item['suggestion_start'];
380 $a_item['end'] = $item['suggestion_end'];
381 $a_item['activation_info'] = 'crs_timings_suggested_info';
382 }
383 } elseif ($item['timing_type'] == self::TIMINGS_PRESETTING) {
384 $a_item['start'] = $item['suggestion_start'];
385 $a_item['end'] = $item['suggestion_end'];
386 $a_item['activation_info'] = 'crs_timings_suggested_info';
387 } elseif ($item['timing_type'] == self::TIMINGS_ACTIVATION) {
388 $a_item['start'] = $item['timing_start'];
389 $a_item['end'] = $item['timing_end'];
390 $a_item['activation_info'] = 'obj_activation_list_gui';
391 } else {
392 $a_item['start'] = 'abc';
393 }
394
395 // #7359 - session sorting should always base on appointment date
396 if ($a_item['type'] == 'sess') {
397 include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
399
400 // #11987
401 $a_item['masked_start'] = $a_item['start'];
402 $a_item['masked_end'] = $a_item['end'];
403 $a_item['start'] = $info['start'];
404 $a_item['end'] = $info['end'];
405 }
406 }
407
415 public static function addListGUIActivationProperty(ilObjectListGUI $a_list_gui, array &$a_item)
416 {
417 global $DIC;
418
419 $lng = $DIC->language();
420
422 if (isset($a_item['timing_type'])) {
423 if (!isset($a_item['masked_start'])) {
424 $start = $a_item['start'];
425 $end = $a_item['end'];
426 } else {
427 $start = $a_item['masked_start'];
428 $end = $a_item['masked_end'];
429 }
430 $activation = '';
431 switch ($a_item['timing_type']) {
434 new ilDateTime($start, IL_CAL_UNIX),
436 );
437 break;
438
441 new ilDate($start, IL_CAL_UNIX),
443 );
444 break;
445 }
446 if ($activation != "") {
447 global $DIC;
448
449 $lng = $DIC->language();
450 $lng->loadLanguageModule('crs');
451
452 $a_list_gui->addCustomProperty(
453 $lng->txt($a_item['activation_info']),
454 $activation,
455 false,
456 true
457 );
458 }
459 }
460 }
461
468 protected static function createDefaultEntry($a_ref_id)
469 {
470 global $DIC;
471
472 $ilDB = $DIC->database();
473 $tree = $DIC->repositoryTree();
474
475 $parent_id = $tree->getParentId($a_ref_id);
476 if (!$parent_id) {
477 return;
478 }
479
480
481 $ilAtomQuery = $ilDB->buildAtomQuery();
482 $ilAtomQuery->addTableLock("crs_items");
483
484 $ilAtomQuery->addQueryCallable(function (ilDBInterface $ilDB) use ($a_ref_id, $parent_id, &$a_item) {
485 $sql = "SELECT * FROM crs_items" .
486 " WHERE obj_id = " . $ilDB->quote($a_ref_id, "integer");
487 $set = $ilDB->query($sql);
488 if (!$ilDB->numRows($set)) {
489 $now = time();
490 $now_parts = getdate($now);
491
492 $a_item = array();
493 $a_item["timing_type"] = self::TIMINGS_DEACTIVATED;
494 $a_item["timing_start"] = $now;
495 $a_item["timing_end"] = $now;
496 $a_item["suggestion_start"] = $now;
497 $a_item["suggestion_end"] = $now;
498 $a_item['visible'] = 0;
499 $a_item['changeable'] = 0;
500 $a_item['earliest_start'] = $now;
501 $a_item['latest_end'] = mktime(23, 55, 00, $now_parts["mon"], $now_parts["mday"], $now_parts["year"]);
502 $a_item['visible'] = 0;
503 $a_item['changeable'] = 0;
504
505 $query = "INSERT INTO crs_items (parent_id,obj_id,timing_type,timing_start,timing_end," .
506 "suggestion_start,suggestion_end, " .
507 "changeable,earliest_start,latest_end,visible,position) " .
508 "VALUES( " .
509 $ilDB->quote($parent_id, 'integer') . "," .
510 $ilDB->quote($a_ref_id, 'integer') . "," .
511 $ilDB->quote($a_item["timing_type"], 'integer') . "," .
512 $ilDB->quote($a_item["timing_start"], 'integer') . "," .
513 $ilDB->quote($a_item["timing_end"], 'integer') . "," .
514 $ilDB->quote($a_item["suggestion_start"], 'integer') . "," .
515 $ilDB->quote($a_item["suggestion_end"], 'integer') . "," .
516 $ilDB->quote($a_item["changeable"], 'integer') . "," .
517 $ilDB->quote($a_item['earliest_start'], 'integer') . ", " .
518 $ilDB->quote($a_item['latest_end'], 'integer') . ", " .
519 $ilDB->quote($a_item["visible"], 'integer') . ", " .
520 $ilDB->quote(0, 'integer') . ")";
521 $ilDB->manipulate($query);
522 }
523 });
524
525 $ilAtomQuery->run();
526
527 // #9982 - to make getItem()-cache work
528 $a_item["obj_id"] = $a_ref_id;
529 $a_item["parent_id"] = $parent_id;
530
531 return $a_item;
532 }
533
539 public static function deleteAllEntries($a_ref_id)
540 {
541 global $DIC;
542
543 $ilDB = $DIC->database();
544
545 if (!$a_ref_id) {
546 return;
547 }
548
549 $query = "DELETE FROM crs_items " .
550 "WHERE obj_id = " . $ilDB->quote($a_ref_id, 'integer');
551 $ilDB->manipulate($query);
552
553 $query = "DELETE FROM crs_items " .
554 "WHERE parent_id = " . $ilDB->quote($a_ref_id, 'integer');
555 $ilDB->manipulate($query);
556
557 return true;
558 }
559
567 public static function cloneDependencies($a_ref_id, $a_target_id, $a_copy_id)
568 {
569 global $DIC;
570
571 $ilLog = $DIC["ilLog"];
572
573 $ilLog->write(__METHOD__ . ': Begin course items...');
574
575 $items = self::getItems($a_ref_id);
576 if (!$items) {
577 $ilLog->write(__METHOD__ . ': No course items found.');
578 return true;
579 }
580
581 // new course item object
582 if (!is_object($new_container = ilObjectFactory::getInstanceByRefId($a_target_id, false))) {
583 $ilLog->write(__METHOD__ . ': Cannot create target object.');
584 return false;
585 }
586
587 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
588 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
589 $mappings = $cp_options->getMappings();
590
591 foreach ($items as $item) {
592 if (!isset($mappings[$item['parent_id']]) or !$mappings[$item['parent_id']]) {
593 $ilLog->write(__METHOD__ . ': No mapping for parent nr. ' . $item['parent_id']);
594 continue;
595 }
596 if (!isset($mappings[$item['obj_id']]) or !$mappings[$item['obj_id']]) {
597 $ilLog->write(__METHOD__ . ': No mapping for item nr. ' . $item['obj_id']);
598 continue;
599 }
600 $new_item_id = $mappings[$item['obj_id']];
601 $new_parent = $mappings[$item['parent_id']];
602
603 $new_item = new self();
604 $new_item->setTimingType($item['timing_type']);
605 $new_item->setTimingStart($item['timing_start']);
606 $new_item->setTimingEnd($item['timing_end']);
607 $new_item->setSuggestionStart($item['suggestion_start']);
608 $new_item->setSuggestionEnd($item['suggestion_end']);
609 $new_item->toggleChangeable($item['changeable']);
610 $new_item->setEarliestStart($item['earliest_start']);
611 $new_item->setLatestEnd($item['latest_end']);
612 $new_item->toggleVisible($item['visible']);
613 $new_item->update($new_item_id, $new_parent);
614
615 $ilLog->write(__METHOD__ . ': Added new entry for item nr. ' . $item['obj_id']);
616 }
617 $ilLog->write(__METHOD__ . ': Finished course items.');
618 }
619
620
621 //
622 // TIMINGS VIEW RELATED (COURSE ONLY)
623 //
624
631 public static function hasTimings($a_ref_id)
632 {
633 global $DIC;
634
635 $tree = $DIC->repositoryTree();
636 $ilDB = $DIC->database();
637
638 $subtree = $tree->getSubTree($tree->getNodeData($a_ref_id));
639 $ref_ids = array();
640 foreach ($subtree as $node) {
641 $ref_ids[] = $node['ref_id'];
642 }
643
644 $query = "SELECT * FROM crs_items " .
645 "WHERE timing_type = " . $ilDB->quote(self::TIMINGS_PRESETTING, 'integer') . " " .
646 "AND " . $ilDB->in('obj_id', $ref_ids, false, 'integer');
647 $res = $ilDB->query($query);
648 return $res->numRows() ? true :false;
649 }
650
657 public static function hasChangeableTimings($a_ref_id)
658 {
659 global $DIC;
660
661 $tree = $DIC->repositoryTree();
662 $ilDB = $DIC->database();
663
664 $subtree = $tree->getSubTree($tree->getNodeData($a_ref_id));
665 $ref_ids = array();
666 foreach ($subtree as $node) {
667 $ref_ids[] = $node['ref_id'];
668 }
669
670 $query = "SELECT * FROM crs_items " .
671 "WHERE timing_type = " . $ilDB->quote(self::TIMINGS_PRESETTING, 'integer') . " " .
672 "AND changeable = " . $ilDB->quote(1, 'integer') . " " .
673 "AND " . $ilDB->in('obj_id', $ref_ids, false, 'integer');
674 $res = $ilDB->query($query);
675 return $res->numRows() ? true : false;
676 }
677
684 protected static function processListItems(array $a_ref_ids)
685 {
686 global $DIC;
687
688 $tree = $DIC->repositoryTree();
689
690 $res = array();
691
692 foreach ($a_ref_ids as $item_ref_id) {
693 if ($tree->isDeleted($item_ref_id)) {
694 continue;
695 }
696 // #7571: when node is removed from system, e.g. inactive trashcan, an empty array is returned
697 $node = $tree->getNodeData($item_ref_id);
698 if ($node["ref_id"] != $item_ref_id) {
699 continue;
700 }
701 $res[$item_ref_id] = $node;
702 }
703
704 if (sizeof($res)) {
705 self::preloadData(array_keys($res));
706 foreach ($res as $idx => $item) {
708 $res[$idx] = $item;
709 }
710 }
711
712 return array_values($res);
713 }
714
721 public static function getItemsByEvent($a_event_id)
722 {
723 include_once 'Modules/Session/classes/class.ilEventItems.php';
724 $event_items = new ilEventItems($a_event_id);
725 return self::processListItems($event_items->getItems());
726 }
727
734 public static function getItemsByItemGroup($a_item_group_ref_id)
735 {
736 include_once 'Modules/ItemGroup/classes/class.ilItemGroupItems.php';
737 $ig_items = new ilItemGroupItems($a_item_group_ref_id);
738 $items = $ig_items->getValidItems();
739 return self::processListItems($items);
740 }
741
748 public static function getItemsByObjective($a_objective_id)
749 {
750 include_once('./Modules/Course/classes/class.ilCourseObjectiveMaterials.php');
751 $item_ids = ilCourseObjectiveMaterials::_getAssignedMaterials($a_objective_id);
752 return self::processListItems($item_ids);
753 }
754
762 public static function getItems($a_parent_id, $a_with_list_data = true)
763 {
764 global $DIC;
765
766 $tree = $DIC->repositoryTree();
767
768 $items = array();
769
770 $ref_ids = array();
771 foreach ($tree->getChilds($a_parent_id) as $item) {
772 if ($item['type'] != 'rolf') {
773 $items[] = $item;
774 $ref_ids[] = $item['ref_id'];
775 }
776 }
777
778 if ($ref_ids) {
779 self::preloadData($ref_ids);
780
781 foreach ($items as $idx => $item) {
782 if (!$a_with_list_data) {
783 $items[$idx] = array_merge($item, self::getItem($item['ref_id']));
784 } else {
786 $items[$idx] = $item;
787 }
788 }
789 }
790
791 return $items;
792 }
793
800 public static function getTimingsAdministrationItems($a_parent_id)
801 {
802 $items = self::getItems($a_parent_id, false);
803
804 if ($items) {
805 $active = $inactive = array();
806 foreach ($items as $item) {
807 // active should be first in order
808 if ($item['timing_type'] == self::TIMINGS_DEACTIVATED) {
809 $inactive[] = $item;
810 } else {
811 $active[] = $item;
812 }
813 }
814
815 $active = ilUtil::sortArray($active, 'start', 'asc');
816 $inactive = ilUtil::sortArray($inactive, 'title', 'asc');
817 $items = array_merge($active, $inactive);
818 }
819
820 return $items;
821 }
822
829 public static function getTimingsItems($a_container_ref_id)
830 {
831 global $DIC;
832
833 $objDefinition = $DIC["objDefinition"];
834
835 $filtered = array();
836
837 include_once 'Modules/Session/classes/class.ilEventItems.php';
838 $event_items = ilEventItems::_getItemsOfContainer($a_container_ref_id);
839 foreach (self::getTimingsAdministrationItems($a_container_ref_id) as $item) {
840 if (!in_array($item['ref_id'], $event_items) &&
841 !$objDefinition->isSideBlock($item['type'])) {
842 $filtered[] = $item;
843 }
844 }
845
846 return $filtered;
847 }
848}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
error($a_errmsg)
set error message @access public
static _getInstance($a_copy_id)
Get instance of copy wizard options.
static _getAssignedMaterials($a_objective_id)
get assigned materials
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
@classDescription Date and time handling
Class for single dates.
class ilEvent
static _getItemsOfContainer($a_ref_id)
Class ilObjectActivation.
getTimingStart()
Get timing start.
setTimingStart($a_start)
Set timing start.
setEarliestStart($a_start)
Set earliest start.
validateActivation()
Validate current properties.
setLatestEnd($a_end)
Set latest end.
enabledVisible()
Get visible status.
static getTimingsAdministrationItems($a_parent_id)
Get (sub) item data for timings administration view (active/inactive)
getEarliestStart()
Get earliest start.
getTimingType()
get timing type
static createDefaultEntry($a_ref_id)
Create db entry with default values.
setTimingType($a_type)
Set timing type.
update($a_ref_id, $a_parent_id=null)
Update db entry.
setSuggestionStart($a_start)
Set suggestion start.
static addListGUIActivationProperty(ilObjectListGUI $a_list_gui, array &$a_item)
Get timing details for list gui.
static getItemsByObjective($a_objective_id)
Get objective items.
static deleteAllEntries($a_ref_id)
Delete all db entries for ref id.
static cloneDependencies($a_ref_id, $a_target_id, $a_copy_id)
Clone dependencies.
enabledChangeable()
Get changeable status.
static hasChangeableTimings($a_ref_id)
Check if there is any active changeable timing (in subtree)
static getItemsByEvent($a_event_id)
Get session material / event items.
setTimingEnd($a_end)
Set timing end.
toggleChangeable($a_status)
Set changeable status.
static hasTimings($a_ref_id)
Check if there is any active timing (in subtree)
static preloadData(array $a_ref_ids)
Preload data to internal cache.
static processListItems(array $a_ref_ids)
Validate ref ids and add list data.
static getItemsByItemGroup($a_item_group_ref_id)
Get materials of item group.
static addAdditionalSubItemInformation(array &$a_item)
Parse item data for list entries.
getSuggestionStart()
Get suggestion start.
static getTimingsItems($a_container_ref_id)
Get (sub) item data for timings view (no session material, no side blocks)
getSuggestionEnd()
Get suggestion end.
static getItem($a_ref_id)
Get item data.
toggleVisible($a_status)
Set visible status.
setSuggestionEnd($a_end)
Set suggestion end.
static getItems($a_parent_id, $a_with_list_data=true)
Get sub item data.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObjectListGUI.
addCustomProperty( $a_property="", $a_value="", $a_alert=false, $a_newline=false)
add custom property
static _lookupObjId($a_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
static _lookupAppointment($a_obj_id)
lookup appointment
static _getPlanedTimings($a_usr_id, $a_item_id)
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
Interface ilDBInterface.
$end
Definition: saml1-acs.php:18
$info
Definition: index.php:5
$query
global $ilErr
Definition: raiseError.php:16
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92