Merge branch 'MDL-42411-master' of git://github.com/damyon/moodle
[moodle.git] / mod / workshop / allocation.php
blobec7a8922789ff3ac4169ea4695b0ac5b65b24cf1
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
25 * @subpackage workshop
26 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
31 require_once(dirname(__FILE__).'/locallib.php');
32 require_once(dirname(__FILE__).'/allocation/lib.php');
34 $cmid = required_param('cmid', PARAM_INT); // course module
35 $method = optional_param('method', 'manual', PARAM_ALPHA); // method to use
37 $cm = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST);
38 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
39 $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
40 $workshop = new workshop($workshop, $cm, $course);
42 $PAGE->set_url($workshop->allocation_url($method));
44 require_login($course, false, $cm);
45 $context = $PAGE->context;
46 require_capability('mod/workshop:allocate', $context);
48 $PAGE->set_title($workshop->name);
49 $PAGE->set_heading($course->fullname);
50 $PAGE->navbar->add(get_string('allocation', 'workshop'));
52 $allocator = $workshop->allocator_instance($method);
53 $initresult = $allocator->init();
56 // Output starts here
58 $output = $PAGE->get_renderer('mod_workshop');
59 echo $output->header();
60 echo $OUTPUT->heading(format_string($workshop->name));
62 $allocators = workshop::installed_allocators();
63 if (!empty($allocators)) {
64 $tabs = array();
65 $row = array();
66 $inactive = array();
67 $activated = array();
68 foreach ($allocators as $methodid => $methodname) {
69 $row[] = new tabobject($methodid, $workshop->allocation_url($methodid)->out(), $methodname);
70 if ($methodid == $method) {
71 $currenttab = $methodid;
75 $tabs[] = $row;
76 print_tabs($tabs, $currenttab, $inactive, $activated);
78 if (is_null($initresult->get_status()) or $initresult->get_status() == workshop_allocation_result::STATUS_VOID) {
79 echo $output->container_start('allocator-ui');
80 echo $allocator->ui();
81 echo $output->container_end();
82 } else {
83 echo $output->container_start('allocator-init-results');
84 echo $output->render($initresult);
85 echo $output->continue_button($workshop->allocation_url($method));
86 echo $output->container_end();
88 echo $output->footer();