ILIAS  release_7 Revision v7.30-3-g800a261c036
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
33 private static $instance_variant_long = null;
37 private static $instance_variant_short = null;
41 private static $instance_variant_scorm = null;
42
46 private $image_path_failed = '';
47
48 //The following two icons are not available as a long variant.
49 private $image_path_asset = '';
50 private $image_path_running = '';
51
55 private $factory;
59 private $renderer;
60
61 public static function getInstance(int $variant = ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer = null, ?\ILIAS\UI\Factory $factory = null) : ilLPStatusIcons
62 {
63 if (!$renderer || !$factory) {
64 global $DIC;
65 $renderer = $DIC->ui()->renderer();
66 $factory = $DIC->ui()->factory();
67 }
68
69 switch ($variant) {
71 if (self::$instance_variant_scorm) {
73 }
74 return self::$instance_variant_scorm = new self(ilLPStatusIcons::ICON_VARIANT_SCORM, $renderer, $factory);
75
77 if (self::$instance_variant_short) {
79 }
80 return self::$instance_variant_short = new self(ilLPStatusIcons::ICON_VARIANT_SHORT, $renderer, $factory);
81
83 if (self::$instance_variant_long) {
85 }
86 return self::$instance_variant_long = new self(ilLPStatusIcons::ICON_VARIANT_LONG, $renderer, $factory);
87
88 default:
89 throw new ilLPException("No such variant of the LP icons exists.");
90 }
91 }
92
93 private function __construct(int $variant, \ILIAS\UI\Renderer $renderer, \ILIAS\UI\Factory $factory)
94 {
95 $this->factory = $factory;
96 $this->renderer = $renderer;
97
98 switch ($variant) {
100 $this->image_path_in_progress = ilUtil::getImagePath('scorm/incomplete.svg');
101 $this->image_path_completed = ilUtil::getImagePath('scorm/complete.svg');
102 $this->image_path_not_attempted = ilUtil::getImagePath('scorm/not_attempted.svg');
103 $this->image_path_failed = ilUtil::getImagePath('scorm/failed.svg');
104 $this->image_path_asset = ilUtil::getImagePath('scorm/asset.svg');
105 $this->image_path_running = ilUtil::getImagePath('scorm/running.svg');
106 break;
107
109 $this->image_path_in_progress = ilUtil::getImagePath('learning_progress/short/in_progress.svg');
110 $this->image_path_completed = ilUtil::getImagePath('learning_progress/short/completed.svg');
111 $this->image_path_not_attempted = ilUtil::getImagePath('learning_progress/short/not_attempted.svg');
112 $this->image_path_failed = ilUtil::getImagePath('learning_progress/short/failed.svg');
113 $this->image_path_asset = ilUtil::getImagePath('learning_progress/short/asset.svg');
114 $this->image_path_running = ilUtil::getImagePath('learning_progress/short/running.svg');
115 break;
116
118 $this->image_path_in_progress = ilUtil::getImagePath('learning_progress/in_progress.svg');
119 $this->image_path_completed = ilUtil::getImagePath('learning_progress/completed.svg');
120 $this->image_path_not_attempted = ilUtil::getImagePath('learning_progress/not_attempted.svg');
121 $this->image_path_failed = ilUtil::getImagePath('learning_progress/failed.svg');
122 break;
123
124 default:
125 throw new ilLPException("No such variant of the LP icons exists.");
126 }
127 }
128
129 public function getImagePathInProgress() : string
130 {
132 }
133
134 public function getImagePathCompleted() : string
135 {
137 }
138
139 public function getImagePathNotAttempted() : string
140 {
142 }
143
144 public function getImagePathFailed() : string
145 {
147 }
148
152 public function getImagePathAsset() : string
153 {
154 if ($this->image_path_asset) {
156 }
157 throw new ilLPException("A long variant of the 'asset' LP icon does not exist.");
158 }
159
163 public function getImagePathRunning() : string
164 {
165 if ($this->image_path_running) {
167 }
168 throw new ilLPException("A long variant of the 'running' LP icon does not exist.");
169 }
170
171 public function renderIcon(string $path, string $alt) : string
172 {
173 if ($this === self::$instance_variant_scorm) {
174 throw new ilLPException("SCORM variants of the LP icons cannot be rendered.");
175 }
176
177 return $this->renderer->render($this->getIconComponent($path, $alt));
178 }
179
180 public function getIconComponent(string $path, string $alt) : \ILIAS\UI\Component\Symbol\Icon\Custom
181 {
182 return $this->factory->symbol()->icon()->custom($path, $alt, \ILIAS\UI\Component\Symbol\Icon\Icon::SMALL);
183 }
184
188 public function getImagePathForStatus(int $a_status) : string
189 {
190 switch ($a_status) {
192 return $this->getImagePathInProgress();
193
195 return $this->getImagePathCompleted();
196
198 return $this->getImagePathNotAttempted();
199
201 return $this->getImagePathFailed();
202
203 default:
204 return $this->getImagePathNotAttempted();
205 }
206 }
207
211 public function renderIconForStatus(int $a_status, ?ilLanguage $a_lng = null) : string
212 {
213 return $this->renderIcon(
214 $this->getImagePathForStatus($a_status),
216 );
217 }
218
222 public function lookupNumStatus(string $a_status) : int
223 {
224 switch ($a_status) {
227
230
233
236
237 default:
238 throw new ilLPException("Not a valid status");
239 }
240 }
241}
An exception for terminatinating execution or to throw for unit testing.
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)
getIconComponent(string $path, string $alt)
renderIconForStatus(int $a_status, ?ilLanguage $a_lng=null)
Returns the rendered icon with alt text.
getImagePathRunning()
A long variant of this icon is not available.
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.
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($a_status, $a_lng=null)
Get status alt text.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: goto.php:24
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.