ILIAS  release_8 Revision v8.24
class.ilLPStatusPlugin.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=0);
4/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
5
12{
19 protected static function initPluginObj(int $a_obj_id)
20 {
21 $olp = ilObjectLP::getInstance($a_obj_id);
22 return $olp->getPluginInstance();
23 }
24
25 public static function _getNotAttempted(int $a_obj_id): array
26 {
27 $plugin = self::initPluginObj($a_obj_id);
28 if ($plugin) {
30 return (array) $plugin->getLPNotAttempted();
31 } else {
32 // re-use existing data for inactive plugin
34 $a_obj_id,
35 self::LP_STATUS_NOT_ATTEMPTED_NUM
36 );
37 }
38 }
39 return array();
40 }
41
42 public static function _getInProgress(int $a_obj_id): array
43 {
44 $plugin = self::initPluginObj($a_obj_id);
45 if ($plugin) {
47 return (array) $plugin->getLPInProgress();
48 } else {
49 // re-use existing data for inactive plugin
51 $a_obj_id,
52 self::LP_STATUS_IN_PROGRESS_NUM
53 );
54 }
55 }
56 return array();
57 }
58
59 public static function _getCompleted(int $a_obj_id): array
60 {
61 $plugin = self::initPluginObj($a_obj_id);
62 if ($plugin) {
64 return (array) $plugin->getLPCompleted();
65 } else {
66 // re-use existing data for inactive plugin
68 $a_obj_id,
69 self::LP_STATUS_COMPLETED_NUM
70 );
71 }
72 }
73 return array();
74 }
75
76 public static function _getFailed(int $a_obj_id): array
77 {
78 $plugin = self::initPluginObj($a_obj_id);
79 if ($plugin) {
81 return (array) $plugin->getLPFailed();
82 } else {
83 // re-use existing data for inactive plugin
85 $a_obj_id,
86 self::LP_STATUS_FAILED_NUM
87 );
88 }
89 }
90 return array();
91 }
92
93 public function determineStatus(
94 int $a_obj_id,
95 int $a_usr_id,
96 object $a_obj = null
97 ): int {
98 $plugin = self::initPluginObj($a_obj_id);
99 if ($plugin) {
101 // :TODO: create read_event here to make sure?
102 return $plugin->getLPStatusForUser($a_usr_id);
103 } else {
104 // re-use existing data for inactive plugin
105 return self::getLPDataForUser($a_obj_id, $a_usr_id);
106 }
107 }
108 // #11368
110 }
111
112 public function determinePercentage(
113 int $a_obj_id,
114 int $a_usr_id,
115 ?object $a_obj = null
116 ): int {
117 $plugin = self::initPluginObj($a_obj_id);
118 if ($plugin) {
120 if (method_exists($plugin, "getPercentageForUser")) {
121 return $plugin->getPercentageForUser($a_usr_id);
122 }
123 }
124 // re-use existing data for inactive plugin
125 return self::getPercentageForUser($a_obj_id, $a_usr_id);
126 }
127 // #11368
128 return 0;
129 }
130
134 protected static function getLPStatusData(
135 int $a_obj_id,
136 int $a_status
137 ): array {
138 global $DIC;
139
140 $ilDB = $DIC['ilDB'];
141
142 $all = array();
143 $set = $ilDB->query(
144 "SELECT usr_id" .
145 " FROM ut_lp_marks" .
146 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
147 " AND status = " . $ilDB->quote($a_status, "integer")
148 );
149 while ($row = $ilDB->fetchAssoc($set)) {
150 $all[] = (int) $row["usr_id"];
151 }
152 return $all;
153 }
154
158 protected static function getLPDataForUser(
159 int $a_obj_id,
160 int $a_user_id
161 ): int {
162 global $DIC;
163
164 $ilDB = $DIC['ilDB'];
165
166 $set = $ilDB->query(
167 "SELECT status" .
168 " FROM ut_lp_marks" .
169 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
170 " AND usr_id = " . $ilDB->quote($a_user_id, "integer")
171 );
172 $row = $ilDB->fetchAssoc($set);
173 $status = $row["status"];
174 if (!$status) {
175 $status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
176 }
177 return $status;
178 }
179
180 protected static function getPercentageForUser(
181 int $a_obj_id,
182 int $a_user_id
183 ): int {
184 global $DIC;
185
186 $ilDB = $DIC['ilDB'];
187
188 $set = $ilDB->query(
189 "SELECT percentage" .
190 " FROM ut_lp_marks" .
191 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
192 " AND usr_id = " . $ilDB->quote($a_user_id, "integer")
193 );
194 $row = $ilDB->fetchAssoc($set);
195 return (int) ($row["percentage"] ?? 0);
196 }
197}
static _getInProgress(int $a_obj_id)
static initPluginObj(int $a_obj_id)
Get ilObjectPlugin for object id.
determinePercentage(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static getLPStatusData(int $a_obj_id, int $a_status)
Read existing LP status data.
static _getCompleted(int $a_obj_id)
static _getFailed(int $a_obj_id)
static getLPDataForUser(int $a_obj_id, int $a_user_id)
Read existing LP status data for user.
determineStatus(int $a_obj_id, int $a_usr_id, object $a_obj=null)
static _getNotAttempted(int $a_obj_id)
static getPercentageForUser(int $a_obj_id, int $a_user_id)
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
const LP_STATUS_NOT_ATTEMPTED_NUM
static getInstance(int $obj_id)
const INACTIVE_PLUGIN
global $DIC
Definition: feed.php:28