2010-04-23 09:07:51 +00:00
|
|
|
<?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.
|
|
|
|
*
|
2012-09-16 21:38:28 +02:00
|
|
|
* @package core_cohort
|
2010-09-17 11:51:49 +00:00
|
|
|
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
2010-04-23 09:07:51 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2021-11-23 13:18:40 +01:00
|
|
|
use core_cohort\reportbuilder\local\systemreports\cohorts;
|
|
|
|
use core_reportbuilder\local\filters\text;
|
|
|
|
use core_reportbuilder\system_report_factory;
|
|
|
|
|
2010-04-23 09:07:51 +00:00
|
|
|
require('../config.php');
|
2018-01-18 11:54:28 +00:00
|
|
|
require_once($CFG->dirroot.'/cohort/lib.php');
|
2010-04-23 09:13:19 +00:00
|
|
|
require_once($CFG->libdir.'/adminlib.php');
|
2010-04-23 09:07:51 +00:00
|
|
|
|
|
|
|
$contextid = optional_param('contextid', 0, PARAM_INT);
|
2011-10-07 12:35:10 +01:00
|
|
|
$searchquery = optional_param('search', '', PARAM_RAW);
|
2014-07-22 17:05:06 +08:00
|
|
|
$showall = optional_param('showall', false, PARAM_BOOL);
|
2010-04-23 09:07:51 +00:00
|
|
|
|
|
|
|
require_login();
|
|
|
|
|
|
|
|
if ($contextid) {
|
2012-08-21 14:20:30 +08:00
|
|
|
$context = context::instance_by_id($contextid, MUST_EXIST);
|
2010-04-23 09:07:51 +00:00
|
|
|
} else {
|
2012-07-23 16:22:36 +08:00
|
|
|
$context = context_system::instance();
|
2010-04-23 09:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('invalidcontext');
|
2010-04-23 09:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$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);
|
2011-08-05 21:43:29 +02:00
|
|
|
$canassign = has_capability('moodle/cohort:assign', $context);
|
2010-04-23 09:07:51 +00:00
|
|
|
if (!$manager) {
|
|
|
|
require_capability('moodle/cohort:view', $context);
|
|
|
|
}
|
|
|
|
|
|
|
|
$strcohorts = get_string('cohorts', 'cohort');
|
|
|
|
|
2010-08-17 13:05:33 +00:00
|
|
|
if ($category) {
|
2013-10-19 12:22:12 +02:00
|
|
|
$PAGE->set_pagelayout('admin');
|
2010-04-23 10:39:47 +00:00
|
|
|
$PAGE->set_context($context);
|
2010-04-23 09:13:19 +00:00
|
|
|
$PAGE->set_url('/cohort/index.php', array('contextid'=>$context->id));
|
2022-02-22 12:05:07 +08:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2010-04-23 09:13:19 +00:00
|
|
|
$PAGE->set_title($strcohorts);
|
2014-07-22 17:05:06 +08:00
|
|
|
$showall = false;
|
2010-04-23 09:13:19 +00:00
|
|
|
} else {
|
2010-11-05 02:53:47 +00:00
|
|
|
admin_externalpage_setup('cohorts', '', null, '', array('pagelayout'=>'report'));
|
2022-03-21 14:21:57 +00:00
|
|
|
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 {
|
2021-11-23 13:18:40 +01:00
|
|
|
$strsystemcohorts = get_string('systemcohorts', 'cohort');
|
|
|
|
$PAGE->set_title($strsystemcohorts);
|
2022-02-24 12:53:46 +05:30
|
|
|
}
|
2010-04-23 09:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo $OUTPUT->header();
|
2021-11-23 13:18:40 +01:00
|
|
|
echo $OUTPUT->heading($strallcohorts ?? $strsystemcohorts ?? $strcohorts);
|
2010-04-23 09:07:51 +00:00
|
|
|
|
2021-11-23 13:18:40 +01:00
|
|
|
$params = [];
|
2014-07-22 17:05:06 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-11-23 13:18:40 +01:00
|
|
|
$reportparams = ['contextid' => $context->id, 'showall' => $showall];
|
|
|
|
$report = system_report_factory::create(cohorts::class, $context, '', '', 0, $reportparams);
|
2010-04-23 09:07:51 +00:00
|
|
|
|
2021-11-23 13:18:40 +01:00
|
|
|
// Check if it needs to search by name.
|
|
|
|
if (!empty($searchquery)) {
|
|
|
|
$report->set_filter_values([
|
|
|
|
'cohort:name_operator' => text::CONTAINS,
|
|
|
|
'cohort:name_value' => $searchquery,
|
|
|
|
]);
|
2010-04-23 09:07:51 +00:00
|
|
|
}
|
2021-11-23 13:18:40 +01:00
|
|
|
|
|
|
|
echo $report->output();
|
2012-09-16 21:38:28 +02:00
|
|
|
echo $OUTPUT->footer();
|