ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilObjStudyProgramme.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2015 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 require_once("./Services/Container/classes/class.ilContainer.php");
6 require_once('./Services/Container/classes/class.ilContainerSorting.php');
7 require_once("./Modules/StudyProgramme/classes/model/class.ilStudyProgramme.php");
8 require_once("./Modules/StudyProgramme/classes/class.ilObjectFactoryWrapper.php");
9 require_once("./Modules/StudyProgramme/classes/interfaces/interface.ilStudyProgrammeLeaf.php");
10 require_once("./Modules/StudyProgramme/classes/exceptions/class.ilStudyProgrammeTreeException.php");
11 require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgrammeCache.php");
12 
19  protected $settings; // ilStudyProgramme | null
20  protected $parent; // ilObjStudyProgramme | null | false
21  protected $children; // [ilObjStudyProgramme] | null
22  protected $lp_children; // [ilStudyProgrammeLeaf] | null;
23 
24  // GLOBALS from ILIAS
25  public $tree;
26  public $ilUser;
27 
28  // Wrapped static ilObjectFactory of ILIAS.
30  // Cache for study programmes
31  static public $study_programme_cache = null;
32 
40  public function __construct($a_id = 0, $a_call_by_reference = true) {
41  $this->type = "prg";
42  $this->settings = null;
43  parent::__construct($a_id, $a_call_by_reference);
44 
45  $this->clearParentCache();
46  $this->clearChildrenCache();
47  $this->clearLPChildrenCache();
48 
49  global $DIC;
50  $tree = $DIC['tree'];
51  $ilUser = $DIC['ilUser'];
52  $this->tree = $tree;
53  $this->ilUser = $ilUser;
54 
55  $this->object_factory = ilObjectFactoryWrapper::singleton();
56  self::initStudyProgrammeCache();
57  }
58 
59  static public function initStudyProgrammeCache() {
60  if (self::$study_programme_cache === null) {
61  self::$study_programme_cache = ilObjStudyProgrammeCache::singleton();
62  }
63  }
64 
68  protected function clearParentCache() {
69  // This is not initialized, but we need null if there is no parent.
70  $this->parent = false;
71  }
72 
76  protected function clearChildrenCache() {
77  $this->children = null;
78  }
79 
83  protected function clearLPChildrenCache() {
84  $this->lp_children = null;
85  }
86 
87 
94  static public function getInstanceByRefId($a_ref_id) {
95  require_once("Modules/StudyProgramme/classes/class.ilObjStudyProgrammeCache.php");
96  if (self::$study_programme_cache === null) {
97  self::initStudyProgrammeCache();
98  }
99  return self::$study_programme_cache->getInstanceByRefId($a_ref_id);
100  }
101 
105  static public function createInstance() {
106  $obj = new ilObjStudyProgramme();
107  $obj->create();
108  $obj->createReference();
109  self::$study_programme_cache->addInstance($obj);
110  return $obj;
111  }
112 
113 
115  // CRUD
117 
122  protected function readSettings() {
123  if ($this->settings !== null) {
124  throw new ilException("ilObjStudyProgramme::loadSettings: already loaded.");
125  }
126  $id = $this->getId();
127  if (!$id) {
128  throw new ilException("ilObjStudyProgramme::loadSettings: no id.");
129  }
130  $this->settings = new ilStudyProgramme($this->getId());
131  }
132 
137  protected function createSettings() {
138  if ($this->settings !== null) {
139  throw new ilException("ilObjStudyProgramme::createSettings: already loaded.");
140  }
141 
142  $id = $this->getId();
143  if (!$id) {
144  throw new ilException("ilObjStudyProgramme::loadSettings: no id.");
145  }
147  }
148 
153  protected function updateSettings() {
154  if ($this->settings === null) {
155  throw new ilException("ilObjStudyProgramme::updateSettings: no settings loaded.");
156  }
157  $this->settings->update();
158  }
159 
164  protected function deleteSettings() {
165  if ($this->settings === null) {
166  throw new Exception("ilObjStudyProgramme::deleteSettings: no settings loaded.");
167  }
168  $this->settings->delete();
169  }
170 
174  protected function deleteAssignments() {
175  foreach ($this->getAssignments() as $ass) {
176  $ass->delete();
177  }
178  }
179 
180  public function read() {
181  parent::read();
182  $this->readSettings();
183  }
184 
185 
186  public function create() {
187  $id = parent::create();
188  $this->createSettings();
189 
190  return $id;
191  }
192 
193 
194  public function update() {
195  parent::update();
196 
197  // Update selection for advanced meta data of the type
198  if ($this->getSubType()) {
199  ilAdvancedMDRecord::saveObjRecSelection($this->getId(), 'prg_type', $this->getSubType()->getAssignedAdvancedMDRecordIds());
200  } else {
201  // If no type is assigned, delete relations by passing an empty array
202  ilAdvancedMDRecord::saveObjRecSelection($this->getId(), 'prg_type', array());
203  }
204 
205  $this->updateSettings();
206  }
207 
213  public function delete() {
214  // always call parent delete function first!!
215  if (!parent::delete()) {
216  return false;
217  }
218 
219  $this->deleteSettings();
220  try {
221  $this->deleteAssignments();
222  } catch(ilStudyProgrammeTreeException $e) {
223  // This would be the case when SP is in trash (#17797)
224  }
225 
226  return true;
227  }
228 
230  // GETTERS AND SETTERS
232 
238  public function getLastChange() {
239  return $this->settings->getLastChange();
240  }
241 
247  public function getPoints() {
248  return $this->settings->getPoints();
249  }
250 
258  public function setPoints($a_points) {
259  $this->settings->setPoints($a_points);
260  $this->updateLastChange();
261  return $this;
262  }
263 
269  public function getLPMode() {
270  return $this->settings->getLPMode();
271  }
272 
281  public function adjustLPMode() {
282  if ($this->getAmountOfLPChildren() > 0) {
284  ->update();
285  }
286  else {
287  if ($this->getAmountOfChildren() > 0) {
288  $this->settings->setLPMode(ilStudyProgramme::MODE_POINTS)
289  ->update();
290  }
291  else {
292  $this->settings->setLPMode(ilStudyProgramme::MODE_UNDEFINED)
293  ->update();
294  }
295  }
296  }
297 
303  public function getStatus() {
304  return $this->settings->getStatus();
305  }
306 
313  public function setStatus($a_status) {
314  $this->settings->setStatus($a_status);
315  $this->updateLastChange();
316  return $this;
317  }
318 
324  public function isActive() {
325  return $this->getStatus() == ilStudyProgramme::STATUS_ACTIVE;
326  }
327 
333  public function getSubtypeId() {
334  return $this->settings->getSubtypeId();
335  }
336 
337 
345  public function setSubtypeId($a_subtype_id) {
346  $this->settings->setSubtypeId($a_subtype_id);
347  return $this;
348  }
349 
355  public function getSubType() {
356  if(!in_array($this->getSubtypeId(), array("-", "0"))) {
357  $subtype_id = $this->getSubtypeId();
358  return new ilStudyProgrammeType($subtype_id);
359  }
360 
361  return null;
362  }
363 
365  // TREE NAVIGATION
367 
377  static public function getAllChildren($a_ref_id) {
378  $ret = array();
379  $root = self::getInstanceByRefId($a_ref_id);
380  $root_id = $root->getId();
381  $root->applyToSubTreeNodes(function($prg) use (&$ret, $root_id) {
382  // exclude root node of subtree.
383  if ($prg->getId() == $root_id) {
384  return;
385  }
386  $ret[] = $prg;
387  });
388  return $ret;
389  }
390 
399  public function getChildren() {
400  $this->throwIfNotInTree();
401 
402  if ($this->children === null) {
403  $ref_ids = $this->tree->getChildsByType($this->getRefId(), "prg");
404 
405  // apply container sorting to tree
406  $sorting = ilContainerSorting::_getInstance($this->getId());
407  $ref_ids = $sorting->sortItems(array('prg'=>$ref_ids));
408  $ref_ids = $ref_ids['prg'];
409 
410  $this->children = array_map(function($node_data) {
411  return ilObjStudyProgramme::getInstanceByRefId($node_data["child"]);
412  }, $ref_ids);
413  }
414 
415  return $this->children;
416  }
417 
426  public function getParent() {
427  if ($this->parent === false) {
428  $this->throwIfNotInTree();
429  $parent_data = $this->tree->getParentNodeData($this->getRefId());
430  if ($parent_data["type"] != "prg") {
431  $this->parent = null;
432  }
433  else {
434  $this->parent = ilObjStudyProgramme::getInstanceByRefId($parent_data["ref_id"]);
435  }
436  }
437  return $this->parent;
438  }
439 
445  public function getParents() {
446  $current = $this;
447  $parents = array();
448  while(true) {
449  $current = $current->getParent();
450  if ($current === null) {
451  return array_reverse($parents);
452  }
453  $parents[] = $current;
454  }
455  }
456 
464  public function hasChildren() {
465  return $this->getAmountOfChildren() > 0;
466  }
467 
476  public function getAmountOfChildren() {
477  return count($this->getChildren());
478  }
479 
488  public function getDepth() {
489  $cur = $this;
490  $count = 0;
491  while ($cur = $cur->getParent()) {
492  $count++;
493  }
494  return $count;
495  }
496 
505  public function getRoot() {
506  $parents = $this->getParents();
507  return $parents[0];
508  }
509 
517  public function getLPChildren() {
518  $this->throwIfNotInTree();
519 
520  if ($this->lp_children === null) {
521  $this->lp_children = array();
522 
523  // TODO: find a better way to get all elements except StudyProgramme-children
524  $ref_ids = $this->tree->getChildsByType($this->getRefId(), "crsr");
525 
526  // apply container sorting to tree
527  $sorting = ilContainerSorting::_getInstance($this->getId());
528  $ref_ids = $sorting->sortItems(array('crs_ref'=>$ref_ids));
529  $ref_ids = $ref_ids['crs_ref'];
530 
531  $lp_children = array_map(function($node_data) {
532  $lp_obj = $this->object_factory->getInstanceByRefId($node_data["child"]);
533 
534  // filter out all StudyProgramme instances
535  return ($lp_obj instanceof $this)? null : $lp_obj;
536  }, $ref_ids);
537 
538  $this->lp_children = array_filter($lp_children);
539  }
540  return $this->lp_children;
541  }
542 
550  public function getLPChildrenIds() {
551  return array_map(function($child) {
552  return $child->getId();
553  }, $this->getLPChildren());
554  }
555 
561  public function getAmountOfLPChildren() {
562  return count($this->getLPChildren());
563  }
564 
572  public function hasLPChildren() {
573  return ($this->getAmountOfLPChildren() > 0);
574  }
575 
580  protected function throwIfNotInTree() {
581  if (!$this->tree->isInTree($this->getRefId())) {
582  throw new ilStudyProgrammeTreeException("This program is not in tree.");
583  }
584  }
585 
587  // QUERIES ON SUBTREE
589 
600  public function applyToSubTreeNodes(Closure $fun) {
601  $this->throwIfNotInTree();
602 
603  if ($fun($this) !== false) {
604  foreach($this->getChildren() as $child) {
605  $child->applyToSubTreeNodes($fun);
606  }
607  }
608  }
609 
616  public function getCompletedCourses($a_user_id) {
617  require_once("Services/ContainerReference/classes/class.ilContainerReference.php");
618  require_once("Services/Tracking/classes/class.ilLPStatus.php");
619 
620  $node_data = $this->tree->getNodeData($this->getRefId());
621  $crsrs = $this->tree->getSubTree($node_data, true, "crsr");
622 
623  $completed_crss = array();
624  foreach ($crsrs as $ref) {
625  $crs_id = ilContainerReference::_lookupTargetId($ref["obj_id"]);
626  if (ilLPStatus::_hasUserCompleted($crs_id, $a_user_id)) {
627  $completed_crss[] = array( "crs_id" => $crs_id
628  , "prg_ref_id" => $ref["parent"]
629  , "crsr_ref_id" => $ref["child"]
630  , "crsr_id" => $ref["obj_id"]
631  , "title" => ilContainerReference::_lookupTargetTitle($ref["obj_id"])
632  );
633  }
634  }
635 
636  return $completed_crss;
637  }
638 
640  // TREE MANIPULATION
642 
653  public function addNode(ilObjStudyProgramme $a_prg) {
654  $this->throwIfNotInTree();
655 
657  throw new ilStudyProgrammeTreeException("Program already contains leafs.");
658  }
659 
660  if ($this->tree->isInTree($a_prg->getRefId())) {
661  throw new ilStudyProgrammeTreeException("Other program already is in tree.");
662  }
663 
664  if ($a_prg->getRefId() === null) {
665  $a_prg->createReference();
666  }
667  $a_prg->putInTree($this->getRefId());
668  return $this;
669  }
670 
674  protected function nodeInserted(ilObjStudyProgramme $a_prg) {
676  throw new ilStudyProgrammeTreeException("Program already contains leafs.");
677  }
678 
679  if ($this->settings->getLPMode() !== ilStudyProgramme::MODE_POINTS) {
680  $this->settings->setLPMode(ilStudyProgramme::MODE_POINTS)
681  ->update();
682  }
683 
684  $this->clearChildrenCache();
685  $this->addMissingProgresses();
686  }
687 
693  public function putInTree($a_parent_ref) {
694  $res = parent::putInTree($a_parent_ref);
695 
696  if (ilObject::_lookupType($a_parent_ref, true) == "prg") {
697  $par = ilObjStudyProgramme::getInstanceByRefId($a_parent_ref);
698  $par->nodeInserted($this);
699  }
700 
701  return $res;
702  }
703 
714  public function removeNode(ilObjStudyProgramme $a_prg) {
715  if ($a_prg->getParent()->getId() !== $this->getId()) {
716  throw new ilStudyProgrammeTreeException("This is no parent of the given programm.");
717  }
718 
719  if (!$a_prg->canBeRemoved()) {
720  throw new ilStudyProgrammeTreeException("The node has relevant assignments.");
721  }
722 
723  // *sigh*...
724  $node_data = $this->tree->getNodeData($a_prg->getRefId());
725  $this->tree->deleteTree($node_data);
726  $a_prg->clearParentCache();
727  $this->clearChildrenCache();
728 
729  return $this;
730  }
731 
738  public function canBeRemoved() {
739  foreach($this->getProgresses() as $progress) {
740  if ($progress->getStatus() != ilStudyProgrammeProgress::STATUS_NOT_RELEVANT) {
741  return false;
742  }
743  if ($progress->getLastChangeBy() !== null) {
744  return false;
745  }
746  }
747  return true;
748  }
749 
759  public function addLeaf(/*ilStudyProgrammeLeaf*/ $a_leaf) {
760  $this->throwIfNotInTree();
761 
762  if ($this->hasChildren()) {
763  throw new ilStudyProgrammeTreeException("Program already contains other programm nodes.");
764  }
765 
766  if ($a_leaf->getRefId() === null) {
767  $a_leaf->createReference();
768  }
769  $a_leaf->putInTree($this->getRefId());
770  $this->clearLPChildrenCache();
771 
773  $this->update();
774 
775  return $this;
776  }
777 
788  public function removeLeaf(/*ilStudyProgrammeLeaf*/ $a_leaf) {
789  if (self::getParentId($a_leaf) !== $this->getId()) {
790  throw new ilStudyProgrammeTreeException("This is no parent of the given leaf node.");
791  }
792 
793  $node_data = $this->tree->getNodeData($a_leaf->getRefId());
794  $this->tree->deleteTree($node_data);
795  $this->clearLPChildrenCache();
796 
797  return $this;
798  }
799 
810  public function moveTo(ilObjStudyProgramme $a_new_parent) {
811  global $DIC;
812  $rbacadmin = $DIC['rbacadmin'];
813 
814  if ($parent = $this->getParent()) {
815 
816  // TODO: check if there some leafs in the new parent
817 
818  $this->tree->moveTree($this->getRefId(), $a_new_parent->getRefId());
819  // necessary to clean up permissions
820  $rbacadmin->adjustMovedObjectPermissions($this->getRefId(), $parent->getRefId());
821 
822  // TODO: lp-progress needs to be updated
823 
824  // clear caches on different nodes
825  $this->clearParentCache();
826 
827  $parent->clearChildrenCache();
828  $parent->clearLPChildrenCache();
829 
830  $a_new_parent->clearChildrenCache();
831  $a_new_parent->clearLPChildrenCache();
832  }
833 
834  return $this;
835  }
836 
838  // USER ASSIGNMENTS
840 
854  public function assignUser($a_usr_id, $a_assigning_usr_id = null) {
855  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserAssignment.php");
856  require_once("./Modules/StudyProgramme/classes/model/class.ilStudyProgrammeAssignment.php");
857  require_once("./Modules/StudyProgramme/classes/model/class.ilStudyProgrammeProgress.php");
858  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeEvents.php");
859 
860  if ($this->settings === null) {
861  throw new ilException("ilObjStudyProgramme::assignUser: Program was not properly created.'");
862  }
863 
864  if ($this->getStatus() != ilStudyProgramme::STATUS_ACTIVE) {
865  throw new ilException("ilObjStudyProgramme::assignUser: Can't assign user to program '"
866  .$this->getId()."', since it's not in active status.");
867  }
868 
869  if ($a_assigning_usr_id === null) {
870  $a_assigning_usr_id = $this->ilUser->getId();
871  }
872 
873  $ass_mod = ilStudyProgrammeAssignment::createFor($this->settings, $a_usr_id, $a_assigning_usr_id);
874  $ass = new ilStudyProgrammeUserAssignment($ass_mod);
875 
876  $this->applyToSubTreeNodes(function(ilObjStudyProgramme $node) use ($ass_mod, $a_assigning_usr_id) {
877  $progress = $node->createProgressForAssignment($ass_mod);
878  if ($node->getStatus() != ilStudyProgramme::STATUS_ACTIVE) {
880  ->update();
881  }
882  });
883 
885 
886  return $ass;
887  }
888 
897  public function removeAssignment(ilStudyProgrammeUserAssignment $a_assignment) {
898  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeEvents.php");
899 
900  if ($a_assignment->getStudyProgramme()->getId() != $this->getId()) {
901  throw new ilException("ilObjStudyProgramme::removeAssignment: Assignment '"
902  .$a_assignment->getId()."' does not belong to study "
903  ."program '".$this->getId()."'.");
904  }
905 
907 
908  $a_assignment->delete();
909 
910  return $this;
911  }
912 
919  public function hasAssignmentOf($a_user_id) {
920  return $this->getAmountOfAssignmentsOf($a_user_id) > 0;
921  }
922 
930  public function getAmountOfAssignmentsOf($a_user_id) {
931  return count($this->getAssignmentsOf($a_user_id));
932  }
933 
942  public function getAssignmentsOf($a_user_id) {
943  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserAssignment.php");
944 
945  $prg_ids = $this->getIdsFromNodesOnPathFromRootToHere();
946  $assignments = ilStudyProgrammeAssignment::where(array( "usr_id" => $a_user_id
947  , "root_prg_id" => $prg_ids
948  ))
949  ->orderBy("last_change", "DESC")
950  ->get();
951  return array_map(function($ass) {
952  return new ilStudyProgrammeUserAssignment($ass);
953  }, array_values($assignments)); // use array values since we want keys 0...
954  }
955 
961  public function getAssignments() {
962  return array_map(function($ass) {
963  return new ilStudyProgrammeUserAssignment($ass);
964  }, array_values($this->getAssignmentsRaw())); // use array values since we want keys 0...
965  }
966 
972  public function hasAssignments() {
973  return count($this->getAssignments()) > 0;
974  }
975 
981  public function updateAllAssignments() {
983  foreach ($assignments as $ass) {
984  $ass->updateFromProgram();
985  }
986  return $this;
987  }
988 
990  // USER PROGRESS
992 
1000  return ilStudyProgrammeProgress::createFor($this->settings, $ass);
1001  }
1002 
1009  public function getProgressesOf($a_user_id) {
1010  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
1011  return ilStudyProgrammeUserProgress::getInstancesForUser($this->getId(), $a_user_id);
1012  }
1013 
1023  public function getProgressForAssignment($a_assignment_id) {
1024  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
1025  return ilStudyProgrammeUserProgress::getInstanceForAssignment($this->getId(), $a_assignment_id);
1026  }
1027 
1035  public function addMissingProgresses() {
1036  foreach ($this->getAssignments() as $ass) {
1037  $ass->addMissingProgresses();
1038  }
1039  }
1040 
1046  public function getProgresses() {
1047  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
1049  }
1050 
1056  public function hasProgresses() {
1057  return count($this->getProgresses()) > 0;
1058  }
1059 
1065  public function hasRelevantProgresses() {
1066  foreach ($this->getProgresses() as $progress) {
1067  if ($progress->isRelevant()) {
1068  return true;
1069  }
1070  }
1071  return false;
1072  }
1073 
1080  $returns = array();
1081  foreach ($this->getProgresses() as $progress) {
1082  if ($progress->isRelevant()) {
1083  $returns[] = $progress->getUserId();
1084  }
1085  }
1086  return array_unique($returns);
1087  }
1088 
1095  $returns = array();
1096  foreach ($this->getProgresses() as $progress) {
1097  if ($progress->isSuccessful()) {
1098  $returns[] = $progress->getUserId();
1099  }
1100  }
1101  return array_unique($returns);
1102  }
1103 
1111  $returns = array();
1112  foreach ($this->getProgresses() as $progress) {
1113  if ($progress->isRelevant() && !$progress->isSuccessful()) {
1114  $returns[] = $progress->getUserId();
1115  }
1116  }
1117  return array_unique($returns);
1118  }
1119 
1121  // HELPERS
1123 
1127  protected function updateLastChange() {
1128  $this->settings->updateLastChange();
1129  if ($parent = $this->getParent()) {
1130  $parent->updateLastChange();
1131  }
1132  $this->update();
1133  }
1134 
1140  $prg_ids =array_map(function($par) {
1141  return $par->getId();
1142  }, $this->getParents());
1143  $prg_ids[] = $this->getId();
1144  return $prg_ids;
1145  }
1146 
1150  protected function getAssignmentsRaw() {
1151  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserAssignment.php");
1152  $prg_ids = $this->getIdsFromNodesOnPathFromRootToHere();
1153  return ilStudyProgrammeAssignment::where(array( "root_prg_id" => $prg_ids))
1154  ->orderBy("last_change", "DESC")
1155  ->get();
1156  }
1157 
1162  static public function setProgressesCompletedFor($a_obj_id, $a_user_id) {
1163  // We only use courses via crs_refs
1164  $type = ilObject::_lookupType($a_obj_id);
1165  if ($type == "crs") {
1166  require_once("Services/ContainerReference/classes/class.ilContainerReference.php");
1167  $crs_reference_obj_ids = ilContainerReference::_lookupSourceIds($a_obj_id);
1168  foreach ($crs_reference_obj_ids as $obj_id) {
1169  foreach(ilObject::_getAllReferences($obj_id) as $ref_id) {
1170  self::setProgressesCompletedIfParentIsProgrammeInLPCompletedMode($ref_id, $obj_id, $a_user_id);
1171  }
1172  }
1173  }
1174  else {
1175  foreach (ilObject::_getAllReferences($a_obj_id) as $ref_id) {
1176  self::setProgressesCompletedIfParentIsProgrammeInLPCompletedMode($ref_id, $a_obj_id, $a_user_id);
1177  }
1178  }
1179  }
1180 
1181  static protected function setProgressesCompletedIfParentIsProgrammeInLPCompletedMode($a_ref_id, $a_obj_id, $a_user_id) {
1182  global $DIC; // TODO: replace this by a settable static for testing purpose?
1183  $tree = $DIC['tree'];
1184  $node_data = $tree->getParentNodeData($a_ref_id);
1185  if ($node_data["type"] !== "prg") {
1186  return;
1187  }
1188  self::initStudyProgrammeCache();
1189  $prg = ilObjStudyProgramme::getInstanceByRefId($node_data["child"]);
1190  if ($prg->getLPMode() != ilStudyProgramme::MODE_LP_COMPLETED) {
1191  return;
1192  }
1193  foreach ($prg->getProgressesOf($a_user_id) as $progress) {
1194  $progress->setLPCompleted($a_obj_id, $a_user_id);
1195  }
1196  }
1197 
1204  static protected function getParentId(ilObject $a_object) {
1205  global $DIC;
1206  $tree = $DIC['tree'];
1207  if (!$tree->isInTree($a_object->getRefId())) {
1208  return null;
1209  }
1210 
1211  $nd = $tree->getParentNodeData($a_object->getRefId());
1212  return $nd["obj_id"];
1213  }
1214 
1222  public function getRawSettings() {
1223  return $this->settings;
1224  }
1225 
1230  public function updateCustomIcon() {
1231  $subtype = $this->getSubType();
1232 
1233  if($subtype) {
1234  if(is_file($subtype->getIconPath(true))) {
1235  $icon = $subtype->getIconPath(true);
1236  $this->saveIcons($icon);
1237  } else {
1238  $this->removeCustomIcon();
1239  }
1240  } else {
1241  $this->removeCustomIcon();
1242  }
1243  }
1244 
1246  // HOOKS
1248 
1259  static public function getCreatableSubObjects($a_subobjects, $a_ref_id) {
1260  if ($a_ref_id === null) {
1261  return $a_subobjects;
1262  }
1263 
1264  if (ilObject::_lookupType($a_ref_id, true) != "prg") {
1265  throw new ilException("Ref-Id '$a_ref_id' does not belong to a study programme object.");
1266  }
1267 
1269 
1270  $mode = $parent->getLPMode();
1271 
1272  switch ($mode) {
1274  return $a_subobjects;
1276  return array("prg" => $a_subobjects["prg"]);
1278  unset($a_subobjects["prg"]);
1279  return $a_subobjects;
1280  }
1281 
1282  throw new ilException("Undefined mode for study programme: '$mode'");
1283  }
1284 
1286  // REWRITES FROM PARENT
1288 
1292  function saveIcons($a_custom_icon)
1293  {
1294  global $DIC;
1295  $ilDB = $DIC['ilDB'];
1296 
1297  $this->createContainerDirectory();
1298  $cont_dir = $this->getContainerDirectory();
1299  $file_name = "";
1300  if ($a_custom_icon != "")
1301  {
1302  $file_name = $cont_dir."/icon_custom.svg";
1303 
1304  ilUtil::moveUploadedFile($a_custom_icon, "icon_custom.svg", $file_name, true, "copy");
1305 
1306  if ($file_name != "" && is_file($file_name))
1307  {
1308  ilContainer::_writeContainerSetting($this->getId(), "icon_custom", 1);
1309  }
1310  else
1311  {
1312  ilContainer::_writeContainerSetting($this->getId(), "icon_custom", 0);
1313  }
1314  }
1315  }
1316 }
1317 
1318 ?>
updateAllAssignments()
Update all assignments to this program node.
adjustLPMode()
Adjust the lp mode to match current state of tree:
addNode(ilObjStudyProgramme $a_prg)
Inserts another ilObjStudyProgramme in this object.
clearLPChildrenCache()
Clear the cached lp children.
static getAllChildren($a_ref_id)
Get a list of all ilObjStudyProgrammes in the subtree starting at $a_ref_id.
Base class for ILIAS Exception handling.
getSubType()
Gets the SubType Object.
applyToSubTreeNodes(Closure $fun)
Apply the given Closure to every node in the subtree starting at this object.
setPoints($a_points)
Set the amount of points.
static createFor(ilStudyProgramme $a_prg, ilStudyProgrammeAssignment $a_ass)
Create a new progress object for a given program node and assignment.
getParent()
Get the parent ilObjStudyProgramme of this object.
assignUser($a_usr_id, $a_assigning_usr_id=null)
Assign a user to this node at the study program.
addLeaf( $a_leaf)
Insert a leaf in this object.
static getInstanceForAssignment($a_program_id, $a_assignment_id)
Get the instance for the assignment on the program.
getIdsOfUsersWithCompletedProgress()
Get the ids of all users that have completed this programme.
createSettings()
Create new settings object.
getCompletedCourses($a_user_id)
Get courses in this program that the given user already completed.
hasChildren()
Does this StudyProgramme have other ilObjStudyProgrammes as children?
updateSettings()
Update settings in DB.
removeCustomIcon()
remove small icon
setSubtypeId($a_subtype_id)
Sets the meta-data subtype id.
getLPChildren()
Get the leafs the study programme contains.
Class ilObject Basic functions for all objects.
getStudyProgramme()
Get the program node where this assignment was made.
updateCustomIcon()
updates the selected custom icon in container folder by type
removeLeaf( $a_leaf)
Remove a leaf from this object.
hasProgresses()
Are there any users that have a progress on this programme?
Class ilStudyProgramme.
getAmountOfChildren()
Get the amount of other StudyProgrammes this StudyProgramme has as children.
static userAssigned(ilStudyProgrammeUserAssignment $a_assignment)
getAssignmentsRaw()
Get model objects for the assignments on this programm.
getAmountOfAssignmentsOf($a_user_id)
Get the amount of assignments a user has on this program node or any node above.
isActive()
Check whether this programme is active.
deleteSettings()
Delete settings from DB.
getAssignmentsOf($a_user_id)
Get the assignments of user at this program or any node above.
static where($where, $operator=null)
static getInstancesForUser($a_program_id, $a_user_id)
Get the instances that user has on program.
static saveObjRecSelection($a_obj_id, $a_sub_type="", array $a_records=null, $a_delete_before=true)
Save repository object record selection.
hasLPChildren()
Does this StudyProgramme has leafs?
static _getAllReferences($a_id)
get all reference ids of object
setStatus($a_status)
Set the status of the node.
getAmountOfLPChildren()
Get the amount of leafs, the study programme contains.
saveIcons($a_custom_icon)
save container icons
getRoot()
Get the ilObjStudyProgramme that is the root node of the tree this programme is in.
static getInstanceByRefId($a_ref_id)
Get an instance of ilObjStudyProgramme, use cache.
static getParentId(ilObject $a_object)
Get the obj id of the parent object for the given object.
createReference()
creates reference for object
removeNode(ilObjStudyProgramme $a_prg)
Remove a node from this object.
hasAssignments()
Are there any assignments on this node or any node above?
getProgresses()
Get all progresses on this node.
$nd
Definition: error.php:11
getContainerDirectory()
Get the container directory.
clearChildrenCache()
Clear the cached children.
getId()
get object id public
hasRelevantProgresses()
Are there any users that have a relevant progress on this programme?
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static _hasUserCompleted($a_obj_id, $a_user_id)
Lookup user object completion.
Class ilObjStudyProgramme.
getProgressForAssignment($a_assignment_id)
Get the progress for an assignment on this node.
nodeInserted(ilObjStudyProgramme $a_prg)
Clears child chache and adds progress for new node.
getIdsOfUsersWithNotCompletedAndRelevantProgress()
Get the ids of all users that have not completed this programme but have a relevant progress on it...
static _lookupTargetTitle($a_obj_id)
Lookup target title.
Class ilStudyProgrammeAssignment.
Class ilContainer.
delete()
Delete the assignment from database.
static setProgressesCompletedIfParentIsProgrammeInLPCompletedMode($a_ref_id, $a_obj_id, $a_user_id)
static userDeassigned(ilStudyProgrammeUserAssignment $a_assignment)
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
getIdsOfUsersWithRelevantProgress()
Get the ids of all users that have a relevant progress at this programme.
static getCreatableSubObjects($a_subobjects, $a_ref_id)
Filter the list of possible subobjects for the objects that actually could be created on a concrete n...
getProgressesOf($a_user_id)
Get the progresses the user has on this node.
getLastChange()
Get the timestamp of the last change on this program or sub program.
static createForObject(ilObject $a_object)
Create new study program settings for an object.
settings()
Definition: settings.php:2
static getInstancesForProgram($a_program_id)
Get all assignments that were made to the given program.
addMissingProgresses()
Add missing progress records for all assignments of this programm.
putInTree($a_parent_ref)
Overwritten from ilObject.
Class ilStudyProgrammeType.
getSubtypeId()
Gets the meta-data subtype id (allows to add additional meta-data based on a type) ...
canBeRemoved()
Check weather a node can be removed.
getDepth()
Get the depth of this StudyProgramme in the tree starting at the topmost StudyProgramme (not root nod...
getRawSettings()
Get the underlying model of this program.
global $ilDB
getChildren()
Get all ilObjStudyProgrammes that are direct children of this object.
getLPChildrenIds()
Get the ids of the leafs the program contains.
$ret
Definition: parser.php:6
getRefId()
get reference id public
static _writeContainerSetting($a_id, $a_keyword, $a_value)
static createFor(ilStudyProgramme $a_prg, $a_usr_id, $a_assigning_usr_id)
Create new assignment object for study program and user.
static createInstance()
Create an instance of ilObjStudyProgramme, put in cache.
removeAssignment(ilStudyProgrammeUserAssignment $a_assignment)
Remove an assignment from this program.
global $DIC
getPoints()
Get the amount of points.
static _getInstance($a_obj_id)
get instance by obj_id
static setProgressesCompletedFor($a_obj_id, $a_user_id)
Set all progresses to completed where the object with given id is a leaf and that belong to the user...
throwIfNotInTree()
Helper function to check, weather object is in tree.
deleteAssignments()
Delete all assignments from the DB.
createContainerDirectory()
Create directory for the container.
hasAssignmentOf($a_user_id)
Check whether user is assigned to this program or any node above.
static _lookupSourceIds($a_target_id)
Get ids of all container references that target the object with the given id.
__construct($a_id=0, $a_call_by_reference=true)
ATTENTION: After using the constructor the object won&#39;t be in the cache.
Exception is thrown when invariants on the program tree would be violated by manipulation of tree...
moveTo(ilObjStudyProgramme $a_new_parent)
Move this tree node to a new parent.
getIdsFromNodesOnPathFromRootToHere()
Get the ids from the nodes in the path leading from the root node of this program to this node...
static _lookupTargetId($a_obj_id)
lookup target id
getParents()
Get all parents of the node, where the root of the program comes first.
Represents one assignment of a user to a study programme.
static getInstancesForProgram($a_program_id)
Get the instances for a program node.
updateLastChange()
Update last change timestamp on this node and its parents.
clearParentCache()
Clear the cached parent to query it again at the tree.
readSettings()
Load Settings from DB.
createProgressForAssignment(ilStudyProgrammeAssignment $ass)
Create a progress on this programme for the given assignment.
getAssignments()
Get all assignments to this program or any node above.