ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilLTIConsumerSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
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 
131  $this->initSubTabs();
132 
133  $nc = $DIC->ctrl()->getNextClass();
134 
135  switch ($nc) {
136  case strtolower(ilCertificateGUI::class):
137 
138  $validator = new ilCertificateActiveValidator();
139 
140  if (!$validator->validate()) {
141  throw new ilCmiXapiException('access denied!');
142  }
143 
144  $DIC->tabs()->activateSubTab(self::SUBTAB_ID_CERTIFICATE);
145 
146  $guiFactory = new ilCertificateGUIFactory();
147  $gui = $guiFactory->create($this->object);
148 
149  $DIC->ctrl()->forwardCommand($gui);
150 
151  break;
152 
153  case strtolower(ilLTIConsumeProviderSettingsGUI::class):
154 
155  $DIC->tabs()->activateSubTab(self::SUBTAB_ID_PROVIDER_SETTINGS);
156 
157  $gui = new ilLTIConsumeProviderSettingsGUI($this->object, $this->access);
158  $DIC->ctrl()->forwardCommand($gui);
159  break;
160 
161  default:
162  $DIC->tabs()->activateSubTab(self::SUBTAB_ID_OBJECT_SETTINGS);
163  $command = $DIC->ctrl()->getCmd(self::CMD_SHOW_SETTINGS) . 'Cmd';
164  $this->{$command}();
165  }
166  }
167 
168  protected function showSettingsCmd(?ilLTIConsumerSettingsFormGUI $form = null): void
169  {
170  global $DIC; /* @var \ILIAS\DI\Container $DIC */
171 
172  if ($form === null) {
173  $form = $this->buildForm();
174  }
175 
176  $DIC->ui()->mainTemplate()->setContent($form->getHTML());
177  }
178 
179  protected function saveSettingsCmd(): void
180  {
181  global $DIC; /* @var \ILIAS\DI\Container $DIC */
182 
183  $form = $this->buildForm();
184 
185  if ($form->checkInput()) {
186  $oldMasteryScore = $this->object->getMasteryScore();
187 
188  $form->initObject($this->object);
189  $this->object->update();
190 
191  if ($oldMasteryScore !== $this->object->getMasteryScore()) {
192  ilLPStatusWrapper::_refreshStatus($this->object->getId());
193  }
194 
195  $this->main_tpl->setOnScreenMessage('success', $DIC->language()->txt('msg_obj_modified'), true);
196  $DIC->ctrl()->redirect($this, self::CMD_SHOW_SETTINGS);
197  }
198 
199  $this->showSettingsCmd($form);
200  }
201 
203  {
204  global $DIC; /* @var \ILIAS\DI\Container $DIC */
205 
206  $form = new ilLTIConsumerSettingsFormGUI(
207  $this->object,
208  $DIC->ctrl()->getFormAction($this),
209  self::CMD_SAVE_SETTINGS,
210  self::CMD_SHOW_SETTINGS
211  );
212 
213  return $form;
214  }
215 
216  protected function deliverCertificateCmd(): void
217  {
218  global $DIC; /* @var \ILIAS\DI\Container $DIC */
219 
220  $validator = new ilCertificateDownloadValidator();
221 
222  if (!$validator->isCertificateDownloadable($DIC->user()->getId(), $this->object->getId())) {
223  $this->main_tpl->setOnScreenMessage('failure', $DIC->language()->txt("permission_denied"), true);
224  $DIC->ctrl()->redirectByClass(ilObjLTIConsumerGUI::class, ilObjLTIConsumerGUI::DEFAULT_CMD);
225  }
226 
227  $repository = new ilUserCertificateRepository();
228 
229  $certLogger = $DIC->logger()->cert();
230  $pdfGenerator = new ilPdfGenerator($repository);
231 
232  $pdfAction = new ilCertificatePdfAction(
233  $pdfGenerator,
235  $DIC->language()->txt('error_creating_certificate_pdf')
236  );
237 
238  $pdfAction->downloadPdf($DIC->user()->getId(), $this->object->getId());
239  }
240 }
static get(string $a_var)
__construct(ilObjLTIConsumer $object, ilLTIConsumerAccess $access)
ilLTIConsumerAccess constructor.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$provider
Definition: ltitoken.php:80
static isUserDynamicRegistrationTransaction(ilLTIConsumeProvider $provider)
Validates if an active certificate is stored in the database and can be downloaded by the user...
global $DIC
Definition: shib_login.php:26
static _refreshStatus(int $a_obj_id, ?array $a_users=null)
static has($a_var)
showSettingsCmd(?ilLTIConsumerSettingsFormGUI $form=null)
downloadPdf(int $userId, int $objectId)