1441 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace report_outline\output;
|
|
|
18 |
|
|
|
19 |
use core_report\output\coursestructure;
|
|
|
20 |
use course_modinfo;
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* Activities list page.
|
|
|
24 |
*
|
|
|
25 |
* @package report_outline
|
|
|
26 |
* @copyright 2024 Amaia Anabitarte <amaia@moodle.com>
|
|
|
27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
28 |
*/
|
|
|
29 |
class activitieslist extends coursestructure {
|
|
|
30 |
/**
|
|
|
31 |
* Constructor
|
|
|
32 |
*
|
|
|
33 |
* @param course_modinfo $modinfo
|
|
|
34 |
* @param array $views Views information for activity and users.
|
|
|
35 |
* @param bool $showlastaccess Whether the last access should be shown or not.
|
|
|
36 |
* @param int $minlog The minimum log time is computed.
|
|
|
37 |
* @param bool $showblogs Whether related blog entries should be shown or not.
|
|
|
38 |
*/
|
|
|
39 |
public function __construct(
|
|
|
40 |
course_modinfo $modinfo,
|
|
|
41 |
/** @var array $views Views information for activity and users. */
|
|
|
42 |
protected array $views,
|
|
|
43 |
/** @var bool $showlastaccess Whether the last access should be shown or not. */
|
|
|
44 |
protected bool $showlastaccess = true,
|
|
|
45 |
/** @var int $minlog The minimum log time is computed. */
|
|
|
46 |
protected int $minlog = 0,
|
|
|
47 |
/** @var bool $showblogs Whether related blog entries should be shown or not. */
|
|
|
48 |
protected bool $showblogs = true,
|
|
|
49 |
) {
|
|
|
50 |
$this->modinfo = $modinfo;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Exports the data.
|
|
|
55 |
*
|
|
|
56 |
* @param \renderer_base $output
|
|
|
57 |
* @return array|\stdClass
|
|
|
58 |
*/
|
|
|
59 |
public function export_for_template(\renderer_base $output) {
|
|
|
60 |
$table = parent::export_for_template($output);
|
|
|
61 |
$table['id'] = 'outlinereport';
|
|
|
62 |
$data = [
|
|
|
63 |
'minlog' => userdate($this->minlog),
|
|
|
64 |
'table' => $table,
|
|
|
65 |
];
|
|
|
66 |
|
|
|
67 |
return $data;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* Exports the headers for report table.
|
|
|
72 |
*
|
|
|
73 |
* @param \renderer_base $output
|
|
|
74 |
* @return array
|
|
|
75 |
*/
|
|
|
76 |
protected function export_headers(\renderer_base $output): array {
|
|
|
77 |
$headers = parent::export_headers($output);
|
|
|
78 |
$headers[] = get_string('views');
|
|
|
79 |
|
|
|
80 |
if ($this->showblogs) {
|
|
|
81 |
$headers[] = get_string('relatedblogentries', 'blog');
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
if ($this->showlastaccess) {
|
|
|
85 |
$headers[] = get_string('lastaccess');
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
return $headers;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* Exports the data for a single activity.
|
|
|
93 |
*
|
|
|
94 |
* @param \renderer_base $output
|
|
|
95 |
* @param \cm_info $cm
|
|
|
96 |
* @param bool $indelegated Whether the activity is part of a delegated section or not.
|
|
|
97 |
* @return array
|
|
|
98 |
*/
|
|
|
99 |
public function export_activity_data(\renderer_base $output, \cm_info $cm, bool $indelegated = false): array {
|
|
|
100 |
global $CFG;
|
|
|
101 |
|
|
|
102 |
$data = parent::export_activity_data($output, $cm, $indelegated);
|
|
|
103 |
if (empty($data) || !in_array('cells', $data)) {
|
|
|
104 |
return [];
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
if (!empty($this->views[$cm->id]->numviews)) {
|
|
|
108 |
$numviewscell = get_string('numviews', 'report_outline', $this->views[$cm->id]);
|
|
|
109 |
} else {
|
|
|
110 |
$numviewscell = '-';
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
$data['cells'][] = [
|
|
|
114 |
'activityclass' => 'numviews',
|
|
|
115 |
'text' => $numviewscell,
|
|
|
116 |
];
|
|
|
117 |
|
|
|
118 |
if ($this->showblogs) {
|
|
|
119 |
$cell = ['activityclass' => 'blog'];
|
|
|
120 |
require_once($CFG->dirroot.'/blog/lib.php');
|
|
|
121 |
if ($blogcount = blog_get_associated_count($cm->get_course()->id, $cm->id)) {
|
|
|
122 |
$blogurl = new \moodle_url('/blog/index.php', ['modid' => $cm->id]);
|
|
|
123 |
$cell['link'] = new \action_link($blogurl, $blogcount);
|
|
|
124 |
} else {
|
|
|
125 |
$cell['text'] = '-';
|
|
|
126 |
}
|
|
|
127 |
$data['cells'][] = $cell;
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
if ($this->showlastaccess) {
|
|
|
131 |
if (isset($this->views[$cm->id]->lasttime)) {
|
|
|
132 |
$timeago = format_time(time() - $this->views[$cm->id]->lasttime);
|
|
|
133 |
$lastaccesscell = userdate($this->views[$cm->id]->lasttime)." ($timeago)";
|
|
|
134 |
} else {
|
|
|
135 |
$lastaccesscell = '';
|
|
|
136 |
}
|
|
|
137 |
$data['cells'][] = [
|
|
|
138 |
'activityclass' => 'lastaccess',
|
|
|
139 |
'text' => $lastaccesscell,
|
|
|
140 |
];
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
return $data;
|
|
|
144 |
}
|
|
|
145 |
}
|