From 63b652f80a4a024fbd61afec50dead2ad51310c6 Mon Sep 17 00:00:00 2001 From: Cristian Fasanando Date: Tue, 6 Jan 2009 20:31:15 +0100 Subject: [PATCH] [svn r17551] Logic Changes - Implemented tracking for activity in forum and chat into learners tracking and course tracking see FS#1099 --- main/inc/lib/tracking.lib.php | 133 ++++++++++++++++++++++++++++++---- main/mySpace/myStudents.php | 17 ++--- main/tracking/courseLog.php | 45 ++++++++++++ 3 files changed, 170 insertions(+), 25 deletions(-) diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index 7f719358f2..fa737aa2b2 100644 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -788,7 +788,116 @@ class Tracking { } } - function last_three_connection_chat($student_id,$course_code) { +/** +* This function counts the number of post by course +* @param string $course_code - Course ID +* @return int the number of post by course +* @author Christian Fasanando , +* @version enero 2009, dokeos 1.8.6 +*/ + function count_number_of_posts_by_course($course_code) { + //protect data + $course_code = addslashes($course_code); + // get the informations of the course + $a_course = CourseManager :: get_course_information($course_code); + $count = 0; + if (!empty($a_course['db_name'])) { + $tbl_posts = Database :: get_course_table(TABLE_FORUM_POST, $a_course['db_name']); + $sql = "SELECT * FROM $tbl_posts"; + $result = api_sql_query($sql, __FILE__, __LINE__); + $count = Database::num_rows($result); + return $count; + } else { + return null; + } + } + +/** +* This function counts the number of threads by course +* @param string $course_code - Course ID +* @return int the number of threads by course +* @author Christian Fasanando , +* @version enero 2009, dokeos 1.8.6 +*/ + function count_number_of_threads_by_course($course_code) { + //protect data + $course_code = addslashes($course_code); + // get the informations of the course + $a_course = CourseManager :: get_course_information($course_code); + $count = 0; + if (!empty($a_course['db_name'])) { + $tbl_threads = Database :: get_course_table(TABLE_FORUM_THREAD, $a_course['db_name']); + $sql = "SELECT * FROM $tbl_threads"; + $result = api_sql_query($sql, __FILE__, __LINE__); + $count = Database::num_rows($result); + return $count; + } else { + return null; + } + } + +/** +* This function counts the number of forums by course +* @param string $course_code - Course ID +* @return int the number of forums by course +* @author Christian Fasanando , +* @version enero 2009, dokeos 1.8.6 +*/ + function count_number_of_forums_by_course($course_code) { + //protect data + $course_code = addslashes($course_code); + // get the informations of the course + $a_course = CourseManager :: get_course_information($course_code); + $count = 0; + if (!empty($a_course['db_name'])) { + $tbl_forums = Database :: get_course_table(TABLE_FORUM, $a_course['db_name']); + $sql = "SELECT * FROM $tbl_forums"; + $result = api_sql_query($sql, __FILE__, __LINE__); + $count = Database::num_rows($result); + return $count; + } else { + return null; + } + } + +/** +* This function counts the chat last connections by course in x days +* @param string $course_code - Course ID +* @param int $last_days - last x days +* @return int the chat last connections by course in x days +* @author Christian Fasanando , +* @version enero 2009, dokeos 1.8.6 +*/ + function chat_connections_during_last_x_days_by_course($course_code,$last_days) { + //protect data + $last_days = intval($last_days); + $course_code = addslashes($course_code); + // get the informations of the course + $a_course = CourseManager :: get_course_information($course_code); + $count = 0; + if (!empty($a_course['db_name'])) { + $tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS, $a_course['db_name']); + + $sql = "SELECT * FROM $tbl_stats_access WHERE DATE_SUB(NOW(),INTERVAL $last_days DAY) <= access_date + AND access_cours_code = '$course_code' AND access_tool='".TOOL_CHAT."'"; + $result = api_sql_query($sql, __FILE__, __LINE__); + $count = Database::num_rows($result); + return $count; + } else { + return null; + } + } + + +/** +* This function gets the last student's connection in chat +* @param int $student_id - Student ID +* @param string $course_code - Course ID +* @return string the last connection +* @author Christian Fasanando , +* @version enero 2009, dokeos 1.8.6 +*/ + function chat_last_connection($student_id,$course_code) { require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php'); //protect datas @@ -797,25 +906,23 @@ class Tracking { // get the informations of the course $a_course = CourseManager :: get_course_information($course_code); - + $date_time = ''; if (!empty($a_course['db_name'])) { // table definition $tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS, $a_course['db_name']); $sql = "SELECT access_date FROM $tbl_stats_access - WHERE access_tool='".TOOL_CHAT."' AND access_user_id='$student_id' AND access_cours_code = '$course_code' ORDER BY access_date DESC limit 3"; + WHERE access_tool='".TOOL_CHAT."' AND access_user_id='$student_id' AND access_cours_code = '$course_code' ORDER BY access_date DESC limit 1"; $rs = api_sql_query($sql, __LINE__, __FILE__); - $last_connnections = array(); - while ($row = Database::fetch_array($rs)) { - $last_connection = $row['access_date']; - if (isset($last_connection)) { - $date_format_long = format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_connection)); - $time = explode(' ',$last_connection); - $date_time = $date_format_long.' '.$time[1]; - $last_connnections[] = $date_time; - } + $row = Database::fetch_array($rs); + $last_connection = $row['access_date']; + if (!empty($last_connection)) { + $date_format_long = format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_connection)); + $time = explode(' ',$last_connection); + $date_time = $date_format_long.' '.$time[1]; } - return $last_connnections; + + return $date_time; } else { return null; } diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php index 0c8f744530..e555ec8aba 100644 --- a/main/mySpace/myStudents.php +++ b/main/mySpace/myStudents.php @@ -1,4 +1,4 @@ - @@ -915,18 +916,10 @@ if(!empty($_GET['student'])) - + - '; - - $last_connections_chat .= str_replace(',', ' ', $last_three_connections_chat[$i]).' '; - } - $csv_content[] = array(get_lang('LastConnectionsInChat'), $last_connections_chat); - ?> + diff --git a/main/tracking/courseLog.php b/main/tracking/courseLog.php index e7fda97614..6d348cdb94 100644 --- a/main/tracking/courseLog.php +++ b/main/tracking/courseLog.php @@ -261,6 +261,51 @@ if($_GET['studentlist'] == 'false') { echo ''; echo '
'; + + /********************** + * FORUMS + **********************/ + + echo '
+

