ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLTIConsumerSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
33 {
34  public const SUBTAB_ID_OBJECT_SETTINGS = 'subtab_object_settings';
35  public const SUBTAB_ID_PROVIDER_SETTINGS = 'subtab_provider_settings';
36  public const SUBTAB_ID_CERTIFICATE = 'subtab_certificate';
37 
38  public const CMD_SHOW_SETTINGS = 'showSettings';
39  public const CMD_SAVE_SETTINGS = 'saveSettings';
40  public const CMD_DELIVER_CERTIFICATE = 'deliverCertificate';
41 
46 
51  private \ilGlobalTemplateInterface $main_tpl;
52 
56  public function __construct(ilObjLTIConsumer $object, ilLTIConsumerAccess $access)
57  {
58  global $DIC;
59  $this->main_tpl = $DIC->ui()->mainTemplate();
60  $this->object = $object;
61  $this->access = $access;
62  }
63 
64  protected function initSubTabs(): void
65  {
66  global $DIC; /* @var \ILIAS\DI\Container $DIC */
67  $DIC->language()->loadLanguageModule('lti');
68 
69  $DIC->tabs()->addSubTab(
70  self::SUBTAB_ID_OBJECT_SETTINGS,
71  $DIC->language()->txt(self::SUBTAB_ID_OBJECT_SETTINGS),
72  $DIC->ctrl()->getLinkTarget($this)
73  );
74 
75  if ($this->needsProviderSettingsSubTab()) {
76  $DIC->tabs()->addSubTab(
77  self::SUBTAB_ID_PROVIDER_SETTINGS,
78  $DIC->language()->txt(self::SUBTAB_ID_PROVIDER_SETTINGS),
79  $DIC->ctrl()->getLinkTargetByClass(ilLTIConsumeProviderSettingsGUI::class)
80  );
81  }
82 
83  $validator = new ilCertificateActiveValidator();
84 
85  if ($validator->validate()) {
86  $DIC->tabs()->addSubTab(
87  self::SUBTAB_ID_CERTIFICATE,
88  $DIC->language()->txt(self::SUBTAB_ID_CERTIFICATE),
89  $DIC->ctrl()->getLinkTargetByClass(ilCertificateGUI::class, 'certificateEditor')
90  );
91  }
92  }
93 
94  protected function needsProviderSettingsSubTab(): bool
95  {
96  global $DIC; /* @var \ILIAS\DI\Container $DIC */
97 
98  if ($this->object->getProvider()->isGlobal()) {
99  return false;
100  }
101 
102  if ($this->object->getProvider()->getCreator() != $DIC->user()->getId()) {
103  return false;
104  }
105 
106  return true;
107  }
108 
110  {
111  global $DIC;
112  if (!ilSession::has('lti_dynamic_registration_client_id')) {
113  return false;
114  }
115  if ($provider->getCreator() != $DIC->user()->getId()) {
116  return false;
117  }
118  if ($provider->getClientId() == ilSession::get('lti_dynamic_registration_client_id')) {
119  return true;
120  }
121  return false;
122  }
123 
127  public function executeCommand(): void
128  {
129  global $DIC; /* @var \ILIAS\DI\Container $DIC */
130  $access = $DIC->access();
131 
132  if (!$access->checkAccess('write', '', $this->object->getRefId())) {
133  $DIC->ui()->mainTemplate()->setOnScreenMessage('failure', $DIC->language()->txt('permission_denied'), true);
134  } else {
135 
136  $this->initSubTabs();
137 
138  $nc = $DIC->ctrl()->getNextClass();
139 
140  switch ($nc) {
141  case strtolower(ilCertificateGUI::class):
142 
143  $validator = new ilCertificateActiveValidator();
144 
145  if (!$validator->validate()) {
146  throw new ilCmiXapiException('access denied!');
147  }
148 
149  $DIC->tabs()->activateSubTab(self::SUBTAB_ID_CERTIFICATE);
150 
151  $guiFactory = new ilCertificateGUIFactory();
152  $gui = $guiFactory->create($this->object);
153 
154  $DIC->ctrl()->forwardCommand($gui);
155 
156  break;
157 
158  case strtolower(ilLTIConsumeProviderSettingsGUI::class):
159 
160  $DIC->tabs()->activateSubTab(self::SUBTAB_ID_PROVIDER_SETTINGS);
161 
162  $gui = new ilLTIConsumeProviderSettingsGUI($this->object, $this->access);
163  $DIC->ctrl()->forwardCommand($gui);
164  break;
165 
166  default:
167  $DIC->tabs()->activateSubTab(self::SUBTAB_ID_OBJECT_SETTINGS);
168  $command = $DIC->ctrl()->getCmd(self::CMD_SHOW_SETTINGS) . 'Cmd';
169  $this->{$command}();
170 
171  }
172  }
173  }
174 
175  protected function showSettingsCmd(ilLTIConsumerSettingsFormGUI $form = null): void
176  {
177  global $DIC; /* @var \ILIAS\DI\Container $DIC */
178 
179  if ($form === null) {
180  $form = $this->buildForm();
181  }
182 
183  $DIC->ui()->mainTemplate()->setContent($form->getHTML());
184  }
185 
186  protected function saveSettingsCmd(): void
187  {
188  global $DIC; /* @var \ILIAS\DI\Container $DIC */
189 
190  $form = $this->buildForm();
191 
192  if ($form->checkInput()) {
193  $oldMasteryScore = $this->object->getMasteryScore();
194 
195  $form->initObject($this->object);
196  $this->object->update();
197 
198  if ($oldMasteryScore !== $this->object->getMasteryScore()) {
199  ilLPStatusWrapper::_refreshStatus($this->object->getId());
200  }
201 
202  $this->main_tpl->setOnScreenMessage('success', $DIC->language()->txt('msg_obj_modified'), true);
203  $DIC->ctrl()->redirect($this, self::CMD_SHOW_SETTINGS);
204  }
205 
206  $this->showSettingsCmd($form);
207  }
208 
210  {
211  global $DIC; /* @var \ILIAS\DI\Container $DIC */
212 
213  $form = new ilLTIConsumerSettingsFormGUI(
214  $this->object,
215  $DIC->ctrl()->getFormAction($this),
216  self::CMD_SAVE_SETTINGS,
217  self::CMD_SHOW_SETTINGS
218  );
219 
220  return $form;
221  }
222 
223  protected function deliverCertificateCmd(): void
224  {
225  global $DIC; /* @var \ILIAS\DI\Container $DIC */
226 
227  $validator = new ilCertificateDownloadValidator();
228 
229  if (!$validator->isCertificateDownloadable($DIC->user()->getId(), $this->object->getId())) {
230  $this->main_tpl->setOnScreenMessage('failure', $DIC->language()->txt("permission_denied"), true);
231  $DIC->ctrl()->redirectByClass(ilObjLTIConsumerGUI::class, ilObjLTIConsumerGUI::DEFAULT_CMD);
232  }
233 
234  $repository = new ilUserCertificateRepository();
235 
236  $certLogger = $DIC->logger()->cert();
237  $pdfGenerator = new ilPdfGenerator($repository, $certLogger);
238 
239  $pdfAction = new ilCertificatePdfAction(
240  $certLogger,
241  $pdfGenerator,
243  $DIC->language()->txt('error_creating_certificate_pdf')
244  );
245 
246  $pdfAction->downloadPdf($DIC->user()->getId(), $this->object->getId());
247  }
248 }
static get(string $a_var)
Class ilPdfGeneratorConstantsTest.
__construct(ilObjLTIConsumer $object, ilLTIConsumerAccess $access)
ilLTIConsumerAccess constructor.
global $DIC
Definition: feed.php:28
$provider
Definition: ltitoken.php:83
checkAccess(string $permission)
static isUserDynamicRegistrationTransaction(ilLTIConsumeProvider $provider)
Validates if an active certificate is stored in the database and can be downloaded by the user...
static _refreshStatus(int $a_obj_id, ?array $a_users=null)
static has($a_var)
showSettingsCmd(ilLTIConsumerSettingsFormGUI $form=null)
Just a wrapper class to create Unit Test for other classes.
downloadPdf(int $userId, int $objectId)