Skip to content

Commit

Permalink
Merge pull request #4655 from HochschuleLuzern/fix_editing_links_ques…
Browse files Browse the repository at this point in the history
…tion_table_in_test

More fixes for edit question
  • Loading branch information
mbecker-databay authored Jun 20, 2022
2 parents 31cddde + 2a7956d commit f78e4f4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 40 deletions.
7 changes: 5 additions & 2 deletions Modules/Test/classes/class.ilObjTestGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,7 @@ public function executeCommand()
$this->prepareOutput();

$this->ctrl->saveParameter($this, "q_id");

require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewGUI.php';

$gui = new ilAssQuestionPreviewGUI($this->ctrl, $this->tabs_gui, $this->tpl, $this->lng, $ilDB, $ilUser);

$gui->initQuestion($this->fetchAuthoringQuestionIdParameter(), $this->object->getId());
Expand All @@ -686,6 +685,10 @@ public function executeCommand()
break;

case 'ilassquestionpagegui':
if ($cmd == 'finishEditing') {
$this->ctrl->redirectByClass('ilassquestionpreviewgui', 'show');
break;
}
if ((!$ilAccess->checkAccess("read", "", $_GET["ref_id"]))) {
$ilias->raiseError($this->lng->txt("permission_denied"), $ilias->error_obj->MESSAGE);
}
Expand Down
82 changes: 44 additions & 38 deletions Modules/Test/classes/tables/class.ilTestQuestionsTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,37 +262,32 @@ public function fillRow($data)
$actions->setId('qst' . $data["question_id"]);
$actions->setListTitle($this->lng->txt('actions'));

$actions->addItem($this->lng->txt('preview'), '', $this->ctrl->getLinkTargetByClass('ilAssQuestionPreviewGUI', ilAssQuestionPreviewGUI::CMD_SHOW));
$actions->addItem(
$this->lng->txt('preview'),
'',
$this->getEditLink($data, get_class($this->getParentObject()), $this->getParentCmd())
);

if ($this->isQuestionManagingEnabled()) {
$editHref = $this->ctrl->getLinkTargetByClass($data['type_tag'] . 'GUI', 'editQuestion');
$editHref = $this->getEditLink($data, $data['type_tag'] . 'GUI', 'editQuestion');
$actions->addItem($this->lng->txt('edit_question'), '', $editHref);

$editPageHref = $this->ctrl->getLinkTargetByClass('ilAssQuestionPageGUI', 'edit');
$editPageHref = $this->getEditLink($data, 'ilAssQuestionPageGUI', 'edit');
$actions->addItem($this->lng->txt('edit_page'), '', $editPageHref);

$this->ctrl->setParameter($this->parent_obj, 'q_id', $data['question_id']);
$moveHref = $this->ctrl->getLinkTarget($this->parent_obj, 'moveQuestions');
$this->ctrl->setParameter($this->parent_obj, 'q_id', null);

$moveHref = $this->getEditLink($data, get_class($this->getParentObject()), 'moveQuestions');
$actions->addItem($this->lng->txt('move'), '', $moveHref);

$this->ctrl->setParameter($this->parent_obj, 'q_id', $data['question_id']);
$copyHref = $this->ctrl->getLinkTarget($this->parent_obj, 'copyQuestion');
$this->ctrl->setParameter($this->parent_obj, 'q_id', null);

$copyHref = $this->getEditLink($data, get_class($this->getParentObject()), 'copyQuestion');
$actions->addItem($this->lng->txt('copy'), '', $copyHref);

$this->ctrl->setParameter($this->parent_obj, 'q_id', $data['question_id']);
$deleteHref = $this->ctrl->getLinkTarget($this->parent_obj, 'removeQuestions');
$this->ctrl->setParameter($this->parent_obj, 'q_id', null);

$deleteHref = $this->getEditLink($data, get_class($this->getParentObject()), 'removeQuestions');
$actions->addItem($this->lng->txt('delete'), '', $deleteHref);

$this->ctrl->setParameterByClass('ilAssQuestionFeedbackEditingGUI', 'q_id', $data['question_id']);
$feedbackHref = $this->ctrl->getLinkTargetByClass('ilAssQuestionFeedbackEditingGUI', ilAssQuestionFeedbackEditingGUI::CMD_SHOW);
$this->ctrl->setParameterByClass('ilAssQuestionFeedbackEditingGUI', 'q_id', null);
$feedbackHref = $this->getEditLink($data, 'ilAssQuestionFeedbackEditingGUI', ilAssQuestionFeedbackEditingGUI::CMD_SHOW);
$actions->addItem($this->lng->txt('tst_feedback'), '', $feedbackHref);

$this->ctrl->setParameterByClass('ilAssQuestionHintsGUI', 'q_id', $data['question_id']);
$hintsHref = $this->ctrl->getLinkTargetByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
$this->ctrl->setParameterByClass('ilAssQuestionHintsGUI', 'q_id', null);

$hintsHref = $this->getEditLink($data, 'ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
$actions->addItem($this->lng->txt('tst_question_hints_tab'), '', $hintsHref);
}
$this->tpl->setVariable('ROW_ACTIONS', $actions->getHTML());
Expand All @@ -301,10 +296,6 @@ public function fillRow($data)
}
}

/**
* @param array $rowData
* @return string
*/
protected function buildQuestionRemoveButton(array $rowData) : string
{
$this->ctrl->setParameter($this->getParentObject(), 'removeQid', $rowData['question_id']);
Expand All @@ -318,30 +309,45 @@ protected function buildQuestionRemoveButton(array $rowData) : string
return $button->render();
}

/**
* @param array $rowData
* @return string
*/
protected function buildQuestionTitleLink(array $rowData) : string
{
$this->ctrl->setParameter(
$this->getParentObject(),
$questionHref = $this->getEditLink($rowData, get_class($this->getParentObject()), $this->getParentCmd());

return '<a href="' . $questionHref . '">' . $rowData["title"] . '</a>';
}

protected function getEditLink(array $rowData, string $target_class, string $cmd) : string
{
$this->ctrl->setParameterByClass(
$target_class,
'eqpl',
current(ilObject::_getAllReferences($rowData['obj_fi']))
);

$this->ctrl->setParameter(
$this->getParentObject(),
$this->ctrl->setParameterByClass(
$target_class,
'eqid',
$rowData['question_id']
);

$questionHref = $this->ctrl->getLinkTarget($this->getParentObject(), $this->getParentCmd());
$this->ctrl->setParameterByClass(
$target_class,
'q_id',
$rowData['question_id']
);
$this->ctrl->setParameterByClass(
$target_class,
'calling_test',
$_GET['ref_id']
);

$link = $this->ctrl->getLinkTargetByClass($target_class, $cmd);

$this->ctrl->setParameter($this->getParentObject(), 'eqpl', '');
$this->ctrl->setParameter($this->getParentObject(), 'eqid', '');
$this->ctrl->setParameterByClass($target_class, 'eqpl', '');
$this->ctrl->setParameterByClass($target_class, 'eqid', '');
$this->ctrl->setParameterByClass($target_class, 'q_id', '');

return '<a href="' . $questionHref . '">' . $rowData["title"] . '</a>';
return $link;
}

/**
Expand Down

0 comments on commit f78e4f4

Please sign in to comment.