123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * Class WhispeakMyStudentsLpTrackingHook.
- */
- class WhispeakMyStudentsLpTrackingHook extends HookObserver implements HookMyStudentsLpTrackingObserverInterface
- {
- /**
- * WhispeakMyStudentsLpTrackingHook constructor.
- */
- protected function __construct()
- {
- parent::__construct(
- 'plugin/whispeakauth/WhispeakAuthPlugin.php',
- 'whispeakauth'
- );
- }
- /**
- * @param HookMyStudentsLpTrackingEventInterface $hook
- *
- * @return array
- */
- public function trackingHeader(HookMyStudentsLpTrackingEventInterface $hook)
- {
- return [
- 'value' => WhispeakAuthPlugin::create()->get_lang('plugin_title'),
- 'attrs' => ['class' => 'text-center'],
- ];
- }
- /**
- * @param HookMyStudentsLpTrackingEventInterface $hook
- *
- * @throws \Doctrine\ORM\Query\QueryException
- *
- * @return array
- */
- public function trackingContent(HookMyStudentsLpTrackingEventInterface $hook)
- {
- $data = $hook->getEventData();
- $totalCount = WhispeakAuthPlugin::countAllAttemptsInLearningPath($data['lp_id'], $data['student_id']);
- if (0 === $totalCount) {
- return [
- 'value' => '-',
- 'attrs' => ['class' => 'text-center'],
- ];
- }
- $successCount = WhispeakAuthPlugin::countSuccessAttemptsInLearningPath($data['lp_id'], $data['student_id']);
- $attrs = ['class' => 'text-center '];
- $attrs['class'] .= $successCount <= $totalCount / 2 ? 'text-danger' : 'text-success';
- return [
- 'value' => Display::tag('strong', "$successCount / $totalCount"),
- 'attrs' => $attrs,
- ];
- }
- }
|