ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
16  public $assignment; // ilStudyProgrammeAssignment
17 
22 
30  {
31  if ($a_id_or_model instanceof ilStudyProgrammeAssignment) {
32  $this->assignment = $a_id_or_model;
33  } else {
34  $this->assignment = ilStudyProgrammeAssignment::find($a_id_or_model);
35  }
36  if ($this->assignment === null) {
37  throw new ilException("ilStudyProgrammeUserAssignment::__construct: "
38  . "Unknown assignmemt id '$a_id_or_model'.");
39  }
40  $this->sp_user_progress_db = $sp_user_progress_db;
41  }
42 
50  public static function getInstance($a_id)
51  {
53  }
54 
61  public static function getInstancesOfUser($a_user_id)
62  {
63  global $DIC;
64  $tree = $DIC['tree'];
65 
66  $assignments = ilStudyProgrammeAssignment::where(array( "usr_id" => $a_user_id ))
67  ->get();
68 
69  //if parent object is deleted or in trash
70  //the assignment for the user should not be returned
71  $ret = array();
72  foreach ($assignments as $ass) {
74  foreach (ilObject::_getAllReferences($ass_obj->assignment->getRootId()) as $value) {
75  if ($tree->isInTree($value)) {
76  $ret[] = $ass_obj;
77  break;
78  }
79  }
80  }
81 
82  return $ret;
83  }
84 
91  public static function getInstancesForProgram($a_program_id)
92  {
93  $assignments = ilStudyProgrammeAssignment::where(array( "root_prg_id" => $a_program_id ))
94  ->get();
95  return array_map(function ($ass) {
97  }, array_values($assignments)); // use array values since we want keys 0...
98  }
99 
105  public function getId()
106  {
107  return $this->assignment->getId();
108  }
109 
118  public function getStudyProgramme()
119  {
120  require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
121  $refs = ilObject::_getAllReferences($this->assignment->getRootId());
122  if (!count($refs)) {
123  throw new ilException("ilStudyProgrammeUserAssignment::getStudyProgramme: "
124  . "could not find ref_id for program '"
125  . $this->assignment->getRootId() . "'.");
126  }
127  return ilObjStudyProgramme::getInstanceByRefId(array_shift($refs));
128  }
129 
136  public function getRootProgress()
137  {
138  return $this->getStudyProgramme()->getProgressForAssignment($this->getId());
139  }
140 
146  public function getUserId()
147  {
148  return $this->assignment->getUserId();
149  }
150 
154  public function deassign()
155  {
156  $this->getStudyProgramme()->removeAssignment($this);
157  }
158 
162  public function delete()
163  {
164  $progresses = $this->sp_user_progress_db->getInstancesForAssignment($this->getId());
165  foreach ($progresses as $progress) {
166  $progress->delete();
167  }
168 
169  $this->assignment->delete();
170  }
171 
178  public function updateFromProgram()
179  {
180  $prg = $this->getStudyProgramme();
181  $id = $this->getId();
182 
183  $prg->applyToSubTreeNodes(function ($node) use ($id) {
188  $progress = $node->getProgressForAssignment($id);
189  return $progress->updateFromProgramNode();
190  });
191 
192  return $this;
193  }
194 
202  public function addMissingProgresses()
203  {
204  require_once("Modules/StudyProgramme/classes/exceptions/class.ilStudyProgrammeNoProgressForAssignmentException.php");
205 
206  $prg = $this->getStudyProgramme();
207  $id = $this->getId();
208 
209  // Make $this->assignment protected again afterwards.
210  $prg->applyToSubTreeNodes(function ($node) use ($id) {
211  try {
212  $node->getProgressForAssignment($id);
214  global $DIC;
215  $ilLog = $DIC['ilLog'];
216  $ilLog->write("Adding progress for: " . $this->getId() . " " . $node->getId());
217  require_once("Modules/StudyProgramme/classes/model/class.ilStudyProgrammeProgress.php");
218  $progress = ilStudyProgrammeProgress::createFor($node->getRawSettings(), $this->assignment);
220  ->update();
221  }
222  });
223 
224  return $this;
225  }
226 }
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.
global $DIC
Definition: saml.php:7
getStudyProgramme()
Get the program node where this assignment was made.
getRootProgress()
Get the progress on the root node of the programme.
if(!array_key_exists('StateId', $_REQUEST)) $id
Storage implementation for ilStudyProgrammeUserProgress.
Exception is thrown when a progress for some programme node and assignment is missing.
static where($where, $operator=null)
static _getAllReferences($a_id)
get all reference ids of object
static _getStudyProgrammeUserProgressDB()
Get an instance of ilStudyProgrammeUserProgressDB.
static getInstanceByRefId($a_ref_id)
Get an instance of ilObjStudyProgramme, use cache.
Class ilStudyProgrammeAssignment.
getUserId()
Get the id of the user who is assigned.
__construct($a_id_or_model, \ilStudyProgrammeUserProgressDB $sp_user_progress_db)
Throws when id does not refer to a study programme assignment.
Create styles array
The data for the language used.
static getInstancesForProgram($a_program_id)
Get all assignments that were made to the given program.
$ret
Definition: parser.php:6
static getInstancesOfUser($a_user_id)
Get all instances for a given user.
Represents one assignment of a user to a study programme.