TeacherTimeReport.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * @package chamilo.admin
  8. */
  9. class TeacherTimeReport
  10. {
  11. /**
  12. * The report data
  13. * @var array
  14. */
  15. public $data = array();
  16. /**
  17. * Callback for compare sessions names
  18. * @param array $dataA The data A
  19. * @param array $dataB The data B
  20. * @return int returns -1 if dataA is less than dataB, 1 if dataA is greater than dataB, and 0 if they are equal
  21. */
  22. public function compareSessions($dataA, $dataB)
  23. {
  24. return strnatcmp($dataA['session']['name'], $dataB['session']['name']);
  25. }
  26. /**
  27. * Callback for compare courses names
  28. * @param array $dataA The datab A
  29. * @param array $dataB The data B
  30. * @return int returns -1 if dataA is less than dataB, 1 if dataA is greater than dataB, and 0 if they are equal
  31. */
  32. public function compareCourses($dataA, $dataB)
  33. {
  34. return strnatcmp($dataA['course']['name'], $dataB['course']['name']);
  35. }
  36. /**
  37. * Callback for compare coaches names
  38. * @param array $dataA The datab A
  39. * @param array $dataB The data B
  40. * @return int returns -1 if dataA is less than dataB, 1 if dataA is greater than dataB, and 0 if they are equal
  41. */
  42. public function compareCoaches($dataA, $dataB)
  43. {
  44. return strnatcmp($dataA['coach']['completeName'], $dataB['coach']['completeName']);
  45. }
  46. /**
  47. * Sort the report data
  48. * @param boolean $withFilter Whether sort by sessions and courses
  49. */
  50. public function sortData($withFilter = false)
  51. {
  52. if ($withFilter) {
  53. uasort($this->data, array($this, 'compareSessions'));
  54. uasort($this->data, array($this, 'compareCourses'));
  55. }
  56. uasort($this->data, array($this, 'compareCoaches'));
  57. }
  58. /**
  59. * @param bool|false $withFilter
  60. * @return array
  61. */
  62. public function prepareDataToExport($withFilter = false)
  63. {
  64. $dataToExport = array();
  65. if ($withFilter) {
  66. $dataToExport[] = array(
  67. get_lang('Session'),
  68. get_lang('Course'),
  69. get_lang('Coach'),
  70. get_lang('TotalTime')
  71. );
  72. } else {
  73. $dataToExport[] = array(
  74. get_lang('Coach'),
  75. get_lang('TotalTime')
  76. );
  77. }
  78. foreach ($this->data as $row) {
  79. $data = array();
  80. if ($withFilter) {
  81. $data[] = $row['session']['name'];
  82. $data[] = $row['course']['name'];
  83. }
  84. $data[] = $row['coach']['completeName'];
  85. $data[] = $row['totalTime'];
  86. $dataToExport[] = $data;
  87. }
  88. return $dataToExport;
  89. }
  90. }