Skip to content

Commit

Permalink
Test: Remove LegacyButton in FileUpload-Question
Browse files Browse the repository at this point in the history
  • Loading branch information
kergomard committed Dec 13, 2023
1 parent 2940b4b commit a988fa5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 204 deletions.
2 changes: 1 addition & 1 deletion Modules/TestQuestionPool/classes/class.assFileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ public function buildTestPresentationConfig(): ilTestQuestionConfig

protected function isFileDeletionAction(): bool
{
return $this->getQuestionAction() == ilAssFileUploadFileTableDeleteButton::ACTION;
return $this->getQuestionAction() == assFileUploadGUI::DELETE_FILES_ACTION;
}

protected function isFileDeletionSubmitAvailable(): bool
Expand Down
54 changes: 20 additions & 34 deletions Modules/TestQuestionPool/classes/class.assFileUploadGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
class assFileUploadGUI extends assQuestionGUI implements ilGuiQuestionScoringAdjustable
{
public const REUSE_FILES_TBL_POSTVAR = 'reusefiles';
public const REUSE_FILES_LANGVAR = 'ass_file_upload_reuse_btn';
public const REUSE_FILES_ACTION = 'reuse';
public const DELETE_FILES_TBL_POSTVAR = 'deletefiles';
public const DELETE_FILES_LANGVAR = 'delete';
public const DELETE_FILES_ACTION = 'delete';
private const HANDLE_FILE_UPLOAD = 'handleFileUpload';

/**
Expand Down Expand Up @@ -328,8 +332,11 @@ public function getPreview($show_question_only = false, $showInlineFeedback = fa
);
$table_gui->setData($files);
// hey: prevPassSolutions - support file reuse with table

list($lang_var, $cmd) = $this->getCommandButtonLangVarAndAction();
$table_gui->initCommand(
$this->buildFileTableDeleteButtonInstance(),
$lang_var,
$cmd,
assFileUpload::DELETE_FILES_TBL_POSTVAR
);
// hey.
Expand Down Expand Up @@ -357,9 +364,7 @@ public function getPreview($show_question_only = false, $showInlineFeedback = fa
return $questionoutput;
}

// hey: prevPassSolutions - pass will be always available from now on
public function getTestOutput($active_id, $pass, $is_postponed = false, $use_post_solutions = false, $show_feedback = false): string
// hey.
{
// generate the question output
$template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html", true, true, "Modules/TestQuestionPool");
Expand All @@ -374,9 +379,11 @@ public function getTestOutput($active_id, $pass, $is_postponed = false, $use_pos
$this->lng->txt('already_delivered_files')
);
$table_gui->setData($files);
// hey: prevPassSolutions - support file reuse with table

list($lang_var, $cmd) = $this->getCommandButtonLangVarAndAction();
$table_gui->initCommand(
$this->buildTestPresentationFileTableCommandButtonInstance(),
$lang_var,
$cmd,
$this->getTestPresentationFileTablePostVar()
);
// hey.
Expand Down Expand Up @@ -406,6 +413,14 @@ public function getTestOutput($active_id, $pass, $is_postponed = false, $use_pos
return $pageoutput;
}

private function getCommandButtonLangVarAndAction(): array
{
if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
return [self::REUSE_FILES_LANGVAR, self::REUSE_FILES_ACTION];
}
return [self::DELETE_FILES_LANGVAR, self::DELETE_FILES_ACTION];
}

public function getSpecificFeedbackOutput(array $userSolution): string
{
$output = "";
Expand Down Expand Up @@ -438,35 +453,6 @@ public function getAggregatedAnswersView(array $relevant_answers): string
return ''; //print_r($relevant_answers,true);
}

// hey: prevPassSolutions - shown files needs to be chosen so upload can replace or complete fileset
/**
* @return ilAssFileUploadFileTableDeleteButton
*/
protected function buildFileTableDeleteButtonInstance(): ilAssFileUploadFileTableDeleteButton
{
return ilAssFileUploadFileTableDeleteButton::getInstance();
}

/**
* @return ilAssFileUploadFileTableReuseButton
*/
protected function buildFileTableReuseButtonInstance(): ilAssFileUploadFileTableReuseButton
{
return ilAssFileUploadFileTableReuseButton::getInstance();
}

/**
* @return ilAssFileUploadFileTableCommandButton
*/
protected function buildTestPresentationFileTableCommandButtonInstance()
{
if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
return $this->buildFileTableReuseButtonInstance();
}

return $this->buildFileTableDeleteButtonInstance();
}

protected function getTestPresentationFileTablePostVar(): string
{
if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
Expand Down
2 changes: 1 addition & 1 deletion Modules/TestQuestionPool/classes/class.assQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ protected function getQuestionAction(): string
return '';
}

if (!is_array($_POST['cmd'][$this->questionActionCmd]) || !count($_POST['cmd'][$this->questionActionCmd])) {
if (!is_array($_POST['cmd'][$this->questionActionCmd]) || $_POST['cmd'][$this->questionActionCmd] === []) {
return '';
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ public function setPostVar($postVar): void
// hey.

// hey: prevPassSolutions - support file reuse with table
public function initCommand(ilAssFileUploadFileTableCommandButton $commandButton, $postVar): void
public function initCommand(string $lang_var, string $cmd, string $post_var): void
{
if (count($this->getData())) {
$this->enable('select_all');

$this->setSelectAllCheckbox($postVar);
$this->setPrefix($postVar);
$this->setPostVar($postVar);
$this->setSelectAllCheckbox($post_var);
$this->setPrefix($post_var);
$this->setPostVar($post_var);

$commandButton->setCommand($this->parent_cmd);
$this->addCommandButtonInstance($commandButton);
$on_click = "return (function(e){ e.name += '[{$cmd}]';})(this);";
$this->addCommandButton($this->parent_cmd, $this->lng->txt($lang_var), $on_click);
}
}
// hey.
Expand Down

0 comments on commit a988fa5

Please sign in to comment.