ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLTIConsumerSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 
18 {
19  const SUBTAB_ID_OBJECT_SETTINGS = 'subtab_object_settings';
20  const SUBTAB_ID_PROVIDER_SETTINGS = 'subtab_provider_settings';
21  const SUBTAB_ID_CERTIFICATE = 'subtab_certificate';
22 
23  const CMD_SHOW_SETTINGS = 'showSettings';
24  const CMD_SAVE_SETTINGS = 'saveSettings';
25  const CMD_DELIVER_CERTIFICATE = 'deliverCertificate';
26 
30  protected $object;
31 
35  protected $access;
36 
42  {
43  $this->object = $object;
44  $this->access = $access;
45  }
46 
47  protected function initSubTabs()
48  {
49  global $DIC; /* @var \ILIAS\DI\Container $DIC */
50  $DIC->language()->loadLanguageModule('lti');
51  $DIC->tabs()->addSubTab(
52  self::SUBTAB_ID_OBJECT_SETTINGS,
53  $DIC->language()->txt(self::SUBTAB_ID_OBJECT_SETTINGS),
54  $DIC->ctrl()->getLinkTarget($this)
55  );
56 
57  if ($this->needsProviderSettingsSubTab()) {
58  $DIC->tabs()->addSubTab(
59  self::SUBTAB_ID_PROVIDER_SETTINGS,
60  $DIC->language()->txt(self::SUBTAB_ID_PROVIDER_SETTINGS),
61  $DIC->ctrl()->getLinkTargetByClass(ilLTIConsumeProviderSettingsGUI::class)
62  );
63  }
64 
65  $validator = new ilCertificateActiveValidator();
66 
67  if ($validator->validate()) {
68  $DIC->tabs()->addSubTab(
69  self::SUBTAB_ID_CERTIFICATE,
70  $DIC->language()->txt(self::SUBTAB_ID_CERTIFICATE),
71  $DIC->ctrl()->getLinkTargetByClass(ilCertificateGUI::class, 'certificateEditor')
72  );
73  }
74  }
75 
76  protected function needsProviderSettingsSubTab()
77  {
78  global $DIC; /* @var \ILIAS\DI\Container $DIC */
79 
80  if ($this->object->getProvider()->isGlobal()) {
81  return false;
82  }
83 
84  if ($this->object->getProvider()->getCreator() != $DIC->user()->getId()) {
85  return false;
86  }
87 
88  return true;
89  }
90 
94  public function executeCommand()
95  {
96  global $DIC; /* @var \ILIAS\DI\Container $DIC */
97 
98  $this->initSubTabs();
99 
100  $nc = $DIC->ctrl()->getNextClass();
101 
102  switch ($nc) {
103  case strtolower(ilCertificateGUI::class):
104 
105  $validator = new ilCertificateActiveValidator();
106 
107  if (!$validator->validate()) {
108  throw new ilCmiXapiException('access denied!');
109  }
110 
111  $DIC->tabs()->activateSubTab(self::SUBTAB_ID_CERTIFICATE);
112 
113  $guiFactory = new ilCertificateGUIFactory();
114  $gui = $guiFactory->create($this->object);
115 
116  $DIC->ctrl()->forwardCommand($gui);
117 
118  break;
119 
120  case strtolower(ilLTIConsumeProviderSettingsGUI::class):
121 
122  $DIC->tabs()->activateSubTab(self::SUBTAB_ID_PROVIDER_SETTINGS);
123 
124  $gui = new ilLTIConsumeProviderSettingsGUI($this->object, $this->access);
125  $DIC->ctrl()->forwardCommand($gui);
126  break;
127 
128  default:
129 
130  $DIC->tabs()->activateSubTab(self::SUBTAB_ID_OBJECT_SETTINGS);
131 
132  $command = $DIC->ctrl()->getCmd(self::CMD_SHOW_SETTINGS) . 'Cmd';
133  $this->{$command}();
134  }
135  }
136 
137  protected function showSettingsCmd(ilLTIConsumerSettingsFormGUI $form = null)
138  {
139  global $DIC; /* @var \ILIAS\DI\Container $DIC */
140 
141  if ($form === null) {
142  $form = $this->buildForm();
143  }
144 
145  $DIC->ui()->mainTemplate()->setContent($form->getHTML());
146  }
147 
148  protected function saveSettingsCmd()
149  {
150  global $DIC; /* @var \ILIAS\DI\Container $DIC */
151 
152  $form = $this->buildForm();
153 
154  if ($form->checkInput()) {
155  $oldMasteryScore = $this->object->getMasteryScore();
156 
157  $form->initObject($this->object);
158  $this->object->update();
159 
160  if ($oldMasteryScore != $this->object->getMasteryScore()) {
161  ilLPStatusWrapper::_refreshStatus($this->object->getId());
162  }
163 
164  ilUtil::sendSuccess($DIC->language()->txt('msg_obj_modified'), true);
165  $DIC->ctrl()->redirect($this, self::CMD_SHOW_SETTINGS);
166  }
167 
168  $this->showSettingsCmd($form);
169  }
170 
171  protected function buildForm()
172  {
173  global $DIC; /* @var \ILIAS\DI\Container $DIC */
174 
175  $form = new ilLTIConsumerSettingsFormGUI(
176  $this->object,
177  $DIC->ctrl()->getFormAction($this),
178  self::CMD_SAVE_SETTINGS,
179  self::CMD_SHOW_SETTINGS
180  );
181 
182  return $form;
183  }
184 
185  protected function deliverCertificateCmd()
186  {
187  global $DIC; /* @var \ILIAS\DI\Container $DIC */
188 
189  $validator = new ilCertificateDownloadValidator();
190 
191  if (!$validator->isCertificateDownloadable((int) $DIC->user()->getId(), (int) $this->object->getId())) {
192  ilUtil::sendFailure($DIC->language()->txt("permission_denied"), true);
193  $DIC->ctrl()->redirectByClass(ilObjLTIConsumerGUI::class, ilObjLTIConsumerGUI::DEFAULT_CMD);
194  }
195 
196  $repository = new ilUserCertificateRepository();
197 
198  $certLogger = $DIC->logger()->cert();
199  $pdfGenerator = new ilPdfGenerator($repository, $certLogger);
200 
201  $pdfAction = new ilCertificatePdfAction(
202  $certLogger,
203  $pdfGenerator,
205  $DIC->language()->txt('error_creating_certificate_pdf')
206  );
207 
208  $pdfAction->downloadPdf((int) $DIC->user()->getId(), (int) $this->object->getId());
209  }
210 }
Class ilPdfGeneratorConstantsTest.
__construct(ilObjLTIConsumer $object, ilLTIConsumerAccess $access)
ilLTIConsumerAccess constructor.
static _refreshStatus($a_obj_id, $a_users=null)
Set dirty.
Validates if an active certificate is stored in the database and can be downloaded by the user...
global $DIC
Definition: goto.php:24
showSettingsCmd(ilLTIConsumerSettingsFormGUI $form=null)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Just a wrapper class to create Unit Test for other classes.
downloadPdf(int $userId, int $objectId)