Merge branch 'MDL-76652-311' of https://github.com/lameze/moodle into MOODLE_311_STABLE
[moodle.git] / mod / workshop / allocation.php
blob5901bcff70302e6764d6671e02e4153b72ab34e7
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * At this page, teachers allocate submissions to students for a review
21 * The allocation logic itself is delegated to allocators - subplugins in ./allocation
22 * folder.
24 * @package mod_workshop
25 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 require(__DIR__.'/../../config.php');
30 require_once(__DIR__.'/locallib.php');
31 require_once(__DIR__.'/allocation/lib.php');
33 $cmid = required_param('cmid', PARAM_INT); // course module
34 $method = optional_param('method', 'manual', PARAM_ALPHA); // method to use
36 $cm = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST);
37 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
38 $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
39 $workshop = new workshop($workshop, $cm, $course);
41 $PAGE->set_url($workshop->allocation_url($method));
43 require_login($course, false, $cm);
44 $context = $PAGE->context;
45 require_capability('mod/workshop:allocate', $context);
47 $PAGE->set_title($workshop->name);
48 $PAGE->set_heading($course->fullname);
49 $PAGE->navbar->add(get_string('allocation', 'workshop'));
51 $allocator = $workshop->allocator_instance($method);
52 $initresult = $allocator->init();
55 // Output starts here
57 $output = $PAGE->get_renderer('mod_workshop');
58 echo $output->header();
59 echo $OUTPUT->heading(format_string($workshop->name));
61 $allocators = workshop::installed_allocators();
62 if (!empty($allocators)) {
63 $tabs = array();
64 $row = array();
65 $inactive = array();
66 $activated = array();
67 foreach ($allocators as $methodid => $methodname) {
68 $row[] = new tabobject($methodid, $workshop->allocation_url($methodid)->out(), $methodname);
69 if ($methodid == $method) {
70 $currenttab = $methodid;
74 $tabs[] = $row;
75 print_tabs($tabs, $currenttab, $inactive, $activated);
77 if (is_null($initresult->get_status()) or $initresult->get_status() == workshop_allocation_result::STATUS_VOID) {
78 echo $output->container_start('allocator-ui');
79 echo $allocator->ui();
80 echo $output->container_end();
81 } else {
82 echo $output->container_start('allocator-init-results');
83 echo $output->render($initresult);
84 echo $output->continue_button($workshop->allocation_url($method));
85 echo $output->container_end();
87 echo $output->footer();