+  '.get_lang('Forum').' '.get_lang('SeeDetail').' +

+ '; + $count_number_of_posts_by_course = Tracking :: count_number_of_posts_by_course($_course['id']); + $count_number_of_forums_by_course = Tracking :: count_number_of_forums_by_course($_course['id']); + $count_number_of_threads_by_course = Tracking :: count_number_of_threads_by_course($_course['id']); + if ($export_csv) { + $csv_content[] = array(get_lang('Forum'),''); + $csv_content[] = array(get_lang('ForumForumsNumber'),$count_number_of_forums_by_course); + $csv_content[] = array(get_lang('ForumThreadsNumber'),$count_number_of_threads_by_course); + $csv_content[] = array(get_lang('ForumPostsNumber'),$count_number_of_posts_by_course); + } + echo ''; + echo ''; + echo ''; + echo '
'.get_lang('ForumForumsNumber').''.$count_number_of_forums_by_course.'
'.get_lang('ForumThreadsNumber').''.$count_number_of_threads_by_course.'
'.get_lang('ForumPostsNumber').''.$count_number_of_posts_by_course.'
'; + echo '
'; + + /********************** + * CHAT + **********************/ + + echo '
+

+  '.get_lang('Chat').' +

+ '; + $chat_connections_during_last_x_days_by_course = Tracking :: chat_connections_during_last_x_days_by_course($_course['id'],7); + if ($export_csv) { + $csv_content[] = array(get_lang('Chat'),''); + $csv_content[] = array(sprintf(get_lang('ChatConnectionsDuringLastXDays'),'7'),$chat_connections_during_last_x_days_by_course); + } + echo ''; + + echo '
'.sprintf(get_lang('ChatConnectionsDuringLastXDays'),'7').''.$chat_connections_during_last_x_days_by_course.'
'; + echo '
'; + + /********************** * TOOLS **********************/