From: Andrew Davis Date: Mon, 11 Jan 2010 07:35:40 +0000 (+0000) Subject: grader report MDL-19704 Added ability to hide course and category totals without... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a25bb902f043c32e8f7d30018221ed9ea0504433;p=moodle.git grader report MDL-19704 Added ability to hide course and category totals without hiding anything else --- diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index abf1f7f0c9..8f1e990ba5 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2857,6 +2857,17 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); upgrade_main_savepoint($result, 2010010601); } + if ($result && $oldversion < 2010010601.01) { + $table = new xmldb_table('grade_categories'); + $field = new xmldb_field('hidden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0); + + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + upgrade_main_savepoint($result, 2010010601.01); + } + return $result; } diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index fac2496382..7447c83ff5 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -45,7 +45,7 @@ class grade_category extends grade_object { */ public $required_fields = array('id', 'courseid', 'parent', 'depth', 'path', 'fullname', 'aggregation', 'keephigh', 'droplow', 'aggregateonlygraded', 'aggregateoutcomes', - 'aggregatesubcats', 'timecreated', 'timemodified'); + 'aggregatesubcats', 'timecreated', 'timemodified', 'hidden'); /** * The course this category belongs to. @@ -1501,26 +1501,6 @@ class grade_category extends grade_object { return $result; } - /** - * Returns the hidden state/date of the associated grade_item. This method is also available in - * grade_item. - * - * @return boolean - */ - public function is_hidden() { - $this->load_grade_item(); - return $this->grade_item->is_hidden(); - } - - /** - * Check grade hidden status. Uses data from both grade item and grade. - * @return boolean true if hiddenuntil, false if not - */ - public function is_hiddenuntil() { - $this->load_grade_item(); - return $this->grade_item->is_hiddenuntil(); - } - /** * Sets the grade_item's hidden variable and updates the grade_item. * Method named after grade_item::set_hidden(). @@ -1530,7 +1510,10 @@ class grade_category extends grade_object { */ public function set_hidden($hidden, $cascade=false) { $this->load_grade_item(); + //this hides the associated grade item (the course total) $this->grade_item->set_hidden($hidden); + //this hides the category itself and everything it contains + parent::set_hidden($hidden, $cascade); if ($cascade) { diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 1cd11dd856..2b9c713cf9 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -214,12 +214,6 @@ class grade_item extends grade_object { */ public $decimals = null; - /** - * 0 if visible, 1 always hidden or date not visible until - * @var int $hidden - */ - public $hidden = 0; - /** * Grade item lock flag. Empty if not locked, locked if any value present, usually date when item was locked. Locking prevents updating. * @var int $locked @@ -559,30 +553,6 @@ class grade_item extends grade_object { return $this->locktime; } - /** - * Returns the hidden state of this grade_item - * @return boolean hidden state - */ - public function is_hidden() { - return ($this->hidden == 1 or ($this->hidden != 0 and $this->hidden > time())); - } - - /** - * Check grade hidden status. Uses data from both grade item and grade. - * @return boolean true if hiddenuntil, false if not - */ - public function is_hiddenuntil() { - return $this->hidden > 1; - } - - /** - * Check grade item hidden status. - * @return int 0 means visible, 1 hidden always, timestamp hidden until - */ - public function get_hidden() { - return $this->hidden; - } - /** * Set the hidden status of grade_item and all grades, 0 mean visible, 1 always hidden, number means date to hide until. * @param int $hidden new hidden status @@ -590,8 +560,7 @@ class grade_item extends grade_object { * @return void */ public function set_hidden($hidden, $cascade=false) { - $this->hidden = $hidden; - $this->update(); + parent::set_hidden($hidden, $cascade); if ($cascade) { if ($grades = grade_grade::fetch_all(array('itemid'=>$this->id))) { diff --git a/lib/grade/grade_object.php b/lib/grade/grade_object.php index 72c9ec618e..7a48965e91 100644 --- a/lib/grade/grade_object.php +++ b/lib/grade/grade_object.php @@ -34,7 +34,7 @@ abstract class grade_object { * Array of required table fields, must start with 'id'. * @var array $required_fields */ - public $required_fields = array('id', 'timecreated', 'timemodified'); + public $required_fields = array('id', 'timecreated', 'timemodified', 'hidden'); /** * Array of optional fields with default values - usually long text information that is not always needed. @@ -61,6 +61,12 @@ abstract class grade_object { */ public $timemodified; + /** + * 0 if visible, 1 always hidden or date not visible until + * @var int $hidden + */ + var $hidden = 0; + /** * Constructor. Optionally (and by default) attempts to fetch corresponding row from DB. * @param array $params an array with required parameters for this grade object. @@ -354,4 +360,33 @@ abstract class grade_object { */ function notify_changed($deleted) { } + + /** + * Returns the hidden state of this grade_item + * @return boolean hidden state + */ + function is_hidden() { + return ($this->hidden == 1 or ($this->hidden != 0 and $this->hidden > time())); + } + + /** + * Check grade hidden status. Uses data from both grade item and grade. + * @return boolean true if hiddenuntil, false if not + */ + function is_hiddenuntil() { + return $this->hidden > 1; + } + + /** + * Check grade item hidden status. + * @return int 0 means visible, 1 hidden always, timestamp hidden until + */ + function get_hidden() { + return $this->hidden; + } + + function set_hidden($hidden, $cascade=false) { + $this->hidden = $hidden; + $this->update(); + } } diff --git a/version.php b/version.php index cd604308c0..0a03e2ee1e 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2010010601; // YYYYMMDD = date of the last version bump + $version = 2010010601.01; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20100111)'; // Human-friendly version name