|
By dservos:
CONTRIB-496
* Added checking of capabilities for each statistic.
* Accounted for moodle/grade:viewhidden capability when gathering grades.
* Added more documenation.
* Cleaned up code a bit.
|
| 43 |
class grade_report_stats extends grade_report { |
class grade_report_stats extends grade_report { |
| 44 |
/** |
/** |
| 45 |
* Capability to view hidden items. |
* Capability to view hidden items. |
|
* TODO: Add a check for hidden items and grades. |
|
| 46 |
* @var bool $canviewhidden |
* @var bool $canviewhidden |
| 47 |
*/ |
*/ |
| 48 |
private $canviewhidden; |
private $canviewhidden; |
| 49 |
|
|
| 50 |
/** |
/** |
|
* Categories to be displayed based on report setting. |
|
|
* @var array $collapsed |
|
|
*/ |
|
|
private $collapsed = array(); |
|
|
|
|
|
/** |
|
| 51 |
* Grade objects of users in the course |
* Grade objects of users in the course |
| 52 |
* @var array $grades |
* @var array $grades |
| 53 |
*/ |
*/ |
| 98 |
|
|
| 99 |
$this->canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->course->id)); |
$this->canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->course->id)); |
| 100 |
|
|
|
/// Set categories to be displayed. |
|
|
if($this->get_pref('stats', 'aggregationview') == GRADE_REPORT_PREFERENCE_DEFAULT || $this->get_pref('stats', 'aggregationview') == GRADE_REPORT_AGGREGATION_VIEW_FULL) { |
|
|
$this->collapsed = array('aggregatesonly' => array(), 'gradesonly' => array()); |
|
|
} elseif($this->get_pref('stats', 'aggregationview') == GRADE_REPORT_AGGREGATION_VIEW_AGGREGATES_ONLY) { |
|
|
$this->collapsed = array('aggregatesonly' => array()); |
|
|
} elseif($this->get_pref('stats', 'aggregationview') == GRADE_REPORT_AGGREGATION_VIEW_GRADES_ONLY) { |
|
|
$this->collapsed = array('gradesonly' => array()); |
|
|
} else { |
|
|
$this->collapsed = array('aggregatesonly' => array(), 'gradesonly' => array()); |
|
|
} |
|
|
|
|
| 101 |
/// Set up urls |
/// Set up urls |
| 102 |
$this->baseurl = 'index.php?id=' . $this->courseid; |
$this->baseurl = 'index.php?id=' . $this->courseid; |
| 103 |
$this->pbarurl = 'index.php?id=' . $this->courseid; |
$this->pbarurl = 'index.php?id=' . $this->courseid; |
| 113 |
|
|
| 114 |
/// Set up Groups |
/// Set up Groups |
| 115 |
if ($this->get_pref('stats', 'showgroups') || is_null($this->get_pref('stats', 'showgroups'))) { |
if ($this->get_pref('stats', 'showgroups') || is_null($this->get_pref('stats', 'showgroups'))) { |
|
if(is_callable(array($this, 'setup_groups'))) { |
|
|
$this->setup_groups(); |
|
|
} else { |
|
| 116 |
$this->setup_groups(); |
$this->setup_groups(); |
| 117 |
} |
} |
|
} |
|
| 118 |
|
|
| 119 |
|
/// Load stats classes from ./statistics |
| 120 |
$this->load_stats(); |
$this->load_stats(); |
| 121 |
} |
} |
| 122 |
|
|
| 298 |
|
|
| 299 |
if(isset($this->grades[$id]) && !is_null($this->grades[$id])) { |
if(isset($this->grades[$id]) && !is_null($this->grades[$id])) { |
| 300 |
foreach ($this->grades[$id] as $grade) { |
foreach ($this->grades[$id] as $grade) { |
| 301 |
if( (($grade->is_hidden() && ($this->get_pref('stats', 'usehidden') || is_null($this->get_pref('stats', 'usehidden')))) || !$grade->is_hidden()) |
if( (($grade->is_hidden() && $this->canviewhidden && ($this->get_pref('stats', 'usehidden') || is_null($this->get_pref('stats', 'usehidden')))) || !$grade->is_hidden()) |
| 302 |
&& (($grade->is_locked() && ($this->get_pref('stats', 'uselocked') || is_null($this->get_pref('stats', 'uselocked')))) || !$grade->is_locked())) { |
&& (($grade->is_locked() && ($this->get_pref('stats', 'uselocked') || is_null($this->get_pref('stats', 'uselocked')))) || !$grade->is_locked())) { |
| 303 |
if($this->get_pref('stats', 'incompleasmin') && is_null($grade->finalgrade)) { |
if($this->get_pref('stats', 'incompleasmin') && is_null($grade->finalgrade)) { |
| 304 |
$this->finalgrades[$id][$i] = $item->grademin; |
$this->finalgrades[$id][$i] = $item->grademin; |
| 318 |
* Runs grades for each item threw the report functions |
* Runs grades for each item threw the report functions |
| 319 |
* of each stats class in $stats and stores the values in |
* of each stats class in $stats and stores the values in |
| 320 |
* reportedstats. |
* reportedstats. |
|
* TODO: Do not report on hidden items if the user can not see them. |
|
| 321 |
*/ |
*/ |
| 322 |
public function report_data() { |
public function report_data() { |
| 323 |
$this->reportedstats = array(); |
$this->reportedstats = array(); |
| 324 |
|
|
| 325 |
foreach(grade_report_stats::$stats as $name=>$stat) { |
foreach(grade_report_stats::$stats as $name=>$stat) { |
| 326 |
if($this->get_pref('stats', $name) || is_null($this->get_pref('stats', $name))) { |
if(($stat->capability == null || has_capability($stat->capability, $this->context)) && ($this->get_pref('stats', $name) || is_null($this->get_pref('stats', $name)))) { |
| 327 |
$this->reportedstats[$name] = array(); |
$this->reportedstats[$name] = array(); |
| 328 |
|
|
| 329 |
foreach($this->finalgrades as $itemid=>$item) { |
foreach($this->finalgrades as $itemid=>$item) { |