ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilFooterTranslationGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
31 use ILIAS\Data\URI;
32 
40 {
41  use Hasher;
42  use UIHelper;
43 
44  public const CMD_DEFAULT = 'index';
45  public const CMD_LANGUAGE_SELECTION = 'selectLanguages';
46  public const CMD_SAVE_LANGUAGE_SELECTION = 'saveLanguages';
47  public const CMD_TRANSLATE_IN_MODAL = 'translateInAsyncModal';
48  public const CMD_SAVE_TRANSLATIONS = 'saveTranslations';
54 
55  public function __construct(
56  private Container $dic,
57  private Translator $translator,
58  private ilObjFooterUIHandling $ui_handling,
59  private TranslatableItem $translatable_item,
60  private ?URI $back_target = null
61  ) {
62  $this->ui_factory = $this->dic->ui()->factory();
63  $this->ctrl = $this->dic->ctrl();
64  $this->request = $this->dic->http()->request();
65 
67  $this->dic->database()
68  );
69 
70  $this->workflow = new TranslationWorkflowForm(
71  $this->dic->learningObjectMetadata(),
72  $this->dic->ui(),
74  $this->translatable_item,
75  );
76  }
77 
78  private function index(): void
79  {
80  // LISTING
81  $translations = $this->repository->get($this->translatable_item);
82  if ($translations->get() === []) {
83  $content = $this->ui_factory->messageBox()->info(
84  $this->translator->translate('no_translations')
85  );
86  } else {
87  $items = [];
88  foreach ($translations->get() as $t) {
89  $items[$this->translator->translate('meta_l_' . $t->getLanguageCode())] = $t->getTranslation();
90  }
91  $content = $this->ui_factory->listing()->descriptive(
92  $items
93  );
94  $content = $this->back_target === null ? $this->ui_factory->panel()->secondary()->legacy(
95  $this->translator->translate('translations'),
96  $this->ui_factory->legacy(
97  $this->ui_handling->render($content)
98  )
99  ) : $content;
100  }
101 
102  $prompt = $this->ui_factory->prompt()->standard(
103  $this->ui_handling->getHereAsURI(self::CMD_LANGUAGE_SELECTION)
104  );
105 
106  // Edit Button
107  $edit_button = $this->ui_factory
108  ->button()
109  ->standard(
110  $this->translator->translate('edit_translations'),
111  '#'
112  )
113  ->withOnClick($prompt->getShowSignal());
114 
115  $this->dic->toolbar()->addComponent(
116  $edit_button
117  );
118 
119  if ($this->back_target === null) {
120  $this->ui_handling->out(
121  $prompt,
122  $content
123  );
124  return;
125  }
126 
127  $this->ui_handling->outAsyncAsModal(
128  'Translations',
129  (string) $this->back_target,
130  $edit_button,
131  $this->ui_factory->divider()->horizontal(),
132  $prompt,
133  $content
134  );
135  }
136 
137  private function selectLanguages(): void
138  {
139  $this->ui_handling->outAsync(
140  $this->workflow->asTranslationWorkflow(
141  $this->ui_handling->getHereAsURI(),
142  $this->back_target ?? $this->ui_handling->getHereAsURI(self::CMD_DEFAULT)
143  )
144  );
145  }
146 
147  private function translateInAsyncModal(): void
148  {
149  $this->ui_handling->outAsync(
150  $this->workflow->asTranslationModal(
151  $this->ui_handling->getHereAsURI(self::CMD_SAVE_TRANSLATIONS)
152  )
153  );
154  }
155 
156  private function saveTranslations(): void
157  {
158  $form = $this->workflow->asTranslationModal(
159  $this->ui_handling->getHereAsURI(self::CMD_SAVE_TRANSLATIONS)
160  );
161  $form = $form->withRequest($this->request);
162  if (($data = $form->getData()) === null) {
163  $this->ui_handling->outAsync($form);
164  return;
165  }
166  $this->ctrl->redirectToURL(
167  (string) ($this->back_target ?? $this->ui_handling->getHereAsURI(self::CMD_DEFAULT))
168  );
169  }
170 
171  // HELPERS AND NEEDED IMPLEMENATIONS
172 
173  public function executeCommand(): void
174  {
175  $this->ui_handling->requireReadable();
176 
177  $next_class = $this->ctrl->getNextClass($this) ?? '';
178  $cmd = $this->ctrl->getCmd(self::CMD_DEFAULT);
179 
180  switch ($cmd) {
181  case self::CMD_DEFAULT:
182  case self::CMD_LANGUAGE_SELECTION:
183  case self::CMD_SAVE_LANGUAGE_SELECTION:
184  case self::CMD_TRANSLATE_IN_MODAL:
185  case self::CMD_SAVE_TRANSLATIONS:
186  default:
187  $this->ui_handling->backToMainTab();
188  $this->ui_handling->requireWritable();
189  $this->$cmd();
190  break;
191  }
192  }
193 
194 }
repository()
description: > Example for rendering a repository card
Definition: repository.php:17
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
TranslationsRepository $repository
This is how the factory for UI elements looks.
Definition: Factory.php:37
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:34
__construct(private Container $dic, private Translator $translator, private ilObjFooterUIHandling $ui_handling, private TranslatableItem $translatable_item, private ?URI $back_target=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$dic
Definition: ltiresult.php:33
TranslationWorkflowForm $workflow