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