ILIAS  Release_4_4_x_branch Revision 61816
 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.ilChangeEvent.php';
66  $users = ilChangeEvent::lookupUsersInProgress($a_obj_id);
67 
68  include_once './Services/Object/classes/class.ilObjectLP.php';
69  $olp = ilObjectLP::getInstance($a_obj_id);
70  $collection = $olp->getCollectionInstance();
71  if($collection)
72  {
73  foreach($collection->getItems() as $item_id)
74  {
75  $item_id = ilObject::_lookupObjId($item_id);
76 
77  // merge arrays of users with status 'in progress'
78  $users = array_unique(array_merge((array) $users,ilLPStatusWrapper::_getInProgress($item_id)));
79  $users = array_unique(array_merge((array) $users,ilLPStatusWrapper::_getCompleted($item_id)));
80  }
81  }
82 
83  // Exclude all users with status completed.
84  $users = array_diff((array) $users,ilLPStatusWrapper::_getCompleted($a_obj_id));
85  // Exclude all users with status failed.
86  $users = array_diff((array) $users,ilLPStatusWrapper::_getFailed($a_obj_id));
87 
88  if($users)
89  {
90  // Exclude all non members
91  $users = array_intersect(self::getMembers($a_obj_id), (array)$users);
92  }
93 
94  return $users;
95  }
96 
104  function _getCompleted($a_obj_id)
105  {
106  global $ilObjDataCache;
107 
108  include_once './Services/Object/classes/class.ilObjectLP.php';
109  $olp = ilObjectLP::getInstance($a_obj_id);
110  $collection = $olp->getCollectionInstance();
111  if($collection)
112  {
113  $grouped_items = $collection->getGroupedItemsForLPStatus();
114  }
115  if(!sizeof($grouped_items))
116  {
117  // #11513 - empty collections cannot be completed
118  return array();
119  }
120  else
121  {
122  // New handling for optional assignments
123  $counter = 0;
124  $users = array();
125  foreach($grouped_items as $grouping_id => $grouping)
126  {
127  $isGrouping = $grouping_id ? true : false;
128  $grouping_completed = array();
129  $grouping_completed_users_num = array();
130  foreach((array) $grouping['items'] as $item)
131  {
132  $item_id = $ilObjDataCache->lookupObjId($item);
133  $tmp_users = ilLPStatusWrapper::_getCompleted($item_id);
134  if($isGrouping)
135  {
136  // Iterated through all grouped items and count the number of fullfiled items
137  foreach($tmp_users as $tmp_user_id)
138  {
139  ++$grouping_completed_users_num[$tmp_user_id];
140  }
141  }
142  else
143  {
144  if(!$counter++)
145  {
146  $users = $tmp_users;
147  }
148  else
149  {
150  $users = array_intersect($users,$tmp_users);
151  }
152  }
153  }
154  if($isGrouping)
155  {
156  // Iterate through all "grouping_completed_users_num"
157  // All users with completed items greater equal than "num_obligatory" are completed
158  foreach($grouping_completed_users_num as $tmp_user_id => $grouping_num_completed)
159  {
160  if($grouping_num_completed >= $grouping['num_obligatory'])
161  {
162  $grouping_completed[] = $tmp_user_id;
163  }
164  }
165 
166  // build intersection of users
167  if(!$counter++)
168  {
169  $users = $grouping_completed;
170  }
171  else
172  {
173  $users = array_intersect($users,$grouping_completed);
174  }
175  }
176  }
177  }
178 
179  $users = array_diff($users,ilLPStatusWrapper::_getFailed($a_obj_id));
180 
181  if($users)
182  {
183  // Exclude all non members
184  $users = array_intersect(self::getMembers($a_obj_id), (array)$users);
185  }
186 
187  return (array) $users;
188  }
189 
190  function _getFailed($a_obj_id)
191  {
192  global $ilObjDataCache;
193 
194  $users = array();
195 
196  include_once './Services/Object/classes/class.ilObjectLP.php';
197  $olp = ilObjectLP::getInstance($a_obj_id);
198  $collection = $olp->getCollectionInstance();
199  if($collection)
200  {
201  foreach($collection->getGroupedItemsForLPStatus() as $grouping_id => $grouping)
202  {
203  $isGrouping = $grouping_id ? true : false;
204 
205  $gr_failed = array();
206  $gr_failed_users_num = array();
207  $counter = 0;
208  foreach((array) $grouping['items'] as $item)
209  {
210  $item_id = $ilObjDataCache->lookupObjId($item);
211  $tmp_users = ilLPStatusWrapper::_getFailed($item_id);
212 
213  if($isGrouping)
214  {
215  foreach($tmp_users as $tmp_user_id)
216  {
217  ++$gr_failed_users_num[$tmp_user_id];
218  }
219  }
220  else
221  {
222  // One item failed is sufficient for status failed.
223  $gr_failed = array_merge($gr_failed,$tmp_users);
224  }
225  $counter++;
226  }
227  if($isGrouping)
228  {
229  $allowed_failed = count($grouping['items']) - $grouping['num_obligatory'];
230  // Itereate over all failed users and check whether the allowd_failed value exceeded
231  foreach($gr_failed_users_num as $tmp_user_id => $num_failed)
232  {
233  if($num_failed > $allowed_failed)
234  {
235  $gr_failed[] = $tmp_user_id;
236  }
237  }
238 
239  }
240  $users = array_unique(array_merge($users, $gr_failed));
241  }
242  }
243 
244  if($users)
245  {
246  // Exclude all non members
247  $users = array_intersect(self::getMembers($a_obj_id), (array)$users);
248  }
249 
250  return array_unique($users);
251  }
252 
253  function _getStatusInfo($a_obj_id)
254  {
255  $status_info = array();
256 
257  include_once './Services/Object/classes/class.ilObjectLP.php';
258  $olp = ilObjectLP::getInstance($a_obj_id);
259  $collection = $olp->getCollectionInstance();
260  if($collection)
261  {
262  $status_info['collections'] = $collection->getItems();
263  $status_info['num_collections'] = count($status_info['collections']);
264  }
265 
266  return $status_info;
267  }
268 
269  function _getTypicalLearningTime($a_obj_id)
270  {
271  global $ilObjDataCache;
272 
273  if($ilObjDataCache->lookupType($a_obj_id) == 'sahs')
274  {
275  return parent::_getTypicalLearningTime($a_obj_id);
276  }
277 
278  $tlt = 0;
279  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
280  foreach($status_info['collections'] as $item)
281  {
282  $tlt += ilLPStatusWrapper::_getTypicalLearningTime($ilObjDataCache->lookupObjId($item));
283  }
284  return $tlt;
285  }
286 
295  function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
296  {
297  global $ilObjDataCache;
298 
299  $status['completed'] = true;
300  $status['failed'] = false;
301  $status['in_progress'] = false;
302 
303  switch ($ilObjDataCache->lookupType($a_obj_id))
304  {
305  case "crs":
306  case "fold":
307  case "grp":
308  include_once "./Services/Tracking/classes/class.ilChangeEvent.php";
309  if (ilChangeEvent::hasAccessed($a_obj_id, $a_user_id))
310  {
311  $status['in_progress'] = true;
312  }
313 
314  include_once './Services/Object/classes/class.ilObjectLP.php';
315  $olp = ilObjectLP::getInstance($a_obj_id);
316  $collection = $olp->getCollectionInstance();
317  if($collection)
318  {
319  $grouped_items = $collection->getGroupedItemsForLPStatus();
320  }
321  if(!sizeof($grouped_items))
322  {
323  // #11513 - empty collections cannot be completed
324  $status['completed'] = false;
325  }
326  else
327  {
328  foreach($grouped_items as $grouping_id => $grouping)
329  {
330  $isGrouping = $grouping_id ? true : false;
331  $status = self::determineGroupingStatus($status,$grouping,$a_user_id,$isGrouping);
332  }
333  }
334 
335  if($status['completed'])
336  {
338  }
339  if($status['failed'])
340  {
342  }
343  if($status['in_progress'])
344  {
346  }
347  break;
348  }
350  }
351 
361  public static function determineGroupingStatus($status,$gr_info,$user_id,$is_grouping)
362  {
363  global $ilObjDataCache;
364 
365  $items = $gr_info['items'];
366  if($is_grouping)
367  {
368  $max_allowed_failed = count($items) - $gr_info['num_obligatory'];
369  $required_completed = $gr_info['num_obligatory'];
370  }
371  else
372  {
373  $max_allowed_failed = 0;
374  $required_completed = count($items);
375  }
376 
377  // Required for grouping with a number of obligatory items
378  $num_failed = 0;
379  $num_completed = 0;
380 
381  foreach($items as $item_id)
382  {
383  $item_id = $ilObjDataCache->lookupObjId($item_id);
384  $gr_status = ilLPStatusWrapper::_determineStatus($item_id, $user_id);
385 
386  if($gr_status == self::LP_STATUS_FAILED_NUM)
387  {
388  if(++$num_failed > $max_allowed_failed)
389  {
390  $status['failed'] = true;
391  $status['completed'] = false;
392  return $status;
393  }
394  }
395  if($gr_status == self::LP_STATUS_COMPLETED_NUM)
396  {
397  if(++$num_completed >= $required_completed)
398  {
399  return $status;
400  }
401  }
402  }
403  // Not completed since returned above
404  $status['completed'] = false;
405  return $status;
406  }
407 
413  protected static function getMembers($a_obj_id)
414  {
415  global $ilObjDataCache, $tree;
416 
417  switch($ilObjDataCache->lookupType($a_obj_id))
418  {
419  case 'crs':
420  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
421  $member_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
422  return $member_obj->getMembers();
423 
424  case 'grp':
425  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
426  $member_obj = ilGroupParticipants::_getInstanceByObjId($a_obj_id);
427  return $member_obj->getMembers();
428 
429  case 'fold':
430  $folder_ref_ids = ilObject::_getAllReferences($a_obj_id);
431  $folder_ref_id = current($folder_ref_ids);
432  if($crs_id = $tree->checkForParentType($folder_ref_id,'crs'))
433  {
434  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
436  return $member_obj->getMembers();
437  }
438  break;
439  }
440 
441  return array();
442  }
443 
451  public static function _lookupCompletedForObject($a_obj_id, $a_user_ids = null)
452  {
453  if(!$a_user_ids)
454  {
455  $a_user_ids = self::getMembers($a_obj_id);
456  if(!$a_user_ids)
457  {
458  return array();
459  }
460  }
461  return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_COMPLETED_NUM, $a_user_ids);
462  }
463 
471  public static function _lookupFailedForObject($a_obj_id, $a_user_ids = null)
472  {
473  if(!$a_user_ids)
474  {
475  $a_user_ids = self::getMembers($a_obj_id);
476  if(!$a_user_ids)
477  {
478  return array();
479  }
480  }
481  return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_FAILED_NUM, $a_user_ids);
482  }
483 
491  public static function _lookupInProgressForObject($a_obj_id, $a_user_ids = null)
492  {
493  if(!$a_user_ids)
494  {
495  $a_user_ids = self::getMembers($a_obj_id);
496  if(!$a_user_ids)
497  {
498  return array();
499  }
500  }
501  return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_IN_PROGRESS_NUM, $a_user_ids);
502  }
503 }
504 ?>