ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjTestListGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
31 require_once './Modules/Test/classes/inc.AssessmentConstants.php';
32 
34 {
35  protected $command_link_params = [];
36 
40  public function init(): void
41  {
42  $this->static_link_enabled = true;
43  $this->delete_enabled = true;
44  $this->cut_enabled = true;
45  $this->copy_enabled = true;
46  $this->subscribe_enabled = true;
47  $this->link_enabled = true;
48  $this->info_screen_enabled = true;
49  $this->type = "tst";
50  $this->gui_class_name = "ilobjtestgui";
51 
52  // general commands array
53  $this->commands = ilObjTestAccess::_getCommands();
54  }
55 
56  public function initItem(
57  int $ref_id,
58  int $obj_id,
59  string $type,
60  string $title = '',
61  string $description = ''
62  ): void {
63  try {
64  if (ilTestDIC::dic()['main_settings_repository']->getForObjFi($obj_id)
65  ->getAdditionalSettings()->getHideInfoTab()) {
66  $this->enableInfoScreen(false);
67  }
68  } catch (Exception $e) {
69 
70  }
71  parent::initItem($ref_id, $obj_id, $type, $title, $description);
72  }
73 
81  public function getCommandFrame(string $cmd): string
82  {
83  $frame = '';
84  switch ($cmd) {
85  case "":
86  case "infoScreen":
87  case "eval_a":
88  case "eval_stat":
89  $frame = ilFrameTargetInfo::_getFrame("MainContent");
90  break;
91 
92  default:
93  }
94 
95  return $frame;
96  }
97 
98 
99 
108  public function getProperties(): array
109  {
110  $props = parent::getProperties();
111 
112  // we cannot use ilObjTestAccess::_isOffline() because of text messages
113  $onlineaccess = ilObjTestAccess::_lookupOnlineTestAccess($this->obj_id, $this->user->getId());
114  if ($onlineaccess !== true) {
115  $props[] = ["alert" => true, "property" => $this->lng->txt("status"),
116  "value" => $onlineaccess];
117  }
118 
119  return $props;
120  }
121 
122  public function getCommandLink(string $cmd): string
123  {
124  $cmd = explode('::', $cmd);
125 
126  if (count($cmd) == 2) {
127  $cmd_link = $this->ctrl->getLinkTargetByClass(['ilRepositoryGUI', 'ilObjTestGUI', $cmd[0]], $cmd[1]);
128  } else {
129  $cmd_link = $this->ctrl->getLinkTargetByClass('ilObjTestGUI', $cmd[0]);
130  }
131 
132  $params = array_merge(['ref_id' => $this->ref_id], $this->command_link_params);
133 
134  foreach ($params as $param => $value) {
135  $cmd_link = ilUtil::appendUrlParameterString($cmd_link, "$param=$value", true);
136  }
137 
138  return $cmd_link;
139  }
140 
141  public function getCommands(): array
142  {
143  $commands = parent::getCommands();
144  if ($this->access->checkAccess('read', '', $this->ref_id)) {
145  $this->insertCommand($this->getCommandLink('ilTestScreenGUI::testScreen'), $this->lng->txt('tst_start_test'));
146  }
147  return $this->handleUserResultsCommand($commands);
148  }
149 
151  {
152  if (!ilLOSettings::isObjectiveTest($this->ref_id)) {
153  return $this->removeUserResultsCommand($commands);
154  }
155 
156  if (!ilObjTestAccess::visibleUserResultExists($this->obj_id, $this->user->getId())) {
157  return $this->removeUserResultsCommand($commands);
158  }
159 
160  return $commands;
161  }
162 
164  {
165  foreach ($commands as $key => $command) {
166  if ($command['cmd'] == 'userResultsGateway') {
167  unset($commands[$key]);
168  break;
169  }
170  }
171 
172  return $commands;
173  }
174 
182  public function createDefaultCommand(array $command): array
183  {
184  return $command;
185  }
186 
187 
194  public function addCommandLinkParameter($a_param)
195  {
196  $this->command_link_params = $a_param;
197  }
198 
199  // begin-patch lok
200  protected function modifyTitleLink(string $default_link): string
201  {
202  if (!ilLOSettings::isObjectiveTest($this->ref_id)) {
203  return parent::modifyTitleLink($default_link);
204  }
205 
206  $path = $this->tree->getPathFull($this->ref_id);
207 
208  while ($parent = array_pop($path)) {
209  if ($parent['type'] === 'crs') {
210  $parent_crs_ref_id = $parent['ref_id'];
211  break;
212  }
213  }
214 
215  $this->ctrl->setParameterByClass("ilrepositorygui", 'ref_id', $parent_crs_ref_id);
216  $this->ctrl->setParameterByClass("ilrepositorygui", 'tid', $this->ref_id);
217  $cmd_link = $this->ctrl->getLinkTargetByClass("ilrepositorygui", 'redirectLocToTest');
218  $this->ctrl->setParameterByClass("ilrepositorygui", "ref_id", $this->ref_id);
219  $this->ctrl->clearParametersByClass('ilrepositorygui');
220 
221  return parent::modifyTitleLink($cmd_link);
222  }
223 
224  // end-patch lok
225 } // END class.ilObjTestListGUI
getCommandFrame(string $cmd)
Get command target frame.
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
initItem(int $ref_id, int $obj_id, string $type, string $title='', string $description='')
getProperties()
Get item properties.
$path
Definition: ltiservices.php:32
enableInfoScreen(bool $info_screen)
modifyTitleLink(string $default_link)
static _lookupOnlineTestAccess($a_test_id, $a_user_id)
Checks if a user is allowd to run an online exam.
Class ilObjTestListGUI.
$param
Definition: xapitoken.php:46
string $key
Consumer key/client ID value.
Definition: System.php:193
addCommandLinkParameter($a_param)
add command link parameters
static isObjectiveTest(int $a_trst_ref_id)
Check if test ref_id is used in an objective course.
static dic()
createDefaultCommand(array $command)
overwritten from base class for course objectives
insertCommand(string $href, string $text, string $frame='', string $img='', string $cmd='', string $onclick='')
insert command button
static _getFrame(string $a_class)
static visibleUserResultExists($test_obj_id, $user_id)