ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjTestListGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23use ILIAS\UI\Component\Card\RepositoryObject as RepositoryObjectCard;
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
203 ): ?RepositoryObjectCard {
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 isObjectiveTest(int $a_trst_ref_id)
Check if test ref_id is used in an objective course.
Class ilObjTestAccess.
static _getCommands()
get commands
Class ilObjTestListGUI.
addCommandLinkParameter($a_param)
add command link parameters
initItem(int $ref_id, int $obj_id, string $type, string $title='', string $description='')
initialize new item (is called by getItemHTML())
getProperties()
Get item properties.
getCommandLink(string $cmd)
Get command link url.
createDefaultCommand(array $command)
overwritten from base class for course objectives
modifyTitleLink(string $default_link)
ilObjTestAccess $obj_test_access
getCommands()
get all current commands for a specific ref id (in the permission context of the current user)
enableInfoScreen(bool $info_screen)
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
$ref_id
Definition: ltiauth.php:66
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
$path
Definition: ltiservices.php:30
try
handle Lrs Init
Definition: xapiproxy.php:86
if(!file_exists('../ilias.ini.php'))
$param
Definition: xapitoken.php:46