Merge branch 'install_23_STABLE' of git://git.moodle.cz/moodle-install into MOODLE_23...
[moodle.git] / mod / workshop / allocation.php
blob33842a8d6ac7bc05e24c815f821f0cbc4e46b92f
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();
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();