ILIAS  Release_4_1_x_branch Revision 61804
 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.ilObjGroup.php';
66  $members = ilObjGroup::_getMembers($a_obj_id);
67 
68  // diff in progress and completed (use stored result in LPStatusWrapper)
69  $users = array_diff((array) $members, ilLPStatusWrapper::_getInProgress($a_obj_id));
70  $users = array_diff((array) $users, ilLPStatusWrapper::_getCompleted($a_obj_id));
71  $users = array_diff((array) $users, ilLPStatusWrapper::_getFailed($a_obj_id));
72  return $users;
73 
74  case 'fold':
75  $folder_ref_ids = ilObject::_getAllReferences($a_obj_id);
76  $folder_ref_id = current($folder_ref_ids);
77  if($crs_id = $tree->checkForParentType($folder_ref_id,'crs'))
78  {
79  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
81  $members = $member_obj->getMembers();
82 
83  // diff in progress and completed (use stored result in LPStatusWrapper)
84  $users = array_diff((array) $members,ilLPStatusWrapper::_getInProgress($a_obj_id));
85  $users = array_diff((array) $users, ilLPStatusWrapper::_getCompleted($a_obj_id));
86  $users = array_diff((array) $users, ilLPStatusWrapper::_getFailed($a_obj_id));
87  return $users;
88  }
89  // fallthrough
90 
91  default:
92  return array();
93  }
94  }
95 
96  function _getInProgress($a_obj_id)
97  {
98  global $tree;
99 
100  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
101 
102  global $ilBench,$ilObjDataCache;
103  $ilBench->start('LearningProgress','9172_LPStatusCollection_inProgress');
104 
105  $in_progress = 0;
106  foreach(ilLPCollectionCache::_getItems($a_obj_id, true) as $item_id)
107  {
108  $item_id = $ilObjDataCache->lookupObjId($item_id);
109 
110  // merge arrays of users with status 'in progress'
111  $users = array_unique(array_merge((array) $users,ilLPStatusWrapper::_getInProgress($item_id)));
112  $users = array_unique(array_merge((array) $users,ilLPStatusWrapper::_getCompleted($item_id)));
113  }
114 
115  // Exclude all users with status completed.
116  $users = array_diff((array) $users,ilLPStatusWrapper::_getCompleted($a_obj_id));
117  // Exclude all users with status failed.
118  $users = array_diff((array) $users,ilLPStatusWrapper::_getFailed($a_obj_id));
119 
120  switch($ilObjDataCache->lookupType($a_obj_id))
121  {
122  case 'crs':
123  // Exclude all non members
124  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
125  $members_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
126  $members = $members_obj->getMembers();
127  $users = array_intersect($members,(array) $users);
128  break;
129 
130  case 'grp':
131  include_once './Modules/Group/classes/class.ilObjGroup.php';
132  $members = ilObjGroup::_getMembers($a_obj_id);
133  $users = array_intersect($members,(array) $users);
134  break;
135 
136  case 'fold':
137  $folder_ref_ids = ilObject::_getAllReferences($a_obj_id);
138  $folder_ref_id = current($folder_ref_ids);
139  if($crs_id = $tree->checkForParentType($folder_ref_id,'crs'))
140  {
141  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
143  $members = $members_obj->getMembers();
144  $users = array_intersect($members,(array) $users);
145  }
146  break;
147  }
148 
149  $ilBench->stop('LearningProgress','9172_LPStatusCollection_inProgress');
150  return $users;
151  }
152 
153  function _getCompleted($a_obj_id)
154  {
155  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
156 
157  global $ilBench,$ilObjDataCache,$tree;
158  $ilBench->start('LearningProgress','9173_LPStatusCollection_completed');
159 
160  $counter = 0;
161  $users = array();
162  foreach(ilLPCollectionCache::_getItems($a_obj_id, true) as $item_id)
163  {
164  $item_id = $ilObjDataCache->lookupObjId($item_id);
165 
166  $tmp_users = ilLPStatusWrapper::_getCompleted($item_id);
167  if(!$counter++)
168  {
169  $users = $tmp_users;
170  }
171  else
172  {
173  $users = array_intersect($users,$tmp_users);
174  }
175 
176  }
177 
178  switch($ilObjDataCache->lookupType($a_obj_id))
179  {
180  case 'crs':
181  // Exclude all non members
182  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
183  $member_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
184  $users = array_intersect($member_obj->getMembers(),(array) $users);
185  break;
186 
187  case 'grp':
188  include_once './Modules/Group/classes/class.ilObjGroup.php';
189  $members = ilObjGroup::_getMembers($a_obj_id);
190  $users = array_intersect($members,(array) $users);
191  break;
192 
193  case 'fold':
194  $folder_ref_ids = ilObject::_getAllReferences($a_obj_id);
195  $folder_ref_id = current($folder_ref_ids);
196  if($crs_id = $tree->checkForParentType($folder_ref_id,'crs'))
197  {
198  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
200  $users = array_intersect($members_obj->getMembers(),(array) $users);
201  }
202  break;
203 
204  }
205  $users = array_diff($users,ilLPStatusWrapper::_getFailed($a_obj_id));
206  $ilBench->stop('LearningProgress','9173_LPStatusCollection_completed');
207  return (array) $users;
208  }
209 
210  function _getFailed($a_obj_id)
211  {
212  global $ilObjDataCache,$tree;
213 
214  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
215 
216  $users = array();
217  foreach(ilLPCollectionCache::_getItems($a_obj_id, true) as $item_id)
218  {
219  $item_id = $ilObjDataCache->lookupObjId($item_id);
220  $tmp_users = ilLPStatusWrapper::_getFailed($item_id);
221  $users = array_merge($users,$tmp_users);
222  }
223 
224  switch($ilObjDataCache->lookupType($a_obj_id))
225  {
226  case 'crs':
227  // Exclude all non members
228  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
229  $members_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
230  $members = $members_obj->getMembers();
231 
232  $users = array_intersect($members,(array) $users);
233  break;
234 
235  case 'grp':
236  include_once './Modules/Group/classes/class.ilObjGroup.php';
237  $members = ilObjGroup::_getMembers($a_obj_id);
238  $users = array_intersect($members,(array) $users);
239  break;
240 
241  case 'fold':
242  $folder_ref_ids = ilObject::_getAllReferences($a_obj_id);
243  $folder_ref_id = current($folder_ref_ids);
244  if($crs_id = $tree->checkForParentType($folder_ref_id,'crs'))
245  {
247  $members = $members_obj->getMembers();
248  $users = array_intersect($members,(array) $users);
249  }
250  break;
251  }
252 
253  return array_unique($users);
254  }
255 
256 
257  function _getStatusInfo($a_obj_id)
258  {
259  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
260 
261  $status_info['collections'] = ilLPCollectionCache::_getItems($a_obj_id);
262  $status_info['num_collections'] = count($status_info['collections']);
263  return $status_info;
264  }
265 
266  function _getTypicalLearningTime($a_obj_id)
267  {
268  global $ilObjDataCache;
269 
270  if($ilObjDataCache->lookupType($a_obj_id) == 'sahs')
271  {
272  return parent::_getTypicalLearningTime($a_obj_id);
273  }
274 
275  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
276  foreach($status_info['collections'] as $item)
277  {
278  $tlt += ilLPStatusWrapper::_getTypicalLearningTime($ilObjDataCache->lookupObjId($item));
279  }
280  return $tlt;
281  }
282 
291  function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
292  {
293  global $ilObjDataCache, $ilDB;
294 
295  $status = LP_STATUS_NOT_ATTEMPTED_NUM;
296  switch ($ilObjDataCache->lookupType($a_obj_id))
297  {
298  case "crs":
299  case "fold":
300  case "grp":
301  include_once "./Services/Tracking/classes/class.ilChangeEvent.php";
302  if (ilChangeEvent::hasAccessed($a_obj_id, $a_user_id))
303  {
304  $status = LP_STATUS_IN_PROGRESS_NUM;
305  }
306 
307  $completed = true;
308  $failed = false;
309  include_once("./Services/Tracking/classes/class.ilLPCollectionCache.php");
310  foreach(ilLPCollectionCache::_getItems($a_obj_id, true) as $item_id)
311  {
312  $item_id = $ilObjDataCache->lookupObjId($item_id);
313  $st2 = ilLPStatusWrapper::_determineStatus($item_id, $a_user_id);
314  if ($st2
316  {
317  $completed = false;
318  }
319  if ($st2
321  {
322  $status = LP_STATUS_IN_PROGRESS_NUM;
323  }
324  if ($st2
326  {
327  $failed = true;
328  }
329  }
330  if ($failed)
331  {
332  $status = LP_STATUS_FAILED_NUM;
333  }
334  else if ($completed)
335  {
336  $status = LP_STATUS_COMPLETED_NUM;
337  }
338 
339  break;
340  }
341 
342  return $status;
343  }
344 
345 }
346 ?>