Browse Source

Vendor - Add GamificationUtils class - refs BT#9901 #TMI

Angel Fernando Quiroz Campos 9 years ago
parent
commit
8e5fc8f72c
1 changed files with 40 additions and 0 deletions
  1. 40 0
      main/inc/lib/GamificationUtils.php

+ 40 - 0
main/inc/lib/GamificationUtils.php

@@ -0,0 +1,40 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ * GamificationUtils class
+ * Functions to manage the gamification mode
+ * @package chamilo.library
+ * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
+ */
+class GamificationUtils
+{
+
+    /**
+     * Get the calculated points on session with gamification mode
+     * @param int $userId The user ID
+     * @param int $userStatus The user Status
+     * @return int
+     */
+    public static function getTotalUserPoints($userId, $userStatus)
+    {
+        $points = 0;
+
+        $sessions = SessionManager::getSessionsFollowedByUser(
+            $userId,
+            $userStatus
+        );
+
+        if (empty($sessions)) {
+            return 0;
+        }
+
+        foreach ($sessions as $session) {
+            $points += SessionManager::getPointsFromGamification(
+                $session['id']
+            );
+        }
+
+        return $points;
+    }
+
+}