ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLPStatusVisitedPages.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
27{
28 public static function _getInProgress(int $a_obj_id): array
29 {
30 $users = ilChangeEvent::lookupUsersInProgress($a_obj_id);
31 $users = array_diff(
32 $users,
34 );
35 return $users;
36 }
37
38 public static function _getCompleted(int $a_obj_id): array
39 {
40 $users = array();
41
42 $all_page_ids = self::getLMPages($a_obj_id);
43 foreach (self::getVisitedPages(
44 $a_obj_id
45 ) as $user_id => $user_page_ids) {
46 if (!(bool) sizeof(array_diff($all_page_ids, $user_page_ids))) {
47 $users[] = $user_id;
48 }
49 }
50
51 return $users;
52 }
53
54 public function determineStatus(
55 int $a_obj_id,
56 int $a_usr_id,
57 ?object $a_obj = null
58 ): int {
59 $status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
60 switch (ilObject::_lookupType($a_obj_id)) {
61 case 'lm':
62 if (ilChangeEvent::hasAccessed($a_obj_id, $a_usr_id)) {
64
65 if (self::hasVisitedAllPages($a_obj_id, $a_usr_id)) {
67 }
68 }
69 break;
70 }
71
72 return $status;
73 }
74
75 public function determinePercentage(
76 int $a_obj_id,
77 int $a_usr_id,
78 ?object $a_obj = null
79 ): int {
80 $all_page_ids = sizeof(self::getLMPages($a_obj_id));
81 if (!$all_page_ids) {
82 return 0;
83 }
84 $user_page_ids = sizeof(self::getVisitedPages($a_obj_id, $a_usr_id));
85 return (int) floor($user_page_ids / $all_page_ids * 100);
86 }
87
88 protected static function hasVisitedAllPages(
89 int $a_obj_id,
90 int $a_user_id
91 ): bool {
92 $all_page_ids = self::getLMPages($a_obj_id);
93 if (!sizeof($all_page_ids)) {
94 return false;
95 }
96 $user_page_ids = self::getVisitedPages($a_obj_id, $a_user_id);
97 return !(bool) array_diff($all_page_ids, $user_page_ids);
98 }
99
100 protected static function getLMPages(int $a_obj_id): array
101 {
102 global $DIC;
103
104 $ilDB = $DIC['ilDB'];
105
106 $res = array();
107
108 $set = $ilDB->query(
109 "SELECT lm_data.obj_id" .
110 " FROM lm_data" .
111 " JOIN lm_tree ON (lm_tree.child = lm_data.obj_id)" .
112 " WHERE lm_tree.lm_id = " . $ilDB->quote($a_obj_id, "integer") .
113 " AND lm_data.type = " . $ilDB->quote("pg", "text")
114 );
115 while ($row = $ilDB->fetchAssoc($set)) {
116 // only active pages (time-based activation not supported)
117 if (ilPageObject::_lookupActive($row["obj_id"], "lm")) {
118 $res[] = (int) $row["obj_id"];
119 }
120 }
121 return $res;
122 }
123
124 protected static function getVisitedPages(
125 int $a_obj_id,
126 ?int $a_user_id = null
127 ): array {
128 global $DIC;
129
130 $ilDB = $DIC['ilDB'];
131
132 $res = array();
133
134 $all_page_ids = self::getLMPages($a_obj_id);
135 if (!sizeof($all_page_ids)) {
136 return $res;
137 }
138
139 $sql = "SELECT obj_id, usr_id" .
140 " FROM lm_read_event" .
141 " WHERE " . $ilDB->in("obj_id", $all_page_ids, "", "integer");
142
143 if ($a_user_id) {
144 $sql .= " AND usr_id = " . $ilDB->quote($a_user_id, "integer");
145 }
146
147 $set = $ilDB->query($sql);
148 while ($row = $ilDB->fetchAssoc($set)) {
149 $res[(int) $row["usr_id"]][] = (int) $row["obj_id"];
150 }
151
152 if ($a_user_id) {
153 $res = $res[$a_user_id] ?? [];
154 }
155
156 return $res;
157 }
158}
static hasAccessed(int $a_obj_id, int $a_usr_id)
Has accessed.
static lookupUsersInProgress(int $a_obj_id)
static getVisitedPages(int $a_obj_id, ?int $a_user_id=null)
static _getInProgress(int $a_obj_id)
determinePercentage(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
determineStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static hasVisitedAllPages(int $a_obj_id, int $a_user_id)
static _getCompleted(int $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(int $id, bool $reference=false)
static _lookupActive(int $a_id, string $a_parent_type, bool $a_check_scheduled_activation=false, string $a_lang="-")
lookup activation status
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26