2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Attendance module renderering helpers
20 * @package mod_attendance
21 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
27 require_once(dirname(__FILE__
).'/renderables.php');
30 * class Template method for generating user's session's cells
32 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 class user_sessions_cells_generator
{
36 protected $cells = array();
38 protected $reportdata;
41 public function __construct(attendance_report_data
$reportdata, $user) {
42 $this->reportdata
= $reportdata;
46 public function get_cells($remarks = false
) {
48 foreach ($this->reportdata
->sessions
as $sess) {
49 if (array_key_exists($sess->id
, $this->reportdata
->sessionslog
[$this->user
->id
])) {
50 $statusid = $this->reportdata
->sessionslog
[$this->user
->id
][$sess->id
]->statusid
;
51 if (array_key_exists($statusid, $this->reportdata
->statuses
)) {
52 $points = format_float($this->reportdata
->statuses
[$statusid]->grade
, 1, true
, true
);
53 $maxpoints = format_float($sess->maxpoints
, 1, true
, true
);
54 $this->construct_existing_status_cell($this->reportdata
->statuses
[$statusid]->acronym
.
55 " ({$points}/{$maxpoints})");
57 $this->construct_hidden_status_cell($this->reportdata
->allstatuses
[$statusid]->acronym
);
60 $this->construct_remarks_cell($this->reportdata
->sessionslog
[$this->user
->id
][$sess->id
]->remarks
);
63 if ($this->user
->enrolmentstart
> $sess->sessdate
) {
64 $starttext = get_string('enrolmentstart', 'attendance', userdate($this->user
->enrolmentstart
, '%d.%m.%Y'));
65 $this->construct_enrolments_info_cell($starttext);
66 } else if ($this->user
->enrolmentend
and $this->user
->enrolmentend
< $sess->sessdate
) {
67 $endtext = get_string('enrolmentend', 'attendance', userdate($this->user
->enrolmentend
, '%d.%m.%Y'));
68 $this->construct_enrolments_info_cell($endtext);
69 } else if (!$this->user
->enrolmentend
and $this->user
->enrolmentstatus
== ENROL_USER_SUSPENDED
) {
70 // No enrolmentend and ENROL_USER_SUSPENDED.
71 $suspendext = get_string('enrolmentsuspended', 'attendance', userdate($this->user
->enrolmentend
, '%d.%m.%Y'));
72 $this->construct_enrolments_info_cell($suspendext);
74 if ($sess->groupid
== 0 or array_key_exists($sess->groupid
, $this->reportdata
->usersgroups
[$this->user
->id
])) {
75 $this->construct_not_taken_cell('?');
77 $this->construct_not_existing_for_user_session_cell('');
81 $this->construct_remarks_cell('');
85 $this->finalize_cells();
90 protected function init_cells() {
94 protected function construct_existing_status_cell($text) {
95 $this->cells
[] = $text;
98 protected function construct_hidden_status_cell($text) {
99 $this->cells
[] = $text;
102 protected function construct_enrolments_info_cell($text) {
103 $this->cells
[] = $text;
106 protected function construct_not_taken_cell($text) {
107 $this->cells
[] = $text;
110 protected function construct_remarks_cell($text) {
111 $this->cells
[] = $text;
114 protected function construct_not_existing_for_user_session_cell($text) {
115 $this->cells
[] = $text;
118 protected function finalize_cells() {
123 * class Template method for generating user's session's cells in html
125 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
126 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
128 class user_sessions_cells_html_generator
extends user_sessions_cells_generator
{
131 protected function construct_existing_status_cell($text) {
132 $this->close_open_cell_if_needed();
133 $this->cells
[] = html_writer
::span($text, 'attendancestatus-'.$text);
136 protected function construct_hidden_status_cell($text) {
137 $this->cells
[] = html_writer
::tag('s', $text);
140 protected function construct_enrolments_info_cell($text) {
141 if (is_null($this->cell
)) {
142 $this->cell
= new html_table_cell($text);
143 $this->cell
->colspan
= 1;
145 if ($this->cell
->text
!= $text) {
146 $this->cells
[] = $this->cell
;
147 $this->cell
= new html_table_cell($text);
148 $this->cell
->colspan
= 1;
150 $this->cell
->colspan++
;
155 private function close_open_cell_if_needed() {
157 $this->cells
[] = $this->cell
;
162 protected function construct_not_taken_cell($text) {
163 $this->close_open_cell_if_needed();
164 $this->cells
[] = $text;
167 protected function construct_remarks_cell($text) {
174 // Format the remark.
175 $icon = $OUTPUT->pix_icon('i/info', '');
176 $remark = html_writer
::span($text, 'remarkcontent');
177 $remark = html_writer
::span($icon.$remark, 'remarkholder');
179 // Add it into the previous cell.
180 $markcell = array_pop($this->cells
);
181 $markcell .= ' '.$remark;
182 $this->cells
[] = $markcell;
185 protected function construct_not_existing_for_user_session_cell($text) {
186 $this->close_open_cell_if_needed();
187 $this->cells
[] = $text;
190 protected function finalize_cells() {
192 $this->cells
[] = $this->cell
;
198 * class Template method for generating user's session's cells in text
200 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
201 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
203 class user_sessions_cells_text_generator
extends user_sessions_cells_generator
{
204 private $enrolmentsinfocelltext;
206 protected function construct_hidden_status_cell($text) {
207 $this->cells
[] = '-'.$text;
210 protected function construct_enrolments_info_cell($text) {
211 if ($this->enrolmentsinfocelltext
!= $text) {
212 $this->enrolmentsinfocelltext
= $text;
213 $this->cells
[] = $text;
215 $this->cells
[] = '←';
220 function construct_session_time($datetime, $duration) {
221 $starttime = userdate($datetime, get_string('strftimehm', 'attendance'));
222 $endtime = userdate($datetime +
$duration, get_string('strftimehm', 'attendance'));
224 return $starttime . ($duration > 0 ?
' - ' . $endtime : '');
227 function construct_session_full_date_time($datetime, $duration) {
228 $sessinfo = userdate($datetime, get_string('strftimedmyw', 'attendance'));
229 $sessinfo .= ' '.construct_session_time($datetime, $duration);
234 function construct_user_data_stat($usersummary, $view) {
235 $stattable = new html_table();
236 $stattable->attributes
['class'] = 'attlist';
237 $row = new html_table_row();
238 $row->attributes
['class'] = 'normal';
239 $row->cells
[] = get_string('sessionscompleted', 'attendance') . ':';
240 $row->cells
[] = $usersummary->numtakensessions
;
241 $stattable->data
[] = $row;
243 $row = new html_table_row();
244 $row->attributes
['class'] = 'normal';
245 $row->cells
[] = get_string('pointssessionscompleted', 'attendance') . ':';
246 $row->cells
[] = format_float($usersummary->takensessionspoints
, 1, true
, true
) . ' / ' .
247 format_float($usersummary->takensessionsmaxpoints
, 1, true
, true
);
248 $stattable->data
[] = $row;
250 $row = new html_table_row();
251 $row->attributes
['class'] = 'normal';
252 $row->cells
[] = get_string('percentagesessionscompleted', 'attendance') . ':';
253 $row->cells
[] = format_float($usersummary->takensessionspercentage
* 100) . '%';
254 $stattable->data
[] = $row;
256 if ($view == ATT_VIEW_ALL
) {
257 $row = new html_table_row();
258 $row->attributes
['class'] = 'highlight';
259 $row->cells
[] = get_string('sessionstotal', 'attendance') . ':';
260 $row->cells
[] = $usersummary->numallsessions
;
261 $stattable->data
[] = $row;
263 $row = new html_table_row();
264 $row->attributes
['class'] = 'highlight';
265 $row->cells
[] = get_string('pointsallsessions', 'attendance') . ':';
266 $row->cells
[] = format_float($usersummary->takensessionspoints
, 1, true
, true
) . ' / ' .
267 format_float($usersummary->allsessionsmaxpoints
, 1, true
, true
);
268 $stattable->data
[] = $row;
270 $row = new html_table_row();
271 $row->attributes
['class'] = 'highlight';
272 $row->cells
[] = get_string('percentageallsessions', 'attendance') . ':';
273 $row->cells
[] = format_float($usersummary->allsessionspercentage
* 100) . '%';
274 $stattable->data
[] = $row;
276 $row = new html_table_row();
277 $row->attributes
['class'] = 'normal';
278 $row->cells
[] = get_string('maxpossiblepoints', 'attendance') . ':';
279 $row->cells
[] = format_float($usersummary->maxpossiblepoints
, 1, true
, true
) . ' / ' .
280 format_float($usersummary->allsessionsmaxpoints
, 1, true
, true
);
281 $stattable->data
[] = $row;
283 $row = new html_table_row();
284 $row->attributes
['class'] = 'normal';
285 $row->cells
[] = get_string('maxpossiblepercentage', 'attendance') . ':';
286 $row->cells
[] = format_float($usersummary->maxpossiblepercentage
* 100) . '%';
287 $stattable->data
[] = $row;
290 return html_writer
::table($stattable);
293 function construct_full_user_stat_html_table($attendance, $user) {
294 $summary = new mod_attendance_summary($attendance->id
, $user->id
);
295 return construct_user_data_stat($summary->get_all_sessions_summary_for($user->id
), ATT_VIEW_ALL
);