Adding function get_user_taken_sessions_percentages to summary class
authorAntonio Carlos Mariani <antonio.c.mariani@ufsc.br>
Tue, 10 May 2016 17:47:17 +0000 (14:47 -0300)
committerAntonio Carlos Mariani <antonio.c.mariani@ufsc.br>
Tue, 10 May 2016 17:47:17 +0000 (14:47 -0300)
classes/summary.php

index 917b786..d83bfb8 100644 (file)
@@ -22,6 +22,8 @@
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
+include_once($CFG->dirroot . '/mod/attendance/locallib.php');
+
 class mod_attendance_summary {
 
     /** @var int attendance instance identifier */
@@ -83,6 +85,21 @@ class mod_attendance_summary {
     }
 
     /**
+     * Returns the percentages of each user related to the taken sessions
+     *
+     * @return array
+     */
+    public function get_user_taken_sessions_percentages() {
+        $percentages = array();
+
+        foreach ($this->userspoints as $userid => $userpoints) {
+            $percentages[$userid] = attendance_calc_fraction($userpoints->points, $userpoints->maxpoints);
+        }
+
+        return $percentages;
+    }
+
+    /**
      * Returns a summary of the points assigned to the user related to the taken sessions
      *
      * @param int userid User instance id