ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLPStatusManual.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Services/Tracking/classes/class.ilLPStatus.php';
5 
15 {
16 
17  function ilLPStatusManual($a_obj_id)
18  {
19  global $ilDB;
20 
21  parent::ilLPStatus($a_obj_id);
22  $this->db =& $ilDB;
23  }
24 
25  function _getNotAttempted($a_obj_id)
26  {
27  global $ilObjDataCache;
28 
29  global $ilBench;
30  $ilBench->start('LearningProgress','9161_LPStatusManual_notAttempted');
31 
32  switch($ilObjDataCache->lookupType($a_obj_id))
33  {
34  case 'crs':
35 
36  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
37  $members_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
38  $members = $members_obj->getMembers();
39 
40  // diff in progress and completed (use stored result in LPStatusWrapper)
41  $users = array_diff($members,$inp = ilLPStatusWrapper::_getInProgress($a_obj_id));
42  $users = array_diff($users,$com = ilLPStatusWrapper::_getCompleted($a_obj_id));
43 
44  $ilBench->stop('LearningProgress','9161_LPStatusManual_notAttempted');
45  return $users;
46 
47  case 'grp':
48 
49  include_once './Modules/Group/classes/class.ilObjGroup.php';
50 
51  $members = ilObjGroup::_getMembers($a_obj_id);
52  // diff in progress and completed (use stored result in LPStatusWrapper)
53  $users = array_diff($members,$inp = ilLPStatusWrapper::_getInProgress($a_obj_id));
54  $users = array_diff($users,$com = ilLPStatusWrapper::_getCompleted($a_obj_id));
55 
56  $ilBench->stop('LearningProgress','9161_LPStatusManual_notAttempted');
57  return $users;
58 
59  default:
60  $ilBench->stop('LearningProgress','9161_LPStatusManual_notAttempted');
61  return array();
62  }
63  }
64 
65  function _getInProgress($a_obj_id)
66  {
67  global $ilObjDataCache;
68 
69  global $ilBench;
70  $ilBench->start('LearningProgress','9162_LPStatusManual_inProgress');
71 
72 
73  switch($ilObjDataCache->lookupType($a_obj_id))
74  {
75  case 'dbk':
76  case 'lm':
77  case 'htlm':
78  $ilBench->stop('LearningProgress','9162_LPStatusManual_inProgress');
79  return ilLPStatusManual::__getLMInProgress($a_obj_id);
80 
81  case 'crs':
82  $ilBench->stop('LearningProgress','9162_LPStatusManual_inProgress');
84 
85  case 'grp':
86  $ilBench->stop('LearningProgress','9162_LPStatusManual_inProgress');
88 
89  default:
90  $ilBench->stop('LearningProgress','9162_LPStatusManual_inProgress');
91  echo "ilLPStatusManual: unknown type ".$ilObjDataCache->lookupType($a_obj_id);
92 
93  }
94  return array();
95  }
96 
97  function _getCompleted($a_obj_id)
98  {
99  global $ilDB;
100 
101  global $ilBench;
102  $ilBench->start('LearningProgress','9163_LPStatusManual_completed');
103 
104  $query = "SELECT DISTINCT(usr_id) user_id FROM ut_lp_marks ".
105  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
106  "AND completed = '1' ";
107 
108  $res = $ilDB->query($query);
109  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
110  {
111  $usr_ids[] = $row->user_id;
112  }
113  $ilBench->stop('LearningProgress','9163_LPStatusManual_completed');
114  return $usr_ids ? $usr_ids : array();
115  }
116 
117  // Private
118  function __getLMInProgress($a_obj_id)
119  {
120  global $ilDB;
121 
122  $completed = ilLPStatusWrapper::_getCompleted($a_obj_id);
123 
124  include_once './Services/Tracking/classes/class.ilChangeEvent.php';
125  $all = ilChangeEvent::lookupUsersInProgress($a_obj_id);
126  foreach($all as $user_id)
127  {
128  if(!in_array($user_id,$completed))
129  {
130  $user_ids[] = $user_id;
131  }
132  }
133  return $user_ids ? $user_ids : array();
134  }
135 
136  function __getCourseInProgress($a_obj_id)
137  {
138  global $ilDB;
139 
140  $completed = ilLPStatusWrapper::_getCompleted($a_obj_id);
141 
142  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
143  $members_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
144  $members = $members_obj->getMembers();
145 
146  include_once './Services/Tracking/classes/class.ilChangeEvent.php';
147  $all = ilChangeEvent::lookupUsersInProgress($a_obj_id);
148  foreach($all as $user_id)
149  {
150  if(!in_array($user_id,$completed) and in_array($user_id,$members))
151  {
152  $user_ids[] = $user_id;
153  }
154  }
155  return $user_ids ? $user_ids : array();
156  }
157 
158  function __getGroupInProgress($a_obj_id)
159  {
160  global $ilDB;
161 
162  $completed = ilLPStatusWrapper::_getCompleted($a_obj_id);
163 
164  include_once './Modules/Group/classes/class.ilObjGroup.php';
165  $members = ilObjGroup::_getMembers($a_obj_id);
166 
167  include_once './Services/Tracking/classes/class.ilChangeEvent.php';
168  $all = ilChangeEvent::lookupUsersInProgress($a_obj_id);
169  foreach($all as $user_id)
170  {
171  if(!in_array($user_id,$completed) and in_array($user_id,$members))
172  {
173  $user_ids[] = $user_id;
174  }
175  }
176  return $user_ids ? $user_ids : array();
177  }
178 
187  function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
188  {
189  global $ilObjDataCache, $ilDB;
190 
191  $status = LP_STATUS_NOT_ATTEMPTED_NUM;
192  switch ($ilObjDataCache->lookupType($a_obj_id))
193  {
194  case 'dbk':
195  case 'lm':
196  case 'htlm':
197  include_once("./Services/Tracking/classes/class.ilChangeEvent.php");
198  if (ilChangeEvent::hasAccessed($a_obj_id, $a_user_id))
199  {
200  $status = LP_STATUS_IN_PROGRESS_NUM;
201 
202  // completed?
203  $set = $ilDB->query($q = "SELECT usr_id FROM ut_lp_marks ".
204  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
205  "AND usr_id = ".$ilDB->quote($a_user_id ,'integer')." ".
206  "AND completed = '1' ");
207  if ($rec = $ilDB->fetchAssoc($set))
208  {
209  $status = LP_STATUS_COMPLETED_NUM;
210  }
211  }
212  break;
213  }
214  return $status;
215  }
216 }
217 ?>