ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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':
130  foreach((array) $valid_users as $usr_id)
131  {
132  $obj->removeTestResultsForUser($usr_id);
133  }
134  break;
135  }
136 
137  // Refresh status
138  include_once './Services/Tracking/classes/class.ilLPStatusWrapper.php';
140  ilLPStatusWrapper::_refreshStatus($obj->getId(), $valid_users);
141 
142  }
143  return true;
144  }
145 
154  protected function applyProgressFilter($obj_id, Array $usr_ids, Array $filter)
155  {
156  include_once './Services/Tracking/classes/class.ilLPStatusWrapper.php';
157 
158 
159  $all_users = array();
160  if(in_array(self::USER_FILTER_ALL, $usr_ids))
161  {
162  $all_users = array_unique(
163  array_merge(
167  )
168  );
169  }
170  else
171  {
172  $all_users = $usr_ids;
173  }
174 
175  if(!$filter or in_array(self::PROGRESS_FILTER_ALL, $filter))
176  {
177  $GLOBALS['log']->write(__METHOD__.': Deleting all progress data');
178  return $all_users;
179  }
180 
181  $filter_users = array();
182  if(in_array(self::PROGRESS_FILTER_IN_PROGRESS, $filter))
183  {
184  $GLOBALS['log']->write(__METHOD__.': Filtering in progress.');
185  $filter_users = array_merge($filter, ilLPStatusWrapper::_getInProgress($obj_id));
186  }
187  if(in_array(self::PROGRESS_FILTER_COMPLETED, $filter))
188  {
189  $GLOBALS['log']->write(__METHOD__.': Filtering completed.');
190  $filter_users = array_merge($filter, ilLPStatusWrapper::_getCompleted($obj_id));
191  }
192  if(in_array(self::PROGRESS_FILTER_FAILED, $filter))
193  {
194  $GLOBALS['log']->write(__METHOD__.': Filtering failed.');
195  $filter_users = array_merge($filter, ilLPStatusWrapper::_getFailed($obj_id));
196  }
197 
198  // Build intersection
199  return array_intersect($all_users, $filter_users);
200  }
201 
209  protected function deleteScormTracking($a_obj_id, $a_usr_ids)
210  {
211  global $ilDB;
212 
213  $query = 'DELETE FROM scorm_tracking '.
214  'WHERE '.$ilDB->in('user_id',$a_usr_ids,false,'integer').' '.
215  'AND obj_id = '. $ilDB->quote($a_obj_id,'integer').' ';
216  $res = $ilDB->manipulate($query);
217  return true;
218  }
219 
225  protected function deleteScorm2004Tracking($a_obj_id, $a_usr_ids)
226  {
227  global $ilDB;
228 
229  $query = 'SELECT cp_node_id FROM cp_node '.
230  'WHERE nodename = '. $ilDB->quote('item','text').' '.
231  'AND cp_node.slm_id = '.$ilDB->quote($a_obj_id,'integer');
232  $res = $ilDB->query($query);
233 
234  $scos = array();
235  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
236  {
237  $scos[] = $row->cp_node_id;
238  }
239 
240  $query = 'DELETE FROM cmi_node '.
241  'WHERE '.$ilDB->in('user_id',(array) $a_usr_ids,false,'integer').' '.
242  'AND '.$ilDB->in('cp_node_id',$scos,false,'integer');
243  $ilDB->manipulate($query);
244 
245  }
246 
250  public function getLearningProgressChanges($sid, $timestamp, $include_ref_ids, $type_filter)
251  {
252  $this->initAuth($sid);
253  $this->initIlias();
254 
255  if(!$this->__checkSession($sid))
256  {
257  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
258  }
259  global $rbacsystem, $tree, $ilLog;
260 
261  // check administrator
262  $types = "";
263  if (is_array($type_filter))
264  {
265  $types = implode($type_filter, ",");
266  }
267 
268  // output lp changes as xml
269  try
270  {
271  include_once './Services/Tracking/classes/class.ilLPXmlWriter.php';
272  $writer = new ilLPXmlWriter(true);
273  $writer->setTimestamp($timestamp);
274  $writer->setIncludeRefIds($include_ref_ids);
275  $writer->setTypeFilter($type_filter);
276  $writer->write();
277 
278  return $writer->xmlDumpMem(true);
279  }
280  catch(UnexpectedValueException $e)
281  {
282  return $this->__raiseError($e->getMessage(), 'Client');
283  }
284  }
285 
286 }
287 ?>