ILIAS  release_8 Revision v8.24
class.ilLPStatusIcons.php
Go to the documentation of this file.
1<?php
2
24{
25 public const ICON_VARIANT_LONG = 0;
26 public const ICON_VARIANT_SHORT = 1;
27 public const ICON_VARIANT_SCORM = 2;
29
30 private static ?self $instance_variant_long = null;
31 private static ?self $instance_variant_short = null;
32 private static ?self $instance_variant_scorm = null;
33
34 private string $image_path_in_progress = '';
35 private string $image_path_completed = '';
36 private string $image_path_not_attempted = '';
37 private string $image_path_failed = '';
38
39 //The following two icons are not available as a long variant.
40 private string $image_path_asset = '';
41 private string $image_path_running = '';
42
43 private \ILIAS\UI\Factory $factory;
44 private \ILIAS\UI\Renderer $renderer;
45
46 public static function getInstance(int $variant = ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer = null, ?\ILIAS\UI\Factory $factory = null): ilLPStatusIcons
47 {
48 if (!$renderer || !$factory) {
49 global $DIC;
50 $renderer = $DIC->ui()->renderer();
51 $factory = $DIC->ui()->factory();
52 }
53
54 switch ($variant) {
56 if (self::$instance_variant_scorm) {
58 }
59 return self::$instance_variant_scorm = new self(ilLPStatusIcons::ICON_VARIANT_SCORM, $renderer, $factory);
60
62 if (self::$instance_variant_short) {
64 }
65 return self::$instance_variant_short = new self(ilLPStatusIcons::ICON_VARIANT_SHORT, $renderer, $factory);
66
68 if (self::$instance_variant_long) {
70 }
71 return self::$instance_variant_long = new self(ilLPStatusIcons::ICON_VARIANT_LONG, $renderer, $factory);
72
73 default:
74 throw new ilLPException("No such variant of the LP icons exists.");
75 }
76 }
77
78 private function __construct(int $variant, \ILIAS\UI\Renderer $renderer, \ILIAS\UI\Factory $factory)
79 {
80 $this->factory = $factory;
81 $this->renderer = $renderer;
82
83 switch ($variant) {
85 $this->image_path_in_progress = ilUtil::getImagePath('scorm/incomplete.svg');
86 $this->image_path_completed = ilUtil::getImagePath('scorm/complete.svg');
87 $this->image_path_not_attempted = ilUtil::getImagePath('scorm/not_attempted.svg');
88 $this->image_path_failed = ilUtil::getImagePath('scorm/failed.svg');
89 $this->image_path_asset = ilUtil::getImagePath('scorm/asset.svg');
90 $this->image_path_running = ilUtil::getImagePath('scorm/running.svg');
91 break;
92
94 $this->image_path_in_progress = ilUtil::getImagePath('learning_progress/short/in_progress.svg');
95 $this->image_path_completed = ilUtil::getImagePath('learning_progress/short/completed.svg');
96 $this->image_path_not_attempted = ilUtil::getImagePath('learning_progress/short/not_attempted.svg');
97 $this->image_path_failed = ilUtil::getImagePath('learning_progress/short/failed.svg');
98 $this->image_path_asset = ilUtil::getImagePath('learning_progress/short/asset.svg');
99 $this->image_path_running = ilUtil::getImagePath('learning_progress/short/running.svg');
100 break;
101
103 $this->image_path_in_progress = ilUtil::getImagePath('learning_progress/in_progress.svg');
104 $this->image_path_completed = ilUtil::getImagePath('learning_progress/completed.svg');
105 $this->image_path_not_attempted = ilUtil::getImagePath('learning_progress/not_attempted.svg');
106 $this->image_path_failed = ilUtil::getImagePath('learning_progress/failed.svg');
107 break;
108
109 default:
110 throw new ilLPException("No such variant of the LP icons exists.");
111 }
112 }
113
114 public function getImagePathInProgress(): string
115 {
117 }
118
119 public function getImagePathCompleted(): string
120 {
122 }
123
124 public function getImagePathNotAttempted(): string
125 {
127 }
128
129 public function getImagePathFailed(): string
130 {
132 }
133
137 public function getImagePathAsset(): string
138 {
139 if ($this->image_path_asset) {
141 }
142 throw new ilLPException("A long variant of the 'asset' LP icon does not exist.");
143 }
144
148 public function getImagePathRunning(): string
149 {
150 if ($this->image_path_running) {
152 }
153 throw new ilLPException("A long variant of the 'running' LP icon does not exist.");
154 }
155
156 public function renderIcon(string $path, string $alt): string
157 {
158 if ($this === self::$instance_variant_scorm) {
159 throw new ilLPException("SCORM variants of the LP icons cannot be rendered.");
160 }
161
162 return $this->renderer->render($this->getIconComponent($path, $alt));
163 }
164
165 public function getIconComponent(string $path, string $alt): \ILIAS\UI\Component\Symbol\Icon\Custom
166 {
167 return $this->factory->symbol()->icon()->custom($path, $alt, \ILIAS\UI\Component\Symbol\Icon\Icon::SMALL);
168 }
169
173 public function getImagePathForStatus(int $a_status): string
174 {
175 switch ($a_status) {
177 return $this->getImagePathInProgress();
178
180 return $this->getImagePathCompleted();
181
183 return $this->getImagePathNotAttempted();
184
186 return $this->getImagePathFailed();
187
188 default:
189 return $this->getImagePathNotAttempted();
190 }
191 }
192
196 public function renderIconForStatus(int $a_status, ?ilLanguage $a_lng = null): string
197 {
198 return $this->renderIcon(
199 $this->getImagePathForStatus($a_status),
201 );
202 }
203
207 public function lookupNumStatus(string $a_status): int
208 {
209 switch ($a_status) {
212
215
218
221
222 default:
223 throw new ilLPException("Not a valid status");
224 }
225 }
226}
Base class for learning progress exceptions.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
static self $instance_variant_short
getIconComponent(string $path, string $alt)
ILIAS UI Renderer $renderer
renderIconForStatus(int $a_status, ?ilLanguage $a_lng=null)
Returns the rendered icon with alt text.
ILIAS UI Factory $factory
getImagePathRunning()
A long variant of this icon is not available.
static self $instance_variant_scorm
renderIcon(string $path, string $alt)
getImagePathForStatus(int $a_status)
__construct(int $variant, \ILIAS\UI\Renderer $renderer, \ILIAS\UI\Factory $factory)
getImagePathAsset()
A long variant of this icon is not available.
lookupNumStatus(string $a_status)
Transforms the string constants for the status to their interger equivalent.
static self $instance_variant_long
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_COMPLETED
const LP_STATUS_FAILED
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
const LP_STATUS_FAILED_NUM
const LP_STATUS_NOT_ATTEMPTED
const LP_STATUS_IN_PROGRESS
language handling
static _getStatusText(int $a_status, ?ilLanguage $a_lng=null)
Get status alt text.
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: feed.php:28
$path
Definition: ltiservices.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.