ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
5require_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 $DIC;
55 $tree = $DIC['tree'];
56
57 $assignments = ilStudyProgrammeAssignment::where(array( "usr_id" => $a_user_id ))
58 ->get();
59
60 //if parent object is deleted or in trash
61 //the assignment for the user should not be returned
62 $ret = array();
63 foreach($assignments as $ass) {
64 $ass_obj = new ilStudyProgrammeUserAssignment($ass);
65 foreach (ilObject::_getAllReferences($ass_obj->assignment->getRootId()) as $value) {
66 if($tree->isInTree($value)) {
67 $ret[] = $ass_obj;
68 break;
69 }
70 }
71 }
72
73 return $ret;
74 }
75
82 static public function getInstancesForProgram($a_program_id) {
83 $assignments = ilStudyProgrammeAssignment::where(array( "root_prg_id" => $a_program_id ))
84 ->get();
85 return array_map(function($ass) {
86 return new ilStudyProgrammeUserAssignment($ass);
87 }, array_values($assignments)); // use array values since we want keys 0...
88 }
89
95 public function getId() {
96 return $this->assignment->getId();
97 }
98
107 public function getStudyProgramme() {
108 require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
109 $refs = ilObject::_getAllReferences($this->assignment->getRootId());
110 if (!count($refs)) {
111 throw new ilException("ilStudyProgrammeUserAssignment::getStudyProgramme: "
112 ."could not find ref_id for program '"
113 .$this->assignment->getRootId()."'.");
114 }
115 return ilObjStudyProgramme::getInstanceByRefId(array_shift($refs));
116 }
117
124 public function getRootProgress() {
125 return $this->getStudyProgramme()->getProgressForAssignment($this->getId());
126 }
127
133 public function getUserId() {
134 return $this->assignment->getUserId();
135 }
136
140 public function deassign() {
141 $this->getStudyProgramme()->removeAssignment($this);
142 }
143
147 public function delete() {
148 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
150 foreach ($progresses as $progress) {
151 $progress->delete();
152 }
153
154 $this->assignment->delete();
155 }
156
163 public function updateFromProgram() {
164 $prg = $this->getStudyProgramme();
165 $id = $this->getId();
166
167 $prg->applyToSubTreeNodes(function($node) use ($id) {
172 $progress = $node->getProgressForAssignment($id);
173 return $progress->updateFromProgramNode();
174 });
175
176 return $this;
177 }
178
186 public function addMissingProgresses() {
187 require_once("Modules/StudyProgramme/classes/exceptions/class.ilStudyProgrammeNoProgressForAssignmentException.php");
188
189 $prg = $this->getStudyProgramme();
190 $id = $this->getId();
191
192 // Make $this->assignment protected again afterwards.
193 $prg->applyToSubTreeNodes(function($node) use ($id) {
194 try {
195 $node->getProgressForAssignment($id);
196 }
198 global $DIC;
199 $ilLog = $DIC['ilLog'];
200 $ilLog->write("Adding progress for: ".$this->getId()." ".$node->getId());
201 require_once("Modules/StudyProgramme/classes/model/class.ilStudyProgrammeProgress.php");
202 $progress = ilStudyProgrammeProgress::createFor($node->getRawSettings(), $this->assignment);
204 ->update();
205 }
206 });
207
208 return $this;
209 }
210}
211
212?>
static where($where, $operator=null)
An exception for terminatinating execution or to throw for unit testing.
Base class for ILIAS Exception handling.
static getInstanceByRefId($a_ref_id)
Get an instance of ilObjStudyProgramme, use cache.
static _getAllReferences($a_id)
get all reference ids of object
Class ilStudyProgrammeAssignment.
Exception is thrown when a progress for some programme node and assignment is missing.
static createFor(ilStudyProgramme $a_prg, ilStudyProgrammeAssignment $a_ass)
Create a new progress object for a given program node and assignment.
Represents one assignment of a user to a study programme.
getStudyProgramme()
Get the program node where this assignment was made.
getRootProgress()
Get the progress on the root node of the programme.
static getInstancesOfUser($a_user_id)
Get all instances for a given user.
__construct($a_id_or_model)
Throws when id does not refer to a study programme assignment.
addMissingProgresses()
Add missing progresses for new nodes in the programm.
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 getInstancesForAssignment($a_assignment_id)
Get the instance for an assignment.
$ret
Definition: parser.php:6
global $DIC