MDL-78544 forms: fix string to number comparison bug in duration element
[moodle.git] / cohort / index.php
blob9b40c5db09cae20afd64a32837eeff74d6a194a5
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.
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/>.
17 /**
18 * Cohort related management functions, this file needs to be included manually.
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
25 use core_cohort\reportbuilder\local\systemreports\cohorts;
26 use core_reportbuilder\local\filters\text;
27 use core_reportbuilder\system_report_factory;
29 require('../config.php');
30 require_once($CFG->dirroot.'/cohort/lib.php');
31 require_once($CFG->libdir.'/adminlib.php');
33 $contextid = optional_param('contextid', 0, PARAM_INT);
34 $searchquery = optional_param('search', '', PARAM_RAW);
35 $showall = optional_param('showall', false, PARAM_BOOL);
37 require_login();
39 if ($contextid) {
40 $context = context::instance_by_id($contextid, MUST_EXIST);
41 } else {
42 $context = context_system::instance();
45 if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
46 throw new \moodle_exception('invalidcontext');
49 $category = null;
50 if ($context->contextlevel == CONTEXT_COURSECAT) {
51 $category = $DB->get_record('course_categories', array('id'=>$context->instanceid), '*', MUST_EXIST);
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);
60 $strcohorts = get_string('cohorts', 'cohort');
62 if ($category) {
63 $PAGE->set_pagelayout('admin');
64 $PAGE->set_context($context);
65 $PAGE->set_url('/cohort/index.php', array('contextid'=>$context->id));
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();
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);
88 echo $OUTPUT->header();
89 echo $OUTPUT->heading($strallcohorts ?? $strsystemcohorts ?? $strcohorts);
91 $params = [];
92 if ($contextid) {
93 $params['contextid'] = $contextid;
95 if ($searchquery) {
96 $params['search'] = $searchquery;
98 if ($showall) {
99 $params['showall'] = true;
101 $baseurl = new moodle_url('/cohort/index.php', $params);
103 if ($editcontrols = cohort_edit_controls($context, $baseurl)) {
104 echo $OUTPUT->render($editcontrols);
107 $reportparams = ['contextid' => $context->id, 'showall' => $showall];
108 $report = system_report_factory::create(cohorts::class, $context, '', '', 0, $reportparams);
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,
118 echo $report->output();
119 echo $OUTPUT->footer();