ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCourseStart.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2005 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 {
35  public $db;
36 
37  public $ref_id;
38  public $id;
39  public $start_objs = array();
40 
47  public function __construct($a_course_ref_id, $a_course_obj_id)
48  {
49  global $DIC;
50 
51  $ilDB = $DIC['ilDB'];
52 
53  $this->db = $ilDB;
54 
55  $this->ref_id = $a_course_ref_id;
56  $this->id = $a_course_obj_id;
57 
58  $this->__read();
59  }
60  public function setId($a_id)
61  {
62  $this->id = $a_id;
63  }
64  public function getId()
65  {
66  return $this->id;
67  }
68  public function setRefId($a_ref_id)
69  {
70  $this->ref_id = $a_ref_id;
71  }
72  public function getRefId()
73  {
74  return $this->ref_id;
75  }
76  public function getStartObjects()
77  {
78  return $this->start_objs ? $this->start_objs : array();
79  }
80 
89  public function cloneDependencies($a_target_id, $a_copy_id)
90  {
91  global $DIC;
92 
93  $ilObjDataCache = $DIC['ilObjDataCache'];
94  $ilLog = $DIC['ilLog'];
95 
96  $ilLog->write(__METHOD__ . ': Begin course start objects...');
97 
98  $new_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
99  $start = new ilCourseStart($a_target_id, $new_obj_id);
100 
101  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
102  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
103  $mappings = $cwo->getMappings();
104  foreach ($this->getStartObjects() as $start_id => $data) {
105  $item_ref_id = $data['item_ref_id'];
106  if (isset($mappings[$item_ref_id]) and $mappings[$item_ref_id]) {
107  $ilLog->write(__METHOD__ . ': Clone start object nr. ' . $item_ref_id);
108  $start->add($mappings[$item_ref_id]);
109  } else {
110  $ilLog->write(__METHOD__ . ': No mapping found for start object nr. ' . $item_ref_id);
111  }
112  }
113  $ilLog->write(__METHOD__ . ': ... end course start objects');
114  return true;
115  }
116 
117  public function delete($a_crs_start_id)
118  {
119  global $DIC;
120 
121  $ilDB = $DIC['ilDB'];
122 
123  $query = "DELETE FROM crs_start " .
124  "WHERE crs_start_id = " . $ilDB->quote($a_crs_start_id, 'integer') . " " .
125  "AND crs_id = " . $ilDB->quote($this->getId(), 'integer') . " ";
126  $res = $ilDB->manipulate($query);
127  return true;
128  }
129 
130  public function exists($a_item_ref_id)
131  {
132  global $DIC;
133 
134  $ilDB = $DIC['ilDB'];
135 
136  $query = "SELECT * FROM crs_start " .
137  "WHERE crs_id = " . $ilDB->quote($this->getId(), 'integer') . " " .
138  "AND item_ref_id = " . $ilDB->quote($a_item_ref_id, 'integer') . " ";
139  $res = $this->db->query($query);
140 
141  return $res->numRows() ? true : false;
142  }
143 
144  public function add($a_item_ref_id)
145  {
146  global $DIC;
147 
148  $ilDB = $DIC['ilDB'];
149 
150  if ($a_item_ref_id) {
151  $next_id = $ilDB->nextId('crs_start');
152  $query = "INSERT INTO crs_start (crs_start_id,crs_id,item_ref_id) " .
153  "VALUES( " .
154  $ilDB->quote($next_id, 'integer') . ", " .
155  $ilDB->quote($this->getId(), 'integer') . ", " .
156  $ilDB->quote($a_item_ref_id, 'integer') . " " .
157  ")";
158  $res = $ilDB->manipulate($query);
159  return true;
160  }
161  return false;
162  }
163 
164  public function __deleteAll()
165  {
166  global $DIC;
167 
168  $ilDB = $DIC['ilDB'];
169 
170  $query = "DELETE FROM crs_start " .
171  "WHERE crs_id = " . $ilDB->quote($this->getId(), 'integer') . " ";
172  $res = $ilDB->manipulate($query);
173 
174  return true;
175  }
176 
177  public function getPossibleStarters()
178  {
179  include_once "Services/Object/classes/class.ilObjectActivation.php";
180  foreach (ilObjectActivation::getItems($this->getRefId(), false) as $node) {
181  switch ($node['type']) {
182  case 'lm':
183  case 'sahs':
184  case 'svy':
185  case 'tst':
186  $poss_items[] = $node['ref_id'];
187  break;
188  }
189  }
190  return $poss_items ? $poss_items : array();
191  }
192 
193  public function allFullfilled($user_id)
194  {
195  foreach ($this->getStartObjects() as $item) {
196  if (!$this->isFullfilled($user_id, $item['item_ref_id'])) {
197  return false;
198  }
199  }
200  return true;
201  }
202 
203 
204  public function isFullfilled($user_id, $item_id)
205  {
206  global $DIC;
207 
208  $ilObjDataCache = $DIC['ilObjDataCache'];
209 
210  include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
211  $lm_continue = new ilCourseLMHistory($this->getRefId(), $user_id);
212  $continue_data = $lm_continue->getLMHistory();
213 
214  $obj_id = $ilObjDataCache->lookupObjId($item_id);
215  $type = $ilObjDataCache->lookupType($obj_id);
216 
217  switch ($type) {
218  case 'tst':
219  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
220  include_once './Services/Conditions/classes/class.ilConditionHandler.php';
221 
223  return false;
224  }
225  break;
226  case 'svy':
227  include_once './Modules/Survey/classes/class.ilObjSurveyAccess.php';
228  if (!ilObjSurveyAccess::_lookupFinished($obj_id, $user_id)) {
229  return false;
230  }
231  break;
232  case 'sahs':
233  include_once 'Services/Tracking/classes/class.ilLPStatus.php';
234  if (!ilLPStatus::_hasUserCompleted($obj_id, $user_id)) {
235  return false;
236  }
237  break;
238 
239  default:
240  if (!isset($continue_data[$item_id])) {
241  return false;
242  }
243  }
244  return true;
245  }
246 
247 
248  // PRIVATE
249  public function __read()
250  {
251  global $DIC;
252 
253  $tree = $DIC['tree'];
254  $ilDB = $DIC['ilDB'];
255 
256  $this->start_objs = array();
257 
258  $query = "SELECT * FROM crs_start " .
259  "WHERE crs_id = " . $ilDB->quote($this->getId(), 'integer') . " ";
260 
261  $res = $this->db->query($query);
262  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
263  if ($tree->isInTree($row->item_ref_id)) {
264  $this->start_objs[$row->crs_start_id]['item_ref_id'] = $row->item_ref_id;
265  } else {
266  $this->delete($row->item_ref_id);
267  }
268  }
269  return true;
270  }
271 } // END class.ilObjCourseGrouping
exists($a_item_ref_id)
add($a_item_ref_id)
static getItems($a_parent_id, $a_with_list_data=true)
Get sub item data.
global $DIC
Definition: saml.php:7
Class ilObj<module_name>
$start
Definition: bench.php:8
isFullfilled($user_id, $item_id)
static _getInstance($a_copy_id)
Get instance of copy wizard options.
foreach($_POST as $key=> $value) $res
__construct($a_course_ref_id, $a_course_obj_id)
Constructor public.
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
global $ilDB
static checkCondition($a_obj_id, $a_operator, $a_value, $a_usr_id)
check condition
class ilCourseLMHistory
cloneDependencies($a_target_id, $a_copy_id)
Clone dependencies.
$data
Definition: bench.php:6