ILIAS  release_8 Revision v8.24
class.ilLPStatusCourseReference.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{
15 private static $instances = [];
16
17 private int $target_obj_id = 0;
18 private array $status_info = [];
19
20 public function __construct(int $a_obj_id)
21 {
22 global $DIC;
23
24 parent::__construct($a_obj_id);
25 $this->readTargetObjId($a_obj_id);
26 $this->readStatusInfo($a_obj_id);
27 }
28
32 public static function _getCountNotAttempted(int $a_obj_id): int
33 {
34 $self = self::getInstanceByObjId($a_obj_id);
35 return count($self->getNotAttempted());
36 }
37
41 public static function _getNotAttempted(int $a_obj_id): array
42 {
43 $self = self::getInstanceByObjId($a_obj_id);
44 return $self->getNotAttempted();
45 }
46
50 public function getNotAttempted()
51 {
52 return $this->status_info[\ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM];
53 }
54
58 public static function _getCountInProgress(int $a_obj_id): int
59 {
60 $self = self::getInstanceByObjId($a_obj_id);
61 return count($self->getInProgress());
62 }
63
67 public static function _getInProgress(int $a_obj_id): array
68 {
69 $self = self::getInstanceByObjId($a_obj_id);
70 return $self->getInProgress();
71 }
72
76 public function getInProgress()
77 {
78 return $this->status_info[\ilLPStatus::LP_STATUS_IN_PROGRESS_NUM];
79 }
80
84 public static function _getCountCompleted(int $a_obj_id): int
85 {
86 $self = self::getInstanceByObjId($a_obj_id);
87 return count($self->getCompleted());
88 }
89
93 public static function _getCompleted(int $a_obj_id): array
94 {
95 $self = self::getInstanceByObjId($a_obj_id);
96 return $self->getCompleted();
97 }
98
102 public function getCompleted()
103 {
104 return $this->status_info[\ilLPStatus::LP_STATUS_COMPLETED_NUM];
105 }
106
110 public static function _getStatusInfo(int $a_obj_id): array
111 {
112 $self = self::getInstanceByObjId($a_obj_id);
113 return $self->getStatusInfo();
114 }
115
116 public function getStatusInfo()
117 {
118 return $this->status_info;
119 }
120
124 public function readStatusInfo(int $a_obj_id): void
125 {
126 global $DIC;
127
128 $database = $DIC->database();
129 $query = 'select status,usr_id from ut_lp_marks ' .
130 'where obj_id = ' . $database->quote(
131 $this->target_obj_id,
133 );
134 $res = $database->query($query);
135
136 $info = [
141 ];
142 while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
143 if (array_key_exists((int) $row->status, $info)) {
144 $info[(int) $row->status][] = (int) $row->usr_id;
145 }
146 }
147 $this->status_info = $info;
148 }
149
153 public function determineStatus(
154 int $a_obj_id,
155 int $a_usr_id,
156 object $a_obj = null
157 ): int {
158 $status = \ilLPStatus::_lookupStatus(
159 $this->target_obj_id,
160 $a_usr_id,
161 false
162 );
163 if ($status) {
164 return $status;
165 }
166 return \ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM;
167 }
168
169 private static function getInstanceByObjId(
170 int $a_reference_obj_id
172 if (!isset(self::$instances[$a_reference_obj_id])) {
173 self::$instances[$a_reference_obj_id] = new self(
174 $a_reference_obj_id
175 );
176 }
177 return self::$instances[$a_reference_obj_id];
178 }
179
180 private function readTargetObjId(int $a_obj_id): void
181 {
182 $this->target_obj_id = ilObject::_lookupObjId(
184 );
185 }
186}
static _lookupTargetRefId(int $a_obj_id)
Class ilLPStatusCourseReference.
static getInstanceByObjId(int $a_reference_obj_id)
static _getCompleted(int $a_obj_id)
int[]
determineStatus(int $a_obj_id, int $a_usr_id, object $a_obj=null)
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)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$query