ILIAS  Release_4_2_x_branch Revision 61807
 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  global $ilObjDataCache,$tree;
50 
51  switch($ilObjDataCache->lookupType($a_obj_id))
52  {
53  case 'crs':
54  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
55  $member_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
56  $members = $member_obj->getMembers();
57 
58  // diff in progress and completed (use stored result in LPStatusWrapper)
59  $users = array_diff((array) $members, ilLPStatusWrapper::_getInProgress($a_obj_id));
60  $users = array_diff((array) $users, ilLPStatusWrapper::_getCompleted($a_obj_id));
61  $users = array_diff((array) $users, ilLPStatusWrapper::_getFailed($a_obj_id));
62  return $users;
63 
64  case 'grp':
65  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
66  $member_obj = ilGroupParticipants::_getInstanceByObjId($a_obj_id);
67  $members = $member_obj->getMembers();
68 
69  // diff in progress and completed (use stored result in LPStatusWrapper)
70  $users = array_diff((array) $members, ilLPStatusWrapper::_getInProgress($a_obj_id));
71  $users = array_diff((array) $users, ilLPStatusWrapper::_getCompleted($a_obj_id));
72  $users = array_diff((array) $users, ilLPStatusWrapper::_getFailed($a_obj_id));
73  return $users;
74 
75  case 'fold':
76  $folder_ref_ids = ilObject::_getAllReferences($a_obj_id);
77  $folder_ref_id = current($folder_ref_ids);
78  if($crs_id = $tree->checkForParentType($folder_ref_id,'crs'))
79  {
80  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
82  $members = $member_obj->getMembers();
83 
84  // diff in progress and completed (use stored result in LPStatusWrapper)
85  $users = array_diff((array) $members,ilLPStatusWrapper::_getInProgress($a_obj_id));
86  $users = array_diff((array) $users, ilLPStatusWrapper::_getCompleted($a_obj_id));
87  $users = array_diff((array) $users, ilLPStatusWrapper::_getFailed($a_obj_id));
88  return $users;
89  }
90  // fallthrough
91 
92  default:
93  return array();
94  }
95  }
96 
97  function _getInProgress($a_obj_id)
98  {
99  global $tree;
100 
101  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
102 
103  global $ilBench,$ilObjDataCache;
104  $ilBench->start('LearningProgress','9172_LPStatusCollection_inProgress');
105 
106  $in_progress = 0;
107 
108  include_once './Services/Tracking/classes/class.ilChangeEvent.php';
109  $users = ilChangeEvent::lookupUsersInProgress($a_obj_id);
110  foreach(ilLPCollectionCache::_getItems($a_obj_id, true) as $item_id)
111  {
112  $item_id = $ilObjDataCache->lookupObjId($item_id);
113 
114  // merge arrays of users with status 'in progress'
115  $users = array_unique(array_merge((array) $users,ilLPStatusWrapper::_getInProgress($item_id)));
116  $users = array_unique(array_merge((array) $users,ilLPStatusWrapper::_getCompleted($item_id)));
117  }
118 
119  // Exclude all users with status completed.
120  $users = array_diff((array) $users,ilLPStatusWrapper::_getCompleted($a_obj_id));
121  // Exclude all users with status failed.
122  $users = array_diff((array) $users,ilLPStatusWrapper::_getFailed($a_obj_id));
123 
124  switch($ilObjDataCache->lookupType($a_obj_id))
125  {
126  case 'crs':
127  // Exclude all non members
128  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
129  $members_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
130  $members = $members_obj->getMembers();
131  $users = array_intersect($members,(array) $users);
132  break;
133 
134  case 'grp':
135  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
136  $member_obj = ilGroupParticipants::_getInstanceByObjId($a_obj_id);
137  $members = $member_obj->getMembers();
138  $users = array_intersect($members,(array) $users);
139  break;
140 
141  case 'fold':
142  $folder_ref_ids = ilObject::_getAllReferences($a_obj_id);
143  $folder_ref_id = current($folder_ref_ids);
144  if($crs_id = $tree->checkForParentType($folder_ref_id,'crs'))
145  {
146  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
148  $members = $members_obj->getMembers();
149  $users = array_intersect($members,(array) $users);
150  }
151  break;
152  }
153 
154  $ilBench->stop('LearningProgress','9172_LPStatusCollection_inProgress');
155  return $users;
156  }
157 
167  function _getCompleted($a_obj_id)
168  {
169  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
170 
171  global $ilBench,$ilObjDataCache,$tree;
172  $ilBench->start('LearningProgress','9173_LPStatusCollection_completed');
173 
174  // New handling for optional assignments
175  $counter = 0;
176  $users = array();
177  foreach(ilLPCollectionCache::getGroupedItems($a_obj_id, true) as $grouping_id => $grouping)
178  {
179  $isGrouping = $grouping_id ? true : false;
180  $grouping_completed = array();
181  $grouping_completed_users_num = array();
182  foreach((array) $grouping['items'] as $item)
183  {
184  $item_id = $ilObjDataCache->lookupObjId($item);
185  $tmp_users = ilLPStatusWrapper::_getCompleted($item_id);
186  if($isGrouping)
187  {
188  // Iterated through all grouped items and count the number of fullfiled items
189  foreach($tmp_users as $tmp_user_id)
190  {
191  ++$grouping_completed_users_num[$tmp_user_id];
192  }
193  }
194  else
195  {
196  if(!$counter++)
197  {
198  $users = $tmp_users;
199  }
200  else
201  {
202  $users = array_intersect($users,$tmp_users);
203  }
204  }
205  }
206  if($isGrouping)
207  {
208  // Iterate through all "grouping_completed_users_num"
209  // All users with completed items greater equal than "num_obligatory" are completed
210  foreach($grouping_completed_users_num as $tmp_user_id => $grouping_num_completed)
211  {
212  if($grouping_num_completed >= $grouping['num_obligatory'])
213  {
214  $grouping_completed[] = $tmp_user_id;
215  }
216  }
217 
218  // build intersection of users
219  if(!$counter++)
220  {
221  $users = $grouping_completed;
222  }
223  else
224  {
225  $users = array_intersect($users,$grouping_completed);
226  }
227  }
228  }
229 
230  switch($ilObjDataCache->lookupType($a_obj_id))
231  {
232  case 'crs':
233  // Exclude all non members
234  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
235  $member_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
236  $users = array_intersect($member_obj->getMembers(),(array) $users);
237  break;
238 
239  case 'grp':
240  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
241  $member_obj = ilGroupParticipants::_getInstanceByObjId($a_obj_id);
242  $members = $member_obj->getMembers();
243  $users = array_intersect($members,(array) $users);
244  break;
245 
246  case 'fold':
247  $folder_ref_ids = ilObject::_getAllReferences($a_obj_id);
248  $folder_ref_id = current($folder_ref_ids);
249  if($crs_id = $tree->checkForParentType($folder_ref_id,'crs'))
250  {
251  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
253  $users = array_intersect($members_obj->getMembers(),(array) $users);
254  }
255  break;
256 
257  }
258  $users = array_diff($users,ilLPStatusWrapper::_getFailed($a_obj_id));
259  $ilBench->stop('LearningProgress','9173_LPStatusCollection_completed');
260  return (array) $users;
261  }
262 
263  function _getFailed($a_obj_id)
264  {
265  global $ilObjDataCache,$tree;
266 
267  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
268 
269  $users = array();
270  foreach(ilLPCollectionCache::getGroupedItems($a_obj_id, true) as $grouping_id => $grouping)
271  {
272  $isGrouping = $grouping_id ? true : false;
273 
274  $gr_failed = array();
275  $gr_failed_users_num = array();
276  $counter = 0;
277  foreach((array) $grouping['items'] as $item)
278  {
279  $item_id = $ilObjDataCache->lookupObjId($item);
280  $tmp_users = ilLPStatusWrapper::_getFailed($item_id);
281 
282  if($isGrouping)
283  {
284  foreach($tmp_users as $tmp_user_id)
285  {
286  ++$gr_failed_users_num[$tmp_user_id];
287  }
288  }
289  else
290  {
291  // One item failed is sufficient for status failed.
292  $gr_failed = array_merge($gr_failed,$tmp_users);
293  }
294  $counter++;
295  }
296  if($isGrouping)
297  {
298  $allowed_failed = count($grouping['items']) - $grouping['num_obligatory'];
299  // Itereate over all failed users and check whether the allowd_failed value exceeded
300  foreach($gr_failed_users_num as $tmp_user_id => $num_failed)
301  {
302  if($num_failed > $allowed_failed)
303  {
304  $gr_failed[] = $tmp_user_id;
305  }
306  }
307 
308  }
309  $users = array_unique(array_merge($users, $gr_failed));
310  }
311 
312 
313  switch($ilObjDataCache->lookupType($a_obj_id))
314  {
315  case 'crs':
316  // Exclude all non members
317  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
318  $members_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
319  $members = $members_obj->getMembers();
320  $users = array_intersect($members,(array) $users);
321  break;
322 
323  case 'grp':
324  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
325  $member_obj = ilGroupParticipants::_getInstanceByObjId($a_obj_id);
326  $members = $member_obj->getMembers();
327  $users = array_intersect($members,(array) $users);
328  break;
329 
330  case 'fold':
331  $folder_ref_ids = ilObject::_getAllReferences($a_obj_id);
332  $folder_ref_id = current($folder_ref_ids);
333  if($crs_id = $tree->checkForParentType($folder_ref_id,'crs'))
334  {
336  $members = $members_obj->getMembers();
337  $users = array_intersect($members,(array) $users);
338  }
339  break;
340  }
341 
342  return array_unique($users);
343  }
344 
345 
346  function _getStatusInfo($a_obj_id)
347  {
348  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
349 
350  $status_info['collections'] = ilLPCollectionCache::_getItems($a_obj_id);
351  $status_info['num_collections'] = count($status_info['collections']);
352  return $status_info;
353  }
354 
355  function _getTypicalLearningTime($a_obj_id)
356  {
357  global $ilObjDataCache;
358 
359  if($ilObjDataCache->lookupType($a_obj_id) == 'sahs')
360  {
361  return parent::_getTypicalLearningTime($a_obj_id);
362  }
363 
364  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
365  foreach($status_info['collections'] as $item)
366  {
367  $tlt += ilLPStatusWrapper::_getTypicalLearningTime($ilObjDataCache->lookupObjId($item));
368  }
369  return $tlt;
370  }
371 
380  function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
381  {
382  global $ilObjDataCache, $ilDB;
383 
384  $status['completed'] = true;
385  $status['failed'] = false;
386  $status['in_progress'] = false;
387  $status['not_attempted'] = true;
388 
389  switch ($ilObjDataCache->lookupType($a_obj_id))
390  {
391  case "crs":
392  case "fold":
393  case "grp":
394  include_once "./Services/Tracking/classes/class.ilChangeEvent.php";
395  if (ilChangeEvent::hasAccessed($a_obj_id, $a_user_id))
396  {
397  $status['in_progress'] = true;
398  }
399 
400  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
401  foreach(ilLPCollectionCache::getGroupedItems($a_obj_id, true) as $grouping_id => $grouping)
402  {
403  $isGrouping = $grouping_id ? true : false;
404  $status = self::determineGroupingStatus($status,$grouping,$a_user_id,$isGrouping);
405  }
406  if($status['completed'])
407  {
409  }
410  if($status['failed'])
411  {
412  return LP_STATUS_FAILED_NUM;
413  }
414  if($status['in_progress'])
415  {
417  }
419  }
421  }
422 
432  public static function determineGroupingStatus($status,$gr_info,$user_id,$is_grouping)
433  {
434  global $ilObjDataCache;
435 
436  $items = $gr_info['items'];
437  if($is_grouping)
438  {
439  $max_allowed_failed = count($items) - $gr_info['num_obligatory'];
440  $required_completed = $gr_info['num_obligatory'];
441  }
442  else
443  {
444  $max_allowed_failed = 0;
445  $required_completed = count($items);
446  }
447 
448  // Required for grouping with a number of obligatory items
449  $num_failed = 0;
450  $num_completed = 0;
451 
452  include_once("./Services/Tracking/classes/class.ilLPCollectionCache.php");
453  foreach($items as $item_id)
454  {
455  $item_id = $ilObjDataCache->lookupObjId($item_id);
456  $gr_status = ilLPStatusWrapper::_determineStatus($item_id, $user_id);
457 
458  if($gr_status == LP_STATUS_FAILED_NUM)
459  {
460  if(++$failed > $max_allowed_failed)
461  {
462  $status['failed'] = true;
463  $status['completed'] = false;
464  return $status;
465  }
466  }
467  if($gr_status == LP_STATUS_COMPLETED_NUM)
468  {
469  if(++$num_completed >= $required_completed)
470  {
471  return $status;
472  }
473  }
474  }
475  // Not completed since returned above
476  $status['completed'] = false;
477  return $status;
478  }
479 }
480 ?>