ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
14 protected $ref_id;
15 protected $obj_id;
16 protected $start_objs = array();
17
18 public function __construct($a_object_ref_id, $a_object_id)
19 {
20 $this->setRefId($a_object_ref_id);
21 $this->setObjId($a_object_id);
22
23 $this->__read();
24 }
25
26 protected function setObjId($a_id)
27 {
28 $this->obj_id = $a_id;
29 }
30
31 public function getObjId()
32 {
33 return $this->obj_id;
34 }
35
36 protected function setRefId($a_ref_id)
37 {
38 $this->ref_id = $a_ref_id;
39 }
40
41 public function getRefId()
42 {
43 return $this->ref_id;
44 }
45
46 public function getStartObjects()
47 {
48 return $this->start_objs ? $this->start_objs : array();
49 }
50
51 protected function __read()
52 {
53 global $tree, $ilDB;
54
55 $this->start_objs = array();
56
57 $query = "SELECT * FROM crs_start".
58 " WHERE crs_id = ".$ilDB->quote($this->getObjId(), 'integer').
59 " ORDER BY pos, crs_start_id";
60 $res = $ilDB->query($query);
61 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
62 {
63 if($tree->isInTree($row->item_ref_id))
64 {
65 $this->start_objs[$row->crs_start_id]['item_ref_id'] = $row->item_ref_id;
66 }
67 else
68 {
69 $this->delete($row->item_ref_id);
70 }
71 }
72 return true;
73 }
74
81 public function delete($a_crs_start_id)
82 {
83 global $ilDB;
84
85 $query = "DELETE FROM crs_start".
86 " WHERE crs_start_id = ".$ilDB->quote($a_crs_start_id, 'integer').
87 " AND crs_id = ".$ilDB->quote($this->getObjId(), 'integer');
88 $ilDB->manipulate($query);
89 return true;
90 }
91
96 public function deleteItem($a_item_ref_id)
97 {
98 global $ilDB;
99
100 $query = "DELETE FROM crs_start".
101 " WHERE crs_id = ".$ilDB->quote($this->getObjId(), 'integer').
102 " AND item_ref_id = ".$ilDB->quote($a_item_ref_id, 'integer');
103 $ilDB->manipulate($query);
104 return true;
105 }
106
107 public function exists($a_item_ref_id)
108 {
109 global $ilDB;
110
111 $query = "SELECT * FROM crs_start".
112 " WHERE crs_id = ".$ilDB->quote($this->getObjId(), 'integer').
113 " AND item_ref_id = ".$ilDB->quote($a_item_ref_id, 'integer');
114 $res = $ilDB->query($query);
115
116 return $res->numRows() ? true : false;
117 }
118
119 public function add($a_item_ref_id)
120 {
121 global $ilDB;
122
123 if($a_item_ref_id)
124 {
125 $max_pos = $ilDB->query("SELECT max(pos) pos FROM crs_start".
126 " WHERE crs_id = ".$ilDB->quote($this->getObjId(), "integer"));
127 $max_pos = $ilDB->fetchAssoc($max_pos);
128 $max_pos = ((int)$max_pos["pos"])+10;
129
130 $next_id = $ilDB->nextId('crs_start');
131 $query = "INSERT INTO crs_start".
132 " (crs_start_id,crs_id,item_ref_id,pos)".
133 " VALUES".
134 " (".$ilDB->quote($next_id, 'integer').
135 ", ".$ilDB->quote($this->getObjId(), 'integer').
136 ", ".$ilDB->quote($a_item_ref_id, 'integer').
137 ", ".$ilDB->quote($max_pos, 'integer').
138 ")";
139 $ilDB->manipulate($query);
140 return true;
141 }
142 return false;
143 }
144
145 public function __deleteAll()
146 {
147 global $ilDB;
148
149 $query = "DELETE FROM crs_start".
150 " WHERE crs_id = ".$ilDB->quote($this->getObjId(), 'integer');
151 $ilDB->manipulate($query);
152 return true;
153 }
154
155 public function setObjectPos($a_start_id, $a_pos)
156 {
157 global $ilDB;
158
159 if(!(int)$a_start_id || !(int)$a_pos)
160 {
161 return;
162 }
163
164 $ilDB->manipulate("UPDATE crs_start".
165 " SET pos = ".$ilDB->quote($a_pos, "integer").
166 " WHERE crs_id = ".$ilDB->quote($this->getObjId(), 'integer').
167 " AND crs_start_id = ".$ilDB->quote($a_start_id, 'integer'));
168 }
169
170 public function getPossibleStarters()
171 {
172 include_once "Services/Object/classes/class.ilObjectActivation.php";
173 foreach(ilObjectActivation::getItems($this->getRefId(), false) as $node)
174 {
175 switch($node['type'])
176 {
177 case 'lm':
178 case 'sahs':
179 case 'svy':
180 case 'tst':
181 $poss_items[] = $node['ref_id'];
182 break;
183 }
184 }
185 return $poss_items ? $poss_items : array();
186 }
187
188 public function allFullfilled($a_user_id)
189 {
190 foreach($this->getStartObjects() as $item)
191 {
192 if(!$this->isFullfilled($a_user_id, $item['item_ref_id']))
193 {
194 return false;
195 }
196 }
197 return true;
198 }
199
200 public function isFullfilled($a_user_id, $a_item_id)
201 {
202 global $ilObjDataCache;
203
204 $obj_id = $ilObjDataCache->lookupObjId($a_item_id);
205 $type = $ilObjDataCache->lookupType($obj_id);
206
207 switch($type)
208 {
209 case 'tst':
210 include_once './Modules/Test/classes/class.ilObjTestAccess.php';
211 if(!ilObjTestAccess::checkCondition($obj_id,'finished','',$a_user_id)) // #14000
212 {
213 return false;
214 }
215 break;
216
217 case 'svy':
218
219 include_once './Modules/Survey/classes/class.ilObjSurveyAccess.php';
221 {
222 return false;
223 }
224 break;
225
226 case 'sahs':
227 include_once 'Services/Tracking/classes/class.ilLPStatus.php';
228 if(!ilLPStatus::_hasUserCompleted($obj_id, $a_user_id))
229 {
230 return false;
231 }
232 break;
233
234 default:
235 include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
236 $lm_continue = new ilCourseLMHistory($this->getRefId(), $a_user_id);
237 $continue_data = $lm_continue->getLMHistory();
238 if(!isset($continue_data[$a_item_id]))
239 {
240 return false;
241 }
242 break;
243 }
244
245 return true;
246 }
247
248 public function cloneDependencies($a_target_id, $a_copy_id)
249 {
250 global $ilObjDataCache, $ilLog;
251
252 $ilLog->write(__METHOD__.': Begin course start objects...');
253
254 $new_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
255 $start = new self($a_target_id, $new_obj_id);
256
257 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
258 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
259 $mappings = $cwo->getMappings();
260 foreach($this->getStartObjects() as $data)
261 {
262 $item_ref_id = $data['item_ref_id'];
263 if(isset($mappings[$item_ref_id]) and $mappings[$item_ref_id])
264 {
265 $ilLog->write(__METHOD__.': Clone start object nr. '.$item_ref_id);
266 $start->add($mappings[$item_ref_id]);
267 }
268 else
269 {
270 $ilLog->write(__METHOD__.': No mapping found for start object nr. '.$item_ref_id);
271 }
272 }
273 $ilLog->write(__METHOD__.': ... end course start objects');
274 return true;
275 }
276
284 public static function isStartObject($a_container_id, $a_item_ref_id)
285 {
286 global $ilDB;
287
288 $query = 'SELECT crs_start_id FROM crs_start '.
289 'WHERE crs_id = '.$ilDB->quote($a_container_id,'integer').' '.
290 'AND item_ref_id = '.$ilDB->quote($a_item_ref_id,'integer');
291 $res = $ilDB->query($query);
292 if($res->numRows() >= 1)
293 {
294 return true;
295 }
296 return false;
297 }
298
299}
300
301?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
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.
_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.
$data
global $ilDB