Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Cohort related management functions, this file needs to be included manually. 19 * 20 * @package core_cohort 21 * @copyright 2010 Petr Skoda {@link http://skodak.org} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 use core_cohort\reportbuilder\local\systemreports\cohorts; 26 use core_reportbuilder\local\filters\text; 27 use core_reportbuilder\system_report_factory; 28 29 require('../config.php'); 30 require_once($CFG->dirroot.'/cohort/lib.php'); 31 require_once($CFG->libdir.'/adminlib.php'); 32 33 $contextid = optional_param('contextid', 0, PARAM_INT); 34 $searchquery = optional_param('search', '', PARAM_RAW); 35 $showall = optional_param('showall', false, PARAM_BOOL); 36 37 require_login(); 38 39 if ($contextid) { 40 $context = context::instance_by_id($contextid, MUST_EXIST); 41 } else { 42 $context = context_system::instance(); 43 } 44 45 if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) { 46 throw new \moodle_exception('invalidcontext'); 47 } 48 49 $category = null; 50 if ($context->contextlevel == CONTEXT_COURSECAT) { 51 $category = $DB->get_record('course_categories', array('id'=>$context->instanceid), '*', MUST_EXIST); 52 } 53 54 $manager = has_capability('moodle/cohort:manage', $context); 55 $canassign = has_capability('moodle/cohort:assign', $context); 56 if (!$manager) { 57 require_capability('moodle/cohort:view', $context); 58 } 59 60 $strcohorts = get_string('cohorts', 'cohort'); 61 62 if ($category) { 63 $PAGE->set_pagelayout('admin'); 64 $PAGE->set_context($context); 65 $PAGE->set_url('/cohort/index.php', array('contextid'=>$context->id)); 66 67 core_course_category::page_setup(); 68 // Set the cohorts node active in the settings navigation block. 69 if ($cohortsnode = $PAGE->settingsnav->find('cohort', navigation_node::TYPE_SETTING)) { 70 $cohortsnode->make_active(); 71 } 72 73 $PAGE->set_title($strcohorts); 74 $showall = false; 75 } else { 76 admin_externalpage_setup('cohorts', '', null, '', array('pagelayout'=>'report')); 77 navigation_node::override_active_url(new moodle_url('/cohort/index.php')); 78 if ($showall) { 79 $strallcohorts = get_string('allcohorts', 'cohort'); 80 $PAGE->set_title($strallcohorts); 81 $PAGE->navbar->add($strallcohorts, $PAGE->url); 82 } else { 83 $strsystemcohorts = get_string('systemcohorts', 'cohort'); 84 $PAGE->set_title($strsystemcohorts); 85 } 86 } 87 88 echo $OUTPUT->header(); 89 echo $OUTPUT->heading($strallcohorts ?? $strsystemcohorts ?? $strcohorts); 90 91 $params = []; 92 if ($contextid) { 93 $params['contextid'] = $contextid; 94 } 95 if ($searchquery) { 96 $params['search'] = $searchquery; 97 } 98 if ($showall) { 99 $params['showall'] = true; 100 } 101 $baseurl = new moodle_url('/cohort/index.php', $params); 102 103 if ($editcontrols = cohort_edit_controls($context, $baseurl)) { 104 echo $OUTPUT->render($editcontrols); 105 } 106 107 $reportparams = ['contextid' => $context->id, 'showall' => $showall]; 108 $report = system_report_factory::create(cohorts::class, $context, '', '', 0, $reportparams); 109 110 // Check if it needs to search by name. 111 if (!empty($searchquery)) { 112 $report->set_filter_values([ 113 'cohort:name_operator' => text::CONTAINS, 114 'cohort:name_value' => $searchquery, 115 ]); 116 } 117 118 echo $report->output(); 119 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body