Permalink
Browse files

MDL-29482, MDL-29794, MDL-30037: supporting form status in rubricedit…

…or and forms sharing; fixed bug with grade calculation
  • Loading branch information...
1 parent 2ae7faf commit 3599b113a6261e894f044543ae6221718425e138 @marinaglancy marinaglancy committed Nov 2, 2011
View
38 grade/grading/form/lib.php
@@ -122,16 +122,7 @@ public function is_form_defined() {
* @return boolean
*/
public function is_form_available() {
-
- if (!$this->is_form_defined()) {
- return false;
- }
-
- if ($this->definition->status == self::DEFINITION_STATUS_READY) {
- return true;
- }
-
- return false;
+ return ($this->is_form_defined() && $this->definition->status == self::DEFINITION_STATUS_READY);
}
/**
@@ -217,6 +208,7 @@ public function get_definition_copy(gradingform_controller $target) {
$new->description = $old->description;
$new->descriptionformat = $old->descriptionformat;
$new->options = $old->options;
+ $new->status = $old->status;
return $new;
}
@@ -229,10 +221,9 @@ public function get_definition_copy(gradingform_controller $target) {
* and save their data into own tables, too.
*
* @param stdClass $definition data containing values for the {grading_definition} table
- * @param int|null $status optionally overwrite the status field with this value
* @param int|null $usermodified optional userid of the author of the definition, defaults to the current user
*/
- public function update_definition(stdClass $definition, $status = null, $usermodified = null) {
+ public function update_definition(stdClass $definition, $usermodified = null) {
global $DB, $USER;
if (is_null($usermodified)) {
@@ -261,10 +252,6 @@ public function update_definition(stdClass $definition, $status = null, $usermod
// set the modification flags
$record->timemodified = time();
$record->usermodified = $usermodified;
- // overwrite the status if required
- if (!is_null($status)) {
- $record->status = $status;
- }
$DB->update_record('grading_definitions', $record);
@@ -290,11 +277,12 @@ public function update_definition(stdClass $definition, $status = null, $usermod
$record->usercreated = $usermodified;
$record->timemodified = $record->timecreated;
$record->usermodified = $record->usercreated;
- if (!is_null($status)) {
- $record->status = $status;
- } else {
+ if (empty($record->status)) {
$record->status = self::DEFINITION_STATUS_DRAFT;
}
+ if (empty($record->descriptionformat)) {
+ $record->descriptionformat = FORMAT_MOODLE; // field can not be empty
+ }
$DB->insert_record('grading_definitions', $record);
@@ -304,6 +292,18 @@ public function update_definition(stdClass $definition, $status = null, $usermod
}
/**
+ * Formats the definition description for display on page
+ *
+ * @return string
+ */
+ public function get_formatted_description() {
+ if (!isset($this->definition->description)) {
+ return '';
+ }
+ return format_text($this->definition->description, $this->definition->descriptionformat);
+ }
+
+ /**
* Returns the ACTIVE instance for this definition for the specified $raterid and $itemid
* (if multiple raters are allowed, or only for $itemid otherwise).
*
View
9 grade/grading/form/rubric/edit.php
@@ -53,13 +53,8 @@
redirect($returnurl);
} else if ($mform->is_submitted() && $mform->is_validated()) {
$data = $mform->get_data();
- if (!empty($data->submitfinal)) {
- $controller->update_definition($data, gradingform_controller::DEFINITION_STATUS_READY);
- redirect($returnurl);
- } else {
- $controller->update_definition($data, gradingform_controller::DEFINITION_STATUS_DRAFT);
- redirect($PAGE->url);
- }
+ $controller->update_definition($data);
+ redirect($returnurl);
}
echo $OUTPUT->header();
View
11 grade/grading/form/rubric/edit_form.php
@@ -58,10 +58,9 @@ public function definition() {
// rubric completion status
$choices = array();
- $choices[gradingform_controller::DEFINITION_STATUS_WORKINPROGRESS] = get_string('statusworkinprogress', 'gradingform_rubric');
- $choices[gradingform_controller::DEFINITION_STATUS_PRIVATE] = get_string('statusprivate', 'gradingform_rubric');
- $choices[gradingform_controller::DEFINITION_STATUS_PUBLIC] = get_string('statuspublic', 'gradingform_rubric');
- $form->addElement('select', 'status', 'Current rubric status', $choices)->freeze();
+ $choices[gradingform_controller::DEFINITION_STATUS_DRAFT] = get_string('statusdraft', 'grading');
+ $choices[gradingform_controller::DEFINITION_STATUS_READY] = get_string('statusready', 'grading');
+ $form->addElement('select', 'status', get_string('rubricstatus', 'gradingform_rubric'), $choices)->freeze();
// rubric editor
$element = $form->addElement('rubriceditor', 'rubric', get_string('rubric', 'gradingform_rubric'));
@@ -112,9 +111,9 @@ function validation($data, $files) {
function get_data() {
$data = parent::get_data();
if (!empty($data->saverubric)) {
- $data->status = gradingform_controller::DEFINITION_STATUS_PUBLIC; // TODO ???
+ $data->status = gradingform_controller::DEFINITION_STATUS_READY;
} else if (!empty($data->saverubricdraft)) {
- $data->status = gradingform_controller::DEFINITION_STATUS_WORKINPROGRESS;
+ $data->status = gradingform_controller::DEFINITION_STATUS_DRAFT;
}
return $data;
}
View
8 grade/grading/form/rubric/lang/en/gradingform_rubric.php
@@ -56,12 +56,12 @@
$string['enableremarks'] = 'Allow grader to add text remarks for each criteria';
$string['showremarksstudent'] = 'Show remarks to those being graded';
-$string['saverubric'] = 'Save rubric and make it available';
+$string['saverubric'] = 'Save rubric and make it ready';
$string['saverubricdraft'] = 'Save as draft';
-$string['statusworkinprogress'] = 'Work in progress';
-$string['statusprivate'] = 'Private';
-$string['statuspublic'] = 'Public';
+$string['rubricstatus'] = 'Current rubric status';
+$string['statusdraft'] = 'Draft';
+$string['statusready'] = 'Ready';
$string['err_nocriteria'] = 'Rubric must contain at least one criterion';
$string['err_mintwolevels'] = 'Each criterion must have at least two levels';
View
70 grade/grading/form/rubric/lib.php
@@ -62,17 +62,16 @@ public function extend_settings_navigation(settings_navigation $settingsnav, nav
*
* @see parent::update_definition()
* @param stdClass $newdefinition rubric definition data as coming from gradingform_rubric_editrubric::get_data()
- * @param int|null $status optionally overwrite the status field with this value
* @param int|null $usermodified optional userid of the author of the definition, defaults to the current user
*/
- public function update_definition(stdClass $newdefinition, $status = null, $usermodified = null) {
+ public function update_definition(stdClass $newdefinition, $usermodified = null) {
global $DB;
// firstly update the common definition data in the {grading_definition} table
if ($this->definition === false) {
// if definition does not exist yet, create a blank one
// (we need id to save files embedded in description)
- parent::update_definition((object)array(), $status, $usermodified);
+ parent::update_definition(new stdClass(), $usermodified);
parent::load_definition();
}
if (!isset($newdefinition->rubric['options'])) {
@@ -82,7 +81,7 @@ public function update_definition(stdClass $newdefinition, $status = null, $user
$editoroptions = self::description_form_field_options($this->get_context());
$newdefinition = file_postupdate_standard_editor($newdefinition, 'description', $editoroptions, $this->get_context(),
'gradingform_rubric', 'definition_description', $this->definition->id);
- parent::update_definition($newdefinition, $status, $usermodified);
+ parent::update_definition($newdefinition, $usermodified);
// reload the definition from the database
$currentdefinition = $this->get_definition(true);
@@ -336,9 +335,14 @@ public static function description_form_field_options($context) {
);
}
+ /**
+ * Formats the definition description for display on page
+ *
+ * @return string
+ */
public function get_formatted_description() {
- if ($this->definition === false) {
- return null;
+ if (!isset($this->definition->description)) {
+ return '';
}
$context = $this->get_context();
@@ -584,10 +588,13 @@ public function get_grade() {
$minscore = 0;
$maxscore = 0;
foreach ($this->get_controller()->get_definition()->rubric_criteria as $id => $criterion) {
- $keys = array_keys($criterion['levels']);
- sort($keys);
- $minscore += $criterion['levels'][$keys[0]]['score'];
- $maxscore += $criterion['levels'][$keys[sizeof($keys)-1]]['score'];
+ $scores = array();
+ foreach ($criterion['levels'] as $level) {
+ $scores[] = $level['score'];
+ }
+ sort($scores);
+ $minscore += $criterion['levels'][$scores[0]];
+ $maxscore += $criterion['levels'][$scores[sizeof($scores)-1]];
}
if ($maxscore <= $minscore) {
@@ -646,4 +653,45 @@ public function render_grading_element($page, $gradingformelement) {
}
return $this->get_controller()->get_renderer($page)->display_rubric($criteria, $options, $mode, $gradingformelement->getName(), $value);
}
-}
+}
+
+
+/**
+ * Processes file requests for the gradingform_rubric
+ *
+ * Required to serve files for this plugin
+ * Called from pluginfile.php
+ *
+ * @global moodle_database $DB
+ * @param stdClass $course
+ * @param null $cm
+ * @param stdClass $context
+ * @param string $filearea
+ * @param array $args
+ * @param bool $forcedownload
+ * @return void|false
+ */
+function gradingform_rubric_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
+ global $CFG, $DB;
+ // First argument should ALWAYS be the itemid
+ $itemid = (int)array_shift($args);
+ // Construct a URL to the file and check it exists
+ $fs = get_file_storage();
+ $relativepath = implode('/', $args);
+ $fullpath = "/$context->id/gradingform_rubric/$filearea/$itemid/$relativepath";
+ if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
+ // File doesnt exist anyway no point proceeding.
+ return false;
+ }
+ // Switch by the fileare and check the appropriate information
+ switch ($filearea) {
+ case 'definition_description' :
+ // Make sure the itemid points to a valid definition
+ if ($DB->record_exists('grading_definitions', array('id' => $itemid))) {
+ send_stored_file($file, 0, 0, $forcedownload);
+ }
+ break;
+ }
+ // Obviosly bogus comething or other in there
+ return false;
+}
View
10 grade/grading/manage.php
@@ -115,8 +115,7 @@
$newareaid = $manager->create_shared_area($method);
$targetarea = get_grading_manager($newareaid);
$targetcontroller = $targetarea->get_controller($method);
- $targetcontroller->update_definition($controller->get_definition_copy($targetcontroller),
- gradingform_controller::DEFINITION_STATUS_READY);
+ $targetcontroller->update_definition($controller->get_definition_copy($targetcontroller));
$DB->set_field('grading_definitions', 'timecopied', time(), array('id' => $definition->id));
redirect(new moodle_url($PAGE->url, array('message' => get_string('manageactionsharedone', 'core_grading'))));
}
@@ -175,7 +174,10 @@
} else {
$hasoriginal = $DB->record_exists('grading_definitions', array('id' => $definition->copiedfromid));
}
- if (!$hasoriginal) {
+ if (!$controller->is_form_available()) {
+ // drafts can not be shared
+ $allowshare = false;
+ } else if (!$hasoriginal) {
// was created from scratch or is orphaned
if (empty($definition->timecopied)) {
// was never shared before
@@ -232,7 +234,7 @@
$tag = html_writer::tag('span', get_string('statusdraft', 'core_grading'), array('class' => 'status-draft'));
}
echo $output->heading(s($definition->name) . ' ' . $tag, 3, 'definition-name');
- echo $output->box(format_text($definition->description, $definition->descriptionformat));
+ echo $output->box($controller->get_formatted_description());
echo $output->box($controller->render_preview($PAGE), 'definition-preview');
}
}
View
5 grade/grading/pick.php
@@ -88,8 +88,7 @@
die();
} else {
require_sesskey();
- $targetcontroller->update_definition($sourcecontroller->get_definition_copy($targetcontroller),
- gradingform_controller::DEFINITION_STATUS_READY);
+ $targetcontroller->update_definition($sourcecontroller->get_definition_copy($targetcontroller));
$DB->set_field('grading_definitions', 'timecopied', time(), array('id' => $definition->id));
redirect(new moodle_url('/grade/grading/manage.php', array('areaid' => $targetid)));
}
@@ -199,7 +198,7 @@
get_string('templatedelete', 'core_grading'), 't/delete', 'remove');
}
$out .= $output->box(join(' ', $actions), 'template-actions');
- $out .= $output->box(format_text($template->description, $template->descriptionformat), 'template-description');
+ $out .= $output->box($controller->get_formatted_description(), 'template-description');
// ideally we should highlight just the name, description and the fields
// in the preview that were actually searched. to make our life easier, we
View
2 lang/en/grading.php
@@ -57,8 +57,6 @@
$string['manageactionsharedone'] = 'The form was successfully saved as a template';
$string['noitemid'] = 'Grading not possible. The graded item does not exist.';
$string['nosharedformfound'] = 'No template found';
-$string['saveandcontinue'] = 'Save as draft';
-$string['saveandmakeready'] = 'Save as ready for usage';
$string['statusdraft'] = 'Draft';
$string['statusready'] = 'Ready for usage';
$string['templatedelete'] = 'Delete';

0 comments on commit 3599b11

Please sign in to comment.