TeacherTimeReport.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Library for generate a teacher time report.
  5. *
  6. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  7. *
  8. * @package chamilo.admin
  9. */
  10. class TeacherTimeReport
  11. {
  12. /**
  13. * The report data.
  14. *
  15. * @var array
  16. */
  17. public $data = [];
  18. /**
  19. * Callback for compare sessions names.
  20. *
  21. * @param array $dataA The data A
  22. * @param array $dataB The data B
  23. *
  24. * @return int returns -1 if dataA is less than dataB, 1 if dataA is greater than dataB, and 0 if they are equal
  25. */
  26. public function compareSessions($dataA, $dataB)
  27. {
  28. return strnatcmp($dataA['session']['name'], $dataB['session']['name']);
  29. }
  30. /**
  31. * Callback for compare courses names.
  32. *
  33. * @param array $dataA The datab A
  34. * @param array $dataB The data B
  35. *
  36. * @return int returns -1 if dataA is less than dataB, 1 if dataA is greater than dataB, and 0 if they are equal
  37. */
  38. public function compareCourses($dataA, $dataB)
  39. {
  40. return strnatcmp($dataA['course']['name'], $dataB['course']['name']);
  41. }
  42. /**
  43. * Callback for compare coaches names.
  44. *
  45. * @param array $dataA The datab A
  46. * @param array $dataB The data B
  47. *
  48. * @return int returns -1 if dataA is less than dataB, 1 if dataA is greater than dataB, and 0 if they are equal
  49. */
  50. public function compareCoaches($dataA, $dataB)
  51. {
  52. return strnatcmp($dataA['coach']['complete_name'], $dataB['coach']['complete_name']);
  53. }
  54. /**
  55. * Sort the report data.
  56. *
  57. * @param bool $withFilter Whether sort by sessions and courses
  58. */
  59. public function sortData($withFilter = false)
  60. {
  61. if ($withFilter) {
  62. uasort($this->data, [$this, 'compareSessions']);
  63. uasort($this->data, [$this, 'compareCourses']);
  64. }
  65. uasort($this->data, [$this, 'compareCoaches']);
  66. }
  67. /**
  68. * @param bool|false $withFilter
  69. *
  70. * @return array
  71. */
  72. public function prepareDataToExport($withFilter = false)
  73. {
  74. $dataToExport = [];
  75. if ($withFilter) {
  76. $dataToExport[] = [
  77. get_lang('Session'),
  78. get_lang('Course'),
  79. get_lang('Coach'),
  80. get_lang('Total time'),
  81. ];
  82. } else {
  83. $dataToExport[] = [
  84. get_lang('Coach'),
  85. get_lang('Total time'),
  86. ];
  87. }
  88. foreach ($this->data as $row) {
  89. $data = [];
  90. if ($withFilter) {
  91. $data[] = $row['session']['name'];
  92. $data[] = $row['course']['name'];
  93. }
  94. $data[] = $row['coach']['complete_name'];
  95. $data[] = $row['total_time'];
  96. $dataToExport[] = $data;
  97. }
  98. return $dataToExport;
  99. }
  100. }