$param->element_type = optional_param('element_type', 0, PARAM_ALPHA);
$param->category_name = optional_param('category_name', 0, PARAM_ALPHA);
+print_object($param);
+
$tree = new grade_tree($param->courseid);
$select_source = false;
case 'edit':
break;
case 'delete':
- if ($param->confirm == 1) {
+ if ($param->confirm == 1) { // Perform the deletion
$tree->remove_element($param->target);
$tree->renumber();
$tree->update_db();
// Print result message
- } else {
- // Print confirmation dialog
+ } else { // Print confirmation dialog
$strdeletecheckfull = get_string('deletecheck', '', $element->element['object']->get_name());
$linkyes = "category.php?target=$param->target&action=delete&confirm=1$tree->commonvars";
$linkno = "category.php?$tree->commonvars";
break;
}
unset($param->target);
-} elseif (!empty($param->element_type) &&
- !empty($param->action) &&
- $param->action == 'create' &&
- confirm_sesskey() &&
- !empty($param->category_name)) {
- if ($param->element_type == 'items') {
+} elseif (!empty($param->element_type) && !empty($param->action) && $param->action == 'create' && confirm_sesskey()) {
+ if (empty($param->category_name)) {
+ notice(get_string('createcategoryerror', 'grades') . ': ' . get_string('nocategoryname', 'grades'));
+ } elseif ($param->element_type == 'items') {
+
if (!empty($param->items)) {
$category = new grade_category();
$category->fullname = $param->category_name;
}
} else { // No items selected. Can't create a category over them...
- notice("Couldn't create a category, you did not select any grade items.");
+ notice(get_string('createcategoryerror', 'grades') . ': ' . get_string('noselecteditems', 'grades'));
}
} elseif ($param->element_type == 'categories') {
if (!empty($param->categories)) {
}
} else { // No categories selected. Can't create a category over them...
- notice("Couldn't create a category, you did not select any sub-categories.");
+ notice(get_string('createcategoryerror', 'grades') . ': ' . get_string('noselectedcategories', 'grades'));
}
} else { // The element_type wasn't set properly, throw up an error
$string['category'] = 'Category';
$string['categoryname'] = 'Category name';
$string['choosecategory'] = 'Select Category';
-$string['createcategory'] = 'Create category';
+$string['createcategory'] = 'Create Category';
+$string['createcategoryerror'] = 'Could not create a new category';
$string['creatinggradebooksettings'] = 'Creating Gradebook settings';
$string['curveto'] = 'Curve To';
$string['deletecategory'] = 'Delete Category';
$string['newcategory'] = 'New category';
$string['no'] = 'No';
$string['nocategories'] = 'Grade categories could not be added or found for this course';
+$string['nocategoryname'] = 'No category name was given.';
$string['nocategoryview'] = 'No category to view by';
$string['nogradeletters'] = 'No grade letters set';
$string['nogradesreturned'] = 'No grades returned';
$string['nomode'] = 'NA';
$string['nonnumericweight'] = 'Received non-numeric value for';
$string['nonweightedpct'] = 'non-weighted %%';
+$string['noselectedcategories'] = 'no categories were selected.';
+$string['noselecteditems'] = 'no items were selected.';
$string['notteachererror'] = 'You must be a teacher to use this feature.';
$string['pctoftotalgrade'] = '%% of total grade';
$string['percent'] = 'Percent';
$string['writinggradebookinfo'] = 'Writing Gradebook settings';
$string['yes'] = 'Yes';
$string['yourgrade'] = 'Your grade';
-
?>
<FIELD NAME="itemnumber" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Can be used to distinguish multiple grades for an activity" PREVIOUS="iteminstance" NEXT="iteminfo"/>
<FIELD NAME="iteminfo" TYPE="text" LENGTH="medium" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="Info and notes about this item XXX" PREVIOUS="itemnumber" NEXT="idnumber"/>
<FIELD NAME="idnumber" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="Arbitrary idnumber provided by the module responsible" PREVIOUS="iteminfo" NEXT="gradetype"/>
- <FIELD NAME="gradetype" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="0 = value, 1 = scale, 2 = text" PREVIOUS="idnumber" NEXT="grademax"/>
+ <FIELD NAME="gradetype" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="1" SEQUENCE="false" ENUM="false" COMMENT="0 = value, 1 = scale, 2 = text" PREVIOUS="idnumber" NEXT="grademax"/>
<FIELD NAME="grademax" TYPE="number" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="100" SEQUENCE="false" ENUM="false" DECIMALS="5" COMMENT="What is the maximum allowable grade?" PREVIOUS="gradetype" NEXT="grademin"/>
<FIELD NAME="grademin" TYPE="number" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" DECIMALS="5" COMMENT="What is the minimum allowable grade?" PREVIOUS="grademax" NEXT="scaleid"/>
<FIELD NAME="scaleid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="If this grade is based on a scale, which one is it?" PREVIOUS="grademin" NEXT="outcomeid"/>
// Launch add field deleted
$result = $result && add_field($table, $field);
}
+
if ($result && $oldversion < 2007060500) {
/// Launch add key usermodified
$result = $result && add_key($table, $key);
}
+
+ if ($result && $oldversion < 2007060501) {
+ /// Changing the default of field gradetype on table grade_items to 1
+ $table = new XMLDBTable('grade_items');
+ $field = new XMLDBField('gradetype');
+ $field->setAttributes(XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '1', 'idnumber');
+
+ /// Launch change of default for field gradetype
+ $result = $result && change_field_default($table, $field);
+ }
+
return $result;
}
}
/**
- * This method checks whether an existing child exists for this
- * category. If the new child is of a different type, the method will return false (not allowed).
- * Otherwise it will return true.
+ * Checks whether an existing child exists for this category. If the new child is of a
+ * different type, the method will return false (not allowed). Otherwise it will return true.
* @param object $child This must be a complete object, not a stdClass
* @return boolean Success or failure
*/
* A number of constraints are necessary:
* - The children must all be of the same type and at the same level
* - The children cannot already be top categories
- * - The children cannot already have a top categorya
* - The children all belong to the same course
* @param array $children An array of fully instantiated grade_category OR grade_item objects
*
function set_as_parent($children) {
global $CFG;
+ if (empty($children) || !is_array($children)) {
+ debugging("Passed an empty or non-array variable to grade_category::set_as_parent()");
+ return false;
+ }
+
// Check type and sortorder of first child
$first_child = current($children);
$first_child_type = get_class($first_child);
debugging("Violated constraint: Attempted to set a category over children which are already top categories.");
return false;
}
- if ($first_child_type == 'grade_item') {
- $child->load_category();
- if (!empty($child->category->parent)) {
- debugging("Violated constraint: Attempted to set a category over children that already have a top category.");
- return false;
- }
- } elseif ($first_child_type == 'grade_category') {
+
+ if ($first_child_type == 'grade_category') {
if (!empty($child->parent)) {
debugging("Violated constraint: Attempted to set a category over children that already have a top category.");
return false;
}
}
+ // If not set, generate an idnumber from itemmodule and iteminstance
+ if (empty($this->idnumber)) {
+ if (!empty($this->itemmodule) && !empty($this->iteminstance)) {
+ $this->idnumber = "$this->itemmodule.$this->iteminstance";
+ } else { // No itemmodule or iteminstance, generate a random idnumber
+ $this->idnumber = rand(0,9999999999); // TODO replace rand() with proper random generator
+ }
+ }
+
$result = parent::insert();
// Notify parent category of need to update. Note that a grade_item may not have a categoryid.
* @param array $tree
*/
function grade_tree($courseid=NULL, $include_grades=false, $tree=NULL) {
- global $USER;
+ if (empty($courseid)) {
+ // empty object, do nothing
+ } else {
+ if ($courseid == 0) {
+ $courseid = null;
+ }
- $this->courseid = $courseid;
- $this->include_grades = $include_grades;
- $this->commonvars = "&sesskey=$USER->sesskey&courseid=$this->courseid";
+ global $USER;
- if (!empty($tree)) {
- $this->tree_array = $tree;
- } else {
- $this->tree_array = $this->get_tree();
- }
-
- if (!empty($this->tree_array)) {
- $this->first_sortorder = key($this->tree_array);
- $this->renumber();
+ $this->courseid = $courseid;
+ $this->include_grades = $include_grades;
+ $this->commonvars = "&sesskey=$USER->sesskey&courseid=$this->courseid";
+
+ if (!empty($tree)) {
+ $this->tree_array = $tree;
+ } else {
+ $this->tree_array = $this->get_tree();
+ }
+
+ if (!empty($this->tree_array)) {
+ $this->first_sortorder = key($this->tree_array);
+ $this->renumber();
+ }
}
}
foreach ($elements as $sortorder => $element) {
$object = $element['object'];
- if (empty($element->next_sortorder)) {
- $element->next_sortorder = null;
- }
-
$object_name = $object->get_name();
$object_class = get_class($object);
$object_parent = $object->get_parent_id();
define('GRADE_CHILDTYPE_CAT', 1);
define('GRADE_ITEM', 0); // Used to compare class names with CHILDTYPE values
define('GRADE_CATEGORY', 1); // Used to compare class names with CHILDTYPE values
-define('GRADE_TYPE_VALUE', 0);
-define('GRADE_TYPE_SCALE', 1);
-define('GRADE_TYPE_TEXT', 2);
+define('GRADE_TYPE_NONE', 0);
+define('GRADE_TYPE_VALUE', 1);
+define('GRADE_TYPE_SCALE', 2);
+define('GRADE_TYPE_TEXT', 3);
require_once($CFG->libdir . '/grade/grade_category.php');
require_once($CFG->libdir . '/grade/grade_item.php');
// Generate 3 random data sets
$grade_sets = array();
-
+
for ($i = 0; $i < 3; $i++) {
for ($j = 0; $j < 200; $j++) {
$grade_sets[$i][] = $this->generate_random_raw_grade(new grade_item($this->grade_items[$i]), $j);
}
- }
+ }
$aggregated_grades = $category->aggregate_grades($grade_sets);
$this->assertEqual(200, count($aggregated_grades));
$this->assertFalse($grade_category->set_as_parent(array($child1)));
$CFG->debug = $debuglevel;
- // 3. Child already has a top category
+ // 3. Children belong to different courses
$child1 = new grade_item($this->grade_items[0]);
+ $child2 = new grade_item($this->grade_items[1]);
+ $child2->courseid = 543;
$CFG->debug = 2;
- $this->assertFalse($grade_category->set_as_parent(array($child1)));
+ $this->assertFalse($grade_category->set_as_parent(array($child1, $child2)));
$CFG->debug = $debuglevel;
// Now test setting parent correctly
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2007060500; // YYYYMMDD = date
+ $version = 2007060501; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.9 dev'; // Human-friendly version name