ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 
5 include_once './webservice/soap/classes/class.ilSoapAdministration.php';
6 
15 {
16  protected static $DELETE_PROGRESS_FILTER_TYPES = array('sahs', 'tst');
17 
22 
23  const USER_FILTER_ALL = -1;
24 
29  public function deleteProgress($sid, $ref_ids, $usr_ids, $type_filter, $progress_filter)
30  {
31  $this->initAuth($sid);
32  $this->initIlias();
33 
34  // Check session
35  if(!$this->__checkSession($sid))
36  {
37  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
38  }
39 
40  // Check filter
41  if(array_diff((array) $type_filter, self::$DELETE_PROGRESS_FILTER_TYPES))
42  {
43  return $this->__raiseError('Invalid filter type given', 'Client');
44  }
45 
46  include_once 'Services/User/classes/class.ilObjUser.php';
47  if(!in_array(self::USER_FILTER_ALL, $usr_ids) and !ilObjUser::userExists($usr_ids))
48  {
49  return $this->__raiseError('Invalid user ids given', 'Client');
50  }
51 
52  $valid_refs = array();
53  foreach((array) $ref_ids as $ref_id)
54  {
55  $obj_id = ilObject::_lookupObjId($ref_id);
56  $type = ilObject::_lookupType($obj_id);
57 
58  // All containers
59  if($GLOBALS['objDefinition']->isContainer($type))
60  {
61  $all_sub_objs = array();
62  foreach(($type_filter) as $type_filter_item)
63  {
64  $sub_objs = $GLOBALS['tree']->getSubTree(
65  $GLOBALS['tree']->getNodeData($ref_id),
66  false,
67  $type_filter_item
68  );
69  $all_sub_objs = array_merge($all_sub_objs, $sub_objs);
70  }
71 
72  foreach($all_sub_objs as $child_ref)
73  {
74  $child_type = ilObject::_lookupType(ilObject::_lookupObjId($child_ref));
75  if(!$GLOBALS['ilAccess']->checkAccess('write', '', $child_ref))
76  {
77  return $this->__raiseError('Permission denied for : '. $ref_id.' -> type '.$type, 'Client');
78  }
79  $valid_refs[] = $child_ref;
80  }
81 
82  }
83  elseif(in_array($type, $type_filter))
84  {
85  if(!$GLOBALS['ilAccess']->checkAccess('write','',$ref_id))
86  {
87  return $this->__raiseError('Permission denied for : '. $ref_id.' -> type '.$type, 'Client');
88  }
89  $valid_refs[] = $ref_id;
90  }
91  else
92  {
93  return $this->__raiseError('Invalid object type given for : '. $ref_id.' -> type '.$type, 'Client');
94  }
95  }
96 
97  // Delete tracking data
98  foreach($valid_refs as $ref_id)
99  {
100  include_once './Services/Object/classes/class.ilObjectFactory.php';
101  $obj = ilObjectFactory::getInstanceByRefId($ref_id, false);
102 
103  if(!$obj instanceof ilObject)
104  {
105  return $this->__raiseError('Invalid reference id given : '. $ref_id.' -> type '.$type, 'Client');
106  }
107 
108  // filter users
109  $valid_users = $this->applyProgressFilter($obj->getId(), (array) $usr_ids, (array) $progress_filter);
110 
111  switch($obj->getType())
112  {
113  case 'sahs':
114  include_once './Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
115  $subtype = ilObjSAHSLearningModule::_lookupSubType($obj->getId());
116 
117  switch($subtype)
118  {
119  case 'scorm':
120  $this->deleteScormTracking($obj->getId(),(array) $valid_users);
121  break;
122 
123  case 'scorm2004':
124  $this->deleteScorm2004Tracking($obj->getId(), (array) $valid_users);
125  break;
126  }
127  break;
128 
129  case 'tst':
131  $obj->removeTestResultsByUserIds(array_values((array)$valid_users));
132  break;
133  }
134 
135  // Refresh status
136  include_once './Services/Tracking/classes/class.ilLPStatusWrapper.php';
138  ilLPStatusWrapper::_refreshStatus($obj->getId(), $valid_users);
139 
140  }
141  return true;
142  }
143 
152  protected function applyProgressFilter($obj_id, Array $usr_ids, Array $filter)
153  {
154  include_once './Services/Tracking/classes/class.ilLPStatusWrapper.php';
155 
156 
157  $all_users = array();
158  if(in_array(self::USER_FILTER_ALL, $usr_ids))
159  {
160  $all_users = array_unique(
161  array_merge(
165  )
166  );
167  }
168  else
169  {
170  $all_users = $usr_ids;
171  }
172 
173  if(!$filter or in_array(self::PROGRESS_FILTER_ALL, $filter))
174  {
175  $GLOBALS['log']->write(__METHOD__.': Deleting all progress data');
176  return $all_users;
177  }
178 
179  $filter_users = array();
180  if(in_array(self::PROGRESS_FILTER_IN_PROGRESS, $filter))
181  {
182  $GLOBALS['log']->write(__METHOD__.': Filtering in progress.');
183  $filter_users = array_merge($filter, ilLPStatusWrapper::_getInProgress($obj_id));
184  }
185  if(in_array(self::PROGRESS_FILTER_COMPLETED, $filter))
186  {
187  $GLOBALS['log']->write(__METHOD__.': Filtering completed.');
188  $filter_users = array_merge($filter, ilLPStatusWrapper::_getCompleted($obj_id));
189  }
190  if(in_array(self::PROGRESS_FILTER_FAILED, $filter))
191  {
192  $GLOBALS['log']->write(__METHOD__.': Filtering failed.');
193  $filter_users = array_merge($filter, ilLPStatusWrapper::_getFailed($obj_id));
194  }
195 
196  // Build intersection
197  return array_intersect($all_users, $filter_users);
198  }
199 
207  protected function deleteScormTracking($a_obj_id, $a_usr_ids)
208  {
209  global $ilDB;
210 
211  $query = 'DELETE FROM scorm_tracking '.
212  'WHERE '.$ilDB->in('user_id',$a_usr_ids,false,'integer').' '.
213  'AND obj_id = '. $ilDB->quote($a_obj_id,'integer').' ';
214  $res = $ilDB->manipulate($query);
215  return true;
216  }
217 
223  protected function deleteScorm2004Tracking($a_obj_id, $a_usr_ids)
224  {
225  global $ilDB;
226 
227  $query = 'SELECT cp_node_id FROM cp_node '.
228  'WHERE nodename = '. $ilDB->quote('item','text').' '.
229  'AND cp_node.slm_id = '.$ilDB->quote($a_obj_id,'integer');
230  $res = $ilDB->query($query);
231 
232  $scos = array();
233  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
234  {
235  $scos[] = $row->cp_node_id;
236  }
237 
238  $query = 'DELETE FROM cmi_node '.
239  'WHERE '.$ilDB->in('user_id',(array) $a_usr_ids,false,'integer').' '.
240  'AND '.$ilDB->in('cp_node_id',$scos,false,'integer');
241  $ilDB->manipulate($query);
242 
243  }
244 
248  public function getLearningProgressChanges($sid, $timestamp, $include_ref_ids, $type_filter)
249  {
250  $this->initAuth($sid);
251  $this->initIlias();
252 
253  if(!$this->__checkSession($sid))
254  {
255  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
256  }
257  global $rbacsystem, $tree, $ilLog;
258 
259  // check administrator
260  $types = "";
261  if (is_array($type_filter))
262  {
263  $types = implode($type_filter, ",");
264  }
265 
266  // output lp changes as xml
267  try
268  {
269  include_once './Services/Tracking/classes/class.ilLPXmlWriter.php';
270  $writer = new ilLPXmlWriter(true);
271  $writer->setTimestamp($timestamp);
272  $writer->setIncludeRefIds($include_ref_ids);
273  $writer->setTypeFilter($type_filter);
274  $writer->write();
275 
276  return $writer->xmlDumpMem(true);
277  }
278  catch(UnexpectedValueException $e)
279  {
280  return $this->__raiseError($e->getMessage(), 'Client');
281  }
282  }
283 
284 }
285 ?>
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
This class handles all DB changes necessary for fraunhofer.
Class ilObject Basic functions for all objects.
static userExists($a_usr_ids=array())
static _resetInfoCaches($a_obj_id)
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
XML writer learning progress.
_getFailed($a_obj_id)
Static function to read the users who have the status &#39;completed&#39;.
$GLOBALS['ct_recipient']
static _lookupObjId($a_id)
__raiseError($a_message, $a_code)
_lookupSubType($a_obj_id)
lookup subtype id (scorm, aicc, hacp)
_getCompleted($a_obj_id)
Static function to read the users who have the status &#39;completed&#39;.
getLearningProgressChanges($sid, $timestamp, $include_ref_ids, $type_filter)
Get learning progress changes.
deleteScormTracking($a_obj_id, $a_usr_ids)
Delete SCORM Tracking type $ilDB.
static _lookupType($a_id, $a_reference=false)
lookup object type
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
_refreshStatus($a_obj_id, $a_users=null)
Set dirty.
deleteScorm2004Tracking($a_obj_id, $a_usr_ids)
Delete scorm 2004 tracking.
$ref_id
Definition: sahs_server.php:39
global $ilDB
applyProgressFilter($obj_id, Array $usr_ids, Array $filter)
Apply progress filter.
_getInProgress($a_obj_id)
Static function to read users who have the status &#39;in_progress&#39;.