ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilObjTestListGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
37 {
38  protected $command_link_params = [];
41 
45  public function init(): void
46  {
47  $this->static_link_enabled = true;
48  $this->delete_enabled = true;
49  $this->cut_enabled = true;
50  $this->copy_enabled = true;
51  $this->subscribe_enabled = true;
52  $this->link_enabled = true;
53  $this->info_screen_enabled = true;
54  $this->type = "tst";
55  $this->gui_class_name = "ilobjtestgui";
56 
57  // general commands array
58  $this->commands = ilObjTestAccess::_getCommands();
59  $this->obj_test_access = new ilObjTestAccess();
60  }
61 
62  public function initItem(
63  int $ref_id,
64  int $obj_id,
65  string $type,
66  string $title = '',
67  string $description = ''
68  ): void {
69  try {
70  if (TestDIC::dic()['settings.main.repository']->getForObjFi($obj_id)
71  ->getAdditionalSettings()->getHideInfoTab()) {
72  $this->enableInfoScreen(false);
73  }
74  } catch (Exception $e) {
75  $this->disableTitleLink(true);
76  $this->enableInfoScreen(false);
77  $this->enableLearningProgress(false);
78  $this->enableLPSettingsCommand(false);
79  $this->enableTimings(false);
80  $this->enableLink(false);
81  $this->enableCut(false);
82  $this->enableCopy(false);
83  $this->enableComments(false);
84  $this->enableNotes(false);
85  $this->enableTags(false);
86  $this->enableSubscribe(false);
87  $this->enableMultiDownload(false);
88  }
89  $this->test_access = new ilTestAccess($ref_id);
90  parent::initItem($ref_id, $obj_id, $type, $title, $description);
91  }
92 
101  public function getProperties(): array
102  {
103  $props = parent::getProperties();
104 
105  $participant_access = $this->test_access->isParticipantAllowed(
106  $this->obj_id,
107  $this->user->getId()
108  );
109 
110  if ($participant_access !== ParticipantAccess::ALLOWED) {
111  $props[] = ['alert' => true, 'property' => $this->lng->txt('status'),
112  'value' => $participant_access->getAccessForbiddenMessage($this->lng)];
113  return $props;
114  }
115 
116  if ($this->obj_test_access->showCertificateFor($this->user->getId(), $this->obj_id)) {
117  $this->lng->loadLanguageModule('certificate');
118  $this->ctrl->setParameterByClass(ilTestEvaluationGUI::class, 'ref_id', $this->ref_id);
119  $props[] = [
120  'alert' => false,
121  'property' => $this->lng->txt('certificate'),
122  'value' => $this->ui->renderer()->render(
123  $this->ui->factory()->link()->standard(
124  $this->lng->txt('download_certificate'),
125  $this->ctrl->getLinkTargetByClass(
126  [
127  ilObjTestGUI::class,
128  ilTestEvaluationGUI::class
129  ],
130  'outCertificate'
131  )
132  )
133  )
134  ];
135  $this->ctrl->setParameterByClass(ilTestEvaluationGUI::class, 'ref_id', null);
136  }
137 
138  return $props;
139  }
140 
141  public function getCommandLink(string $cmd): string
142  {
143  $cmd = explode('::', $cmd);
144 
145  if (count($cmd) === 2) {
146  $cmd_link = $this->ctrl->getLinkTargetByClass([ilRepositoryGUI::class, ilObjTestGUI::class, $cmd[0]], $cmd[1]);
147  } else {
148  $cmd_link = $this->ctrl->getLinkTargetByClass('ilObjTestGUI', $cmd[0]);
149  }
150 
151  $params = array_merge(['ref_id' => $this->ref_id], $this->command_link_params);
152 
153  foreach ($params as $param => $value) {
154  $cmd_link = ilUtil::appendUrlParameterString($cmd_link, "$param=$value", true);
155  }
156 
157  return $cmd_link;
158  }
159 
160  public function getCommands(): array
161  {
162  if ($this->test_access->isParticipantAllowed($this->obj_id, $this->user->getId())
163  === ParticipantAccess::BROKEN_TEST) {
164  return [];
165  }
166  $commands = parent::getCommands();
167  if ($this->access->checkAccess('read', '', $this->ref_id)) {
168  $this->insertCommand($this->getCommandLink('ILIAS\Test\Presentation\TestScreenGUI::testScreen'), $this->lng->txt('tst_start_test'));
169  }
170  return $commands;
171  }
172 
180  public function createDefaultCommand(array $command): array
181  {
182  return $command;
183  }
184 
185 
192  public function addCommandLinkParameter($a_param)
193  {
194  $this->command_link_params = $a_param;
195  }
196 
197  public function getAsCard(
198  int $ref_id,
199  int $obj_id,
200  string $type,
201  string $title,
202  string $description
205  $card = parent::getAsCard($ref_id, $obj_id, $type, $title, $description);
206  if ($this->obj_test_access->showCertificateFor($this->user->getId(), $obj_id)) {
207  $card = $card->withCertificateIcon(true);
208  }
209 
210  return $card;
211  }
212 
213  protected function modifyTitleLink(string $default_link): string
214  {
215  if (!ilLOSettings::isObjectiveTest($this->ref_id)) {
216  return parent::modifyTitleLink($default_link);
217  }
218 
219  $path = $this->tree->getPathFull($this->ref_id);
220 
221  while ($parent = array_pop($path)) {
222  if ($parent['type'] === 'crs') {
223  $parent_crs_ref_id = $parent['ref_id'];
224  break;
225  }
226  }
227 
228  $this->ctrl->setParameterByClass(ilObjCourseGUI::class, 'ref_id', $parent_crs_ref_id);
229  $this->ctrl->setParameterByClass(ilObjCourseGUI::class, 'tid', $this->ref_id);
230  $cmd_link = $this->ctrl->getLinkTargetByClass([ilRepositoryGUI::class, ilObjCourseGUI::class], 'redirectLocToTest');
231  $this->ctrl->clearParametersByClass('ilrepositorygui');
232 
233  return parent::modifyTitleLink($cmd_link);
234  }
235 }
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
enableMultiDownload(bool $value)
Toggles whether multiple objects can be downloaded at once or not.
initItem(int $ref_id, int $obj_id, string $type, string $title='', string $description='')
enableSubscribe(bool $status)
ilObjTestAccess $obj_test_access
getProperties()
Get item properties.
$path
Definition: ltiservices.php:29
enableInfoScreen(bool $info_screen)
modifyTitleLink(string $default_link)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
enableComments(bool $value, bool $enable_comments_settings=true)
Class ilObjTestListGUI.
enableLPSettingsCommand(bool $enabled)
$param
Definition: xapitoken.php:46
getAsCard(int $ref_id, int $obj_id, string $type, string $title, string $description)
Get card object.
addCommandLinkParameter($a_param)
add command link parameters
disableTitleLink(bool $status)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjTestAccess.
enableLearningProgress(bool $enabled)
static isObjectiveTest(int $a_trst_ref_id)
Check if test ref_id is used in an objective course.
createDefaultCommand(array $command)
overwritten from base class for course objectives
enableTimings(bool $status)
enable timings link
insertCommand(string $href, string $text, string $frame='', string $img='', string $cmd='', string $onclick='')
insert command button