ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLPStatusVisitedPages.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once './Services/Tracking/classes/class.ilLPStatus.php';
6 
16 {
17  static function _getInProgress($a_obj_id)
18  {
19  include_once './Services/Tracking/classes/class.ilChangeEvent.php';
20  $users = ilChangeEvent::lookupUsersInProgress($a_obj_id);
21 
22  $users = array_diff($users, ilLPStatusWrapper::_getCompleted($a_obj_id));
23 
24  return $users;
25  }
26 
27  static function _getCompleted($a_obj_id)
28  {
29  $users = array();
30 
31  $all_page_ids = self::getLMPages($a_obj_id);
32  foreach(self::getVisitedPages($a_obj_id) as $user_id => $user_page_ids)
33  {
34  if(!(bool)sizeof(array_diff($all_page_ids, $user_page_ids)))
35  {
36  $users[] = $user_id;
37  }
38  }
39 
40  return $users;
41  }
42 
51  function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
52  {
53  /* once completed will not be changed anymore
54  if(ilLPStatus::_hasUserCompleted($a_obj_id, $a_user_id))
55  {
56  return self::LP_STATUS_COMPLETED_NUM;
57  }
58  */
59 
60  $status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
61  switch(ilObject::_lookupType($a_obj_id))
62  {
63  case 'lm':
64  if(ilChangeEvent::hasAccessed($a_obj_id, $a_user_id))
65  {
66  $status = self::LP_STATUS_IN_PROGRESS_NUM;
67 
68  if(self::hasVisitedAllPages($a_obj_id, $a_user_id))
69  {
70  $status = self::LP_STATUS_COMPLETED_NUM;
71  }
72  }
73  break;
74  }
75 
76  return $status;
77  }
78 
87  function determinePercentage($a_obj_id, $a_user_id, $a_obj = null)
88  {
89  /* once completed will not be changed anymore
90  if(ilLPStatus::_hasUserCompleted($a_obj_id, $a_user_id))
91  {
92  return 100;
93  }
94  */
95 
96  $all_page_ids = sizeof(self::getLMPages($a_obj_id));
97  if(!$all_page_ids)
98  {
99  return 0;
100  }
101 
102  $user_page_ids = sizeof(self::getVisitedPages($a_obj_id, $a_user_id));
103 
104  return floor($user_page_ids/$all_page_ids*100);
105  }
106 
107 
108  //
109  // HELPER
110  //
111 
112  protected static function hasVisitedAllPages($a_obj_id, $a_user_id)
113  {
114  $all_page_ids = self::getLMPages($a_obj_id);
115  if(!sizeof($all_page_ids))
116  {
117  return false;
118  }
119 
120  $user_page_ids = self::getVisitedPages($a_obj_id, $a_user_id);
121  return !(bool)sizeof(array_diff($all_page_ids, $user_page_ids));
122  }
123 
124  protected static function getLMPages($a_obj_id)
125  {
126  global $ilDB;
127 
128  $res = array();
129 
130  include_once "Services/COPage/classes/class.ilPageObject.php";
131 
132  $set = $ilDB->query("SELECT lm_data.obj_id".
133  " FROM lm_data".
134  " JOIN lm_tree ON (lm_tree.child = lm_data.obj_id)".
135  " WHERE lm_tree.lm_id = ".$ilDB->quote($a_obj_id, "integer").
136  " AND lm_data.type = ".$ilDB->quote("pg", "text"));
137  while($row = $ilDB->fetchAssoc($set))
138  {
139  // only active pages (time-based activation not supported)
140  if(ilPageObject::_lookupActive($row["obj_id"], "lm"))
141  {
142  $res[] = $row["obj_id"];
143  }
144  }
145 
146  return $res;
147  }
148 
149  protected static function getVisitedPages($a_obj_id, $a_user_id = null)
150  {
151  global $ilDB;
152 
153  $res = array();
154 
155  $all_page_ids = self::getLMPages($a_obj_id);
156  if(!sizeof($all_page_ids))
157  {
158  return $res;
159  }
160 
161  $sql = "SELECT obj_id, usr_id".
162  " FROM lm_read_event".
163  " WHERE ".$ilDB->in("obj_id", $all_page_ids, "", "integer");
164 
165  if($a_user_id)
166  {
167  $sql .= " AND usr_id = ".$ilDB->quote($a_user_id, "integer");
168  }
169 
170  $set = $ilDB->query($sql);
171  while($row = $ilDB->fetchAssoc($set))
172  {
173  $res[$row["usr_id"]][] = $row["obj_id"];
174  }
175 
176  if($a_user_id)
177  {
178  $res = (array)$res[$a_user_id];
179  }
180 
181  return $res;
182  }
183 }
static hasAccessed($a_obj_id, $a_usr_id)
Has accessed.
static _getCompleted($a_obj_id)
Static function to read the users who have the status &#39;completed&#39;.
determineStatus($a_obj_id, $a_user_id, $a_obj=null)
Determine status.
static getVisitedPages($a_obj_id, $a_user_id=null)
static _lookupActive($a_id, $a_parent_type, $a_check_scheduled_activation=false, $a_lang="-")
lookup activation status
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
determinePercentage($a_obj_id, $a_user_id, $a_obj=null)
Determine percentage.
global $ilDB
static hasVisitedAllPages($a_obj_id, $a_user_id)
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
static lookupUsersInProgress($a_obj_id)
Lookup users in progress.