Optimising the grader report

This commit is contained in:
nicolasconnault 2007-07-13 19:02:40 +00:00
parent ed8bebce5a
commit 388234f4c5
3 changed files with 120 additions and 76 deletions

View file

@ -146,10 +146,13 @@ class grade_grades extends grade_object {
/**
* Loads the grade_item object referenced by $this->itemid and saves it as $this->grade_item for easy access.
* @param object $grade_item An optional grade_item given to avoid having to reload one from the DB
* @return object grade_item.
*/
function load_grade_item() {
if (empty($this->grade_item) && !empty($this->itemid)) {
function load_grade_item($grade_item=null) {
if (!empty($grade_item) && get_class($grade_item) == 'grade_item') {
$this->grade_item = $grade_item;
} elseif (empty($this->grade_item) && !empty($this->itemid)) {
$this->grade_item = grade_item::fetch(array('id'=>$this->itemid));
}
return $this->grade_item;
@ -157,15 +160,15 @@ class grade_grades extends grade_object {
/**
* Is grading object editable?
* @param object $grade_item An optional grade_item given to avoid having to reload one from the DB
* @return boolean
*/
function is_editable() {
if ($this->is_locked()) {
function is_editable($grade_item=null) {
if ($this->is_locked($grade_item)) {
return false;
}
$grade_item = $this->load_grade_item();
$grade_item = $this->load_grade_item($grade_item);
if ($grade_item->gradetype == GRADE_TYPE_NONE) {
return false;
@ -179,10 +182,11 @@ class grade_grades extends grade_object {
* Internally any date in locked field (including future ones) means locked,
* 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
* @return boolean true if locked, false if not
*/
function is_locked() {
$this->load_grade_item();
function is_locked($grade_item=null) {
$this->load_grade_item($grade_item);
return !empty($this->locked) or $this->grade_item->is_locked();
}
@ -192,7 +196,7 @@ class grade_grades extends grade_object {
}
/**
* Lock/unlopck this grade.
* Lock/unlock this grade.
*
* @param boolean $lockstate true means lock, false unlock grade
* @return boolean true if sucessful, false if can not set new lock state for grade
@ -277,10 +281,11 @@ class grade_grades extends grade_object {
* 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
* @return boolean true if hidden, false if not
*/
function is_hidden() {
$this->load_grade_item();
function is_hidden($grade_item=null) {
$this->load_grade_item($grade_item);
return $this->hidden == 1 or $this->hidden > time() or $this->grade_item->is_hidden();
}