Skip to content

Commit

Permalink
exercise: improve deletion process
Browse files Browse the repository at this point in the history
  • Loading branch information
alex40724 committed Sep 28, 2024
1 parent 9ae1fa3 commit 563e7c1
Show file tree
Hide file tree
Showing 17 changed files with 246 additions and 50 deletions.
21 changes: 12 additions & 9 deletions components/ILIAS/Exercise/Assignment/AssignmentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,20 @@ class AssignmentManager
protected InternalDomainService $domain;
protected AssignmentsDBRepository $repo;
protected int $obj_id;
protected int $ref_id;

public function __construct(
InternalRepoService $repo_service,
InternalDomainService $domain_service,
int $ref_id,
int $obj_id,
int $user_id
) {
$this->ref_id = $ref_id;
$this->obj_id = \ilObject::_lookupObjId($ref_id);
$this->obj_id = $obj_id;
$this->domain = $domain_service;
$this->repo = $repo_service->assignment()->assignments();
$this->lng = $domain_service->lng();
$this->user_id = $user_id;
}

protected function getExcRefId(): int
{
return $this->ref_id;
}

protected function getExcId(): int
{
return $this->obj_id;
Expand Down Expand Up @@ -103,6 +96,16 @@ public function getList(string $mode): \Iterator
}
}

/**
* @return iterable<Assignment>
*/
public function getAll(): \Iterator
{
foreach ($this->repo->getList($this->getExcId()) as $ass) {
yield $ass;
}
}

