From 64baf96413a4dcd8792de2c9b1aa6dfc85e08068 Mon Sep 17 00:00:00 2001 From: Antonio Carlos Mariani Date: Tue, 3 May 2016 14:57:26 -0300 Subject: [PATCH] Removing functions that are no longer used --- classes/structure.php | 110 ------------------------------------------ locallib.php | 80 ------------------------------ 2 files changed, 190 deletions(-) diff --git a/classes/structure.php b/classes/structure.php index d0c30e0..f04b0fc 100644 --- a/classes/structure.php +++ b/classes/structure.php @@ -746,116 +746,6 @@ class mod_attendance_structure { return $DB->get_records('attendance_log', array('sessionid' => $sessionid), '', 'studentid,statusid,remarks,id'); } - public function get_user_stat($userid) { - $ret = array(); - $ret['completed'] = $this->get_user_taken_sessions_count($userid); - $ret['statuses'] = $this->get_user_statuses_stat($userid); - - return $ret; - } - - public function get_user_taken_sessions_count($userid) { - if (!array_key_exists($userid, $this->usertakensesscount)) { - if (!empty($this->pageparams->startdate) && !empty($this->pageparams->enddate)) { - $this->usertakensesscount[$userid] = attendance_get_user_taken_sessions_count($this->id, $this->course->startdate, - $userid, $this->cm, $this->pageparams->startdate, $this->pageparams->enddate); - } else { - $this->usertakensesscount[$userid] = attendance_get_user_taken_sessions_count($this->id, $this->course->startdate, - $userid, $this->cm); - } - } - return $this->usertakensesscount[$userid]; - } - - /** - * - * @param type $userid - * @param type $filters - An array things to filter by. For now only enddate is valid. - * @return type - */ - public function get_user_statuses_stat($userid, array $filters = null) { - global $DB; - $params = array( - 'aid' => $this->id, - 'cstartdate' => $this->course->startdate, - 'uid' => $userid); - - $processedfilters = array(); - - // We test for any valid filters sent. - if (isset($filters['enddate'])) { - $processedfilters[] = 'ats.sessdate <= :enddate'; - $params['enddate'] = $filters['enddate']; - } - - // Make the filter array into a SQL string. - if (!empty($processedfilters)) { - $processedfilters = ' AND '.implode(' AND ', $processedfilters); - } else { - $processedfilters = ''; - } - - $period = ''; - if (!empty($this->pageparams->startdate) && !empty($this->pageparams->enddate)) { - $period = ' AND ats.sessdate >= :sdate AND ats.sessdate < :edate '; - $params['sdate'] = $this->pageparams->startdate; - $params['edate'] = $this->pageparams->enddate; - } - - if ($this->get_group_mode()) { - $qry = "SELECT al.statusid, count(al.statusid) AS stcnt - FROM {attendance_log} al - JOIN {attendance_sessions} ats ON al.sessionid = ats.id - LEFT JOIN {groups_members} gm ON gm.userid = al.studentid AND gm.groupid = ats.groupid - WHERE ats.attendanceid = :aid AND - ats.sessdate >= :cstartdate AND - al.studentid = :uid AND - (ats.groupid = 0 or gm.id is NOT NULL)".$period.$processedfilters." - GROUP BY al.statusid"; - } else { - $qry = "SELECT al.statusid, count(al.statusid) AS stcnt - FROM {attendance_log} al - JOIN {attendance_sessions} ats - ON al.sessionid = ats.id - WHERE ats.attendanceid = :aid AND - ats.sessdate >= :cstartdate AND - al.studentid = :uid".$period.$processedfilters." - GROUP BY al.statusid"; - } - - // We do not want to cache, or use a cached version of the results when a filter is set. - if ($filters !== null) { - return $DB->get_records_sql($qry, $params); - } else if (!array_key_exists($userid, $this->userstatusesstat)) { - // Not filtered so if we do not already have them do the query. - $this->userstatusesstat[$userid] = $DB->get_records_sql($qry, $params); - } - - // Return the cached stats. - return $this->userstatusesstat[$userid]; - } - - /** - * - * @param type $userid - * @param type $filters - An array things to filter by. For now only enddate is valid. - * @return type - */ - public function get_user_grade($userid, array $filters = null) { - return attendance_get_user_grade($this->get_user_statuses_stat($userid, $filters), $this->get_statuses(true, true)); - } - - // For getting sessions count implemented simplest method - taken sessions. - // It can have error if users don't have attendance info for some sessions. - // In the future we can implement another methods: - // * all sessions between user start enrolment date and now; - // * all sessions between user start and end enrolment date. - // While implementing those methods we need recalculate grades of all users - // on session adding. - public function get_user_max_grade($userid) { - return attendance_get_user_max_grade($this->get_user_taken_sessions_count($userid), $this->get_statuses(true, true)); - } - public function update_users_grade($userids) { attendance_update_users_grade($this, $userids); } diff --git a/locallib.php b/locallib.php index 3f85862..984fef9 100644 --- a/locallib.php +++ b/locallib.php @@ -88,86 +88,6 @@ function attendance_get_setname($attid, $statusset, $includevalues = true) { return $statusname; } -function attendance_get_user_taken_sessions_count($attid, $coursestartdate, $userid, $coursemodule, $startdate = '', $enddate = '') { - global $DB, $COURSE; - $groupmode = groups_get_activity_groupmode($coursemodule, $COURSE); - if (!empty($groupmode)) { - $qry = "SELECT count(*) as cnt - FROM {attendance_log} al - JOIN {attendance_sessions} ats ON al.sessionid = ats.id - LEFT JOIN {groups_members} gm ON gm.userid = al.studentid AND gm.groupid = ats.groupid - WHERE ats.attendanceid = :aid AND - ats.sessdate >= :cstartdate AND - al.studentid = :uid AND - (ats.groupid = 0 or gm.id is NOT NULL)"; - } else { - $qry = "SELECT count(*) as cnt - FROM {attendance_log} al - JOIN {attendance_sessions} ats - ON al.sessionid = ats.id - WHERE ats.attendanceid = :aid AND - ats.sessdate >= :cstartdate AND - al.studentid = :uid"; - } - $params = array( - 'aid' => $attid, - 'cstartdate' => $coursestartdate, - 'uid' => $userid); - - if (!empty($startdate) && !empty($enddate)) { - $qry .= ' AND sessdate >= :sdate AND sessdate < :edate '; - $params['sdate'] = $startdate; - $params['edate'] = $enddate; - } - - return $DB->count_records_sql($qry, $params); -} - -function attendance_get_user_statuses_stat($attid, $coursestartdate, $userid, $coursemodule) { - global $DB, $COURSE; - $groupmode = groups_get_activity_groupmode($coursemodule, $COURSE); - if (!empty($groupmode)) { - $qry = "SELECT al.statusid, count(al.statusid) AS stcnt - FROM {attendance_log} al - JOIN {attendance_sessions} ats ON al.sessionid = ats.id - LEFT JOIN {groups_members} gm ON gm.userid = al.studentid AND gm.groupid = ats.groupid - WHERE ats.attendanceid = :aid AND - ats.sessdate >= :cstartdate AND - al.studentid = :uid AND - (ats.groupid = 0 or gm.id is NOT NULL) - GROUP BY al.statusid"; - } else { - $qry = "SELECT al.statusid, count(al.statusid) AS stcnt - FROM {attendance_log} al - JOIN {attendance_sessions} ats - ON al.sessionid = ats.id - WHERE ats.attendanceid = :aid AND - ats.sessdate >= :cstartdate AND - al.studentid = :uid - GROUP BY al.statusid"; - } - $params = array( - 'aid' => $attid, - 'cstartdate' => $coursestartdate, - 'uid' => $userid); - - return $DB->get_records_sql($qry, $params); -} - -function attendance_get_user_grade($userstatusesstat, $statuses) { - $sum = 0; - foreach ($userstatusesstat as $stat) { - $sum += $stat->stcnt * $statuses[$stat->statusid]->grade; - } - - return $sum; -} - -function attendance_get_user_max_grade($sesscount, $statuses) { - reset($statuses); - return current($statuses)->grade * $sesscount; -} - function attendance_get_user_courses_attendances($userid) { global $DB;