Skip to content

Commit

Permalink
Fixes/from ilias 6 (#4115)
Browse files Browse the repository at this point in the history
* cherry-pick #2742

* Org.Units: Fix filter when listing courses for user (#4035)

* cherry pick #3768

* show enrolments for a single user (#3595)

* Allows custom positions to be imported. (#3113)

* Update class.ilOrgUnitSimpleUserImport.php

* cherry-pick #2778

* cherry-pick #2769

* cherry-pick #4078


Co-authored-by: Stefan Hecken <[email protected]>
Co-authored-by: Michael Jansen <[email protected]>
Co-authored-by: Jephte Abijuru <[email protected]>
Co-authored-by: Evan Jackson <[email protected]>
Co-authored-by: Marvin Barz <[email protected]>
  • Loading branch information
6 people authored Mar 10, 2022
1 parent b6cd535 commit 9dab9a8
Show file tree
Hide file tree
Showing 17 changed files with 202 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Modules/Cloud/classes/class.ilCloudFileTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public function getServiceName() : string
return $this->service_name;
}

public function isCaseSensitive() : boolean
public function isCaseSensitive() : bool
{
return $this->case_sensitive;
}

public function setCaseSensitive(boolean $case_sensitive)
public function setCaseSensitive(bool $case_sensitive)
{
$this->case_sensitive = $case_sensitive;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/Cloud/classes/class.ilObjCloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function currentUserIsOwner() : bool
return ($ilUser->getId() === $this->getOwnerId());
}

public function setAuthComplete(boolean $auth_complete) : void
public function setAuthComplete(bool $auth_complete) : void
{
$this->auth_complete = $auth_complete;
}
Expand Down
2 changes: 2 additions & 0 deletions Modules/OrgUnit/classes/ARHelper/BaseCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ abstract class BaseCommands
const CMD_EDIT = "edit";
const CMD_UPDATE = "update";
const CMD_CONFIRM = "confirm";
const CMD_CONFIRM_RECURSIVE = "confirmRecursive";
const CMD_DELETE = "delete";
const CMD_DELETE_RECURSIVE = "deleteRecursive";
const CMD_CANCEL = "cancel";
const AR_ID = "arid";
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,27 @@ class ilOrgUnitDefaultPermissionFormGUI extends ilPropertyFormGUI
* @var \ilOrgUnitPermission[]
*/
protected $ilOrgUnitPermissions = [];
/**
* @var ilObjectDefinition
*/
protected $objectDefinition;

/**
* ilOrgUnitDefaultPermissionFormGUI constructor.
* @param \ILIAS\Modules\OrgUnit\ARHelper\BaseCommands $parent_gui
* @param ilOrgUnitPermission[] $ilOrgUnitPermissionsFilter
* @param ilObjectDefinition $objectDefinition
*/
public function __construct(BaseCommands $parent_gui, array $ilOrgUnitPermissionsFilter)
{
public function __construct(
BaseCommands $parent_gui,
array $ilOrgUnitPermissionsFilter,
ilObjectDefinition $objectDefinition
) {
$this->parent_gui = $parent_gui;
$this->ilOrgUnitPermissions = $ilOrgUnitPermissionsFilter;
$this->dic()->ctrl()->saveParameter($parent_gui, 'arid');
$this->setFormAction($this->dic()->ctrl()->getFormAction($this->parent_gui));
$this->objectDefinition = $objectDefinition;
$this->initFormElements();
$this->initButtons();
$this->setTarget('_top');
Expand Down Expand Up @@ -63,12 +72,12 @@ protected function initFormElements()
foreach ($this->ilOrgUnitPermissions as $ilOrgUnitPermission) {
$header = new ilFormSectionHeaderGUI();
$context = $ilOrgUnitPermission->getContext()->getContext();
$header->setTitle($this->txt("obj_{$context}", false));
$header->setTitle($this->getTitleForFormHeaderByContext($context));
$this->addItem($header);

// Checkboxes
foreach ($ilOrgUnitPermission->getPossibleOperations() as $operation) {
$title = $this->txt("org_op_{$operation->getOperationString()}", false);
$title = $this->txt("org_op_{$operation->getOperationString()}");
$id = $operation->getOperationId();
$cb = new ilCheckboxInputGUI($title, "operations[{$context}][{$id}]");
$this->addItem($cb);
Expand Down Expand Up @@ -142,4 +151,14 @@ protected function txt($key)
{
return $this->parent_gui->txt($key);
}

protected function getTitleForFormHeaderByContext(string $context)
{
$lang_code = "obj_{$context}";
if ($this->objectDefinition->isPlugin($context)) {
return ilObjectPlugin::lookupTxtById($context, $lang_code);
}

return $this->txt($lang_code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ protected function index()
$this->getParentGui()->addSubTabs();
$this->getParentGui()->activeSubTab(ilOrgUnitPositionGUI::SUBTAB_PERMISSIONS);
$ilOrgUnitPermissions = ilOrgUnitPermissionQueries::getAllTemplateSetsForAllActivedContexts($this->getCurrentPositionId());
$ilOrgUnitDefaultPermissionFormGUI = new ilOrgUnitDefaultPermissionFormGUI($this, $ilOrgUnitPermissions);
$ilOrgUnitDefaultPermissionFormGUI = new ilOrgUnitDefaultPermissionFormGUI(
$this,
$ilOrgUnitPermissions,
$this->dic()["objDefinition"]
);
$ilOrgUnitDefaultPermissionFormGUI->fillForm();

$this->setContent($ilOrgUnitDefaultPermissionFormGUI->getHTML());
Expand All @@ -31,9 +35,12 @@ protected function index()
protected function update()
{
$this->getParentGui()->addSubTabs();
$ilOrgUnitPermissions = ilOrgUnitPermissionQueries::getAllTemplateSetsForAllActivedContexts($this->getCurrentPositionId(),
true);
$ilOrgUnitDefaultPermissionFormGUI = new ilOrgUnitDefaultPermissionFormGUI($this, $ilOrgUnitPermissions);
$ilOrgUnitPermissions = ilOrgUnitPermissionQueries::getAllTemplateSetsForAllActivedContexts($this->getCurrentPositionId(), true);
$ilOrgUnitDefaultPermissionFormGUI = new ilOrgUnitDefaultPermissionFormGUI(
$this,
$ilOrgUnitPermissions,
$this->dic()["objDefinition"]
);
if ($ilOrgUnitDefaultPermissionFormGUI->saveObject()) {
$this->main_tpl->setOnScreenMessage('success', $this->txt('msg_success_permission_saved'), true);
$this->cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ public function fillRow(array $a_set) : void
*/
protected function addActions(&$selection)
{
$selection->addItem($this->lng->txt("remove"), "delete_from_employees",
$this->ctrl->getLinkTargetByClass(ilOrgUnitUserAssignmentGUI::class,
ilOrgUnitUserAssignmentGUI::CMD_CONFIRM));
$selection->addItem($this->lng->txt("remove"), "delete_from_employees", $this->ctrl->getLinkTargetByClass(ilOrgUnitUserAssignmentGUI::class, ilOrgUnitUserAssignmentGUI::CMD_CONFIRM_RECURSIVE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ protected function assignmentsRecursive()
}

protected function confirm()
{
$confirmation = $this->getConfirmationGUI();
$confirmation->setConfirm($this->txt('remove_user'), self::CMD_DELETE);

$this->setContent($confirmation->getHTML());
}

protected function confirmRecursive()
{
$confirmation = $this->getConfirmationGUI();
$confirmation->setConfirm($this->txt('remove_user'), self::CMD_DELETE_RECURSIVE);

$this->setContent($confirmation->getHTML());
}

protected function getConfirmationGUI() : ilConfirmationGUI
{
$this->ctrl()->saveParameter($this, 'position_id');
$r = $this->http()->request();
Expand All @@ -106,13 +122,11 @@ protected function confirm()
*/
$confirmation = new ilConfirmationGUI();
$confirmation->setFormAction($this->ctrl()->getFormAction($this));
$confirmation->setCancel($this->txt(self::CMD_CANCEL), self::CMD_CANCEL);
$confirmation->setConfirm($this->txt('remove_user'), self::CMD_DELETE);
$confirmation->setHeaderText(sprintf($this->txt('msg_confirm_remove_user'), $ilOrgUnitPosition->getTitle()));
$confirmation->addItem('usr_id', $r->getQueryParams()['usr_id'],
ilObjUser::_lookupLogin($r->getQueryParams()['usr_id']));
$confirmation->addItem('usr_id', $r->getQueryParams()['usr_id'], ilObjUser::_lookupLogin($r->getQueryParams()['usr_id']));
$confirmation->setCancel($this->txt(self::CMD_CANCEL), self::CMD_CANCEL);

$this->setContent($confirmation->getHTML());
return $confirmation;
}

protected function delete()
Expand All @@ -126,6 +140,20 @@ protected function delete()
$this->cancel();
}

protected function deleteRecursive()
{
$r = $this->http()->request();
$assignments = ilOrgUnitUserAssignmentQueries::getInstance()
->getAssignmentsOfUserIdAndPosition((int) $_POST['usr_id'], (int) $r->getQueryParams()['position_id'])
;

foreach ($assignments as $assignment) {
$assignment->delete();
}
ilUtil::sendSuccess($this->txt('remove_successful'), true);
$this->cancel();
}

protected function cancel()
{
$this->ctrl()->redirect($this, self::CMD_INDEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ public function getAssignmentsOfUserId($user_id)
return ilOrgUnitUserAssignment::where(['user_id' => $user_id])->get();
}

/**
* @param $user_id
*
* @return ilOrgUnitUserAssignment[]
*/
public function getAssignmentsOfUserIdAndPosition(int $user_id, int $position_id) : array
{
return ilOrgUnitUserAssignment::where(
[
'user_id' => $user_id,
'position_id' => $position_id
]
)->get();
}

/**
* @param $orgunit_ref_id
* @return ilOrgUnitUserAssignment[]
Expand Down
8 changes: 7 additions & 1 deletion Modules/OrgUnit/classes/Provider/OrgUnitToolProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ private function getTree() : Tree

private function getTreeRecursion() : TreeRecursion
{
$tree = new ilOrgUnitExplorerGUI("orgu_explorer", ilObjOrgUnitGUI::class, "showTree", new ilTree(1));
$tree = new ilOrgUnitExplorerGUI(
"orgu_explorer",
ilObjOrgUnitGUI::class,
"showTree",
new ilTree(1),
$this->dic["ilAccess"]
);
$tree->setTypeWhiteList($this->getTreeWhiteList());
$tree->setRootId(ilObjOrgUnit::getRootOrgRefId());
$tree->setPathOpen($_GET['item_ref_id'] ?? $_GET['ref_id'] ?? '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ public function simpleUserImportElement(SimpleXMLElement $a)
} elseif ($role === 'superior') {
$position_id = ilOrgUnitPosition::CORE_POSITION_SUPERIOR;
} else {
$this->addError('not_a_valid_role', $user_id);

return;
//if passed a custom position.
$position = ilOrgUnitPosition::where(['title' => $role])->first();
if ($position instanceof ilOrgUnitPosition) {
$position_id = $position->getId();
} else {
$this->addError('not_a_valid_role', $user_id);
return;
}
}

if ($action == 'add') {
Expand Down
34 changes: 33 additions & 1 deletion Modules/OrgUnit/classes/class.ilOrgUnitExplorerGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,30 @@ class ilOrgUnitExplorerGUI extends ilTreeExplorerGUI implements TreeRecursion
* @var array
*/
protected $stay_with_command = array('', 'render', 'view', 'infoScreen', 'showStaff', 'performPaste', 'cut');
/**
* @var
*/
protected ?ilTree $tree = null;

/**
* @var ilAccessHandler
*/
protected $access;

/**
* @param $a_expl_id
* @param $a_parent_obj
* @param $a_parent_cmd
* @param $a_tree
* @param $access
*/
public function __construct($a_expl_id, $a_parent_obj, $a_parent_cmd, $a_tree)
public function __construct($a_expl_id, $a_parent_obj, $a_parent_cmd, $a_tree, \ilAccessHandler $access = null)
{
parent::__construct($a_expl_id, $a_parent_obj, $a_parent_cmd, $a_tree);
$this->setAjax(true);
$this->setTypeWhiteList(array(self::ORGU));
$this->tree->initLangCode();
$this->access = $access;
}

/**
Expand Down Expand Up @@ -155,4 +166,25 @@ public function isNodeSelectable($a_node) : bool

return !($a_node['child'] === $current_node || $this->tree->isGrandChild($current_node, $a_node['child']));
}

public function getChildsOfNode($a_parent_node_id) : array
{
$children = parent::getChildsOfNode($a_parent_node_id);

if (!is_null($this->access)) {
$children = $this->filterChildrenByPermission($children);
}

return $children;
}

protected function filterChildrenByPermission(array $children) : array
{
return array_filter(
$children,
function ($child) {
return $this->access->checkAccess("visible", "", $child["ref_id"]);
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ilMStListCompetencesSkill
protected string $login;
protected string $last_name;
protected string $first_name;
protected integer $user_id;
protected int $user_id;

public function __construct(
string $skill_title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ protected function createWhereStatement(array $arr_filter): string
$where[] = 'usr_id = ' . $this->dic->database()->quote($arr_filter['usr_id'], \ilDBConstants::T_INTEGER);
}

if (isset($arr_filter['usr_id']) && is_numeric($arr_filter['usr_id'])) {
$where[] = 'usr_id = ' . $this->dic->database()->quote($arr_filter['usr_id'], \ilDBConstants::T_INTEGER);
}

if (!empty($where)) {
return ' WHERE ' . implode(' AND ', $where) . ' ';
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function __construct()
global $DIC;
$this->main_tpl = $DIC->ui()->mainTemplate();
$this->access = ilMyStaffAccess::getInstance();
$this->help = $DIC->help();
$this->help->setScreenIdComponent('msta');
}

protected function checkAccessOrFail() : void
Expand Down Expand Up @@ -80,6 +82,7 @@ final public function listUsers() : void
global $DIC;

$this->checkAccessOrFail();
$this->help->setScreenId('courses_list');

$this->table = new ilMStListCoursesTableGUI($this, self::CMD_INDEX);
$DIC->ui()->mainTemplate()->setTitle($DIC->language()->txt('mst_list_courses'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function __construct()
global $DIC;
$this->main_tpl = $DIC->ui()->mainTemplate();
$this->access = ilMyStaffAccess::getInstance();
$this->help = $DIC->help();
$this->help->setScreenIdComponent('msta');
}

protected function checkAccessOrFail()
Expand Down Expand Up @@ -69,6 +71,7 @@ final public function listUsers(): void
{
global $DIC;

$this->help->setScreenId('users_list');
$this->table = new ilMStListUsersTableGUI($this, self::CMD_INDEX);
$DIC->ui()->mainTemplate()->setTitle($DIC->language()->txt('mst_list_users'));
$DIC->ui()->mainTemplate()->setContent($this->table->getHTML());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,25 @@
*/
class ilMStShowUserCourses extends ilMStListCourses
{
/**
* @param array $arr_filter
* @return string
*/
protected function createWhereStatement(array $arr_filter): string
{
global $DIC;

if (!$arr_filter['usr_id']) {
return '';
}

$where = parent::createWhereStatement($arr_filter);
$usr_filter = "a_table.usr_id = " . $DIC->database()->quote($arr_filter['usr_id'], 'integer');

if (empty($where)) {
return ' WHERE ' . $usr_filter;
} else {
return $where . ' AND ' . $usr_filter;
}
}
}
Loading

0 comments on commit 9dab9a8

Please sign in to comment.