ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLPStatusObjectives.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once 'Services/Tracking/classes/class.ilLPStatus.php';
6 
7 
17 {
18 
19  function ilLPStatusObjectives($a_obj_id)
20  {
21  global $ilDB;
22 
23  parent::ilLPStatus($a_obj_id);
24  $this->db =& $ilDB;
25  }
26 
27  function _getNotAttempted($a_obj_id)
28  {
29  global $ilObjDataCache;
30 
31  global $ilBench;
32  $ilBench->start('LearningProgress','9171_LPStatusObjectives_notAttempted');
33 
34  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
35  $members_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
36  $members = $members_obj->getParticipants();
37 
38  // diff in progress and completed (use stored result in LPStatusWrapper)
39  $users = array_diff($members,$inp = ilLPStatusWrapper::_getInProgress($a_obj_id));
40  $users = array_diff($users,$com = ilLPStatusWrapper::_getCompleted($a_obj_id));
41 
42  $ilBench->stop('LearningProgress','9171_LPStatusObjectives_notAttempted');
43  return $users ? $users : array();
44  }
45 
46  function _getInProgress($a_obj_id)
47  {
48  global $ilDB;
49 
50  $completed = ilLPStatusWrapper::_getCompleted($a_obj_id);
51 
52  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
53  $members_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
54  $members = $members_obj->getParticipants();
55 
56  include_once './Services/Tracking/classes/class.ilChangeEvent.php';
57  $all = ilChangeEvent::lookupUsersInProgress($a_obj_id);
58  foreach($all as $user_id)
59  {
60  if(!in_array($user_id,$completed) and in_array($user_id,$members))
61  {
62  $user_ids[] = $user_id;
63  }
64  }
65  return $user_ids ? $user_ids : array();
66  }
67 
68  function _getCompleted($a_obj_id)
69  {
70  global $ilDB;
71 
72  global $ilBench;
73 
74  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
75  foreach($status_info['objective_result'] as $user_id => $completed)
76  {
77  if(count($completed) == $status_info['num_objectives'])
78  {
79  $usr_ids[] = $user_id;
80  }
81  }
82  return $usr_ids ? $usr_ids : array();
83  }
84 
85 
86  function _getStatusInfo($a_obj_id)
87  {
88  include_once 'Modules/Course/classes/class.ilCourseObjective.php';
89 
90  global $ilDB;
91 
92  $status_info['objective_result'] = array();
93  $status_info['objectives'] = ilCourseObjective::_getObjectiveIds($a_obj_id);
94  $status_info['num_objectives'] = count($status_info['objectives']);
95 
96  if(!$status_info['num_objectives'])
97  {
98  return $status_info;
99  }
100  else
101  {
102  $in = $ilDB->in('objective_id',$status_info['objectives'], false,'integer');
103  }
104 
105  $query = "SELECT * FROM crs_objective_status ".
106  "WHERE ".$in;
107 
108  $res = $ilDB->query($query);
109  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
110  {
111  $status_info['completed'][$row->objective_id][] = $row->user_id;
112  $status_info['objective_result'][$row->user_id][$row->objective_id] = $row->objective_id;
113  }
114 
115  // Read title/description
116  $query = "SELECT * FROM crs_objectives ".
117  "WHERE ".$in;
118  $res = $ilDB->query($query);
119  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
120  {
121  $status_info['objective_title'][$row->objective_id] = $row->title;
122  $status_info['objective_description'][$row->objective_id] = $row->description;
123  }
124  return $status_info;
125  }
126 
135  function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
136  {
137  global $ilObjDataCache, $ilDB;
138 
139  // the status completed depends on:
140  // $status_info['num_objectives'] (ilLPStatusWrapper::_getStatusInfo($a_obj_id);)
141  // - ilCourseObjective::_getObjectiveIds($a_obj_id);
142  // - table crs_objectives manipulated in
143  // - ilCourseObjective
144 
145  // $status_info['objective_result'] (ilLPStatusWrapper::_getStatusInfo($a_obj_id);)
146  // table crs_objective_status (must not contain a dataset)
147  // ilCourseObjectiveResult -> added ilLPStatusWrapper::_updateStatus()
148 
149  $status = LP_STATUS_NOT_ATTEMPTED_NUM;
150  switch ($ilObjDataCache->lookupType($a_obj_id))
151  {
152  case "crs":
153  include_once("./Services/Tracking/classes/class.ilChangeEvent.php");
154  if (ilChangeEvent::hasAccessed($a_obj_id, $a_user_id))
155  {
156  $status = LP_STATUS_IN_PROGRESS_NUM;
157 
158  include_once 'Modules/Course/classes/class.ilCourseObjective.php';
159  $objectives = ilCourseObjective::_getObjectiveIds($a_obj_id);
160  if ($objectives)
161  {
162  $set = $ilDB->query("SELECT count(objective_id) cnt FROM crs_objective_status ".
163  "WHERE ".$ilDB->in('objective_id',$objectives, false,'integer').
164  " AND user_id = ".$ilDB->quote($a_user_id, "integer"));
165  if ($rec = $ilDB->fetchAssoc($set))
166  {
167  if ($rec["cnt"] == count($objectives))
168  {
169  $status = LP_STATUS_COMPLETED_NUM;
170  }
171  }
172  }
173  }
174  break;
175  }
176  return $status;
177  }
178 
179 }
180 
181 
182 ?>