ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilContainerStartObjects.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13{
17 protected $tree;
18
22 protected $db;
23
27 protected $obj_data_cache;
28
32 protected $log;
33
34 protected $ref_id;
35 protected $obj_id;
36 protected $start_objs = array();
37
38 public function __construct($a_object_ref_id, $a_object_id)
39 {
40 global $DIC;
41
42 $this->tree = $DIC->repositoryTree();
43 $this->db = $DIC->database();
44 $this->obj_data_cache = $DIC["ilObjDataCache"];
45 $this->log = $DIC["ilLog"];
46 $this->setRefId($a_object_ref_id);
47 $this->setObjId($a_object_id);
48
49 $this->__read();
50 }
51
52 protected function setObjId($a_id)
53 {
54 $this->obj_id = $a_id;
55 }
56
57 public function getObjId()
58 {
59 return $this->obj_id;
60 }
61
62 protected function setRefId($a_ref_id)
63 {
64 $this->ref_id = $a_ref_id;
65 }
66
67 public function getRefId()
68 {
69 return $this->ref_id;
70 }
71
72 public function getStartObjects()
73 {
74 return $this->start_objs ? $this->start_objs : array();
75 }
76
77 protected function __read()
78 {
81
82 $this->start_objs = array();
83
84 $query = "SELECT * FROM crs_start" .
85 " WHERE crs_id = " . $ilDB->quote($this->getObjId(), 'integer') .
86 " ORDER BY pos, crs_start_id";
87 $res = $ilDB->query($query);
88 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
89 if ($tree->isInTree($row->item_ref_id)) {
90 $this->start_objs[$row->crs_start_id]['item_ref_id'] = $row->item_ref_id;
91 } else {
92 $this->delete($row->item_ref_id);
93 }
94 }
95 return true;
96 }
97
104 public function delete($a_crs_start_id)
105 {
107
108 $query = "DELETE FROM crs_start" .
109 " WHERE crs_start_id = " . $ilDB->quote($a_crs_start_id, 'integer') .
110 " AND crs_id = " . $ilDB->quote($this->getObjId(), 'integer');
111 $ilDB->manipulate($query);
112 return true;
113 }
114
119 public function deleteItem($a_item_ref_id)
120 {
122
123 $query = "DELETE FROM crs_start" .
124 " WHERE crs_id = " . $ilDB->quote($this->getObjId(), 'integer') .
125 " AND item_ref_id = " . $ilDB->quote($a_item_ref_id, 'integer');
126 $ilDB->manipulate($query);
127 return true;
128 }
129
130 public function exists($a_item_ref_id)
131 {
133
134 $query = "SELECT * FROM crs_start" .
135 " WHERE crs_id = " . $ilDB->quote($this->getObjId(), 'integer') .
136 " AND item_ref_id = " . $ilDB->quote($a_item_ref_id, 'integer');
137 $res = $ilDB->query($query);
138
139 return $res->numRows() ? true : false;
140 }
141
142 public function add($a_item_ref_id)
143 {
145
146 if ($a_item_ref_id) {
147 $max_pos = $ilDB->query("SELECT max(pos) pos FROM crs_start" .
148 " WHERE crs_id = " . $ilDB->quote($this->getObjId(), "integer"));
149 $max_pos = $ilDB->fetchAssoc($max_pos);
150 $max_pos = ((int) $max_pos["pos"])+10;
151
152 $next_id = $ilDB->nextId('crs_start');
153 $query = "INSERT INTO crs_start" .
154 " (crs_start_id,crs_id,item_ref_id,pos)" .
155 " VALUES" .
156 " (" . $ilDB->quote($next_id, 'integer') .
157 ", " . $ilDB->quote($this->getObjId(), 'integer') .
158 ", " . $ilDB->quote($a_item_ref_id, 'integer') .
159 ", " . $ilDB->quote($max_pos, 'integer') .
160 ")";
161 $ilDB->manipulate($query);
162 return true;
163 }
164 return false;
165 }
166
167 public function __deleteAll()
168 {
170
171 $query = "DELETE FROM crs_start" .
172 " WHERE crs_id = " . $ilDB->quote($this->getObjId(), 'integer');
173 $ilDB->manipulate($query);
174 return true;
175 }
176
177 public function setObjectPos($a_start_id, $a_pos)
178 {
180
181 if (!(int) $a_start_id || !(int) $a_pos) {
182 return;
183 }
184
185 $ilDB->manipulate("UPDATE crs_start" .
186 " SET pos = " . $ilDB->quote($a_pos, "integer") .
187 " WHERE crs_id = " . $ilDB->quote($this->getObjId(), 'integer') .
188 " AND crs_start_id = " . $ilDB->quote($a_start_id, 'integer'));
189 }
190
191 public function getPossibleStarters()
192 {
193 include_once "Services/Object/classes/class.ilObjectActivation.php";
194 foreach (ilObjectActivation::getItems($this->getRefId(), false) as $node) {
195 switch ($node['type']) {
196 case 'lm':
197 case 'sahs':
198 case 'svy':
199 case 'tst':
200 $poss_items[] = $node['ref_id'];
201 break;
202 }
203 }
204 return $poss_items ? $poss_items : array();
205 }
206
207 public function allFullfilled($a_user_id)
208 {
209 foreach ($this->getStartObjects() as $item) {
210 if (!$this->isFullfilled($a_user_id, $item['item_ref_id'])) {
211 return false;
212 }
213 }
214 return true;
215 }
216
217 public function isFullfilled($a_user_id, $a_item_id)
218 {
219 $ilObjDataCache = $this->obj_data_cache;
220
221 $obj_id = $ilObjDataCache->lookupObjId($a_item_id);
222 $type = $ilObjDataCache->lookupType($obj_id);
223
224 switch ($type) {
225 case 'tst':
226 include_once './Modules/Test/classes/class.ilObjTestAccess.php';
227 if (!ilObjTestAccess::checkCondition($obj_id, 'finished', '', $a_user_id)) { // #14000
228 return false;
229 }
230 break;
231
232 case 'svy':
233
234 include_once './Modules/Survey/classes/class.ilObjSurveyAccess.php';
236 return false;
237 }
238 break;
239
240 case 'sahs':
241 include_once 'Services/Tracking/classes/class.ilLPStatus.php';
242 if (!ilLPStatus::_hasUserCompleted($obj_id, $a_user_id)) {
243 return false;
244 }
245 break;
246
247 default:
248 include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
249 $lm_continue = new ilCourseLMHistory($this->getRefId(), $a_user_id);
250 $continue_data = $lm_continue->getLMHistory();
251 if (!isset($continue_data[$a_item_id])) {
252 return false;
253 }
254 break;
255 }
256
257 return true;
258 }
259
260 public function cloneDependencies($a_target_id, $a_copy_id)
261 {
262 $ilObjDataCache = $this->obj_data_cache;
264
265 $ilLog->write(__METHOD__ . ': Begin course start objects...');
266
267 $new_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
268 $start = new self($a_target_id, $new_obj_id);
269
270 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
271 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
272 $mappings = $cwo->getMappings();
273 foreach ($this->getStartObjects() as $data) {
274 $item_ref_id = $data['item_ref_id'];
275 if (isset($mappings[$item_ref_id]) and $mappings[$item_ref_id]) {
276 $ilLog->write(__METHOD__ . ': Clone start object nr. ' . $item_ref_id);
277 $start->add($mappings[$item_ref_id]);
278 } else {
279 $ilLog->write(__METHOD__ . ': No mapping found for start object nr. ' . $item_ref_id);
280 }
281 }
282 $ilLog->write(__METHOD__ . ': ... end course start objects');
283 return true;
284 }
285
293 public static function isStartObject($a_container_id, $a_item_ref_id)
294 {
295 global $DIC;
296
297 $ilDB = $DIC->database();
298
299 $query = 'SELECT crs_start_id FROM crs_start ' .
300 'WHERE crs_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
301 'AND item_ref_id = ' . $ilDB->quote($a_item_ref_id, 'integer');
302 $res = $ilDB->query($query);
303 if ($res->numRows() >= 1) {
304 return true;
305 }
306 return false;
307 }
308}
An exception for terminatinating execution or to throw for unit testing.
cloneDependencies($a_target_id, $a_copy_id)
deleteItem($a_item_ref_id)
Delete item by ref_id.
static isStartObject($a_container_id, $a_item_ref_id)
Check if object is start object @global type $ilDB.
__construct($a_object_ref_id, $a_object_id)
static _getInstance($a_copy_id)
Get instance of copy wizard options.
class ilCourseLMHistory
static _hasUserCompleted($a_obj_id, $a_user_id)
Lookup user object completion.
static _lookupFinished($a_obj_id, $a_user_id="")
get finished status
static checkCondition($a_obj_id, $a_operator, $a_value, $a_usr_id)
check condition
static getItems($a_parent_id, $a_with_list_data=true)
Get sub item data.
$query
$type
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB