ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLPStatusCourseReference.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
25{
29 private static $instances = [];
30
31 private int $target_obj_id = 0;
32 private array $status_info = [];
33
34 public function __construct(int $a_obj_id)
35 {
36 global $DIC;
37
38 parent::__construct($a_obj_id);
39 $this->readTargetObjId($a_obj_id);
40 $this->readStatusInfo($a_obj_id);
41 }
42
46 public static function _getCountNotAttempted(int $a_obj_id): int
47 {
48 $self = self::getInstanceByObjId($a_obj_id);
49 return count($self->getNotAttempted());
50 }
51
55 public static function _getNotAttempted(int $a_obj_id): array
56 {
57 $self = self::getInstanceByObjId($a_obj_id);
58 return $self->getNotAttempted();
59 }
60
64 public function getNotAttempted()
65 {
66 return $this->status_info[\ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM];
67 }
68
72 public static function _getCountInProgress(int $a_obj_id): int
73 {
74 $self = self::getInstanceByObjId($a_obj_id);
75 return count($self->getInProgress());
76 }
77
81 public static function _getInProgress(int $a_obj_id): array
82 {
83 $self = self::getInstanceByObjId($a_obj_id);
84 return $self->getInProgress();
85 }
86
90 public function getInProgress()
91 {
92 return $this->status_info[\ilLPStatus::LP_STATUS_IN_PROGRESS_NUM];
93 }
94
98 public static function _getCountCompleted(int $a_obj_id): int
99 {
100 $self = self::getInstanceByObjId($a_obj_id);
101 return count($self->getCompleted());
102 }
103
107 public static function _getCompleted(int $a_obj_id): array
108 {
109 $self = self::getInstanceByObjId($a_obj_id);
110 return $self->getCompleted();
111 }
112
116 public function getCompleted()
117 {
118 return $this->status_info[\ilLPStatus::LP_STATUS_COMPLETED_NUM];
119 }
120
124 public static function _getStatusInfo(int $a_obj_id): array
125 {
126 $self = self::getInstanceByObjId($a_obj_id);
127 return $self->getStatusInfo();
128 }
129
130 public function getStatusInfo()
131 {
132 return $this->status_info;
133 }
134
138 public function readStatusInfo(int $a_obj_id): void
139 {
140 global $DIC;
141
142 $database = $DIC->database();
143 $query = 'select status,usr_id from ut_lp_marks ' .
144 'where obj_id = ' . $database->quote(
145 $this->target_obj_id,
147 );
148 $res = $database->query($query);
149
150 $info = [
155 ];
156 while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
157 if (array_key_exists((int) $row->status, $info)) {
158 $info[(int) $row->status][] = (int) $row->usr_id;
159 }
160 }
161 $this->status_info = $info;
162 }
163
167 public function determineStatus(
168 int $a_obj_id,
169 int $a_usr_id,
170 ?object $a_obj = null
171 ): int {
172 $status = \ilLPStatus::_lookupStatus(
173 $this->target_obj_id,
174 $a_usr_id,
175 false
176 );
177 if ($status) {
178 return $status;
179 }
180 return \ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM;
181 }
182
183 private static function getInstanceByObjId(
184 int $a_reference_obj_id
186 if (!isset(self::$instances[$a_reference_obj_id])) {
187 self::$instances[$a_reference_obj_id] = new self(
188 $a_reference_obj_id
189 );
190 }
191 return self::$instances[$a_reference_obj_id];
192 }
193
194 private function readTargetObjId(int $a_obj_id): void
195 {
196 $this->target_obj_id = ilObject::_lookupObjId(
198 );
199 }
200}
static _lookupTargetRefId(int $a_obj_id)
Class ilLPStatusCourseReference.
static getInstanceByObjId(int $a_reference_obj_id)
determineStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static _getCompleted(int $a_obj_id)
int[]
static _getNotAttempted(int $a_obj_id)
int[]
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 _lookupStatus(int $a_obj_id, int $a_user_id, bool $a_create=true)
Lookup status.
const LP_STATUS_FAILED_NUM
static _lookupObjId(int $ref_id)
$info
Definition: entry_point.php:21
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26