Browse Source

Add hook system for My Student's LP tracking table - refs BT#15821

Angel Fernando Quiroz Campos 5 năm trước cách đây
mục cha
commit
f103bf22dd

+ 54 - 0
main/inc/lib/hook/HookMyStudentsLpTracking.php

@@ -0,0 +1,54 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+ * Class HookMyStudentsLpTracking.
+ */
+class HookMyStudentsLpTracking extends HookEvent implements HookMyStudentsLpTrackingEventInterface
+{
+    /**
+     * HookMyStudentsLpTracking constructor.
+     *
+     * @throws Exception
+     */
+    protected function __construct()
+    {
+        parent::__construct('HookMyStudentsLpTracking');
+    }
+
+    /**
+     * @return array
+     */
+    public function notifyTrackingHeader()
+    {
+        $results = [];
+
+        /** @var HookMyStudentsLpTrackingObserverInterface $observer */
+        foreach ($this->observers as $observer) {
+            $results[] = $observer->trackingHeader($this);
+        }
+
+        return $results;
+    }
+
+    /**
+     * @param int $lpId
+     * @param int $studentId
+     *
+     * @return array
+     */
+    public function notifyTrackingContent($lpId, $studentId)
+    {
+        $this->eventData['lp_id'] = $lpId;
+        $this->eventData['student_id'] = $studentId;
+
+        $results = [];
+
+        /** @var HookMyStudentsLpTrackingObserverInterface $observer */
+        foreach ($this->observers as $observer) {
+            $results[] = $observer->trackingContent($this);
+        }
+
+        return $results;
+    }
+}

+ 21 - 0
main/inc/lib/hook/interfaces/HookMyStudentsLpTrackingEventInterface.php

@@ -0,0 +1,21 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+ * Interface HookMyStudentsLpTrackingEventInterface.
+ */
+interface HookMyStudentsLpTrackingEventInterface extends HookEventInterface
+{
+    /**
+     * @return array
+     */
+    public function notifyTrackingHeader();
+
+    /**
+     * @param int $lpId
+     * @param int $studentId
+     *
+     * @return array
+     */
+    public function notifyTrackingContent($lpId, $studentId);
+}

+ 38 - 0
main/inc/lib/hook/interfaces/HookMyStudentsLpTrackingObserverInterface.php

@@ -0,0 +1,38 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+ * Interface HookMyStudentsLpTrackingObserverInterface.
+ */
+interface HookMyStudentsLpTrackingObserverInterface extends HookObserverInterface
+{
+    /**
+     * Return an associative array this value and attributes.
+     * <code>
+     * [
+     *     'value' => 'Users online',
+     *     'attrs' => ['class' => 'text-center'],
+     * ]
+     * </code>
+     *
+     * @param HookMyStudentsLpTrackingEventInterface $hook
+     *
+     * @return array
+     */
+    public function trackingHeader(HookMyStudentsLpTrackingEventInterface $hook);
+
+    /**
+     * Return an associative array this value and attributes.
+     * <code>
+     * [
+     *     'value' => '5 connected users ',
+     *     'attrs' => ['class' => 'text-center text-success'],
+     * ]
+     * </code>
+     *
+     * @param HookMyStudentsLpTrackingEventInterface $hook
+     *
+     * @return array
+     */
+    public function trackingContent(HookMyStudentsLpTrackingEventInterface $hook);
+}