Rough search and replace accumulative > comments

This commit is contained in:
David Mudrak
2010-01-04 18:21:24 +00:00
parent 669314615f
commit 6f3535ac9c
6 changed files with 60 additions and 63 deletions
@@ -16,9 +16,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file defines an mform to assess a submission by accumulative grading strategy
* This file defines an mform to assess a submission by comments grading strategy
*
* @package mod-workshop
* @package mod-workshopform-comments
* @copyright 2009 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,11 +28,11 @@ defined('MOODLE_INTERNAL') || die();
require_once(dirname(dirname(__FILE__)).'/assessment_form.php'); // parent class definition
/**
* Class representing a form for assessing submissions by accumulative grading strategy
* Class representing a form for assessing submissions by comments grading strategy
*
* @uses moodleform
*/
class workshop_accumulative_assessment_form extends workshop_assessment_form {
class workshop_comments_assessment_form extends workshop_assessment_form {
/**
* Define the elements to be displayed at the form
@@ -50,7 +50,7 @@ class workshop_accumulative_assessment_form extends workshop_assessment_form {
for ($i = 0; $i < $nodims; $i++) {
// dimension header
$dimtitle = get_string('dimensionnumber', 'workshopform_accumulative', $i+1);
$dimtitle = get_string('dimensionnumber', 'workshopform_comments', $i+1);
$mform->addElement('header', 'dimensionhdr__idx_'.$i, $dimtitle);
// dimension id
@@ -60,18 +60,18 @@ class workshop_accumulative_assessment_form extends workshop_assessment_form {
$mform->addElement('hidden', 'gradeid__idx_'.$i); // value set by set_data() later
// dimension description
$desc = '<div id="id_dim_'.$fields->{'dimensionid__idx_'.$i}.'_desc" class="fitem description accumulative">'."\n";
$desc = '<div id="id_dim_'.$fields->{'dimensionid__idx_'.$i}.'_desc" class="fitem description comments">'."\n";
$desc .= format_text($fields->{'description__idx_'.$i}, $fields->{'description__idx_'.$i.'format'});
$desc .= "\n</div>";
$mform->addElement('html', $desc);
// grade for this aspect
$label = get_string('dimensiongrade', 'workshopform_accumulative');
$label = get_string('dimensiongrade', 'workshopform_comments');
$options = make_grades_menu($fields->{'grade__idx_' . $i});
$mform->addElement('select', 'grade__idx_' . $i, $label, $options);
// comment
$label = get_string('dimensioncomment', 'workshopform_accumulative');
$label = get_string('dimensioncomment', 'workshopform_comments');
//$mform->addElement('editor', 'peercomment__idx_' . $i, $label, null, array('maxfiles' => 0));
$mform->addElement('textarea', 'peercomment__idx_' . $i, $label, array('cols' => 60, 'rows' => 5));
}
+10 -10
View File
@@ -16,9 +16,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file defines an mform to edit accumulative grading strategy forms.
* This file defines an mform to edit comments grading strategy forms.
*
* @package mod-workshop
* @package mod-workshopform-comments
* @copyright 2009 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -29,11 +29,11 @@ require_once(dirname(dirname(dirname(__FILE__))).'/lib.php'); // module librar
require_once(dirname(dirname(__FILE__)).'/edit_form.php'); // parent class definition
/**
* Class for editing accumulative grading strategy forms.
* Class for editing comments grading strategy forms.
*
* @uses moodleform
*/
class workshop_edit_accumulative_strategy_form extends workshop_edit_strategy_form {
class workshop_edit_comments_strategy_form extends workshop_edit_strategy_form {
/**
* Define the elements to be displayed at the form
@@ -55,22 +55,22 @@ class workshop_edit_accumulative_strategy_form extends workshop_edit_strategy_fo
$weights = workshop_get_dimension_weights();
for ($i = 0; $i < $norepeats; $i++) {
$mform->addElement('header', 'dimension'.$i, get_string('dimensionnumber', 'workshopform_accumulative', $i+1));
$mform->addElement('header', 'dimension'.$i, get_string('dimensionnumber', 'workshopform_comments', $i+1));
$mform->addElement('hidden', 'dimensionid__idx_'.$i);
$mform->addElement('editor', 'description__idx_'.$i.'_editor',
get_string('dimensiondescription', 'workshopform_accumulative'), '', $descriptionopts);
get_string('dimensiondescription', 'workshopform_comments'), '', $descriptionopts);
// todo replace modgrade with an advanced element (usability issue discussed with Olli)
$mform->addElement('modgrade', 'grade__idx_'.$i,
get_string('dimensionmaxgrade','workshopform_accumulative'), null, true);
get_string('dimensionmaxgrade','workshopform_comments'), null, true);
$mform->setDefault('grade__idx_'.$i, 10);
$mform->addElement('select', 'weight__idx_'.$i,
get_string('dimensionweight', 'workshopform_accumulative'), $weights);
get_string('dimensionweight', 'workshopform_comments'), $weights);
$mform->setDefault('weight__idx_'.$i, 1);
}
$mform->registerNoSubmitButton('noadddims');
$mform->addElement('submit', 'noadddims', get_string('addmoredimensions', 'workshopform_accumulative',
workshop_accumulative_strategy::ADDDIMS));
$mform->addElement('submit', 'noadddims', get_string('addmoredimensions', 'workshopform_comments',
workshop_comments_strategy::ADDDIMS));
$mform->closeHeaderBefore('noadddims');
$this->set_data($current);
}
@@ -16,9 +16,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* English strings for Workshop subplugin - "Accumulative" grading strategy
* English strings for Workshop subplugin - "Comments" grading strategy
*
* @package mod-workshop
* @package mod-workshopform-commentsform-comments
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,8 +28,5 @@ defined('MOODLE_INTERNAL') || die();
$string['addmoredimensions'] = 'Blanks for $a more aspects';
$string['dimensioncomment'] = 'Comment';
$string['dimensiondescription'] = 'Description';
$string['dimensiongrade'] = 'Grade';
$string['dimensionmaxgrade'] = 'Best possible grade / Scale to use';
$string['dimensionnumber'] = 'Aspect $a';
$string['dimensionweight'] = 'Weight';
$string['pluginname'] = 'Accumulative grading';
$string['pluginname'] = 'Comments';
+29 -29
View File
@@ -16,9 +16,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file defines a class with accumulative grading strategy logic
* This file defines a class with comments grading strategy logic
*
* @package mod-workshop
* @package mod-workshopform-comments
* @copyright 2009 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -31,7 +31,7 @@ require_once($CFG->libdir . '/gradelib.php'); // to handle float vs de
/**
* Accumulative grading strategy logic.
*/
class workshop_accumulative_strategy implements workshop_strategy {
class workshop_comments_strategy implements workshop_strategy {
/** @const default number of dimensions to show */
const MINDIMS = 3;
@@ -84,7 +84,7 @@ class workshop_accumulative_strategy implements workshop_strategy {
for ($i = 0; $i < $nodimensions; $i++) {
// prepare all editor elements
$fields = file_prepare_standard_editor($fields, 'description__idx_'.$i, $this->descriptionopts,
$PAGE->context, 'workshopform_accumulative_description', $fields->{'dimensionid__idx_'.$i});
$PAGE->context, 'workshopform_comments_description', $fields->{'dimensionid__idx_'.$i});
}
$customdata = array();
@@ -95,7 +95,7 @@ class workshop_accumulative_strategy implements workshop_strategy {
$customdata['current'] = $fields;
$attributes = array('class' => 'editstrategyform');
return new workshop_edit_accumulative_strategy_form($actionurl, $customdata, 'post', '', $attributes);
return new workshop_edit_comments_strategy_form($actionurl, $customdata, 'post', '', $attributes);
}
/**
@@ -117,7 +117,7 @@ class workshop_accumulative_strategy implements workshop_strategy {
$norepeats = $data->norepeats;
$data = $this->prepare_database_fields($data);
$records = $data->accumulative; // records to be saved into {workshopform_accumulative}
$records = $data->comments; // records to be saved into {workshopform_comments}
$todelete = array(); // dimension ids to be deleted
for ($i=0; $i < $norepeats; $i++) {
@@ -131,15 +131,15 @@ class workshop_accumulative_strategy implements workshop_strategy {
}
if (empty($record->id)) {
// new field
$record->id = $DB->insert_record('workshopform_accumulative', $record);
$record->id = $DB->insert_record('workshopform_comments', $record);
} else {
// exiting field
$DB->update_record('workshopform_accumulative', $record);
$DB->update_record('workshopform_comments', $record);
}
// re-save with correct path to embeded media files
$record = file_postupdate_standard_editor($record, 'description', $this->descriptionopts,
$PAGE->context, 'workshopform_accumulative_description', $record->id);
$DB->update_record('workshopform_accumulative', $record);
$PAGE->context, 'workshopform_comments_description', $record->id);
$DB->update_record('workshopform_comments', $record);
}
$this->delete_dimensions($todelete);
}
@@ -164,7 +164,7 @@ class workshop_accumulative_strategy implements workshop_strategy {
// rewrite URLs to the embeded files
for ($i = 0; $i < $nodimensions; $i++) {
$fields->{'description__idx_'.$i} = file_rewrite_pluginfile_urls($fields->{'description__idx_'.$i},
'pluginfile.php', $PAGE->context->id, 'workshopform_accumulative_description', $fields->{'dimensionid__idx_'.$i});
'pluginfile.php', $PAGE->context->id, 'workshopform_comments_description', $fields->{'dimensionid__idx_'.$i});
}
if ('assessment' === $mode and !empty($assessment)) {
@@ -190,9 +190,9 @@ class workshop_accumulative_strategy implements workshop_strategy {
$customdata['nodims'] = $nodimensions;
$customdata['fields'] = $fields;
$customdata['current'] = isset($current) ? $current : null;
$attributes = array('class' => 'assessmentform accumulative');
$attributes = array('class' => 'assessmentform comments');
return new workshop_accumulative_assessment_form($actionurl, $customdata, 'post', '', $attributes, $editable);
return new workshop_comments_assessment_form($actionurl, $customdata, 'post', '', $attributes, $editable);
}
/**
@@ -214,7 +214,7 @@ class workshop_accumulative_strategy implements workshop_strategy {
$grade = new stdClass();
$grade->id = $data->{'gradeid__idx_' . $i};
$grade->assessmentid = $assessment->id;
$grade->strategy = 'accumulative';
$grade->strategy = 'comments';
$grade->dimensionid = $data->{'dimensionid__idx_' . $i};
$grade->grade = $data->{'grade__idx_' . $i};
$grade->peercomment = $data->{'peercomment__idx_' . $i};
@@ -279,7 +279,7 @@ class workshop_accumulative_strategy implements workshop_strategy {
global $DB;
$sql = 'SELECT d.id, d.grade, d.weight, s.scale
FROM {workshopform_accumulative} d
FROM {workshopform_comments} d
LEFT JOIN {scale} s ON (d.grade < 0 AND -d.grade = s.id)
WHERE d.workshopid = :workshopid';
$params = array('workshopid' => $this->workshop->id);
@@ -315,7 +315,7 @@ class workshop_accumulative_strategy implements workshop_strategy {
global $DB;
$sql = 'SELECT *
FROM {workshopform_accumulative}
FROM {workshopform_comments}
WHERE workshopid = :workshopid
ORDER BY sort';
$params = array('workshopid' => $this->workshop->id);
@@ -358,14 +358,14 @@ class workshop_accumulative_strategy implements workshop_strategy {
$fs = get_file_storage();
foreach ($ids as $id) {
if (!empty($id)) { // to prevent accidental removal of all files in the area
$fs->delete_area_files($PAGE->context->id, 'workshopform_accumulative_description', $id);
$fs->delete_area_files($PAGE->context->id, 'workshopform_comments_description', $id);
}
}
$DB->delete_records_list('workshopform_accumulative', 'id', $ids);
$DB->delete_records_list('workshopform_comments', 'id', $ids);
}
/**
* Prepares data returned by {@link workshop_edit_accumulative_strategy_form} so they can be saved into database
* Prepares data returned by {@link workshop_edit_comments_strategy_form} so they can be saved into database
*
* It automatically adds some columns into every record. The sorting is
* done by the order of the returned array and starts with 1.
@@ -379,16 +379,16 @@ class workshop_accumulative_strategy implements workshop_strategy {
global $PAGE;
$cook = new stdClass(); // to be returned
$cook->accumulative = array(); // records to be stored in {workshopform_accumulative}
$cook->comments = array(); // records to be stored in {workshopform_comments}
for ($i = 0; $i < $raw->norepeats; $i++) {
$cook->accumulative[$i] = new stdClass();
$cook->accumulative[$i]->id = $raw->{'dimensionid__idx_'.$i};
$cook->accumulative[$i]->workshopid = $this->workshop->id;
$cook->accumulative[$i]->sort = $i + 1;
$cook->accumulative[$i]->description_editor = $raw->{'description__idx_'.$i.'_editor'};
$cook->accumulative[$i]->grade = $raw->{'grade__idx_'.$i};
$cook->accumulative[$i]->weight = $raw->{'weight__idx_'.$i};
$cook->comments[$i] = new stdClass();
$cook->comments[$i]->id = $raw->{'dimensionid__idx_'.$i};
$cook->comments[$i]->workshopid = $this->workshop->id;
$cook->comments[$i]->sort = $i + 1;
$cook->comments[$i]->description_editor = $raw->{'description__idx_'.$i.'_editor'};
$cook->comments[$i]->grade = $raw->{'grade__idx_'.$i};
$cook->comments[$i]->weight = $raw->{'weight__idx_'.$i};
}
return $cook;
}
@@ -410,7 +410,7 @@ class workshop_accumulative_strategy implements workshop_strategy {
$sql = "SELECT dimensionid, *
FROM {workshop_grades}
WHERE assessmentid = :assessmentid AND strategy= :strategy AND dimensionid $dimsql";
$params = array('assessmentid' => $assessment->id, 'strategy' => 'accumulative');
$params = array('assessmentid' => $assessment->id, 'strategy' => 'comments');
$params = array_merge($params, $dimparams);
return $DB->get_records_sql($sql, $params);
@@ -475,7 +475,7 @@ class workshop_accumulative_strategy implements workshop_strategy {
/**
* Convert scale grade to numerical grades
*
* In accumulative grading strategy, scales are considered as grades from 0 to M-1, where M is the number of scale items.
* In comments grading strategy, scales are considered as grades from 0 to M-1, where M is the number of scale items.
*
* @throws coding_exception
* @param string $scaleid Scale identifier
@@ -18,7 +18,7 @@
/**
* Unit tests for Accumulative grading strategy logic
*
* @package mod-workshop
* @package mod-workshopform-comments
* @copyright 2009 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -27,7 +27,7 @@ defined('MOODLE_INTERNAL') || die();
// Include the code to test
require_once($CFG->dirroot . '/mod/workshop/locallib.php');
require_once($CFG->dirroot . '/mod/workshop/form/accumulative/lib.php');
require_once($CFG->dirroot . '/mod/workshop/form/comments/lib.php');
global $DB;
Mock::generate(get_class($DB), 'mockDB');
@@ -35,7 +35,7 @@ Mock::generate(get_class($DB), 'mockDB');
/**
* Test subclass that makes all the protected methods we want to test public
*/
class testable_workshop_accumulative_strategy extends workshop_accumulative_strategy {
class testable_workshop_comments_strategy extends workshop_comments_strategy {
/** allows to set dimensions manually */
public $dimensions = array();
@@ -48,7 +48,7 @@ class testable_workshop_accumulative_strategy extends workshop_accumulative_stra
}
}
class workshop_accumulative_strategy_test extends UnitTestCase {
class workshop_comments_strategy_test extends UnitTestCase {
/** real database */
protected $realDB;
@@ -70,9 +70,9 @@ class workshop_accumulative_strategy_test extends UnitTestCase {
$cm = new stdClass();
$course = new stdClass();
$context = new stdClass();
$workshop = (object)array('id' => 42, 'strategy' => 'accumulative');
$workshop = (object)array('id' => 42, 'strategy' => 'comments');
$this->workshop = new workshop($workshop, $cm, $course, $context);
$this->strategy = new testable_workshop_accumulative_strategy($this->workshop);
$this->strategy = new testable_workshop_comments_strategy($this->workshop);
}
public function tearDown() {
+4 -4
View File
@@ -16,17 +16,17 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Defines the version of workshop accumulative grading strategy subplugin
* Defines the version of workshop comments grading strategy subplugin
*
* This code fragment is called by moodle_needs_upgrading() and
* /admin/index.php
*
* @package mod-workshop
* @package mod-workshopform-comments
* @copyright 2009 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2009081300;
$plugin->requires = 2009080700; // Requires this Moodle version
$plugin->version = 2009102600;
$plugin->requires = 2009102600; // Requires this Moodle version