ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilDB;
50
51 $this->db = $ilDB;
52
53 $this->ref_id = $a_course_ref_id;
54 $this->id = $a_course_obj_id;
55
56 $this->__read();
57 }
58 public function setId($a_id)
59 {
60 $this->id = $a_id;
61 }
62 public function getId()
63 {
64 return $this->id;
65 }
66 public function setRefId($a_ref_id)
67 {
68 $this->ref_id = $a_ref_id;
69 }
70 public function getRefId()
71 {
72 return $this->ref_id;
73 }
74 public function getStartObjects()
75 {
76 return $this->start_objs ? $this->start_objs : array();
77 }
78
87 public function cloneDependencies($a_target_id, $a_copy_id)
88 {
89 global $ilObjDataCache,$ilLog;
90
91 $ilLog->write(__METHOD__ . ': Begin course start objects...');
92
93 $new_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
94 $start = new ilCourseStart($a_target_id, $new_obj_id);
95
96 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
97 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
98 $mappings = $cwo->getMappings();
99 foreach ($this->getStartObjects() as $start_id => $data) {
100 $item_ref_id = $data['item_ref_id'];
101 if (isset($mappings[$item_ref_id]) and $mappings[$item_ref_id]) {
102 $ilLog->write(__METHOD__ . ': Clone start object nr. ' . $item_ref_id);
103 $start->add($mappings[$item_ref_id]);
104 } else {
105 $ilLog->write(__METHOD__ . ': No mapping found for start object nr. ' . $item_ref_id);
106 }
107 }
108 $ilLog->write(__METHOD__ . ': ... end course start objects');
109 return true;
110 }
111
112 public function delete($a_crs_start_id)
113 {
114 global $ilDB;
115
116 $query = "DELETE FROM crs_start " .
117 "WHERE crs_start_id = " . $ilDB->quote($a_crs_start_id, 'integer') . " " .
118 "AND crs_id = " . $ilDB->quote($this->getId(), 'integer') . " ";
119 $res = $ilDB->manipulate($query);
120 return true;
121 }
122
123 public function exists($a_item_ref_id)
124 {
125 global $ilDB;
126
127 $query = "SELECT * FROM crs_start " .
128 "WHERE crs_id = " . $ilDB->quote($this->getId(), 'integer') . " " .
129 "AND item_ref_id = " . $ilDB->quote($a_item_ref_id, 'integer') . " ";
130 $res = $this->db->query($query);
131
132 return $res->numRows() ? true : false;
133 }
134
135 public function add($a_item_ref_id)
136 {
137 global $ilDB;
138
139 if ($a_item_ref_id) {
140 $next_id = $ilDB->nextId('crs_start');
141 $query = "INSERT INTO crs_start (crs_start_id,crs_id,item_ref_id) " .
142 "VALUES( " .
143 $ilDB->quote($next_id, 'integer') . ", " .
144 $ilDB->quote($this->getId(), 'integer') . ", " .
145 $ilDB->quote($a_item_ref_id, 'integer') . " " .
146 ")";
147 $res = $ilDB->manipulate($query);
148 return true;
149 }
150 return false;
151 }
152
153 public function __deleteAll()
154 {
155 global $ilDB;
156
157 $query = "DELETE FROM crs_start " .
158 "WHERE crs_id = " . $ilDB->quote($this->getId(), 'integer') . " ";
159 $res = $ilDB->manipulate($query);
160
161 return true;
162 }
163
164 public function getPossibleStarters()
165 {
166 include_once "Services/Object/classes/class.ilObjectActivation.php";
167 foreach (ilObjectActivation::getItems($this->getRefId(), false) as $node) {
168 switch ($node['type']) {
169 case 'lm':
170 case 'sahs':
171 case 'svy':
172 case 'tst':
173 $poss_items[] = $node['ref_id'];
174 break;
175 }
176 }
177 return $poss_items ? $poss_items : array();
178 }
179
180 public function allFullfilled($user_id)
181 {
182 foreach ($this->getStartObjects() as $item) {
183 if (!$this->isFullfilled($user_id, $item['item_ref_id'])) {
184 return false;
185 }
186 }
187 return true;
188 }
189
190
191 public function isFullfilled($user_id, $item_id)
192 {
193 global $ilObjDataCache;
194
195 include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
196 $lm_continue = new ilCourseLMHistory($this->getRefId(), $user_id);
197 $continue_data = $lm_continue->getLMHistory();
198
199 $obj_id = $ilObjDataCache->lookupObjId($item_id);
200 $type = $ilObjDataCache->lookupType($obj_id);
201
202 switch ($type) {
203 case 'tst':
204 include_once './Modules/Test/classes/class.ilObjTestAccess.php';
205 include_once './Services/AccessControl/classes/class.ilConditionHandler.php';
206
208 return false;
209 }
210 break;
211 case 'svy':
212 include_once './Modules/Survey/classes/class.ilObjSurveyAccess.php';
213 if (!ilObjSurveyAccess::_lookupFinished($obj_id, $user_id)) {
214 return false;
215 }
216 break;
217 case 'sahs':
218 include_once 'Services/Tracking/classes/class.ilLPStatus.php';
219 if (!ilLPStatus::_hasUserCompleted($obj_id, $user_id)) {
220 return false;
221 }
222 break;
223
224 default:
225 if (!isset($continue_data[$item_id])) {
226 return false;
227 }
228 }
229 return true;
230 }
231
232
233 // PRIVATE
234 public function __read()
235 {
236 global $tree,$ilDB;
237
238 $this->start_objs = array();
239
240 $query = "SELECT * FROM crs_start " .
241 "WHERE crs_id = " . $ilDB->quote($this->getId(), 'integer') . " ";
242
243 $res = $this->db->query($query);
244 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
245 if ($tree->isInTree($row->item_ref_id)) {
246 $this->start_objs[$row->crs_start_id]['item_ref_id'] = $row->item_ref_id;
247 } else {
248 $this->delete($row->item_ref_id);
249 }
250 }
251 return true;
252 }
253} // END class.ilObjCourseGrouping
An exception for terminatinating execution or to throw for unit testing.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
class ilCourseLMHistory
Class ilObj<module_name>
setRefId($a_ref_id)
set reference id @access public
exists($a_item_ref_id)
add($a_item_ref_id)
getRefId()
get reference id @access public
__construct($a_course_ref_id, $a_course_obj_id)
Constructor @access public.
getId()
get object id @access public
isFullfilled($user_id, $item_id)
setId($a_id)
set object id @access public
cloneDependencies($a_target_id, $a_copy_id)
Clone dependencies.
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
foreach($_POST as $key=> $value) $res
global $ilDB