ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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  $this->ilContainer($a_id, $a_call_by_reference);
44 
45  $this->clearParentCache();
46  $this->clearChildrenCache();
47  $this->clearLPChildrenCache();
48 
49  global $tree, $ilUser;
50  $this->tree = $tree;
51  $this->ilUser = $ilUser;
52 
53  $this->object_factory = ilObjectFactoryWrapper::singleton();
54  self::initStudyProgrammeCache();
55  }
56 
57  static public function initStudyProgrammeCache() {
58  if (self::$study_programme_cache === null) {
59  self::$study_programme_cache = ilObjStudyProgrammeCache::singleton();
60  }
61  }
62 
66  protected function clearParentCache() {
67  // This is not initialized, but we need null if there is no parent.
68  $this->parent = false;
69  }
70 
74  protected function clearChildrenCache() {
75  $this->children = null;
76  }
77 
81  protected function clearLPChildrenCache() {
82  $this->lp_children = null;
83  }
84 
85 
92  static public function getInstanceByRefId($a_ref_id) {
93  require_once("Modules/StudyProgramme/classes/class.ilObjStudyProgrammeCache.php");
94  if (self::$study_programme_cache === null) {
95  self::initStudyProgrammeCache();
96  }
97  return self::$study_programme_cache->getInstanceByRefId($a_ref_id);
98  }
99 
103  static public function createInstance() {
104  $obj = new ilObjStudyProgramme();
105  $obj->create();
106  $obj->createReference();
107  self::$study_programme_cache->addInstance($obj);
108  return $obj;
109  }
110 
111 
113  // CRUD
115 
120  protected function readSettings() {
121  if ($this->settings !== null) {
122  throw new ilException("ilObjStudyProgramme::loadSettings: already loaded.");
123  }
124  $id = $this->getId();
125  if (!$id) {
126  throw new ilException("ilObjStudyProgramme::loadSettings: no id.");
127  }
128  $this->settings = new ilStudyProgramme($this->getId());
129  }
130 
135  protected function createSettings() {
136  if ($this->settings !== null) {
137  throw new ilException("ilObjStudyProgramme::createSettings: already loaded.");
138  }
139 
140  $id = $this->getId();
141  if (!$id) {
142  throw new ilException("ilObjStudyProgramme::loadSettings: no id.");
143  }
144  $this->settings = ilStudyProgramme::createForObject($this);
145  }
146 
151  protected function updateSettings() {
152  if ($this->settings === null) {
153  throw new ilException("ilObjStudyProgramme::updateSettings: no settings loaded.");
154  }
155  $this->settings->update();
156  }
157 
162  protected function deleteSettings() {
163  if ($this->settings === null) {
164  throw new Exception("ilObjStudyProgramme::deleteSettings: no settings loaded.");
165  }
166  $this->settings->delete();
167  }
168 
172  protected function deleteAssignments() {
173  foreach ($this->getAssignments() as $ass) {
174  $ass->delete();
175  }
176  }
177 
178  public function read() {
179  parent::read();
180  $this->readSettings();
181  }
182 
183 
184  public function create() {
185  $id = parent::create();
186  $this->createSettings();
187 
188  return $id;
189  }
190 
191 
192  public function update() {
193  parent::update();
194 
195  // Update selection for advanced meta data of the type
196  if ($this->getSubType()) {
197  ilAdvancedMDRecord::saveObjRecSelection($this->getId(), 'prg_type', $this->getSubType()->getAssignedAdvancedMDRecordIds());
198  } else {
199  // If no type is assigned, delete relations by passing an empty array
200  ilAdvancedMDRecord::saveObjRecSelection($this->getId(), 'prg_type', array());
201  }
202 
203  $this->updateSettings();
204  }
205 
211  public function delete() {
212  // always call parent delete function first!!
213  if (!parent::delete()) {
214  return false;
215  }
216 
217  $this->deleteSettings();
218  try {
219  $this->deleteAssignments();
220  } catch(ilStudyProgrammeTreeException $e) {
221  // This would be the case when SP is in trash (#17797)
222  }
223 
224  return true;
225  }
226 
228  // GETTERS AND SETTERS
230 
236  public function getLastChange() {
237  return $this->settings->getLastChange();
238  }
239 
245  public function getPoints() {
246  return $this->settings->getPoints();
247  }
248 
256  public function setPoints($a_points) {
257  $this->settings->setPoints($a_points);
258  $this->updateLastChange();
259  return $this;
260  }
261 
267  public function getLPMode() {
268  return $this->settings->getLPMode();
269  }
270 
279  public function adjustLPMode() {
280  if ($this->getAmountOfLPChildren() > 0) {
281  $this->settings->setLPMode(ilStudyProgramme::MODE_LP_COMPLETED)
282  ->update();
283  }
284  else {
285  if ($this->getAmountOfChildren() > 0) {
286  $this->settings->setLPMode(ilStudyProgramme::MODE_POINTS)
287  ->update();
288  }
289  else {
290  $this->settings->setLPMode(ilStudyProgramme::MODE_UNDEFINED)
291  ->update();
292  }
293  }
294  }
295 
301  public function getStatus() {
302  return $this->settings->getStatus();
303  }
304 
311  public function setStatus($a_status) {
312  $this->settings->setStatus($a_status);
313  $this->updateLastChange();
314  return $this;
315  }
316 
322  public function isActive() {
323  return $this->getStatus() == ilStudyProgramme::STATUS_ACTIVE;
324  }
325 
331  public function getSubtypeId() {
332  return $this->settings->getSubtypeId();
333  }
334 
335 
343  public function setSubtypeId($a_subtype_id) {
344  $this->settings->setSubtypeId($a_subtype_id);
345  return $this;
346  }
347 
353  public function getSubType() {
354  if(!in_array($this->getSubtypeId(), array("-", "0"))) {
355  $subtype_id = $this->getSubtypeId();
356  return new ilStudyProgrammeType($subtype_id);
357  }
358 
359  return null;
360  }
361 
363  // TREE NAVIGATION
365 
375  static public function getAllChildren($a_ref_id) {
376  $ret = array();
377  $root = self::getInstanceByRefId($a_ref_id);
378  $root_id = $root->getId();
379  $root->applyToSubTreeNodes(function($prg) use (&$ret, $root_id) {
380  // exclude root node of subtree.
381  if ($prg->getId() == $root_id) {
382  return;
383  }
384  $ret[] = $prg;
385  });
386  return $ret;
387  }
388 
397  public function getChildren() {
398  $this->throwIfNotInTree();
399 
400  if ($this->children === null) {
401  $ref_ids = $this->tree->getChildsByType($this->getRefId(), "prg");
402 
403  // apply container sorting to tree
404  $sorting = ilContainerSorting::_getInstance($this->getId());
405  $ref_ids = $sorting->sortItems(array('prg'=>$ref_ids));
406  $ref_ids = $ref_ids['prg'];
407 
408  $this->children = array_map(function($node_data) {
409  return ilObjStudyProgramme::getInstanceByRefId($node_data["child"]);
410  }, $ref_ids);
411  }
412 
413  return $this->children;
414  }
415 
424  public function getParent() {
425  if ($this->parent === false) {
426  $this->throwIfNotInTree();
427  $parent_data = $this->tree->getParentNodeData($this->getRefId());
428  if ($parent_data["type"] != "prg") {
429  $this->parent = null;
430  }
431  else {
432  $this->parent = ilObjStudyProgramme::getInstanceByRefId($parent_data["ref_id"]);
433  }
434  }
435  return $this->parent;
436  }
437 
443  public function getParents() {
444  $current = $this;
445  $parents = array();
446  while(true) {
447  $current = $current->getParent();
448  if ($current === null) {
449  return array_reverse($parents);
450  }
451  $parents[] = $current;
452  }
453  }
454 
462  public function hasChildren() {
463  return $this->getAmountOfChildren() > 0;
464  }
465 
474  public function getAmountOfChildren() {
475  return count($this->getChildren());
476  }
477 
486  public function getDepth() {
487  $cur = $this;
488  $count = 0;
489  while ($cur = $cur->getParent()) {
490  $count++;
491  }
492  return $count;
493  }
494 
503  public function getRoot() {
504  $parents = $this->getParents();
505  return $parents[0];
506  }
507 
515  public function getLPChildren() {
516  $this->throwIfNotInTree();
517 
518  if ($this->lp_children === null) {
519  $this->lp_children = array();
520 
521  // TODO: find a better way to get all elements except StudyProgramme-children
522  $ref_ids = $this->tree->getChildsByType($this->getRefId(), "crsr");
523 
524  // apply container sorting to tree
525  $sorting = ilContainerSorting::_getInstance($this->getId());
526  $ref_ids = $sorting->sortItems(array('crs_ref'=>$ref_ids));
527  $ref_ids = $ref_ids['crs_ref'];
528 
529  // TODO: $this could be removed as soon as support for PHP 5.3 is dropped:
530  $self = $this;
531  $lp_children = array_map(function($node_data) use ($self) {
532  $lp_obj = $self->object_factory->getInstanceByRefId($node_data["child"]);
533 
534  // filter out all StudyProgramme instances
535  return ($lp_obj instanceof $self)? 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 
772  $this->settings->setLPMode(ilStudyProgramme::MODE_LP_COMPLETED);
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 $rbacadmin;
812 
813  if ($parent = $this->getParent()) {
814 
815  // TODO: check if there some leafs in the new parent
816 
817  $this->tree->moveTree($this->getRefId(), $a_new_parent->getRefId());
818  // necessary to clean up permissions
819  $rbacadmin->adjustMovedObjectPermissions($this->getRefId(), $parent->getRefId());
820 
821  // TODO: lp-progress needs to be updated
822 
823  // clear caches on different nodes
824  $this->clearParentCache();
825 
826  $parent->clearChildrenCache();
827  $parent->clearLPChildrenCache();
828 
829  $a_new_parent->clearChildrenCache();
830  $a_new_parent->clearLPChildrenCache();
831  }
832 
833  return $this;
834  }
835 
837  // USER ASSIGNMENTS
839 
853  public function assignUser($a_usr_id, $a_assigning_usr_id = null) {
854  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserAssignment.php");
855  require_once("./Modules/StudyProgramme/classes/model/class.ilStudyProgrammeAssignment.php");
856  require_once("./Modules/StudyProgramme/classes/model/class.ilStudyProgrammeProgress.php");
857  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeEvents.php");
858 
859  if ($this->settings === null) {
860  throw new ilException("ilObjStudyProgramme::assignUser: Program was not properly created.'");
861  }
862 
863  if ($this->getStatus() != ilStudyProgramme::STATUS_ACTIVE) {
864  throw new ilException("ilObjStudyProgramme::assignUser: Can't assign user to program '"
865  .$this->getId()."', since it's not in active status.");
866  }
867 
868  if ($a_assigning_usr_id === null) {
869  $a_assigning_usr_id = $this->ilUser->getId();
870  }
871 
872  $ass_mod = ilStudyProgrammeAssignment::createFor($this->settings, $a_usr_id, $a_assigning_usr_id);
873  $ass = new ilStudyProgrammeUserAssignment($ass_mod);
874 
875  $this->applyToSubTreeNodes(function(ilObjStudyProgramme $node) use ($ass_mod, $a_assigning_usr_id) {
876  $progress = $node->createProgressForAssignment($ass_mod);
877  if ($node->getStatus() != ilStudyProgramme::STATUS_ACTIVE) {
879  ->update();
880  }
881  });
882 
884 
885  return $ass;
886  }
887 
896  public function removeAssignment(ilStudyProgrammeUserAssignment $a_assignment) {
897  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeEvents.php");
898 
899  if ($a_assignment->getStudyProgramme()->getId() != $this->getId()) {
900  throw new ilException("ilObjStudyProgramme::removeAssignment: Assignment '"
901  .$a_assignment->getId()."' does not belong to study "
902  ."program '".$this->getId()."'.");
903  }
904 
906 
907  $a_assignment->delete();
908 
909  return $this;
910  }
911 
918  public function hasAssignmentOf($a_user_id) {
919  return $this->getAmountOfAssignmentsOf($a_user_id) > 0;
920  }
921 
929  public function getAmountOfAssignmentsOf($a_user_id) {
930  return count($this->getAssignmentsOf($a_user_id));
931  }
932 
941  public function getAssignmentsOf($a_user_id) {
942  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserAssignment.php");
943 
944  $prg_ids = $this->getIdsFromNodesOnPathFromRootToHere();
945  $assignments = ilStudyProgrammeAssignment::where(array( "usr_id" => $a_user_id
946  , "root_prg_id" => $prg_ids
947  ))
948  ->orderBy("last_change", "DESC")
949  ->get();
950  return array_map(function($ass) {
951  return new ilStudyProgrammeUserAssignment($ass);
952  }, array_values($assignments)); // use array values since we want keys 0...
953  }
954 
960  public function getAssignments() {
961  return array_map(function($ass) {
962  return new ilStudyProgrammeUserAssignment($ass);
963  }, array_values($this->getAssignmentsRaw())); // use array values since we want keys 0...
964  }
965 
971  public function hasAssignments() {
972  return count($this->getAssignments()) > 0;
973  }
974 
980  public function updateAllAssignments() {
982  foreach ($assignments as $ass) {
983  $ass->updateFromProgram();
984  }
985  return $this;
986  }
987 
989  // USER PROGRESS
991 
999  return ilStudyProgrammeProgress::createFor($this->settings, $ass);
1000  }
1001 
1008  public function getProgressesOf($a_user_id) {
1009  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
1010  return ilStudyProgrammeUserProgress::getInstancesForUser($this->getId(), $a_user_id);
1011  }
1012 
1022  public function getProgressForAssignment($a_assignment_id) {
1023  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
1024  return ilStudyProgrammeUserProgress::getInstanceForAssignment($this->getId(), $a_assignment_id);
1025  }
1026 
1034  public function addMissingProgresses() {
1035  foreach ($this->getAssignments() as $ass) {
1036  $ass->addMissingProgresses();
1037  }
1038  }
1039 
1045  public function getProgresses() {
1046  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
1048  }
1049 
1055  public function hasProgresses() {
1056  return count($this->getProgresses()) > 0;
1057  }
1058 
1064  public function hasRelevantProgresses() {
1065  foreach ($this->getProgresses() as $progress) {
1066  if ($progress->isRelevant()) {
1067  return true;
1068  }
1069  }
1070  return false;
1071  }
1072 
1079  $returns = array();
1080  foreach ($this->getProgresses() as $progress) {
1081  if ($progress->isRelevant()) {
1082  $returns[] = $progress->getUserId();
1083  }
1084  }
1085  return array_unique($returns);
1086  }
1087 
1094  $returns = array();
1095  foreach ($this->getProgresses() as $progress) {
1096  if ($progress->isSuccessful()) {
1097  $returns[] = $progress->getUserId();
1098  }
1099  }
1100  return array_unique($returns);
1101  }
1102 
1110  $returns = array();
1111  foreach ($this->getProgresses() as $progress) {
1112  if ($progress->isRelevant() && !$progress->isSuccessful()) {
1113  $returns[] = $progress->getUserId();
1114  }
1115  }
1116  return array_unique($returns);
1117  }
1118 
1120  // HELPERS
1122 
1126  protected function updateLastChange() {
1127  $this->settings->updateLastChange();
1128  if ($parent = $this->getParent()) {
1129  $parent->updateLastChange();
1130  }
1131  $this->update();
1132  }
1133 
1139  $prg_ids =array_map(function($par) {
1140  return $par->getId();
1141  }, $this->getParents());
1142  $prg_ids[] = $this->getId();
1143  return $prg_ids;
1144  }
1145 
1149  protected function getAssignmentsRaw() {
1150  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeUserAssignment.php");
1151  $prg_ids = $this->getIdsFromNodesOnPathFromRootToHere();
1152  return ilStudyProgrammeAssignment::where(array( "root_prg_id" => $prg_ids))
1153  ->orderBy("last_change", "DESC")
1154  ->get();
1155  }
1156 
1161  static public function setProgressesCompletedFor($a_obj_id, $a_user_id) {
1162  // We only use courses via crs_refs
1163  $type = ilObject::_lookupType($a_obj_id);
1164  if ($type == "crs") {
1165  require_once("Services/ContainerReference/classes/class.ilContainerReference.php");
1166  $crs_reference_obj_ids = ilContainerReference::_lookupSourceIds($a_obj_id);
1167  foreach ($crs_reference_obj_ids as $obj_id) {
1168  foreach(ilObject::_getAllReferences($obj_id) as $ref_id) {
1169  self::setProgressesCompletedIfParentIsProgrammeInLPCompletedMode($ref_id, $obj_id, $a_user_id);
1170  }
1171  }
1172  }
1173  else {
1174  foreach (ilObject::_getAllReferences($a_obj_id) as $ref_id) {
1175  self::setProgressesCompletedIfParentIsProgrammeInLPCompletedMode($ref_id, $a_obj_id, $a_user_id);
1176  }
1177  }
1178  }
1179 
1180  static protected function setProgressesCompletedIfParentIsProgrammeInLPCompletedMode($a_ref_id, $a_obj_id, $a_user_id) {
1181  global $tree; // TODO: replace this by a settable static for testing purpose?
1182  $node_data = $tree->getParentNodeData($a_ref_id);
1183  if ($node_data["type"] !== "prg") {
1184  return;
1185  }
1186  self::initStudyProgrammeCache();
1187  $prg = ilObjStudyProgramme::getInstanceByRefId($node_data["child"]);
1188  if ($prg->getLPMode() != ilStudyProgramme::MODE_LP_COMPLETED) {
1189  return;
1190  }
1191  foreach ($prg->getProgressesOf($a_user_id) as $progress) {
1192  $progress->setLPCompleted($a_obj_id, $a_user_id);
1193  }
1194  }
1195 
1202  static protected function getParentId(ilObject $a_object) {
1203  global $tree;
1204  if (!$tree->isInTree($a_object->getRefId())) {
1205  return null;
1206  }
1207 
1208  $nd = $tree->getParentNodeData($a_object->getRefId());
1209  return $nd["obj_id"];
1210  }
1211 
1219  public function getRawSettings() {
1220  return $this->settings;
1221  }
1222 
1227  public function updateCustomIcon() {
1228  $subtype = $this->getSubType();
1229 
1230  if($subtype) {
1231  if(is_file($subtype->getIconPath(true))) {
1232  $icon = $subtype->getIconPath(true);
1233  $this->saveIcons($icon);
1234  } else {
1235  $this->removeCustomIcon();
1236  }
1237  } else {
1238  $this->removeCustomIcon();
1239  }
1240  }
1241 
1243  // HOOKS
1245 
1256  static public function getCreatableSubObjects($a_subobjects, $a_ref_id) {
1257  if ($a_ref_id === null) {
1258  return $a_subobjects;
1259  }
1260 
1261  if (ilObject::_lookupType($a_ref_id, true) != "prg") {
1262  throw new ilException("Ref-Id '$a_ref_id' does not belong to a study programme object.");
1263  }
1264 
1266 
1267  $mode = $parent->getLPMode();
1268 
1269  switch ($mode) {
1271  return $a_subobjects;
1273  return array("prg" => $a_subobjects["prg"]);
1275  unset($a_subobjects["prg"]);
1276  return $a_subobjects;
1277  }
1278 
1279  throw new ilException("Undefined mode for study programme: '$mode'");
1280  }
1281 
1283  // REWRITES FROM PARENT
1285 
1289  function saveIcons($a_custom_icon)
1290  {
1291  global $ilDB;
1292 
1293  $this->createContainerDirectory();
1294  $cont_dir = $this->getContainerDirectory();
1295  $file_name = "";
1296  if ($a_custom_icon != "")
1297  {
1298  $file_name = $cont_dir."/icon_custom.svg";
1299 
1300  ilUtil::moveUploadedFile($a_custom_icon, "icon_custom.svg", $file_name, true, "copy");
1301 
1302  if ($file_name != "" && is_file($file_name))
1303  {
1304  ilContainer::_writeContainerSetting($this->getId(), "icon_custom", 1);
1305  }
1306  else
1307  {
1308  ilContainer::_writeContainerSetting($this->getId(), "icon_custom", 0);
1309  }
1310  }
1311  }
1312 }
1313 
1314 ?>
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.
_writeContainerSetting($a_id, $a_keyword, $a_value)
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 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.
static where($where, $operator=NULL)
delete()
Delete the assignment from database.
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
ilContainer($a_id=0, $a_call_by_reference=true)
Constructor public.
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.
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.
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.
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.