return $count;
}
+ /**
+ * 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_hiding($update_final=false, $new_state=NULL) {
+ $this->hidden = !$this->hidden;
+
+ if (!empty($new_state)) {
+ $this->hidden = $new_state;
+ }
+
+ if (!$this->update()) {
+ return false;
+ }
+
+ $count = 0;
+
+ if ($update_final) {
+ $this->load_final();
+ foreach ($this->grade_grades_final as $id => $final) {
+ $final->hidden = $this->hidden;
+ if (!$final->update()) {
+ return false;
+ }
+ $count++;
+ }
+ $this->load_final();
+ }
+
+ return $count;
+ }
+
+
/**
* Performs the necessary calculations on the grades_final referenced by this grade_item,
* and stores the results in grade_grades_final. Performs this for only one userid if
$this->assertTrue($grade_item->grade_grades_final[3]->locked);
}
+ function test_grade_item_toggle_hiding() {
+ $grade_item = new grade_item($this->grade_items[0]);
+ $this->assertTrue(method_exists($grade_item, 'toggle_hiding'));
+
+ $this->assertFalse($grade_item->hidden);
+ $this->assertEqual(0, $grade_item->toggle_hiding());
+ $this->assertTrue($grade_item->hidden);
+ $grade_item->load_final();
+ $this->assertFalse($grade_item->grade_grades_final[1]->hidden);
+
+ $grade_item->hidden = false;
+ $this->assertEqual(3, $grade_item->toggle_hiding(true));
+ $this->assertTrue($grade_item->hidden);
+ $this->assertTrue($grade_item->grade_grades_final[1]->hidden);
+ $this->assertTrue($grade_item->grade_grades_final[2]->hidden);
+ $this->assertTrue($grade_item->grade_grades_final[3]->hidden);
+ }
+
// GRADE_CATEGORY OBJECT
function test_grade_category_construct() {