ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLPStatusObjectives.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 
36 {
37 
38  function ilLPStatusObjectives($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','9171_LPStatusObjectives_notAttempted');
52 
53  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
54  $members_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
55  $members = $members_obj->getParticipants();
56 
57  // diff in progress and completed (use stored result in LPStatusWrapper)
58  $users = array_diff($members,$inp = ilLPStatusWrapper::_getInProgress($a_obj_id));
59  $users = array_diff($users,$com = ilLPStatusWrapper::_getCompleted($a_obj_id));
60 
61  $ilBench->stop('LearningProgress','9171_LPStatusObjectives_notAttempted');
62  return $users ? $users : array();
63  }
64 
65  function _getInProgress($a_obj_id)
66  {
67  global $ilDB;
68 
69  $completed = ilLPStatusWrapper::_getCompleted($a_obj_id);
70 
71  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
72  $members_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
73  $members = $members_obj->getParticipants();
74 
75  include_once './Services/Tracking/classes/class.ilChangeEvent.php';
76  $all = ilChangeEvent::lookupUsersInProgress($a_obj_id);
77  foreach($all as $user_id)
78  {
79  if(!in_array($user_id,$completed) and in_array($user_id,$members))
80  {
81  $user_ids[] = $user_id;
82  }
83  }
84  return $user_ids ? $user_ids : array();
85  }
86 
87  function _getCompleted($a_obj_id)
88  {
89  global $ilDB;
90 
91  global $ilBench;
92 
93  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
94  foreach($status_info['objective_result'] as $user_id => $completed)
95  {
96  if(count($completed) == $status_info['num_objectives'])
97  {
98  $usr_ids[] = $user_id;
99  }
100  }
101  return $usr_ids ? $usr_ids : array();
102  }
103 
104 
105  function _getStatusInfo($a_obj_id)
106  {
107  include_once 'Modules/Course/classes/class.ilCourseObjective.php';
108 
109  global $ilDB;
110 
111  $status_info['objective_result'] = array();
112  $status_info['objectives'] = ilCourseObjective::_getObjectiveIds($a_obj_id);
113  $status_info['num_objectives'] = count($status_info['objectives']);
114 
115  if(!$status_info['num_objectives'])
116  {
117  return $status_info;
118  }
119  else
120  {
121  $in = $ilDB->in('objective_id',$status_info['objectives'], false,'integer');
122  }
123 
124  $query = "SELECT * FROM crs_objective_status ".
125  "WHERE ".$in;
126 
127  $res = $ilDB->query($query);
128  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
129  {
130  $status_info['completed'][$row->objective_id][] = $row->user_id;
131  $status_info['objective_result'][$row->user_id][$row->objective_id] = $row->objective_id;
132  }
133 
134  // Read title/description
135  $query = "SELECT * FROM crs_objectives ".
136  "WHERE ".$in;
137  $res = $ilDB->query($query);
138  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
139  {
140  $status_info['objective_title'][$row->objective_id] = $row->title;
141  $status_info['objective_description'][$row->objective_id] = $row->description;
142  }
143  return $status_info;
144  }
145 
154  function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
155  {
156  global $ilObjDataCache, $ilDB;
157 
158  // the status completed depends on:
159  // $status_info['num_objectives'] (ilLPStatusWrapper::_getStatusInfo($a_obj_id);)
160  // - ilCourseObjective::_getObjectiveIds($a_obj_id);
161  // - table crs_objectives manipulated in
162  // - ilCourseObjective
163 
164  // $status_info['objective_result'] (ilLPStatusWrapper::_getStatusInfo($a_obj_id);)
165  // table crs_objective_status (must not contain a dataset)
166  // ilCourseObjectiveResult -> added ilLPStatusWrapper::_updateStatus()
167 
168  $status = LP_STATUS_NOT_ATTEMPTED_NUM;
169  switch ($ilObjDataCache->lookupType($a_obj_id))
170  {
171  case "crs":
172  if (ilChangeEvent::hasAccessed($a_obj_id, $a_user_id))
173  {
174  $status = LP_STATUS_IN_PROGRESS_NUM;
175 
176  include_once 'Modules/Course/classes/class.ilCourseObjective.php';
177  $objectives = ilCourseObjective::_getObjectiveIds($a_obj_id);
178  if ($objectives)
179  {
180  $set = $ilDB->query("SELECT count(objective_id) cnt FROM crs_objective_status ".
181  "WHERE ".$ilDB->in('objective_id',$objectives, false,'integer').
182  " AND user_id = ".$ilDB->quote($a_user_id, "integer"));
183  if ($rec = $ilDB->fetchAssoc($set))
184  {
185  if ($rec["cnt"] == count($objectives))
186  {
187  $status = LP_STATUS_COMPLETED_NUM;
188  }
189  }
190  }
191  }
192  break;
193  }
194  return $status;
195  }
196 
197 }
198 
199 
200 ?>