function opigno_lrs_stats_course_content_course_contexts_statistics in Opigno TinCan API 7
Present course contexts statistics
Output example: array( 'http://opigno.com/node/15' => array( 'number_of_visit' => 123, 'number_of_users' => 15, 'percentage_of_users' => 34 ), 'http://opigno.com/node/18' => array( 'number_of_visit' => 33, 'number_of_users' => 15, 'percentage_of_users' => 12 )
)
Parameters
$statement_filter_function: Function to use as statement filter
Return value
array
1 call to opigno_lrs_stats_course_content_course_contexts_statistics()
- opigno_lrs_stats_course_content_page in modules/
opigno_tincan_api_stats/ includes/ course_content/ course_content.pages.inc - Display courses statistic page
File
- modules/
opigno_tincan_api_stats/ includes/ course_content/ model.inc, line 118 - Courses model functions
Code
function opigno_lrs_stats_course_content_course_contexts_statistics($statement_filter_function = NULL) {
$statements = function_exists($statement_filter_function) ? $statement_filter_function(opigno_lrs_stats_all_course_content_statements()) : opigno_lrs_stats_all_course_content_statements();
$statements_aggregated_by_courses = opigno_lrs_stats_aggregate_statements_by_context($statements);
$course_contexts_statistics = array_fill_keys(array_keys($statements_aggregated_by_courses), array(
'number_of_visit' => 0,
'number_of_users' => 0,
'percentage_of_users' => 0,
));
$statements_aggregated_by_courses_and_verb = array_map('opigno_lrs_stats_aggregate_statements_by_verb', $statements_aggregated_by_courses);
$statements_aggregated_by_courses_and_user = array_map('opigno_lrs_stats_aggregate_statements_by_user', $statements_aggregated_by_courses);
$total_number_of_users = count(opigno_lrs_stats_aggregate_statements_by_user(isset($statement_filter_function) ? $statement_filter_function(opigno_lrs_stats_all_statements()) : opigno_lrs_stats_all_statements()));
foreach ($course_contexts_statistics as $course_context_id => &$course_context_statistics) {
//Get course title in first statement
//Try to use node title first, then if node has been removed, use title from statement
$course_nid = opigno_lrs_stats_get_nid_by_object_id($course_context_id);
$course = node_load($course_nid);
$course_context_statistics['title'] = $course ? $course->title : $statements_aggregated_by_courses[$course_context_id][0]->context->contextActivities->grouping->definition->name->{'en-US'};
// $tincan_verb=tincanapi_get_verb('viewed'); // TODO: remove this
$tincan_verb = OpignoTincanApiTinCanVerbs::$viewed;
$viewed_verb_id = $tincan_verb['id'];
$viewed_statements = @$statements_aggregated_by_courses_and_verb[$course_context_id][$viewed_verb_id];
if (isset($viewed_statements)) {
$course_context_statistics['number_of_visit'] = count($viewed_statements);
}
$course_context_statistics['number_of_users'] = count($statements_aggregated_by_courses_and_user[$course_context_id]);
$course_context_statistics['percentage_of_users'] = $total_number_of_users > 0 ? round($course_context_statistics['number_of_users'] / $total_number_of_users * 100, 0) : 0;
}
return $course_contexts_statistics;
}