ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLPStatusManual.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 {
37 
38  function ilLPStatusManual($a_obj_id)
39  {
40  global $ilDB;
41 
42  parent::ilLPStatus($a_obj_id);
43  $this->db =& $ilDB;
44  }
45 
46  function _getNotAttempted($a_obj_id)
47  {
48  global $ilObjDataCache;
49 
50  global $ilBench;
51  $ilBench->start('LearningProgress','9161_LPStatusManual_notAttempted');
52 
53  switch($ilObjDataCache->lookupType($a_obj_id))
54  {
55  case 'crs':
56 
57  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
58  $members_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
59  $members = $members_obj->getParticipants();
60 
61  // diff in progress and completed (use stored result in LPStatusWrapper)
62  $users = array_diff($members,$inp = ilLPStatusWrapper::_getInProgress($a_obj_id));
63  $users = array_diff($users,$com = ilLPStatusWrapper::_getCompleted($a_obj_id));
64 
65  $ilBench->stop('LearningProgress','9161_LPStatusManual_notAttempted');
66  return $users;
67 
68  case 'grp':
69 
70  include_once './Modules/Group/classes/class.ilObjGroup.php';
71 
72  $members = ilObjGroup::_getMembers($a_obj_id);
73  // diff in progress and completed (use stored result in LPStatusWrapper)
74  $users = array_diff($members,$inp = ilLPStatusWrapper::_getInProgress($a_obj_id));
75  $users = array_diff($users,$com = ilLPStatusWrapper::_getCompleted($a_obj_id));
76 
77  $ilBench->stop('LearningProgress','9161_LPStatusManual_notAttempted');
78  return $users;
79 
80  default:
81  $ilBench->stop('LearningProgress','9161_LPStatusManual_notAttempted');
82  return array();
83  }
84  }
85 
86  function _getInProgress($a_obj_id)
87  {
88  global $ilObjDataCache;
89 
90  global $ilBench;
91  $ilBench->start('LearningProgress','9162_LPStatusManual_inProgress');
92 
93 
94  switch($ilObjDataCache->lookupType($a_obj_id))
95  {
96  case 'lm':
97  case 'htlm':
98  $ilBench->stop('LearningProgress','9162_LPStatusManual_inProgress');
99  return ilLPStatusManual::__getLMInProgress($a_obj_id);
100 
101  case 'crs':
102  $ilBench->stop('LearningProgress','9162_LPStatusManual_inProgress');
103  return ilLPStatusManual::__getCourseInProgress($a_obj_id);
104 
105  case 'grp':
106  $ilBench->stop('LearningProgress','9162_LPStatusManual_inProgress');
107  return ilLPStatusManual::__getGroupInProgress($a_obj_id);
108 
109  default:
110  $ilBench->stop('LearningProgress','9162_LPStatusManual_inProgress');
111  echo "ilLPStatusManual: unknown type ".$ilObjDataCache->lookupType($a_obj_id);
112 
113  }
114  return array();
115  }
116 
117  function _getCompleted($a_obj_id)
118  {
119  global $ilDB;
120 
121  global $ilBench;
122  $ilBench->start('LearningProgress','9163_LPStatusManual_completed');
123 
124  $query = "SELECT DISTINCT(usr_id) as user_id FROM ut_lp_marks ".
125  "WHERE obj_id = '".$a_obj_id."' ".
126  "AND completed = '1'";
127 
128  $res = $ilDB->query($query);
129  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
130  {
131  $usr_ids[] = $row->user_id;
132  }
133  $ilBench->stop('LearningProgress','9163_LPStatusManual_completed');
134  return $usr_ids ? $usr_ids : array();
135  }
136 
137  // Private
138  function __getLMInProgress($a_obj_id)
139  {
140  global $ilDB;
141 
142  $completed = ilLPStatusWrapper::_getCompleted($a_obj_id);
143  $query = "SELECT DISTINCT(usr_id) FROM read_event ".
144  "WHERE obj_id = '".$a_obj_id."'";
145 
146  $res = $ilDB->query($query);
147  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
148  {
149  if(!in_array($row->usr_id,$completed))
150  {
151  $user_ids[] = $row->usr_id;
152  }
153  }
154  return $user_ids ? $user_ids : array();
155  }
156 
157  function __getCourseInProgress($a_obj_id)
158  {
159  global $ilDB;
160 
161  $completed = ilLPStatusWrapper::_getCompleted($a_obj_id);
162 
163  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
164  $members_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
165  $members = $members_obj->getParticipants();
166 
167  $query = "SELECT DISTINCT(usr_id) FROM read_event ".
168  "WHERE obj_id = '".$a_obj_id."'";
169 
170  $res = $ilDB->query($query);
171  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
172  {
173  if(!in_array($row->usr_id,$completed) and in_array($row->usr_id,$members))
174  {
175  $user_ids[] = $row->usr_id;
176  }
177  }
178  return $user_ids ? $user_ids : array();
179  }
180 
181  function __getGroupInProgress($a_obj_id)
182  {
183  global $ilDB;
184 
185  $completed = ilLPStatusWrapper::_getCompleted($a_obj_id);
186 
187  include_once './Modules/Group/classes/class.ilObjGroup.php';
188  $members = ilObjGroup::_getMembers($a_obj_id);
189 
190  $query = "SELECT DISTINCT(usr_id) FROM read_event ".
191  "WHERE obj_id = '".$a_obj_id."'";
192 
193  $res = $ilDB->query($query);
194  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
195  {
196  if(!in_array($row->user_id,$completed) and in_array($row->user_id,$members))
197  {
198  $user_ids[] = $row->user_id;
199  }
200  }
201  return $user_ids ? $user_ids : array();
202  }
203 }
204 ?>