improved hiding support in grade/

This commit is contained in:
skodak 2007-08-09 16:19:06 +00:00
parent e3fa6587ee
commit f60c61b1b2
11 changed files with 98 additions and 60 deletions

View file

@ -38,7 +38,7 @@ switch ($action) {
if ($type == 'grade' and empty($object->id)) {
$object->insert();
}
$object->set_hidden(1);
$object->set_hidden(1, true);
}
break;
@ -50,7 +50,7 @@ switch ($action) {
if ($type == 'grade' and empty($object->id)) {
$object->insert();
}
$object->set_hidden(0);
$object->set_hidden(0, true);
}
break;

View file

@ -90,11 +90,15 @@ if ($grade = get_record('grade_grades', 'itemid', $grade_item->id, 'userid', $us
if ($grade->hidden > 1) {
$grade->hiddenuntil = $grade->hidden;
$grade->hidden = 0;
$grade->hidden = 1;
} else {
$grade->hiddenuntil = 0;
}
if ($grade_item->is_hidden()) {
$grade->hidden = 1;
}
if ($grade_item->is_locked()) {
$grade->locked = 1;
}
@ -131,14 +135,21 @@ if ($mform->is_cancelled()) {
$grade_grade->grade_item =& $grade_item; // no db fetching
if (has_capability('moodle/grade:manage', $context) or has_capability('moodle/grade:hide', $context)) {
if (empty($data->hidden)) {
if (empty($data->hiddenuntil)) {
$grade_grade->set_hidden(0);
$hidden = empty($data->hidden) ? 0: $data->hidden;
$hiddenuntil = empty($data->hiddenuntil) ? 0: $data->hiddenuntil;
if ($grade_item->is_hidden()) {
if ($old_grade_grade->hidden == 1 and $hiddenuntil == 0) {
//nothing to do - grade was originally hidden, we want to keep it that way
} else {
$grade_grade->set_hidden($data->hiddenuntil);
$grade_grade->set_hidden($hiddenuntil);
}
} else {
$grade_grade->set_hidden(1);
if ($hiddenuntil) {
$grade_grade->set_hidden($hiddenuntil);
} else {
$grade_grade->set_hidden($hidden); // checkbox data might be undefined
}
}
}

View file

@ -59,7 +59,7 @@ class edit_grade_form extends moodleform {
$mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade'));
$mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true));
$mform->setHelpButton('hiddenuntil', array('hiddenuntil', get_string('hiddenuntil', 'grades'), 'grade'));
$mform->disabledIf('hiddenuntil', 'hidden', 'checked');
$mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked');
/// locking
$mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades'));
@ -136,6 +136,10 @@ class edit_grade_form extends moodleform {
$old_grade_grade = new grade_grade(array('itemid'=>$grade_item->id, 'userid'=>$userid));
if ($grade_item->is_hidden()) {
$mform->hardFreeze('hidden');
}
if ($old_grade_grade->is_locked()) {
if ($grade_item->is_locked()) {
$mform->hardFreeze('locked');

View file

@ -78,11 +78,11 @@ if ($data = $mform->get_data(false)) {
$grade_item->update();
}
// update hiding flag (in grades too if needed)
if (empty($hidden)) {
$grade_item->set_hidden($hiddenuntil);
// update hiding flag
if ($hiddenuntil) {
$grade_item->set_hidden($hiddenuntil, false);
} else {
$grade_item->set_hidden(1);
$grade_item->set_hidden($hidden, false);
}
$grade_item->set_locktime($locktime); // locktime first - it might be removed when unlocking

View file

@ -89,7 +89,7 @@ class edit_item_form extends moodleform {
$mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade'));
$mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true));
$mform->setHelpButton('hiddenuntil', array('hiddenuntil', get_string('hiddenuntil', 'grades'), 'grade'));
$mform->disabledIf('hiddenuntil', 'hidden', 'checked');
$mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked');
/// locking
$mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades'));

View file

@ -130,11 +130,11 @@ if ($data = $mform->get_data(false)) {
$grade_item->update();
}
// update hiding flag (in grades too if needed)
if (empty($hidden)) {
$grade_item->set_hidden($hiddenuntil);
// update hiding flag
if ($hiddenuntil) {
$grade_item->set_hidden($hiddenuntil, false);
} else {
$grade_item->set_hidden(1);
$grade_item->set_hidden($hidden, false);
}
$grade_item->set_locktime($locktime); // locktime first - it might be removed when unlocking

View file

@ -57,7 +57,7 @@ class edit_outcomeitem_form extends moodleform {
$mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade'));
$mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true));
$mform->setHelpButton('hiddenuntil', array('hiddenuntil', get_string('hiddenuntil', 'grades'), 'grade'));
$mform->disabledIf('hiddenuntil', 'hidden', 'checked');
$mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked');
//locking
$mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades'));

View file

@ -825,9 +825,9 @@ class grade_tree {
$icon = 'show';
$tooltip = '';
if ($element['object']->hidden > 1) { // Change the icon and add a tooltip showing the date
if ($element['type'] != 'category' and $element['object']->get_hidden() > 1) { // Change the icon and add a tooltip showing the date
$icon = 'hiddenuntil';
$tooltip = userdate($element['object']->hidden);
$tooltip = userdate($element['object']->get_hidden());
}
$url = $CFG->wwwroot.'/grade/edit/tree/action.php?id='.$this->courseid.'&action=show&sesskey='.sesskey()

View file

@ -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);
}
}
}
}
}
?>

View file

@ -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();
}

View file

@ -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);
}
}
}
}