ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
5include_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';
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 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
59 switch (ilObject::_lookupType($a_obj_id)) {
60 case 'lm':
61 if (ilChangeEvent::hasAccessed($a_obj_id, $a_user_id)) {
63
64 if (self::hasVisitedAllPages($a_obj_id, $a_user_id)) {
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 $DIC;
120
121 $ilDB = $DIC['ilDB'];
122
123 $res = array();
124
125 include_once "Services/COPage/classes/class.ilPageObject.php";
126
127 $set = $ilDB->query("SELECT lm_data.obj_id" .
128 " FROM lm_data" .
129 " JOIN lm_tree ON (lm_tree.child = lm_data.obj_id)" .
130 " WHERE lm_tree.lm_id = " . $ilDB->quote($a_obj_id, "integer") .
131 " AND lm_data.type = " . $ilDB->quote("pg", "text"));
132 while ($row = $ilDB->fetchAssoc($set)) {
133 // only active pages (time-based activation not supported)
134 if (ilPageObject::_lookupActive($row["obj_id"], "lm")) {
135 $res[] = $row["obj_id"];
136 }
137 }
138
139 return $res;
140 }
141
142 protected static function getVisitedPages($a_obj_id, $a_user_id = null)
143 {
144 global $DIC;
145
146 $ilDB = $DIC['ilDB'];
147
148 $res = array();
149
150 $all_page_ids = self::getLMPages($a_obj_id);
151 if (!sizeof($all_page_ids)) {
152 return $res;
153 }
154
155 $sql = "SELECT obj_id, usr_id" .
156 " FROM lm_read_event" .
157 " WHERE " . $ilDB->in("obj_id", $all_page_ids, "", "integer");
158
159 if ($a_user_id) {
160 $sql .= " AND usr_id = " . $ilDB->quote($a_user_id, "integer");
161 }
162
163 $set = $ilDB->query($sql);
164 while ($row = $ilDB->fetchAssoc($set)) {
165 $res[$row["usr_id"]][] = $row["obj_id"];
166 }
167
168 if ($a_user_id) {
169 $res = (array) $res[$a_user_id];
170 }
171
172 return $res;
173 }
174}
An exception for terminatinating execution or to throw for unit testing.
static lookupUsersInProgress($a_obj_id)
Lookup users in progress.
static hasAccessed($a_obj_id, $a_usr_id)
Has accessed.
determineStatus($a_obj_id, $a_user_id, $a_obj=null)
Determine status.
static getVisitedPages($a_obj_id, $a_user_id=null)
determinePercentage($a_obj_id, $a_user_id, $a_obj=null)
Determine percentage.
static hasVisitedAllPages($a_obj_id, $a_user_id)
static _getCompleted($a_obj_id)
Static function to read the users who have the status 'completed'.
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
static _lookupType($a_id, $a_reference=false)
lookup object type
static _lookupActive($a_id, $a_parent_type, $a_check_scheduled_activation=false, $a_lang="-")
lookup activation status
foreach($_POST as $key=> $value) $res
global $ilDB
$DIC
Definition: xapitoken.php:46