Last active
November 20, 2018 07:34
-
-
Save ArtisKrumins/47f59a32ed646bb6b3eb9e95db8bb299 to your computer and use it in GitHub Desktop.
Zenitel Opigno LMS patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/includes/group/course/queries.inc b/includes/group/course/queries.inc | |
index 1030014..d1ecd42 100644 | |
--- a/includes/group/course/queries.inc | |
+++ b/includes/group/course/queries.inc | |
@@ -273,21 +273,61 @@ function opigno_statistics_app_query_course_students_results($course_nid) { | |
", array( | |
':course_nid' => $course_nid | |
)); | |
+ // Put on array, so can this can be merged and find unique results | |
+ while ($user = $result->fetchAssoc()) { | |
+ $couse_users_with_results[$user['uid']] = $user; | |
+ } | |
+ | |
+ $result = db_query(" | |
+ SELECT u.student_name, j1.page_views as number_of_interactions, uc.score, uc.status, ms.etid as uid | |
+ FROM {og_membership} as ms | |
+ Left Join ( | |
+ Select name as student_name, uid | |
+ From {users} | |
+ ) u ON u.uid = ms.etid | |
+ Left Join ( | |
+ Select username as student_name, uid, score, status, course_nid | |
+ From {opigno_statistics_user_course} as uc | |
+ Where course_nid = :course_nid | |
+ ) uc ON uc.uid = ms.etid | |
+ Left JOIN ( | |
+ SELECT SUM(page_views) as page_views, uid | |
+ FROM {opigno_statistics_user_group} ug | |
+ WHERE group_nid = :course_nid | |
+ GROUP BY uid | |
+ ) j1 ON uc.uid = j1.uid | |
+ WHERE gid = :course_nid | |
+ ", array( | |
+ ':course_nid' => $course_nid | |
+ )); | |
+ | |
+ // Put on array, so can this can be merged and find unique results | |
+ while ($user = $result->fetchAssoc()) { | |
+ $couse_users[$user['uid']] = $user; | |
+ } | |
+ | |
+ $students_results_all = array_unique(array_merge($couse_users_with_results,$couse_users), SORT_REGULAR); | |
$total_number_of_interactions = 0; | |
$total_score = 0; | |
- while($record = $result->fetchAssoc()) { | |
+ $users_with_scores = 0; | |
+ foreach ($students_results_all as $record) { | |
$students_results[] = $record; | |
$total_number_of_interactions += $record['number_of_interactions']; | |
- $total_score += $record['score']; | |
+ if($record['number_of_interactions'] != NULL){ | |
+ $total_score += $record['score']; | |
+ $users_with_scores ++; | |
+ } | |
} | |
- $avg_number_of_interactions = count($students_results)>0 ? $total_number_of_interactions / count($students_results) : 0; | |
- $avg_score = count($students_results)>0 ? $total_score / count($students_results) : 0; | |
+ $avg_number_of_interactions = $users_with_scores>0 ? $total_number_of_interactions / $users_with_scores : 0; | |
+ $avg_score = $users_with_scores>0 ? $total_score / $users_with_scores : 0; | |
foreach($students_results as &$student_result) { | |
- $student_result['avg_number_of_interactions'] = round($avg_number_of_interactions, 0); | |
- $student_result['avg_score'] = round($avg_score, 0); | |
+ if ($student_result['number_of_interactions']){ | |
+ $student_result['avg_number_of_interactions'] = round($avg_number_of_interactions, 0); | |
+ $student_result['avg_score'] = round($avg_score, 0); | |
+ } | |
} | |
cache_set($cache_key, $students_results, 'cache', time() + 86400); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment