ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLPStatusCollection.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
33 include_once './Services/Tracking/classes/class.ilLPStatus.php';
34 include_once './Services/Tracking/classes/class.ilLPStatusWrapper.php';
35 
37 {
38 
39  function ilLPStatusCollection($a_obj_id)
40  {
41  global $ilDB;
42 
43  parent::ilLPStatus($a_obj_id);
44  $this->db =& $ilDB;
45  }
46 
47  function _getNotAttempted($a_obj_id)
48  {
49  $users = array();
50 
51  $members = self::getMembers($a_obj_id);
52  if($members)
53  {
54  // diff in progress and completed (use stored result in LPStatusWrapper)
55  $users = array_diff((array) $members, ilLPStatusWrapper::_getInProgress($a_obj_id));
56  $users = array_diff((array) $users, ilLPStatusWrapper::_getCompleted($a_obj_id));
57  $users = array_diff((array) $users, ilLPStatusWrapper::_getFailed($a_obj_id));
58  }
59 
60  return $users;
61  }
62 
63  function _getInProgress($a_obj_id)
64  {
65  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
66  include_once './Services/Tracking/classes/class.ilChangeEvent.php';
67  $users = ilChangeEvent::lookupUsersInProgress($a_obj_id);
68  foreach(ilLPCollectionCache::_getItems($a_obj_id, true) as $item_id)
69  {
70  $item_id = ilObject::_lookupObjId($item_id);
71 
72  // merge arrays of users with status 'in progress'
73  $users = array_unique(array_merge((array) $users,ilLPStatusWrapper::_getInProgress($item_id)));
74  $users = array_unique(array_merge((array) $users,ilLPStatusWrapper::_getCompleted($item_id)));
75  }
76 
77  // Exclude all users with status completed.
78  $users = array_diff((array) $users,ilLPStatusWrapper::_getCompleted($a_obj_id));
79  // Exclude all users with status failed.
80  $users = array_diff((array) $users,ilLPStatusWrapper::_getFailed($a_obj_id));
81 
82  if($users)
83  {
84  // Exclude all non members
85  $users = array_intersect(self::getMembers($a_obj_id), (array)$users);
86  }
87 
88  return $users;
89  }
90 
98  function _getCompleted($a_obj_id)
99  {
100  global $ilObjDataCache;
101 
102  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
103 
104  // New handling for optional assignments
105  $counter = 0;
106  $users = array();
107  foreach(ilLPCollectionCache::getGroupedItems($a_obj_id, true) as $grouping_id => $grouping)
108  {
109  $isGrouping = $grouping_id ? true : false;
110  $grouping_completed = array();
111  $grouping_completed_users_num = array();
112  foreach((array) $grouping['items'] as $item)
113  {
114  $item_id = $ilObjDataCache->lookupObjId($item);
115  $tmp_users = ilLPStatusWrapper::_getCompleted($item_id);
116  if($isGrouping)
117  {
118  // Iterated through all grouped items and count the number of fullfiled items
119  foreach($tmp_users as $tmp_user_id)
120  {
121  ++$grouping_completed_users_num[$tmp_user_id];
122  }
123  }
124  else
125  {
126  if(!$counter++)
127  {
128  $users = $tmp_users;
129  }
130  else
131  {
132  $users = array_intersect($users,$tmp_users);
133  }
134  }
135  }
136  if($isGrouping)
137  {
138  // Iterate through all "grouping_completed_users_num"
139  // All users with completed items greater equal than "num_obligatory" are completed
140  foreach($grouping_completed_users_num as $tmp_user_id => $grouping_num_completed)
141  {
142  if($grouping_num_completed >= $grouping['num_obligatory'])
143  {
144  $grouping_completed[] = $tmp_user_id;
145  }
146  }
147 
148  // build intersection of users
149  if(!$counter++)
150  {
151  $users = $grouping_completed;
152  }
153  else
154  {
155  $users = array_intersect($users,$grouping_completed);
156  }
157  }
158  }
159 
160  $users = array_diff($users,ilLPStatusWrapper::_getFailed($a_obj_id));
161 
162  if($users)
163  {
164  // Exclude all non members
165  $users = array_intersect(self::getMembers($a_obj_id), (array)$users);
166  }
167 
168  return (array) $users;
169  }
170 
171  function _getFailed($a_obj_id)
172  {
173  global $ilObjDataCache;
174 
175  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
176 
177  $users = array();
178  foreach(ilLPCollectionCache::getGroupedItems($a_obj_id, true) as $grouping_id => $grouping)
179  {
180  $isGrouping = $grouping_id ? true : false;
181 
182  $gr_failed = array();
183  $gr_failed_users_num = array();
184  $counter = 0;
185  foreach((array) $grouping['items'] as $item)
186  {
187  $item_id = $ilObjDataCache->lookupObjId($item);
188  $tmp_users = ilLPStatusWrapper::_getFailed($item_id);
189 
190  if($isGrouping)
191  {
192  foreach($tmp_users as $tmp_user_id)
193  {
194  ++$gr_failed_users_num[$tmp_user_id];
195  }
196  }
197  else
198  {
199  // One item failed is sufficient for status failed.
200  $gr_failed = array_merge($gr_failed,$tmp_users);
201  }
202  $counter++;
203  }
204  if($isGrouping)
205  {
206  $allowed_failed = count($grouping['items']) - $grouping['num_obligatory'];
207  // Itereate over all failed users and check whether the allowd_failed value exceeded
208  foreach($gr_failed_users_num as $tmp_user_id => $num_failed)
209  {
210  if($num_failed > $allowed_failed)
211  {
212  $gr_failed[] = $tmp_user_id;
213  }
214  }
215 
216  }
217  $users = array_unique(array_merge($users, $gr_failed));
218  }
219 
220  if($users)
221  {
222  // Exclude all non members
223  $users = array_intersect(self::getMembers($a_obj_id), (array)$users);
224  }
225 
226  return array_unique($users);
227  }
228 
229  function _getStatusInfo($a_obj_id)
230  {
231  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
232 
233  $status_info = array();
234  $status_info['collections'] = ilLPCollectionCache::_getItems($a_obj_id);
235  $status_info['num_collections'] = count($status_info['collections']);
236  return $status_info;
237  }
238 
239  function _getTypicalLearningTime($a_obj_id)
240  {
241  global $ilObjDataCache;
242 
243  if($ilObjDataCache->lookupType($a_obj_id) == 'sahs')
244  {
245  return parent::_getTypicalLearningTime($a_obj_id);
246  }
247 
248  $tlt = 0;
249  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
250  foreach($status_info['collections'] as $item)
251  {
252  $tlt += ilLPStatusWrapper::_getTypicalLearningTime($ilObjDataCache->lookupObjId($item));
253  }
254  return $tlt;
255  }
256 
265  function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
266  {
267  global $ilObjDataCache;
268 
269  $status['completed'] = true;
270  $status['failed'] = false;
271  $status['in_progress'] = false;
272  $status['not_attempted'] = true;
273 
274  switch ($ilObjDataCache->lookupType($a_obj_id))
275  {
276  case "crs":
277  case "fold":
278  case "grp":
279  include_once "./Services/Tracking/classes/class.ilChangeEvent.php";
280  if (ilChangeEvent::hasAccessed($a_obj_id, $a_user_id))
281  {
282  $status['in_progress'] = true;
283  }
284 
285  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
286  foreach(ilLPCollectionCache::getGroupedItems($a_obj_id, true) as $grouping_id => $grouping)
287  {
288  $isGrouping = $grouping_id ? true : false;
289  $status = self::determineGroupingStatus($status,$grouping,$a_user_id,$isGrouping);
290  }
291  if($status['completed'])
292  {
294  }
295  if($status['failed'])
296  {
297  return LP_STATUS_FAILED_NUM;
298  }
299  if($status['in_progress'])
300  {
302  }
304  }
306  }
307 
317  public static function determineGroupingStatus($status,$gr_info,$user_id,$is_grouping)
318  {
319  global $ilObjDataCache;
320 
321  $items = $gr_info['items'];
322  if($is_grouping)
323  {
324  $max_allowed_failed = count($items) - $gr_info['num_obligatory'];
325  $required_completed = $gr_info['num_obligatory'];
326  }
327  else
328  {
329  $max_allowed_failed = 0;
330  $required_completed = count($items);
331  }
332 
333  // Required for grouping with a number of obligatory items
334  $num_failed = 0;
335  $num_completed = 0;
336 
337  include_once("./Services/Tracking/classes/class.ilLPCollectionCache.php");
338  foreach($items as $item_id)
339  {
340  $item_id = $ilObjDataCache->lookupObjId($item_id);
341  $gr_status = ilLPStatusWrapper::_determineStatus($item_id, $user_id);
342 
343  if($gr_status == LP_STATUS_FAILED_NUM)
344  {
345  if(++$num_failed > $max_allowed_failed)
346  {
347  $status['failed'] = true;
348  $status['completed'] = false;
349  return $status;
350  }
351  }
352  if($gr_status == LP_STATUS_COMPLETED_NUM)
353  {
354  if(++$num_completed >= $required_completed)
355  {
356  return $status;
357  }
358  }
359  }
360  // Not completed since returned above
361  $status['completed'] = false;
362  return $status;
363  }
364 
370  protected static function getMembers($a_obj_id)
371  {
372  global $ilObjDataCache, $tree;
373 
374  switch($ilObjDataCache->lookupType($a_obj_id))
375  {
376  case 'crs':
377  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
378  $member_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
379  return $member_obj->getMembers();
380 
381  case 'grp':
382  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
383  $member_obj = ilGroupParticipants::_getInstanceByObjId($a_obj_id);
384  return $member_obj->getMembers();
385 
386  case 'fold':
387  $folder_ref_ids = ilObject::_getAllReferences($a_obj_id);
388  $folder_ref_id = current($folder_ref_ids);
389  if($crs_id = $tree->checkForParentType($folder_ref_id,'crs'))
390  {
391  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
393  return $member_obj->getMembers();
394  }
395  break;
396  }
397 
398  return array();
399  }
400 
408  public static function _lookupCompletedForObject($a_obj_id, $a_user_ids = null)
409  {
410  if(!$a_user_ids)
411  {
412  $a_user_ids = self::getMembers($a_obj_id);
413  if(!$a_user_ids)
414  {
415  return array();
416  }
417  }
418  return self::_lookupStatusForObject($a_obj_id, LP_STATUS_COMPLETED_NUM, $a_user_ids);
419  }
420 
428  public static function _lookupFailedForObject($a_obj_id, $a_user_ids = null)
429  {
430  if(!$a_user_ids)
431  {
432  $a_user_ids = self::getMembers($a_obj_id);
433  if(!$a_user_ids)
434  {
435  return array();
436  }
437  }
438  return self::_lookupStatusForObject($a_obj_id, LP_STATUS_FAILED_NUM, $a_user_ids);
439  }
440 
448  public static function _lookupInProgressForObject($a_obj_id, $a_user_ids = null)
449  {
450  if(!$a_user_ids)
451  {
452  $a_user_ids = self::getMembers($a_obj_id);
453  if(!$a_user_ids)
454  {
455  return array();
456  }
457  }
458  return self::_lookupStatusForObject($a_obj_id, LP_STATUS_IN_PROGRESS_NUM, $a_user_ids);
459  }
460 }
461 ?>