You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.8 KiB
112 lines
2.8 KiB
10 years ago
|
<?php
|
||
|
/* For licensing terms, see /license.txt */
|
||
|
|
||
|
/**
|
||
7 years ago
|
* Library for generate a teacher time report.
|
||
10 years ago
|
*
|
||
|
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
|
||
|
*/
|
||
|
class TeacherTimeReport
|
||
|
{
|
||
|
/**
|
||
7 years ago
|
* The report data.
|
||
|
*
|
||
10 years ago
|
* @var array
|
||
|
*/
|
||
7 years ago
|
public $data = [];
|
||
10 years ago
|
|
||
|
/**
|
||
7 years ago
|
* Callback for compare sessions names.
|
||
|
*
|
||
9 years ago
|
* @param array $dataA The data A
|
||
10 years ago
|
* @param array $dataB The data B
|
||
7 years ago
|
*
|
||
9 years ago
|
* @return int returns -1 if dataA is less than dataB, 1 if dataA is greater than dataB, and 0 if they are equal
|
||
10 years ago
|
*/
|
||
|
public function compareSessions($dataA, $dataB)
|
||
|
{
|
||
|
return strnatcmp($dataA['session']['name'], $dataB['session']['name']);
|
||
|
}
|
||
|
|
||
|
/**
|
||
7 years ago
|
* Callback for compare courses names.
|
||
|
*
|
||
10 years ago
|
* @param array $dataA The datab A
|
||
|
* @param array $dataB The data B
|
||
7 years ago
|
*
|
||
9 years ago
|
* @return int returns -1 if dataA is less than dataB, 1 if dataA is greater than dataB, and 0 if they are equal
|
||
10 years ago
|
*/
|
||
|
public function compareCourses($dataA, $dataB)
|
||
|
{
|
||
|
return strnatcmp($dataA['course']['name'], $dataB['course']['name']);
|
||
|
}
|
||
|
|
||
|
/**
|
||
7 years ago
|
* Callback for compare coaches names.
|
||
|
*
|
||
10 years ago
|
* @param array $dataA The datab A
|
||
|
* @param array $dataB The data B
|
||
7 years ago
|
*
|
||
9 years ago
|
* @return int returns -1 if dataA is less than dataB, 1 if dataA is greater than dataB, and 0 if they are equal
|
||
10 years ago
|
*/
|
||
|
public function compareCoaches($dataA, $dataB)
|
||
|
{
|
||
8 years ago
|
return strnatcmp($dataA['coach']['complete_name'], $dataB['coach']['complete_name']);
|
||
10 years ago
|
}
|
||
|
|
||
|
/**
|
||
7 years ago
|
* Sort the report data.
|
||
|
*
|
||
|
* @param bool $withFilter Whether sort by sessions and courses
|
||
10 years ago
|
*/
|
||
|
public function sortData($withFilter = false)
|
||
|
{
|
||
|
if ($withFilter) {
|
||
7 years ago
|
uasort($this->data, [$this, 'compareSessions']);
|
||
|
uasort($this->data, [$this, 'compareCourses']);
|
||
10 years ago
|
}
|
||
|
|
||
7 years ago
|
uasort($this->data, [$this, 'compareCoaches']);
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
/**
|
||
|
* @param bool|false $withFilter
|
||
7 years ago
|
*
|
||
9 years ago
|
* @return array
|
||
|
*/
|
||
10 years ago
|
public function prepareDataToExport($withFilter = false)
|
||
|
{
|
||
7 years ago
|
$dataToExport = [];
|
||
10 years ago
|
|
||
|
if ($withFilter) {
|
||
7 years ago
|
$dataToExport[] = [
|
||
10 years ago
|
get_lang('Session'),
|
||
|
get_lang('Course'),
|
||
|
get_lang('Coach'),
|
||
5 years ago
|
get_lang('Total time'),
|
||
7 years ago
|
];
|
||
10 years ago
|
} else {
|
||
7 years ago
|
$dataToExport[] = [
|
||
10 years ago
|
get_lang('Coach'),
|
||
5 years ago
|
get_lang('Total time'),
|
||
7 years ago
|
];
|
||
10 years ago
|
}
|
||
|
|
||
|
foreach ($this->data as $row) {
|
||
7 years ago
|
$data = [];
|
||
10 years ago
|
|
||
|
if ($withFilter) {
|
||
|
$data[] = $row['session']['name'];
|
||
|
$data[] = $row['course']['name'];
|
||
|
}
|
||
|
|
||
8 years ago
|
$data[] = $row['coach']['complete_name'];
|
||
|
$data[] = $row['total_time'];
|
||
10 years ago
|
|
||
|
$dataToExport[] = $data;
|
||
|
}
|
||
|
|
||
|
return $dataToExport;
|
||
|
}
|
||
|
}
|