ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  public static function _getInProgress($a_obj_id)
18  {
19  include_once './Services/Tracking/classes/class.ilChangeEvent.php';
21 
22  $users = array_diff($users, ilLPStatusWrapper::_getCompleted($a_obj_id));
23 
24  return $users;
25  }
26 
27  public 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  if (!(bool) sizeof(array_diff($all_page_ids, $user_page_ids))) {
34  $users[] = $user_id;
35  }
36  }
37 
38  return $users;
39  }
40 
49  public function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
50  {
51  /* once completed will not be changed anymore
52  if(ilLPStatus::_hasUserCompleted($a_obj_id, $a_user_id))
53  {
54  return self::LP_STATUS_COMPLETED_NUM;
55  }
56  */
57 
58  $status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
59  switch (ilObject::_lookupType($a_obj_id)) {
60  case 'lm':
61  if (ilChangeEvent::hasAccessed($a_obj_id, $a_user_id)) {
62  $status = self::LP_STATUS_IN_PROGRESS_NUM;
63 
64  if (self::hasVisitedAllPages($a_obj_id, $a_user_id)) {
65  $status = self::LP_STATUS_COMPLETED_NUM;
66  }
67  }
68  break;
69  }
70 
71  return $status;
72  }
73 
82  public function determinePercentage($a_obj_id, $a_user_id, $a_obj = null)
83  {
84  /* once completed will not be changed anymore
85  if(ilLPStatus::_hasUserCompleted($a_obj_id, $a_user_id))
86  {
87  return 100;
88  }
89  */
90 
91  $all_page_ids = sizeof(self::getLMPages($a_obj_id));
92  if (!$all_page_ids) {
93  return 0;
94  }
95 
96  $user_page_ids = sizeof(self::getVisitedPages($a_obj_id, $a_user_id));
97 
98  return floor($user_page_ids/$all_page_ids*100);
99  }
100 
101 
102  //
103  // HELPER
104  //
105 
106  protected static function hasVisitedAllPages($a_obj_id, $a_user_id)
107  {
108  $all_page_ids = self::getLMPages($a_obj_id);
109  if (!sizeof($all_page_ids)) {
110  return false;
111  }
112 
113  $user_page_ids = self::getVisitedPages($a_obj_id, $a_user_id);
114  return !(bool) sizeof(array_diff($all_page_ids, $user_page_ids));
115  }
116 
117  protected static function getLMPages($a_obj_id)
118  {
119  global $ilDB;
120 
121  $res = array();
122 
123  include_once "Services/COPage/classes/class.ilPageObject.php";
124 
125  $set = $ilDB->query("SELECT lm_data.obj_id" .
126  " FROM lm_data" .
127  " JOIN lm_tree ON (lm_tree.child = lm_data.obj_id)" .
128  " WHERE lm_tree.lm_id = " . $ilDB->quote($a_obj_id, "integer") .
129  " AND lm_data.type = " . $ilDB->quote("pg", "text"));
130  while ($row = $ilDB->fetchAssoc($set)) {
131  // only active pages (time-based activation not supported)
132  if (ilPageObject::_lookupActive($row["obj_id"], "lm")) {
133  $res[] = $row["obj_id"];
134  }
135  }
136 
137  return $res;
138  }
139 
140  protected static function getVisitedPages($a_obj_id, $a_user_id = null)
141  {
142  global $ilDB;
143 
144  $res = array();
145 
146  $all_page_ids = self::getLMPages($a_obj_id);
147  if (!sizeof($all_page_ids)) {
148  return $res;
149  }
150 
151  $sql = "SELECT obj_id, usr_id" .
152  " FROM lm_read_event" .
153  " WHERE " . $ilDB->in("obj_id", $all_page_ids, "", "integer");
154 
155  if ($a_user_id) {
156  $sql .= " AND usr_id = " . $ilDB->quote($a_user_id, "integer");
157  }
158 
159  $set = $ilDB->query($sql);
160  while ($row = $ilDB->fetchAssoc($set)) {
161  $res[$row["usr_id"]][] = $row["obj_id"];
162  }
163 
164  if ($a_user_id) {
165  $res = (array) $res[$a_user_id];
166  }
167 
168  return $res;
169  }
170 }
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)
foreach($_POST as $key=> $value) $res
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.
$users
Definition: authpage.php:44
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.