ILIAS  release_8 Revision v8.24
class.ilDidacticTemplateIconFactory.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
6
14
21{
23
27 private array $icon_types = [];
29 private array $assignments = [];
30
31 public function __construct()
32 {
33 global $DIC;
34
35 $this->definition = $DIC['objDefinition'];
36 $this->initTemplates();
37 }
38
40 {
41 if (!isset(self::$instance)) {
42 self::$instance = new self();
43 }
44
45 return self::$instance;
46 }
47
48 public function getIconPathForReference(int $ref_id): string
49 {
52
53 if (!$type || !$this->supportsCustomIcon($type)) {
54 return '';
55 }
56 $assigned_template = $this->findAssignedTemplate($ref_id);
57 if (!$assigned_template) {
58 return '';
59 }
60
61 $path = $this->getIconPathForTemplate($assigned_template);
62 return $path;
63 }
64
65 protected function getIconPathForTemplate(int $template_id): ?string
66 {
67 foreach ($this->settings->getTemplates() as $template) {
68 if ($template->getId() === $template_id) {
69 return $template->getIconHandler()->getAbsolutePath();
70 }
71 }
72
73 return null;
74 }
75
76 protected function findAssignedTemplate(int $ref_id): int
77 {
78 foreach ($this->assignments as $tpl_id => $assignments) {
79 if (in_array($ref_id, $assignments, true)) {
80 return $tpl_id;
81 }
82 }
83
84 return 0;
85 }
86
93 public function getIconPathForObject(int $obj_id): string
94 {
95 // no support for referenced objects
96 if (!$this->definition->isContainer(ilObject::_lookupType($obj_id))) {
97 return '';
98 }
99 $refs = ilObject::_getAllReferences($obj_id);
100 $ref_id = end($refs);
101
102 return $this->getIconPathForReference((int) $ref_id);
103 }
104
105 protected function supportsCustomIcon(string $type): bool
106 {
107 return in_array($type, $this->icon_types, true);
108 }
109
110 private function initTemplates(): void
111 {
113 $this->icon_types = [];
114
115 $templates = [];
116 foreach ($this->settings->getTemplates() as $tpl) {
117 if ($tpl->getIconIdentifier() !== '') {
118 $templates[] = $tpl->getId();
119 foreach ($tpl->getAssignments() as $assignment) {
120 if (!in_array($assignment, $this->icon_types, true)) {
121 $this->icon_types[] = $assignment;
122 }
123 }
124 }
125 }
126 $this->assignments = ilDidacticTemplateObjSettings::getAssignmentsForTemplates($templates);
127 }
128}
Icon factory for didactic template custom icons.
static ilDidacticTemplateIconFactory $instance
getIconPathForObject(int $obj_id)
Get icon path for object Not applicable to non container objects, use getIconPathForReference instead...
static getAssignmentsForTemplates(array $template_ids)
parses the objects.xml it handles the xml-description of all ilias objects
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
Interface Location.
Definition: Location.php:30
Interface Filesystem.
Definition: Filesystem.php:40
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$ref_id
Definition: ltiauth.php:67
$path
Definition: ltiservices.php:32
$type