ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLPStatusManualByTutor.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 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 
36 {
44  function __construct($a_obj_id)
45  {
46  global $ilDB;
47 
48  parent::ilLPStatus($a_obj_id);
49  $this->db = $ilDB;
50  }
51 
60  public function _getNotAttempted($a_obj_id)
61  {
62  global $ilObjDataCache;
63 
64  global $ilBench;
65  $ilBench->start('LearningProgress','9161_LPStatusManual_notAttempted');
66 
67  switch($ilObjDataCache->lookupType($a_obj_id))
68  {
69  case 'crs':
70 
71  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
72  $members_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
73  $members = $members_obj->getMembers();
74 
75  // diff in progress and completed (use stored result in LPStatusWrapper)
76  $users = array_diff($members,$inp = ilLPStatusWrapper::_getInProgress($a_obj_id));
77  $users = array_diff($users,$com = ilLPStatusWrapper::_getCompleted($a_obj_id));
78 
79  $ilBench->stop('LearningProgress','9161_LPStatusManual_notAttempted');
80  return $users;
81 
82  case 'grp':
83 
84  include_once './Modules/Group/classes/class.ilObjGroup.php';
85 
86  $members = ilObjGroup::_getMembers($a_obj_id);
87  // diff in progress and completed (use stored result in LPStatusWrapper)
88  $users = array_diff($members,$inp = ilLPStatusWrapper::_getInProgress($a_obj_id));
89  $users = array_diff($users,$com = ilLPStatusWrapper::_getCompleted($a_obj_id));
90 
91  $ilBench->stop('LearningProgress','9161_LPStatusManual_notAttempted');
92  return $users;
93 
94  default:
95  $ilBench->stop('LearningProgress','9161_LPStatusManual_notAttempted');
96  return array();
97  }
98  }
99 
108  public function _getInProgress($a_obj_id)
109  {
110  global $ilObjDataCache;
111 
112  global $ilBench;
113  $ilBench->start('LearningProgress','9162_LPStatusManualByTutor_inProgress');
114 
115 
116  switch($ilObjDataCache->lookupType($a_obj_id))
117  {
118  case 'crs':
119  $ilBench->stop('LearningProgress','9162_LPStatusManualByTutor_inProgress');
120  return self::__getCourseInProgress($a_obj_id);
121 
122  case 'grp':
123  $ilBench->stop('LearningProgress','9162_LPStatusManualByTutor_inProgress');
124  return self::__getGroupInProgress($a_obj_id);
125 
126  default:
127  $ilBench->stop('LearningProgress','9162_LPStatusManualByTutor_inProgress');
128  break;
129  }
130  return array();
131 
132  }
133 
134 
135  function __getCourseInProgress($a_obj_id)
136  {
137  global $ilDB;
138 
139  $completed = ilLPStatusWrapper::_getCompleted($a_obj_id);
140 
141  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
142  $members_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
143  $members = $members_obj->getMembers();
144 
145  include_once './Services/Tracking/classes/class.ilChangeEvent.php';
146  $all = ilChangeEvent::lookupUsersInProgress($a_obj_id);
147  foreach($all as $user_id)
148  {
149  if(!in_array($user_id,$completed) and in_array($user_id,$members))
150  {
151  $user_ids[] = $user_id;
152  }
153  }
154  return $user_ids ? $user_ids : array();
155  }
156 
157  function __getGroupInProgress($a_obj_id)
158  {
159  global $ilDB;
160 
161  $completed = ilLPStatusWrapper::_getCompleted($a_obj_id);
162 
163  include_once './Modules/Group/classes/class.ilObjGroup.php';
164  $members = ilObjGroup::_getMembers($a_obj_id);
165 
166  include_once './Services/Tracking/classes/class.ilChangeEvent.php';
167  $all = ilChangeEvent::lookupUsersInProgress($a_obj_id);
168  foreach($all as $user_id)
169  {
170  if(!in_array($user_id,$completed) and in_array($user_id,$members))
171  {
172  $user_ids[] = $user_id;
173  }
174  }
175  return $user_ids ? $user_ids : array();
176  }
177 
178  function _getCompleted($a_obj_id)
179  {
180  global $ilDB;
181 
182  global $ilBench;
183  $ilBench->start('LearningProgress','9163_LPStatusManualByTutor_completed');
184 
185  $query = "SELECT DISTINCT(usr_id) user_id FROM ut_lp_marks ".
186  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
187  "AND completed = '1' ";
188 
189  $res = $ilDB->query($query);
190  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
191  {
192  $usr_ids[] = $row->user_id;
193  }
194  $ilBench->stop('LearningProgress','9163_LPStatusManualByTutor_completed');
195  return $usr_ids ? $usr_ids : array();
196  }
197 
206  function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
207  {
208  global $ilObjDataCache, $ilDB;
209 
210  $status = LP_STATUS_NOT_ATTEMPTED_NUM;
211  switch ($ilObjDataCache->lookupType($a_obj_id))
212  {
213  case "crs":
214  case "grp":
215  // completed?
216  $set = $ilDB->query($q = "SELECT usr_id FROM ut_lp_marks ".
217  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
218  "AND usr_id = ".$ilDB->quote($a_user_id ,'integer')." ".
219  "AND completed = '1' ");
220  if ($rec = $ilDB->fetchAssoc($set))
221  {
222  $status = LP_STATUS_COMPLETED_NUM;
223  }
224  else
225  {
226  include_once './Services/Tracking/classes/class.ilChangeEvent.php';
227  if (ilChangeEvent::hasAccessed($a_obj_id, $a_user_id))
228  {
229  $status = LP_STATUS_IN_PROGRESS_NUM;
230  }
231  }
232  break;
233  }
234  return $status;
235  }
236 
237 }
238 ?>