diff --git a/Modules/OrgUnit/classes/Positions/Operation/class.ilOrgUnitOperation.php b/Modules/OrgUnit/classes/Positions/Operation/class.ilOrgUnitOperation.php index 693b7632641f..68a3716aa4a7 100644 --- a/Modules/OrgUnit/classes/Positions/Operation/class.ilOrgUnitOperation.php +++ b/Modules/OrgUnit/classes/Positions/Operation/class.ilOrgUnitOperation.php @@ -16,6 +16,8 @@ class ilOrgUnitOperation extends ActiveRecord const OP_ACCESS_ENROLMENTS = 'access_enrolments'; const OP_MANAGE_PARTICIPANTS = 'manage_participants'; const OP_SCORE_PARTICIPANTS = 'score_participants'; + const OP_VIEW_CERTIFICATES = 'view_certificates'; + const OP_VIEW_COMPETENCES = 'view_competences'; const OP_EDIT_USER_ACCOUNTS = 'edit_user_accounts'; const OP_VIEW_MEMBERS = 'view_members'; const OP_VIEW_INDIVIDUAL_PLAN = 'view_individual_plan'; diff --git a/Modules/OrgUnit/classes/Positions/Operation/class.ilOrgUnitOperationContext.php b/Modules/OrgUnit/classes/Positions/Operation/class.ilOrgUnitOperationContext.php index 3bb40e0ca340..f41088b502d9 100644 --- a/Modules/OrgUnit/classes/Positions/Operation/class.ilOrgUnitOperationContext.php +++ b/Modules/OrgUnit/classes/Positions/Operation/class.ilOrgUnitOperationContext.php @@ -18,6 +18,25 @@ class ilOrgUnitOperationContext extends ActiveRecord const CONTEXT_USRF = "usrf"; const CONTEXT_PRG = "prg"; + /** + * @var array + */ + public static $available_contexts = [ + self::CONTEXT_OBJECT, + self::CONTEXT_CRS, + self::CONTEXT_GRP, + self::CONTEXT_IASS, + self::CONTEXT_TST, + self::CONTEXT_EXC, + self::CONTEXT_SVY, + self::CONTEXT_USRF, + self::CONTEXT_PRG, + ]; + + + + + /** * @return array if own and */ diff --git a/Modules/OrgUnit/classes/class.ilObjOrgUnitGUI.php b/Modules/OrgUnit/classes/class.ilObjOrgUnitGUI.php index 47e863ba8b17..7c2d72e1d9b9 100644 --- a/Modules/OrgUnit/classes/class.ilObjOrgUnitGUI.php +++ b/Modules/OrgUnit/classes/class.ilObjOrgUnitGUI.php @@ -390,7 +390,8 @@ public function showPossibleSubObjects() { $gui = new ilObjectAddNewItemGUI($this->object->getRefId()); $gui->setMode(ilObjectDefinition::MODE_ADMINISTRATION); - $gui->setCreationUrl("ilias.php?ref_id=" . $_GET["ref_id"] . "&admin_mode=settings&cmd=create&baseClass=ilAdministrationGUI"); + //$gui->setCreationUrl("ilias.php?ref_id=" . $_GET["ref_id"] . "&admin_mode=settings&cmd=create&baseClass=ilAdministrationGUI&cmdClass=ilobjorgunitgui"); + $gui->setCreationUrl($this->ctrl->getLinkTarget($this, 'create')); $gui->render(); } diff --git a/Services/MyStaff/classes/ListCertificates/class.ilMStListCertificates.php b/Services/MyStaff/classes/ListCertificates/class.ilMStListCertificates.php new file mode 100644 index 000000000000..187554fa2dad --- /dev/null +++ b/Services/MyStaff/classes/ListCertificates/class.ilMStListCertificates.php @@ -0,0 +1,90 @@ + + */ +class ilMStListCertificates +{ + + /** + * @var Container + */ + protected $dic; + + + /** + * ilMStListCertificates constructor. + * + * @param Container $dic + */ + public function __construct(Container $dic) + { + $this->dic = $dic; + } + + + /** + * @param array $arr_usr_ids + * @param array $options + * + * @return UserCertificateDto[] + */ + public function getData(array $options = array()) : array + { + //Permission Filter + $operation_access = ilOrgUnitOperation::OP_VIEW_CERTIFICATES; + + + $_options = array( + 'filters' => array(), + 'sort' => array(), + 'limit' => array(), + ); + $options = array_merge($_options, $options); + + $cert_api = new UserCertificateAPI(); + + $data = []; + $users_per_position = ilMyStaffAccess::getInstance()->getUsersForUserPerPosition($this->dic->user()->getId()); + foreach ($users_per_position as $position_id => $users) { + $usr_data_filter = new UserDataFilter(); + $usr_data_filter = $usr_data_filter->withUserIds($users); + $usr_data_filter = $usr_data_filter->withObjIds(ilMyStaffAccess::getInstance()->getIdsForUserAndOperation($this->dic->user()->getId(), $operation_access)); + + + if (!empty($options['filters']['user'])) { + $usr_data_filter = $usr_data_filter->withUserLogin($options['filters']['user']); + } + if (!empty($options['filters']['obj_title'])) { + $usr_data_filter = $usr_data_filter->withObjectTitle($options['filters']['obj_title']); + } + + + $data = array_merge($data, $cert_api->getUserCertificateData($usr_data_filter, [ilMyStaffGUI::class, ilMStListCertificatesGUI::class])); + } + + $unique_cert_data = []; + foreach ($data as $cert_data) { + /** + * @var UserCertificateDto $cert_data + */ + $unique_cert_data[$cert_data->getCertificateId()] = $cert_data; + } + + return $unique_cert_data; + } +} diff --git a/Services/MyStaff/classes/ListCertificates/class.ilMStListCertificatesGUI.php b/Services/MyStaff/classes/ListCertificates/class.ilMStListCertificatesGUI.php new file mode 100644 index 000000000000..ff2c3b49a27d --- /dev/null +++ b/Services/MyStaff/classes/ListCertificates/class.ilMStListCertificatesGUI.php @@ -0,0 +1,192 @@ + + * + * @ilCtrl_IsCalledBy ilMStListCertificatesGUI: ilMyStaffGUI + * @ilCtrl_Calls ilMStListCertificatesGUI: ilFormPropertyDispatchGUI + * @ilCtrl_Calls ilMStListCertificatesGUI: ilUserCertificateApiGUI + */ +class ilMStListCertificatesGUI { + + const CMD_APPLY_FILTER = 'applyFilter'; + const CMD_INDEX = 'index'; + const CMD_GET_ACTIONS = "getActions"; + const CMD_RESET_FILTER = 'resetFilter'; + /** + * @var ilTable2GUI + */ + protected $table; + /** + * @var ilMyStaffAccess + */ + protected $access; + + + /** + * + */ + public function __construct() { + $this->access = ilMyStaffAccess::getInstance(); + } + + + /** + * + */ + protected function checkAccessOrFail() { + global $DIC; + + if ($this->access->hasCurrentUserAccessToMyStaff()) { + return; + } else { + ilUtil::sendFailure($DIC->language()->txt("permission_denied"), true); + $DIC->ctrl()->redirectByClass(ilDashboardGUI::class, ""); + } + } + + + /** + * + */ + public function executeCommand() { + global $DIC; + + $cmd = $DIC->ctrl()->getCmd(); + $next_class = $DIC->ctrl()->getNextClass(); + + switch ($next_class) { + case strtolower(ilFormPropertyDispatchGUI::class): + $this->checkAccessOrFail(); + + $DIC->ctrl()->setReturn($this, self::CMD_INDEX); + $this->table = new ilMStListCertificatesTableGUI($this, self::CMD_INDEX); + $this->table->executeCommand(); + break; + case strtolower(ilUserCertificateApiGUI::class): + $this->checkAccessOrFail(); + $DIC->ctrl()->forwardCommand(new ilUserCertificateApiGUI()); + break; + default: + switch ($cmd) { + + case self::CMD_RESET_FILTER: + case self::CMD_APPLY_FILTER: + case self::CMD_INDEX: + case self::CMD_GET_ACTIONS: + $this->$cmd(); + break; + default: + $this->index(); + break; + } + break; + } + } + + + /** + * + */ + public function index() { + $this->listUsers(); + } + + + /** + * + */ + public function listUsers() { + global $DIC; + + $this->checkAccessOrFail(); + + $this->table = new ilMStListCertificatesTableGUI($this, self::CMD_INDEX); + $this->table->setTitle($DIC->language()->txt('mst_list_certificates')); + $DIC->ui()->mainTemplate()->setContent($this->table->getHTML()); + } + + + /** + * + */ + public function applyFilter() { + $this->table = new ilMStListCertificatesTableGUI($this, self::CMD_APPLY_FILTER); + $this->table->writeFilterToSession(); + $this->table->resetOffset(); + $this->index(); + } + + + /** + * + */ + public function resetFilter() { + $this->table = new ilMStListCertificatesTableGUI($this, self::CMD_RESET_FILTER); + $this->table->resetOffset(); + $this->table->resetFilter(); + $this->index(); + } + + + /** + * @return string + */ + public function getId() { + $this->table = new ilMStListCertificatesTableGUI($this, self::CMD_INDEX); + + return $this->table->getId(); + } + + + /** + * + */ + public function cancel() { + global $DIC; + + $DIC->ctrl()->redirect($this); + } + + + /** + * + */ + public function getActions() { + global $DIC; + + $mst_co_usr_id = $DIC->http()->request()->getQueryParams()['mst_lco_usr_id']; + $mst_lco_crs_ref_id = $DIC->http()->request()->getQueryParams()['mst_lco_crs_ref_id']; + + if ($mst_co_usr_id > 0 && $mst_lco_crs_ref_id > 0) { + $selection = new ilAdvancedSelectionListGUI(); + + if ($DIC->access()->checkAccess("visible", "", $mst_lco_crs_ref_id)) { + $link = ilLink::_getStaticLink($mst_lco_crs_ref_id, ilMyStaffAccess::DEFAULT_CONTEXT); + $selection->addItem(ilObject2::_lookupTitle(ilObject2::_lookupObjectId($mst_lco_crs_ref_id)), '', $link); + }; + + $org_units = ilOrgUnitPathStorage::getTextRepresentationOfOrgUnits('ref_id'); + foreach (ilOrgUnitUserAssignment::innerjoin('object_reference', 'orgu_id', 'ref_id')->where(array( + 'user_id' => $mst_co_usr_id, + 'object_reference.deleted' => null + ), array( 'user_id' => '=', 'object_reference.deleted' => '!=' ))->get() as $org_unit_assignment) { + if ($DIC->access()->checkAccess("read", "", $org_unit_assignment->getOrguId())) { + $link = ilLink::_getStaticLink($org_unit_assignment->getOrguId(), 'orgu'); + $selection->addItem($org_units[$org_unit_assignment->getOrguId()], '', $link); + } + } + + $selection = ilMyStaffGUI::extendActionMenuWithUserActions($selection, $mst_co_usr_id, rawurlencode($DIC->ctrl() + ->getLinkTarget($this, self::CMD_INDEX))); + + echo $selection->getHTML(true); + } + exit; + } +} diff --git a/Services/MyStaff/classes/ListCertificates/class.ilMStListCertificatesTableGUI.php b/Services/MyStaff/classes/ListCertificates/class.ilMStListCertificatesTableGUI.php new file mode 100644 index 000000000000..40b70bec2be9 --- /dev/null +++ b/Services/MyStaff/classes/ListCertificates/class.ilMStListCertificatesTableGUI.php @@ -0,0 +1,336 @@ + + */ +class ilMStListCertificatesTableGUI extends ilTable2GUI +{ + + /** + * @var array + */ + protected $filter = array(); + /** + * @var ilMyStaffAccess + */ + protected $access; + + + /** + * @param ilMStListCertificatesGUI $parent_obj + * @param string $parent_cmd + */ + public function __construct(ilMStListCertificatesGUI $parent_obj, $parent_cmd = ilMStListCertificatesGUI::CMD_INDEX) + { + global $DIC; + + $this->access = ilMyStaffAccess::getInstance(); + + $this->setPrefix('myst_lcrt'); + $this->setFormName('myst_lcrt'); + $this->setId('myst_lcrt'); + + parent::__construct($parent_obj, $parent_cmd, ''); + + $this->setRowTemplate('tpl.list_courses_row.html', "Services/MyStaff"); + $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj)); + $this->setDefaultOrderDirection('desc'); + + $this->setShowRowsSelector(true); + + $this->setEnableTitle(true); + $this->setDisableFilterHiding(true); + $this->setEnableNumInfo(true); + + $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV)); + + $this->setFilterCols(5); + $this->initFilter(); + + $this->addColumns(); + + $this->parseData(); + } + + + /** + * + */ + protected function parseData() : void + { + global $DIC; + + $this->setExternalSorting(true); + $this->setDefaultOrderField('obj_title'); + + $this->determineLimit(); + $this->determineOffsetAndOrder(); + + $options = array( + 'filters' => $this->filter, + 'limit' => array(), + 'count' => true, + 'sort' => array( + 'field' => $this->getOrderField(), + 'direction' => $this->getOrderDirection(), + ), + ); + + $certificates_fetcher = new ilMStListCertificates($DIC); + $data = $certificates_fetcher->getData($options); + $options['limit'] = array( + 'start' => intval($this->getOffset()), + 'end' => intval($this->getLimit()), + ); + $this->setMaxCount(count($data)); + $this->setData($data); + } + + + public function initFilter() + { + global $DIC; + + $item = new ilTextInputGUI($DIC->language()->txt("title"), "obj_title"); + $this->addFilterItem($item); + $item->readFromSession(); + $this->filter['obj_title'] = $item->getValue(); + + //user + $item = new ilTextInputGUI($DIC->language()->txt("login") . "/" . $DIC->language()->txt("email") . "/" . $DIC->language() + ->txt("name"), "user"); + + $this->addFilterItem($item); + $item->readFromSession(); + $this->filter['user'] = $item->getValue(); + + if (ilUserSearchOptions::_isEnabled('org_units')) { + $paths = ilOrgUnitPathStorage::getTextRepresentationOfOrgUnits(); + $options[0] = $DIC->language()->txt('mst_opt_all'); + foreach ($paths as $org_ref_id => $path) { + $options[$org_ref_id] = $path; + } + $item = new ilSelectInputGUI($DIC->language()->txt('obj_orgu'), 'org_unit'); + $item->setOptions($options); + $this->addFilterItem($item); + $item->readFromSession(); + $this->filter['org_unit'] = $item->getValue(); + } + } + + + /** + * @return array + */ + public function getSelectableColumns() : array + { + global $DIC; + + $cols = array(); + + $arr_searchable_user_columns = ilUserSearchOptions::getSelectableColumnInfo(); + + $cols['objectTitle'] = array( + 'txt' => $DIC->language()->txt('title'), + 'default' => true, + 'width' => 'auto', + 'sort_field' => 'objectTitle', + ); + $cols['issuedOnTimestamp'] = array( + 'txt' => $DIC->language()->txt('mst_cert_issued_on'), + 'default' => true, + 'width' => 'auto', + 'sort_field' => 'issuedOnTimestamp', + ); + if ($arr_searchable_user_columns['login']) { + $cols['userLogin'] = array( + 'txt' => $DIC->language()->txt('login'), + 'default' => true, + 'width' => 'auto', + 'sort_field' => 'userLogin', + ); + } + if ($arr_searchable_user_columns['firstname']) { + $cols['userFirstName'] = array( + 'txt' => $DIC->language()->txt('firstname'), + 'default' => true, + 'width' => 'auto', + 'sort_field' => 'userFirstName', + ); + } + if ($arr_searchable_user_columns['lastname']) { + $cols['userLastName'] = array( + 'txt' => $DIC->language()->txt('lastname'), + 'default' => true, + 'width' => 'auto', + 'sort_field' => 'userLastName', + ); + } + + if ($arr_searchable_user_columns['email']) { + $cols['usr_email'] = array( + 'txt' => $DIC->language()->txt('email'), + 'default' => true, + 'width' => 'auto', + 'sort_field' => 'usr_email', + ); + } + if ($arr_searchable_user_columns['org_units']) { + $cols['usr_assinged_orgus'] = array( + 'txt' => $DIC->language()->txt('objs_orgu'), + 'default' => true, + 'width' => 'auto', + ); + } + + return $cols; + } + + + /** + * + */ + private function addColumns() + { + global $DIC; + + foreach ($this->getSelectableColumns() as $k => $v) { + if ($this->isColumnSelected($k)) { + if (isset($v['sort_field'])) { + $sort = $v['sort_field']; + } else { + $sort = null; + } + $this->addColumn($v['txt'], $sort, $v['width']); + } + } + + //Actions + if (!$this->getExportMode()) { + $this->addColumn($DIC->language()->txt('actions')); + } + } + + + /** + * @param UserCertificateDto $user_certificate_dto + */ + public function fillRow($user_certificate_dto) + { + global $DIC; + + $propGetter = Closure::bind(function ($prop) { return $this->$prop; }, $user_certificate_dto, $user_certificate_dto); + + foreach ($this->getSelectableColumns() as $k => $v) { + if ($this->isColumnSelected($k)) { + switch ($k) { + case 'usr_assinged_orgus': + $this->tpl->setCurrentBlock('td'); + $this->tpl->setVariable('VALUE', strval(ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($user_certificate_dto->getUserId()))); + $this->tpl->parseCurrentBlock(); + break; + case 'issuedOnTimestamp': + $date_time = new ilDateTime($propGetter($k), IL_CAL_UNIX); + $this->tpl->setCurrentBlock('td'); + $this->tpl->setVariable('VALUE', $date_time->get(IL_CAL_DATE)); + $this->tpl->parseCurrentBlock(); + break; + default: + if ($propGetter($k) !== null) { + $this->tpl->setCurrentBlock('td'); + $this->tpl->setVariable('VALUE', (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k))); + $this->tpl->parseCurrentBlock(); + } else { + $this->tpl->setCurrentBlock('td'); + $this->tpl->setVariable('VALUE', ' '); + $this->tpl->parseCurrentBlock(); + } + break; + } + } + } + + $actions = new ilAdvancedSelectionListGUI(); + $actions->setListTitle($DIC->language()->txt("actions")); + $actions->setAsynch(false); + $actions->setId($user_certificate_dto->getCertificateId()); + $actions->addItem($DIC->language()->txt("mst_download_certificate"), '', $user_certificate_dto->getDownloadLink()); + + $this->tpl->setVariable('ACTIONS', $actions->getHTML()); + $this->tpl->parseCurrentBlock(); + } + + + /** + * @param ilExcel $a_excel excel wrapper + * @param int $a_row + * @param UserCertificateDto $user_certificate_dto + */ + protected function fillRowExcel(ilExcel $a_excel, &$a_row, $user_certificate_dto) + { + $col = 0; + foreach ($this->getFieldValuesForExport($user_certificate_dto) as $k => $v) { + $a_excel->setCell($a_row, $col, $v); + $col++; + } + } + + + /** + * @param ilCSVWriter $a_csv + * @param UserCertificateDto $user_certificate_dto + */ + protected function fillRowCSV($a_csv, $user_certificate_dto) + { + foreach ($this->getFieldValuesForExport($user_certificate_dto) as $k => $v) { + $a_csv->addColumn($v); + } + $a_csv->addRow(); + } + + + /** + * @param UserCertificateDto $user_certificate_dto + * + * @return array + */ + protected function getFieldValuesForExport(UserCertificateDto $user_certificate_dto) + { + $propGetter = Closure::bind(function ($prop) { return $this->$prop; }, $user_certificate_dto, $user_certificate_dto); + + $field_values = array(); + foreach ($this->getSelectedColumns() as $k => $v) { + switch ($k) { + case 'usr_assinged_orgus': + $field_values[$k] = ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($user_certificate_dto->getUserId()); + break; + case 'issuedOnTimestamp': + $field_values[$k] = new ilDateTime($propGetter($k), IL_CAL_UNIX); + break; + default: + $field_values[$k] = strip_tags($propGetter($k)); + break; + } + } + + return $field_values; + } +} diff --git a/Services/MyStaff/classes/ListCompetences/Skills/class.ilMStListCompetencesSkill.php b/Services/MyStaff/classes/ListCompetences/Skills/class.ilMStListCompetencesSkill.php new file mode 100644 index 000000000000..f5de485c0e35 --- /dev/null +++ b/Services/MyStaff/classes/ListCompetences/Skills/class.ilMStListCompetencesSkill.php @@ -0,0 +1,166 @@ + + */ +class ilMStListCompetencesSkill +{ + + /** + * @var string + */ + protected $skill_title; + /** + * @var string + */ + protected $skill_level; + /** + * @var string + */ + protected $login; + /** + * @var string + */ + protected $last_name; + /** + * @var string + */ + protected $first_name; + /** + * @var integer + */ + protected $user_id; + + + /** + * ilMStListCompetencesSkill constructor. + * + * @param string $skill_title + * @param string $skill_level + * @param string $login + * @param string $last_name + * @param string $first_name + * @param int $user_id + */ + public function __construct(string $skill_title, string $skill_level, string $login, string $last_name, string $first_name, int $user_id) + { + $this->skill_title = $skill_title; + $this->skill_level = $skill_level; + $this->login = $login; + $this->last_name = $last_name; + $this->first_name = $first_name; + $this->user_id = $user_id; + } + + + /** + * @return string + */ + public function getSkillTitle() : string + { + return $this->skill_title; + } + + + /** + * @param string $skill_title + */ + public function setSkillTitle(string $skill_title) : void + { + $this->skill_title = $skill_title; + } + + + /** + * @return string + */ + public function getSkillLevel() : string + { + return $this->skill_level; + } + + + /** + * @param string $skill_level + */ + public function setSkillLevel(string $skill_level) : void + { + $this->skill_level = $skill_level; + } + + + /** + * @return string + */ + public function getLogin() : string + { + return $this->login; + } + + + /** + * @param string $login + */ + public function setLogin(string $login) : void + { + $this->login = $login; + } + + + /** + * @return string + */ + public function getLastName() : string + { + return $this->last_name; + } + + + /** + * @param string $last_name + */ + public function setLastName(string $last_name) : void + { + $this->last_name = $last_name; + } + + + /** + * @return string + */ + public function getFirstName() : string + { + return $this->first_name; + } + + + /** + * @param string $first_name + */ + public function setFirstName(string $first_name) : void + { + $this->first_name = $first_name; + } + + + /** + * @return int + */ + public function getUserId() : int + { + return $this->user_id; + } + + + /** + * @param int $user_id + */ + public function setUserId(int $user_id) : void + { + $this->user_id = $user_id; + } + + +} \ No newline at end of file diff --git a/Services/MyStaff/classes/ListCompetences/Skills/class.ilMStListCompetencesSkills.php b/Services/MyStaff/classes/ListCompetences/Skills/class.ilMStListCompetencesSkills.php new file mode 100644 index 000000000000..836b6493302d --- /dev/null +++ b/Services/MyStaff/classes/ListCompetences/Skills/class.ilMStListCompetencesSkills.php @@ -0,0 +1,129 @@ + + */ +class ilMStListCompetencesSkills +{ + + /** + * @var Container + */ + protected $dic; + + + /** + * ilMStListCompetencesSkills constructor. + * + * @param Container $dic + */ + public function __construct(Container $dic) + { + $this->dic = $dic; + } + + + /** + * @param int[] $options + * + * @return ilMStListCompetencesSkill[] + */ + public function getData(array $options) + { + //Permission Filter + $operation_access = ilOrgUnitOperation::OP_VIEW_COMPETENCES; + + $select = $options['count'] === true ? + 'SELECT count(*)' : 'SELECT sktree.title as skill_title, skill_node_id, ulvl.trigger_obj_id, user_id, login, firstname, lastname, lvl.title as skill_level'; + + $query = $select . + ' FROM skl_personal_skill sk ' . + ' INNER JOIN usr_data ud ON ud.usr_id = sk.user_id ' . + ' INNER JOIN skl_tree_node sktree ON sktree.obj_id = sk.skill_node_id ' . + ' INNER JOIN (SELECT trigger_obj_id, skill_id, MAX(level_id) AS level_id ' . + ' FROM skl_user_has_level WHERE self_eval = 0 GROUP BY skill_id) ulvl ON sk.skill_node_id = ulvl.skill_id ' . + ' INNER JOIN skl_level lvl ON lvl.id = ulvl.level_id ' . + ' WHERE '; + + $data = []; + $users_per_position = ilMyStaffAccess::getInstance()->getUsersForUserPerPosition($this->dic->user()->getId()); + + $arr_query = []; + foreach ($users_per_position as $position_id => $users) { + + $obj_ids = ilMyStaffAccess::getInstance()->getIdsForUserAndOperation($this->dic->user()->getId(), $operation_access); + $arr_query[] = $query . $this->dic->database()->in('ulvl.trigger_obj_id', $obj_ids, false, 'integer') . " AND " . $this->dic->database()->in('sk.user_id ', $users, false, 'integer') + . $this->getAdditionalWhereStatement($options['filters']); + } + + $union_query = "SELECT * FROM ((" . implode(') UNION (', $arr_query) . ")) as a_table"; + + if ($options['count'] === true) { + $set = $this->dic->database()->query($union_query); + + return $this->dic->database()->numRows($set); + } + + if ($options['sort']) { + $union_query .= " ORDER BY " . $options['sort']['field'] . " " . $options['sort']['direction']; + } + + if (isset($options['limit']['start']) && isset($options['limit']['end'])) { + $union_query .= " LIMIT " . $options['limit']['start'] . "," . $options['limit']['end']; + } + + $set = $this->dic->database()->query($union_query); + + $skills = []; + while ($rec = $this->dic->database()->fetchAssoc($set)) { + $skills[] = new ilMStListCompetencesSkill( + $rec['skill_title'], + $rec['skill_level'], + $rec['login'], + $rec['lastname'], + $rec['firstname'], + $rec['user_id'] + ); + } + + return $skills; + } + + + /** + * @param array $filters + * + * @return string + */ + protected function getAdditionalWhereStatement(array $filters) : string + { + $wheres = []; + + if (!empty($filters['skill'])) { + $wheres[] = "sktree.title LIKE '%" . $filters['skill'] . "%'"; + } + + if (!empty($filters['skill_level'])) { + $wheres[] = "lvl.title LIKE '%" . $filters['skill_level'] . "%'"; + } + + if (!empty($filters['user'])) { + $wheres[] = "(" . $this->dic->database()->like("ud.login", "text", "%" . $filters['user'] . "%") . " " . "OR " . $this->dic->database() + ->like("ud.firstname", "text", "%" . $filters['user'] . "%") . " " . "OR " . $this->dic->database() + ->like("ud.lastname", "text", "%" . $filters['user'] . "%") . " " . "OR " . $this->dic->database() + ->like("ud.email", "text", "%" . $filters['user'] . "%") . ") "; + } + + if (!empty($arr_filter['org_unit'])) { + $wheres[] = 'ud.usr_id IN (SELECT user_id FROM il_orgu_ua WHERE orgu_id = ' . + $this->dic->database()->quote($filters['org_unit'], 'integer') . ')'; + } + + return empty($wheres) ? '' : ' AND ' . implode(' AND ', $wheres); + } +} \ No newline at end of file diff --git a/Services/MyStaff/classes/ListCompetences/Skills/class.ilMStListCompetencesSkillsGUI.php b/Services/MyStaff/classes/ListCompetences/Skills/class.ilMStListCompetencesSkillsGUI.php new file mode 100644 index 000000000000..af2c4d75c567 --- /dev/null +++ b/Services/MyStaff/classes/ListCompetences/Skills/class.ilMStListCompetencesSkillsGUI.php @@ -0,0 +1,146 @@ + + */ +class ilMStListCompetencesSkillsGUI +{ + + const CMD_APPLY_FILTER = 'applyFilter'; + const CMD_INDEX = 'index'; + const CMD_GET_ACTIONS = "getActions"; + const CMD_RESET_FILTER = 'resetFilter'; + /** + * @var ilTable2GUI + */ + protected $table; + /** + * @var ilMyStaffAccess + */ + protected $access; + /** + * @var Container + */ + private $dic; + + + /** + * @param Container $dic + */ + public function __construct(Container $dic) + { + $this->access = ilMyStaffAccess::getInstance(); + $this->dic = $dic; + } + + + protected function checkAccessOrFail() : void + { + if ($this->access->hasCurrentUserAccessToMyStaff()) { + return; + } else { + ilUtil::sendFailure($this->dic->language()->txt("permission_denied"), true); + $this->dic->ctrl()->redirectByClass(ilDashboardGUI::class, ""); + } + } + + + public function executeCommand() : void + { + + $cmd = $this->dic->ctrl()->getCmd(); + $next_class = $this->dic->ctrl()->getNextClass(); + switch ($next_class) { + default: + switch ($cmd) { + case self::CMD_RESET_FILTER: + case self::CMD_APPLY_FILTER: + case self::CMD_INDEX: + case self::CMD_GET_ACTIONS: + $this->$cmd(); + break; + default: + $this->index(); + break; + } + break; + } + } + + + public function index() : void + { + $this->listUsers(); + } + + + public function listUsers() : void + { + $this->checkAccessOrFail(); + + $this->table = new ilMStListCompetencesSkillsTableGUI($this, self::CMD_INDEX, $this->dic); + $this->table->setTitle($this->dic->language()->txt('mst_list_competences')); + $this->dic->ui()->mainTemplate()->setContent($this->table->getHTML()); + } + + + public function applyFilter() : void + { + $this->table = new ilMStListCompetencesSkillsTableGUI($this, self::CMD_APPLY_FILTER, $this->dic); + $this->table->writeFilterToSession(); + $this->table->resetOffset(); + $this->index(); + } + + + public function resetFilter() : void + { + $this->table = new ilMStListCompetencesSkillsTableGUI($this, self::CMD_RESET_FILTER, $this->dic); + $this->table->resetOffset(); + $this->table->resetFilter(); + $this->index(); + } + + + /** + * @return string + */ + public function getId() : string + { + $this->table = new ilMStListCompetencesSkillsTableGUI($this, self::CMD_INDEX, $this->dic); + + return $this->table->getId(); + } + + + public function cancel() : void + { + $this->dic->ctrl()->redirect($this); + } + + + protected function getActions() : void + { + global $DIC; + + $mst_co_usr_id = $DIC->http()->request()->getQueryParams()['mst_lcom_usr_id']; + + if ($mst_co_usr_id > 0) { + $selection = new ilAdvancedSelectionListGUI(); + + $selection = ilMyStaffGUI::extendActionMenuWithUserActions($selection, $mst_co_usr_id, rawurlencode($DIC->ctrl() + ->getLinkTarget($this, self::CMD_INDEX))); + + echo $selection->getHTML(true); + } + exit; + } +} \ No newline at end of file diff --git a/Services/MyStaff/classes/ListCompetences/Skills/class.ilMStListCompetencesSkillsTableGUI.php b/Services/MyStaff/classes/ListCompetences/Skills/class.ilMStListCompetencesSkillsTableGUI.php new file mode 100644 index 000000000000..1cf0264a2bf6 --- /dev/null +++ b/Services/MyStaff/classes/ListCompetences/Skills/class.ilMStListCompetencesSkillsTableGUI.php @@ -0,0 +1,313 @@ + + */ +class ilMStListCompetencesSkillsTableGUI extends ilTable2GUI +{ + + /** + * @var array + */ + protected $filter = array(); + /** + * @var ilMyStaffAccess + */ + protected $access; + /** + * @var Container + */ + protected $dic; + + + /** + * @param $parent_obj + * @param string $parent_cmd + * @param Container $dic + */ + public function __construct($parent_obj, string $parent_cmd, Container $dic) + { + $this->dic = $dic; + $this->access = ilMyStaffAccess::getInstance(); + + $this->setPrefix('myst_cs'); + $this->setFormName('myst_cs'); + $this->setId('myst_cs'); + + parent::__construct($parent_obj, $parent_cmd, ''); + + $this->setRowTemplate('tpl.list_skills_row.html', "Services/MyStaff"); + $this->setFormAction($this->dic->ctrl()->getFormAction($parent_obj)); + $this->setDefaultOrderDirection('desc'); + + $this->setShowRowsSelector(true); + + $this->setEnableTitle(true); + $this->setDisableFilterHiding(true); + $this->setEnableNumInfo(true); + + $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV)); + + $this->setFilterCols(5); + $this->initFilter(); + + $this->addColumns(); + + $this->parseData(); + } + + + /** + * + */ + protected function parseData() + { + $this->setExternalSorting(true); + $this->setExternalSegmentation(true); + $this->setDefaultOrderField('skill_title'); + + $this->determineLimit(); + $this->determineOffsetAndOrder(); + + $options = array( + 'filters' => $this->filter, + 'limit' => array(), + 'count' => true, + 'sort' => array( + 'field' => $this->getOrderField(), + 'direction' => $this->getOrderDirection(), + ), + ); + + + $skills_fetcher = new ilMStListCompetencesSkills($this->dic); + $count = $skills_fetcher->getData($options); + $options['limit'] = array( + 'start' => intval($this->getOffset()), + 'end' => intval($this->getLimit()), + ); + $options['count'] = false; + $data = $skills_fetcher->getData($options); + $this->setMaxCount($count); + $this->setData($data); + } + + + /** + * + */ + public function initFilter() + { + // skill + $item = new ilTextInputGUI($this->dic->language()->txt("skmg_skill"), 'skill'); + $this->addFilterItem($item); + $item->readFromSession(); + $this->filter['skill'] = $item->getValue(); + + // skill level + $item = new ilTextInputGUI($this->dic->language()->txt("skmg_skill_level"), 'skill_level'); + $this->addFilterItem($item); + $item->readFromSession(); + $this->filter['skill_level'] = $item->getValue(); + + //user + $item = new ilTextInputGUI($this->dic->language()->txt("login") . "/" . $this->dic->language()->txt("email") . "/" . $this->dic->language() + ->txt("name"), "user"); + + $this->addFilterItem($item); + $item->readFromSession(); + $this->filter['user'] = $item->getValue(); + + // orgunits + if (ilUserSearchOptions::_isEnabled('org_units')) { + $paths = ilOrgUnitPathStorage::getTextRepresentationOfOrgUnits(); + $options[0] = $this->dic->language()->txt('mst_opt_all'); + foreach ($paths as $org_ref_id => $path) { + $options[$org_ref_id] = $path; + } + $item = new ilSelectInputGUI($this->dic->language()->txt('obj_orgu'), 'org_unit'); + $item->setOptions($options); + $this->addFilterItem($item); + $item->readFromSession(); + $this->filter['org_unit'] = $item->getValue(); + } + } + + + /** + * @return array + */ + public function getSelectableColumns() + { + $cols = array(); + + $arr_searchable_user_columns = ilUserSearchOptions::getSelectableColumnInfo(); + + $cols['skill_title'] = array( + 'txt' => $this->dic->language()->txt('skmg_skill'), + 'default' => true, + 'width' => 'auto', + 'sort_field' => 'skill_title', + ); + $cols['skill_level'] = array( + 'txt' => $this->dic->language()->txt('skmg_skill_level'), + 'default' => true, + 'width' => 'auto', + 'sort_field' => 'skill_level', + ); + + if ($arr_searchable_user_columns['login']) { + $cols['login'] = array( + 'txt' => $this->dic->language()->txt('login'), + 'default' => true, + 'width' => 'auto', + 'sort_field' => 'login', + ); + } + if ($arr_searchable_user_columns['firstname']) { + $cols['first_name'] = array( + 'txt' => $this->dic->language()->txt('firstname'), + 'default' => true, + 'width' => 'auto', + 'sort_field' => 'firstname', + ); + } + if ($arr_searchable_user_columns['lastname']) { + $cols['last_name'] = array( + 'txt' => $this->dic->language()->txt('lastname'), + 'default' => true, + 'width' => 'auto', + 'sort_field' => 'lastname', + ); + } + + return $cols; + } + + + /** + * + */ + private function addColumns() + { + foreach ($this->getSelectableColumns() as $k => $v) { + if ($this->isColumnSelected($k)) { + if (isset($v['sort_field'])) { + $sort = $v['sort_field']; + } else { + $sort = null; + } + $this->addColumn($v['txt'], $sort, $v['width']); + } + } + + //Actions + if (!$this->getExportMode()) { + $this->addColumn($this->dic->language()->txt('actions')); + } + } + + + /** + * @param ilMStListCompetencesSkill $profile + */ + public function fillRow($profile) + { + $propGetter = Closure::bind(function ($prop) { return $this->$prop; }, $profile, $profile); + + foreach ($this->getSelectableColumns() as $k => $v) { + if ($this->isColumnSelected($k)) { + if ($propGetter($k) !== null) { + $this->tpl->setCurrentBlock('td'); + $this->tpl->setVariable('VALUE', (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k))); + $this->tpl->parseCurrentBlock(); + } else { + $this->tpl->setCurrentBlock('td'); + $this->tpl->setVariable('VALUE', ' '); + $this->tpl->parseCurrentBlock(); + } + } + } + + $actions = new ilAdvancedSelectionListGUI(); + $actions->setListTitle($this->dic->language()->txt("actions")); + $actions->setAsynch(true); + + $this->dic->ctrl()->setParameterByClass(get_class($this->parent_obj), 'mst_lcom_usr_id', $profile->getUserId()); + + $actions->setAsynchUrl(str_replace("\\", "\\\\", $this->dic->ctrl() + ->getLinkTarget($this->parent_obj, ilMStListCompetencesSkillsGUI::CMD_GET_ACTIONS, "", true))); + $this->tpl->setVariable('ACTIONS', $actions->getHTML()); + $this->tpl->parseCurrentBlock(); + } + + + /** + * @param ilExcel $a_excel excel wrapper + * @param int $a_row + * @param ilMStListCompetencesSkill $selected_skill + */ + protected function fillRowExcel(ilExcel $a_excel, &$a_row, $selected_skill) + { + $col = 0; + foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) { + $a_excel->setCell($a_row, $col, $v); + $col++; + } + } + + + /** + * @param ilCSVWriter $a_csv + * @param ilMStListCompetencesSkill $selected_skill + */ + protected function fillRowCSV($a_csv, $selected_skill) + { + foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) { + $a_csv->addColumn($v); + } + $a_csv->addRow(); + } + + + /** + * @param ilMStListCompetencesSkill $selected_skill + * + * @return array + */ + protected function getFieldValuesForExport(ilMStListCompetencesSkill $selected_skill) + { + $propGetter = Closure::bind(function ($prop) { return $this->$prop; }, $selected_skill, $selected_skill); + + $field_values = array(); + foreach ($this->getSelectedColumns() as $k => $v) { + switch ($k) { + default: + $field_values[$k] = strip_tags($propGetter($k)); + break; + } + } + + return $field_values; + } +} diff --git a/Services/MyStaff/classes/ListCompetences/class.ilMStListCompetencesGUI.php b/Services/MyStaff/classes/ListCompetences/class.ilMStListCompetencesGUI.php new file mode 100644 index 000000000000..cb2b56706550 --- /dev/null +++ b/Services/MyStaff/classes/ListCompetences/class.ilMStListCompetencesGUI.php @@ -0,0 +1,158 @@ + + * + * @ilCtrl_IsCalledBy ilMStListCompetencesGUI: ilMyStaffGUI + * @ilCtrl_Calls ilMStListCompetencesGUI: ilMStListCompetencesSkillsGUI + * @ilCtrl_Calls ilMStListCompetencesGUI: ilMStListCompetencesProfilesGUI + */ +class ilMStListCompetencesGUI +{ + + const CMD_APPLY_FILTER = 'applyFilter'; + const CMD_INDEX = 'index'; + const CMD_GET_ACTIONS = "getActions"; + const CMD_RESET_FILTER = 'resetFilter'; + const SUB_TAB_SKILLS = 'skills'; + /** + * @var ilTable2GUI + */ + protected $table; + /** + * @var ilMyStaffAccess + */ + protected $access; + /** + * @var Container + */ + private $dic; + + + /** + * @param Container $dic + */ + public function __construct(Container $dic = null) + { + if (is_null($dic)) { + global $DIC; + $dic = $DIC; + } + $this->access = ilMyStaffAccess::getInstance(); + $this->dic = $dic; + } + + + /** + * + */ + protected function checkAccessOrFail() + { + if ($this->access->hasCurrentUserAccessToMyStaff()) { + return; + } else { + ilUtil::sendFailure($this->dic->language()->txt("permission_denied"), true); + $this->dic->ctrl()->redirectByClass(ilDashboardGUI::class, ""); + } + } + + + /** + * + */ + public function executeCommand() + { + + $cmd = $this->dic->ctrl()->getCmd(); + $next_class = $this->dic->ctrl()->getNextClass(); + switch ($next_class) { + case strtolower(ilMStListCompetencesSkillsGUI::class): + $this->addSubTabs(self::SUB_TAB_SKILLS); + $gui = new ilMStListCompetencesSkillsGUI($this->dic); + $this->dic->ctrl()->forwardCommand($gui); + break; + default: + switch ($cmd) { + case self::CMD_INDEX: + $this->$cmd(); + break; + default: + $this->index(); + break; + } + break; + } + } + + + /** + * @param string $subtab_active + */ + protected function addSubTabs(string $subtab_active) : void + { + $this->dic->language()->loadLanguageModule('skmg'); + $this->dic->tabs()->addSubTab( + self::SUB_TAB_SKILLS, + $this->dic->language()->txt('skmg_selected_skills'), + $this->dic->ctrl()->getLinkTargetByClass([ + self::class, + ilMStListCompetencesSkillsGUI::class + ]) + ); + + $this->dic->tabs()->activateSubTab($subtab_active); + } + + + /** + * + */ + public function index() + { + $this->dic->ctrl()->redirectByClass(ilMStListCompetencesSkillsGUI::class); + } + + + /** + * + */ + public function getActions() + { + + $mst_co_usr_id = $this->dic->http()->request()->getQueryParams()['mst_lco_usr_id']; + $mst_lco_crs_ref_id = $this->dic->http()->request()->getQueryParams()['mst_lco_crs_ref_id']; + + if ($mst_co_usr_id > 0 && $mst_lco_crs_ref_id > 0) { + $selection = new ilAdvancedSelectionListGUI(); + + if ($this->dic->access()->checkAccess("visible", "", $mst_lco_crs_ref_id)) { + $link = ilLink::_getStaticLink($mst_lco_crs_ref_id, ilMyStaffAccess::DEFAULT_CONTEXT); + $selection->addItem(ilObject2::_lookupTitle(ilObject2::_lookupObjectId($mst_lco_crs_ref_id)), '', $link); + }; + + $org_units = ilOrgUnitPathStorage::getTextRepresentationOfOrgUnits('ref_id'); + foreach ( + ilOrgUnitUserAssignment::innerjoin('object_reference', 'orgu_id', 'ref_id')->where(array( + 'user_id' => $mst_co_usr_id, + 'object_reference.deleted' => null + ), array('user_id' => '=', 'object_reference.deleted' => '!='))->get() as $org_unit_assignment + ) { + if ($this->dic->access()->checkAccess("read", "", $org_unit_assignment->getOrguId())) { + $link = ilLink::_getStaticLink($org_unit_assignment->getOrguId(), 'orgu'); + $selection->addItem($org_units[$org_unit_assignment->getOrguId()], '', $link); + } + } + + $selection = ilMyStaffGUI::extendActionMenuWithUserActions($selection, $mst_co_usr_id, rawurlencode($this->dic->ctrl() + ->getLinkTarget($this, self::CMD_INDEX))); + + echo $selection->getHTML(true); + } + exit; + } +} diff --git a/Services/MyStaff/classes/ListCourses/class.ilMStListCourse.php b/Services/MyStaff/classes/ListCourses/class.ilMStListCourse.php index 7a25b5da3867..16d265775e0b 100644 --- a/Services/MyStaff/classes/ListCourses/class.ilMStListCourse.php +++ b/Services/MyStaff/classes/ListCourses/class.ilMStListCourse.php @@ -1,4 +1,7 @@ $prop; + } /** * @return int diff --git a/Services/MyStaff/classes/ListCourses/class.ilMStListCourses.php b/Services/MyStaff/classes/ListCourses/class.ilMStListCourses.php index dd303f7c3cbd..4bbb88c895eb 100644 --- a/Services/MyStaff/classes/ListCourses/class.ilMStListCourses.php +++ b/Services/MyStaff/classes/ListCourses/class.ilMStListCourses.php @@ -1,4 +1,9 @@ dic = $dic; + } + /** * @param array $arr_usr_ids * @param array $options * * @return array|int */ - public static function getData(array $arr_usr_ids = array(), array $options = array()) { - global $DIC; - + public function getData(array $arr_usr_ids = array(), array $options = array()) { //Permission Filter $operation_access = ilOrgUnitOperation::OP_ACCESS_ENROLMENTS; if (!empty($options['filters']['lp_status']) || $options['filters']['lp_status'] === 0) { $operation_access = ilOrgUnitOperation::OP_READ_LEARNING_PROGRESS; } - $tmp_table_user_matrix = ilMyStaffAccess::getInstance()->buildTempTableIlobjectsUserMatrixForUserOperationAndContext($DIC->user() - ->getId(), $operation_access, ilMyStaffAccess::DEFAULT_CONTEXT, ilMyStaffAccess::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX); + /*$tmp_table_user_matrix = ilMyStaffAccess::getInstance()->buildTempTableIlobjectsUserMatrixForUserOperationAndContext($this->dic->user() + ->getId(), $operation_access, ilMyStaffAccess::DEFAULT_CONTEXT, ilMyStaffAccess::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX);*/ $_options = array( 'filters' => array(), @@ -33,43 +53,57 @@ public static function getData(array $arr_usr_ids = array(), array $options = ar ); $options = array_merge($_options, $options); - $select = 'SELECT crs_ref.ref_id AS crs_ref_id, crs.title AS crs_title, reg_status, lp_status, usr_data.usr_id AS usr_id, usr_data.login AS usr_login, usr_data.lastname AS usr_lastname, usr_data.firstname AS usr_firstname, usr_data.email AS usr_email FROM ( + $query = 'SELECT crs_ref.ref_id AS crs_ref_id, crs.title AS crs_title, reg_status, lp_status, usr_data.usr_id AS usr_id, usr_data.login AS usr_login, usr_data.lastname AS usr_lastname, usr_data.firstname AS usr_firstname, usr_data.email AS usr_email FROM ( SELECT reg.obj_id, reg.usr_id, ' . ilMStListCourse::MEMBERSHIP_STATUS_REGISTERED . ' AS reg_status, lp.status AS lp_status FROM obj_members AS reg LEFT JOIN ut_lp_marks AS lp on lp.obj_id = reg.obj_id AND lp.usr_id = reg.usr_id - WHERE ' . $DIC->database()->in('reg.usr_id', $arr_usr_ids, false, 'integer') . ' + WHERE ' . $this->dic->database()->in('reg.usr_id', $arr_usr_ids, false, 'integer') . ' UNION SELECT obj_id, usr_id, ' . ilMStListCourse::MEMBERSHIP_STATUS_WAITINGLIST . ' AS reg_status, 0 AS lp_status FROM crs_waiting_list AS waiting - WHERE ' . $DIC->database()->in('waiting.usr_id', $arr_usr_ids, false, 'integer') . ' + WHERE ' . $this->dic->database()->in('waiting.usr_id', $arr_usr_ids, false, 'integer') . ' UNION SELECT obj_id, usr_id, ' . ilMStListCourse::MEMBERSHIP_STATUS_REQUESTED . ' AS reg_status, 0 AS lp_status FROM il_subscribers AS requested - WHERE ' . $DIC->database()->in('requested.usr_id', $arr_usr_ids, false, 'integer') . ' + WHERE ' . $this->dic->database()->in('requested.usr_id', $arr_usr_ids, false, 'integer') . ' ) AS memb - INNER JOIN object_data AS crs on crs.obj_id = memb.obj_id AND crs.type = ' . $DIC->database() + INNER JOIN object_data AS crs on crs.obj_id = memb.obj_id AND crs.type = ' . $this->dic->database() ->quote(ilMyStaffAccess::DEFAULT_CONTEXT, 'text') . ' INNER JOIN object_reference AS crs_ref on crs_ref.obj_id = crs.obj_id INNER JOIN usr_data on usr_data.usr_id = memb.usr_id AND usr_data.active = 1'; - $select .= static::createWhereStatement($arr_usr_ids, $options['filters'], $tmp_table_user_matrix); + + $data = []; + $users_per_position = ilMyStaffAccess::getInstance()->getUsersForUserPerPosition($this->dic->user()->getId()); + + $arr_query = []; + foreach ($users_per_position as $position_id => $users) { + + $obj_ids = ilMyStaffAccess::getInstance()->getIdsForUserAndOperation($this->dic->user()->getId(), $operation_access); + $arr_query[] = $query ." AND ". $this->dic->database()->in('crs.obj_id', $obj_ids, false,'integer') ." AND ". $this->dic->database()->in('usr_data.usr_id', $users, false,'integer'); + + } + + $union_query = "SELECT * FROM ((".implode(') UNION (', $arr_query).")) as a_table"; + + $union_query .= static::createWhereStatement($options['filters']); if ($options['count']) { - $result = $DIC->database()->query($select); + $result = $this->dic->database()->query($union_query); - return $DIC->database()->numRows($result); + return $this->dic->database()->numRows($result); } if ($options['sort']) { - $select .= " ORDER BY " . $options['sort']['field'] . " " . $options['sort']['direction']; + $union_query .= " ORDER BY " . $options['sort']['field'] . " " . $options['sort']['direction']; } if (isset($options['limit']['start']) && isset($options['limit']['end'])) { - $select .= " LIMIT " . $options['limit']['start'] . "," . $options['limit']['end']; + $union_query .= " LIMIT " . $options['limit']['start'] . "," . $options['limit']['end']; } - $result = $DIC->database()->query($select); + $result = $this->dic->database()->query($union_query); $crs_data = array(); - while ($crs = $DIC->database()->fetchAssoc($result)) { + while ($crs = $this->dic->database()->fetchAssoc($result)) { $list_course = new ilMStListCourse(); $list_course->setCrsRefId($crs['crs_ref_id']); $list_course->setCrsTitle($crs['crs_title']); @@ -97,23 +131,16 @@ public static function getData(array $arr_usr_ids = array(), array $options = ar * * @return string */ - protected static function createWhereStatement(array $arr_usr_ids, array $arr_filter, $tmp_table_user_matrix) { - global $DIC; - + protected function createWhereStatement(array $arr_filter) { $where = array(); - $where[] = '(crs_ref.ref_id, usr_data.usr_id) IN (SELECT * FROM ' . $tmp_table_user_matrix . ')'; - - if (count($arr_usr_ids)) { - $where[] = $DIC->database()->in('usr_data.usr_id', $arr_usr_ids, false, 'integer'); - } if (!empty($arr_filter['crs_title'])) { - $where[] = '(crs.title LIKE ' . $DIC->database()->quote('%' . $arr_filter['crs_title'] . '%', 'text') . ')'; + $where[] = '(crs_title LIKE ' . $this->dic->database()->quote('%' . $arr_filter['crs_title'] . '%', 'text') . ')'; } if ($arr_filter['course'] > 0) { - $where[] = '(crs_ref.ref_id = ' . $DIC->database()->quote($arr_filter['course'], 'integer') . ')'; + $where[] = '(crs_ref_id = ' . $this->dic->database()->quote($arr_filter['course'], 'integer') . ')'; } if (!empty($arr_filter['lp_status']) || $arr_filter['lp_status'] === 0) { @@ -121,27 +148,27 @@ protected static function createWhereStatement(array $arr_usr_ids, array $arr_fi switch ($arr_filter['lp_status']) { case ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM: //if a user has the lp status not attempted it could be, that the user hase no records in table ut_lp_marks - $where[] = '(lp_status = ' . $DIC->database()->quote($arr_filter['lp_status'], 'integer') . ' OR lp_status is NULL)'; + $where[] = '(lp_status = ' . $this->dic->database()->quote($arr_filter['lp_status'], 'integer') . ' OR lp_status is NULL)'; break; default: - $where[] = '(lp_status = ' . $DIC->database()->quote($arr_filter['lp_status'], 'integer') . ')'; + $where[] = '(lp_status = ' . $this->dic->database()->quote($arr_filter['lp_status'], 'integer') . ')'; break; } } if (!empty($arr_filter['memb_status'])) { - $where[] = '(reg_status = ' . $DIC->database()->quote($arr_filter['memb_status'], 'integer') . ')'; + $where[] = '(reg_status = ' . $this->dic->database()->quote($arr_filter['memb_status'], 'integer') . ')'; } if (!empty($arr_filter['user'])) { - $where[] = "(" . $DIC->database()->like("usr_data.login", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $DIC->database() - ->like("usr_data.firstname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $DIC->database() - ->like("usr_data.lastname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $DIC->database() - ->like("usr_data.email", "text", "%" . $arr_filter['user'] . "%") . ") "; + $where[] = "(" . $this->dic->database()->like("usr_login", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database() + ->like("usr_firstname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database() + ->like("usr_lastname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database() + ->like("usr_email", "text", "%" . $arr_filter['user'] . "%") . ") "; } if (!empty($arr_filter['org_unit'])) { - $where[] = 'usr_data.usr_id IN (SELECT user_id FROM il_orgu_ua WHERE orgu_id = ' . $DIC->database() + $where[] = 'usr_id IN (SELECT user_id FROM il_orgu_ua WHERE orgu_id = ' . $this->dic->database() ->quote($arr_filter['org_unit'], 'integer') . ')'; } diff --git a/Services/MyStaff/classes/ListCourses/class.ilMStListCoursesGUI.php b/Services/MyStaff/classes/ListCourses/class.ilMStListCoursesGUI.php index 16b7064bcea4..36dc01a34d8b 100644 --- a/Services/MyStaff/classes/ListCourses/class.ilMStListCoursesGUI.php +++ b/Services/MyStaff/classes/ListCourses/class.ilMStListCoursesGUI.php @@ -1,5 +1,8 @@ access->getUsersForUser($DIC->user()->getId()); - $count = ilMStListCourses::getData($all_users_for_user, $options); + $list_courses_fetcher = new ilMStListCourses($DIC); + $count = $list_courses_fetcher->getData($all_users_for_user, $options); $options['limit'] = array( 'start' => intval($this->getOffset()), 'end' => intval($this->getLimit()), ); $options['count'] = false; - $data = ilMStListCourses::getData($all_users_for_user, $options); + $data = $list_courses_fetcher->getData($all_users_for_user, $options); $this->setMaxCount($count); $this->setData($data); } @@ -268,29 +285,29 @@ private function addColumns() { /** - * @param ilMStListCourse $my_staff_course + * @param ilMStListCourse $profile */ - public function fillRow($my_staff_course) { + public function fillRow($profile) { global $DIC; - $propGetter = Closure::bind(function ($prop) { return $this->$prop; }, $my_staff_course, $my_staff_course); + $propGetter = Closure::bind(function ($prop) { return $this->$prop; }, $profile, $profile); foreach ($this->getSelectableColumns() as $k => $v) { if ($this->isColumnSelected($k)) { switch ($k) { case 'usr_assinged_orgus': $this->tpl->setCurrentBlock('td'); - $this->tpl->setVariable('VALUE', strval(ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($my_staff_course->getUsrId()))); + $this->tpl->setVariable('VALUE', strval(ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($profile->getUsrId()))); $this->tpl->parseCurrentBlock(); break; case 'usr_reg_status': $this->tpl->setCurrentBlock('td'); - $this->tpl->setVariable('VALUE', ilMStListCourse::getMembershipStatusText($my_staff_course->getUsrRegStatus())); + $this->tpl->setVariable('VALUE', ilMStListCourse::getMembershipStatusText($profile->getUsrRegStatus())); $this->tpl->parseCurrentBlock(); break; case 'usr_lp_status': $this->tpl->setCurrentBlock('td'); - $this->tpl->setVariable('VALUE', ilMyStaffGUI::getUserLpStatusAsHtml($my_staff_course)); + $this->tpl->setVariable('VALUE', ilMyStaffGUI::getUserLpStatusAsHtml($profile)); $this->tpl->parseCurrentBlock(); break; default: @@ -311,10 +328,10 @@ public function fillRow($my_staff_course) { $actions = new ilAdvancedSelectionListGUI(); $actions->setListTitle($DIC->language()->txt("actions")); $actions->setAsynch(true); - $actions->setId($my_staff_course->getUsrId() . "-" . $my_staff_course->getCrsRefId()); + $actions->setId($profile->getUsrId() . "-" . $profile->getCrsRefId()); - $DIC->ctrl()->setParameterByClass(ilMStListCoursesGUI::class, 'mst_lco_usr_id', $my_staff_course->getUsrId()); - $DIC->ctrl()->setParameterByClass(ilMStListCoursesGUI::class, 'mst_lco_crs_ref_id', $my_staff_course->getCrsRefId()); + $DIC->ctrl()->setParameterByClass(ilMStListCoursesGUI::class, 'mst_lco_usr_id', $profile->getUsrId()); + $DIC->ctrl()->setParameterByClass(ilMStListCoursesGUI::class, 'mst_lco_crs_ref_id', $profile->getCrsRefId()); $actions->setAsynchUrl(str_replace("\\", "\\\\", $DIC->ctrl() ->getLinkTarget($this->parent_obj, ilMStListCoursesGUI::CMD_GET_ACTIONS, "", true))); @@ -326,11 +343,11 @@ public function fillRow($my_staff_course) { /** * @param ilExcel $a_excel excel wrapper * @param int $a_row - * @param ilMStListCourse $my_staff_course + * @param ilMStListCourse $selected_skill */ - protected function fillRowExcel(ilExcel $a_excel, &$a_row, $my_staff_course) { + protected function fillRowExcel(ilExcel $a_excel, &$a_row, $selected_skill) { $col = 0; - foreach ($this->getFieldValuesForExport($my_staff_course) as $k => $v) { + foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) { $a_excel->setCell($a_row, $col, $v); $col ++; } @@ -339,10 +356,10 @@ protected function fillRowExcel(ilExcel $a_excel, &$a_row, $my_staff_course) { /** * @param ilCSVWriter $a_csv - * @param ilMStListCourse $my_staff_course + * @param ilMStListCourse $selected_skill */ - protected function fillRowCSV($a_csv, $my_staff_course) { - foreach ($this->getFieldValuesForExport($my_staff_course) as $k => $v) { + protected function fillRowCSV($a_csv, $selected_skill) { + foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) { $a_csv->addColumn($v); } $a_csv->addRow(); diff --git a/Services/MyStaff/classes/ListUsers/class.ilMStListUser.php b/Services/MyStaff/classes/ListUsers/class.ilMStListUser.php index a4523f625568..8f73d335184d 100644 --- a/Services/MyStaff/classes/ListUsers/class.ilMStListUser.php +++ b/Services/MyStaff/classes/ListUsers/class.ilMStListUser.php @@ -1,4 +1,6 @@ dic = $dic; + } + /** * @param array $arr_usr_ids * @param array $options * * @return array|int */ - public static function getData(array $arr_usr_ids = array(), array $options = array()) { - global $DIC; - + public function getData(array $arr_usr_ids = array(), array $options = array()) { //Permissions if (count($arr_usr_ids) == 0) { if ($options['count']) { @@ -54,14 +70,14 @@ public static function getData(array $arr_usr_ids = array(), array $options = ar phone_office, phone_mobile, active - FROM ' . $DIC->database()->quoteIdentifier('usr_data') . + FROM ' . $this->dic->database()->quoteIdentifier('usr_data') . self::createWhereStatement($arr_usr_ids, $options['filters']); if ($options['count']) { - $result = $DIC->database()->query($select); + $result = $this->dic->database()->query($select); - return $DIC->database()->numRows($result); + return $this->dic->database()->numRows($result); } if ($options['sort']) { @@ -72,10 +88,10 @@ public static function getData(array $arr_usr_ids = array(), array $options = ar $select .= " LIMIT " . $options['limit']['start'] . "," . $options['limit']['end']; } - $result = $DIC->database()->query($select); + $result = $this->dic->database()->query($select); $user_data = array(); - while ($user = $DIC->database()->fetchAssoc($result)) { + while ($user = $this->dic->database()->fetchAssoc($result)) { $list_user = new ilMStListUser(); $list_user->setUsrId($user['usr_id']); $list_user->setGender($user['gender']); @@ -113,40 +129,38 @@ public static function getData(array $arr_usr_ids = array(), array $options = ar * * @return string */ - private static function createWhereStatement(array $arr_usr_ids, array $arr_filter) { - global $DIC; - + private function createWhereStatement(array $arr_usr_ids, array $arr_filter) { $where = array(); - $where[] = $DIC->database()->in('usr_data.usr_id', $arr_usr_ids, false, 'integer'); + $where[] = $this->dic->database()->in('usr_data.usr_id', $arr_usr_ids, false, 'integer'); if (!empty($arr_filter['user'])) { - $where[] = "(" . $DIC->database()->like("usr_data.login", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $DIC->database() - ->like("usr_data.firstname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $DIC->database() - ->like("usr_data.lastname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $DIC->database() + $where[] = "(" . $this->dic->database()->like("usr_data.login", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database() + ->like("usr_data.firstname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database() + ->like("usr_data.lastname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database() ->like("usr_data.email", "text", "%" . $arr_filter['user'] . "%") . ") "; } if (!empty($arr_filter['org_unit'])) { - $where[] = 'usr_data.usr_id IN (SELECT user_id FROM il_orgu_ua WHERE orgu_id = ' . $DIC->database() + $where[] = 'usr_data.usr_id IN (SELECT user_id FROM il_orgu_ua WHERE orgu_id = ' . $this->dic->database() ->quote($arr_filter['org_unit'], 'integer') . ')'; } if (!empty($arr_filter['lastname'])) { - $where[] = '(lastname LIKE ' . $DIC->database()->quote('%' . str_replace('*', '%', $arr_filter['lastname']) . '%', 'text') . ')'; + $where[] = '(lastname LIKE ' . $this->dic->database()->quote('%' . str_replace('*', '%', $arr_filter['lastname']) . '%', 'text') . ')'; } if (!empty($arr_filter['firstname'])) { - $where[] = '(firstname LIKE ' . $DIC->database()->quote('%' . str_replace('*', '%', $arr_filter['firstname']) . '%', 'text') . ')'; + $where[] = '(firstname LIKE ' . $this->dic->database()->quote('%' . str_replace('*', '%', $arr_filter['firstname']) . '%', 'text') . ')'; } if (!empty($arr_filter['email'])) { - $where[] = '(email LIKE ' . $DIC->database()->quote('%' . str_replace('*', '%', $arr_filter['email']) . '%', 'text') . ')'; + $where[] = '(email LIKE ' . $this->dic->database()->quote('%' . str_replace('*', '%', $arr_filter['email']) . '%', 'text') . ')'; } if (!empty($arr_filter['title'])) { - $where[] = '(title LIKE ' . $DIC->database()->quote('%' . str_replace('*', '%', $arr_filter['title']) . '%', 'text') . ')'; + $where[] = '(title LIKE ' . $this->dic->database()->quote('%' . str_replace('*', '%', $arr_filter['title']) . '%', 'text') . ')'; } if ($arr_filter['activation']) { diff --git a/Services/MyStaff/classes/ListUsers/class.ilMStListUsersGUI.php b/Services/MyStaff/classes/ListUsers/class.ilMStListUsersGUI.php index 764b9a0e5cea..3091c6b9810a 100644 --- a/Services/MyStaff/classes/ListUsers/class.ilMStListUsersGUI.php +++ b/Services/MyStaff/classes/ListUsers/class.ilMStListUsersGUI.php @@ -1,5 +1,8 @@ 0) { $selection = new ilAdvancedSelectionListGUI(); - $DIC->ctrl()->setParameterByClass(ilMStShowUserGUI::class, 'usr_id', $mst_lus_usr_id); - $selection->addItem($DIC->language()->txt('mst_show_courses'), '', $DIC->ctrl()->getLinkTargetByClass(array( - ilDashboardGUI::class, - ilMyStaffGUI::class, - ilMStShowUserGUI::class, - ))); - - $selection = ilMyStaffGUI::extendActionMenuWithUserActions($selection, $mst_lus_usr_id, rawurlencode($DIC->ctrl() + if ($this->access->hasCurrentUserAccessToMyStaff()) { + $DIC->ctrl()->setParameterByClass(ilMStShowUserCoursesGUI::class, 'usr_id', $mst_lus_usr_id); + $selection->addItem($DIC->language()->txt('mst_show_courses'), '', $DIC->ctrl()->getLinkTargetByClass(array( + ilDashboardGUI::class, + ilMyStaffGUI::class, + ilMStShowUserGUI::class, + ilMStShowUserCoursesGUI::class, + ))); + } + + if ($this->access->hasCurrentUserAccessToCertificates()) { + $DIC->ctrl()->setParameterByClass(ilUserCertificateGUI::class, 'usr_id', $mst_lus_usr_id); + $selection->addItem($DIC->language()->txt('mst_list_certificates'), '', $DIC->ctrl()->getLinkTargetByClass(array( + ilDashboardGUI::class, + ilMyStaffGUI::class, + ilMStShowUserGUI::class, + ilUserCertificateGUI::class, + ))); + } + + if ($this->access->hasCurrentUserAccessToCompetences()) { + $DIC->ctrl()->setParameterByClass(ilMStShowUserCompetencesGUI::class, 'usr_id', $mst_lus_usr_id); + $selection->addItem($DIC->language()->txt('mst_list_competences'), '', $DIC->ctrl()->getLinkTargetByClass(array( + ilDashboardGUI::class, + ilMyStaffGUI::class, + ilMStShowUserGUI::class, + ilMStShowUserCompetencesGUI::class, + ))); + } + + + $selection = ilMyStaffGUI::extendActionMenuWithUserActions($selection, $mst_lus_usr_id, rawurlencode($DIC->ctrl() ->getLinkTarget($this, self::CMD_INDEX))); echo $selection->getHTML(true); diff --git a/Services/MyStaff/classes/ListUsers/class.ilMStListUsersTableGUI.php b/Services/MyStaff/classes/ListUsers/class.ilMStListUsersTableGUI.php index 1fd3fe141e9d..c86f8a2db3ec 100644 --- a/Services/MyStaff/classes/ListUsers/class.ilMStListUsersTableGUI.php +++ b/Services/MyStaff/classes/ListUsers/class.ilMStListUsersTableGUI.php @@ -1,4 +1,18 @@ $this->getOrderDirection(), ), ); - $count = ilMStListUsers::getData($arr_usr_id, $options); + + $list_users_fetcher = new ilMStListUsers($DIC); + $count = $list_users_fetcher->getData($arr_usr_id, $options); $options['limit'] = array( 'start' => intval($this->getOffset()), 'end' => intval($this->getLimit()), ); $options['count'] = false; - $data = ilMStListUsers::getData($arr_usr_id, $options); + $data = $list_users_fetcher->getData($arr_usr_id, $options); $this->setMaxCount($count); $this->setData($data); diff --git a/Services/MyStaff/classes/Provider/StaffMainBarProvider.php b/Services/MyStaff/classes/Provider/StaffMainBarProvider.php index 3ffbed055868..e81aa548cb0d 100644 --- a/Services/MyStaff/classes/Provider/StaffMainBarProvider.php +++ b/Services/MyStaff/classes/Provider/StaffMainBarProvider.php @@ -1,8 +1,19 @@ -getOrganisationIdentification(); $title = $this->dic->language()->txt("mm_staff_list"); - $icon = $this->dic->ui()->factory()->symbol()->icon()->custom(\ilUtil::getImagePath("simpleline/people.svg"), $title); + $icon = $this->dic->ui()->factory()->symbol()->icon()->custom(ilUtil::getImagePath("simpleline/people.svg"), $title); // My Staff $items[] = $this->mainmenu->link($this->if->identifier('mm_pd_mst')) ->withSymbol($icon) ->withTitle($title) ->withAction($this->dic->ctrl()->getLinkTargetByClass([ - \ilDashboardGUI::class, - \ilMyStaffGUI::class, - \ilMStListCoursesGUI::class, - ], \ilMStListCoursesGUI::CMD_INDEX)) + ilDashboardGUI::class, + ilMyStaffGUI::class, + ilMStListUsersGUI::class, + ], ilMStListUsersGUI::CMD_INDEX)) ->withParent($top) ->withPosition(10) ->withAvailableCallable( @@ -57,17 +68,17 @@ function () { )->withNonAvailableReason($dic->ui()->factory()->legacy("{$dic->language()->txt('component_not_active')}")); $title = $this->dic->language()->txt("mm_enrolments"); - $icon = $this->dic->ui()->factory()->symbol()->icon()->custom(\ilUtil::getImagePath("simpleline/notebook.svg"), $title); + $icon = $this->dic->ui()->factory()->symbol()->icon()->custom(ilUtil::getImagePath("simpleline/notebook.svg"), $title); - // My Enrollments + // My Enrolments $items[] = $this->mainmenu->link($this->if->identifier('mm_pd_enrol')) ->withSymbol($icon) ->withTitle($title) ->withAction($this->dic->ctrl()->getLinkTargetByClass([ - \ilDashboardGUI::class, - \ilMyStaffGUI::class, - \ilMStListCoursesGUI::class, - ], \ilMStListCoursesGUI::CMD_INDEX)) + ilDashboardGUI::class, + ilMyStaffGUI::class, + ilMStListCoursesGUI::class, + ], ilMStListCoursesGUI::CMD_INDEX)) ->withParent($top) ->withPosition(20) ->withAvailableCallable( @@ -81,6 +92,54 @@ function () { } )->withNonAvailableReason($dic->ui()->factory()->legacy("{$dic->language()->txt('component_not_active')}")); + // My Certificates + $icon = $this->dic->ui()->factory()->symbol()->icon()->custom(ilUtil::getImagePath("simpleline/badge.svg"), $title); + $items[] = $this->mainmenu->link($this->if->identifier("mm_pd_cert")) + ->withSymbol($icon) + ->withTitle($this->dic->language()->txt("mm_certificates")) + ->withAction($this->dic->ctrl()->getLinkTargetByClass([ + ilDashboardGUI::class, + ilMyStaffGUI::class, + ilMStListCertificatesGUI::class, + ], ilMStListCertificatesGUI::CMD_INDEX)) + ->withParent($top) + ->withPosition(30) + ->withAvailableCallable( + function () : bool { + return boolval($this->dic->settings()->get("enable_my_staff")); + } + ) + ->withVisibilityCallable( + function () : bool { + return boolval(ilMyStaffAccess::getInstance()->hasCurrentUserAccessToCertificates()); + } + )->withNonAvailableReason($this->dic->ui()->factory()->legacy("{$this->dic->language()->txt("component_not_active")}")); + + + // My Competences + $icon = $this->dic->ui()->factory()->symbol()->icon()->custom(ilUtil::getImagePath("simpleline/plus.svg"), $title); + $items[] = $this->mainmenu->link($this->if->identifier("mm_pd_comp")) + ->withSymbol($icon) + ->withTitle($this->dic->language()->txt("mm_skills")) + ->withAction($this->dic->ctrl()->getLinkTargetByClass([ + ilDashboardGUI::class, + ilMyStaffGUI::class, + ilMStListCompetencesGUI::class, + ], ilMStListCompetencesGUI::CMD_INDEX)) + ->withParent($top) + ->withPosition(30) + ->withAvailableCallable( + function () : bool { + return boolval($this->dic->settings()->get("enable_my_staff")); + } + ) + ->withVisibilityCallable( + function () : bool { + return boolval(ilMyStaffAccess::getInstance()->hasCurrentUserAccessToCompetences()); + } + )->withNonAvailableReason($this->dic->ui()->factory()->legacy("{$this->dic->language()->txt("component_not_active")}")); + + return $items; } } diff --git a/Services/MyStaff/classes/ShowUser/Competences/class.ilMStShowUserCompetencesGUI.php b/Services/MyStaff/classes/ShowUser/Competences/class.ilMStShowUserCompetencesGUI.php new file mode 100644 index 000000000000..e9290db7f603 --- /dev/null +++ b/Services/MyStaff/classes/ShowUser/Competences/class.ilMStShowUserCompetencesGUI.php @@ -0,0 +1,124 @@ + + * + * @ilCtrl_IsCalledBy ilMStShowUserCompetencesGUI: ilMStShowUserGUI + */ +class ilMStShowUserCompetencesGUI +{ + + const CMD_SHOW_SKILLS = 'showSkills'; + const CMD_INDEX = self::CMD_SHOW_SKILLS; + const SUB_TAB_SKILLS = 'skills'; + /** + * @var int + */ + protected $usr_id; + /** + * @var ilTable2GUI + */ + protected $table; + /** + * @var ilMyStaffAccess + */ + protected $access; + /** + * @var Container + */ + private $dic; + + + /** + * @param Container $dic + */ + public function __construct(Container $dic) + { + $this->dic = $dic; + $this->access = ilMyStaffAccess::getInstance(); + + $this->usr_id = $this->dic->http()->request()->getQueryParams()['usr_id']; + $this->dic->ctrl()->setParameter($this, 'usr_id', $this->usr_id); + } + + + /** + * + */ + protected function checkAccessOrFail() + { + if (!$this->usr_id) { + ilUtil::sendFailure($this->dic->language()->txt("permission_denied"), true); + $this->dic->ctrl()->redirectByClass(ilDashboardGUI::class, ""); + } + + if ($this->access->hasCurrentUserAccessToMyStaff() + && $this->access->hasCurrentUserAccessToUser($this->usr_id) + ) { + return; + } else { + ilUtil::sendFailure($this->dic->language()->txt("permission_denied"), true); + $this->dic->ctrl()->redirectByClass(ilDashboardGUI::class, ""); + } + } + + + /** + * + */ + public function executeCommand() + { + $this->checkAccessOrFail(); + + $cmd = $this->dic->ctrl()->getCmd(); + $next_class = $this->dic->ctrl()->getNextClass(); + + switch ($next_class) { + default: + switch ($cmd) { + case self::CMD_INDEX: + case self::CMD_SHOW_SKILLS: + default: + $this->addSubTabs(self::SUB_TAB_SKILLS); + $this->showSkills(); + break; + } + } + } + + + /** + * @param string $active_sub_tab + */ + protected function addSubTabs(string $active_sub_tab) + { + $this->dic->language()->loadLanguageModule('skmg'); + $this->dic->tabs()->addSubTab( + self::SUB_TAB_SKILLS, + $this->dic->language()->txt('skmg_selected_skills'), + $this->dic->ctrl()->getLinkTarget($this, self::CMD_SHOW_SKILLS) + ); + + $this->dic->tabs()->activateSubTab($active_sub_tab); + } + + + /** + * + */ + protected function showSkills() + { + $skills_gui = new ilPersonalSkillsGUI(); + $skills = ilPersonalSkill::getSelectedUserSkills($this->usr_id); + $html = ''; + foreach ($skills as $skill) { + $html .= $skills_gui->getSkillHTML($skill["skill_node_id"], $this->usr_id); + } + $this->dic->ui()->mainTemplate()->setContent($html); + } +} \ No newline at end of file diff --git a/Services/MyStaff/classes/ShowUser/class.ilMStShowUserCourses.php b/Services/MyStaff/classes/ShowUser/Courses/class.ilMStShowUserCourses.php similarity index 65% rename from Services/MyStaff/classes/ShowUser/class.ilMStShowUserCourses.php rename to Services/MyStaff/classes/ShowUser/Courses/class.ilMStShowUserCourses.php index 4838ad053cbe..75763b268f20 100644 --- a/Services/MyStaff/classes/ShowUser/class.ilMStShowUserCourses.php +++ b/Services/MyStaff/classes/ShowUser/Courses/class.ilMStShowUserCourses.php @@ -1,4 +1,6 @@ + * + * @ilCtrl_IsCalledBy ilMStShowUserCoursesGUI: ilMStShowUserGUI + * @ilCtrl_Calls ilMStShowUserCoursesGUI: ilFormPropertyDispatchGUI + */ +class ilMStShowUserCoursesGUI +{ + + const CMD_INDEX = 'index'; + const CMD_RESET_FILTER = 'resetFilter'; + const CMD_APPLY_FILTER = 'applyFilter'; + const CMD_GET_ACTIONS = "getActions"; + /** + * @var int + */ + protected $usr_id; + /** + * @var ilTable2GUI + */ + protected $table; + /** + * @var ilMyStaffAccess + */ + protected $access; + + + /** + * + */ + public function __construct() + { + global $DIC; + + $this->access = ilMyStaffAccess::getInstance(); + + $this->usr_id = $DIC->http()->request()->getQueryParams()['usr_id']; + $DIC->ctrl()->setParameter($this, 'usr_id', $this->usr_id); + } + + + /** + * + */ + protected function checkAccessOrFail() + { + global $DIC; + + if (!$this->usr_id) { + ilUtil::sendFailure($DIC->language()->txt("permission_denied"), true); + $DIC->ctrl()->redirectByClass(ilDashboardGUI::class, ""); + } + + if ($this->access->hasCurrentUserAccessToMyStaff() + && $this->access->hasCurrentUserAccessToUser($this->usr_id) + ) { + return; + } else { + ilUtil::sendFailure($DIC->language()->txt("permission_denied"), true); + $DIC->ctrl()->redirectByClass(ilDashboardGUI::class, ""); + } + } + + + /** + * + */ + public function executeCommand() + { + global $DIC; + + $this->checkAccessOrFail(); + + $cmd = $DIC->ctrl()->getCmd(); + $next_class = $DIC->ctrl()->getNextClass(); + + switch ($next_class) { + case strtolower(ilFormPropertyDispatchGUI::class): + $DIC->ctrl()->setReturn($this, self::CMD_INDEX); + $this->table = new ilMStShowUserCoursesTableGUI($this, self::CMD_INDEX); + $this->table->executeCommand(); + break; + default: + switch ($cmd) { + case self::CMD_RESET_FILTER: + case self::CMD_APPLY_FILTER: + case self::CMD_INDEX: + case self::CMD_GET_ACTIONS: + $this->$cmd(); + break; + default: + $this->index(); + break; + } + } + } + + + /** + * + */ + protected function index() + { + $this->listUsers(); + } + + + /** + * + */ + protected function listUsers() + { + global $DIC; + + $this->table = new ilMStShowUserCoursesTableGUI($this, self::CMD_INDEX); + $this->table->setTitle(sprintf($DIC->language()->txt('mst_courses_of'), ilObjCourse::_lookupTitle($this->usr_id))); + + $DIC->ui()->mainTemplate()->setContent($this->table->getHTML()); + } + + /** + * + */ + protected function applyFilter() + { + $this->table = new ilMStShowUserCoursesTableGUI($this, self::CMD_APPLY_FILTER); + $this->table->writeFilterToSession(); + $this->table->resetOffset(); + $this->index(); + } + + + /** + * + */ + protected function resetFilter() + { + $this->table = new ilMStShowUserCoursesTableGUI($this, self::CMD_RESET_FILTER); + $this->table->resetOffset(); + $this->table->resetFilter(); + $this->index(); + } + + + /** + * @return string + */ + public function getId() + { + $this->table = new ilMStShowUserCoursesTableGUI($this, self::CMD_INDEX); + + return $this->table->getId(); + } + + + /** + * + */ + public function cancel() + { + global $DIC; + + $DIC->ctrl()->redirect($this); + } + + + /** + * + */ + public function getActions() + { + global $DIC; + + $mst_co_usr_id = $DIC->http()->request()->getQueryParams()['mst_lco_usr_id']; + $mst_lco_crs_ref_id = $DIC->http()->request()->getQueryParams()['mst_lco_crs_ref_id']; + + if ($mst_co_usr_id > 0 && $mst_lco_crs_ref_id > 0) { + $selection = new ilAdvancedSelectionListGUI(); + + if ($DIC->access()->checkAccess("visible", "", $mst_lco_crs_ref_id)) { + $link = ilLink::_getStaticLink($mst_lco_crs_ref_id, ilMyStaffAccess::DEFAULT_CONTEXT); + $selection->addItem(ilObject2::_lookupTitle(ilObject2::_lookupObjectId($mst_lco_crs_ref_id)), '', $link); + }; + + $org_units = ilOrgUnitPathStorage::getTextRepresentationOfOrgUnits('ref_id'); + foreach ( + ilOrgUnitUserAssignment::innerjoin('object_reference', 'orgu_id', 'ref_id')->where(array( + 'user_id' => $mst_co_usr_id, + 'object_reference.deleted' => null + ), array('user_id' => '=', 'object_reference.deleted' => '!='))->get() as $org_unit_assignment + ) { + if ($DIC->access()->checkAccess("read", "", $org_unit_assignment->getOrguId())) { + $link = ilLink::_getStaticLink($org_unit_assignment->getOrguId(), 'orgu'); + $selection->addItem($org_units[$org_unit_assignment->getOrguId()], '', $link); + } + } + + $selection = ilMyStaffGUI::extendActionMenuWithUserActions($selection, $mst_co_usr_id, rawurlencode($DIC->ctrl() + ->getLinkTarget($this, self::CMD_INDEX))); + + echo $selection->getHTML(true); + } + exit; + } +} \ No newline at end of file diff --git a/Services/MyStaff/classes/ShowUser/Courses/class.ilMStShowUserCoursesTableGUI.php b/Services/MyStaff/classes/ShowUser/Courses/class.ilMStShowUserCoursesTableGUI.php new file mode 100644 index 000000000000..b6b2022d5e8d --- /dev/null +++ b/Services/MyStaff/classes/ShowUser/Courses/class.ilMStShowUserCoursesTableGUI.php @@ -0,0 +1,354 @@ + + */ +class ilMStShowUserCoursesTableGUI extends ilTable2GUI +{ + + /** + * @var int + */ + protected $usr_id; + /** + * @var array + */ + protected $filter = array(); + /** + * @var ilMyStaffAccess + */ + protected $access; + + + /** + * @param ilMStShowUserCoursesGUI $parent_obj + * @param string $parent_cmd + */ + public function __construct(ilMStShowUserCoursesGUI $parent_obj, $parent_cmd = ilMStShowUserCoursesGUI::CMD_INDEX) + { + global $DIC; + + $this->access = ilMyStaffAccess::getInstance(); + + $this->usr_id = $DIC->http()->request()->getQueryParams()['usr_id']; + + $this->setPrefix('myst_su'); + $this->setFormName('myst_su'); + $this->setId('myst_su'); + + parent::__construct($parent_obj, $parent_cmd, ''); + $this->setRowTemplate('tpl.list_user_courses_row.html', "Services/MyStaff"); + $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));; + $this->setDefaultOrderDirection('desc'); + + $this->setShowRowsSelector(true); + + $this->setEnableTitle(true); + $this->setDisableFilterHiding(true); + $this->setEnableNumInfo(true); + + $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV)); + + $this->setFilterCols(5); + $this->initFilter(); + $this->addColumns(); + + $this->parseData(); + } + + + /** + * + */ + protected function parseData() + { + global $DIC; + + $this->setExternalSorting(true); + $this->setExternalSegmentation(true); + $this->setDefaultOrderField('crs_title'); + + $this->determineLimit(); + $this->determineOffsetAndOrder(); + + $arr_usr_id = $this->access->getUsersForUserOperationAndContext($DIC->user() + ->getId(), ilOrgUnitOperation::OP_ACCESS_ENROLMENTS, ilMyStaffAccess::DEFAULT_CONTEXT); + + $this->filter['usr_id'] = $this->usr_id; + $options = array( + 'filters' => $this->filter, + 'limit' => array(), + 'count' => true, + 'sort' => array( + 'field' => $this->getOrderField(), + 'direction' => $this->getOrderDirection(), + ), + ); + + $user_courses_fetcher = new ilMStShowUserCourses($DIC); + $count = $user_courses_fetcher->getData($arr_usr_id, $options); + $options['limit'] = array( + 'start' => intval($this->getOffset()), + 'end' => intval($this->getLimit()), + ); + $options['count'] = false; + $data = $user_courses_fetcher->getData($arr_usr_id, $options); + + $this->setMaxCount($count); + $this->setData($data); + } + + + /** + * + */ + public function initFilter() + { + global $DIC; + + $item = new ilTextInputGUI($DIC->language()->txt("crs_title"), "crs_title"); + $this->addFilterItem($item); + $item->readFromSession(); + $this->filter['crs_title'] = $item->getValue(); + + // course members + $item = new ilRepositorySelectorInputGUI($DIC->language()->txt("usr_filter_coursemember"), "course"); + $item->setSelectText($DIC->language()->txt("mst_select_course")); + $item->setHeaderMessage($DIC->language()->txt("mst_please_select_course")); + $item->setClickableTypes(array(ilMyStaffAccess::DEFAULT_CONTEXT)); + $this->addFilterItem($item); + $item->readFromSession(); + $item->setParent($this->getParentObject()); + $this->filter["course"] = $item->getValue(); + + //membership status + $item = new ilSelectInputGUI($DIC->language()->txt('member_status'), 'memb_status'); + $item->setOptions(array( + "" => $DIC->language()->txt("mst_opt_all"), + ilMStListCourse::MEMBERSHIP_STATUS_REQUESTED => $DIC->language()->txt('mst_memb_status_requested'), + ilMStListCourse::MEMBERSHIP_STATUS_WAITINGLIST => $DIC->language()->txt('mst_memb_status_waitinglist'), + ilMStListCourse::MEMBERSHIP_STATUS_REGISTERED => $DIC->language()->txt('mst_memb_status_registered'), + )); + $this->addFilterItem($item); + $item->readFromSession(); + $this->filter["memb_status"] = $item->getValue(); + + if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) { + //learning progress status + $item = new ilSelectInputGUI($DIC->language()->txt('learning_progress'), 'lp_status'); + //+1 because LP_STATUS_NOT_ATTEMPTED_NUM is 0. + $item->setOptions(array( + "" => $DIC->language()->txt("mst_opt_all"), + ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM + 1 => $DIC->language()->txt(ilLPStatus::LP_STATUS_NOT_ATTEMPTED), + ilLPStatus::LP_STATUS_IN_PROGRESS_NUM + 1 => $DIC->language()->txt(ilLPStatus::LP_STATUS_IN_PROGRESS), + ilLPStatus::LP_STATUS_COMPLETED_NUM + 1 => $DIC->language()->txt(ilLPStatus::LP_STATUS_COMPLETED), + ilLPStatus::LP_STATUS_FAILED_NUM + 1 => $DIC->language()->txt(ilLPStatus::LP_STATUS_FAILED), + )); + $this->addFilterItem($item); + $item->readFromSession(); + $this->filter["lp_status"] = $item->getValue(); + if ($this->filter["lp_status"]) { + $this->filter["lp_status"] = $this->filter["lp_status"] - 1; + } + } + } + + + /** + * @return array + */ + public function getSelectableColumns() + { + global $DIC; + + $cols = array(); + + $cols['crs_title'] = array( + 'txt' => $DIC->language()->txt('crs_title'), + 'default' => true, + 'width' => 'auto', + 'sort_field' => 'crs_title', + ); + $cols['usr_reg_status'] = array( + 'txt' => $DIC->language()->txt('member_status'), + 'default' => true, + 'width' => 'auto', + 'sort_field' => 'reg_status', + ); + if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) { + $cols['usr_lp_status'] = array( + 'txt' => $DIC->language()->txt('learning_progress'), + 'default' => true, + 'width' => 'auto', + 'sort_field' => 'lp_status', + ); + } + + return $cols; + } + + + /** + * + */ + private function addColumns() + { + global $DIC; + + foreach ($this->getSelectableColumns() as $k => $v) { + if ($this->isColumnSelected($k)) { + if (isset($v['sort_field'])) { + $sort = $v['sort_field']; + } else { + $sort = null; + } + $this->addColumn($v['txt'], $sort, $v['width']); + } + } + //Actions + if (!$this->getExportMode()) { + $this->addColumn($DIC->language()->txt('actions')); + } + } + + + /** + * @param ilMStListCourse $profile + */ + public function fillRow($profile) + { + global $DIC; + + $propGetter = Closure::bind(function ($prop) { + return $this->$prop; + }, $profile, $profile); + + foreach ($this->getSelectableColumns() as $k => $v) { + if ($this->isColumnSelected($k)) { + switch ($k) { + case 'usr_reg_status': + $this->tpl->setCurrentBlock('td'); + $this->tpl->setVariable('VALUE', $this->getSpaceOrValue(ilMStListCourse::getMembershipStatusText($profile->getUsrRegStatus()))); + $this->tpl->parseCurrentBlock(); + break; + case 'usr_lp_status': + $this->tpl->setCurrentBlock('td'); + $this->tpl->setVariable('VALUE', $this->getSpaceOrValue(ilMyStaffGUI::getUserLpStatusAsHtml($profile))); + $this->tpl->parseCurrentBlock(); + break; + default: + if ($propGetter($k) !== null) { + $this->tpl->setCurrentBlock('td'); + $this->tpl->setVariable('VALUE', (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k))); + $this->tpl->parseCurrentBlock(); + } else { + $this->tpl->setCurrentBlock('td'); + $this->tpl->setVariable('VALUE', ' '); + $this->tpl->parseCurrentBlock(); + } + break; + } + } + } + + $actions = new ilAdvancedSelectionListGUI(); + $actions->setListTitle($DIC->language()->txt("actions")); + $actions->setAsynch(true); + $actions->setId($profile->getUsrId() . "-" . $profile->getCrsRefId()); + + $DIC->ctrl()->setParameterByClass(ilMStShowUserCoursesGUI::class, 'mst_lco_usr_id', $profile->getUsrId()); + $DIC->ctrl()->setParameterByClass(ilMStShowUserCoursesGUI::class, 'mst_lco_crs_ref_id', $profile->getCrsRefId()); + + $actions->setAsynchUrl(str_replace("\\", "\\\\", $DIC->ctrl() + ->getLinkTarget($this->parent_obj, ilMStShowUserCoursesGUI::CMD_GET_ACTIONS, "", true))); + $this->tpl->setVariable('ACTIONS', $actions->getHTML()); + $this->tpl->parseCurrentBlock(); + } + + + /** + * @param ilExcel $a_excel excel wrapper + * @param int $a_row + * @param ilMStListCourse $selected_skill + */ + protected function fillRowExcel(ilExcel $a_excel, &$a_row, $selected_skill) + { + $col = 0; + foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) { + $a_excel->setCell($a_row, $col, $v); + $col++; + } + } + + + /** + * @param ilCSVWriter $a_csv + * @param ilMStListCourse $selected_skill + */ + protected function fillRowCSV($a_csv, $selected_skill) + { + foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) { + $a_csv->addColumn($v); + } + $a_csv->addRow(); + } + + + /** + * @param ilMStListCourse $my_staff_course + */ + protected function getFieldValuesForExport(ilMStListCourse $my_staff_course) + { + $propGetter = Closure::bind(function ($prop) { return $this->$prop; }, $my_staff_course, $my_staff_course); + + $field_values = array(); + + foreach ($this->getSelectedColumns() as $k => $v) { + switch ($k) { + case 'usr_reg_status': + $field_values[$k] = ilMStListCourse::getMembershipStatusText($my_staff_course->getUsrRegStatus()); + break; + case 'usr_lp_status': + $field_values[$k] = ilMyStaffGUI::getUserLpStatusAsText($my_staff_course); + break; + default: + $field_values[$k] = strip_tags($propGetter($k)); + break; + } + } + + return $field_values; + } + + + protected function getSpaceOrValue(string $string) + { + if (!$this->getExportMode()) { + if (empty($string)) { + return " "; + } + } + + return $string; + } +} diff --git a/Services/MyStaff/classes/ShowUser/class.ilMStShowUserCoursesTableGUI.php b/Services/MyStaff/classes/ShowUser/class.ilMStShowUserCoursesTableGUI.php deleted file mode 100644 index 69acb789b540..000000000000 --- a/Services/MyStaff/classes/ShowUser/class.ilMStShowUserCoursesTableGUI.php +++ /dev/null @@ -1,321 +0,0 @@ - - */ -class ilMStShowUserCoursesTableGUI extends ilTable2GUI { - - /** - * @var int - */ - protected $usr_id; - /** - * @var array - */ - protected $filter = array(); - /** - * @var ilMyStaffAccess - */ - protected $access; - - - /** - * @param ilMStShowUserGUI $parent_obj - * @param string $parent_cmd - */ - public function __construct(ilMStShowUserGUI $parent_obj, $parent_cmd = ilMStShowUserGUI::CMD_INDEX) { - global $DIC; - - $this->access = ilMyStaffAccess::getInstance(); - - $this->usr_id = $DIC->http()->request()->getQueryParams()['usr_id']; - - $this->setPrefix('myst_su'); - $this->setFormName('myst_su'); - $this->setId('myst_su'); - - parent::__construct($parent_obj, $parent_cmd, ''); - $this->setRowTemplate('tpl.list_user_courses_row.html', "Services/MyStaff"); - $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));; - $this->setDefaultOrderDirection('desc'); - - $this->setShowRowsSelector(true); - - $this->setEnableTitle(true); - $this->setDisableFilterHiding(true); - $this->setEnableNumInfo(true); - - $this->setExportFormats(array( self::EXPORT_EXCEL, self::EXPORT_CSV )); - - $this->setFilterCols(5); - $this->initFilter(); - $this->addColumns(); - - $this->parseData(); - } - - - /** - * - */ - protected function parseData() { - global $DIC; - - $this->setExternalSorting(true); - $this->setExternalSegmentation(true); - $this->setDefaultOrderField('crs_title'); - - $this->determineLimit(); - $this->determineOffsetAndOrder(); - - $arr_usr_id = $this->access->getUsersForUserOperationAndContext($DIC->user() - ->getId(), ilOrgUnitOperation::OP_ACCESS_ENROLMENTS, ilMyStaffAccess::DEFAULT_CONTEXT); - - $this->filter['usr_id'] = $this->usr_id; - $options = array( - 'filters' => $this->filter, - 'limit' => array(), - 'count' => true, - 'sort' => array( - 'field' => $this->getOrderField(), - 'direction' => $this->getOrderDirection(), - ), - ); - $count = ilMStShowUserCourses::getData($arr_usr_id, $options); - $options['limit'] = array( - 'start' => intval($this->getOffset()), - 'end' => intval($this->getLimit()), - ); - $options['count'] = false; - $data = ilMStShowUserCourses::getData($arr_usr_id, $options); - - $this->setMaxCount($count); - $this->setData($data); - } - - - /** - * - */ - public function initFilter() { - global $DIC; - - $item = new ilTextInputGUI($DIC->language()->txt("crs_title"), "crs_title"); - $this->addFilterItem($item); - $item->readFromSession(); - $this->filter['crs_title'] = $item->getValue(); - - // course members - $item = new ilRepositorySelectorInputGUI($DIC->language()->txt("usr_filter_coursemember"), "course"); - $item->setSelectText($DIC->language()->txt("mst_select_course")); - $item->setHeaderMessage($DIC->language()->txt("mst_please_select_course")); - $item->setClickableTypes(array( ilMyStaffAccess::DEFAULT_CONTEXT )); - $this->addFilterItem($item); - $item->readFromSession(); - $item->setParent($this->getParentObject()); - $this->filter["course"] = $item->getValue(); - - //membership status - $item = new ilSelectInputGUI($DIC->language()->txt('member_status'), 'memb_status'); - $item->setOptions(array( - "" => $DIC->language()->txt("mst_opt_all"), - ilMStListCourse::MEMBERSHIP_STATUS_REQUESTED => $DIC->language()->txt('mst_memb_status_requested'), - ilMStListCourse::MEMBERSHIP_STATUS_WAITINGLIST => $DIC->language()->txt('mst_memb_status_waitinglist'), - ilMStListCourse::MEMBERSHIP_STATUS_REGISTERED => $DIC->language()->txt('mst_memb_status_registered'), - )); - $this->addFilterItem($item); - $item->readFromSession(); - $this->filter["memb_status"] = $item->getValue(); - - if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) { - //learning progress status - $item = new ilSelectInputGUI($DIC->language()->txt('learning_progress'), 'lp_status'); - //+1 because LP_STATUS_NOT_ATTEMPTED_NUM is 0. - $item->setOptions(array( - "" => $DIC->language()->txt("mst_opt_all"), - ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM + 1 => $DIC->language()->txt(ilLPStatus::LP_STATUS_NOT_ATTEMPTED), - ilLPStatus::LP_STATUS_IN_PROGRESS_NUM + 1 => $DIC->language()->txt(ilLPStatus::LP_STATUS_IN_PROGRESS), - ilLPStatus::LP_STATUS_COMPLETED_NUM + 1 => $DIC->language()->txt(ilLPStatus::LP_STATUS_COMPLETED), - ilLPStatus::LP_STATUS_FAILED_NUM + 1 => $DIC->language()->txt(ilLPStatus::LP_STATUS_FAILED), - )); - $this->addFilterItem($item); - $item->readFromSession(); - $this->filter["lp_status"] = $item->getValue(); - if ($this->filter["lp_status"]) { - $this->filter["lp_status"] = $this->filter["lp_status"] - 1; - } - } - } - - - /** - * @return array - */ - public function getSelectableColumns() { - global $DIC; - - $cols = array(); - - $cols['crs_title'] = array( - 'txt' => $DIC->language()->txt('crs_title'), - 'default' => true, - 'width' => 'auto', - 'sort_field' => 'crs_title', - ); - $cols['usr_reg_status'] = array( - 'txt' => $DIC->language()->txt('member_status'), - 'default' => true, - 'width' => 'auto', - 'sort_field' => 'reg_status', - ); - if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) { - $cols['usr_lp_status'] = array( - 'txt' => $DIC->language()->txt('learning_progress'), - 'default' => true, - 'width' => 'auto', - 'sort_field' => 'lp_status', - ); - } - - return $cols; - } - - - /** - * - */ - private function addColumns() { - global $DIC; - - foreach ($this->getSelectableColumns() as $k => $v) { - if ($this->isColumnSelected($k)) { - if (isset($v['sort_field'])) { - $sort = $v['sort_field']; - } else { - $sort = null; - } - $this->addColumn($v['txt'], $sort, $v['width']); - } - } - //Actions - if (!$this->getExportMode()) { - $this->addColumn($DIC->language()->txt('actions')); - } - } - - - /** - * @param ilMStListCourse $my_staff_course - */ - public function fillRow($my_staff_course) { - global $DIC; - - $propGetter = Closure::bind(function ($prop) { - return $this->$prop; - }, $my_staff_course, $my_staff_course); - - foreach ($this->getSelectableColumns() as $k => $v) { - if ($this->isColumnSelected($k)) { - switch ($k) { - case 'usr_reg_status': - $this->tpl->setCurrentBlock('td'); - $this->tpl->setVariable('VALUE', $this->getSpaceOrValue(ilMStListCourse::getMembershipStatusText($my_staff_course->getUsrRegStatus()))); - $this->tpl->parseCurrentBlock(); - break; - case 'usr_lp_status': - $this->tpl->setCurrentBlock('td'); - $this->tpl->setVariable('VALUE', $this->getSpaceOrValue(ilMyStaffGUI::getUserLpStatusAsHtml($my_staff_course))); - $this->tpl->parseCurrentBlock(); - break; - default: - if ($propGetter($k) !== null) { - $this->tpl->setCurrentBlock('td'); - $this->tpl->setVariable('VALUE', (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k))); - $this->tpl->parseCurrentBlock(); - } else { - $this->tpl->setCurrentBlock('td'); - $this->tpl->setVariable('VALUE', ' '); - $this->tpl->parseCurrentBlock(); - } - break; - } - } - } - - $actions = new ilAdvancedSelectionListGUI(); - $actions->setListTitle($DIC->language()->txt("actions")); - $actions->setAsynch(true); - $actions->setId($my_staff_course->getUsrId() . "-" . $my_staff_course->getCrsRefId()); - - $DIC->ctrl()->setParameterByClass(ilMStShowUserGUI::class, 'mst_lco_usr_id', $my_staff_course->getUsrId()); - $DIC->ctrl()->setParameterByClass(ilMStShowUserGUI::class, 'mst_lco_crs_ref_id', $my_staff_course->getCrsRefId()); - - $actions->setAsynchUrl(str_replace("\\", "\\\\", $DIC->ctrl() - ->getLinkTarget($this->parent_obj, ilMStShowUserGUI::CMD_GET_ACTIONS, "", true))); - $this->tpl->setVariable('ACTIONS', $actions->getHTML()); - $this->tpl->parseCurrentBlock(); - } - - - /** - * @param ilExcel $a_excel excel wrapper - * @param int $a_row - * @param ilMStListCourse $my_staff_course - */ - protected function fillRowExcel(ilExcel $a_excel, &$a_row, $my_staff_course) { - $col = 0; - foreach ($this->getFieldValuesForExport($my_staff_course) as $k => $v) { - $a_excel->setCell($a_row, $col, $v); - $col ++; - } - } - - - /** - * @param ilCSVWriter $a_csv - * @param ilMStListCourse $my_staff_course - */ - protected function fillRowCSV($a_csv, $my_staff_course) { - foreach ($this->getFieldValuesForExport($my_staff_course) as $k => $v) { - $a_csv->addColumn($v); - } - $a_csv->addRow(); - } - - - /** - * @param ilMStListCourse $my_staff_course - */ - protected function getFieldValuesForExport(ilMStListCourse $my_staff_course) { - $propGetter = Closure::bind(function ($prop) { return $this->$prop; }, $my_staff_course, $my_staff_course); - - $field_values = array(); - - foreach ($this->getSelectedColumns() as $k => $v) { - switch ($k) { - case 'usr_reg_status': - $field_values[$k] = ilMStListCourse::getMembershipStatusText($my_staff_course->getUsrRegStatus()); - break; - case 'usr_lp_status': - $field_values[$k] = ilMyStaffGUI::getUserLpStatusAsText($my_staff_course); - break; - default: - $field_values[$k] = strip_tags($propGetter($k)); - break; - } - } - - return $field_values; - } - - protected function getSpaceOrValue(string $string) { - if(!$this->getExportMode()) { - if(empty($string)) { - return " "; - } - } - return $string; - } -} diff --git a/Services/MyStaff/classes/ShowUser/class.ilMStShowUserGUI.php b/Services/MyStaff/classes/ShowUser/class.ilMStShowUserGUI.php index 7314734e7184..8d64344d475c 100644 --- a/Services/MyStaff/classes/ShowUser/class.ilMStShowUserGUI.php +++ b/Services/MyStaff/classes/ShowUser/class.ilMStShowUserGUI.php @@ -1,30 +1,29 @@ * * @ilCtrl_IsCalledBy ilMStShowUserGUI: ilMyStaffGUI - * @ilCtrl_Calls ilMStShowUserGUI: ilFormPropertyDispatchGUI + * @ilCtrl_Calls ilMStShowUserGUI: ilUserCertificateGUI */ class ilMStShowUserGUI { const CMD_INDEX = 'index'; - const CMD_SHOWUSER = 'showUser'; - const CMD_RESET_FILTER = 'resetFilter'; - const CMD_APPLY_FILTER = 'applyFilter'; - const TAB_SHOW_COURSES = 'show_courses'; - const TAB_SHOW_USER = 'show_user'; - const CMD_GET_ACTIONS = "getActions"; + const CMD_SHOW_USER = 'showUser'; + + const TAB_SHOW_USER = 'show_user'; + const TAB_SHOW_COURSES = 'show_courses'; + const TAB_SHOW_CERTIFICATES = 'show_certificates'; + const TAB_SHOW_COMPETENCES = 'show_competences'; + /** * @var int */ protected $usr_id; - /** - * @var ilTable2GUI - */ - protected $table; /** * @var ilMyStaffAccess */ @@ -80,26 +79,34 @@ public function executeCommand() { $next_class = $DIC->ctrl()->getNextClass(); switch ($next_class) { - case strtolower(ilFormPropertyDispatchGUI::class): - $DIC->ctrl()->setReturn($this, self::CMD_INDEX); - $this->table = new ilMStShowUserCoursesTableGUI($this, self::CMD_INDEX); - $this->table->executeCommand(); + case strtolower(ilMStShowUserCoursesGUI::class): + $this->addTabs(self::TAB_SHOW_COURSES); + $gui = new ilMStShowUserCoursesGUI(); + $DIC->ctrl()->forwardCommand($gui); break; + case strtolower(ilUserCertificateGUI::class): + $this->addTabs(self::TAB_SHOW_CERTIFICATES); + $gui = new ilUserCertificateGUI( + null, + null, + null, + new ilObjUser($this->usr_id) + ); + $DIC->ctrl()->forwardCommand($gui); + break; + case strtolower(ilMStShowUserCompetencesGUI::class): + $this->addTabs(self::TAB_SHOW_COMPETENCES); + $gui = new ilMStShowUserCompetencesGUI($DIC); + $DIC->ctrl()->forwardCommand($gui); + break; default: + switch ($cmd) { - case self::CMD_RESET_FILTER: - case self::CMD_APPLY_FILTER: - case self::CMD_INDEX: - case self::CMD_GET_ACTIONS: - $this->addTabs(self::TAB_SHOW_COURSES); - $this->$cmd(); - break; - case self::CMD_SHOWUSER: - $this->addTabs(self::TAB_SHOW_USER); - $this->$cmd(); - break; - default: - $this->addTabs(self::TAB_SHOW_COURSES); + case self::CMD_SHOW_USER: + $this->addTabs(self::TAB_SHOW_USER); + $this->$cmd(); + break; + default: $this->index(); break; } @@ -111,20 +118,8 @@ public function executeCommand() { * */ protected function index() { - $this->listUsers(); - } - - - /** - * - */ - protected function listUsers() { global $DIC; - - $this->table = new ilMStShowUserCoursesTableGUI($this, self::CMD_INDEX); - $this->table->setTitle(sprintf($DIC->language()->txt('mst_courses_of'), ilObjCourse::_lookupTitle($this->usr_id))); - - $DIC->ui()->mainTemplate()->setContent($this->table->getHTML()); + $DIC->ctrl()->redirectByClass(ilMStShowUserCoursesGUI::class); } @@ -145,38 +140,6 @@ protected function showUser() { } - /** - * - */ - protected function applyFilter() { - $this->table = new ilMStShowUserCoursesTableGUI($this, self::CMD_APPLY_FILTER); - $this->table->writeFilterToSession(); - $this->table->resetOffset(); - $this->index(); - } - - - /** - * - */ - protected function resetFilter() { - $this->table = new ilMStShowUserCoursesTableGUI($this, self::CMD_RESET_FILTER); - $this->table->resetOffset(); - $this->table->resetFilter(); - $this->index(); - } - - - /** - * @return string - */ - public function getId() { - $this->table = new ilMStShowUserCoursesTableGUI($this, self::CMD_INDEX); - - return $this->table->getId(); - } - - /** * */ @@ -193,19 +156,41 @@ public function cancel() { protected function addTabs($active_tab_id) { global $DIC; - $DIC->tabs()->setBackTarget($DIC->language()->txt('mst_list_users'), $DIC->ctrl()->getLinkTargetByClass(array( - ilMyStaffGUI::class, - ilMStListUsersGUI::class, - ))); - $DIC->tabs()->addTab(self::TAB_SHOW_COURSES, $DIC->language()->txt('mst_show_courses'), $DIC->ctrl()->getLinkTargetByClass(array( - ilMyStaffGUI::class, - self::class, - ), self::CMD_INDEX)); + $DIC->tabs()->setBackTarget($DIC->language()->txt('mst_list_users'), $DIC->ctrl()->getLinkTargetByClass(array( + ilMyStaffGUI::class, + self::class, + ilMStListUsersGUI::class, + ))); + + if ($this->access->hasCurrentUserAccessToMyStaff()) { + $DIC->tabs()->addTab(self::TAB_SHOW_COURSES, $DIC->language()->txt('mst_list_courses'), $DIC->ctrl()->getLinkTargetByClass(array( + ilMyStaffGUI::class, + self::class, + ilMStShowUserCoursesGUI::class, + ))); + } - $user = new ilObjUser($this->usr_id); + if ($this->access->hasCurrentUserAccessToCertificates()) { + $DIC->tabs()->addTab(self::TAB_SHOW_CERTIFICATES, $DIC->language()->txt('mst_list_certificates'), $DIC->ctrl()->getLinkTargetByClass(array( + ilMyStaffGUI::class, + self::class, + ilUserCertificateGUI::class, + ))); + } + + if ($this->access->hasCurrentUserAccessToCompetences()) { + $DIC->tabs()->addTab(self::TAB_SHOW_COMPETENCES, $DIC->language()->txt('mst_list_competences'), $DIC->ctrl()->getLinkTargetByClass(array( + ilMyStaffGUI::class, + self::class, + ilMStShowUserCompetencesGUI::class, + ))); + } + + + $user = new ilObjUser($this->usr_id); if ($user->hasPublicProfile()) { $DIC->ctrl()->setParameterByClass(self::class, 'usr_id', $this->usr_id); - $public_profile_url = $DIC->ctrl()->getLinkTargetByClass(self::class, self::CMD_SHOWUSER); + $public_profile_url = $DIC->ctrl()->getLinkTargetByClass(self::class, self::CMD_SHOW_USER); $DIC->tabs()->addTab(self::TAB_SHOW_USER, $DIC->language()->txt('public_profile'), $public_profile_url); } @@ -213,40 +198,4 @@ protected function addTabs($active_tab_id) { $DIC->tabs()->activateTab($active_tab_id); } } - - /** - * - */ - public function getActions() { - global $DIC; - - $mst_co_usr_id = $DIC->http()->request()->getQueryParams()['mst_lco_usr_id']; - $mst_lco_crs_ref_id = $DIC->http()->request()->getQueryParams()['mst_lco_crs_ref_id']; - - if ($mst_co_usr_id > 0 && $mst_lco_crs_ref_id > 0) { - $selection = new ilAdvancedSelectionListGUI(); - - if ($DIC->access()->checkAccess("visible", "", $mst_lco_crs_ref_id)) { - $link = ilLink::_getStaticLink($mst_lco_crs_ref_id, ilMyStaffAccess::DEFAULT_CONTEXT); - $selection->addItem(ilObject2::_lookupTitle(ilObject2::_lookupObjectId($mst_lco_crs_ref_id)), '', $link); - }; - - $org_units = ilOrgUnitPathStorage::getTextRepresentationOfOrgUnits('ref_id'); - foreach (ilOrgUnitUserAssignment::innerjoin('object_reference', 'orgu_id', 'ref_id')->where(array( - 'user_id' => $mst_co_usr_id, - 'object_reference.deleted' => null - ), array( 'user_id' => '=', 'object_reference.deleted' => '!=' ))->get() as $org_unit_assignment) { - if ($DIC->access()->checkAccess("read", "", $org_unit_assignment->getOrguId())) { - $link = ilLink::_getStaticLink($org_unit_assignment->getOrguId(), 'orgu'); - $selection->addItem($org_units[$org_unit_assignment->getOrguId()], '', $link); - } - } - - $selection = ilMyStaffGUI::extendActionMenuWithUserActions($selection, $mst_co_usr_id, rawurlencode($DIC->ctrl() - ->getLinkTarget($this, self::CMD_INDEX))); - - echo $selection->getHTML(true); - } - exit; - } } diff --git a/Services/MyStaff/classes/class.ilMyStaffAccess.php b/Services/MyStaff/classes/class.ilMyStaffAccess.php index 2bb7f857e586..f0d9fd0add99 100644 --- a/Services/MyStaff/classes/class.ilMyStaffAccess.php +++ b/Services/MyStaff/classes/class.ilMyStaffAccess.php @@ -1,221 +1,326 @@ */ -class ilMyStaffAccess extends ilObjectAccess { - - const TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_SPEC_PERMISSIONS = 'tmp_obj_spec_perm'; - const TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_DEFAULT_PERMISSIONS = 'tmp_obj_def_perm'; - const TMP_DEFAULT_TABLE_NAME_PREFIX_IL_ORGU_DEFAULT_PERMISSIONS = 'tmp_orgu_def_perm'; - const TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS = 'tmp_crs_members'; - const TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS = 'tmp_orgu_members'; - const TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX = 'tmp_obj_user_matr'; - const DEFAULT_ORG_UNIT_OPERATION = ilOrgUnitOperation::OP_ACCESS_ENROLMENTS; - const DEFAULT_CONTEXT = 'crs'; - /** - * @var self - */ - protected static $instance = null; - /** - * @var - */ - protected static $orgu_users_of_current_user_show_staff_permission; - - - /** - * @return self - */ - public static function getInstance() { - global $DIC; - - if (self::$instance === null) { - self::$instance = new self(); - - self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_SPEC_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_" - . self::DEFAULT_CONTEXT); - self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_DEFAULT_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION - . "_" . self::DEFAULT_CONTEXT); - self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_ORGU_DEFAULT_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION - . "_" . self::DEFAULT_CONTEXT); - self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS . "_user_id_" . $DIC->user()->getId()); - self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS . "_user_id_" . $DIC->user()->getId()); - self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_" - . self::DEFAULT_CONTEXT); - } - - return self::$instance; - } - - - /** - * - */ - private function __construct() { - - } - - - /** - * @return bool - */ - public function hasCurrentUserAccessToMyStaff() { - global $DIC; - - if (!$DIC->settings()->get("enable_my_staff")) { - return false; - } - - $operation = ilOrgUnitOperationQueries::findByOperationString(ilOrgUnitOperation::OP_ACCESS_ENROLMENTS, self::DEFAULT_CONTEXT); - if (!$operation) { - return false; - } - if ($this->countOrgusOfUserWithOperationAndContext($DIC->user()->getId(), ilOrgUnitOperation::OP_ACCESS_ENROLMENTS, self::DEFAULT_CONTEXT) - > 0) { - return true; - } - - return false; - } - - - /** - * @param int $usr_id - * - * @return bool - */ - public function hasCurrentUserAccessToUser($usr_id = 0) { - global $DIC; - - if (in_array($usr_id, $this->getUsersForUser($DIC->user()->getId()))) { - return true; - } - - return false; - } - - - /** - * @param int $ref_id - * - * @return bool - */ - public function hasCurrentUserAccessToLearningProgressInObject($ref_id = 0) { - global $DIC; - - return $DIC->access()->checkPositionAccess(ilOrgUnitOperation::OP_READ_LEARNING_PROGRESS, $ref_id); - } - - - /** - * @return bool - */ - public function hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser() { - global $DIC; - - $arr_usr_id = $this->getUsersForUserOperationAndContext($DIC->user() - ->getId(), ilOrgUnitOperation::OP_READ_LEARNING_PROGRESS, self::DEFAULT_CONTEXT); - if (count($arr_usr_id) > 0) { - return true; - } - - return false; - } - - - /** - * @param int $user_id - * - * @return int - */ - public function countOrgusOfUserWithAtLeastOneOperation($user_id) { - global $DIC; - - $q = "SELECT COUNT(orgu_ua.orgu_id) AS 'cnt' FROM il_orgu_permissions AS perm +class ilMyStaffAccess extends ilObjectAccess +{ + + const TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_SPEC_PERMISSIONS = 'tmp_obj_spec_perm'; + const TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_DEFAULT_PERMISSIONS = 'tmp_obj_def_perm'; + const TMP_DEFAULT_TABLE_NAME_PREFIX_IL_ORGU_DEFAULT_PERMISSIONS = 'tmp_orgu_def_perm'; + const TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS = 'tmp_crs_members'; + const TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS = 'tmp_orgu_members'; + const TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX = 'tmp_obj_user_matr'; + const DEFAULT_ORG_UNIT_OPERATION = ilOrgUnitOperation::OP_ACCESS_ENROLMENTS; + const DEFAULT_CONTEXT = 'crs'; + /** + * @var self + */ + protected static $instance = null; + /** + * @var + */ + protected static $orgu_users_of_current_user_show_staff_permission; + + + /** + * @return self + */ + public static function getInstance() + { + global $DIC; + + if (self::$instance === null) { + self::$instance = new self(); + + self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_SPEC_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_" + . self::DEFAULT_CONTEXT); + self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_DEFAULT_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION + . "_" . self::DEFAULT_CONTEXT); + self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_ORGU_DEFAULT_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION + . "_" . self::DEFAULT_CONTEXT); + self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS . "_user_id_" . $DIC->user()->getId()); + self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS . "_user_id_" . $DIC->user()->getId()); + self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_" + . self::DEFAULT_CONTEXT); + } + + return self::$instance; + } + + + /** + * + */ + private function __construct() + { + + } + + + /** + * @return bool + */ + public function hasCurrentUserAccessToMyStaff() : bool + { + global $DIC; + + if (!$DIC->settings()->get("enable_my_staff")) { + return false; + } + + if (!$this->hasCurrentUserAccessToUser()) { + return true; + } + + if ($this->countOrgusOfUserWithOperationAndContext($DIC->user()->getId(), ilOrgUnitOperation::OP_ACCESS_ENROLMENTS, self::DEFAULT_CONTEXT) + > 0 + ) { + return true; + } + + if ($this->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) { + return true; + } + + if ($this->hasCurrentUserAccessToCertificates()) { + return true; + } + + if ($this->hasCurrentUserAccessToCompetences()) { + true; + } + + return false; + } + + + /** + * @return bool + */ + public function hasCurrentUserAccessToCertificates() : bool + { + global $DIC; + + if (!$DIC->settings()->get("enable_my_staff")) { + return false; + } + + if ($this->countOrgusOfUserWithOperationAndContext($DIC->user()->getId(), ilOrgUnitOperation::OP_VIEW_CERTIFICATES, self::DEFAULT_CONTEXT) + > 0 + ) { + return true; + } + + return false; + } + + + /** + * @return bool + */ + public function hasCurrentUserAccessToCompetences() : bool + { + global $DIC; + + if (!$DIC->settings()->get("enable_my_staff")) { + return false; + } + + if ($this->countOrgusOfUserWithOperationAndContext($DIC->user()->getId(), ilOrgUnitOperation::OP_VIEW_COMPETENCES, self::DEFAULT_CONTEXT) + > 0 + ) { + return true; + } + + return false; + } + + + /** + * @param int $usr_id + * + * @return bool + */ + public function hasCurrentUserAccessToUser($usr_id = 0) : bool + { + global $DIC; + + if (in_array($usr_id, $this->getUsersForUser($DIC->user()->getId()))) { + return true; + } + + return false; + } + + + /** + * @param int $ref_id + * + * @return bool + */ + public function hasCurrentUserAccessToLearningProgressInObject($ref_id = 0) : bool + { + global $DIC; + + return $DIC->access()->checkPositionAccess(ilOrgUnitOperation::OP_READ_LEARNING_PROGRESS, $ref_id); + } + + + /** + * @return bool + */ + public function hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser() : bool + { + global $DIC; + + $arr_usr_id = $this->getUsersForUserOperationAndContext($DIC->user() + ->getId(), ilOrgUnitOperation::OP_READ_LEARNING_PROGRESS, self::DEFAULT_CONTEXT); + if (count($arr_usr_id) > 0) { + return true; + } + + return false; + } + + + /** + * @param int $user_id + * + * @return int + */ + public function countOrgusOfUserWithAtLeastOneOperation($user_id) + { + global $DIC; + + $q = "SELECT COUNT(orgu_ua.orgu_id) AS 'cnt' FROM il_orgu_permissions AS perm INNER JOIN il_orgu_ua AS orgu_ua ON orgu_ua.position_id = perm.position_id INNER JOIN il_orgu_op_contexts AS contexts on contexts.id = perm.context_id AND contexts.context is not NULL WHERE orgu_ua.user_id = " . $DIC->database()->quote($user_id, 'integer') . " AND perm.operations is not NULL AND perm.parent_id = -1"; - $set = $DIC->database()->query($q); - $rec = $DIC->database()->fetchAssoc($set); + $set = $DIC->database()->query($q); + $rec = $DIC->database()->fetchAssoc($set); - return $rec['cnt']; - } + return $rec['cnt']; + } - /** - * @param int $user_id - * @param string $org_unit_operation_string see ilOrgUnitOperation - * @param string $context - * - * @return int - */ - public function countOrgusOfUserWithOperationAndContext($user_id, $org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, $context = self::DEFAULT_CONTEXT) { - global $DIC; + /** + * @param int $user_id + * @param string $org_unit_operation_string see ilOrgUnitOperation + * @param string $context + * + * @return int + */ + public function countOrgusOfUserWithOperationAndContext($user_id, $org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, $context = self::DEFAULT_CONTEXT) + { + global $DIC; - /** - * @var ilOrgUnitOperation $operation - */ - $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context); + /** + * @var ilOrgUnitOperation $operation + */ + $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context); - $q = "SELECT COUNT(orgu_ua.orgu_id) AS cnt FROM il_orgu_permissions AS perm + $q = "SELECT COUNT(orgu_ua.orgu_id) AS cnt FROM il_orgu_permissions AS perm INNER JOIN il_orgu_ua AS orgu_ua ON orgu_ua.position_id = perm.position_id INNER JOIN il_orgu_op_contexts AS contexts on contexts.id = perm.context_id AND contexts.context = '" . $context . "' and orgu_ua.user_id = " . $DIC->database()->quote($user_id, 'integer') . " AND perm.operations LIKE '%\"" - . $operation->getOperationId() . "\"%' + . $operation->getOperationId() . "\"%' WHERE perm.parent_id = -1"; - $set = $DIC->database()->query($q); - $rec = $DIC->database()->fetchAssoc($set); - - return $rec['cnt']; - } - - - /** - * @param int $user_id - * @param string $org_unit_operation_string - * @param string $context - * @param string $tmp_table_name_prefix - * - * @return array - */ - public function getUsersForUserOperationAndContext($user_id, $org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, $context = self::DEFAULT_CONTEXT, $tmp_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX) { - global $DIC; - - $tmp_table_name = $this->buildTempTableIlobjectsUserMatrixForUserOperationAndContext($user_id, $org_unit_operation_string, $context, $tmp_table_name_prefix); - - $q = 'SELECT usr_id FROM ' . $tmp_table_name; - - $user_set = $DIC->database()->query($q); - - $arr_users = array(); - - while ($rec = $DIC->database()->fetchAssoc($user_set)) { - $arr_users[$rec['usr_id']] = $rec['usr_id']; - } - - return $arr_users; - } - - - /** - * @param int $user_id - * - * @return array - */ - public function getUsersForUser($user_id) { - global $DIC; - - $tmp_orgu_members = $this->buildTempTableOrguMemberships(self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS, array()); - - $q = "SELECT " . $tmp_orgu_members . ".user_id AS usr_id + $set = $DIC->database()->query($q); + $rec = $DIC->database()->fetchAssoc($set); + + return $rec['cnt']; + } + + + /** + * @param int $user_id + * @param string $org_unit_operation_string + * @param string $context + * @param string $tmp_table_name_prefix + * + * @return array + */ + public function getUsersForUserOperationAndContext( + $user_id, + $org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, + $context = self::DEFAULT_CONTEXT, + $tmp_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX + ) { + global $DIC; + + $tmp_table_name = $this->buildTempTableIlobjectsUserMatrixForUserOperationAndContext($user_id, $org_unit_operation_string, $context, $tmp_table_name_prefix); + + $q = 'SELECT usr_id FROM ' . $tmp_table_name; + + $user_set = $DIC->database()->query($q); + + $arr_users = array(); + + while ($rec = $DIC->database()->fetchAssoc($user_set)) { + $arr_users[$rec['usr_id']] = $rec['usr_id']; + } + + return $arr_users; + } + + + /** + * @param $user_id + * + * @return array + */ + public function getUsersForUserPerPosition($user_id) : array + { + $users = []; + $user_assignments = ilOrgUnitUserAssignmentQueries::getInstance()->getAssignmentsOfUserId($user_id); + foreach ($user_assignments as $user_assignment) { + $users[$user_assignment->getPositionId()] = $this->getUsersForUser($user_id, $user_assignment->getPositionId()); + } + + return $users; + } + + + /** + * @param int $user_id + * + * @param int|null $position_id + * + * @return int[] + */ + public function getUsersForUser($user_id, ?int $position_id = null) : array + { + global $DIC; + + $tmp_orgu_members = $this->buildTempTableOrguMemberships(self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS, array()); + + $position_limitation = ''; + if (!is_null($position_id)) { + $position_limitation = ' AND orgu_ua_current_user.position_id = ' . $position_id; + } + + $q = "SELECT " . $tmp_orgu_members . ".user_id AS usr_id FROM " . $tmp_orgu_members . " INNER JOIN il_orgu_ua AS orgu_ua_current_user on orgu_ua_current_user.user_id = " . $DIC->database()->quote($user_id, 'integer') . " - INNER JOIN il_orgu_authority AS auth ON auth.position_id = orgu_ua_current_user.position_id + INNER JOIN il_orgu_authority AS auth ON auth.position_id = orgu_ua_current_user.position_id " . $position_limitation . " WHERE ( /* Identische OrgUnit wie Current User; Nicht Rekursiv; Fixe Position */ @@ -252,89 +357,202 @@ public function getUsersForUser($user_id) { ) )"; - $user_set = $DIC->database()->query($q); - - $arr_users = array(); - - while ($rec = $DIC->database()->fetchAssoc($user_set)) { - $arr_users[$rec['usr_id']] = $rec['usr_id']; - } - - return $arr_users; - } - - - /** - * @param int $user_id - * @param string $org_unit_operation_string - * @param string $context - * - * @return array - */ - public function getIlobjectsAndUsersForUserOperationAndContext($user_id, $org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, $context = self::DEFAULT_CONTEXT) { - global $DIC; - - /** - * @var ilOrgUnitOperation $operation - */ - $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context); - - $tmp_table_name = 'tmp_ilobj_user_matrix_' . $operation->getOperationId(); + $user_set = $DIC->database()->query($q); + + $arr_users = array(); + + while ($rec = $DIC->database()->fetchAssoc($user_set)) { + $arr_users[$rec['usr_id']] = $rec['usr_id']; + } + + return $arr_users; + } + + + /** + * @param int $user_id + * @param string $operation + * @param bool $return_ref_id + * + * @return int[] + */ + public function getIdsForUserAndOperation(int $user_id, string $operation, bool $return_ref_id = false) : array + { + $user_assignments = ilOrgUnitUserAssignmentQueries::getInstance()->getAssignmentsOfUserId($user_id); + $ids = []; + foreach ($user_assignments as $user_assignment) { + $ids = array_merge($ids, $this->getIdsForPositionAndOperation($user_assignment->getPositionId(), $operation, $return_ref_id)); + } + + return $ids; + } + + + /** + * @param int $position_id + * @param string $operation + * @param bool $return_ref_id + * + * @return array + */ + public function getIdsForPositionAndOperation(int $position_id, string $operation, bool $return_ref_id) : array + { + $ids = []; + foreach (ilOrgUnitOperationContext::$available_contexts as $context) { + $ids = array_merge($ids, $this->getIdsForPositionAndOperationAndContext($position_id, $operation, $context, $return_ref_id)); + } + + return $ids; + } + + + /** + * returns all obj_ids/ref_ids (depending on flag "ref_id") of objects of type $context, + * to which the position with $position_id has permissions + * on the operation with $operation_id + * + * @param int $position_id + * @param string $operation + * @param string $context + * + * @param bool $return_ref_id + * + * @return array + */ + public function getIdsForPositionAndOperationAndContext(int $position_id, string $operation, string $context, bool $return_ref_id) : array + { + global $DIC; + $context_id = ilOrgUnitOperationContextQueries::findByName($context)->getId(); + $operation_object = ilOrgUnitOperationQueries::findByOperationString($operation, $context); + if (is_null($operation_object)) { + // operation doesn't exist in this context + return []; + } + $operation_id = $operation_object->getOperationId(); + + if ($this->hasPositionDefaultPermissionForOperationInContext($position_id, $operation_id, $context_id)) { + $query = 'select ' . ($return_ref_id ? 'object_reference.ref_id' : 'object_data.obj_id') . ' from object_data ' . + 'inner join object_reference on object_reference.obj_id = object_data.obj_id ' . + 'where type = "' . $context . '" ' . + 'AND object_reference.ref_id not in ' . + ' (SELECT parent_id FROM il_orgu_permissions ' . + ' where position_id = ' . $position_id . ' and context_id = ' . $context_id . ' and operations not like \'%"' . $operation_id . '"%\' and parent_id <> -1)'; + } else { + $query = $return_ref_id + ? + 'SELECT parent_id as ref_id FROM il_orgu_permissions ' + : + 'SELECT obj_id FROM il_orgu_permissions INNER JOIN object_reference ON object_reference.ref_id = il_orgu_permissions.parent_id '; + $query .= ' where position_id = ' . $position_id . ' and context_id = ' . $context_id . ' and operations like \'%"' . $operation_id . '"%\' and parent_id <> -1'; + } + + return array_map(function ($item) use ($return_ref_id) { + return $return_ref_id ? $item['ref_id'] : $item['obj_id']; + }, $DIC->database()->fetchAll($DIC->database()->query($query))); + } + + + /** + * @param int $position_id + * @param int $operation_id + * @param int $context_id + * + * @return bool + */ + public function hasPositionDefaultPermissionForOperationInContext(int $position_id, int $operation_id, int $context_id) : bool + { + global $DIC; + $res = $DIC->database()->query('SELECT * FROM il_orgu_permissions ' . + ' WHERE context_id = ' . $context_id . ' ' . + 'AND operations LIKE \'%"' . $operation_id . '"%\' ' . + 'AND position_id = ' . $position_id . ' ' . + 'AND parent_id = -1'); + + return (bool) $DIC->database()->numRows($res) > 0; + } + + + /** + * @param int $user_id + * @param string $org_unit_operation_string + * @param string $context + * + * @return array + */ + public function getIlobjectsAndUsersForUserOperationAndContext($user_id, $org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, $context = self::DEFAULT_CONTEXT) + { + global $DIC; + + /** + * @var ilOrgUnitOperation $operation + */ + $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context); + + $tmp_table_name = 'tmp_ilobj_user_matrix_' . $operation->getOperationId(); + + $this->buildTempTableIlobjectsUserMatrixForUserOperationAndContext($user_id, $org_unit_operation_string, $context, $tmp_table_name); + + $q = 'SELECT * FROM ' . $tmp_table_name; + + $user_set = $DIC->database()->query($q); + + $arr_user_obj = array(); + + while ($rec = $DIC->database()->fetchAssoc($user_set)) { + $arr_user_obj[] = $rec; + } + + return $arr_user_obj; + } + + + /** + * @param int $user_id + * @param string $org_unit_operation_string + * @param string $context + * @param string $temporary_table_name_prefix + * + * @return string + */ + public function buildTempTableIlobjectsUserMatrixForUserOperationAndContext( + $user_id, + $org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, + $context = self::DEFAULT_CONTEXT, + $temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX + ) { + global $DIC; + + $temporary_table_name = $temporary_table_name_prefix . "_" . $org_unit_operation_string . "_" . $context; + + /** + * @var ilOrgUnitOperation $operation + */ + $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context); + + $all_users_for_user = $this->getUsersForUser($GLOBALS['DIC']->user()->getId()); + + $tmp_table_objects_specific_perimissions = $this->buildTempTableIlobjectsSpecificPermissionSetForOperationAndContext($org_unit_operation_string, $context, + self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_SPEC_PERMISSIONS); + + $tmp_table_objects_default_perimissions = $this->buildTempTableIlobjectsDefaultPermissionSetForOperationAndContext($org_unit_operation_string, $context, + self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_DEFAULT_PERMISSIONS); + + $tmp_table_orgunit_default_perimissions = $this->buildTempTableIlorgunitDefaultPermissionSetForOperationAndContext($org_unit_operation_string, $context, + self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_ORGU_DEFAULT_PERMISSIONS); + + $tmp_table_course_members = $this->buildTempTableCourseMemberships(self::TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS, $all_users_for_user); + + $tmp_table_orgu_members = $this->buildTempTableOrguMemberships(self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS, $all_users_for_user); - $this->buildTempTableIlobjectsUserMatrixForUserOperationAndContext($user_id, $org_unit_operation_string, $context, $tmp_table_name); + $tmp_table_orgu_member_path = $this->buildTempTableOrguMemberships('tmp_orgu_members_path', $all_users_for_user); - $q = 'SELECT * FROM ' . $tmp_table_name; + if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_" + . self::DEFAULT_CONTEXT + ) { + $this->dropTempTable($temporary_table_name); + } - $user_set = $DIC->database()->query($q); - - $arr_user_obj = array(); - - while ($rec = $DIC->database()->fetchAssoc($user_set)) { - $arr_user_obj[] = $rec; - } - - return $arr_user_obj; - } - - - /** - * @param int $user_id - * @param string $org_unit_operation_string - * @param string $context - * @param string $temporary_table_name_prefix - * - * @return string - */ - public function buildTempTableIlobjectsUserMatrixForUserOperationAndContext($user_id, $org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, $context = self::DEFAULT_CONTEXT, $temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX) { - global $DIC; - - $temporary_table_name = $temporary_table_name_prefix . "_" . $org_unit_operation_string . "_" . $context; - - /** - * @var ilOrgUnitOperation $operation - */ - $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context); - - $all_users_for_user = $this->getUsersForUser($GLOBALS['DIC']->user()->getId()); - - $tmp_table_objects_specific_perimissions = $this->buildTempTableIlobjectsSpecificPermissionSetForOperationAndContext($org_unit_operation_string, $context, self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_SPEC_PERMISSIONS); - - $tmp_table_objects_default_perimissions = $this->buildTempTableIlobjectsDefaultPermissionSetForOperationAndContext($org_unit_operation_string, $context, self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_DEFAULT_PERMISSIONS); - - $tmp_table_orgunit_default_perimissions = $this->buildTempTableIlorgunitDefaultPermissionSetForOperationAndContext($org_unit_operation_string, $context, self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_ORGU_DEFAULT_PERMISSIONS); - - $tmp_table_course_members = $this->buildTempTableCourseMemberships(self::TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS, $all_users_for_user); - - $tmp_table_orgu_members = $this->buildTempTableOrguMemberships(self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS, $all_users_for_user); - - $tmp_table_orgu_member_path = $this->buildTempTableOrguMemberships('tmp_orgu_members_path', $all_users_for_user); - - if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_" - . self::DEFAULT_CONTEXT) { - $this->dropTempTable($temporary_table_name); - } - - $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . " AS ( + $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . " AS ( SELECT DISTINCT user_perm_matrix.perm_for_ref_id, user_perm_matrix.usr_id FROM ( SELECT crs.*," . $tmp_table_course_members . ".ref_id," . $tmp_table_course_members . ".usr_id FROM @@ -352,13 +570,13 @@ public function buildTempTableIlobjectsUserMatrixForUserOperationAndContext($use ) UNION SELECT " . $tmp_table_orgunit_default_perimissions . ".*, " . $tmp_table_orgu_members . ".orgu_id AS ref_id, " - . $tmp_table_orgu_members . ".user_id FROM " . $tmp_table_orgunit_default_perimissions . " + . $tmp_table_orgu_members . ".user_id FROM " . $tmp_table_orgunit_default_perimissions . " INNER JOIN " . $tmp_table_orgu_members . " on " . $tmp_table_orgu_members . ".orgu_id = " - . $tmp_table_orgunit_default_perimissions . ".perm_for_ref_id + . $tmp_table_orgunit_default_perimissions . ".perm_for_ref_id and ( ( " . $tmp_table_orgu_members . ".orgu_id = " . $tmp_table_orgunit_default_perimissions . ".perm_for_orgu_id AND " - . $tmp_table_orgu_members . ".user_position_id = " . $tmp_table_orgunit_default_perimissions . ".perm_over_user_with_position AND perm_orgu_scope = 1 + . $tmp_table_orgu_members . ".user_position_id = " . $tmp_table_orgunit_default_perimissions . ".perm_over_user_with_position AND perm_orgu_scope = 1 ) or perm_orgu_scope = 2 ) @@ -410,35 +628,40 @@ public function buildTempTableIlobjectsUserMatrixForUserOperationAndContext($use ) );"; - $DIC->database()->manipulate($q); + $DIC->database()->manipulate($q); - return $temporary_table_name; - } + return $temporary_table_name; + } - /** - * @param string $org_unit_operation_string - * @param string $context - * @param string $temporary_table_name_prefix - * - * @return string - */ - public function buildTempTableIlobjectsSpecificPermissionSetForOperationAndContext($org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, $context = self::DEFAULT_CONTEXT, $temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_SPEC_PERMISSIONS) { - global $DIC; + /** + * @param string $org_unit_operation_string + * @param string $context + * @param string $temporary_table_name_prefix + * + * @return string + */ + public function buildTempTableIlobjectsSpecificPermissionSetForOperationAndContext( + $org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, + $context = self::DEFAULT_CONTEXT, + $temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_SPEC_PERMISSIONS + ) { + global $DIC; - $temporary_table_name = $temporary_table_name_prefix . "_" . $org_unit_operation_string . "_" . $context; + $temporary_table_name = $temporary_table_name_prefix . "_" . $org_unit_operation_string . "_" . $context; - /** - * @var ilOrgUnitOperation $operation - */ - $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context); + /** + * @var ilOrgUnitOperation $operation + */ + $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context); - if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_SPEC_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_" - . self::DEFAULT_CONTEXT) { - $this->dropTempTable($temporary_table_name); - } + if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_SPEC_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_" + . self::DEFAULT_CONTEXT + ) { + $this->dropTempTable($temporary_table_name); + } - $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . " + $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . " (INDEX i1 (perm_for_ref_id), INDEX i2 (perm_for_orgu_id), INDEX i3 (perm_orgu_scope), INDEX i4 (perm_for_position_id), INDEX i5 (perm_over_user_with_position)) AS ( SELECT @@ -451,7 +674,7 @@ public function buildTempTableIlobjectsSpecificPermissionSetForOperationAndConte il_orgu_permissions AS perm INNER JOIN il_orgu_ua AS orgu_ua ON orgu_ua.position_id = perm.position_id INNER JOIN il_orgu_authority AS auth ON auth.position_id = orgu_ua.position_id AND orgu_ua.user_id = " . $GLOBALS['DIC']->user() - ->getId() . " + ->getId() . " INNER JOIN object_reference AS obj_ref ON obj_ref.ref_id = perm.parent_id INNER JOIN object_data AS obj ON obj.obj_id = obj_ref.obj_id AND obj.type = '$context' INNER JOIN il_orgu_op_contexts AS contexts on contexts.id = perm.context_id AND contexts.context = '$context' @@ -459,35 +682,40 @@ public function buildTempTableIlobjectsSpecificPermissionSetForOperationAndConte perm.operations LIKE '%\"" . $operation->getOperationId() . "\"%' );"; - $DIC->database()->manipulate($q); + $DIC->database()->manipulate($q); - return $temporary_table_name; - } + return $temporary_table_name; + } - /** - * @param string $org_unit_operation_string - * @param string $context - * @param string $temporary_table_name_prefix - * - * @return string - */ - public function buildTempTableIlobjectsDefaultPermissionSetForOperationAndContext($org_unit_operation_string = ilOrgUnitOperation::OP_ACCESS_ENROLMENTS, $context = self::DEFAULT_CONTEXT, $temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_DEFAULT_PERMISSIONS) { - global $DIC; + /** + * @param string $org_unit_operation_string + * @param string $context + * @param string $temporary_table_name_prefix + * + * @return string + */ + public function buildTempTableIlobjectsDefaultPermissionSetForOperationAndContext( + $org_unit_operation_string = ilOrgUnitOperation::OP_ACCESS_ENROLMENTS, + $context = self::DEFAULT_CONTEXT, + $temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_DEFAULT_PERMISSIONS + ) { + global $DIC; - $temporary_table_name = $temporary_table_name_prefix . "_" . $org_unit_operation_string . "_" . $context; + $temporary_table_name = $temporary_table_name_prefix . "_" . $org_unit_operation_string . "_" . $context; - /** - * @var ilOrgUnitOperation $operation - */ - $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context); + /** + * @var ilOrgUnitOperation $operation + */ + $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context); - if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_DEFAULT_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_" - . self::DEFAULT_CONTEXT) { - $this->dropTempTable($temporary_table_name); - } + if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_DEFAULT_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_" + . self::DEFAULT_CONTEXT + ) { + $this->dropTempTable($temporary_table_name); + } - $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . " + $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . " (INDEX i1 (perm_for_ref_id), INDEX i2 (perm_for_orgu_id), INDEX i3 (perm_orgu_scope), INDEX i4 (perm_for_position_id),INDEX i5 (perm_over_user_with_position)) AS ( SELECT @@ -502,7 +730,7 @@ public function buildTempTableIlobjectsDefaultPermissionSetForOperationAndContex INNER JOIN il_orgu_permissions AS perm ON perm.operations LIKE '%\"" . $operation->getOperationId() . "\"%' AND perm.parent_id = -1 INNER JOIN il_orgu_op_contexts AS contexts on contexts.id = perm.context_id AND contexts.context = '" . $context . "' INNER JOIN il_orgu_ua AS orgu_ua ON orgu_ua.position_id = perm.position_id AND orgu_ua.user_id = " . $GLOBALS['DIC']->user() - ->getId() . " + ->getId() . " INNER JOIN il_orgu_authority AS auth ON auth.position_id = orgu_ua.position_id WHERE @@ -518,34 +746,39 @@ public function buildTempTableIlobjectsDefaultPermissionSetForOperationAndContex WHERE perm.parent_id <> -1) );"; - $DIC->database()->manipulate($q); - - return $temporary_table_name; - } - - - /** - * @param string $org_unit_operation_string - * @param string $context - * @param string $temporary_table_name_prefix - * - * @return string - */ - public function buildTempTableIlorgunitDefaultPermissionSetForOperationAndContext($org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, $context = self::DEFAULT_CONTEXT, $temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_ORGU_DEFAULT_PERMISSIONS) { - global $DIC; - - $temporary_table_name = $temporary_table_name_prefix . "_" . $org_unit_operation_string . "_" . $context; - /** - * @var ilOrgUnitOperation $operation - */ - $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context); - - if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_ORGU_DEFAULT_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_" - . self::DEFAULT_CONTEXT) { - $this->dropTempTable($temporary_table_name); - } - - $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . " + $DIC->database()->manipulate($q); + + return $temporary_table_name; + } + + + /** + * @param string $org_unit_operation_string + * @param string $context + * @param string $temporary_table_name_prefix + * + * @return string + */ + public function buildTempTableIlorgunitDefaultPermissionSetForOperationAndContext( + $org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, + $context = self::DEFAULT_CONTEXT, + $temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_ORGU_DEFAULT_PERMISSIONS + ) { + global $DIC; + + $temporary_table_name = $temporary_table_name_prefix . "_" . $org_unit_operation_string . "_" . $context; + /** + * @var ilOrgUnitOperation $operation + */ + $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context); + + if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_ORGU_DEFAULT_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_" + . self::DEFAULT_CONTEXT + ) { + $this->dropTempTable($temporary_table_name); + } + + $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . " (INDEX i1 (perm_for_ref_id), INDEX i2 (perm_for_orgu_id), INDEX i3 (perm_orgu_scope), INDEX i4 (perm_for_position_id), INDEX i5 (perm_over_user_with_position)) AS ( SELECT @@ -557,36 +790,38 @@ public function buildTempTableIlorgunitDefaultPermissionSetForOperationAndContex FROM il_orgu_permissions AS perm INNER JOIN il_orgu_ua AS orgu_ua ON orgu_ua.position_id = perm.position_id AND perm.parent_id = -1 AND orgu_ua.user_id = " - . $GLOBALS['DIC']->user()->getId() . " + . $GLOBALS['DIC']->user()->getId() . " INNER JOIN il_orgu_authority AS auth ON auth.position_id = orgu_ua.position_id INNER JOIN il_orgu_op_contexts AS contexts on contexts.id = perm.context_id AND contexts.context = '" . $context . "' WHERE perm.operations LIKE '%\"" . $operation->getOperationId() . "\"%' );"; - $DIC->database()->manipulate($q); + $DIC->database()->manipulate($q); - return $temporary_table_name; - } + return $temporary_table_name; + } - /** - * @param string $temporary_table_name_prefix - * @param array $only_courses_of_user_ids - * - * @return string - */ - public function buildTempTableCourseMemberships($temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS, array $only_courses_of_user_ids = array()) { - global $DIC; + /** + * @param string $temporary_table_name_prefix + * @param array $only_courses_of_user_ids + * + * @return string + */ + public function buildTempTableCourseMemberships($temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS, array $only_courses_of_user_ids = array()) + { + global $DIC; - $temporary_table_name = $temporary_table_name_prefix . "_user_id_" . $DIC->user()->getId(); + $temporary_table_name = $temporary_table_name_prefix . "_user_id_" . $DIC->user()->getId(); - if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS . "_user_id_" . $DIC->user()->getId() - || count($only_courses_of_user_ids) > 0) { - $this->dropTempTable($temporary_table_name); - } + if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS . "_user_id_" . $DIC->user()->getId() + || count($only_courses_of_user_ids) > 0 + ) { + $this->dropTempTable($temporary_table_name); + } - $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . " + $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . " (INDEX i1(ref_id), INDEX i2 (usr_id), INDEX i3 (position_id), INDEX i4 (orgu_id)) AS ( SELECT crs_members_crs_ref.ref_id, crs_members.usr_id, orgu_ua.position_id, orgu_ua.orgu_id @@ -604,29 +839,31 @@ public function buildTempTableCourseMemberships($temporary_table_name_prefix = s INNER JOIN il_orgu_ua AS orgu_ua on orgu_ua.user_id = crs_members.usr_id );"; - $DIC->database()->manipulate($q); + $DIC->database()->manipulate($q); - return $temporary_table_name; - } + return $temporary_table_name; + } - /** - * @param string $temporary_table_name_prefix - * @param array $only_orgus_of_user_ids - * - * @return string - */ - public function buildTempTableOrguMemberships($temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS, array $only_orgus_of_user_ids = array()) { - global $DIC; + /** + * @param string $temporary_table_name_prefix + * @param array $only_orgus_of_user_ids + * + * @return string + */ + public function buildTempTableOrguMemberships($temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS, array $only_orgus_of_user_ids = array()) + { + global $DIC; - $temporary_table_name = $temporary_table_name_prefix . "_user_id_" . $DIC->user()->getId(); + $temporary_table_name = $temporary_table_name_prefix . "_user_id_" . $DIC->user()->getId(); - if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS . "_user_id_" . $DIC->user()->getId() - || count($only_orgus_of_user_ids) > 0) { - $this->dropTempTable($temporary_table_name); - } + if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS . "_user_id_" . $DIC->user()->getId() + || count($only_orgus_of_user_ids) > 0 + ) { + $this->dropTempTable($temporary_table_name); + } - $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . " + $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . " (INDEX i1(orgu_id), INDEX i2 (tree_path), INDEX i3 (tree_child), INDEX i4 (tree_parent), INDEX i5 (tree_lft), INDEX i6 (tree_rgt), INDEX i7 (user_position_id), INDEX i8 (user_id)) AS ( SELECT orgu_ua.orgu_id AS orgu_id, @@ -642,29 +879,30 @@ public function buildTempTableOrguMemberships($temporary_table_name_prefix = sel INNER JOIN object_reference AS obj_ref on obj_ref.ref_id = orgu_ua.orgu_id AND obj_ref.deleted is null LEFT JOIN tree AS tree_orgu ON tree_orgu.child = orgu_ua.orgu_id"; - if (count($only_orgus_of_user_ids) > 0) { - $q .= " WHERE " . $DIC->database()->in('orgu_ua.user_id', $only_orgus_of_user_ids, false, 'integer') . " "; - } + if (count($only_orgus_of_user_ids) > 0) { + $q .= " WHERE " . $DIC->database()->in('orgu_ua.user_id', $only_orgus_of_user_ids, false, 'integer') . " "; + } - $q .= ");"; + $q .= ");"; - $DIC->database()->manipulate($q); + $DIC->database()->manipulate($q); - return $temporary_table_name; - } + return $temporary_table_name; + } - /** - * @param string $temporary_table_name - * - * @return bool - */ - public function dropTempTable($temporary_table_name) { - global $DIC; + /** + * @param string $temporary_table_name + * + * @return bool + */ + public function dropTempTable($temporary_table_name) + { + global $DIC; - $q = "DROP TABLE IF EXISTS " . $temporary_table_name; - $DIC->database()->manipulate($q); + $q = "DROP TABLE IF EXISTS " . $temporary_table_name; + $DIC->database()->manipulate($q); - return true; - } + return true; + } } diff --git a/Services/MyStaff/classes/class.ilMyStaffGUI.php b/Services/MyStaff/classes/class.ilMyStaffGUI.php index 5426592512ce..6521939986e9 100644 --- a/Services/MyStaff/classes/class.ilMyStaffGUI.php +++ b/Services/MyStaff/classes/class.ilMyStaffGUI.php @@ -1,5 +1,8 @@ addTabs(self::TAB_LIST_COURSES); - $list_course_gui = new ilMStListCoursesGUI(); - $DIC->ctrl()->forwardCommand($list_course_gui); - break; - case strtolower(ilMStShowUserGUI::class): - $list_course_gui = new ilMStShowUserGUI(); - $DIC->ctrl()->forwardCommand($list_course_gui); + $list_gui = new ilMStListCoursesGUI(); + $DIC->ctrl()->forwardCommand($list_gui); break; + case strtolower(ilMStListCertificatesGUI::class): + $this->addTabs(self::TAB_LIST_CERTIFICATES); + $list_gui = new ilMStListCertificatesGUI(); + $DIC->ctrl()->forwardCommand($list_gui); + break; + case strtolower(ilMStListCompetencesGUI::class): + $this->addTabs(self::TAB_LIST_COMPETENCES); + $list_gui = new ilMStListCompetencesGUI($DIC); + $DIC->ctrl()->forwardCommand($list_gui); + break; + case strtolower(ilMStListStudyProgrammesGUI::class): + $list_gui = new ilMStListStudyProgrammesGUI(); + $DIC->ctrl()->forwardCommand($list_gui); + break; + case strtolower(ilMStShowUserGUI::class): + $user_gui = new ilMStShowUserGUI(); + $DIC->ctrl()->forwardCommand($user_gui); + break; default: $this->addTabs(self::TAB_LIST_USERS); - $list_user_gui = new ilMStListUsersGUI(); - $DIC->ctrl()->forwardCommand($list_user_gui); + $list_gui = new ilMStListUsersGUI(); + $DIC->ctrl()->forwardCommand($list_gui); break; } @@ -62,15 +82,32 @@ public function executeCommand() { */ protected function addTabs($active_tab_id) { global $DIC; - - $DIC->tabs()->addTab(self::TAB_LIST_USERS, $DIC->language()->txt('mst_list_users'), $DIC->ctrl()->getLinkTargetByClass(array( - self::class, - ilMStListUsersGUI::class, - ), self::CMD_INDEX)); - $DIC->tabs()->addTab(self::TAB_LIST_COURSES, $DIC->language()->txt('mst_list_courses'), $DIC->ctrl()->getLinkTargetByClass(array( - self::class, - ilMStListCoursesGUI::class, - ), self::CMD_INDEX)); + $access = ilMyStaffAccess::getInstance(); + + if ($access->hasCurrentUserAccessToMyStaff()) { + $DIC->tabs()->addTab(self::TAB_LIST_USERS, $DIC->language()->txt('mst_list_users'), $DIC->ctrl()->getLinkTargetByClass(array( + self::class, + ilMStListUsersGUI::class, + ), self::CMD_INDEX)); + $DIC->tabs()->addTab(self::TAB_LIST_COURSES, $DIC->language()->txt('mst_list_courses'), $DIC->ctrl()->getLinkTargetByClass(array( + self::class, + ilMStListCoursesGUI::class, + ), self::CMD_INDEX)); + } + + if ($access->hasCurrentUserAccessToCertificates()) { + $DIC->tabs()->addTab(self::TAB_LIST_CERTIFICATES, $DIC->language()->txt('mst_list_certificates'), $DIC->ctrl()->getLinkTargetByClass(array( + self::class, + ilMStListCertificatesGUI::class, + ), self::CMD_INDEX)); + } + + if ($access->hasCurrentUserAccessToCompetences()) { + $DIC->tabs()->addTab(self::TAB_LIST_COMPETENCES, $DIC->language()->txt('mst_list_competences'), $DIC->ctrl()->getLinkTargetByClass(array( + self::class, + ilMStListCompetencesGUI::class, + ), self::CMD_INDEX)); + } if ($active_tab_id) { $DIC->tabs()->activateTab($active_tab_id); diff --git a/Services/MyStaff/templates/default/tpl.list_skills_row.html b/Services/MyStaff/templates/default/tpl.list_skills_row.html new file mode 100644 index 000000000000..87540769fd33 --- /dev/null +++ b/Services/MyStaff/templates/default/tpl.list_skills_row.html @@ -0,0 +1,6 @@ + + + {VALUE} + + {ACTIONS} + \ No newline at end of file diff --git a/Services/User/classes/class.ilUserUtil.php b/Services/User/classes/class.ilUserUtil.php index 066d0a80cdd3..c11fecdff746 100755 --- a/Services/User/classes/class.ilUserUtil.php +++ b/Services/User/classes/class.ilUserUtil.php @@ -1,6 +1,8 @@ +<#5649> + \ No newline at end of file