public function get(int $ass_id): Assignment
{
$ass = $this->repo->get($this->getExcId(), $ass_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public function __construct(
}


public function assignments(int $ref_id, int $user_id): AssignmentManager
public function assignments(int $obj_id, int $user_id): AssignmentManager
{
return new AssignmentManager(
$this->repo_service,
$this->domain_service,
$ref_id,
$obj_id,
$user_id
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(
$this->exc = $exc;
$this->user = $domain_service->user();
$this->ass_manager = $domain_service->assignment()->assignments(
$exc->getRefId(),
$exc->getId(),
$this->user->getId()
);
$this->panel_builder = $gui_service->assignment()->panelBuilder(
Expand Down
61 changes: 50 additions & 11 deletions components/ILIAS/Exercise/Assignment/class.ilExAssignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ public function save(): void

self::createNewAssignmentRecords($next_id, $exc);
ilObjectSearch::raiseContentChanged($this->getExerciseId());
$this->handleCalendarEntries("create");
$this->handleCalendarEntries("create", $exc);
}

/**
Expand Down Expand Up @@ -820,28 +820,67 @@ public function update(): void
$exc = new ilObjExercise($this->getExerciseId(), false);
$exc->updateAllUsersStatus();
ilObjectSearch::raiseContentChanged($this->getExerciseId());
$this->handleCalendarEntries("update");
$this->handleCalendarEntries("update", $exc);
}

/**
* @throws ilDateTimeException
*/
public function delete(): void
{
public function delete(
ilObjExercise $exc,
bool $update_user_status = true
): void {
$ilDB = $this->db;

// delete submissions
$exc_members = new ilExerciseMembers($exc);
foreach ($exc_members->getMembers() as $mem) {
$submission = new ilExSubmission($this, $mem);
$submission->deleteAllFiles();
}

$ilDB->manipulateF(
"DELETE FROM exc_usr_tutor " .
"WHERE ass_id = %s",
array("integer"),
array($this->getId())
);

// remove peer review data
if ($this->getPeerReview()) {
$peer_review = new ilExPeerReview($this);
$peer_review->resetPeerReviews();
}

$ilDB->manipulate(
"DELETE FROM exc_ass_file_order" .
" WHERE assignment_id = " . $ilDB->quote($this->getId(), 'integer')
);

$ilDB->manipulate(
"DELETE FROM exc_mem_ass_status" .
" WHERE ass_id = " . $ilDB->quote($this->getId(), 'integer')
);

$ilDB->manipulate(
"DELETE FROM exc_assignment WHERE " .
" id = " . $ilDB->quote($this->getId(), "integer")
);
$exc = new ilObjExercise($this->getExerciseId(), false);
$exc->updateAllUsersStatus();

$this->handleCalendarEntries("delete");
if ($update_user_status) {
$exc->updateAllUsersStatus();
}

$this->handleCalendarEntries("delete", $exc);

ilExcIndividualDeadline::deleteForAssignment($this->getId());

$reminder = new ilExAssignmentReminder();
$reminder->deleteReminders($this->getId());

// delete teams
$this->domain->team()->deleteTeamsOfAssignment($this->getId());

// delete resource collections and resources
$this->domain->assignment()->instructionFiles($this->getId())
->deleteCollection();
Expand Down Expand Up @@ -1328,8 +1367,10 @@ public static function createNewAssignmentRecords(
* Handle calendar entries for deadline(s)
* @throws ilDateTimeException
*/
protected function handleCalendarEntries(string $a_event): void
{
protected function handleCalendarEntries(
string $a_event,
ilObjExercise $exc
): void {
$ilAppEventHandler = $this->app_event_handler;

$dl_id = $this->getId() . "0";
Expand Down Expand Up @@ -1366,8 +1407,6 @@ protected function handleCalendarEntries(string $a_event): void
}
}

$exc = new ilObjExercise($this->getExerciseId(), false);

$ilAppEventHandler->raise(
'components/ILIAS/Exercise',
$a_event . 'Assignment',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1253,11 +1253,10 @@ public function deleteAssignmentsObject(): void
{
$ilCtrl = $this->ctrl;
$lng = $this->lng;

$delete = false;
foreach ($this->requested_ass_ids as $id) {
$ass = new ilExAssignment(ilUtil::stripSlashes($id));
$ass->delete();
$ass->delete($this->exc);
$delete = true;
}

Expand Down
50 changes: 50 additions & 0 deletions components/ILIAS/Exercise/Exercise/ExerciseManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* 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);

namespace ILIAS\Exercise;

class ExerciseManager
{
public function __construct(
protected InternalRepoService $repo,
protected InternalDomainService $domain,
protected $obj_id
) {
}

public function delete(
\ilObjExercise $exc
): void {
// delete assignments
$ass_manager = $this->domain->assignment()->assignments(
$this->obj_id,
0
);
foreach ($ass_manager->getAll() as $assignment) {
$this->domain->assignment()->getAssignment(
$assignment->getId()
)->delete($exc, false);
}

foreach (\ilExcCriteriaCatalogue::getInstancesByParentId($this->obj_id) as $crit_cat) {
$crit_cat->delete();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ public function delete(): void
);
}

public static function deleteForAssignment(int $ass_id): void
{
global $DIC;

$ilDB = $DIC->database();

$ilDB->manipulate(
"DELETE FROM exc_idl " .
" WHERE ass_id = " . $ilDB->quote($ass_id, "integer")
);
}


/**
* Get starting timestamp data for an assignment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,6 @@ public function delete(): void
" WHERE id = " . $ilDB->quote($this->id, "integer"));
}

public static function deleteByParent(int $a_parent_id): void
{
global $DIC;

$ilDB = $DIC->database();

if ($a_parent_id <= 0) {
return;
}

$ilDB->manipulate("DELETE FROM exc_crit" .
" WHERE parent = " . $ilDB->quote($a_parent_id, "integer"));
}

public function cloneObject(int $a_target_parent_id): int
{
$new_obj = new self();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
use ILIAS\DI\Container;
use ILIAS\Exercise\Object\ObjectManager;
use ILIAS\Exercise\Notification\NotificationManager;
use ILIAS\Refinery\Logical\Not;
use ILIAS\Exercise\InstructionFile\InstructionFileManager;
use ILIAS\Exercise\Team\TeamManager;
use ILIAS\Exercise\IndividualDeadline\IndividualDeadlineManager;
use ILIAS\Exercise\Submission\SubmissionManager;
Expand Down Expand Up @@ -100,7 +98,8 @@ public function team(): TeamManager
{
return new TeamManager(
$this->repo,
$this
$this,
new \ilExcTutorTeamFeedbackFileStakeholder()
);
}

Expand All @@ -109,4 +108,13 @@ public function individualDeadline(): IndividualDeadlineManager
return new IndividualDeadlineManager();
}

public function exercise(
int $obj_id
): ExerciseManager {
return new ExerciseManager(
$this->repo,
$this,
$obj_id
);
}
}
11 changes: 11 additions & 0 deletions components/ILIAS/Exercise/Submission/class.ilExSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ public static function deleteUser(
int $a_exc_id,
int $a_user_id
): void {
global $DIC;

$db = $DIC->database();

foreach (ilExAssignment::getInstancesByExercise($a_exc_id) as $ass) {
$submission = new self($ass, $a_user_id);
$submission->deleteAllFiles();
Expand All @@ -456,6 +460,13 @@ public static function deleteUser(
$member_status = $ass->getMemberStatus($a_user_id);
$member_status->setStatus("notgraded");
$member_status->update();

$db->manipulateF(
"DELETE FROM exc_usr_tutor " .
"WHERE ass_id = %s AND usr_id = %s",
array("integer", "integer"),
array($ass->getId(), $a_user_id)
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,9 @@ protected function parseRow(
if (!$has_no_team_yet) {
$this->tpl->setVariable(
"VAL_" . strtoupper($col),
ilLegacyFormElementsUtil::prepareFormOutput(trim((string) $a_row[$col]))
ilLegacyFormElementsUtil::prepareFormOutput(
trim((string) ($a_row[$col] ?? ""))
)
);
}
break;
Expand Down Expand Up @@ -457,7 +459,7 @@ protected function parseRow(
}
$this->tpl->setVariable(
"VAL_" . strtoupper($col),
$a_row[$col]
($a_row[$col] ?? false)
? ilDatePresentation::formatDate(
new ilDateTime($a_row[$col], IL_CAL_DATETIME),
false,
Expand Down
Loading

0 comments on commit 563e7c1

Please sign in to comment.