ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
20  protected $settings; // ilStudyProgramme | null
21  protected $parent; // ilObjStudyProgramme | null | false
22  protected $children; // [ilObjStudyProgramme] | null
23  protected $lp_children; // [ilStudyProgrammeLeaf] | null;
24 
25  // GLOBALS from ILIAS
26  public $webdir;
27  public $tree;
28  public $ilUser;
29 
30  // Wrapped static ilObjectFactory of ILIAS.
32  // Cache for study programmes
33  public static $study_programme_cache = null;
34 
39 
47  public function __construct($a_id = 0, $a_call_by_reference = true)
48  {
49  $this->type = "prg";
50  $this->settings = null;
51  parent::__construct($a_id, $a_call_by_reference);
52 
53  $this->clearParentCache();
54  $this->clearChildrenCache();
55  $this->clearLPChildrenCache();
56 
57  global $DIC;
58  $tree = $DIC['tree'];
59  $ilUser = $DIC['ilUser'];
60  $this->webdir = $DIC->filesystem()->web();
61  $this->tree = $tree;
62  $this->ilUser = $ilUser;
63 
64  $this->object_factory = ilObjectFactoryWrapper::singleton();
65  self::initStudyProgrammeCache();
66  }
67 
68  public static function initStudyProgrammeCache()
69  {
70  if (self::$study_programme_cache === null) {
71  self::$study_programme_cache = ilObjStudyProgrammeCache::singleton();
72  }
73  }
74 
81  {
82  if (!$this->sp_user_progress_db) {
83  $this->sp_user_progress_db = static::_getStudyProgrammeUserProgressDB();
84  }
86  }
87 
93  public static function _getStudyProgrammeUserProgressDB()
94  {
95  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgressDB.php");
96  static $sp_user_progress_db = null;
97  if ($sp_user_progress_db === null) {
99  }
100  return $sp_user_progress_db;
101  }
102 
103 
107  protected function clearParentCache()
108  {
109  // This is not initialized, but we need null if there is no parent.
110  $this->parent = false;
111  }
112 
116  protected function clearChildrenCache()
117  {
118  $this->children = null;
119  }
120 
124  protected function clearLPChildrenCache()
125  {
126  $this->lp_children = null;
127  }
128 
129 
136  public static function getInstanceByRefId($a_ref_id)
137  {
138  require_once("Modules/StudyProgramme/classes/class.ilObjStudyProgrammeCache.php");
139  if (self::$study_programme_cache === null) {
140  self::initStudyProgrammeCache();
141  }
142  return self::$study_programme_cache->getInstanceByRefId($a_ref_id);
143  }
144 
148  public static function createInstance()
149  {
150  $obj = new ilObjStudyProgramme();
151  $obj->create();
152  $obj->createReference();
153  self::$study_programme_cache->addInstance($obj);
154  return $obj;
155  }
156 
157 
159  // CRUD
161 
166  protected function readSettings()
167  {
168  if ($this->settings !== null) {
169  throw new ilException("ilObjStudyProgramme::loadSettings: already loaded.");
170  }
171  $id = $this->getId();
172  if (!$id) {
173  throw new ilException("ilObjStudyProgramme::loadSettings: no id.");
174  }
175  $this->settings = new ilStudyProgramme($this->getId());
176  }
177 
182  protected function createSettings()
183  {
184  if ($this->settings !== null) {
185  throw new ilException("ilObjStudyProgramme::createSettings: already loaded.");
186  }
187 
188  $id = $this->getId();
189  if (!$id) {
190  throw new ilException("ilObjStudyProgramme::loadSettings: no id.");
191  }
193  }
194 
199  protected function updateSettings()
200  {
201  if ($this->settings === null) {
202  throw new ilException("ilObjStudyProgramme::updateSettings: no settings loaded.");
203  }
204  $this->settings->update();
205  }
206 
211  protected function deleteSettings()
212  {
213  if ($this->settings === null) {
214  throw new Exception("ilObjStudyProgramme::deleteSettings: no settings loaded.");
215  }
216  $this->settings->delete();
217  }
218 
222  protected function deleteAssignments()
223  {
224  foreach ($this->getAssignments() as $ass) {
225  $ass->delete();
226  }
227  }
228 
229  public function read()
230  {
231  parent::read();
232  $this->readSettings();
233  }
234 
235 
236  public function create()
237  {
238  $id = parent::create();
239  $this->createSettings();
240 
241  return $id;
242  }
243 
244 
245  public function update()
246  {
247  parent::update();
248 
249  // Update selection for advanced meta data of the type
250  if ($this->getSubType()) {
251  ilAdvancedMDRecord::saveObjRecSelection($this->getId(), 'prg_type', $this->getSubType()->getAssignedAdvancedMDRecordIds());
252  } else {
253  // If no type is assigned, delete relations by passing an empty array
254  ilAdvancedMDRecord::saveObjRecSelection($this->getId(), 'prg_type', array());
255  }
256 
257  $this->updateSettings();
258  }
259 
265  public function delete()
266  {
267  // always call parent delete function first!!
268  if (!parent::delete()) {
269  return false;
270  }
271 
272  $this->deleteSettings();
273  try {
274  $this->deleteAssignments();
275  } catch (ilStudyProgrammeTreeException $e) {
276  // This would be the case when SP is in trash (#17797)
277  }
278 
279  return true;
280  }
281 
283  // GETTERS AND SETTERS
285 
291  public function getLastChange()
292  {
293  return $this->settings->getLastChange();
294  }
295 
301  public function getPoints()
302  {
303  return $this->settings->getPoints();
304  }
305 
313  public function setPoints($a_points)
314  {
315  $this->settings->setPoints($a_points);
316  $this->updateLastChange();
317  return $this;
318  }
319 
325  public function getLPMode()
326  {
327  return $this->settings->getLPMode();
328  }
329 
338  public function adjustLPMode()
339  {
340  if ($this->getAmountOfLPChildren() > 0) {
342  ->update();
343  } else {
344  if ($this->getAmountOfChildren() > 0) {
345  $this->settings->setLPMode(ilStudyProgramme::MODE_POINTS)
346  ->update();
347  } else {
348  $this->settings->setLPMode(ilStudyProgramme::MODE_UNDEFINED)
349  ->update();
350  }
351  }
352  }
353 
359  public function getStatus()
360  {
361  return $this->settings->getStatus();
362  }
363 
370  public function setStatus($a_status)
371  {
372  $this->settings->setStatus($a_status);
373  $this->updateLastChange();
374  return $this;
375  }
376 
382  public function isActive()
383  {
384  return $this->getStatus() == ilStudyProgramme::STATUS_ACTIVE;
385  }
386 
392  public function getSubtypeId()
393  {
394  return $this->settings->getSubtypeId();
395  }
396 
397 
405  public function setSubtypeId($a_subtype_id)
406  {
407  $this->settings->setSubtypeId($a_subtype_id);
408  return $this;
409  }
410 
416  public function getSubType()
417  {
418  if (!in_array($this->getSubtypeId(), array("-", "0"))) {
419  $subtype_id = $this->getSubtypeId();
420  return new ilStudyProgrammeType($subtype_id);
421  }
422 
423  return null;
424  }
425 
427  // TREE NAVIGATION
429 
439  public static function getAllChildren($a_ref_id)
440  {
441  $ret = array();
442  $root = self::getInstanceByRefId($a_ref_id);
443  $root_id = $root->getId();
444  $root->applyToSubTreeNodes(function ($prg) use (&$ret, $root_id) {
445  // exclude root node of subtree.
446  if ($prg->getId() == $root_id) {
447  return;
448  }
449  $ret[] = $prg;
450  });
451  return $ret;
452  }
453 
462  public function getChildren()
463  {
464  $this->throwIfNotInTree();
465 
466  if ($this->children === null) {
467  $ref_ids = $this->tree->getChildsByType($this->getRefId(), "prg");
468 
469  // apply container sorting to tree
470  $sorting = ilContainerSorting::_getInstance($this->getId());
471  $ref_ids = $sorting->sortItems(array('prg' => $ref_ids));
472  $ref_ids = $ref_ids['prg'];
473 
474  $this->children = array_map(function ($node_data) {
475  return ilObjStudyProgramme::getInstanceByRefId($node_data["child"]);
476  }, $ref_ids);
477  }
478 
479  return $this->children;
480  }
481 
490  public function getParent()
491  {
492  if ($this->parent === false) {
493  $this->throwIfNotInTree();
494  $parent_data = $this->tree->getParentNodeData($this->getRefId());
495  if ($parent_data["type"] != "prg") {
496  $this->parent = null;
497  } else {
498  $this->parent = ilObjStudyProgramme::getInstanceByRefId($parent_data["ref_id"]);
499  }
500  }
501  return $this->parent;
502  }
503 
509  public function getParents()
510  {
511  $current = $this;
512  $parents = array();
513  while (true) {
514  $current = $current->getParent();
515  if ($current === null) {
516  return array_reverse($parents);
517  }
518  $parents[] = $current;
519  }
520  }
521 
529  public function hasChildren()
530  {
531  return $this->getAmountOfChildren() > 0;
532  }
533 
542  public function getAmountOfChildren()
543  {
544  return count($this->getChildren());
545  }
546 
555  public function getDepth()
556  {
557  $cur = $this;
558  $count = 0;
559  while ($cur = $cur->getParent()) {
560  $count++;
561  }
562  return $count;
563  }
564 
573  public function getRoot()
574  {
575  $parents = $this->getParents();
576  return $parents[0];
577  }
578 
586  public function getLPChildren()
587  {
588  $this->throwIfNotInTree();
589 
590  if ($this->lp_children === null) {
591  $this->lp_children = array();
592 
593  // TODO: find a better way to get all elements except StudyProgramme-children
594  $ref_ids = $this->tree->getChildsByType($this->getRefId(), "crsr");
595 
596  // apply container sorting to tree
597  $sorting = ilContainerSorting::_getInstance($this->getId());
598  $ref_ids = $sorting->sortItems(array('crs_ref' => $ref_ids));
599  $ref_ids = $ref_ids['crs_ref'];
600 
601  $lp_children = array_map(function ($node_data) {
602  $lp_obj = $this->object_factory->getInstanceByRefId($node_data["child"]);
603 
604  // filter out all StudyProgramme instances
605  return ($lp_obj instanceof $this)? null : $lp_obj;
606  }, $ref_ids);
607 
608  $this->lp_children = array_filter($lp_children);
609  }
610  return $this->lp_children;
611  }
612 
620  public function getLPChildrenIds()
621  {
622  return array_map(function ($child) {
623  return $child->getId();
624  }, $this->getLPChildren());
625  }
626 
632  public function getAmountOfLPChildren()
633  {
634  return count($this->getLPChildren());
635  }
636 
644  public function hasLPChildren()
645  {
646  return ($this->getAmountOfLPChildren() > 0);
647  }
648 
653  protected function throwIfNotInTree()
654  {
655  if (!$this->tree->isInTree($this->getRefId())) {
656  throw new ilStudyProgrammeTreeException("This program is not in tree.");
657  }
658  }
659 
661  // QUERIES ON SUBTREE
663 
674  public function applyToSubTreeNodes(Closure $fun)
675  {
676  $this->throwIfNotInTree();
677 
678  if ($fun($this) !== false) {
679  foreach ($this->getChildren() as $child) {
680  $child->applyToSubTreeNodes($fun);
681  }
682  }
683  }
684 
691  public function getCompletedCourses($a_user_id)
692  {
693  require_once("Services/ContainerReference/classes/class.ilContainerReference.php");
694  require_once("Services/Tracking/classes/class.ilLPStatus.php");
695 
696  $node_data = $this->tree->getNodeData($this->getRefId());
697  $crsrs = $this->tree->getSubTree($node_data, true, "crsr");
698 
699  $completed_crss = array();
700  foreach ($crsrs as $ref) {
701  $crs_id = ilContainerReference::_lookupTargetId($ref["obj_id"]);
702  if (ilLPStatus::_hasUserCompleted($crs_id, $a_user_id)) {
703  $completed_crss[] = array( "crs_id" => $crs_id
704  , "prg_ref_id" => $ref["parent"]
705  , "crsr_ref_id" => $ref["child"]
706  , "crsr_id" => $ref["obj_id"]
707  , "title" => ilContainerReference::_lookupTargetTitle($ref["obj_id"])
708  );
709  }
710  }
711 
712  return $completed_crss;
713  }
714 
716  // TREE MANIPULATION
718 
729  public function addNode(ilObjStudyProgramme $a_prg)
730  {
731  $this->throwIfNotInTree();
732 
734  throw new ilStudyProgrammeTreeException("Program already contains leafs.");
735  }
736 
737  if ($this->tree->isInTree($a_prg->getRefId())) {
738  throw new ilStudyProgrammeTreeException("Other program already is in tree.");
739  }
740 
741  if ($a_prg->getRefId() === null) {
742  $a_prg->createReference();
743  }
744  $a_prg->putInTree($this->getRefId());
745  return $this;
746  }
747 
751  protected function nodeInserted(ilObjStudyProgramme $a_prg)
752  {
754  throw new ilStudyProgrammeTreeException("Program already contains leafs.");
755  }
756 
757  if ($this->settings->getLPMode() !== ilStudyProgramme::MODE_POINTS) {
758  $this->settings->setLPMode(ilStudyProgramme::MODE_POINTS)
759  ->update();
760  }
761 
762  $this->clearChildrenCache();
763  $this->addMissingProgresses();
764  }
765 
771  public function putInTree($a_parent_ref)
772  {
773  $res = parent::putInTree($a_parent_ref);
774 
775  if (ilObject::_lookupType($a_parent_ref, true) == "prg") {
776  $par = ilObjStudyProgramme::getInstanceByRefId($a_parent_ref);
777  $par->nodeInserted($this);
778  }
779 
780  return $res;
781  }
782 
793  public function removeNode(ilObjStudyProgramme $a_prg)
794  {
795  if ($a_prg->getParent()->getId() !== $this->getId()) {
796  throw new ilStudyProgrammeTreeException("This is no parent of the given programm.");
797  }
798 
799  if (!$a_prg->canBeRemoved()) {
800  throw new ilStudyProgrammeTreeException("The node has relevant assignments.");
801  }
802 
803  // *sigh*...
804  $node_data = $this->tree->getNodeData($a_prg->getRefId());
805  $this->tree->deleteTree($node_data);
806  $a_prg->clearParentCache();
807  $this->clearChildrenCache();
808 
809  return $this;
810  }
811 
818  public function canBeRemoved()
819  {
820  foreach ($this->getProgresses() as $progress) {
821  if ($progress->getStatus() != ilStudyProgrammeProgress::STATUS_NOT_RELEVANT) {
822  return false;
823  }
824  if ($progress->getLastChangeBy() !== null) {
825  return false;
826  }
827  }
828  return true;
829  }
830 
840  public function addLeaf(/*ilStudyProgrammeLeaf*/ $a_leaf)
841  {
842  $this->throwIfNotInTree();
843 
844  if ($this->hasChildren()) {
845  throw new ilStudyProgrammeTreeException("Program already contains other programm nodes.");
846  }
847 
848  if ($a_leaf->getRefId() === null) {
849  $a_leaf->createReference();
850  }
851  $a_leaf->putInTree($this->getRefId());
852  $this->clearLPChildrenCache();
853 
855  $this->update();
856 
857  return $this;
858  }
859 
870  public function removeLeaf(/*ilStudyProgrammeLeaf*/ $a_leaf)
871  {
872  if (self::getParentId($a_leaf) !== $this->getId()) {
873  throw new ilStudyProgrammeTreeException("This is no parent of the given leaf node.");
874  }
875 
876  $node_data = $this->tree->getNodeData($a_leaf->getRefId());
877  $this->tree->deleteTree($node_data);
878  $this->clearLPChildrenCache();
879 
880  return $this;
881  }
882 
893  public function moveTo(ilObjStudyProgramme $a_new_parent)
894  {
895  global $DIC;
896  $rbacadmin = $DIC['rbacadmin'];
897 
898  if ($parent = $this->getParent()) {
899 
900  // TODO: check if there some leafs in the new parent
901 
902  $this->tree->moveTree($this->getRefId(), $a_new_parent->getRefId());
903  // necessary to clean up permissions
904  $rbacadmin->adjustMovedObjectPermissions($this->getRefId(), $parent->getRefId());
905 
906  // TODO: lp-progress needs to be updated
907 
908  // clear caches on different nodes
909  $this->clearParentCache();
910 
911  $parent->clearChildrenCache();
912  $parent->clearLPChildrenCache();
913 
914  $a_new_parent->clearChildrenCache();
915  $a_new_parent->clearLPChildrenCache();
916  }
917 
918  return $this;
919  }
920 
922  // USER ASSIGNMENTS
924 
938  public function assignUser($a_usr_id, $a_assigning_usr_id = null)
939  {
940  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserAssignment.php");
941  require_once("./Modules/StudyProgramme/classes/model/class.ilStudyProgrammeAssignment.php");
942  require_once("./Modules/StudyProgramme/classes/model/class.ilStudyProgrammeProgress.php");
943  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeEvents.php");
944 
945  if ($this->settings === null) {
946  throw new ilException("ilObjStudyProgramme::assignUser: Program was not properly created.'");
947  }
948 
949  if ($this->getStatus() != ilStudyProgramme::STATUS_ACTIVE) {
950  throw new ilException("ilObjStudyProgramme::assignUser: Can't assign user to program '"
951  . $this->getId() . "', since it's not in active status.");
952  }
953 
954  if ($a_assigning_usr_id === null) {
955  $a_assigning_usr_id = $this->ilUser->getId();
956  }
957 
958  $ass_mod = ilStudyProgrammeAssignment::createFor($this->settings, $a_usr_id, $a_assigning_usr_id);
960 
961  $this->applyToSubTreeNodes(function (ilObjStudyProgramme $node) use ($ass_mod, $a_assigning_usr_id) {
962  $progress = $node->createProgressForAssignment($ass_mod);
963  if ($node->getStatus() != ilStudyProgramme::STATUS_ACTIVE) {
965  ->update();
966  }
967  });
968 
970 
971  return $ass;
972  }
973 
982  public function removeAssignment(ilStudyProgrammeUserAssignment $a_assignment)
983  {
984  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeEvents.php");
985 
986  if ($a_assignment->getStudyProgramme()->getId() != $this->getId()) {
987  throw new ilException("ilObjStudyProgramme::removeAssignment: Assignment '"
988  . $a_assignment->getId() . "' does not belong to study "
989  . "program '" . $this->getId() . "'.");
990  }
991 
993 
994  $a_assignment->delete();
995 
996  return $this;
997  }
998 
1005  public function hasAssignmentOf($a_user_id)
1006  {
1007  return $this->getAmountOfAssignmentsOf($a_user_id) > 0;
1008  }
1009 
1017  public function getAmountOfAssignmentsOf($a_user_id)
1018  {
1019  return count($this->getAssignmentsOf($a_user_id));
1020  }
1021 
1030  public function getAssignmentsOf($a_user_id)
1031  {
1032  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserAssignment.php");
1033 
1034  $prg_ids = $this->getIdsFromNodesOnPathFromRootToHere();
1035  $assignments = ilStudyProgrammeAssignment::where(array( "usr_id" => $a_user_id
1036  , "root_prg_id" => $prg_ids
1037  ))
1038  ->orderBy("last_change", "DESC")
1039  ->get();
1040  return array_map(function ($ass) {
1042  }, array_values($assignments)); // use array values since we want keys 0...
1043  }
1044 
1050  public function getAssignments()
1051  {
1052  return array_map(function ($ass) {
1054  }, array_values($this->getAssignmentsRaw())); // use array values since we want keys 0...
1055  }
1056 
1062  public function hasAssignments()
1063  {
1064  return count($this->getAssignments()) > 0;
1065  }
1066 
1072  public function updateAllAssignments()
1073  {
1075  foreach ($assignments as $ass) {
1076  $ass->updateFromProgram();
1077  }
1078  return $this;
1079  }
1080 
1082  // USER PROGRESS
1084 
1092  {
1093  return ilStudyProgrammeProgress::createFor($this->settings, $ass);
1094  }
1095 
1102  public function getProgressesOf($a_user_id)
1103  {
1104  return $this->getStudyProgrammeUserProgressDB()->getInstancesForUser($this->getId(), $a_user_id);
1105  }
1106 
1116  public function getProgressForAssignment($a_assignment_id)
1117  {
1118  return $this->getStudyProgrammeUserProgressDB()->getInstanceForAssignment($this->getId(), $a_assignment_id);
1119  }
1120 
1128  public function addMissingProgresses()
1129  {
1130  foreach ($this->getAssignments() as $ass) {
1131  $ass->addMissingProgresses();
1132  }
1133  }
1134 
1140  public function getProgresses()
1141  {
1142  return $this->getStudyProgrammeUserProgressDB()->getInstancesForProgram($this->getId());
1143  }
1144 
1150  public function hasProgresses()
1151  {
1152  return count($this->getProgresses()) > 0;
1153  }
1154 
1160  public function hasRelevantProgresses()
1161  {
1162  foreach ($this->getProgresses() as $progress) {
1163  if ($progress->isRelevant()) {
1164  return true;
1165  }
1166  }
1167  return false;
1168  }
1169 
1176  {
1177  $returns = array();
1178  foreach ($this->getProgresses() as $progress) {
1179  if ($progress->isRelevant()) {
1180  $returns[] = $progress->getUserId();
1181  }
1182  }
1183  return array_unique($returns);
1184  }
1185 
1192  {
1193  $returns = array();
1194  foreach ($this->getProgresses() as $progress) {
1195  if ($progress->isSuccessful()) {
1196  $returns[] = $progress->getUserId();
1197  }
1198  }
1199  return array_unique($returns);
1200  }
1201 
1208  {
1209  $returns = array();
1210  foreach ($this->getProgresses() as $progress) {
1211  $progress->recalculateFailedToDeadline();
1212  if ($progress->isFailed()) {
1213  $returns[] = $progress->getUserId();
1214  }
1215  }
1216  return array_unique($returns);
1217  }
1218 
1226  {
1227  $returns = array();
1228  foreach ($this->getProgresses() as $progress) {
1229  if ($progress->isRelevant() && !$progress->isSuccessful()) {
1230  $returns[] = $progress->getUserId();
1231  }
1232  }
1233  return array_unique($returns);
1234  }
1235 
1237  // HELPERS
1239 
1243  protected function updateLastChange()
1244  {
1245  $this->settings->updateLastChange();
1246  if ($parent = $this->getParent()) {
1247  $parent->updateLastChange();
1248  }
1249  $this->update();
1250  }
1251 
1257  {
1258  $prg_ids = array_map(function ($par) {
1259  return $par->getId();
1260  }, $this->getParents());
1261  $prg_ids[] = $this->getId();
1262  return $prg_ids;
1263  }
1264 
1268  protected function getAssignmentsRaw()
1269  {
1270  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserAssignment.php");
1271  $prg_ids = $this->getIdsFromNodesOnPathFromRootToHere();
1272  return ilStudyProgrammeAssignment::where(array( "root_prg_id" => $prg_ids))
1273  ->orderBy("last_change", "DESC")
1274  ->get();
1275  }
1276 
1281  public static function setProgressesCompletedFor($a_obj_id, $a_user_id)
1282  {
1283  // We only use courses via crs_refs
1284  $type = ilObject::_lookupType($a_obj_id);
1285  if ($type == "crs") {
1286  require_once("Services/ContainerReference/classes/class.ilContainerReference.php");
1287  $crs_reference_obj_ids = ilContainerReference::_lookupSourceIds($a_obj_id);
1288  foreach ($crs_reference_obj_ids as $obj_id) {
1289  foreach (ilObject::_getAllReferences($obj_id) as $ref_id) {
1290  self::setProgressesCompletedIfParentIsProgrammeInLPCompletedMode($ref_id, $obj_id, $a_user_id);
1291  }
1292  }
1293  } else {
1294  foreach (ilObject::_getAllReferences($a_obj_id) as $ref_id) {
1295  self::setProgressesCompletedIfParentIsProgrammeInLPCompletedMode($ref_id, $a_obj_id, $a_user_id);
1296  }
1297  }
1298  }
1299 
1300  protected static function setProgressesCompletedIfParentIsProgrammeInLPCompletedMode($a_ref_id, $a_obj_id, $a_user_id)
1301  {
1302  global $DIC; // TODO: replace this by a settable static for testing purpose?
1303  $tree = $DIC['tree'];
1304  $node_data = $tree->getParentNodeData($a_ref_id);
1305  if ($node_data["type"] !== "prg") {
1306  return;
1307  }
1308  self::initStudyProgrammeCache();
1309  $prg = ilObjStudyProgramme::getInstanceByRefId($node_data["child"]);
1310  if ($prg->getLPMode() != ilStudyProgramme::MODE_LP_COMPLETED) {
1311  return;
1312  }
1313  foreach ($prg->getProgressesOf($a_user_id) as $progress) {
1314  $progress->setLPCompleted($a_obj_id, $a_user_id);
1315  }
1316  }
1317 
1324  protected static function getParentId(ilObject $a_object)
1325  {
1326  global $DIC;
1327  $tree = $DIC['tree'];
1328  if (!$tree->isInTree($a_object->getRefId())) {
1329  return null;
1330  }
1331 
1332  $nd = $tree->getParentNodeData($a_object->getRefId());
1333  return $nd["obj_id"];
1334  }
1335 
1343  public function getRawSettings()
1344  {
1345  return $this->settings;
1346  }
1347 
1352  public function updateCustomIcon()
1353  {
1354  global $DIC;
1355 
1357  $customIconFactory = $DIC['object.customicons.factory'];
1358  $customIcon = $customIconFactory->getByObjId($this->getId(), $this->getType());
1359 
1360  $subtype = $this->getSubType();
1361 
1362  if ($subtype) {
1363  if ($this->webdir->has($subtype->getIconPath(true))) {
1364  $icon = $subtype->getIconPath(true);
1365  $customIcon->saveFromSourceFile($icon);
1366  } else {
1367  $customIcon->remove();
1368  }
1369  } else {
1370  $customIcon->remove();
1371  }
1372  }
1373 
1375  // HOOKS
1377 
1388  public static function getCreatableSubObjects($a_subobjects, $a_ref_id)
1389  {
1390  if ($a_ref_id === null) {
1391  return $a_subobjects;
1392  }
1393 
1394  if (ilObject::_lookupType($a_ref_id, true) != "prg") {
1395  throw new ilException("Ref-Id '$a_ref_id' does not belong to a study programme object.");
1396  }
1397 
1399 
1400  $mode = $parent->getLPMode();
1401 
1402  switch ($mode) {
1404  return $a_subobjects;
1406  return array("prg" => $a_subobjects["prg"]);
1408  unset($a_subobjects["prg"]);
1409  return $a_subobjects;
1410  }
1411 
1412  throw new ilException("Undefined mode for study programme: '$mode'");
1413  }
1414 }
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.
settings()
Definition: settings.php:2
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.
getIdsOfUsersWithCompletedProgress()
Get the ids of all users that have completed this programme.
global $DIC
Definition: saml.php:7
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.
setSubtypeId($a_subtype_id)
Sets the meta-data subtype id.
getLPChildren()
Get the leafs the study programme contains.
getStudyProgramme()
Get the program node where this assignment was made.
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)
Storage implementation for ilStudyProgrammeUserProgress.
getStudyProgrammeUserProgressDB()
Get a (cached) instance of ilStudyProgrammeUserProgressDB.
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.
getIdsOfUsersWithFailedProgress()
Get the ids of all users that have failed this programme.
static where($where, $operator=null)
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.
static _getStudyProgrammeUserProgressDB()
Get an instance of ilStudyProgrammeUserProgressDB.
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:10
foreach($_POST as $key=> $value) $res
clearChildrenCache()
Clear the cached children.
getId()
get object id public
hasRelevantProgresses()
Are there any users that have a relevant progress on this programme?
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.
$root
Definition: sabredav.php:45
getType()
get object type public
static setProgressesCompletedIfParentIsProgrammeInLPCompletedMode($a_ref_id, $a_obj_id, $a_user_id)
static userDeassigned(ilStudyProgrammeUserAssignment $a_assignment)
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...
update($pash, $contents, Config $config)
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.
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.
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 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.
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.
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.
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.