ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLPStatusPlugin.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
26{
33 protected static function initPluginObj(int $a_obj_id)
34 {
35 $olp = ilObjectLP::getInstance($a_obj_id);
36 return $olp->getPluginInstance();
37 }
38
39 public static function _getNotAttempted(int $a_obj_id): array
40 {
41 $plugin = self::initPluginObj($a_obj_id);
42 if ($plugin) {
44 return (array) $plugin->getLPNotAttempted();
45 } else {
46 // re-use existing data for inactive plugin
48 $a_obj_id,
49 self::LP_STATUS_NOT_ATTEMPTED_NUM
50 );
51 }
52 }
53 return array();
54 }
55
56 public static function _getInProgress(int $a_obj_id): array
57 {
58 $plugin = self::initPluginObj($a_obj_id);
59 if ($plugin) {
61 return (array) $plugin->getLPInProgress();
62 } else {
63 // re-use existing data for inactive plugin
65 $a_obj_id,
66 self::LP_STATUS_IN_PROGRESS_NUM
67 );
68 }
69 }
70 return array();
71 }
72
73 public static function _getCompleted(int $a_obj_id): array
74 {
75 $plugin = self::initPluginObj($a_obj_id);
76 if ($plugin) {
78 return (array) $plugin->getLPCompleted();
79 } else {
80 // re-use existing data for inactive plugin
82 $a_obj_id,
83 self::LP_STATUS_COMPLETED_NUM
84 );
85 }
86 }
87 return array();
88 }
89
90 public static function _getFailed(int $a_obj_id): array
91 {
92 $plugin = self::initPluginObj($a_obj_id);
93 if ($plugin) {
95 return (array) $plugin->getLPFailed();
96 } else {
97 // re-use existing data for inactive plugin
99 $a_obj_id,
100 self::LP_STATUS_FAILED_NUM
101 );
102 }
103 }
104 return array();
105 }
106
107 public function determineStatus(
108 int $a_obj_id,
109 int $a_usr_id,
110 ?object $a_obj = null
111 ): int {
112 $plugin = self::initPluginObj($a_obj_id);
113 if ($plugin) {
115 // :TODO: create read_event here to make sure?
116 return $plugin->getLPStatusForUser($a_usr_id);
117 } else {
118 // re-use existing data for inactive plugin
119 return self::getLPDataForUser($a_obj_id, $a_usr_id);
120 }
121 }
122 // #11368
124 }
125
126 public function determinePercentage(
127 int $a_obj_id,
128 int $a_usr_id,
129 ?object $a_obj = null
130 ): int {
131 $plugin = self::initPluginObj($a_obj_id);
132 if ($plugin) {
134 if (method_exists($plugin, "getPercentageForUser")) {
135 return $plugin->getPercentageForUser($a_usr_id);
136 }
137 }
138 // re-use existing data for inactive plugin
139 return self::getPercentageForUser($a_obj_id, $a_usr_id);
140 }
141 // #11368
142 return 0;
143 }
144
148 protected static function getLPStatusData(
149 int $a_obj_id,
150 int $a_status
151 ): array {
152 global $DIC;
153
154 $ilDB = $DIC['ilDB'];
155
156 $all = array();
157 $set = $ilDB->query(
158 "SELECT usr_id" .
159 " FROM ut_lp_marks" .
160 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
161 " AND status = " . $ilDB->quote($a_status, "integer")
162 );
163 while ($row = $ilDB->fetchAssoc($set)) {
164 $all[] = (int) $row["usr_id"];
165 }
166 return $all;
167 }
168
172 protected static function getLPDataForUser(
173 int $a_obj_id,
174 int $a_user_id
175 ): int {
176 global $DIC;
177
178 $ilDB = $DIC['ilDB'];
179
180 $set = $ilDB->query(
181 "SELECT status" .
182 " FROM ut_lp_marks" .
183 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
184 " AND usr_id = " . $ilDB->quote($a_user_id, "integer")
185 );
186 $row = $ilDB->fetchAssoc($set);
187 $status = $row["status"];
188 if (!$status) {
189 $status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
190 }
191 return $status;
192 }
193
194 protected static function getPercentageForUser(
195 int $a_obj_id,
196 int $a_user_id
197 ): int {
198 global $DIC;
199
200 $ilDB = $DIC['ilDB'];
201
202 $set = $ilDB->query(
203 "SELECT percentage" .
204 " FROM ut_lp_marks" .
205 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
206 " AND usr_id = " . $ilDB->quote($a_user_id, "integer")
207 );
208 $row = $ilDB->fetchAssoc($set);
209 return (int) ($row["percentage"] ?? 0);
210 }
211}
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)
determineStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static getLPDataForUser(int $a_obj_id, int $a_user_id)
Read existing LP status data for user.
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: shib_login.php:26