--- /dev/null
+<?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/>.
+
+
+/**
+ * Assess a submission or preview the assessment form
+ *
+ * Displays an assessment form and saves the grades given by current user (reviewer)
+ * for the dimensions.
+ *
+ * @package mod-workshop
+ * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
+//require_once(dirname(__FILE__).'/lib.php');
+require_once(dirname(__FILE__).'/locallib.php');
+
+if ($preview = optional_param('preview', 0, PARAM_INT)) {
+ $mode = 'preview';
+ if (!$cm = get_coursemodule_from_id('workshop', $preview)) {
+ print_error('invalidcoursemodule');
+ }
+ if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
+ print_error('coursemisconf');
+ }
+ if (!$workshop = $DB->get_record('workshop', array('id' => $cm->instance))) {
+ print_error('err_invalidworkshopid', 'workshop');
+ }
+ $submission = new stdClass();
+ $assessment = new stdClass();
+} else {
+ $mode = 'assessment';
+ $assessmentid = required_param('asid', PARAM_INT); // assessment id
+ if (!$assessment = $DB->get_record('workshop_assessments', array('id' => $assessmentid))) {
+ print_error('err_unknownassessment', 'workshop');
+ }
+ if (!$submission = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid))) {
+ print_error('err_unknownsubmission', 'workshop');
+ }
+ if (!$workshop = $DB->get_record('workshop', array('id' => $submission->workshopid))) {
+ print_error('err_invalidworkshopid', 'workshop');
+ }
+ if (!$cm = get_coursemodule_from_instance('workshop', $workshop->id, $workshop->course)) {
+ print_error('invalidcoursemodule');
+ }
+ if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
+ print_error('coursemisconf');
+ }
+}
+
+require_login($course, false, $cm);
+
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+if (isguestuser()) {
+ print_error('err_noguests', 'workshop', "$CFG->wwwroot/mod/workshop/view.php?id=$cmid");
+}
+
+// where should the user be sent after closing the assessment form
+$returnurl = "{$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}";
+// the URL of this handler
+if ($mode == 'preview') {
+ $selfurl = "{$CFG->wwwroot}/mod/workshop/assessment.php?preview={$cm->id}";
+} elseif ($mode == 'assessment') {
+ $selfurl = "{$CFG->wwwroot}/mod/workshop/assessment.php?asid={$assessment->id}";
+}
+// the URL to edit this assessment form
+$editurl = "{$CFG->wwwroot}/mod/workshop/editform.php?cmid={$cm->id}";
+
+// load the grading strategy logic
+$strategy = workshop_strategy_instance($workshop);
+
+// load the assessment form definition from the database
+// this must be called before get_assessment_form() where we have to know
+// the number of repeating fieldsets
+
+//todo $formdata = $strategy->load_assessment($assessment);
+
+
+
+// load the form to edit the grading strategy dimensions
+$mform = $strategy->get_assessment_form($selfurl, $mode);
+
+// initialize form data
+//todo $mform->set_data($formdata);
+
+if ($mform->is_cancelled()) {
+ redirect($returnurl);
+} elseif ($data = $mform->get_data()) {
+ if (isset($data->backtoeditform)) {
+ redirect($editurl);
+ }
+ $strategy->save_assessment($data);
+ if (isset($data->saveandclose)) {
+ redirect($returnurl);
+ } else {
+ // save and continue - redirect to self to prevent data being re-posted by pressing "Reload"
+ redirect($selfurl);
+ }
+}
+
+// build the navigation and the header
+$navlinks = array();
+$navlinks[] = array('name' => get_string('modulenameplural', 'workshop'),
+ 'link' => "index.php?id=$course->id",
+ 'type' => 'activity');
+$navlinks[] = array('name' => format_string($workshop->name),
+ 'link' => "view.php?id=$cm->id",
+ 'type' => 'activityinstance');
+if ($mode == 'preview') {
+ $navlinks[] = array('name' => get_string('editingassessmentform', 'workshop'),
+ 'link' => $editurl,
+ 'type' => 'title');
+ $navlinks[] = array('name' => get_string('previewassessmentform', 'workshop'),
+ 'link' => '',
+ 'type' => 'title');
+} elseif ($mode == 'assessment') {
+ $navlinks[] = array('name' => get_string('assessingsubmission', 'workshop'),
+ 'link' => '',
+ 'type' => 'title');
+}
+$navigation = build_navigation($navlinks);
+
+// OUTPUT STARTS HERE
+
+print_header_simple(format_string($workshop->name), '', $navigation, '', '', true, '', navmenu($course, $cm));
+
+print_heading(get_string('assessmentform', 'workshop'));
+
+$mform->display();
+
+/// Finish the page
+print_footer($course);
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/lib.php');
+require_once(dirname(__FILE__).'/locallib.php');
$cmid = required_param('cmid', PARAM_INT); // course module id
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (isguestuser()) {
- print_error('guestnoedit', 'workshop', "$CFG->wwwroot/mod/workshop/view.php?id=$cmid");
+ print_error('err_noguests', 'workshop', "$CFG->wwwroot/mod/workshop/view.php?id=$cmid");
}
if (!$workshop = $DB->get_record('workshop', array('id' => $cm->instance))) {
- print_error('invalidid', 'workshop');
+ print_error('err_invalidworkshopid', 'workshop');
}
// where should the user be sent after closing the editing form
-$returnurl = "{$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}";
+$returnurl = "{$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}";
// the URL of this editing form
-$selfurl = "{$CFG->wwwroot}/mod/workshop/editform.php?cmid={$cm->id}";
+$selfurl = "{$CFG->wwwroot}/mod/workshop/editform.php?cmid={$cm->id}";
+// the URL to preview the assessment form
+$previewurl = "{$CFG->wwwroot}/mod/workshop/assessment.php?preview={$cm->id}";
// load the grading strategy logic
-$strategylib = dirname(__FILE__) . '/grading/' . $workshop->strategy . '/strategy.php';
-if (file_exists($strategylib)) {
- require_once($strategylib);
-} else {
- print_error('errloadingstrategylib', 'workshop', $returnurl);
-}
-$classname = 'workshop_' . $workshop->strategy . '_strategy';
-$strategy = new $classname($workshop);
+$strategy = workshop_strategy_instance($workshop);
// load the assessment form definition from the database
// this must be called before get_edit_strategy_form() where we have to know
$strategy->save_form($data);
if (isset($data->saveandclose)) {
redirect($returnurl);
+ } elseif (isset($data->saveandpreview)) {
+ redirect($previewurl);
} else {
+ // save and continue - redirect to self to prevent data being re-posted by pressing "Reload"
redirect($selfurl);
}
}
$navlinks[] = array('name' => format_string($workshop->name),
'link' => "view.php?id=$cm->id",
'type' => 'activityinstance');
-$navlinks[] = array('name' => get_string('editinggradingform', 'workshop'),
+$navlinks[] = array('name' => get_string('editingassessmentform', 'workshop'),
'link' => '',
'type' => 'title');
$navigation = build_navigation($navlinks);
// OUTPUT STARTS HERE
-print_header_simple(format_string($workshop->name), '', $navigation, '', '', true,
- update_module_button($cm->id, $course->id, get_string('modulename', 'workshop')), navmenu($course, $cm));
+print_header_simple(format_string($workshop->name), '', $navigation, '', '', true, '', navmenu($course, $cm));
print_heading(get_string('strategy' . $workshop->strategy, 'workshop'));
--- /dev/null
+<?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/>.
+
+
+/**
+ * This file defines an mform to assess a submission by accumulative grading strategy
+ *
+ * @package mod-workshop
+ * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+//require_once(dirname(dirname(dirname(__FILE__))).'/lib.php'); // module library
+require_once(dirname(dirname(__FILE__)).'/assessment_form.php'); // parent class definition
+
+
+/**
+ * Class representing a form for assessing submissions by accumulative grading strategy
+ *
+ * @uses moodleform
+ */
+class workshop_accumulative_assessment_form extends workshop_assessment_form {
+
+ /**
+ * Define the elements to be displayed at the form
+ *
+ * Called by the parent::definition()
+ *
+ * @access protected
+ * @return void
+ */
+ protected function definition_inner(&$mform) {
+
+ for ($i = 0; $i < $this->strategy->get_number_of_dimensions(); $i++) {
+
+ // dimension header
+ $mform->addElement('header', "dimensionhdr[$i]",
+ str_replace('{no}', $i+1, get_string('dimensionnumberaccumulative', 'workshop', '{no}')));
+
+ // dimension description
+ $desc = '<div id="id_dim_'.$this->fields["dimensionid[$i]"] . '_desc" class="fitem description accumulative">' . "\n";
+ $desc .= format_text($this->fields["description[$i]"], $this->fields["descriptionformat[$i]"]);
+ $desc .= "\n</div>";
+ $mform->addElement('html', $desc);
+
+ // grade for this aspect
+ $label = 'Grade'; // todo
+ $options = array(10,9,8,7,6,5,4,3,2,1,0); // todo
+ $mform->addElement('select', "grade[$i]", $label, $options);
+
+ // comment
+ $label = 'Comment'; //todo
+ $mform->addElement('htmleditor', "comment[$i]", $label, array());
+
+ }
+
+ }
+
+
+}
--- /dev/null
+<?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/>.
+
+
+/**
+ * This file defines a base class for all assessment forms
+ *
+ * @package mod-workshop
+ * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+require_once($CFG->libdir . '/formslib.php'); // parent class definition
+
+
+/**
+ * Base class for all assessment forms
+ *
+ * This defines the common fields that all assessment forms need.
+ * Strategies should define their own class that inherits from this one, and
+ * implements the definition_inner() method.
+ *
+ * @uses moodleform
+ */
+class workshop_assessment_form extends moodleform {
+
+ /** object Strategy logic instance */
+ protected $strategy;
+
+ /** array Assessment form fields defined by teacher */
+ protected $fields = array();
+
+ /** string The mode of the form: "preview" or "assessment" */
+ protected $mode = 'preview';
+
+ /**
+ * Add the fields that are common for all grading strategies.
+ *
+ * If the strategy does not support all these fields, then you can override
+ * this method and remove the ones you don't want with
+ * $mform->removeElement().
+ * Strategy subclassess should define their own fields in definition_inner()
+ *
+ * @access public
+ * @return void
+ */
+ public function definition() {
+ global $CFG;
+
+ $mform = $this->_form;
+ $this->strategy = $this->_customdata['strategy'];
+ $this->fields = (array)$this->_customdata['fields'];
+ $this->mode = $this->_customdata['mode'];
+
+ $mform->addElement('hidden', 'strategyname', $this->strategy->name);
+
+ $this->definition_inner($mform);
+
+ $buttonarray = array();
+ if ($this->mode == 'preview') {
+ $buttonarray[] = &$mform->createElement('submit', 'backtoeditform', get_string('backtoeditform', 'workshop'));
+ }
+ if ($this->mode == 'assessment') {
+ $buttonarray[] = &$mform->createElement('submit', 'saveandcontinue', get_string('saveandcontinue', 'workshop'));
+ $buttonarray[] = &$mform->createElement('submit', 'saveandclose', get_string('saveandclose', 'workshop'));
+ }
+ $buttonarray[] = &$mform->createElement('cancel');
+ $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
+ $mform->closeHeaderBefore('buttonar');
+ }
+
+
+ /**
+ * Add any strategy specific form fields.
+ *
+ * @param object $mform the form being built.
+ */
+ protected function definition_inner(&$mform) {
+ // By default, do nothing.
+ }
+
+}
}
$buttonarray = array();
- $buttonarray[] = &$mform->createElement('submit', 'saveandclose', get_string('saveandclose', 'workshop'));
$buttonarray[] = &$mform->createElement('submit', 'saveandcontinue', get_string('saveandcontinue', 'workshop'));
+ $buttonarray[] = &$mform->createElement('submit', 'saveandpreview', get_string('saveandpreview', 'workshop'));
+ $buttonarray[] = &$mform->createElement('submit', 'saveandclose', get_string('saveandclose', 'workshop'));
$buttonarray[] = &$mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$mform->closeHeaderBefore('buttonar');
}
+ /**
+ * Factory method returning an instance of an assessment form
+ *
+ * By default, the class is defined in grading/{strategy}/assessment_form.php and is named
+ * workshop_{strategy}_assessment_form
+ *
+ * @param string $actionurl URL of form handler, defaults to auto detect the current url
+ * @param string $mode Mode to open the form in: preview/assessment
+ */
+ public function get_assessment_form($actionurl=null, $mode='preview') {
+ global $CFG; // needed because the included files use it
+
+ $assessmentform = dirname(__FILE__) . '/' . $this->name . '/assessment_form.php';
+ if (is_readable($assessmentform)) {
+ require_once($assessmentform);
+ } else {
+ throw new moodle_exception('errloadingassessmentform', 'workshop');
+ }
+ $classname = 'workshop_' . $this->name . '_assessment_form';
+
+ $customdata = new stdClass;
+ $customdata = array(
+ 'strategy' => $this,
+ 'fields' => $this->load_form(),
+ 'mode' => $mode,
+ );
+ $attributes = array('class' => 'assessmentform');
+
+ return new $classname($actionurl, $customdata, 'post', '', $attributes);
+
+ }
+
}
$string[''] = '';
$string[''] = '';
$string[''] = '';
-$string[''] = '';
-$string[''] = '';
-$string[''] = '';
+$string['assessingsubmission'] = 'Assessing submission';
$string['accesscontrol'] = 'Access control';
$string['addmoredimensionsaccumulative'] = 'Blanks for $a more aspects';
$string['addmoredimensionsnoerrors'] = 'Blanks for $a more assertions';
$string['assessallexamples'] = 'Assess all examples';
$string['assessmentcomps'] = 'Required level of assessments similarity';
$string['assessmentend'] = 'End of assessment phase';
+$string['assessmentform'] = 'Assessment form';
$string['assessmentsettings'] = 'Assessment settings';
$string['assessmentstart'] = 'Start of assessment phase';
$string['assesswosubmission'] = 'Assess without submission';
$string['assesswosubmissiondesc'] = 'Users can assess peers even without their own submission';
+$string['backtoeditform'] = 'Back to editing form';
$string['comparisonhigh'] = 'High';
$string['comparisonlow'] = 'Low';
$string['comparisonnormal'] = 'Normal';
$string['dimensionnumberaccumulative'] = 'Aspect $a';
$string['dimensionnumbernoerrors'] = 'Assertion $a';
$string['dimensionweight'] = 'Weight';
-$string['editgradingform'] = 'Edit grading form';
-$string['editinggradingform'] = 'Editing grading form';
+$string['editingassessmentform'] = 'Editing assessment form';
$string['editingsubmission'] = 'Editing submission';
$string['err_removegrademappings'] = 'Unable to remove the unused grade mappings';
$string['examplesbeforeassessment'] = 'Examples are available after own submission and must be assessed before peer/self assessment phase';
$string['noerrorsmapgrade'] = 'Grade for submission';
$string['nsassessments'] = 'Number of required assessments of other users\' work';
$string['percents'] = '$a%';
+$string['previewassessmentform'] = 'Preview';
$string['releasegrades'] = 'Push final grades into the gradebook';
$string['requirepassword'] = 'Require password';
$string['saveandclose'] = 'Save and close';
$string['saveandcontinue'] = 'Save and continue editing';
+$string['saveandpreview'] = 'Save and preview';
$string['strategyaccumulative'] = 'Accumulative grading';
$string['strategy'] = 'Grading strategy';
$string['strategynoerrors'] = 'Number of errors';
defined('MOODLE_INTERNAL') || die();
+function workshop_strategy_instance($workshop) {
+ /** static variable to hold the singleton */
+ static $instance = null;
+
+ if (is_null($instance)) {
+ $strategylib = dirname(__FILE__) . '/grading/' . $workshop->strategy . '/strategy.php';
+ if (is_readable($strategylib)) {
+ require_once($strategylib);
+ } else {
+ throw new moodle_exception('missingstrategy', 'workshop');
+ }
+ $classname = 'workshop_' . $workshop->strategy . '_strategy';
+ $instance = new $classname($workshop);
+ }
+
+ return $instance;
+}
+
+
/**
* Return the user's submission record in the given workshop
*