forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
119 lines (100 loc) · 3.84 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?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/>.
/**
* Cohort related management functions, this file needs to be included manually.
*
* @package core_cohort
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use core_cohort\reportbuilder\local\systemreports\cohorts;
use core_reportbuilder\local\filters\text;
use core_reportbuilder\system_report_factory;
require('../config.php');
require_once($CFG->dirroot.'/cohort/lib.php');
require_once($CFG->libdir.'/adminlib.php');
$contextid = optional_param('contextid', 0, PARAM_INT);
$searchquery = optional_param('search', '', PARAM_RAW);
$showall = optional_param('showall', false, PARAM_BOOL);
require_login();
if ($contextid) {
$context = context::instance_by_id($contextid, MUST_EXIST);
} else {
$context = context_system::instance();
}
if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
throw new \moodle_exception('invalidcontext');
}
$category = null;
if ($context->contextlevel == CONTEXT_COURSECAT) {
$category = $DB->get_record('course_categories', array('id'=>$context->instanceid), '*', MUST_EXIST);
}
$manager = has_capability('moodle/cohort:manage', $context);
$canassign = has_capability('moodle/cohort:assign', $context);
if (!$manager) {
require_capability('moodle/cohort:view', $context);
}
$strcohorts = get_string('cohorts', 'cohort');
if ($category) {
$PAGE->set_pagelayout('admin');
$PAGE->set_context($context);
$PAGE->set_url('/cohort/index.php', array('contextid'=>$context->id));
core_course_category::page_setup();
// Set the cohorts node active in the settings navigation block.
if ($cohortsnode = $PAGE->settingsnav->find('cohort', navigation_node::TYPE_SETTING)) {
$cohortsnode->make_active();
}
$PAGE->set_title($strcohorts);
$showall = false;
} else {
admin_externalpage_setup('cohorts', '', null, '', array('pagelayout'=>'report'));
navigation_node::override_active_url(new moodle_url('/cohort/index.php'));
if ($showall) {
$strallcohorts = get_string('allcohorts', 'cohort');
$PAGE->set_title($strallcohorts);
$PAGE->navbar->add($strallcohorts, $PAGE->url);
} else {
$strsystemcohorts = get_string('systemcohorts', 'cohort');
$PAGE->set_title($strsystemcohorts);
}
}
echo $OUTPUT->header();
echo $OUTPUT->heading($strallcohorts ?? $strsystemcohorts ?? $strcohorts);
$params = [];
if ($contextid) {
$params['contextid'] = $contextid;
}
if ($searchquery) {
$params['search'] = $searchquery;
}
if ($showall) {
$params['showall'] = true;
}
$baseurl = new moodle_url('/cohort/index.php', $params);
if ($editcontrols = cohort_edit_controls($context, $baseurl)) {
echo $OUTPUT->render($editcontrols);
}
$reportparams = ['contextid' => $context->id, 'showall' => $showall];
$report = system_report_factory::create(cohorts::class, $context, '', '', 0, $reportparams);
// Check if it needs to search by name.
if (!empty($searchquery)) {
$report->set_filter_values([
'cohort:name_operator' => text::CONTAINS,
'cohort:name_value' => $searchquery,
]);
}
echo $report->output();
echo $OUTPUT->footer();