return $final->locked;
}
}
+
+ /**
+ * Locks or unlocks this grade_item and (optionally) all its associated final grades.
+ * @param boolean $update_final Whether to update final grades too
+ * @param boolean $new_state Optional new state. Will use inverse of current state otherwise.
+ * @return int Number of final grades changed, or false if error occurred during update.
+ */
+ function toggle_locking($update_final=false, $new_state=NULL) {
+ $this->locked = !$this->locked;
+
+ if (!empty($new_state)) {
+ $this->locked = $new_state;
+ }
+
+ if (!$this->update()) {
+ return false;
+ }
+
+ $count = 0;
+
+ if ($update_final) {
+ $this->load_final();
+ foreach ($this->grade_grades_final as $id => $final) {
+ $final->locked = $this->locked;
+ if (!$final->update()) {
+ return false;
+ }
+ $count++;
+ }
+ $this->load_final();
+ }
+
+ return $count;
+ }
/**
* Performs the necessary calculations on the grades_final referenced by this grade_item,
$this->assertEqual(4, $grade_item->adjust_grade($grade_raw));
}
+ function test_grade_item_toggle_locking() {
+ $grade_item = new grade_item($this->grade_items[0]);
+ $this->assertTrue(method_exists($grade_item, 'toggle_locking'));
+
+ $this->assertFalse($grade_item->locked);
+ $this->assertEqual(0, $grade_item->toggle_locking());
+ $this->assertTrue($grade_item->locked);
+ $grade_item->load_final();
+ $this->assertFalse($grade_item->grade_grades_final[1]->locked);
+
+ $grade_item->locked = false;
+ $this->assertEqual(3, $grade_item->toggle_locking(true));
+ $this->assertTrue($grade_item->locked);
+ $this->assertTrue($grade_item->grade_grades_final[1]->locked);
+ $this->assertTrue($grade_item->grade_grades_final[2]->locked);
+ $this->assertTrue($grade_item->grade_grades_final[3]->locked);
+ }
+
// GRADE_CATEGORY OBJECT
function test_grade_category_construct() {
function test_grade_category_get_children() {
$category = new grade_category($this->grade_categories[0]);
+ $this->assertTrue(method_exists($category, 'get_children'));
+
$children_array = $category->get_children(0);
$this->assertTrue(is_array($children_array));
$this->assertTrue(!empty($children_array[0]));
$this->assertTrue(isset($children_array[0]['object']));
$this->assertEqual($this->grade_items[0]->id, $children_array[0]['object']->id);
}
+
+ function test_grade_category_has_children() {
+ $category = new grade_category($this->grade_categories[0]);
+ $this->assertTrue(method_exists($category, 'has_children'));
+ $this->assertTrue($category->has_children());
+ $category = new grade_category();
+ $this->assertFalse($category->has_children());
+ }
// GRADE_CALCULATION OBJECT