Skip to content

Commit

Permalink
StudyProgramme: fix/amend 'AutomembershipSource Orgu recursive'
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaagen authored and klees committed Aug 23, 2024
1 parent ebe4db7 commit adbabb1
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
<?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);

class ilStudyProgrammeAutoMembershipTableUpdateSteps implements ilDatabaseUpdateSteps
Expand All @@ -22,7 +38,7 @@ public function step_1(): void
'type' => 'integer',
'length' => 1,
'default' => 0,
'notnull' => false
'notnull' => true
]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ public function getUpdateObjective(Config $config = null): Objective
return new ObjectiveCollection(
'Database is updated for component/ILIAS/StudyProgramme',
false,
// ILIAS 10
new ilDatabaseUpdateStepsExecutedObjective(
new ilMigrateStudyProgrammeCertificateProviderDBUpdateSteps()
),
new ilDatabaseUpdateStepsExecutedObjective(
new ilStudyProgrammeAutoMembershipTableUpdateSteps()
),
);
}

Expand All @@ -47,10 +51,15 @@ public function getStatusObjective(Metrics\Storage $storage): Objective
return new ObjectiveCollection(
'Database is updated for component/ILIAS/StudyProgramme',
true,
// ILIAS 10
new ilDatabaseUpdateStepsMetricsCollectedObjective(
$storage,
new ilMigrateStudyProgrammeCertificateProviderDBUpdateSteps()
),
new ilDatabaseUpdateStepsMetricsCollectedObjective(
$storage,
new ilStudyProgrammeAutoMembershipTableUpdateSteps()
),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,6 @@ public function getAutomaticMembershipSources(): array
/**
* Store a source to be monitored for automatic memberships.
*/
// cat-tms-patch start #8290
public function storeAutomaticMembershipSource(string $type, int $src_id, bool $search_recursive): void
{
$ams = $this->auto_memberships_repository->create(
Expand All @@ -1365,7 +1364,6 @@ public function storeAutomaticMembershipSource(string $type, int $src_id, bool $
);
$this->auto_memberships_repository->update($ams);
}
// cat-tms-patch end #8290

/**
* Delete a membership source.
Expand All @@ -1386,7 +1384,6 @@ public function deleteAllAutomaticMembershipSources(): void
/**
* Disable a membership source.
*/
// cat-tms-patch start #8290
public function disableAutomaticMembershipSource(string $type, int $src_id, bool $search_recursive): void
{
$ams = $this->auto_memberships_repository->create(
Expand Down Expand Up @@ -1438,7 +1435,6 @@ protected function getMembersOfMembershipSource(ilStudyProgrammeAutoMembershipSo
$source_reader = $this->membersourcereader_factory->getReaderFor($ams);
return $source_reader->getMemberIds();
}
// cat-tms-patch end #8290

/**
* Get all StudyProgrammes monitoring this membership-source.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ class ilObjStudyProgrammeAutoMembershipsGUI
private const F_SOURCE_ID = 'f_sid';
private const F_ORIGINAL_SOURCE_TYPE = 'f_st_org';
private const F_ORIGINAL_SOURCE_ID = 'f_sid_org';
// cat-tms-patch start #8290
private const F_SEARCH_RECURSIVE = "f_search_recursive";
// cat-tms-patch end #8290

private const CMD_VIEW = 'view';
private const CMD_SAVE = 'save';
private const CMD_DELETE = 'delete';
Expand Down Expand Up @@ -205,8 +202,8 @@ protected function save(): void
$post = $this->request->getParsedBody();
$form->setValuesByArray($post);
$src_type = $post[self::F_SOURCE_TYPE];
$src_id = $post[self::F_SOURCE_ID . $src_type];
$search_recursive = (bool) $post[self::F_SEARCH_RECURSIVE];
$src_id = $post[self::F_SOURCE_ID . $src_type] ?? null;
$search_recursive = (bool) ($post[self::F_SEARCH_RECURSIVE] ?? false);

if (
(is_null($src_type) || $src_type === "") ||
Expand Down Expand Up @@ -311,10 +308,8 @@ protected function enable(): void
$get = $this->request->getQueryParams();
$field = self::CHECKBOX_SOURCE_IDS;
if (array_key_exists($field, $get)) {
// cat-tms-patch start #8290
[$type, $id, $search_recursive] = explode('-', $get[$field]);
$this->getObject()->enableAutomaticMembershipSource((string) $type, (int) $id, (bool) $search_recursive);
// cat-tms-patch end #8290
}
$this->ctrl->redirect($this, self::CMD_VIEW);
}
Expand Down Expand Up @@ -394,16 +389,12 @@ protected function getAsynchModalOutput(): void

$current_src_id = null;
if ($this->request_wrapper->has(self::F_ORIGINAL_SOURCE_ID)) {
$current_src_id = $this->request_wrapper->retrieve(self::F_ORIGINAL_SOURCE_ID, $this->refinery->to()->string());
$current_src_id = $this->request_wrapper->retrieve(self::F_ORIGINAL_SOURCE_ID, $this->refinery->kindlyTo()->int());
}

$form = $this->getForm($current_src_type, $current_src_id);
$search_recursive = false;
if (
array_key_exists(self::F_SEARCH_RECURSIVE, $_GET) &&
!is_null($_GET[self::F_SEARCH_RECURSIVE])
) {
$search_recursive = (bool) $_GET[self::F_SEARCH_RECURSIVE];
if ($this->request_wrapper->has(self::F_SEARCH_RECURSIVE)) {
$search_recursive = $this->request_wrapper->retrieve(self::F_SEARCH_RECURSIVE, $this->refinery->kindlyTo()->bool());
}
$form = $this->getForm($current_src_type, $current_src_id, $search_recursive);
$form_id = "form_" . $form->getId();
Expand Down Expand Up @@ -474,9 +465,7 @@ function ($id) use ($form) {
protected function getForm(
string $source_type = null,
int $source_id = null,
// cat-tms-patch start #8290
bool $search_recursive = false
// cat-tms-patch end #8290
): ilPropertyFormGUI {
$form = new ilPropertyFormGUI();

Expand Down Expand Up @@ -541,12 +530,10 @@ protected function getForm(
$orgu->getExplorerGUI()->setAjax(false);
$radio_orgu->addSubItem($orgu);

// cat-tms-patch start #8290
$recurse = new ilCheckboxInputGUI($this->txt('search_for_orgu_members_recursive'), self::F_SEARCH_RECURSIVE);
$recurse->setValue(1);
$recurse->setValue('1');
$recurse->setChecked($search_recursive);
$radio_orgu->addSubItem($recurse);
// cat-tms-patch end #8290
$rgroup->addOption($radio_orgu);
if (
!is_null($source_type) &&
Expand Down Expand Up @@ -576,7 +563,7 @@ protected function getForm(
$form->addItem($hi);

$hi = new ilHiddenInputGUI(self::F_ORIGINAL_SOURCE_ID);
$hi->setValue($source_id ?? '');
$hi->setValue((string) $source_id ?? '');
$form->addItem($hi);

return $form;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

/**
* Class ilStudyProgrammeAutoMembershipsTableGUI
*
Expand Down Expand Up @@ -49,9 +49,7 @@ public function __construct(
$this->addColumn($this->lng->txt('last_edited_by'), 'editor');
$this->addColumn($this->lng->txt('last_edited'), 'last');
$this->addColumn($this->lng->txt('status'), 'status');
// cat-tms-patch start #8290
$this->addColumn($this->lng->txt('search_for_orgu_members_recursive'), 'search_recursive');
// cat-tms-patch end #8290
$this->addColumn($this->lng->txt('actions'), 'actions');
$this->setSelectAllCheckbox(ilObjStudyProgrammeAutoMembershipsGUI::CHECKBOX_SOURCE_IDS . '[]');
$this->setEnableAllCommand(true);
Expand All @@ -74,22 +72,18 @@ protected function fillRow(array $a_set): void
$status = $ams->isEnabled() ? $this->lng->txt('active') : $this->lng->txt('inactive');
$date = $this->getDatePresentation($ams->getLastEdited()->getTimestamp());

// cat-tms-patch start #8290
$search_recursive = $this->lng->txt("no");
if ($ams->isSearchRecursive()) {
$search_recursive = $this->lng->txt("yes");
}
// cat-tms-patch end #8290

$this->tpl->setVariable("ID", $id);
$this->tpl->setVariable("TYPE", $this->lng->txt($ams->getSourceType()));
$this->tpl->setVariable("TITLE", $title);
$this->tpl->setVariable("EDITOR", $usr);
$this->tpl->setVariable("LAST_EDITED", $date);
$this->tpl->setVariable("STATUS", $status);
// cat-tms-patch start #8290
$this->tpl->setVariable("SEARCH_RECURSIVE", $search_recursive);
// cat-tms-patch end #8290
$this->tpl->setVariable("ACTIONS", $actions);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

/**
* Class ilStudyProgrammeAutoMembershipSource
*
Expand All @@ -37,24 +37,14 @@ class ilStudyProgrammeAutoMembershipSource
self::TYPE_ORGU => ilPRGAssignment::AUTO_ASSIGNED_BY_ORGU
];

protected int $prg_obj_id;
protected string $source_type;
protected int $source_id;
protected bool $enabled;
protected int $last_edited_usr_id;
protected DateTimeImmutable $last_edited;

// cat-tms-patch start #8290
protected bool $search_recursive;

public function __construct(
int $prg_obj_id,
string $source_type,
int $source_id,
bool $enabled,
int $last_edited_usr_id,
DateTimeImmutable $last_edited,
bool $search_recursive
protected int $prg_obj_id,
protected string $source_type,
protected int $source_id,
protected bool $enabled,
protected int $last_edited_usr_id,
protected DateTimeImmutable $last_edited,
protected bool $search_recursive
) {
if (!in_array($source_type, [
self::TYPE_ROLE,
Expand All @@ -64,16 +54,7 @@ public function __construct(
])) {
throw new InvalidArgumentException("Invalid source-type: " . $source_type, 1);
}

$this->prg_obj_id = $prg_obj_id;
$this->source_type = $source_type;
$this->source_id = $source_id;
$this->enabled = $enabled;
$this->last_edited_usr_id = $last_edited_usr_id;
$this->last_edited = $last_edited;
$this->search_recursive = $search_recursive;
}
// cat-tms-patch end #8290

public function getPrgObjId(): int
{
Expand Down Expand Up @@ -105,10 +86,8 @@ public function getLastEdited(): DateTimeImmutable
return $this->last_edited;
}

// cat-tms-patch start #8290
public function isSearchRecursive(): bool
{
return $this->search_recursive;
}
// cat-tms-patch end #8290
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

/**
* Class ilStudyProgrammeAutoMembershipsDBRepository
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

/**
* Provides adapters to read member-ids from a specific source.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,7 @@
*
*********************************************************************/

declare(strict_types=1);
/**
* Provides adapters to read member-ids from a specific source.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

use PHPUnit\Framework\TestCase;

class ilStudyProgrammeAutoMembershipsSourceTest extends TestCase
Expand Down Expand Up @@ -47,7 +47,8 @@ public function testConstruction(): ilStudyProgrammeAutoMembershipSource
$this->source_id,
$this->enbl,
$this->usr_id,
$this->dat
$this->dat,
false
);
$this->assertInstanceOf(
ilStudyProgrammeAutoMembershipSource::class,
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -15245,6 +15245,7 @@ search#:#search_filter_cd#:#Filter nach Erstellungsdatum
search#:#search_for_crs_members#:#Nach Kursen suchen
search#:#search_for_grp_members#:#Nach Gruppen suchen
search#:#search_for_orgu_members#:#Nach Organisationseinheiten suchen
search#:#search_for_orgu_members_recursive#:#Darunterliegende einbeziehen?
search#:#search_for_role_members#:#Nach Rollen suchen
search#:#search_for_users#:#Nach Benutzern suchen
search#:#search_grp_title#:#Gruppenname
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -15176,6 +15176,7 @@ search#:#search_filter_cd#:#Filter by Creation Date
search#:#search_for_crs_members#:#Search for Courses
search#:#search_for_grp_members#:#Search for Groups
search#:#search_for_orgu_members#:#Search for Organisational Units
search#:#search_for_orgu_members_recursive#:#Include Subunits?
search#:#search_for_role_members#:#Search for Roles
search#:#search_for_users#:#Search for Users
search#:#search_grp_title#:#Group Name
Expand Down

0 comments on commit adbabb1

Please sign in to comment.