WhispeakMyStudentsLpTrackingHook.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class WhispeakMyStudentsLpTrackingHook.
  5. */
  6. class WhispeakMyStudentsLpTrackingHook extends HookObserver implements HookMyStudentsLpTrackingObserverInterface
  7. {
  8. /**
  9. * WhispeakMyStudentsLpTrackingHook constructor.
  10. */
  11. protected function __construct()
  12. {
  13. parent::__construct(
  14. 'plugin/whispeakauth/WhispeakAuthPlugin.php',
  15. 'whispeakauth'
  16. );
  17. }
  18. /**
  19. * @param HookMyStudentsLpTrackingEventInterface $hook
  20. *
  21. * @return array
  22. */
  23. public function trackingHeader(HookMyStudentsLpTrackingEventInterface $hook)
  24. {
  25. return [
  26. 'value' => WhispeakAuthPlugin::create()->get_lang('plugin_title'),
  27. 'attrs' => ['class' => 'text-center'],
  28. ];
  29. }
  30. /**
  31. * @param HookMyStudentsLpTrackingEventInterface $hook
  32. *
  33. * @throws \Doctrine\ORM\Query\QueryException
  34. *
  35. * @return array
  36. */
  37. public function trackingContent(HookMyStudentsLpTrackingEventInterface $hook)
  38. {
  39. $data = $hook->getEventData();
  40. $totalCount = WhispeakAuthPlugin::countAllAttemptsInLearningPath($data['lp_id'], $data['student_id']);
  41. if (0 === $totalCount) {
  42. return [
  43. 'value' => '-',
  44. 'attrs' => ['class' => 'text-center'],
  45. ];
  46. }
  47. $successCount = WhispeakAuthPlugin::countSuccessAttemptsInLearningPath($data['lp_id'], $data['student_id']);
  48. $attrs = ['class' => 'text-center '];
  49. $attrs['class'] .= $successCount <= $totalCount / 2 ? 'text-danger' : 'text-success';
  50. return [
  51. 'value' => Display::tag('strong', "$successCount / $totalCount"),
  52. 'attrs' => $attrs,
  53. ];
  54. }
  55. }