You are here

function opigno_statistics_app_query_course_course_lessons in Opigno Statistics App 7

Query course lesson statistics for a course (cached for 1 day)

Parameters

int $course_nid:

Return value

array

1 call to opigno_statistics_app_query_course_course_lessons()
opigno_statistics_app_present_course_course_lessons in includes/group/course/presenters.inc
Present course lessons statistics

File

includes/group/course/queries.inc, line 177

Code

function opigno_statistics_app_query_course_course_lessons($course_nid) {
  $cache_key = __FUNCTION__ . ':' . $course_nid;
  $cached_object = cache_get($cache_key);
  if ($cached_object) {
    $course_lessons = $cached_object->data;
  }
  else {
    $course_lessons = array();
    $result = db_query("\n      SELECT ucd.entity_name as lesson_name, ROUND(AVG(ucd.score), 0) as score, SUM(ug.page_views) as number_of_interactions\n      FROM {opigno_statistics_user_course_details} ucd\n      LEFT JOIN opigno_statistics_user_group ug ON ug.nid = ucd.entity_id\n      WHERE entity_id IN (\n        SELECT etid\n        FROM {og_membership}\n        WHERE group_type = 'node'\n        AND entity_type = 'node'\n        AND gid = :course_nid\n      )\n      GROUP BY entity_id\n    ", array(
      ':course_nid' => $course_nid,
    ));
    while ($record = $result
      ->fetchAssoc()) {
      if (empty($record['number_of_interactions'])) {
        $record['number_of_interactions'] = 0;
      }
      $course_lessons[] = $record;
    }
    cache_set($cache_key, $course_lessons, 'cache', time() + 7200);

    // 7200s = 2h cache
  }
  return $course_lessons;
}