ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 var $db;
36
38 var $id;
39 var $start_objs = array();
40
47 function ilCourseStart($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 function setId($a_id)
59 {
60 $this->id = $a_id;
61 }
62 function getId()
63 {
64 return $this->id;
65 }
66 function setRefId($a_ref_id)
67 {
68 $this->ref_id = $a_ref_id;
69 }
70 function getRefId()
71 {
72 return $this->ref_id;
73 }
74 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 {
101 $item_ref_id = $data['item_ref_id'];
102 if(isset($mappings[$item_ref_id]) and $mappings[$item_ref_id])
103 {
104 $ilLog->write(__METHOD__.': Clone start object nr. '.$item_ref_id);
105 $start->add($mappings[$item_ref_id]);
106 }
107 else
108 {
109 $ilLog->write(__METHOD__.': No mapping found for start object nr. '.$item_ref_id);
110 }
111 }
112 $ilLog->write(__METHOD__.': ... end course start objects');
113 return true;
114 }
115
116 function delete($a_crs_start_id)
117 {
118 global $ilDB;
119
120 $query = "DELETE FROM crs_start ".
121 "WHERE crs_start_id = ".$ilDB->quote($a_crs_start_id ,'integer')." ".
122 "AND crs_id = ".$ilDB->quote($this->getId(),'integer')." ";
123 $res = $ilDB->manipulate($query);
124 return true;
125 }
126
127 function exists($a_item_ref_id)
128 {
129 global $ilDB;
130
131 $query = "SELECT * FROM crs_start ".
132 "WHERE crs_id = ".$ilDB->quote($this->getId() ,'integer')." ".
133 "AND item_ref_id = ".$ilDB->quote($a_item_ref_id ,'integer')." ";
134 $res = $this->db->query($query);
135
136 return $res->numRows() ? true : false;
137 }
138
139 function add($a_item_ref_id)
140 {
141 global $ilDB;
142
143 if($a_item_ref_id)
144 {
145 $next_id = $ilDB->nextId('crs_start');
146 $query = "INSERT INTO crs_start (crs_start_id,crs_id,item_ref_id) ".
147 "VALUES( ".
148 $ilDB->quote($next_id, 'integer').", ".
149 $ilDB->quote($this->getId() ,'integer').", ".
150 $ilDB->quote($a_item_ref_id ,'integer')." ".
151 ")";
152 $res = $ilDB->manipulate($query);
153 return true;
154 }
155 return false;
156 }
157
158 function __deleteAll()
159 {
160 global $ilDB;
161
162 $query = "DELETE FROM crs_start ".
163 "WHERE crs_id = ".$ilDB->quote($this->getId() ,'integer')." ";
164 $res = $ilDB->manipulate($query);
165
166 return true;
167 }
168
170 {
171 include_once "Services/Object/classes/class.ilObjectActivation.php";
172 foreach(ilObjectActivation::getItems($this->getRefId(), false) as $node)
173 {
174 switch($node['type'])
175 {
176 case 'lm':
177 case 'sahs':
178 case 'svy':
179 case 'tst':
180 $poss_items[] = $node['ref_id'];
181 break;
182 }
183 }
184 return $poss_items ? $poss_items : array();
185 }
186
187 function allFullfilled($user_id)
188 {
189 foreach($this->getStartObjects() as $item)
190 {
191 if(!$this->isFullfilled($user_id,$item['item_ref_id']))
192 {
193 return false;
194 }
195 }
196 return true;
197 }
198
199
200 function isFullfilled($user_id,$item_id)
201 {
202 global $ilObjDataCache;
203
204 include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
205 $lm_continue =& new ilCourseLMHistory($this->getRefId(),$user_id);
206 $continue_data = $lm_continue->getLMHistory();
207
208 $obj_id = $ilObjDataCache->lookupObjId($item_id);
209 $type = $ilObjDataCache->lookupType($obj_id);
210
211 switch($type)
212 {
213 case 'tst':
214 include_once './Modules/Test/classes/class.ilObjTestAccess.php';
215 include_once './Services/AccessControl/classes/class.ilConditionHandler.php';
216
218 {
219 return false;
220 }
221 break;
222 case 'svy':
223 include_once './Modules/Survey/classes/class.ilObjSurveyAccess.php';
224 if(!ilObjSurveyAccess::_lookupFinished($obj_id, $user_id))
225 {
226 return false;
227 }
228 break;
229 case 'sahs':
230 include_once 'Services/Tracking/classes/class.ilLPStatus.php';
231 if(!ilLPStatus::_hasUserCompleted($obj_id, $user_id))
232 {
233 return false;
234 }
235 break;
236
237 default:
238 if(!isset($continue_data[$item_id]))
239 {
240 return false;
241 }
242 }
243 return true;
244 }
245
246
247 // PRIVATE
248 function __read()
249 {
250 global $tree,$ilDB;
251
252 $this->start_objs = array();
253
254 $query = "SELECT * FROM crs_start ".
255 "WHERE crs_id = ".$ilDB->quote($this->getId() ,'integer')." ";
256
257 $res = $this->db->query($query);
258 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
259 {
260 if($tree->isInTree($row->item_ref_id))
261 {
262 $this->start_objs[$row->crs_start_id]['item_ref_id'] = $row->item_ref_id;
263 }
264 else
265 {
266 $this->delete($row->item_ref_id);
267 }
268 }
269 return true;
270 }
271
272
273
274
275} // END class.ilObjCourseGrouping
276?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
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
ilCourseStart($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.
_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