Newer
Older
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/
declare(strict_types=1);
use ILIAS\Plugin\PlagScanExercise\Form\EditorGUI;
use ILIAS\Plugin\PlagScanExercise\Form\ExOverviewAdditions;
use ILIAS\Plugin\PlagScanExercise\PlagScan\AssignmentConfigData;
use ILIAS\Plugin\PlagScanExercise\PlagScan\AssignmentConfigPersistence;
use ILIAS\Plugin\PlagScanExercise\PlagScan\DocumentManagement;
use ILIAS\Plugin\PlagScanExercise\Table\AssignmentTableGUI;
use ILIAS\Plugin\PlagScanExercise\Table\ParticipantsTableGUI;
class ilPlagScanExerciseUIHookGUI extends ilUIHookPluginGUI
{
protected static int $assignment_counter = 0;
public function getHTML(string $a_comp, string $a_part, array $a_par = []): array
global $DIC;
$post = $DIC->http()->request()->getParsedBody();
$get = $DIC->http()->request()->getQueryParams();
$ref_id = (int) ($get['ref_id'] ?? 0);
$obj_id = ilObject::_lookupObjectId($ref_id);
$ass_id = (int) ($get['ass_id'] ?? 0);
$tpl = $a_par['tpl_obj'] ?? null;
if (
$a_part === 'template_get' &&
isset($post['cmd']['addAssignment'], $post['type'], $a_par['tpl_id']) &&
$a_par['tpl_id']=== 'Services/Form/tpl.form.html' &&
($post['type'] === '5' || $post['type'] === '1') &&
!($GLOBALS['PLX_IN_EXECasscreate'] ?? '') &&
strtolower($DIC->ctrl()->getCmdClass()) === strtolower(ilExAssignmentEditorGUI::class)
$GLOBALS['PLX_IN_EXECasscreate'] = true;
$override_editor = new EditorGUI($obj_id, false);
if ($post['type'] === '5') {
$form_html = $override_editor->getTextAssignmentCreationForm()->getHtml();
} else {
$form_html = $override_editor->getUploadAssignmentCreationForm()->getHtml();
}
$GLOBALS['PLX_IN_EXEC'] = false;
return ['mode' => ilUIHookPluginGUI::REPLACE, 'html' => $form_html ];
if (
$a_comp === 'Services/Utilities' &&
$a_part === 'redirect' &&
!($GLOBALS['PLX_CREATION_DONE'] ?? '') &&
$DIC->ctrl()->getCmd() === 'saveAssignment' &&
strtolower($DIC->ctrl()->getCmdClass()) === strtolower(ilExAssignmentEditorGUI::class)
$config = new AssignmentConfigData(
$obj_id,
$this->getLatestAssignmentIdForExercise($obj_id),
isset($post['psx_activation']) ? $post['psx_activation'] === '1' : false,
isset($post['psx_checkstart']) ? ilUtil::stripSlashes($post['psx_checkstart']) : 'none',
isset($post['psx_resultshare']) ? ilUtil::stripSlashes($post['psx_resultshare']) : 'none',
isset($post['psx_resulttype']) ? ilUtil::stripSlashes($post['psx_resulttype']) : 'none'
$persistence = new AssignmentConfigPersistence($DIC->database());
$persistence->store($config);
return ['mode' => ilUIHookPluginGUI::KEEP, 'html' => ''];
if (
$a_part === 'template_get' &&
$tpl->currentBlock === '__global__' &&
!($GLOBALS['PLX_IN_EXECass'] ?? '') &&
isset($a_par['tpl_id']) &&
$a_par['tpl_id'] === 'Services/Form/tpl.form.html' &&
strtolower($DIC->ctrl()->getCmdClass()) === strtolower(ilExAssignmentEditorGUI::class) &&
$DIC->ctrl()->getCmd() === 'editAssignment'
) {
$assignment = new ilExAssignment($ass_id);
$override_editor = new EditorGUI($obj_id, false, $assignment);
$form_html = $override_editor->getTextAssignmentUpdateForm()->getHtml();
if ($assignment->getAssignmentType() instanceof ilExAssTypeText) {
$GLOBALS['PLX_IN_EXEC'] = false;
return ['mode' => ilUIHookPluginGUI::REPLACE, 'html' => $form_html];
}
if ($assignment->getAssignmentType() instanceof ilExAssTypeUpload) {
return ['mode' => ilUIHookPluginGUI::REPLACE, 'html' => $form_html];
return ['mode' => ilUIHookPluginGUI::KEEP, 'html' => ''];
if (
$a_part === 'redirect' &&
$a_comp === 'Services/Utilities' &&
strtolower($DIC->ctrl()->getCmdClass()) === strtolower(ilExAssignmentEditorGUI::class) &&
$DIC->ctrl()->getCmd() === 'updateAssignment'
) {
$config = new AssignmentConfigData(
$obj_id,
$ass_id,
isset($post['psx_activation']) ? $post['psx_activation'] === '1' : false,
isset($post['psx_checkstart']) ? ilUtil::stripSlashes($post['psx_checkstart']) : 'none',
isset($post['psx_resultshare']) ? ilUtil::stripSlashes($post['psx_resultshare']) : 'none',
isset($post['psx_resulttype']) ? ilUtil::stripSlashes($post['psx_resulttype']) : 'none'
$persistence = new AssignmentConfigPersistence($DIC->database());
$persistence->store($config);
return ['mode' => ilUIHookPluginGUI::KEEP, 'html' => ''];
if (
$a_part === 'template_get' &&
$tpl->currentBlock === 'tbl_table_end' &&
!($GLOBALS['PLX_IN_EXEC2'] ?? '') &&
strtolower($DIC->ctrl()->getCmdClass()) === strtolower(ilExerciseManagementGUI::class) &&
($DIC->ctrl()->getCmd() === 'members' || $DIC->ctrl()->getCmd() === 'selectAssignment')
) {
if (isset($get['chkdoc'])) {
DocumentManagement::checkDocument((int) $get['chkdoc']);
if (isset($get['subdoc_usr'])) {
DocumentManagement::handInDocumentAsFile((int) $get['subdoc_usr'], (int) $get['subdoc_ass']);
}
if (isset($get['subchk_all'])) {
DocumentManagement::handInAllDocumentAsFile((int) $get['subchk_all']);
DocumentManagement::checkAllDocumentsForAssignment((int) $get['subchk_all']);
}
$exerciseobj = new ilObjExercise($ref_id);
if ($ass_id === 0) {
$ass_data = ilExAssignment::getAssignmentDataOfExercise($exerciseobj->getId());
$ass_id = (int) $ass_data[0]['id'];
}
$assignment = new ilExAssignment($ass_id);
$ex_management = new ilExerciseManagementGUI($DIC->exercise()->internal(), $assignment);
$DIC->ctrl()->clearParametersByClass('ilExerciseManagementGUI');
$DIC->ctrl()->setParameterByClass('ilExerciseManagementGUI', 'subchk_all', $ass_id);
$DIC->toolbar()->addSeparator();
$DIC->toolbar()->addLink(
$this->plugin_object->txt('check_documents'),
$DIC->ctrl()->getLinkTargetByClass('ilExerciseManagementGUI', 'members')
);
$table = new AssignmentTableGUI(
return ['mode' => ilUIHookPluginGUI::REPLACE, 'html' => $html];
if (
$a_part === 'template_get' &&
$tpl->currentBlock === 'tbl_table_end' &&
!($GLOBALS['PLX_IN_EXEC4'] ?? '') &&
strtolower($DIC->ctrl()->getCmdClass()) === strtolower(ilExerciseManagementGUI::class) &&
$DIC->ctrl()->getCmd() === 'showParticipant'
) {
if (isset($get['chkdoc'])) {
$doc_id = (int) $get['chkdoc'];
DocumentManagement::checkDocument($doc_id);
$exerciseobj = new ilObjExercise($ref_id);
$assignment = new ilExAssignment($ass_id);
$ex_management = new ilExerciseManagementGUI($DIC->exercise()->internal(), $assignment);
$table = new ParticipantsTableGUI(
return ['mode' => ilUIHookPluginGUI::REPLACE, 'html' => $html];
if (
$a_part === 'template_get' &&
$a_par['tpl_id'] === 'Modules/Exercise/tpl.assignment_body.html' &&
strtolower($DIC->ctrl()->getCmdClass()) === strtolower(ilObjExerciseGUI::class) &&
$DIC->ctrl()->getCmd() === 'showOverview'
) {
$assignment_persistence = new AssignmentConfigPersistence($DIC->database());
$assignment = $assignment_persistence->getByAssignmentOrderInRef($ref_id, self::$assignment_counter);
if ($assignment->getActivation() === true) {
$additions = new ExOverviewAdditions();
$a_par['html'] .= '<div class="ilExcAssignmentBody" style="padding-top: -10px; margin-top: -10px;">' . $form->getHTML() . '</div>';
return ['mode' => ilUIHookPluginGUI::REPLACE, 'html' => $a_par['html']];
if (
$a_part === 'template_get' &&
isset($a_par['tpl_id']) &&
$a_par['tpl_id'] === 'Services/Form/tpl.property_form.html' &&
strtolower($DIC->ctrl()->getCmdClass()) === strtolower(ilExSubmissionTextGUI::class) &&
$DIC->ctrl()->getCmd() === 'editAssignmentText'
) {
return ['mode' => ilUIHookPluginGUI::REPLACE, 'html' => $a_par['html']];
if (
$a_comp === 'Services/Utilities' &&
$a_part === 'redirect' &&
!($GLOBALS['PLX_IN_EXEC'] ?? '') &&
(
strtolower($DIC->ctrl()->getCmdClass()) === strtolower(ilExSubmissionTextGUI::class) ||
strtolower($DIC->ctrl()->getCmdClass()) === strtolower(ilExSubmissionFileGUI::class)
) &&
(
$DIC->ctrl()->getCmd() === 'updateAssignmentText' ||
$DIC->ctrl()->getCmd() === 'updateAssignmentTextAndReturn' ||
$DIC->ctrl()->getCmd() === 'updateAssignmentFile' ||
$DIC->ctrl()->getCmd() === 'uploadFile'
)
) {
$assignment_persistence = new AssignmentConfigPersistence($DIC->database());
$assignment = $assignment_persistence->getByAssignmentId($ass_id);
if ($assignment->getActivation() === true) {
if ($DIC->ctrl()->getCmd() === 'updateAssignmentFile' || $DIC->ctrl()->getCmd() === 'uploadFile') {
DocumentManagement::handInDocumentAsFile($DIC->user()->getId(), $ass_id);
DocumentManagement::handInDocumentAsText(
$DIC->user()->getId(),
$ass_id,
ilUtil::stripSlashes($post['atxt'] ?? '')
);
return ['mode' => ilUIHookPluginGUI::KEEP, 'html' => ''];
protected function getLatestAssignmentIdForExercise(int $object_id): int
$result = $DIC->database()->queryF(
'SELECT max(id) as maxId FROM exc_assignment WHERE exc_id = %s',
[ilDBConstants::T_INTEGER],
[$object_id]
);
$row = $DIC->database()->fetchAssoc($result);
return (int) $row['maxId'];