ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilSoapLearningProgressAdministration.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once './webservice/soap/classes/class.ilSoapAdministration.php';
6
15{
16 protected static $DELETE_PROGRESS_FILTER_TYPES = array('sahs', 'tst');
17
23
30
31 protected static $PROGRESS_INFO_TYPES = array(
32 self::PROGRESS_FILTER_ALL,
33 self::PROGRESS_FILTER_IN_PROGRESS,
34 self::PROGRESS_FILTER_COMPLETED,
35 self::PROGRESS_FILTER_FAILED,
36 self::PROGRESS_FILTER_NOT_ATTEMPTED
37 );
38
39
40
41 const USER_FILTER_ALL = -1;
42
47 public function deleteProgress($sid, $ref_ids, $usr_ids, $type_filter, $progress_filter)
48 {
49 $this->initAuth($sid);
50 $this->initIlias();
51
52 if(!is_array($usr_ids))
53 {
54 $usr_ids = (array)$usr_ids;
55 }
56 if(!is_array($type_filter))
57 {
58 $type_filter = (array)$type_filter;
59 }
60
61 // Check session
62 if(!$this->__checkSession($sid))
63 {
64 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
65 }
66
67 // Check filter
68 if(array_diff((array) $type_filter, self::$DELETE_PROGRESS_FILTER_TYPES))
69 {
70 return $this->__raiseError('Invalid filter type given', 'Client');
71 }
72
73 include_once 'Services/User/classes/class.ilObjUser.php';
74 if(!in_array(self::USER_FILTER_ALL, $usr_ids) and !ilObjUser::userExists($usr_ids))
75 {
76 return $this->__raiseError('Invalid user ids given', 'Client');
77 }
78
79 $valid_refs = array();
80 foreach((array) $ref_ids as $ref_id)
81 {
83 $type = ilObject::_lookupType($obj_id);
84
85 // All containers
86 if($GLOBALS['objDefinition']->isContainer($type))
87 {
88 $all_sub_objs = array();
89 foreach(($type_filter) as $type_filter_item)
90 {
91 $sub_objs = $GLOBALS['tree']->getSubTree(
92 $GLOBALS['tree']->getNodeData($ref_id),
93 false,
94 $type_filter_item
95 );
96 $all_sub_objs = array_merge($all_sub_objs, $sub_objs);
97 }
98
99 foreach($all_sub_objs as $child_ref)
100 {
101 $child_type = ilObject::_lookupType(ilObject::_lookupObjId($child_ref));
102 if(!$GLOBALS['ilAccess']->checkAccess('write', '', $child_ref))
103 {
104 return $this->__raiseError('Permission denied for : '. $ref_id.' -> type '.$type, 'Client');
105 }
106 $valid_refs[] = $child_ref;
107 }
108
109 }
110 elseif(in_array($type, $type_filter))
111 {
112 if(!$GLOBALS['ilAccess']->checkAccess('write','',$ref_id))
113 {
114 return $this->__raiseError('Permission denied for : '. $ref_id.' -> type '.$type, 'Client');
115 }
116 $valid_refs[] = $ref_id;
117 }
118 else
119 {
120 return $this->__raiseError('Invalid object type given for : '. $ref_id.' -> type '.$type, 'Client');
121 }
122 }
123
124 // Delete tracking data
125 foreach($valid_refs as $ref_id)
126 {
127 include_once './Services/Object/classes/class.ilObjectFactory.php';
129
130 if(!$obj instanceof ilObject)
131 {
132 return $this->__raiseError('Invalid reference id given : '. $ref_id.' -> type '.$type, 'Client');
133 }
134
135 // filter users
136 $valid_users = $this->applyProgressFilter($obj->getId(), (array) $usr_ids, (array) $progress_filter);
137
138 switch($obj->getType())
139 {
140 case 'sahs':
141 include_once './Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
142 $subtype = ilObjSAHSLearningModule::_lookupSubType($obj->getId());
143
144 switch($subtype)
145 {
146 case 'scorm':
147 $this->deleteScormTracking($obj->getId(),(array) $valid_users);
148 break;
149
150 case 'scorm2004':
151 $this->deleteScorm2004Tracking($obj->getId(), (array) $valid_users);
152 break;
153 }
154 break;
155
156 case 'tst':
157
159 $obj->removeTestResultsFromSoapLpAdministration(array_values((array)$valid_users));
160 break;
161 }
162
163 // Refresh status
164 include_once './Services/Tracking/classes/class.ilLPStatusWrapper.php';
166 ilLPStatusWrapper::_refreshStatus($obj->getId(), $valid_users);
167
168 }
169 return true;
170 }
171
172 public function getProgressInfo($sid, $a_ref_id, $a_progress_filter)
173 {
174 global $ilAccess;
175 $this->initAuth($sid);
176 $this->initIlias();
177
178 // Check session
179 if(!$this->__checkSession($sid))
180 {
181 return $this->__raiseError('Error '.self::SOAP_LP_ERROR_AUTHENTICATION.':'.$this->__getMessage(),
182 self::SOAP_LP_ERROR_AUTHENTICATION);
183 }
184
185 // Check filter
186 if(array_diff((array) $a_progress_filter, self::$PROGRESS_INFO_TYPES))
187 {
188 return $this->__raiseError('Error '.self::SOAP_LP_ERROR_INVALID_FILTER.': Invalid filter type given',
189 self::SOAP_LP_ERROR_INVALID_FILTER);
190 }
191 // Check LP enabled
192 include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
194 {
195 return $this->__raiseError('Error '. self::SOAP_LP_ERROR_LP_NOT_ENABLED .': Learning progress not enabled in ILIAS',
196 self::SOAP_LP_ERROR_LP_NOT_ENABLED);
197 }
198
199 include_once './Services/Object/classes/class.ilObjectFactory.php';
200 $obj = ilObjectFactory::getInstanceByRefId($a_ref_id, false);
201 if(!$obj instanceof ilObject)
202 {
203 return $this->__raiseError('Error '.self::SOAP_LP_ERROR_INVALID_REF_ID.': Invalid reference id '. $a_ref_id.' given',
204 self::SOAP_LP_ERROR_INVALID_REF_ID);
205 }
206
207 // check lp available
208 include_once './Services/Tracking/classes/class.ilLPObjSettings.php';
209 $mode = ilLPObjSettings::_lookupDBMode($obj->getId());
211 {
212 return $this->__raiseError('Error '.self::SOAP_LP_ERROR_LP_NOT_AVAILABLE.': Learning progress not available for objects of type '.
213 $obj->getType(),
214 self::SOAP_LP_ERROR_LP_NOT_AVAILABLE);
215 }
216
217 // check rbac
218 if(!$ilAccess->checkAccess('edit_learning_progress','',$a_ref_id))
219 {
220 return $this->__raiseError('Error '. self::SOAP_LP_ERROR_NO_PERMISSION .': No Permission to access learning progress in this object',
221 self::SOAP_LP_ERROR_NO_PERMISSION);
222 }
223
224 include_once './Services/Xml/classes/class.ilXmlWriter.php';
225 $writer = new ilXmlWriter();
226 $writer->xmlStartTag(
227 'LearningProgressInfo',
228 array(
229 'ref_id' => $obj->getRefId(),
230 'type' => $obj->getType()
231 )
232 );
233
234 $writer->xmlStartTag('LearningProgressSummary');
235
236 include_once './Services/Tracking/classes/class.ilLPStatusWrapper.php';
237 if(in_array(self::PROGRESS_FILTER_ALL, $a_progress_filter) or in_array(self::PROGRESS_FILTER_COMPLETED, $a_progress_filter))
238 {
239 $completed = ilLPStatusWrapper::_getCountCompleted($obj->getId());
240 $writer->xmlElement(
241 'Status',
242 array(
243 'type' => self::PROGRESS_FILTER_COMPLETED,
244 'num' => (int) $completed
245 )
246 );
247 }
248 if(in_array(self::PROGRESS_FILTER_ALL, $a_progress_filter) or in_array(self::PROGRESS_FILTER_IN_PROGRESS, $a_progress_filter))
249 {
250 $completed = ilLPStatusWrapper::_getCountInProgress($obj->getId());
251 $writer->xmlElement(
252 'Status',
253 array(
254 'type' => self::PROGRESS_FILTER_IN_PROGRESS,
255 'num' => (int) $completed
256 )
257 );
258 }
259 if(in_array(self::PROGRESS_FILTER_ALL, $a_progress_filter) or in_array(self::PROGRESS_FILTER_FAILED, $a_progress_filter))
260 {
261 $completed = ilLPStatusWrapper::_getCountFailed($obj->getId());
262 $writer->xmlElement(
263 'Status',
264 array(
265 'type' => self::PROGRESS_FILTER_FAILED,
266 'num' => (int) $completed
267 )
268 );
269 }
270 if(in_array(self::PROGRESS_FILTER_ALL, $a_progress_filter) or in_array(self::PROGRESS_FILTER_NOT_ATTEMPTED, $a_progress_filter))
271 {
272 $completed = ilLPStatusWrapper::_getCountNotAttempted($obj->getId());
273 $writer->xmlElement(
274 'Status',
275 array(
276 'type' => self::PROGRESS_FILTER_NOT_ATTEMPTED,
277 'num' => (int) $completed
278 )
279 );
280 }
281 $writer->xmlEndTag('LearningProgressSummary');
282
283
284 $writer->xmlStartTag('UserProgress');
285 if(in_array(self::PROGRESS_FILTER_ALL, $a_progress_filter) or in_array(self::PROGRESS_FILTER_COMPLETED, $a_progress_filter))
286 {
287 $completed = ilLPStatusWrapper::_getCompleted($obj->getId());
288 $this->addUserProgress($writer, $completed, self::PROGRESS_FILTER_COMPLETED);
289 }
290 if(in_array(self::PROGRESS_FILTER_ALL, $a_progress_filter) or in_array(self::PROGRESS_FILTER_IN_PROGRESS, $a_progress_filter))
291 {
292 $completed = ilLPStatusWrapper::_getInProgress($obj->getId());
293 $this->addUserProgress($writer, $completed, self::PROGRESS_FILTER_IN_PROGRESS);
294 }
295 if(in_array(self::PROGRESS_FILTER_ALL, $a_progress_filter) or in_array(self::PROGRESS_FILTER_FAILED, $a_progress_filter))
296 {
297 $completed = ilLPStatusWrapper::_getFailed($obj->getId());
298 $this->addUserProgress($writer, $completed, self::PROGRESS_FILTER_FAILED);
299 }
300 if(in_array(self::PROGRESS_FILTER_ALL, $a_progress_filter) or in_array(self::PROGRESS_FILTER_NOT_ATTEMPTED, $a_progress_filter))
301 {
302 $completed = ilLPStatusWrapper::_getNotAttempted($obj->getId());
303 $this->addUserProgress($writer, $completed, self::PROGRESS_FILTER_NOT_ATTEMPTED);
304 }
305 $writer->xmlEndTag('UserProgress');
306 $writer->xmlEndTag('LearningProgressInfo');
307
308 return $writer->xmlDumpMem();
309 }
310
311 protected function addUserProgress(ilXmlWriter $writer, $users, $a_type)
312 {
313 foreach($users as $user_id)
314 {
315 $writer->xmlStartTag(
316 'User',
317 array(
318 'id' => $user_id,
319 'status' => $a_type
320 )
321 );
322
323 $info = ilObjUser::_lookupName($user_id);
324 $writer->xmlElement('Login',array(),(string) $info['login']);
325 $writer->xmlElement('Firstname',array(),(string) $info['firstname']);
326 $writer->xmlElement('Lastname',array(),(string) $info['lastname']);
327 $writer->xmlEndTag('User');
328
329 }
330 }
331
332
341 protected function applyProgressFilter($obj_id, Array $usr_ids, Array $filter)
342 {
343 include_once './Services/Tracking/classes/class.ilLPStatusWrapper.php';
344
345
346 $all_users = array();
347 if(in_array(self::USER_FILTER_ALL, $usr_ids))
348 {
349 $all_users = array_unique(
350 array_merge(
354 )
355 );
356 }
357 else
358 {
359 $all_users = $usr_ids;
360 }
361
362 if(!$filter or in_array(self::PROGRESS_FILTER_ALL, $filter))
363 {
364 $GLOBALS['log']->write(__METHOD__.': Deleting all progress data');
365 return $all_users;
366 }
367
368 $filter_users = array();
369 if(in_array(self::PROGRESS_FILTER_IN_PROGRESS, $filter))
370 {
371 $GLOBALS['log']->write(__METHOD__.': Filtering in progress.');
372 $filter_users = array_merge($filter, ilLPStatusWrapper::_getInProgress($obj_id));
373 }
374 if(in_array(self::PROGRESS_FILTER_COMPLETED, $filter))
375 {
376 $GLOBALS['log']->write(__METHOD__.': Filtering completed.');
377 $filter_users = array_merge($filter, ilLPStatusWrapper::_getCompleted($obj_id));
378 }
379 if(in_array(self::PROGRESS_FILTER_FAILED, $filter))
380 {
381 $GLOBALS['log']->write(__METHOD__.': Filtering failed.');
382 $filter_users = array_merge($filter, ilLPStatusWrapper::_getFailed($obj_id));
383 }
384
385 // Build intersection
386 return array_intersect($all_users, $filter_users);
387 }
388
396 protected function deleteScormTracking($a_obj_id, $a_usr_ids)
397 {
398 global $ilDB;
399
400 $query = 'DELETE FROM scorm_tracking '.
401 'WHERE '.$ilDB->in('user_id',$a_usr_ids,false,'integer').' '.
402 'AND obj_id = '. $ilDB->quote($a_obj_id,'integer').' ';
403 $res = $ilDB->manipulate($query);
404 return true;
405 }
406
412 protected function deleteScorm2004Tracking($a_obj_id, $a_usr_ids)
413 {
414 global $ilDB;
415
416 $query = 'SELECT cp_node_id FROM cp_node '.
417 'WHERE nodename = '. $ilDB->quote('item','text').' '.
418 'AND cp_node.slm_id = '.$ilDB->quote($a_obj_id,'integer');
419 $res = $ilDB->query($query);
420
421 $scos = array();
422 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
423 {
424 $scos[] = $row->cp_node_id;
425 }
426
427 $query = 'DELETE FROM cmi_node '.
428 'WHERE '.$ilDB->in('user_id',(array) $a_usr_ids,false,'integer').' '.
429 'AND '.$ilDB->in('cp_node_id',$scos,false,'integer');
430 $ilDB->manipulate($query);
431
432 }
433
437 public function getLearningProgressChanges($sid, $timestamp, $include_ref_ids, $type_filter)
438 {
439 $this->initAuth($sid);
440 $this->initIlias();
441
442 if(!$this->__checkSession($sid))
443 {
444 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
445 }
446 global $rbacsystem, $tree, $ilLog;
447
448 // check administrator
449 $types = "";
450 if (is_array($type_filter))
451 {
452 $types = implode($type_filter, ",");
453 }
454
455 // output lp changes as xml
456 try
457 {
458 include_once './Services/Tracking/classes/class.ilLPXmlWriter.php';
459 $writer = new ilLPXmlWriter(true);
460 $writer->setTimestamp($timestamp);
461 $writer->setIncludeRefIds($include_ref_ids);
462 $writer->setTypeFilter($type_filter);
463 $writer->write();
464
465 return $writer->xmlDumpMem(true);
466 }
467 catch(UnexpectedValueException $e)
468 {
469 return $this->__raiseError($e->getMessage(), 'Client');
470 }
471 }
472
473}
474?>
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static _lookupDBMode($a_obj_id)
_refreshStatus($a_obj_id, $a_users=null)
Set dirty.
_getCountCompleted($a_obj_id)
Static function to read the number of user who have the status 'completed'.
_getCountInProgress($a_obj_id)
Static function to read the number of user who have the status 'in_progress'.
_getCompleted($a_obj_id)
Static function to read the users who have the status 'completed'.
_getNotAttempted($a_obj_id)
Static function to read the number of user who have the status 'not_attempted'.
_getFailed($a_obj_id)
Static function to read the users who have the status 'completed'.
static _resetInfoCaches($a_obj_id)
_getCountNotAttempted($a_obj_id)
Static function to read the number of user who have the status 'not_attempted'.
_getCountFailed($a_obj_id)
Static function to read the number of user who have the status 'failed'.
_getInProgress($a_obj_id)
Static function to read users who have the status 'in_progress'.
XML writer learning progress.
_lookupSubType($a_obj_id)
lookup subtype id (scorm, aicc, hacp)
static _enabledLearningProgress()
check wether learing progress is enabled or not
static userExists($a_usr_ids=array())
static _lookupName($a_user_id)
lookup user name
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObject Basic functions for all objects.
static _lookupObjId($a_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
__raiseError($a_message, $a_code)
This class handles all DB changes necessary for fraunhofer.
deleteScorm2004Tracking($a_obj_id, $a_usr_ids)
Delete scorm 2004 tracking.
getLearningProgressChanges($sid, $timestamp, $include_ref_ids, $type_filter)
Get learning progress changes.
applyProgressFilter($obj_id, Array $usr_ids, Array $filter)
Apply progress filter.
deleteScormTracking($a_obj_id, $a_usr_ids)
Delete SCORM Tracking @global type $ilDB.
XML writer class.
xmlEndTag($tag)
Writes an endtag.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
$info
Definition: example_052.php:80
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
$ref_id
Definition: sahs_server.php:39
global $ilDB