ILIAS  release_7 Revision v7.30-3-g800a261c036
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
103 public function delete($a_crs_start_id)
104 {
106
107 $query = "DELETE FROM crs_start" .
108 " WHERE crs_start_id = " . $ilDB->quote($a_crs_start_id, 'integer') .
109 " AND crs_id = " . $ilDB->quote($this->getObjId(), 'integer');
110 $ilDB->manipulate($query);
111 return true;
112 }
113
118 public function deleteItem($a_item_ref_id)
119 {
121
122 $query = "DELETE FROM crs_start" .
123 " WHERE crs_id = " . $ilDB->quote($this->getObjId(), 'integer') .
124 " AND item_ref_id = " . $ilDB->quote($a_item_ref_id, 'integer');
125 $ilDB->manipulate($query);
126 return true;
127 }
128
129 public function exists($a_item_ref_id)
130 {
132
133 $query = "SELECT * FROM crs_start" .
134 " WHERE crs_id = " . $ilDB->quote($this->getObjId(), 'integer') .
135 " AND item_ref_id = " . $ilDB->quote($a_item_ref_id, 'integer');
136 $res = $ilDB->query($query);
137
138 return $res->numRows() ? true : false;
139 }
140
141 public function add($a_item_ref_id)
142 {
144
145 if ($a_item_ref_id) {
146 $max_pos = $ilDB->query("SELECT max(pos) pos FROM crs_start" .
147 " WHERE crs_id = " . $ilDB->quote($this->getObjId(), "integer"));
148 $max_pos = $ilDB->fetchAssoc($max_pos);
149 $max_pos = ((int) $max_pos["pos"]) + 10;
150
151 $next_id = $ilDB->nextId('crs_start');
152 $query = "INSERT INTO crs_start" .
153 " (crs_start_id,crs_id,item_ref_id,pos)" .
154 " VALUES" .
155 " (" . $ilDB->quote($next_id, 'integer') .
156 ", " . $ilDB->quote($this->getObjId(), 'integer') .
157 ", " . $ilDB->quote($a_item_ref_id, 'integer') .
158 ", " . $ilDB->quote($max_pos, 'integer') .
159 ")";
160 $ilDB->manipulate($query);
161 return true;
162 }
163 return false;
164 }
165
166 public function __deleteAll()
167 {
169
170 $query = "DELETE FROM crs_start" .
171 " WHERE crs_id = " . $ilDB->quote($this->getObjId(), 'integer');
172 $ilDB->manipulate($query);
173 return true;
174 }
175
176 public function setObjectPos($a_start_id, $a_pos)
177 {
179
180 if (!(int) $a_start_id || !(int) $a_pos) {
181 return;
182 }
183
184 $ilDB->manipulate("UPDATE crs_start" .
185 " SET pos = " . $ilDB->quote($a_pos, "integer") .
186 " WHERE crs_id = " . $ilDB->quote($this->getObjId(), 'integer') .
187 " AND crs_start_id = " . $ilDB->quote($a_start_id, 'integer'));
188 }
189
190 public function getPossibleStarters()
191 {
192 include_once "Services/Object/classes/class.ilObjectActivation.php";
193 foreach (ilObjectActivation::getItems($this->getRefId(), false) as $node) {
194 switch ($node['type']) {
195 case 'lm':
196 case 'sahs':
197 case 'svy':
198 case 'copa':
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
235 return false;
236 }
237 break;
238
239 case 'sahs':
240 include_once 'Services/Tracking/classes/class.ilLPStatus.php';
241 if (!ilLPStatus::_hasUserCompleted($obj_id, $a_user_id)) {
242 return false;
243 }
244 break;
245
246 case 'copa':
247 if (!ilLPStatus::_hasUserCompleted($obj_id, $a_user_id)) {
248 return false;
249 }
250 break;
251
252 default:
253 include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
254 $lm_continue = new ilCourseLMHistory($this->getRefId(), $a_user_id);
255 $continue_data = $lm_continue->getLMHistory();
256 if (!isset($continue_data[$a_item_id])) {
257 return false;
258 }
259 break;
260 }
261
262 return true;
263 }
264
265 public function cloneDependencies($a_target_id, $a_copy_id)
266 {
267 $ilObjDataCache = $this->obj_data_cache;
268 $ilLog = $this->log;
269
270 $ilLog->write(__METHOD__ . ': Begin course start objects...');
271
272 $new_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
273 $start = new self($a_target_id, $new_obj_id);
274
275 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
276 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
277 $mappings = $cwo->getMappings();
278 foreach ($this->getStartObjects() as $data) {
279 $item_ref_id = $data['item_ref_id'];
280 if (isset($mappings[$item_ref_id]) and $mappings[$item_ref_id]) {
281 $ilLog->write(__METHOD__ . ': Clone start object nr. ' . $item_ref_id);
282 $start->add($mappings[$item_ref_id]);
283 } else {
284 $ilLog->write(__METHOD__ . ': No mapping found for start object nr. ' . $item_ref_id);
285 }
286 }
287 $ilLog->write(__METHOD__ . ': ... end course start objects');
288 return true;
289 }
290
297 public static function isStartObject($a_container_id, $a_item_ref_id)
298 {
299 global $DIC;
300
301 $ilDB = $DIC->database();
302
303 $query = 'SELECT crs_start_id FROM crs_start ' .
304 'WHERE crs_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
305 'AND item_ref_id = ' . $ilDB->quote($a_item_ref_id, 'integer');
306 $res = $ilDB->query($query);
307 if ($res->numRows() >= 1) {
308 return true;
309 }
310 return false;
311 }
312}
An exception for terminatinating execution or to throw for unit testing.
return true
Flag indicating whether or not HTTP headers will be sent when outputting captcha image/audio.
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.
__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.
global $DIC
Definition: goto.php:24
$query
$type
foreach($_POST as $key=> $value) $res
global $ilDB
$data
Definition: storeScorm.php:23