mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
improved hiding support in grade/
This commit is contained in:
parent
e3fa6587ee
commit
f60c61b1b2
11 changed files with 98 additions and 60 deletions
|
@ -1053,22 +1053,24 @@ class grade_category extends grade_object {
|
|||
* Sets the grade_item's hidden variable and updates the grade_item.
|
||||
* Method named after grade_item::set_hidden().
|
||||
* @param int $hidden 0, 1 or a timestamp int(10) after which date the item will be hidden.
|
||||
* @param boolean $cascade apply to child objects too
|
||||
* @return void
|
||||
*/
|
||||
function set_hidden($hidden) {
|
||||
function set_hidden($hidden, $cascade=false) {
|
||||
$this->load_grade_item();
|
||||
$this->grade_item->set_hidden($hidden);
|
||||
if ($children = grade_item::fetch_all(array('categoryid'=>$this->id))) {
|
||||
foreach($children as $child) {
|
||||
$child->set_hidden($hidden);
|
||||
if ($cascade) {
|
||||
if ($children = grade_item::fetch_all(array('categoryid'=>$this->id))) {
|
||||
foreach($children as $child) {
|
||||
$child->set_hidden($hidden, $cascade);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($children = grade_category::fetch_all(array('parent'=>$this->id))) {
|
||||
foreach($children as $child) {
|
||||
$child->set_hidden($hidden);
|
||||
if ($children = grade_category::fetch_all(array('parent'=>$this->id))) {
|
||||
foreach($children as $child) {
|
||||
$child->set_hidden($hidden, $cascade);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -356,24 +356,49 @@ class grade_grade extends grade_object {
|
|||
}
|
||||
|
||||
/**
|
||||
* Check grade lock status. Uses both grade item lock and grade lock.
|
||||
* Internally any date in hidden field (including future ones) means hidden,
|
||||
* the date is stored for logging purposes only.
|
||||
*
|
||||
* @param object $grade_item An optional grade_item given to avoid having to reload one from the DB
|
||||
* Check grade hidden status. Uses data from both grade item and grade.
|
||||
* @return boolean true if hidden, false if not
|
||||
*/
|
||||
function is_hidden($grade_item=null) {
|
||||
$this->load_grade_item($grade_item);
|
||||
function is_hidden() {
|
||||
$this->load_grade_item();
|
||||
|
||||
return $this->hidden == 1 or $this->hidden > time() or $this->grade_item->is_hidden();
|
||||
return $this->hidden == 1 or ($this->hidden != 0 and $this->hidden > time()) or $this->grade_item->is_hidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check grade hidden status. Uses data from both grade item and grade.
|
||||
* @return int 0 means visible, 1 hidden always, timestamp hidden until
|
||||
*/
|
||||
function get_hidden() {
|
||||
$this->load_grade_item();
|
||||
|
||||
$item_hidden = $this->grade_item->get_hidden();
|
||||
|
||||
if ($item_hidden == 1) {
|
||||
return 1;
|
||||
|
||||
} else if ($item_hidden == 0) {
|
||||
return $this->hidden;
|
||||
|
||||
} else {
|
||||
if ($this->hidden == 0) {
|
||||
return $item_hidden;
|
||||
} else if ($this->hidden == 1) {
|
||||
return 1;
|
||||
} else if ($this->hidden > $item_hidden) {
|
||||
return $this->hidden;
|
||||
} else {
|
||||
return $item_hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the hidden status of grade, 0 mean visible, 1 always hidden, number means date to hide until.
|
||||
* @param boolean $cascade ignored
|
||||
* @param int $hidden new hidden status
|
||||
*/
|
||||
function set_hidden($hidden) {
|
||||
function set_hidden($hidden, $cascade=false) {
|
||||
$this->hidden = $hidden;
|
||||
$this->update();
|
||||
}
|
||||
|
|
|
@ -514,41 +514,37 @@ class grade_item extends grade_object {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the hidden state of this grade_item (if the grade_item is hidden OR no specific
|
||||
* $userid is given) or the hidden state of a specific grade within this item if a specific
|
||||
* $userid is given and the grade_item is unhidden.
|
||||
*
|
||||
* @param int $userid
|
||||
* Returns the hidden state of this grade_item
|
||||
* @return boolean hidden state
|
||||
*/
|
||||
function is_hidden($userid=NULL) {
|
||||
if ($this->hidden == 1 or $this->hidden > time()) {
|
||||
return true;
|
||||
}
|
||||
return ($this->hidden == 1 or ($this->hidden != 0 and $this->hidden > time()));
|
||||
}
|
||||
|
||||
if (!empty($userid)) {
|
||||
if ($grade = grade_grade::fetch(array('itemid'=>$this->id, 'userid'=>$userid))) {
|
||||
$grade->grade_item =& $this; // prevent db fetching of cached grade_item
|
||||
return $grade->is_hidden();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
/**
|
||||
* Check grade item hidden status.
|
||||
* @return int 0 means visible, 1 hidden always, timestamp hidden until
|
||||
*/
|
||||
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
|
||||
*/
|
||||
function set_hidden($hidden) {
|
||||
function set_hidden($hidden, $cascade=false) {
|
||||
$this->hidden = $hidden;
|
||||
$this->update();
|
||||
|
||||
if ($grades = grade_grade::fetch_all(array('itemid'=>$this->id))) {
|
||||
foreach($grades as $grade) {
|
||||
$grade->grade_item =& $this;
|
||||
$grade->set_hidden($hidden);
|
||||
if ($cascade) {
|
||||
if ($grades = grade_grade::fetch_all(array('itemid'=>$this->id))) {
|
||||
foreach($grades as $grade) {
|
||||
$grade->grade_item =& $this;
|
||||
$grade->set_hidden($hidden, $cascade);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue