}
if ($formdata->format === 'text') {
- exporttocsv($data, $filename);
+ attendance_exporttocsv($data, $filename);
} else {
- exporttotableed($data, $filename, $formdata->format);
+ attendance_exporttotableed($data, $filename, $formdata->format);
}
exit;
} else {
echo $OUTPUT->footer();
-function exporttotableed($data, $filename, $format) {
- global $CFG;
- if ($format === 'excel') {
- require_once("$CFG->libdir/excellib.class.php");
- $filename .= ".xls";
- $workbook = new MoodleExcelWorkbook("-");
- } else {
- require_once("$CFG->libdir/odslib.class.php");
- $filename .= ".ods";
- $workbook = new MoodleODSWorkbook("-");
- }
- // Sending HTTP headers.
- $workbook->send($filename);
- // Creating the first worksheet.
- $myxls = $workbook->add_worksheet('Attendances');
- // Format types.
- $formatbc = $workbook->add_format();
- $formatbc->set_bold(1);
-
- $myxls->write(0, 0, get_string('course'), $formatbc);
- $myxls->write(0, 1, $data->course);
- $myxls->write(1, 0, get_string('group'), $formatbc);
- $myxls->write(1, 1, $data->group);
-
- $i = 3;
- $j = 0;
- foreach ($data->tabhead as $cell) {
- // Merge cells if the heading would be empty (remarks column).
- if (empty($cell)) {
- $myxls->merge_cells($i, $j - 1, $i, $j);
- } else {
- $myxls->write($i, $j, $cell, $formatbc);
- }
- $j++;
- }
- $i++;
- $j = 0;
- foreach ($data->table as $row) {
- foreach ($row as $cell) {
- $myxls->write($i, $j++, $cell);
- }
- $i++;
- $j = 0;
- }
- $workbook->close();
-}
-
-function exporttocsv($data, $filename) {
- $filename .= ".txt";
-
- header("Content-Type: application/download\n");
- header("Content-Disposition: attachment; filename=\"$filename\"");
- header("Expires: 0");
- header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
- header("Pragma: public");
-
- echo get_string('course')."\t".$data->course."\n";
- echo get_string('group')."\t".$data->group."\n\n";
-
- echo implode("\t", $data->tabhead)."\n";
- foreach ($data->table as $row) {
- echo implode("\t", $row)."\n";
- }
-}
}
}
return $canmark;
+}
+
+/**
+ * Generate worksheet for Attendance export
+ *
+ * @param stdclass $data The data for the report
+ * @param string $filename The name of the file
+ * @param string $format excel|ods
+ *
+ */
+function attendance_exporttotableed($data, $filename, $format) {
+ global $CFG;
+
+ if ($format === 'excel') {
+ require_once("$CFG->libdir/excellib.class.php");
+ $filename .= ".xls";
+ $workbook = new MoodleExcelWorkbook("-");
+ } else {
+ require_once("$CFG->libdir/odslib.class.php");
+ $filename .= ".ods";
+ $workbook = new MoodleODSWorkbook("-");
+ }
+ // Sending HTTP headers.
+ $workbook->send($filename);
+ // Creating the first worksheet.
+ $myxls = $workbook->add_worksheet('Attendances');
+ // Format types.
+ $formatbc = $workbook->add_format();
+ $formatbc->set_bold(1);
+
+ $myxls->write(0, 0, get_string('course'), $formatbc);
+ $myxls->write(0, 1, $data->course);
+ $myxls->write(1, 0, get_string('group'), $formatbc);
+ $myxls->write(1, 1, $data->group);
+
+ $i = 3;
+ $j = 0;
+ foreach ($data->tabhead as $cell) {
+ // Merge cells if the heading would be empty (remarks column).
+ if (empty($cell)) {
+ $myxls->merge_cells($i, $j - 1, $i, $j);
+ } else {
+ $myxls->write($i, $j, $cell, $formatbc);
+ }
+ $j++;
+ }
+ $i++;
+ $j = 0;
+ foreach ($data->table as $row) {
+ foreach ($row as $cell) {
+ $myxls->write($i, $j++, $cell);
+ }
+ $i++;
+ $j = 0;
+ }
+ $workbook->close();
+}
+
+/**
+ * Generate csv for Attendance export
+ *
+ * @param stdclass $data The data for the report
+ * @param string $filename The name of the file
+ *
+ */
+function attendance_exporttocsv($data, $filename) {
+ $filename .= ".txt";
+
+ header("Content-Type: application/download\n");
+ header("Content-Disposition: attachment; filename=\"$filename\"");
+ header("Expires: 0");
+ header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
+ header("Pragma: public");
+
+ echo get_string('course')."\t".$data->course."\n";
+ echo get_string('group')."\t".$data->group."\n\n";
+
+ echo implode("\t", $data->tabhead)."\n";
+ foreach ($data->table as $row) {
+ echo implode("\t", $row)."\n";
+ }
}
\ No newline at end of file
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_sessions_cells_generator {
+ /** @var array $cells - list of table cells. */
protected $cells = array();
+ /** @var stdClass $reportdata - data for report. */
protected $reportdata;
+
+ /** @var stdClass $user - user record. */
protected $user;
+ /**
+ * Set up params.
+ * @param attendance_report_data $reportdata - reportdata.
+ * @param stdClass $user - user record.
+ */
public function __construct(attendance_report_data $reportdata, $user) {
$this->reportdata = $reportdata;
$this->user = $user;
}
+ /**
+ * Get cells for the table.
+ *
+ * @param boolean $remarks - include remarks cell.
+ */
public function get_cells($remarks = false) {
- $this->init_cells();
foreach ($this->reportdata->sessions as $sess) {
if (array_key_exists($sess->id, $this->reportdata->sessionslog[$this->user->id]) &&
!empty($this->reportdata->sessionslog[$this->user->id][$sess->id]->statusid)) {
return $this->cells;
}
- protected function init_cells() {
-
- }
-
+ /**
+ * Construct status cell.
+ *
+ * @param string $text - text for the cell.
+ */
protected function construct_existing_status_cell($text) {
$this->cells[] = $text;
}
+ /**
+ * Construct hidden status cell.
+ *
+ * @param string $text - text for the cell.
+ */
protected function construct_hidden_status_cell($text) {
$this->cells[] = $text;
}
+ /**
+ * Construct enrolments info cell.
+ *
+ * @param string $text - text for the cell.
+ */
protected function construct_enrolments_info_cell($text) {
$this->cells[] = $text;
}
+ /**
+ * Construct not taken cell.
+ *
+ * @param string $text - text for the cell.
+ */
protected function construct_not_taken_cell($text) {
$this->cells[] = $text;
}
+ /**
+ * Construct remarks cell.
+ *
+ * @param string $text - text for the cell.
+ */
protected function construct_remarks_cell($text) {
$this->cells[] = $text;
}
+ /**
+ * Construct not existing user session cell.
+ *
+ * @param string $text - text for the cell.
+ */
protected function construct_not_existing_for_user_session_cell($text) {
$this->cells[] = $text;
}
+ /**
+ * Dummy stub method, called at the end. - override if you need/
+ */
protected function finalize_cells() {
}
}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_sessions_cells_html_generator extends user_sessions_cells_generator {
+ /** @var html_table_cell $cell */
private $cell;
+ /**
+ * Construct status cell.
+ *
+ * @param string $text - text for the cell.
+ */
protected function construct_existing_status_cell($text) {
$this->close_open_cell_if_needed();
$this->cells[] = html_writer::span($text, 'attendancestatus-'.$text);
}
+ /**
+ * Construct hidden status cell.
+ *
+ * @param string $text - text for the cell.
+ */
protected function construct_hidden_status_cell($text) {
$this->cells[] = html_writer::tag('s', $text);
}
+ /**
+ * Construct enrolments info cell.
+ *
+ * @param string $text - text for the cell.
+ */
protected function construct_enrolments_info_cell($text) {
if (is_null($this->cell)) {
$this->cell = new html_table_cell($text);
}
}
+ /**
+ * Close cell if needed.
+ */
private function close_open_cell_if_needed() {
if ($this->cell) {
$this->cells[] = $this->cell;
}
}
+ /**
+ * Construct not taken cell.
+ *
+ * @param string $text - text for the cell.
+ */
protected function construct_not_taken_cell($text) {
$this->close_open_cell_if_needed();
$this->cells[] = $text;
}
+ /**
+ * Construct remarks cell.
+ *
+ * @param string $text - text for the cell.
+ */
protected function construct_remarks_cell($text) {
global $OUTPUT;
$this->cells[] = $markcell;
}
+ /**
+ * Construct not existing for user session cell.
+ *
+ * @param string $text - text for the cell.
+ */
protected function construct_not_existing_for_user_session_cell($text) {
$this->close_open_cell_if_needed();
$this->cells[] = $text;
}
+ /**
+ * Finalize cells.
+ *
+ */
protected function finalize_cells() {
if ($this->cell) {
$this->cells[] = $this->cell;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_sessions_cells_text_generator extends user_sessions_cells_generator {
+ /** @var string $enrolmentsinfocelltext. */
private $enrolmentsinfocelltext;
+ /**
+ * Construct hidden status cell.
+ *
+ * @param string $text - text for the cell.
+ */
protected function construct_hidden_status_cell($text) {
$this->cells[] = '-'.$text;
}
+ /**
+ * Construct enrolments info cell.
+ *
+ * @param string $text - text for the cell.
+ */
protected function construct_enrolments_info_cell($text) {
if ($this->enrolmentsinfocelltext != $text) {
$this->enrolmentsinfocelltext = $text;
}
}
-// Used to print simple time - 1am instead of 1:00am.
+/**
+ * Used to print simple time - 1am instead of 1:00am.
+ *
+ * @param int $time - unix timestamp.
+ */
function attendance_strftimehm($time) {
$mins = userdate($time, '%M');
if ($mins == '00') {
}
}
+/**
+ * Used to print simple time - 1am instead of 1:00am.
+ *
+ * @param int $datetime - unix timestamp.
+ * @param int $duration - number of seconds.
+ */
function construct_session_time($datetime, $duration) {
$starttime = attendance_strftimehm($datetime);
$endtime = attendance_strftimehm($datetime + $duration);
return $starttime . ($duration > 0 ? ' - ' . $endtime : '');
}
+/**
+ * Used to print session time.
+ *
+ * @param int $datetime - unix timestamp.
+ * @param int $duration - number of seconds duration.
+ * @return string.
+ */
function construct_session_full_date_time($datetime, $duration) {
$sessinfo = userdate($datetime, get_string('strftimedmyw', 'attendance'));
$sessinfo .= ' '.construct_session_time($datetime, $duration);
return $sessinfo;
}
+/**
+ * Used to construct user summary.
+ *
+ * @param stdclass $usersummary - data for summary.
+ * @param int $view - ATT_VIEW_ALL|ATT_VIEW_
+ * @return string.
+ */
function construct_user_data_stat($usersummary, $view) {
$stattable = new html_table();
$stattable->attributes['class'] = 'attlist';
return html_writer::table($stattable);
}
+/**
+ * Returns html user summary
+ *
+ * @param stdclass $attendance - attendance record.
+ * @param stdclass $user - user record
+ * @return string.
+ *
+ */
function construct_full_user_stat_html_table($attendance, $user) {
$summary = new mod_attendance_summary($attendance->id, $user->id);
return construct_user_data_stat($summary->get_all_sessions_summary_for($user->id), ATT_VIEW_ALL);