123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * Library for generate a teacher time report.
- *
- * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
- *
- * @package chamilo.admin
- */
- class TeacherTimeReport
- {
- /**
- * The report data.
- *
- * @var array
- */
- public $data = [];
- /**
- * Callback for compare sessions names.
- *
- * @param array $dataA The data A
- * @param array $dataB The data B
- *
- * @return int returns -1 if dataA is less than dataB, 1 if dataA is greater than dataB, and 0 if they are equal
- */
- public function compareSessions($dataA, $dataB)
- {
- return strnatcmp($dataA['session']['name'], $dataB['session']['name']);
- }
- /**
- * Callback for compare courses names.
- *
- * @param array $dataA The datab A
- * @param array $dataB The data B
- *
- * @return int returns -1 if dataA is less than dataB, 1 if dataA is greater than dataB, and 0 if they are equal
- */
- public function compareCourses($dataA, $dataB)
- {
- return strnatcmp($dataA['course']['name'], $dataB['course']['name']);
- }
- /**
- * Callback for compare coaches names.
- *
- * @param array $dataA The datab A
- * @param array $dataB The data B
- *
- * @return int returns -1 if dataA is less than dataB, 1 if dataA is greater than dataB, and 0 if they are equal
- */
- public function compareCoaches($dataA, $dataB)
- {
- return strnatcmp($dataA['coach']['complete_name'], $dataB['coach']['complete_name']);
- }
- /**
- * Sort the report data.
- *
- * @param bool $withFilter Whether sort by sessions and courses
- */
- public function sortData($withFilter = false)
- {
- if ($withFilter) {
- uasort($this->data, [$this, 'compareSessions']);
- uasort($this->data, [$this, 'compareCourses']);
- }
- uasort($this->data, [$this, 'compareCoaches']);
- }
- /**
- * @param bool|false $withFilter
- *
- * @return array
- */
- public function prepareDataToExport($withFilter = false)
- {
- $dataToExport = [];
- if ($withFilter) {
- $dataToExport[] = [
- get_lang('Session'),
- get_lang('Course'),
- get_lang('Coach'),
- get_lang('TotalTime'),
- ];
- } else {
- $dataToExport[] = [
- get_lang('Coach'),
- get_lang('TotalTime'),
- ];
- }
- foreach ($this->data as $row) {
- $data = [];
- if ($withFilter) {
- $data[] = $row['session']['name'];
- $data[] = $row['course']['name'];
- }
- $data[] = $row['coach']['complete_name'];
- $data[] = $row['total_time'];
- $dataToExport[] = $data;
- }
- return $dataToExport;
- }
- }
|