index.php 4.07 KB
Newer Older
Petr Skoda's avatar
Petr Skoda committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?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.
 *
21
 * @package    core
Petr Skoda's avatar
Petr Skoda committed
22
 * @subpackage cohort
23
 * @copyright  2010 Petr Skoda  {@link http://skodak.org}
Petr Skoda's avatar
Petr Skoda committed
24
25
26
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

require('../config.php');
28
require_once($CFG->libdir.'/adminlib.php');
Petr Skoda's avatar
Petr Skoda committed
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

$contextid = optional_param('contextid', 0, PARAM_INT);

require_login();

if ($contextid) {
    $context = get_context_instance_by_id($contextid, MUST_EXIST);
} else {
    $context = get_context_instance(CONTEXT_SYSTEM);
}

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);
if (!$manager) {
    require_capability('moodle/cohort:view', $context);
}

$strcohorts = get_string('cohorts', 'cohort');

56
if ($category) {
57
    $PAGE->set_pagelayout('report');
58
    $PAGE->set_context($context);
59
60
    $PAGE->set_url('/cohort/index.php', array('contextid'=>$context->id));
    $PAGE->set_title($strcohorts);
Rossiani Wijaya's avatar
Rossiani Wijaya committed
61
    $PAGE->set_heading($COURSE->fullname);
Petr Skoda's avatar
Petr Skoda committed
62
    $PAGE->navbar->add($category->name, new moodle_url('/course/index.php', array('categoryedit'=>'1')));
63
64
    $PAGE->navbar->add($strcohorts);
} else {
65
    admin_externalpage_setup('cohorts', '', null, '', array('pagelayout'=>'report'));
Petr Skoda's avatar
Petr Skoda committed
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
}

echo $OUTPUT->header();

echo $OUTPUT->heading(get_string('cohortsin', 'cohort', print_context_name($context)));

$cohorts = $DB->get_records('cohort', array('contextid'=>$context->id));

$data = array();
foreach($cohorts as $cohort) {
    $line = array();
    $line[] = format_string($cohort->name);
    $line[] = $cohort->idnumber;
    $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);
    }

    if ($manager) {
        if (empty($cohort->component)) {
            $buttons = html_writer::link(new moodle_url('/cohort/edit.php', array('id'=>$cohort->id)), get_string('edit'));
            $buttons .= ' '.html_writer::link(new moodle_url('/cohort/edit.php', array('id'=>$cohort->id, 'delete'=>1)), get_string('delete'));
            $buttons .= ' '.html_writer::link(new moodle_url('/cohort/assign.php', array('id'=>$cohort->id)), get_string('assign', 'cohort'));
        } else {
            $buttons = '';
        }
    } else {
        $buttons = '';
    }
    $line[] = $buttons;

    $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'));
$table->size  = array('20%', '10%', '40%', '10%', '10%', '10%');
$table->align = array('left', 'left', 'left', 'left','center', 'center');
$table->width = '80%';
$table->data  = $data;
echo html_writer::table($table);

if ($manager) {
    echo $OUTPUT->single_button(new moodle_url('/cohort/edit.php', array('contextid'=>$context->id)), get_string('add'));
}

echo $OUTPUT->footer();