ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilLPStatusIcons.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
27  public const ICON_VARIANT_LONG = 0;
28  public const ICON_VARIANT_SHORT = 1;
29  public const ICON_VARIANT_SCORM = 2;
31 
32  private static ?self $instance_variant_long = null;
33  private static ?self $instance_variant_short = null;
34  private static ?self $instance_variant_scorm = null;
35 
36  private string $image_path_in_progress = '';
37  private string $image_path_completed = '';
38  private string $image_path_not_attempted = '';
39  private string $image_path_failed = '';
40 
41  //The following two icons are not available as a long variant.
42  private string $image_path_asset = '';
43  private string $image_path_running = '';
44 
45  private \ILIAS\UI\Factory $factory;
46  private \ILIAS\UI\Renderer $renderer;
47 
48  public static function getInstance(int $variant = ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer = null, ?\ILIAS\UI\Factory $factory = null): ilLPStatusIcons
49  {
50  if (!$renderer || !$factory) {
51  global $DIC;
52  $renderer = $DIC->ui()->renderer();
53  $factory = $DIC->ui()->factory();
54  }
55 
56  switch ($variant) {
58  if (self::$instance_variant_scorm) {
59  return self::$instance_variant_scorm;
60  }
61  return self::$instance_variant_scorm = new self(ilLPStatusIcons::ICON_VARIANT_SCORM, $renderer, $factory);
62 
64  if (self::$instance_variant_short) {
65  return self::$instance_variant_short;
66  }
67  return self::$instance_variant_short = new self(ilLPStatusIcons::ICON_VARIANT_SHORT, $renderer, $factory);
68 
70  if (self::$instance_variant_long) {
71  return self::$instance_variant_long;
72  }
73  return self::$instance_variant_long = new self(ilLPStatusIcons::ICON_VARIANT_LONG, $renderer, $factory);
74 
75  default:
76  throw new ilLPException("No such variant of the LP icons exists.");
77  }
78  }
79 
80  private function __construct(int $variant, \ILIAS\UI\Renderer $renderer, \ILIAS\UI\Factory $factory)
81  {
82  $this->factory = $factory;
83  $this->renderer = $renderer;
84 
85  switch ($variant) {
87  $this->image_path_in_progress = $this->buildImagePath('scorm/incomplete.svg');
88  $this->image_path_completed = $this->buildImagePath('scorm/complete.svg');
89  $this->image_path_not_attempted = $this->buildImagePath('scorm/not_attempted.svg');
90  $this->image_path_failed = $this->buildImagePath('scorm/failed.svg');
91  $this->image_path_asset = $this->buildImagePath('scorm/asset.svg');
92  $this->image_path_running = $this->buildImagePath('scorm/running.svg');
93  break;
94 
96  $this->image_path_in_progress = $this->buildImagePath('learning_progress/short/in_progress.svg');
97  $this->image_path_completed = $this->buildImagePath('learning_progress/short/completed.svg');
98  $this->image_path_not_attempted = $this->buildImagePath('learning_progress/short/not_attempted.svg');
99  $this->image_path_failed = $this->buildImagePath('learning_progress/short/failed.svg');
100  $this->image_path_asset = $this->buildImagePath('learning_progress/short/asset.svg');
101  $this->image_path_running = $this->buildImagePath('learning_progress/short/running.svg');
102  break;
103 
105  $this->image_path_in_progress = $this->buildImagePath('learning_progress/in_progress.svg');
106  $this->image_path_completed = $this->buildImagePath('learning_progress/completed.svg');
107  $this->image_path_not_attempted = $this->buildImagePath('learning_progress/not_attempted.svg');
108  $this->image_path_failed = $this->buildImagePath('learning_progress/failed.svg');
109  break;
110 
111  default:
112  throw new ilLPException("No such variant of the LP icons exists.");
113  }
114  }
115 
116  protected function buildImagePath(string $image_name): string
117  {
118  return ilUtil::getImagePath($image_name);
119  }
120 
121  public function getImagePathInProgress(): string
122  {
124  }
125 
126  public function getImagePathCompleted(): string
127  {
129  }
130 
131  public function getImagePathNotAttempted(): string
132  {
134  }
135 
136  public function getImagePathFailed(): string
137  {
139  }
140 
144  public function getImagePathAsset(): string
145  {
146  if ($this->image_path_asset) {
148  }
149  throw new ilLPException("A long variant of the 'asset' LP icon does not exist.");
150  }
151 
155  public function getImagePathRunning(): string
156  {
157  if ($this->image_path_running) {
159  }
160  throw new ilLPException("A long variant of the 'running' LP icon does not exist.");
161  }
162 
163  public function renderIcon(string $path, string $alt): string
164  {
165  if ($this === self::$instance_variant_scorm) {
166  throw new ilLPException("SCORM variants of the LP icons cannot be rendered.");
167  }
168 
169  return $this->renderer->render($this->getIconComponent($path, $alt));
170  }
171 
172  public function getIconComponent(string $path, string $alt): \ILIAS\UI\Component\Symbol\Icon\Custom
173  {
174  return $this->factory->symbol()->icon()->custom($path, $alt, \ILIAS\UI\Component\Symbol\Icon\Icon::SMALL);
175  }
176 
180  public function getImagePathForStatus(int $a_status): string
181  {
182  switch ($a_status) {
184  return $this->getImagePathInProgress();
185 
187  return $this->getImagePathCompleted();
188 
190  return $this->getImagePathNotAttempted();
191 
193  return $this->getImagePathFailed();
194 
195  default:
196  return $this->getImagePathNotAttempted();
197  }
198  }
199 
203  public function renderIconForStatus(int $a_status, ?ilLanguage $a_lng = null): string
204  {
205  return $this->renderIcon(
206  $this->getImagePathForStatus($a_status),
208  );
209  }
210 
214  public function lookupNumStatus(string $a_status): int
215  {
216  switch ($a_status) {
219 
222 
225 
228 
229  default:
230  throw new ilLPException("Not a valid status");
231  }
232  }
233 }
const LP_STATUS_COMPLETED_NUM
Interface Observer Contains several chained tasks and infos about them.
factory()
const LP_STATUS_NOT_ATTEMPTED
renderer()
const LP_STATUS_IN_PROGRESS_NUM
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
static self $instance_variant_scorm
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
renderIconForStatus(int $a_status, ?ilLanguage $a_lng=null)
Returns the rendered icon with alt text.
$path
Definition: ltiservices.php:29
const LP_STATUS_IN_PROGRESS
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getIconComponent(string $path, string $alt)
__construct(int $variant, \ILIAS\UI\Renderer $renderer, \ILIAS\UI\Factory $factory)
const LP_STATUS_FAILED
getImagePathRunning()
A long variant of this icon is not available.
global $DIC
Definition: shib_login.php:22
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static _getStatusText(int $a_status, ?ilLanguage $a_lng=null)
Get status alt text.
renderIcon(string $path, string $alt)
ILIAS UI Factory $factory
ILIAS UI Renderer $renderer
static self $instance_variant_long
const LP_STATUS_NOT_ATTEMPTED_NUM
lookupNumStatus(string $a_status)
Transforms the string constants for the status to their interger equivalent.
buildImagePath(string $image_name)
getImagePathAsset()
A long variant of this icon is not available.
const LP_STATUS_COMPLETED
static self $instance_variant_short
const LP_STATUS_FAILED_NUM
getImagePathForStatus(int $a_status)