ILIAS  release_4-3 Revision
 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 './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';
139  ilLPStatusWrapper::_refreshStatus($obj->getId());
140 
141  }
142  return true;
143  }
144 
153  protected function applyProgressFilter($obj_id, Array $usr_ids, Array $filter)
154  {
155  include_once './Services/Tracking/classes/class.ilLPStatusWrapper.php';
156 
157 
158  $all_users = array();
159  if(in_array(self::USER_FILTER_ALL, $usr_ids))
160  {
161  $all_users = array_unique(
162  array_merge(
166  )
167  );
168  }
169  else
170  {
171  $all_users = $usr_ids;
172  }
173 
174  if(!$filter or in_array(self::PROGRESS_FILTER_ALL, $filter))
175  {
176  $GLOBALS['log']->write(__METHOD__.': Deleting all progress data');
177  return $all_users;
178  }
179 
180  $filter_users = array();
181  if(in_array(self::PROGRESS_FILTER_IN_PROGRESS, $filter))
182  {
183  $GLOBALS['log']->write(__METHOD__.': Filtering in progress.');
184  $filter_users = array_merge($filter, ilLPStatusWrapper::_getInProgress($obj_id));
185  }
186  if(in_array(self::PROGRESS_FILTER_COMPLETED, $filter))
187  {
188  $GLOBALS['log']->write(__METHOD__.': Filtering completed.');
189  $filter_users = array_merge($filter, ilLPStatusWrapper::_getCompleted($obj_id));
190  }
191  if(in_array(self::PROGRESS_FILTER_FAILED, $filter))
192  {
193  $GLOBALS['log']->write(__METHOD__.': Filtering failed.');
194  $filter_users = array_merge($filter, ilLPStatusWrapper::_getFailed($obj_id));
195  }
196 
197  // Build intersection
198  return array_intersect($all_users, $filter_users);
199  }
200 
208  protected function deleteScormTracking($a_obj_id, $a_usr_ids)
209  {
210  global $ilDB;
211 
212  $query = 'DELETE FROM scorm_tracking '.
213  'WHERE '.$ilDB->in('user_id',$a_usr_ids,false,'integer').' '.
214  'AND obj_id = '. $ilDB->quote($a_obj_id,'integer').' ';
215  $res = $ilDB->manipulate($query);
216  return true;
217  }
218 
224  protected function deleteScorm2004Tracking($a_obj_id, $a_usr_ids)
225  {
226  global $ilDB;
227 
228  $query = 'SELECT cp_node_id FROM cp_node '.
229  'WHERE nodename = '. $ilDB->quote('item','text').' '.
230  'AND cp_node.slm_id = '.$ilDB->quote($a_obj_id,'integer');
231  $res = $ilDB->query($query);
232 
233  $scos = array();
234  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
235  {
236  $scos[] = $row->cp_node_id;
237  }
238 
239  $query = 'DELETE FROM cmi_node '.
240  'WHERE '.$ilDB->in('user_id',(array) $a_usr_ids,false,'integer').' '.
241  'AND '.$ilDB->in('cp_node_id',$scos,false,'integer');
242  $ilDB->manipulate($query);
243 
244  }
245 }
246 ?>