ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  {
80  $ilDB = $this->db;
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  {
105  $ilDB = $this->db;
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  {
120  $ilDB = $this->db;
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  {
131  $ilDB = $this->db;
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  {
143  $ilDB = $this->db;
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  {
168  $ilDB = $this->db;
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  {
178  $ilDB = $this->db;
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 'copa':
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';
235  if (!ilObjSurveyAccess::_lookupFinished($obj_id, $a_user_id)) {
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  case 'copa':
248  if (!ilLPStatus::_hasUserCompleted($obj_id, $a_user_id)) {
249  return false;
250  }
251  break;
252 
253  default:
254  include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
255  $lm_continue = new ilCourseLMHistory($this->getRefId(), $a_user_id);
256  $continue_data = $lm_continue->getLMHistory();
257  if (!isset($continue_data[$a_item_id])) {
258  return false;
259  }
260  break;
261  }
262 
263  return true;
264  }
265 
266  public function cloneDependencies($a_target_id, $a_copy_id)
267  {
268  $ilObjDataCache = $this->obj_data_cache;
269  $ilLog = $this->log;
270 
271  $ilLog->write(__METHOD__ . ': Begin course start objects...');
272 
273  $new_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
274  $start = new self($a_target_id, $new_obj_id);
275 
276  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
277  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
278  $mappings = $cwo->getMappings();
279  foreach ($this->getStartObjects() as $data) {
280  $item_ref_id = $data['item_ref_id'];
281  if (isset($mappings[$item_ref_id]) and $mappings[$item_ref_id]) {
282  $ilLog->write(__METHOD__ . ': Clone start object nr. ' . $item_ref_id);
283  $start->add($mappings[$item_ref_id]);
284  } else {
285  $ilLog->write(__METHOD__ . ': No mapping found for start object nr. ' . $item_ref_id);
286  }
287  }
288  $ilLog->write(__METHOD__ . ': ... end course start objects');
289  return true;
290  }
291 
298  public static function isStartObject($a_container_id, $a_item_ref_id)
299  {
300  global $DIC;
301 
302  $ilDB = $DIC->database();
303 
304  $query = 'SELECT crs_start_id FROM crs_start ' .
305  'WHERE crs_id = ' . $ilDB->quote($a_container_id, 'integer') . ' ' .
306  'AND item_ref_id = ' . $ilDB->quote($a_item_ref_id, 'integer');
307  $res = $ilDB->query($query);
308  if ($res->numRows() >= 1) {
309  return true;
310  }
311  return false;
312  }
313 }
static getItems($a_parent_id, $a_with_list_data=true)
Get sub item data.
$type
global $DIC
Definition: saml.php:7
deleteItem($a_item_ref_id)
Delete item by ref_id.
$start
Definition: bench.php:8
static _getInstance($a_copy_id)
Get instance of copy wizard options.
foreach($_POST as $key=> $value) $res
static _hasUserCompleted($a_obj_id, $a_user_id)
Lookup user object completion.
$query
static _lookupFinished($a_obj_id, $a_user_id="")
get finished status
$row
__construct($a_object_ref_id, $a_object_id)
global $ilDB
static checkCondition($a_obj_id, $a_operator, $a_value, $a_usr_id)
check condition
cloneDependencies($a_target_id, $a_copy_id)
class ilCourseLMHistory
static isStartObject($a_container_id, $a_item_ref_id)
Check if object is start object.
$data
Definition: bench.php:6