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
|
|
|
|
*/
|
|
|
|
|
|
|
|
require('../config.php');
|
2011-10-07 12:35:10 +01:00
|
|
|
require($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
|
|
|
$page = optional_param('page', 0, PARAM_INT);
|
|
|
|
$searchquery = optional_param('search', '', PARAM_RAW);
|
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) {
|
|
|
|
print_error('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);
|
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));
|
|
|
|
$PAGE->set_title($strcohorts);
|
2010-05-27 09:33:46 +00:00
|
|
|
$PAGE->set_heading($COURSE->fullname);
|
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'));
|
2010-04-23 09:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo $OUTPUT->header();
|
|
|
|
|
2012-09-16 21:56:27 +02:00
|
|
|
$cohorts = cohort_get_cohorts($context->id, $page, 25, $searchquery);
|
|
|
|
|
|
|
|
$count = '';
|
|
|
|
if ($cohorts['allcohorts'] > 0) {
|
|
|
|
if ($searchquery === '') {
|
|
|
|
$count = ' ('.$cohorts['allcohorts'].')';
|
|
|
|
} else {
|
|
|
|
$count = ' ('.$cohorts['totalcohorts'].'/'.$cohorts['allcohorts'].')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $OUTPUT->heading(get_string('cohortsin', 'cohort', $context->get_context_name()).$count);
|
2010-04-23 09:07:51 +00:00
|
|
|
|
2012-09-16 21:38:28 +02:00
|
|
|
// Add search form.
|
2011-10-07 12:35:10 +01:00
|
|
|
$search = html_writer::start_tag('form', array('id'=>'searchcohortquery', 'method'=>'get'));
|
|
|
|
$search .= html_writer::start_tag('div');
|
2012-09-16 21:38:28 +02:00
|
|
|
$search .= html_writer::label(get_string('searchcohort', 'cohort'), 'cohort_search_q'); // No : in form labels!
|
2011-10-07 12:35:10 +01:00
|
|
|
$search .= html_writer::empty_tag('input', array('id'=>'cohort_search_q', 'type'=>'text', 'name'=>'search', 'value'=>$searchquery));
|
|
|
|
$search .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('search', 'cohort')));
|
2013-06-07 22:07:15 +02:00
|
|
|
$search .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'contextid', 'value'=>$contextid));
|
2011-10-07 12:35:10 +01:00
|
|
|
$search .= html_writer::end_tag('div');
|
|
|
|
$search .= html_writer::end_tag('form');
|
|
|
|
echo $search;
|
|
|
|
|
|
|
|
|
2012-09-16 21:38:28 +02:00
|
|
|
// Output pagination bar.
|
2011-10-07 12:35:10 +01:00
|
|
|
$params = array('page' => $page);
|
|
|
|
if ($contextid) {
|
|
|
|
$params['contextid'] = $contextid;
|
|
|
|
}
|
|
|
|
if ($search) {
|
|
|
|
$params['search'] = $searchquery;
|
|
|
|
}
|
|
|
|
$baseurl = new moodle_url('/cohort/index.php', $params);
|
|
|
|
echo $OUTPUT->paging_bar($cohorts['totalcohorts'], $page, 25, $baseurl);
|
2010-04-23 09:07:51 +00:00
|
|
|
|
|
|
|
$data = array();
|
2011-10-07 12:35:10 +01:00
|
|
|
foreach($cohorts['cohorts'] as $cohort) {
|
2010-04-23 09:07:51 +00:00
|
|
|
$line = array();
|
|
|
|
$line[] = format_string($cohort->name);
|
2012-09-16 21:38:28 +02:00
|
|
|
$line[] = s($cohort->idnumber); // All idnumbers are plain text.
|
2010-04-23 09:07:51 +00:00
|
|
|
$line[] = format_text($cohort->description, $cohort->descriptionformat);
|
|
|
|
|
|
|
|
$line[] = $DB->count_records('cohort_members', array('cohortid'=>$cohort->id));
|
|
|
|
|
|
|
|
if (empty($cohort->component)) {
|
|
|
|
$line[] = get_string('nocomponent', 'cohort');
|
|
|
|
} else {
|
|
|
|
$line[] = get_string('pluginname', $cohort->component);
|
|
|
|
}
|
|
|
|
|
2011-08-05 21:43:29 +02:00
|
|
|
$buttons = array();
|
|
|
|
if (empty($cohort->component)) {
|
|
|
|
if ($manager) {
|
|
|
|
$buttons[] = html_writer::link(new moodle_url('/cohort/edit.php', array('id'=>$cohort->id, 'delete'=>1)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/delete'), 'alt'=>get_string('delete'), 'class'=>'iconsmall')));
|
|
|
|
$buttons[] = html_writer::link(new moodle_url('/cohort/edit.php', array('id'=>$cohort->id)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/edit'), 'alt'=>get_string('edit'), 'class'=>'iconsmall')));
|
|
|
|
}
|
|
|
|
if ($manager or $canassign) {
|
|
|
|
$buttons[] = html_writer::link(new moodle_url('/cohort/assign.php', array('id'=>$cohort->id)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('i/users'), 'alt'=>get_string('assign', 'core_cohort'), 'class'=>'iconsmall')));
|
2010-04-23 09:07:51 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-05 21:43:29 +02:00
|
|
|
$line[] = implode(' ', $buttons);
|
2010-04-23 09:07:51 +00:00
|
|
|
|
|
|
|
$data[] = $line;
|
|
|
|
}
|
|
|
|
$table = new html_table();
|
|
|
|
$table->head = array(get_string('name', 'cohort'), get_string('idnumber', 'cohort'), get_string('description', 'cohort'),
|
|
|
|
get_string('memberscount', 'cohort'), get_string('component', 'cohort'), get_string('edit'));
|
2013-01-07 17:14:43 +08:00
|
|
|
$table->colclasses = array('leftalign name', 'leftalign id', 'leftalign description', 'leftalign size','centeralign source', 'centeralign action');
|
|
|
|
$table->id = 'cohorts';
|
|
|
|
$table->attributes['class'] = 'admintable generaltable';
|
2010-04-23 09:07:51 +00:00
|
|
|
$table->data = $data;
|
|
|
|
echo html_writer::table($table);
|
2011-10-07 12:35:10 +01:00
|
|
|
echo $OUTPUT->paging_bar($cohorts['totalcohorts'], $page, 25, $baseurl);
|
2010-04-23 09:07:51 +00:00
|
|
|
|
|
|
|
if ($manager) {
|
|
|
|
echo $OUTPUT->single_button(new moodle_url('/cohort/edit.php', array('contextid'=>$context->id)), get_string('add'));
|
|
|
|
}
|
|
|
|
|
2012-09-16 21:38:28 +02:00
|
|
|
echo $OUTPUT->footer();
|