Skip to content

Commit

Permalink
T&A, 40076: do not create FeedbackPages by calling the form
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaagen authored and thojou committed Jun 24, 2024
1 parent df5bccd commit 834a271
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ private function saveFeedbackFormCmd(): void
$this->tpl->setContent($this->ctrl->getHTML($form));
}

private function createFeedbackPageCmd(): void
{
$mode = $this->request->raw('fb_mode');
$this->ctrl->redirectToUrl(
$this->feedbackOBJ->createFeedbackPages($mode)
);
}

/**
* builds the feedback editing form object
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,37 @@ final public function initGenericFormProperties(ilPropertyFormGUI $form): void
if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
$page_object_type = $this->getGenericFeedbackPageObjectType();

$value_feedback_solution_complete = $this->getPageObjectNonEditableValueHTML(
$page_object_type,
$this->getGenericFeedbackPageObjectId($this->questionOBJ->getId(), true)
);
$page_object_id = $this->getGenericFeedbackId($this->questionOBJ->getId(), true);

if($page_object_id === -1) {
$this->ctrl->setParameterByClass(ilAssQuestionFeedbackEditingGUI::class, 'feedback_type', $page_object_type);
$this->ctrl->setParameterByClass(ilAssQuestionFeedbackEditingGUI::class, 'fb_mode', 'complete');
$link = $this->ctrl->getLinkTargetByClass(ilAssQuestionFeedbackEditingGUI::class, 'createFeedbackPage');
$value_feedback_solution_complete = sprintf(
'<a href="%s">%s</a>',
$link,
$this->lng->txt('tst_question_feedback_edit_page')
);
$this->ctrl->setParameterByClass(ilAssQuestionFeedbackEditingGUI::class, 'fb_mode', 'incomplete');
$link = $this->ctrl->getLinkTargetByClass(ilAssQuestionFeedbackEditingGUI::class, 'createFeedbackPage');
$value_feedback_solution_incomplete = sprintf(
'<a href="%s">%s</a>',
$link,
$this->lng->txt('tst_question_feedback_edit_page')
);
} else {
$this->ensurePageObjectExists($page_object_type, $page_object_id);

$value_feedback_solution_complete = $this->getPageObjectNonEditableValueHTML(
$page_object_type,
$this->getGenericFeedbackPageObjectId($this->questionOBJ->getId(), true)
);
$value_feedback_solution_incomplete = $this->getPageObjectNonEditableValueHTML(
$page_object_type,
$this->getGenericFeedbackPageObjectId($this->questionOBJ->getId(), false)
);
}

$value_feedback_solution_incomplete = $this->getPageObjectNonEditableValueHTML(
$page_object_type,
$this->getGenericFeedbackPageObjectId($this->questionOBJ->getId(), false)
);
} else {
$value_feedback_solution_complete = $this->getGenericFeedbackContent(
$this->questionOBJ->getId(),
Expand Down Expand Up @@ -523,8 +545,12 @@ final protected function getPageObjectNonEditableValueHTML(string $page_object_t
{
$link = $this->getPageObjectEditingLink($page_object_type, $page_object_id);
$content = $this->getPageObjectContent($page_object_type, $page_object_id);

return "$link<br /><br />$content";
return sprintf(
'<a href="%s">%s</a><br /><br />%s',
$link,
$this->lng->txt('tst_question_feedback_edit_page'),
$content
);
}

public function getClassNameByType(string $a_type, bool $a_gui = false): string
Expand All @@ -545,10 +571,7 @@ private function getPageObjectEditingLink(string $page_object_type, int $page_ob
$this->ctrl->setParameterByClass($cl, 'feedback_type', $page_object_type);
$this->ctrl->setParameterByClass($cl, 'feedback_id', $page_object_id);

$linkHREF = $this->ctrl->getLinkTargetByClass($cl, 'edit');
$linkTEXT = $this->lng->txt('tst_question_feedback_edit_page');

return "<a href='$linkHREF'>$linkTEXT</a>";
return $this->ctrl->getLinkTargetByClass($cl, 'edit');
}

final public function setPageObjectOutputMode(string $page_obj_output_mode): void
Expand Down Expand Up @@ -674,11 +697,6 @@ final public static function isValidFeedbackPageObjectType(string $feedbackPageO
final protected function getGenericFeedbackPageObjectId(int $question_id, bool $solution_completed): int
{
$page_object_id = $this->getGenericFeedbackId($question_id, $solution_completed);

if ($page_object_id == -1) {
$page_object_id = $this->saveGenericFeedbackContent($question_id, $solution_completed, '');
}

return $page_object_id;
}

Expand Down Expand Up @@ -749,4 +767,29 @@ protected function cleanupPageContent(string $content): string
}
return $content;
}

public function createFeedbackPages(string $mode): string
{
$page_object_type = ilAssQuestionFeedback::PAGE_OBJECT_TYPE_GENERIC_FEEDBACK;
$page_object_id_complete = $this->saveGenericFeedbackContent(
$this->questionOBJ->getId(),
true,
''
);
$this->ensurePageObjectExists($page_object_type, $page_object_id_complete);

$page_object_id_incomplete = $this->saveGenericFeedbackContent(
$this->questionOBJ->getId(),
false,
''
);
$this->ensurePageObjectExists($page_object_type, $page_object_id_incomplete);

$page_object_id = ($mode === 'complete') ? $page_object_id_complete : $page_object_id_incomplete;
return $this->getPageObjectEditingLink(
$page_object_type,
$page_object_id
);
}

}

0 comments on commit 834a271

Please sign in to comment.