Skip to content

Commit

Permalink
grader report MDL-19704 Added ability to hide course and category tot…
Browse files Browse the repository at this point in the history
…als without hiding anything else
  • Loading branch information
Andrew Davis committed Jan 11, 2010
1 parent 086f0e6 commit a25bb90
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 55 deletions.
11 changes: 11 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2857,6 +2857,17 @@ function xmldb_main_upgrade($oldversion) {
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;
}

Expand Down
25 changes: 4 additions & 21 deletions lib/grade/grade_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1501,26 +1501,6 @@ public function set_locked($lockedstate, $cascade=false, $refresh=true) {
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().
Expand All @@ -1530,7 +1510,10 @@ public function is_hiddenuntil() {
*/
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) {

Expand Down
33 changes: 1 addition & 32 deletions lib/grade/grade_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -559,39 +553,14 @@ public function get_locktime() {
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
* @param boolean $cascade apply to child objects too
* @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))) {
Expand Down
37 changes: 36 additions & 1 deletion lib/grade/grade_object.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -354,4 +360,33 @@ public static function set_properties(&$instance, $params) {
*/
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();
}
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a25bb90

Please sign in to comment.