ILIAS  release_8 Revision v8.24
class.ilLPStatusVisitedPages.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=0);
4
5/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
6
13{
14 public static function _getInProgress(int $a_obj_id): array
15 {
16 $users = ilChangeEvent::lookupUsersInProgress($a_obj_id);
17 $users = array_diff(
18 $users,
20 );
21 return $users;
22 }
23
24 public static function _getCompleted(int $a_obj_id): array
25 {
26 $users = array();
27
28 $all_page_ids = self::getLMPages($a_obj_id);
29 foreach (self::getVisitedPages(
30 $a_obj_id
31 ) as $user_id => $user_page_ids) {
32 if (!(bool) sizeof(array_diff($all_page_ids, $user_page_ids))) {
33 $users[] = $user_id;
34 }
35 }
36
37 return $users;
38 }
39
40 public function determineStatus(
41 int $a_obj_id,
42 int $a_usr_id,
43 object $a_obj = null
44 ): int {
45 $status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
46 switch (ilObject::_lookupType($a_obj_id)) {
47 case 'lm':
48 if (ilChangeEvent::hasAccessed($a_obj_id, $a_usr_id)) {
50
51 if (self::hasVisitedAllPages($a_obj_id, $a_usr_id)) {
53 }
54 }
55 break;
56 }
57
58 return $status;
59 }
60
61 public function determinePercentage(
62 int $a_obj_id,
63 int $a_usr_id,
64 ?object $a_obj = null
65 ): int {
66 $all_page_ids = sizeof(self::getLMPages($a_obj_id));
67 if (!$all_page_ids) {
68 return 0;
69 }
70 $user_page_ids = sizeof(self::getVisitedPages($a_obj_id, $a_usr_id));
71 return (int) floor($user_page_ids / $all_page_ids * 100);
72 }
73
74 protected static function hasVisitedAllPages(
75 int $a_obj_id,
76 int $a_user_id
77 ): bool {
78 $all_page_ids = self::getLMPages($a_obj_id);
79 if (!sizeof($all_page_ids)) {
80 return false;
81 }
82 $user_page_ids = self::getVisitedPages($a_obj_id, $a_user_id);
83 return !(bool) array_diff($all_page_ids, $user_page_ids);
84 }
85
86 protected static function getLMPages(int $a_obj_id): array
87 {
88 global $DIC;
89
90 $ilDB = $DIC['ilDB'];
91
92 $res = array();
93
94 $set = $ilDB->query(
95 "SELECT lm_data.obj_id" .
96 " FROM lm_data" .
97 " JOIN lm_tree ON (lm_tree.child = lm_data.obj_id)" .
98 " WHERE lm_tree.lm_id = " . $ilDB->quote($a_obj_id, "integer") .
99 " AND lm_data.type = " . $ilDB->quote("pg", "text")
100 );
101 while ($row = $ilDB->fetchAssoc($set)) {
102 // only active pages (time-based activation not supported)
103 if (ilPageObject::_lookupActive($row["obj_id"], "lm")) {
104 $res[] = (int) $row["obj_id"];
105 }
106 }
107 return $res;
108 }
109
110 protected static function getVisitedPages(
111 int $a_obj_id,
112 ?int $a_user_id = null
113 ): array {
114 global $DIC;
115
116 $ilDB = $DIC['ilDB'];
117
118 $res = array();
119
120 $all_page_ids = self::getLMPages($a_obj_id);
121 if (!sizeof($all_page_ids)) {
122 return $res;
123 }
124
125 $sql = "SELECT obj_id, usr_id" .
126 " FROM lm_read_event" .
127 " WHERE " . $ilDB->in("obj_id", $all_page_ids, "", "integer");
128
129 if ($a_user_id) {
130 $sql .= " AND usr_id = " . $ilDB->quote($a_user_id, "integer");
131 }
132
133 $set = $ilDB->query($sql);
134 while ($row = $ilDB->fetchAssoc($set)) {
135 $res[(int) $row["usr_id"]][] = (int) $row["obj_id"];
136 }
137
138 if ($a_user_id) {
139 $res = $res[$a_user_id] ?? [];
140 }
141
142 return $res;
143 }
144}
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)
determineStatus(int $a_obj_id, int $a_usr_id, object $a_obj=null)
static _getInProgress(int $a_obj_id)
determinePercentage(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
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69