ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilStudyProgrammeUserAssignment.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("./Modules/StudyProgramme/classes/model/class.ilStudyProgrammeAssignment.php");
6 
15  public $assignment; // ilStudyProgrammeAssignment
16 
23  public function __construct($a_id_or_model) {
24  if ($a_id_or_model instanceof ilStudyProgrammeAssignment) {
25  $this->assignment = $a_id_or_model;
26  }
27  else {
28  $this->assignment = ilStudyProgrammeAssignment::find($a_id_or_model);
29  }
30  if ($this->assignment === null) {
31  throw new ilException("ilStudyProgrammeUserAssignment::__construct: "
32  ."Unknown assignmemt id '$a_id_or_model'.");
33  }
34  }
35 
43  static public function getInstance($a_id) {
44  return new ilStudyProgrammeUserAssignment($a_id);
45  }
46 
53  static public function getInstancesOfUser($a_user_id) {
54  global $tree;
55 
56  $assignments = ilStudyProgrammeAssignment::where(array( "usr_id" => $a_user_id ))
57  ->get();
58 
59  //if parent object is deleted or in trash
60  //the assignment for the user should not be returned
61  $ret = array();
62  foreach($assignments as $ass) {
63  $ass_obj = new ilStudyProgrammeUserAssignment($ass);
64  foreach (ilObject::_getAllReferences($ass_obj->assignment->getRootId()) as $value) {
65  if($tree->isInTree($value)) {
66  $ret[] = $ass_obj;
67  break;
68  }
69  }
70  }
71 
72  return $ret;
73  }
74 
81  static public function getInstancesForProgram($a_program_id) {
82  $assignments = ilStudyProgrammeAssignment::where(array( "root_prg_id" => $a_program_id ))
83  ->get();
84  return array_map(function($ass) {
85  return new ilStudyProgrammeUserAssignment($ass);
86  }, array_values($assignments)); // use array values since we want keys 0...
87  }
88 
94  public function getId() {
95  return $this->assignment->getId();
96  }
97 
106  public function getStudyProgramme() {
107  require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
108  $refs = ilObject::_getAllReferences($this->assignment->getRootId());
109  if (!count($refs)) {
110  throw new ilException("ilStudyProgrammeUserAssignment::getStudyProgramme: "
111  ."could not find ref_id for program '"
112  .$this->assignment->getRootId()."'.");
113  }
114  return ilObjStudyProgramme::getInstanceByRefId(array_shift($refs));
115  }
116 
123  public function getRootProgress() {
124  return $this->getStudyProgramme()->getProgressForAssignment($this->getId());
125  }
126 
132  public function getUserId() {
133  return $this->assignment->getUserId();
134  }
135 
139  public function deassign() {
140  $this->getStudyProgramme()->removeAssignment($this);
141  }
142 
146  public function delete() {
147  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
149  foreach ($progresses as $progress) {
150  $progress->delete();
151  }
152 
153  $this->assignment->delete();
154  }
155 
162  public function updateFromProgram() {
163  $prg = $this->getStudyProgramme();
164  $id = $this->getId();
165 
166  $prg->applyToSubTreeNodes(function($node) use ($id) {
171  $progress = $node->getProgressForAssignment($id);
172  return $progress->updateFromProgramNode();
173  });
174 
175  return $this;
176  }
177 
185  public function addMissingProgresses() {
186  require_once("Modules/StudyProgramme/classes/exceptions/class.ilStudyProgrammeNoProgressForAssignmentException.php");
187 
188  $prg = $this->getStudyProgramme();
189  $id = $this->getId();
190 
191  // TODO: $this could be removed as soon as support for PHP 5.3 is dropped:
192  $self = $this;
193  // Make $this->assignment protected again afterwards.
194  $prg->applyToSubTreeNodes(function($node) use ($id, $self) {
195  try {
196  $node->getProgressForAssignment($id);
197  }
199  global $ilLog;
200  $ilLog->write("Adding progress for: ".$self->getId()." ".$node->getId());
201  require_once("Modules/StudyProgramme/classes/model/class.ilStudyProgrammeProgress.php");
202  $progress = ilStudyProgrammeProgress::createFor($node->getRawSettings(), $self->assignment);
204  ->update();
205  }
206  });
207 
208  return $this;
209  }
210 }
211 
212 ?>
__construct($a_id_or_model)
Throws when id does not refer to a study programme assignment.
Base class for ILIAS Exception handling.
static createFor(ilStudyProgramme $a_prg, ilStudyProgrammeAssignment $a_ass)
Create a new progress object for a given program node and assignment.
addMissingProgresses()
Add missing progresses for new nodes in the programm.
getStudyProgramme()
Get the program node where this assignment was made.
getRootProgress()
Get the progress on the root node of the programme.
Exception is thrown when a progress for some programme node and assignment is missing.
static _getAllReferences($a_id)
get all reference ids of object
static getInstanceByRefId($a_ref_id)
Get an instance of ilObjStudyProgramme, use cache.
static getInstancesForAssignment($a_assignment_id)
Get the instance for an assignment.
Class ilStudyProgrammeAssignment.
static where($where, $operator=NULL)
getUserId()
Get the id of the user who is assigned.
static getInstancesForProgram($a_program_id)
Get all assignments that were made to the given program.
static getInstancesOfUser($a_user_id)
Get all instances for a given user.
Represents one assignment of a user to a study programme.