Skip to content

Commit

Permalink
yurinskiy#6: Add capability to view cohort details on profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
djarran committed Feb 5, 2024
1 parent c469175 commit 0b96bef
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
37 changes: 37 additions & 0 deletions db/access.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Version details.
*
* @package local_cohort_profile
* @copyright 2024, Yuriy Yurinskiy <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die;

$capabilities = array(
'local/cohort_profile:view_cohort_list' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_USER,
'archetypes' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
),
),
);
14 changes: 12 additions & 2 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* This file contains the code for the plugin integration.
*
* @package local_cohort_profile
* @copyright 2019, Yuriy Yurinskiy <[email protected]>
* @copyright 2024, Yuriy Yurinskiy <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand All @@ -39,9 +39,19 @@
* @return void
*/
function local_cohort_profile_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {
global $CFG, $DB;
global $CFG, $DB, $USER;
require_once($CFG->dirroot . '/cohort/lib.php');

$context = context_user::instance($user->id);

$hascapability = has_capability('local/cohort_profile:view_cohort_list', $context);
$ownprofile = $user->id == $USER->id;

# Don't show if user doesn't have capability or is not viewing their own profile
if (!$hascapability && !$ownprofile) {
return;
}

$showallcohorts = optional_param('showallcohorts', 0, PARAM_INT);

$sql = 'SELECT %s FROM {cohort} c
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die;

$plugin->version = 2020022200;
$plugin->version = 2020022201;
$plugin->requires = 2018120300;
$plugin->component = 'local_cohort_profile';
$plugin->maturity = MATURITY_STABLE;
Expand Down

0 comments on commit 0b96bef

Please sign in to comment.