From ebe4db74ac608ded490ea49470e8029fab589a0d Mon Sep 17 00:00:00 2001 From: Stefan Hecken Date: Fri, 1 Sep 2023 11:42:33 +0200 Subject: [PATCH] TMS StudyProgramme: 8290 add new config option search recursive TMS StudyProgramme: 8290 be secure there is a tree path TMS OrgUnit: 8290 move position events after action is executed TMS StudyProgramme: 8290 check on automatism euqlas sry is not necessary TMS StudyProgramme: 8291 use assignment of process to check user should be removed or not --- ...rogrammeAutoMembershipTableUpdateSteps.php | 29 ++++++++++ .../classes/class.ilObjStudyProgramme.php | 54 ++++++++++++----- ....ilObjStudyProgrammeAutoMembershipsGUI.php | 58 ++++++++++++++----- ...lStudyProgrammeAutoMembershipsTableGUI.php | 23 +++++++- ...s.ilStudyProgrammeAutoMembershipSource.php | 15 ++++- ...dyProgrammeAutoMembershipsDBRepository.php | 56 +++++++++++------- ...ProgrammeMembershipSourceReaderFactory.php | 10 +++- ...udyProgrammeMembershipSourceReaderOrgu.php | 30 ++++++---- .../default/tpl.automembers_table_row.html | 3 + 9 files changed, 212 insertions(+), 66 deletions(-) create mode 100644 Modules/StudyProgramme/classes/Setup/ilStudyProgrammeAutoMembershipTableUpdateSteps.php diff --git a/Modules/StudyProgramme/classes/Setup/ilStudyProgrammeAutoMembershipTableUpdateSteps.php b/Modules/StudyProgramme/classes/Setup/ilStudyProgrammeAutoMembershipTableUpdateSteps.php new file mode 100644 index 000000000000..79c809eb551f --- /dev/null +++ b/Modules/StudyProgramme/classes/Setup/ilStudyProgrammeAutoMembershipTableUpdateSteps.php @@ -0,0 +1,29 @@ +db = $db; + } + + public function step_1(): void + { + $this->db->addTableColumn( + self::TABLE_NAME, + 'search_recursive', + [ + 'type' => 'integer', + 'length' => 1, + 'default' => 0, + 'notnull' => false + ] + ); + } +} diff --git a/components/ILIAS/StudyProgramme/classes/class.ilObjStudyProgramme.php b/components/ILIAS/StudyProgramme/classes/class.ilObjStudyProgramme.php index 393c6adde5b4..3b4c40fab590 100755 --- a/components/ILIAS/StudyProgramme/classes/class.ilObjStudyProgramme.php +++ b/components/ILIAS/StudyProgramme/classes/class.ilObjStudyProgramme.php @@ -517,7 +517,7 @@ public function getChildren(bool $include_references = false): array array_unique( array_map( static function ($data) { - return (int)$data['child']; + return (int) $data['child']; }, array_filter($ref_child_ref_ids, static function ($data) { return $data["deleted"] === null; @@ -1351,11 +1351,21 @@ public function getAutomaticMembershipSources(): array /** * Store a source to be monitored for automatic memberships. */ - public function storeAutomaticMembershipSource(string $type, int $src_id): void + // cat-tms-patch start #8290 + public function storeAutomaticMembershipSource(string $type, int $src_id, bool $search_recursive): void { - $ams = $this->auto_memberships_repository->create($this->getId(), $type, $src_id, false); + $ams = $this->auto_memberships_repository->create( + $this->getId(), + $type, + $src_id, + false, + null, + null, + $search_recursive + ); $this->auto_memberships_repository->update($ams); } + // cat-tms-patch end #8290 /** * Delete a membership source. @@ -1376,9 +1386,18 @@ public function deleteAllAutomaticMembershipSources(): void /** * Disable a membership source. */ - public function disableAutomaticMembershipSource(string $type, int $src_id): void + // cat-tms-patch start #8290 + public function disableAutomaticMembershipSource(string $type, int $src_id, bool $search_recursive): void { - $ams = $this->auto_memberships_repository->create($this->getId(), $type, $src_id, false); + $ams = $this->auto_memberships_repository->create( + $this->getId(), + $type, + $src_id, + false, + null, + null, + $search_recursive + ); $this->auto_memberships_repository->update($ams); } @@ -1386,7 +1405,7 @@ public function disableAutomaticMembershipSource(string $type, int $src_id): voi * Enable a membership source. * @throws ilException */ - public function enableAutomaticMembershipSource(string $type, int $src_id, bool $assign_now = false): void + public function enableAutomaticMembershipSource(string $type, int $src_id, bool $search_recursive, $assign_now = false): void { if ($assign_now) { $assigned_by = ilStudyProgrammeAutoMembershipSource::SOURCE_MAPPING[$type]; @@ -1397,7 +1416,15 @@ public function enableAutomaticMembershipSource(string $type, int $src_id, bool } } } - $ams = $this->auto_memberships_repository->create($this->getId(), $type, $src_id, true); + $ams = $this->auto_memberships_repository->create( + $this->getId(), + $type, + $src_id, + true, + null, + null, + $search_recursive + ); $this->auto_memberships_repository->update($ams); } @@ -1406,12 +1433,12 @@ public function enableAutomaticMembershipSource(string $type, int $src_id, bool * @return int[] * @throws InvalidArgumentException if $src_type is not in AutoMembershipSource-types */ - protected function getMembersOfMembershipSource(string $src_type, int $src_id): array + protected function getMembersOfMembershipSource(ilStudyProgrammeAutoMembershipSource $ams): array { - $source_reader = $this->membersourcereader_factory->getReaderFor($src_type, $src_id); + $source_reader = $this->membersourcereader_factory->getReaderFor($ams); return $source_reader->getMemberIds(); } - + // cat-tms-patch end #8290 /** * Get all StudyProgrammes monitoring this membership-source. @@ -1478,11 +1505,8 @@ public function getApplicableMembershipSourceForUser( ?int $exclude_id ): ?ilStudyProgrammeAutoMembershipSource { foreach ($this->getAutomaticMembershipSources() as $ams) { - $src_id = $ams->getSourceId(); - if ($src_id !== $exclude_id - && $ams->isEnabled() - ) { - $source_members = $this->getMembersOfMembershipSource($ams->getSourceType(), $src_id); + if ($ams->isEnabled()) { + $source_members = $this->getMembersOfMembershipSource($ams); if (in_array($usr_id, $source_members)) { return $ams; } diff --git a/components/ILIAS/StudyProgramme/classes/class.ilObjStudyProgrammeAutoMembershipsGUI.php b/components/ILIAS/StudyProgramme/classes/class.ilObjStudyProgrammeAutoMembershipsGUI.php index 17e40ac1be67..00519a4ebdc8 100755 --- a/components/ILIAS/StudyProgramme/classes/class.ilObjStudyProgrammeAutoMembershipsGUI.php +++ b/components/ILIAS/StudyProgramme/classes/class.ilObjStudyProgrammeAutoMembershipsGUI.php @@ -43,6 +43,9 @@ 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'; @@ -169,11 +172,10 @@ protected function view(bool $profile_not_public = false): void $data = []; foreach ($this->getObject()->getAutomaticMembershipSources() as $ams) { $title = $this->getTitleRepresentation($ams); - $usr = $this->getUserRepresentation($ams->getLastEditorId()); - $modal = $this->getModal($ams->getSourceType(), $ams->getSourceId()); + $usr = $this->getUserRepresentation($ams->getLastEditorId()) ?? $this->ui_factory->legacy('-'); + $modal = $this->getModal($ams->getSourceType(), $ams->getSourceId(), $ams->isSearchRecursive()); $collected_modals[] = $modal; - - $src_id = $ams->getSourceType() . '-' . $ams->getSourceId(); + $src_id = $ams->getSourceType() . '-' . $ams->getSourceId() . '-' . $ams->isSearchRecursive(); $actions = $this->getItemAction( $src_id, $modal->getShowSignal(), @@ -204,6 +206,7 @@ protected function save(): void $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]; if ( (is_null($src_type) || $src_type === "") || @@ -229,7 +232,7 @@ protected function save(): void ); } - $this->getObject()->storeAutomaticMembershipSource($src_type, (int) $src_id); + $this->getObject()->storeAutomaticMembershipSource($src_type, (int) $src_id, $search_recursive); $this->tpl->setOnScreenMessage("success", $this->txt("auto_add_success"), true); $this->ctrl->redirect($this, self::CMD_VIEW); } @@ -308,8 +311,10 @@ protected function enable(): void $get = $this->request->getQueryParams(); $field = self::CHECKBOX_SOURCE_IDS; if (array_key_exists($field, $get)) { - [$type, $id] = explode('-', $get[$field]); - $this->getObject()->enableAutomaticMembershipSource((string) $type, (int) $id); + // 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); } @@ -322,8 +327,8 @@ protected function disable(): void $get = $this->request->getQueryParams(); $field = self::CHECKBOX_SOURCE_IDS; if (array_key_exists($field, $get)) { - [$type, $id] = explode('-', $get[$field]); - $this->getObject()->disableAutomaticMembershipSource((string) $type, (int) $id); + [$type, $id, $search_recursive] = explode('-', $get[$field]); + $this->getObject()->disableAutomaticMembershipSource((string) $type, (int) $id, (bool) $search_recursive); } $this->ctrl->redirect($this, self::CMD_VIEW); } @@ -357,13 +362,18 @@ protected function getObject(): ilObjStudyProgramme return $this->object; } - protected function getModal(string $source_type = null, int $source_id = null): RoundTrip - { + protected function getModal( + string $source_type = null, + int $source_id = null, + bool $search_recursive = false + ): RoundTrip { $this->ctrl->setParameter($this, self::F_ORIGINAL_SOURCE_TYPE, $source_type); $this->ctrl->setParameter($this, self::F_ORIGINAL_SOURCE_ID, $source_id); + $this->ctrl->setParameter($this, self::F_SEARCH_RECURSIVE, $search_recursive); $link = $this->ctrl->getLinkTarget($this, "getAsynchModalOutput", "", true); $this->ctrl->setParameter($this, self::F_ORIGINAL_SOURCE_TYPE, null); $this->ctrl->setParameter($this, self::F_ORIGINAL_SOURCE_ID, null); + $this->ctrl->setParameter($this, self::F_SEARCH_RECURSIVE, null); return $this->ui_factory->modal()->roundtrip( '', @@ -388,6 +398,14 @@ protected function getAsynchModalOutput(): void } $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]; + } + $form = $this->getForm($current_src_type, $current_src_id, $search_recursive); $form_id = "form_" . $form->getId(); $modal = $this->ui_factory->modal()->roundtrip( @@ -453,8 +471,13 @@ function ($id) use ($form) { exit; } - protected function getForm(string $source_type = null, ?string $source_id = ''): ilPropertyFormGUI - { + 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(); if (is_null($source_type)) { @@ -517,6 +540,13 @@ protected function getForm(string $source_type = null, ?string $source_id = ''): $orgu->getExplorerGUI()->setRootId(ilObjOrgUnit::getRootOrgRefId()); $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->setChecked($search_recursive); + $radio_orgu->addSubItem($recurse); + // cat-tms-patch end #8290 $rgroup->addOption($radio_orgu); if ( !is_null($source_type) && @@ -727,7 +757,7 @@ static function (array $c): string { case ilStudyProgrammeAutoMembershipSource::TYPE_ORGU: $hops = array_map( static function (array $c): string { - return ilObject::_lookupTitle((int)$c["obj_id"]); + return ilObject::_lookupTitle((int) $c["obj_id"]); }, $this->tree->getPathFull($src_id) ); diff --git a/components/ILIAS/StudyProgramme/classes/class.ilStudyProgrammeAutoMembershipsTableGUI.php b/components/ILIAS/StudyProgramme/classes/class.ilStudyProgrammeAutoMembershipsTableGUI.php index c438b5c6eaaf..5fd3ff01da65 100755 --- a/components/ILIAS/StudyProgramme/classes/class.ilStudyProgrammeAutoMembershipsTableGUI.php +++ b/components/ILIAS/StudyProgramme/classes/class.ilStudyProgrammeAutoMembershipsTableGUI.php @@ -49,6 +49,9 @@ 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); @@ -57,18 +60,36 @@ public function __construct( protected function fillRow(array $a_set): void { - [$ams, $title, $usr, $actions] = $a_set; + /** @var ilStudyProgrammeAutoMembershipSource $ams */ + list($ams, $title, $usr, $actions) = $a_set; + + $username = ilObjUser::_lookupName($ams->getLastEditorId()); + $editor = implode(' ', [ + $username['firstname'], + $username['lastname'], + '(' . $username['login'] . ')' + ]); $id = $ams->getSourceType() . '-' . $ams->getSourceId(); $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); } diff --git a/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeAutoMembershipSource.php b/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeAutoMembershipSource.php index 0b72472e2fef..775b54f0ee82 100755 --- a/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeAutoMembershipSource.php +++ b/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeAutoMembershipSource.php @@ -44,13 +44,17 @@ class ilStudyProgrammeAutoMembershipSource 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 + DateTimeImmutable $last_edited, + bool $search_recursive ) { if (!in_array($source_type, [ self::TYPE_ROLE, @@ -67,7 +71,9 @@ public function __construct( $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 { @@ -98,4 +104,11 @@ 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 } diff --git a/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeAutoMembershipsDBRepository.php b/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeAutoMembershipsDBRepository.php index c6d4f422bf15..b8dc6aa40bc2 100755 --- a/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeAutoMembershipsDBRepository.php +++ b/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeAutoMembershipsDBRepository.php @@ -19,10 +19,10 @@ *********************************************************************/ /** -* Class ilStudyProgrammeAutoMembershipsDBRepository -* -* @author Nils Haagen -*/ + * Class ilStudyProgrammeAutoMembershipsDBRepository + * + * @author Nils Haagen + */ class ilStudyProgrammeAutoMembershipsDBRepository implements ilStudyProgrammeAutoMembershipsRepository { private const TABLE = 'prg_auto_membership'; @@ -32,6 +32,7 @@ class ilStudyProgrammeAutoMembershipsDBRepository implements ilStudyProgrammeAut private const FIELD_ENABLED = 'enabled'; private const FIELD_EDITOR_ID = 'last_usr_id'; private const FIELD_LAST_EDITED = 'last_edited'; + private const FIELD_SEARCH_RECURSIVE = 'search_recursive'; protected ilDBInterface $db; protected int$current_usr_id; @@ -53,7 +54,8 @@ public function getFor(int $prg_obj_id): array . self::FIELD_SOURCE_ID . ',' . self::FIELD_ENABLED . ',' . self::FIELD_EDITOR_ID . ',' - . self::FIELD_LAST_EDITED + . self::FIELD_LAST_EDITED . ',' + . self::FIELD_SEARCH_RECURSIVE . PHP_EOL . 'FROM ' . self::TABLE . PHP_EOL . 'WHERE ' . self::FIELD_PRG_OBJ_ID . ' = ' . $this->db->quote($prg_obj_id, 'integer'); @@ -66,7 +68,8 @@ public function getFor(int $prg_obj_id): array (int) $rec[self::FIELD_SOURCE_ID], (bool) $rec[self::FIELD_ENABLED], (int) $rec[self::FIELD_EDITOR_ID], - new DateTimeImmutable($rec[self::FIELD_LAST_EDITED]) + new DateTimeImmutable($rec[self::FIELD_LAST_EDITED]), + (bool) $rec[self::FIELD_SEARCH_RECURSIVE] ); } return $ret; @@ -78,7 +81,8 @@ public function create( int $source_id, bool $enabled, int $last_edited_usr_id = null, - DateTimeImmutable $last_edited = null + DateTimeImmutable $last_edited = null, + bool $search_recursive = false ): ilStudyProgrammeAutoMembershipSource { if (is_null($last_edited_usr_id)) { $last_edited_usr_id = $this->current_usr_id; @@ -92,7 +96,8 @@ public function create( $source_id, $enabled, $last_edited_usr_id, - $last_edited + $last_edited, + $search_recursive ); } @@ -121,7 +126,8 @@ function (ilDBInterface $db) use ($ams, $current_usr_id) { self::FIELD_SOURCE_ID => ['integer', $ams->getSourceId()], self::FIELD_ENABLED => ['integer', $ams->isEnabled()], self::FIELD_EDITOR_ID => ['integer', $current_usr_id], - self::FIELD_LAST_EDITED => ['timestamp', $now] + self::FIELD_LAST_EDITED => ['timestamp', $now], + self::FIELD_SEARCH_RECURSIVE => ['integer', $ams->isSearchRecursive()] ] ); } @@ -157,17 +163,27 @@ public function deleteFor(int $prg_obj_id): void */ public static function getProgrammesFor(string $source_type, int $source_id): array { - global $ilDB; - $query = 'SELECT ' . self::FIELD_PRG_OBJ_ID - . PHP_EOL . 'FROM ' . self::TABLE . ' prgs' - . PHP_EOL . 'INNER JOIN object_reference oref ON ' - . 'prgs.' . self::FIELD_PRG_OBJ_ID . ' = oref.obj_id' - . PHP_EOL . 'WHERE ' . self::FIELD_SOURCE_TYPE . ' = ' . $ilDB->quote($source_type, 'text') - . PHP_EOL . 'AND ' . self::FIELD_SOURCE_ID . ' = ' . $ilDB->quote($source_id, 'integer') - . PHP_EOL . 'AND ' . self::FIELD_ENABLED . ' = 1' - . PHP_EOL . 'AND oref.deleted IS NULL'; + global $DIC; + $db = $DIC["ilDB"]; + + $q = "SELECT path FROM tree WHERE child = " . $db->quote($source_id, "integer"); + $res = $db->query($q); + $row = $db->fetchAssoc($res); + $path = explode(".", $row["path"] ?? ""); + + $query = 'SELECT ' . self::FIELD_PRG_OBJ_ID . PHP_EOL + . 'FROM ' . self::TABLE . ' prgs' . PHP_EOL + . 'INNER JOIN object_reference oref ON ' . PHP_EOL + . 'prgs.' . self::FIELD_PRG_OBJ_ID . ' = oref.obj_id' . PHP_EOL + . 'WHERE (' + . self::FIELD_SOURCE_ID . ' = ' . $db->quote($source_id, 'integer') . PHP_EOL + . ' OR (' . $db->in(self::FIELD_SOURCE_ID, $path, false, 'integer') . ' AND search_recursive = 1)' . PHP_EOL + . ')' . PHP_EOL + . 'AND ' . self::FIELD_ENABLED . ' = 1' . PHP_EOL + . 'AND ' . self::FIELD_SOURCE_TYPE . ' = ' . $db->quote($source_type, 'text') . PHP_EOL + . 'AND oref.deleted IS NULL'; - $res = $ilDB->query($query); - return $ilDB->fetchAll($res); + $res = $db->query($query); + return $db->fetchAll($res); } } diff --git a/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeMembershipSourceReaderFactory.php b/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeMembershipSourceReaderFactory.php index 995454dc4edc..c5188c0692d5 100755 --- a/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeMembershipSourceReaderFactory.php +++ b/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeMembershipSourceReaderFactory.php @@ -35,9 +35,10 @@ public function __construct(Pimple\Container $dic) * * @throws InvalidArgumentException if $src_type is not one of the constant types in ilStudyProgrammeAutoMembershipSource. */ - public function getReaderFor(string $src_type, int $src_id): ilStudyProgrammeMembershipSourceReader + public function getReaderFor(ilStudyProgrammeAutoMembershipSource $ams, int $exclude_id): ilStudyProgrammeMembershipSourceReader { - switch ($src_type) { + $src_id = $ams->getSourceId(); + switch ($ams->getSourceType()) { case ilStudyProgrammeAutoMembershipSource::TYPE_ROLE: return new ilStudyProgrammeMembershipSourceReaderRole( $this->dic['rbacreview'], @@ -51,7 +52,10 @@ public function getReaderFor(string $src_type, int $src_id): ilStudyProgrammeMem case ilStudyProgrammeAutoMembershipSource::TYPE_ORGU: return new ilStudyProgrammeMembershipSourceReaderOrgu( ilObjOrgUnitTree::_getInstance(), - $src_id + new ilOrgUnitUserAssignment(), + $src_id, + $ams->isSearchRecursive(), + $exclude_id ); default: diff --git a/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeMembershipSourceReaderOrgu.php b/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeMembershipSourceReaderOrgu.php index 700591ce937b..a8556091c574 100755 --- a/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeMembershipSourceReaderOrgu.php +++ b/components/ILIAS/StudyProgramme/classes/model/AutoMemberships/class.ilStudyProgrammeMembershipSourceReaderOrgu.php @@ -23,19 +23,13 @@ */ class ilStudyProgrammeMembershipSourceReaderOrgu implements ilStudyProgrammeMembershipSourceReader { - protected ilObjOrgUnitTree $orgu_tree; - protected int $src_id; - protected ilOrgUnitUserAssignmentDBRepository $assignmentRepo; - public function __construct( - ilObjOrgUnitTree $orgu_tree, - int $src_id + protected ilObjOrgUnitTree $orgu_tree, + protected ilOrgUnitUserAssignment $orgu_assignment, + protected int $src_id, + protected bool $search_recursive, + protected int $exclude_id ) { - $this->orgu_tree = $orgu_tree; - $this->src_id = $src_id; - - $dic = ilOrgUnitLocalDIC::dic(); - $this->assignmentRepo = $dic["repo.UserAssignments"]; } /** @@ -43,6 +37,18 @@ public function __construct( */ public function getMemberIds(): array { - return $this->assignmentRepo->getUsersByOrgUnits([$this->src_id]); + $children[] = $this->src_id; + if ($this->search_recursive) { + $children = array_unique(array_merge($children, $this->orgu_tree->getChildren($this->src_id))); + } + + $assignees = $this->orgu_assignment::where( + ['orgu_id' => $children] + )->getArray('id', 'user_id'); + + return array_map( + 'intval', + array_values($assignees) + ); } } diff --git a/components/ILIAS/StudyProgramme/templates/default/tpl.automembers_table_row.html b/components/ILIAS/StudyProgramme/templates/default/tpl.automembers_table_row.html index bc705c3f3bf9..fd4609388e17 100755 --- a/components/ILIAS/StudyProgramme/templates/default/tpl.automembers_table_row.html +++ b/components/ILIAS/StudyProgramme/templates/default/tpl.automembers_table_row.html @@ -17,6 +17,9 @@ {STATUS} + + {SEARCH_RECURSIVE} + {ACTIONS}