ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLPStatusCollectionMobs.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
25{
26 public static function _getInProgress(int $a_obj_id): array
27 {
28 $users = array();
29
30 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
31 if (isset($status_info["user_status"]["in_progress"])) {
32 $users = $status_info["user_status"]["in_progress"];
33 }
34 return $users;
35 }
36
37 public static function _getCompleted(int $a_obj_id): array
38 {
39 $users = array();
40
41 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
42 if (isset($status_info["user_status"]["completed"])) {
43 $users = $status_info["user_status"]["completed"];
44 }
45
46 return $users;
47 }
48
49 public static function _getStatusInfo(int $a_obj_id): array
50 {
51 global $DIC;
52
53 $ilDB = $DIC['ilDB'];
54
55 $res = array();
56
57 $coll_items = self::getCollectionItems($a_obj_id, true);
58
59 $res["items"] = array_keys($coll_items);
60 if (sizeof($res["items"])) {
61 // titles
62 foreach ($coll_items as $mob_id => $item) {
63 $res["item_titles"][$mob_id] = $item["title"];
64 }
65
66 // status per item
67 foreach ($res["items"] as $mob_id) {
68 $res["completed"][$mob_id] = array();
69 $res["in_progress"][$mob_id] = array();
70 }
71
72 $set = $ilDB->query(
73 "SELECT obj_id, usr_id FROM read_event" .
74 " WHERE " . $ilDB->in("obj_id", $res["items"], "", "integer")
75 );
76 while ($row = $ilDB->fetchAssoc($set)) {
77 $res["completed"][(int) $row["obj_id"]][] = (int) $row["usr_id"];
78 }
79
80 // status per user
81 $tmp = array();
82 foreach ($res["items"] as $mob_id) {
83 foreach ($res["completed"][$mob_id] as $user_id) {
84 $tmp[$user_id][] = (int) $mob_id;
85 }
86 }
87 foreach ($tmp as $user_id => $completed_items) {
88 if (sizeof($completed_items) == sizeof($res["items"])) {
89 $res["user_status"]["completed"][] = (int) $user_id;
90 } else {
91 $res["user_status"]["in_progress"][] = (int) $user_id;
92 }
93 }
94 }
95
96 $users = ilChangeEvent::lookupUsersInProgress($a_obj_id);
97 foreach ($users as $user_id) {
98 if ((!isset($res["user_status"]["in_progress"]) || !in_array(
100 $res["user_status"]["in_progress"]
101 )) &&
102 (!isset($res["user_status"]["completed"]) || !in_array(
103 $user_id,
104 $res["user_status"]["completed"]
105 ))) {
106 $res["user_status"]["in_progress"][] = (int) $user_id;
107 }
108 }
109
110 return $res;
111 }
112
113 protected static function getCollectionItems(
114 $a_obj_id,
115 $a_include_titles = false
116 ) {
117 $res = array();
118
119 $olp = ilObjectLP::getInstance($a_obj_id);
120 $collection = $olp->getCollectionInstance();
121 if ($collection) {
122 $possible = $collection->getPossibleItems();
123
124 // there could be invalid items in the selection
125 $valid = array_intersect(
126 $collection->getItems(),
127 array_keys($possible)
128 );
129
130 if ($a_include_titles) {
131 foreach ($valid as $item_id) {
132 $res[$item_id] = $possible[$item_id];
133 }
134 } else {
135 $res = $valid;
136 }
137 }
138 return $res;
139 }
140
141 public function determineStatus(
142 int $a_obj_id,
143 int $a_usr_id,
144 ?object $a_obj = null
145 ): int {
146 $status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
147 if (ilChangeEvent::hasAccessed($a_obj_id, $a_usr_id)) {
149 }
150
151 // an empty collection is always not attempted
152 $items = self::getCollectionItems($a_obj_id);
153 if (count($items) > 0) {
154 // process mob status for user
155
156 $found = array();
157
158 $set = $this->db->query(
159 "SELECT obj_id FROM read_event" .
160 " WHERE usr_id = " . $this->db->quote($a_usr_id, "integer") .
161 " AND " . $this->db->in("obj_id", $items, false, "integer")
162 );
163 while ($row = $this->db->fetchAssoc($set)) {
164 $found[] = (int) $row["obj_id"];
165 }
166
167 if (count($found) > 0) {
169
170 if (count($found) == count($items)) {
172 }
173 }
174 }
175 return $status;
176 }
177
178 public function determinePercentage(
179 int $a_obj_id,
180 int $a_usr_id,
181 ?object $a_obj = null
182 ): int {
183 $per = 0;
184
185 // an empty collection is always not attempted
186 $items = self::getCollectionItems($a_obj_id);
187 if (count($items) > 0) {
188 // process mob status for user
189
190 $found = array();
191 $set = $this->db->query(
192 "SELECT obj_id FROM read_event" .
193 " WHERE usr_id = " . $this->db->quote($a_usr_id, "integer") .
194 " AND " . $this->db->in("obj_id", $items, false, "integer")
195 );
196 while ($row = $this->db->fetchAssoc($set)) {
197 $found[] = (int) $row["obj_id"];
198 }
199
200 if (count($found) > 0 && count($items) > 0) {
201 $per = (int) round(100 / count($items) * count($found));
202 }
203 }
204
205 return $per;
206 }
207}
static hasAccessed(int $a_obj_id, int $a_usr_id)
Has accessed.
static lookupUsersInProgress(int $a_obj_id)
determineStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static getCollectionItems( $a_obj_id, $a_include_titles=false)
determinePercentage(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static _getStatusInfo(int $a_obj_id)
Reads informations about the object e.g test results, tlt, number of visits.
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 getInstance(int $obj_id)
$valid
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26