ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
IconListingUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\File\Icon;
22 
24 
29 {
30  private \ilCtrl $ctrl;
31  private \ilLanguage $lng;
32  private \ILIAS\UI\Factory $ui_factory;
33  private \ILIAS\Refinery\Factory $refinery;
34  private \ILIAS\ResourceStorage\Services $storage;
35  private array $deletion_modals = [];
36  private \ILIAS\UI\Component\Panel\Listing\Standard $icon_list;
37  private \ilUIFilterService $filter_service;
38  private \ILIAS\UI\Component\Input\Container\Filter\Standard $filter;
39  private \ILIAS\HTTP\Services $http;
40 
41  public function __construct(
42  private IconRepositoryInterface $icon_repo,
43  private object $gui
44  ) {
45  global $DIC;
46 
47  $this->ctrl = $DIC->ctrl();
48  $this->lng = $DIC->language();
49  $this->lng->loadLanguageModule('file');
50  $this->ui_factory = $DIC->ui()->factory();
51  $this->refinery = $DIC->refinery();
52  $this->storage = $DIC->resourceStorage();
53  $this->http = $DIC->http();
54  $this->filter_service = $DIC->uiService()->filter();
55 
56  $this->initFilter();
57  $this->initListing();
58  }
59 
60  private function initFilter(): void
61  {
62  // Filters
63  $this->filter = $this->filter_service->standard(
64  $this->gui::class . '_filter7',
65  $this->ctrl->getLinkTarget($this->gui),
66  [
67  'suffixes' => $this->ui_factory->input()->field()->text($this->lng->txt('suffixes')),
68  'active' => $this->ui_factory->input()->field()->select($this->lng->txt('status'), [
69  '1' => $this->lng->txt('active'),
70  '0' => $this->lng->txt('inactive'),
71  ])->withValue('1'),
72  'is_default_icon' => $this->ui_factory->input()->field()->select($this->lng->txt('default'), [
73  '1' => $this->lng->txt('yes'),
74  '0' => $this->lng->txt('no'),
75  ])
76  ],
77  [
78  'suffix' => true,
79  'status' => true,
80  'type' => true,
81  ],
82  true,
83  true
84  );
85  }
86 
87  public function getFilter(): \ILIAS\UI\Component\Input\Container\Filter\Standard
88  {
89  return $this->filter;
90  }
91 
92  protected function initListing(): void
93  {
94  $icon_items = [];
95  $this->icon_repo->getIcons();
96 
97  // Filterting
98  $filter_data = $this->filter_service->getData($this->filter) ?? [];
99 
100  foreach ($this->icon_repo->getIconsForFilter($filter_data) as $icon) {
101  $this->ctrl->setParameterByClass(
102  ilObjFileIconsOverviewGUI::class,
104  $icon->getRid()
105  );
106  $edit_target = $this->ctrl->getLinkTargetByClass(
107  ilObjFileIconsOverviewGUI::class,
109  );
110  $change_activation_target = $this->ctrl->getLinkTargetByClass(
111  ilObjFileIconsOverviewGUI::class,
113  );
114  $this->deletion_modals[] = $deletion_modal = $this->getDeletionConfirmationModal($icon);
115 
116  $item_action_entries = [
117  $this->ui_factory->button()->shy(
118  $this->lng->txt('de_activate_icon'),
119  $change_activation_target
120  )
121  ];
122  if (!$icon->isDefaultIcon()) {
123  $item_action_entries[] = $this->ui_factory->button()->shy($this->lng->txt('edit'), $edit_target);
124  $item_action_entries[] = $this->ui_factory->button()->shy($this->lng->txt('delete'), '#')->withOnClick(
125  $deletion_modal->getShowSignal()
126  );
127  }
128  $item_actions = $this->ui_factory->dropdown()->standard($item_action_entries);
129 
130  $id = $this->storage->manage()->find($icon->getRid());
131  $icon_src = "";
132  if ($id !== null) {
133  $icon_src = $this->storage->consume()->src($id)->getSrc();
134  }
135 
136  $suffixes_array_into_string = $this->icon_repo->turnSuffixesArrayIntoString(
137  $icon->getSuffixes()
138  );
139 
140  $icon_image = $this->ui_factory->symbol()->icon()->custom(
141  $icon_src,
142  "Icon $suffixes_array_into_string"
143  )->withSize('large');
144 
145  $icon_items[] = $this->ui_factory->item()
146  ->standard($this->lng->txt('icon') . " $suffixes_array_into_string")
147  ->withActions($item_actions)
148  ->withProperties(
149  [
150  $this->lng->txt('active') => $icon->isActive() ? $this->lng->txt(
151  'yes'
152  ) : $this->lng->txt('no'),
153  $this->lng->txt('default') => $icon->isDefaultIcon(
154  ) ? $this->lng->txt('yes') : $this->lng->txt('no'),
155  $this->lng->txt(
156  'suffixes'
157  ) => $suffixes_array_into_string
158  ]
159  )
160  ->withLeadIcon($icon_image);
161  }
162 
163  $this->icon_list = $this->ui_factory->panel()->listing()->standard(
164  $this->lng->txt('suffix_specific_icons'),
165  [$this->ui_factory->item()->group("", $icon_items)]
166  );
167  }
168 
169  public function getIconList(): \ILIAS\UI\Component\Panel\Listing\Standard
170  {
171  return $this->icon_list;
172  }
173 
177  public function getDeletionModals(): array
178  {
179  return $this->deletion_modals;
180  }
181 
182  private function getDeletionConfirmationModal(Icon $a_icon): Interruptive
183  {
184  $target = $this->ctrl->getLinkTargetByClass(
185  ilObjFileIconsOverviewGUI::class,
187  );
188  $rid = $this->refinery->kindlyTo()->string()->transform($a_icon->getRid());
189 
190  $id = $this->storage->manage()->find($rid);
191  $icon_src = "";
192  if ($id !== null) {
193  $icon_src = $this->storage->consume()->src($id)->getSrc();
194  }
195  $img_icon = $this->ui_factory->image()->standard(
196  $icon_src,
197  "Icon"
198  );
199  $txt_suffixes = $this->lng->txt('suffixes') . ": " . $this->icon_repo->turnSuffixesArrayIntoString(
200  $a_icon->getSuffixes()
201  );
202 
203  return $this->ui_factory->modal()->interruptive(
204  $this->lng->txt("delete"),
205  $this->lng->txt('msg_confirm_entry_deletion'),
206  $target
207  )->withAffectedItems([
208  $this->ui_factory->modal()->interruptiveItem()->standard(
209  $rid,
210  $txt_suffixes,
211  $img_icon
212  )
213  ]);
214  }
215 }
ILIAS ResourceStorage Services $storage
ILIAS Refinery Factory $refinery
ILIAS UI Component Input Container Filter Standard $filter
ilUIFilterService $filter_service
Interface Observer Contains several chained tasks and infos about them.
ILIAS HTTP Services $http
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
ILIAS UI Component Panel Listing Standard $icon_list
global $DIC
Definition: shib_login.php:25
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
__construct(private IconRepositoryInterface $icon_repo, private object $gui)
getDeletionConfirmationModal(Icon $a_icon)