MDL-32235 introducing new workshop scheduled allocation plugin

The idea is to build a plugin that will internally call the random
allocator when the submissions deadline is reached. The teacher is able
to pre-define the configuration for the random allocator.
This commit is contained in:
David Mudrak 2012-03-29 12:05:09 +02:00
parent b7cd6736e8
commit 9862128087
9 changed files with 303 additions and 9 deletions

View File

@ -516,7 +516,7 @@ class plugin_manager {
),
'workshopallocation' => array(
'manual', 'random'
'manual', 'random', 'scheduled'
),
'workshopeval' => array(

View File

@ -85,10 +85,8 @@ class workshop_allocation_result implements renderable {
const STATUS_EXECUTED = 1;
/** a serious error has occurred during the allocation (as a hole) */
const STATUS_FAILED = 2;
/** scheduled allocation was configured to be executed later */
const STATUS_SCHEDULED_ON = 3;
/** scheduled allocation was disabled */
const STATUS_SCHEDULED_OFF = 4;
/** scheduled allocation was configured (to be executed later, for example) */
const STATUS_CONFIGURED = 3;
/** @var workshop_allocator the instance of the allocator that produced this result */
protected $allocator;

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/workshop/allocation/scheduled/db" VERSION="20120328" COMMENT="XMLDB file for Moodle mod/workshop/allocation/scheduled"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="scheduled" COMMENT="Default comment for scheduled, please edit me" NEXT="workshopallocation_scheduled">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="workshopallocation_scheduled" COMMENT="Stores the allocation settings for the scheduled allocator" PREVIOUS="scheduled">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="workshopid"/>
<FIELD NAME="workshopid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="workshop id we are part of" PREVIOUS="id" NEXT="enabled"/>
<FIELD NAME="enabled" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Is the scheduled allocation enabled" PREVIOUS="workshopid" NEXT="submissionend"/>
<FIELD NAME="submissionend" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="What was the workshop's submissionend when this record was created or modified" PREVIOUS="enabled" NEXT="timeallocated"/>
<FIELD NAME="timeallocated" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="When was the last scheduled allocation executed" PREVIOUS="submissionend" NEXT="settings"/>
<FIELD NAME="settings" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The pre-defined settings for the underlying random allocation to run it with" PREVIOUS="timeallocated"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="fkuq_workshopid"/>
<KEY NAME="fkuq_workshopid" TYPE="foreign-unique" FIELDS="workshopid" REFTABLE="workshop" REFFIELDS="id" COMMENT="Max one record for each workshop" PREVIOUS="primary"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>

View File

@ -0,0 +1,40 @@
<?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/>.
/**
* Strings for the Workshop's scheduled allocator
*
* @package workshopallocation_scheduled
* @subpackage mod_workshop
* @copyright 2012 David Mudrak <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$string['enablescheduled'] = 'Enable scheduled allocation';
$string['enablescheduledinfo'] = 'Automatically allocate submissions after the deadline';
$string['scheduledsettings'] = 'Scheduled allocation settings';
$string['scheduledsettings_help'] = 'If enabled, the scheduled allocation method will automatically allocate submissions for the assessment at the end of the submission phase. The end of the phase can be defined in the workshop setting \'Submissions deadline\'.
Internally, the random allocation method is executed with the parameters pre-defined in this form. It means that the scheduled allocation works as if the teacher executed the random allocation themselves at the end of the submission phase using the allocation settings below.
Note that the scheduled allocation is *not* executed if you manually switch the workshop into the assessment phase before the submissions deadline. You have to allocate submissions yourself in that case. The scheduled allocation method is particularly useful when used together with the automatic phase switching feature.';
$string['nosubmissionend'] = 'You have to define the submissions deadline in the workshop settings in order to use scheduled allocation. Press the \'Continue\' button to edit the workshop settings.';
$string['pluginname'] = 'Scheduled allocation';
$string['resultdisabled'] = 'Scheduled allocation was disabled';
$string['resultenabled'] = 'Scheduled allocation was enabled';

View File

@ -0,0 +1,137 @@
<?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/>.
/**
* Scheduled allocator that internally executes the random allocation later
*
* @package workshopallocation_scheduled
* @subpackage mod_workshop
* @copyright 2012 David Mudrak <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once(dirname(dirname(__FILE__)) . '/lib.php'); // interface definition
require_once(dirname(dirname(dirname(__FILE__))) . '/locallib.php'); // workshop internal API
require_once(dirname(dirname(__FILE__)) . '/random/lib.php'); // random allocator
require_once(dirname(__FILE__) . '/settings_form.php'); // our settings form
/**
* Allocates the submissions randomly in a cronjob task
*/
class workshop_scheduled_allocator implements workshop_allocator {
/** workshop instance */
protected $workshop;
/** workshop_scheduled_allocator_form with settings for the random allocator */
protected $mform;
/**
* @param workshop $workshop Workshop API object
*/
public function __construct(workshop $workshop) {
$this->workshop = $workshop;
}
/**
* Save the settings for the random allocator to execute it later
*/
public function init() {
global $PAGE;
$result = new workshop_allocation_result($this);
$customdata = array();
$customdata['workshop'] = $this->workshop;
$this->mform = new workshop_scheduled_allocator_form($PAGE->url, $customdata);
if ($this->mform->is_cancelled()) {
redirect($PAGE->url->out(false));
} else if ($settings = $this->mform->get_data()) {
if (empty($settings->enablescheduled)) {
$enabled = false;
} else {
$enabled = true;
}
$settings = workshop_random_allocator_setting::instance_from_object($settings);
$this->store_settings($enabled, $settings, $result);
if ($enabled) {
$msg = get_string('resultenabled', 'workshopallocation_scheduled');
} else {
$msg = get_string('resultdisabled', 'workshopallocation_scheduled');
}
$result->set_status(workshop_allocation_result::STATUS_CONFIGURED, $msg);
return $result;
} else {
// this branch is executed if the form is submitted but the data
// doesn't validate and the form should be redisplayed
// or on the first display of the form.
$result->set_status(workshop_allocation_result::STATUS_VOID);
return $result;
}
}
/**
* Returns the HTML code to print the user interface
*/
public function ui() {
global $PAGE;
$output = $PAGE->get_renderer('mod_workshop');
// the submissions deadline must be defined
if (empty($this->workshop->submissionend)) {
$out = $output->box(get_string('nosubmissionend', 'workshopallocation_scheduled'), 'generalbox', 'notice');
$out .= $output->continue_button($this->workshop->updatemod_url());
return $out;
}
$out = $output->container_start('scheduled-allocator');
// the nasty hack follows to bypass the sad fact that moodle quickforms do not allow to actually
// return the HTML content, just to display it
ob_start();
$this->mform->display();
$out .= ob_get_contents();
ob_end_clean();
$out .= $output->container_end();
return $out;
}
/**
* Delete all data related to a given workshop module instance
*
* @see workshop_delete_instance()
* @param int $workshopid id of the workshop module instance being deleted
* @return void
*/
public static function delete_instance($workshopid) {
// TODO
return;
}
/**
* Stores the pre-defined random allocation settings for later usage
*
* @param bool $enabled is the scheduled allocation enabled
* @param workshop_random_allocator_setting $settings settings form data
* @param workshop_allocation_result $result logger
*/
protected function store_settings($enabled, workshop_random_allocator_setting $settings, workshop_allocation_result $result) {
$result->log(print_r($settings, true), 'debug');
}
}

View File

@ -0,0 +1,55 @@
<?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/>.
/**
* Scheduled allocator's settings
*
* @package workshopallocation_scheduled
* @subpackage mod_workshop
* @copyright 2012 David Mudrak <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/lib/formslib.php');
require_once(dirname(dirname(__FILE__)) . '/random/settings_form.php'); // parent form
/**
* Allocator settings form
*
* This is used by {@see workshop_scheduled_allocator::ui()} to set up allocation parameters.
*/
class workshop_scheduled_allocator_form extends workshop_random_allocator_form {
/**
* Definition of the setting form elements
*/
public function definition() {
$mform = $this->_form;
$workshop = $this->_customdata['workshop'];
$mform->addElement('header', 'scheduledsettings', get_string('pluginname', 'workshopallocation_scheduled'));
$mform->addHelpButton('scheduledsettings', 'scheduledsettings', 'workshopallocation_scheduled');
$mform->addElement('static', 'submissionendinfo', get_string('submissionend', 'workshop'),
workshop::timestamp_formats($workshop->submissionend)->datetime);
$mform->addElement('checkbox', 'enablescheduled', get_string('enablescheduled', 'workshopallocation_scheduled'), get_string('enablescheduledinfo', 'workshopallocation_scheduled'), 1);
parent::definition();
}
}

View File

@ -0,0 +1,35 @@
<?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/>.
/**
* Scheduled allocator that internally executes the random one
*
* @package workshopallocation_scheduled
* @subpackage mod_workshop
* @copyright 2012 David Mudrak <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'workshopallocation_scheduled';
$plugin->version = 2012032801;
$plugin->requires = 2012032300;
$plugin->dependencies = array(
'workshopallocation_random' => 2012032800,
);
$plugin->maturity = MATURITY_ALPHA;

View File

@ -32,7 +32,7 @@ $string['allocatedetails'] = 'expected: {$a->expected}<br />submitted: {$a->subm
$string['allocation'] = 'Submission allocation';
$string['allocationdone'] = 'Allocation done';
$string['allocationerror'] = 'Allocation error';
$string['allocationscheduleconfigured'] = 'Scheduled allocation configured';
$string['allocationconfigured'] = 'Allocation configured';
$string['allsubmissions'] = 'All submissions';
$string['alreadygraded'] = 'Already graded';
$string['areainstructauthors'] = 'Instructions for submission';

View File

@ -340,12 +340,11 @@ class mod_workshop_renderer extends plugin_renderer_base {
}
break;
case workshop_allocation_result::STATUS_SCHEDULED_ON:
case workshop_allocation_result::STATUS_SCHEDULED_OFF:
case workshop_allocation_result::STATUS_CONFIGURED:
if ($message = $result->get_message()) {
$message = new workshop_message($message, workshop_message::TYPE_INFO);
} else {
$message = new workshop_message(get_string('allocationscheduleconfigured', 'workshop'), workshop_message::TYPE_INFO);
$message = new workshop_message(get_string('allocationconfigured', 'workshop'), workshop_message::TYPE_INFO);
}
break;