Minor - format code, adding docs, removing using global $_configuration

1.9.x
Julio Montoya 11 years ago
parent 49fa5ac510
commit bc40f9de5e
  1. 6
      main/admin/statistics/index.php
  2. 106
      main/admin/statistics/statistics.lib.php
  3. 239
      main/inc/lib/events.lib.inc.php

@ -48,7 +48,6 @@ $tools[$strSocial]['report=messagesent'] = get_lang('MessagesSent');
$tools[$strSocial]['report=messagereceived'] = get_lang('MessagesReceived');
$tools[$strSocial]['report=friends'] = get_lang('CountFriends');
echo '<table><tr>';
foreach ($tools as $section => $items) {
echo '<td style="vertical-align:top;">';
@ -86,7 +85,8 @@ switch ($_REQUEST['report']) {
case 'users':
// total amount of users
Statistics::print_stats(
get_lang('NumberOfUsers'), array(
get_lang('NumberOfUsers'),
array(
get_lang('Teachers') => Statistics::count_users(1, null, $_GET['count_invisible_courses']),
get_lang('Students') => Statistics::count_users(5, null, $_GET['count_invisible_courses'])
)
@ -117,11 +117,9 @@ switch ($_REQUEST['report']) {
case 'zombies':
ZombieReport::create(array('report' => 'zombies'))->display();
break;
//---
case 'activities':
Statistics::print_activities_stats();
break;
//---
case 'messagesent':
$messages_sent = Statistics::get_messages('sent');
Statistics::print_stats(get_lang('MessagesSent'), $messages_sent);

@ -5,14 +5,15 @@
* This class provides some functions for statistics
* @package chamilo.statistics
*/
class Statistics {
class Statistics
{
/**
* Converts a number of bytes in a formatted string
* @param int $size
* @return string Formatted file size
*/
static function make_size_string($size) {
static function make_size_string($size)
{
if ($size < pow(2,10)) return $size." bytes";
if ($size >= pow(2,10) && $size < pow(2,20)) return round($size / pow(2,10), 0)." KB";
if ($size >= pow(2,20) && $size < pow(2,30)) return round($size / pow(2,20), 1)." MB";
@ -25,8 +26,8 @@ class Statistics {
* all courses.
* @return int Number of courses counted
*/
static function count_courses($category_code = NULL) {
global $_configuration;
static function count_courses($category_code = NULL)
{
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$access_url_rel_course_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$current_url_id = api_get_current_access_url_id();
@ -52,13 +53,17 @@ class Statistics {
* all courses.
* @return int Number of courses counted
*/
static function count_courses_by_visibility($vis = null) {
if (!isset($vis)) { return 0; }
static function count_courses_by_visibility($vis = null)
{
if (!isset($vis)) {
return 0;
}
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$access_url_rel_course_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$current_url_id = api_get_current_access_url_id();
if (api_is_multiple_url_enabled()) {
$sql = "SELECT COUNT(*) AS number FROM ".$course_table." as c, ".$access_url_rel_course_table." as u WHERE u.course_code=c.code AND access_url_id='".$current_url_id."'";
$sql = "SELECT COUNT(*) AS number FROM ".$course_table." as c, ".$access_url_rel_course_table." as u
WHERE u.course_code=c.code AND access_url_id='".$current_url_id."'";
if (isset ($vis)) {
$sql .= " AND visibility = ".intval($vis);
}
@ -81,7 +86,8 @@ class Statistics {
* @param bool count only active users (false to only return currently active users)
* @return int Number of users counted
*/
static function count_users($status = null, $category_code = null, $count_invisible_courses = true, $only_active = false) {
static function count_users($status = null, $category_code = null, $count_invisible_courses = true, $only_active = false)
{
// Database table definitions
$course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
@ -113,7 +119,8 @@ class Statistics {
* Count sessions
* @return int Number of sessions counted
*/
static function count_sessions() {
static function count_sessions()
{
$session_table = Database :: get_main_table(TABLE_MAIN_SESSION);
$access_url_rel_session_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
if (api_is_multiple_url_enabled()) {
@ -126,11 +133,13 @@ class Statistics {
$obj = Database::fetch_object($res);
return $obj->number;
}
/**
* Count activities from track_e_default_table
* @return int Number of activities counted
*/
static function get_number_of_activities() {
static function get_number_of_activities()
{
// Database table definitions
global $_configuration;
$track_e_default = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
@ -156,8 +165,9 @@ class Statistics {
/**
* Get activities data to display
*/
static function get_activities_data($from, $number_of_items, $column, $direction) {
global $dateTimeFormatLong, $_configuration;
static function get_activities_data($from, $number_of_items, $column, $direction)
{
global $dateTimeFormatLong;
$track_e_default = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
@ -170,7 +180,8 @@ class Statistics {
if (!in_array($direction, array('ASC','DESC'))) {
$direction = 'DESC';
}
if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$sql = "SELECT ".
"default_event_type as col0, ".
"default_value_type as col1, ".
@ -239,7 +250,8 @@ class Statistics {
* Get all course categories
* @return array All course categories (code => name)
*/
static function get_course_categories() {
static function get_course_categories()
{
$category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
$sql = "SELECT code, name FROM $category_table ORDER BY tree_pos";
$res = Database::query($sql);
@ -321,12 +333,13 @@ class Statistics {
* Show some stats about the number of logins
* @param string $type month, hour or day
*/
static function print_login_stats($type) {
global $_configuration;
static function print_login_stats($type)
{
$table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$current_url_id = api_get_current_access_url_id();
if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$table_url = ", $access_url_rel_user_table";
$where_url = " WHERE login_user_id=user_id AND access_url_id='".$current_url_id."'";
$where_url_last = ' AND login_date > DATE_SUB(NOW(),INTERVAL 1 %s)';
@ -395,13 +408,13 @@ class Statistics {
/**
* Print the number of recent logins
*/
static function print_recent_login_stats() {
global $_configuration;
static function print_recent_login_stats()
{
$total_logins = array();
$table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$current_url_id = api_get_current_access_url_id();
if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$table_url = ", $access_url_rel_user_table";
$where_url = " AND login_user_id=user_id AND access_url_id='".$current_url_id."'";
} else {
@ -422,8 +435,8 @@ class Statistics {
/**
* Show some stats about the accesses to the different course tools
*/
static function print_tool_stats() {
global $_configuration;
static function print_tool_stats()
{
$table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
$access_url_rel_course_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$current_url_id = api_get_current_access_url_id();
@ -436,7 +449,7 @@ class Statistics {
foreach ($tools as $tool) {
$tool_names[$tool] = get_lang(ucfirst($tool), '');
}
if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$sql = "SELECT access_tool, count( access_id ) ".
"AS number_of_logins FROM $table, $access_url_rel_course_table ".
"WHERE access_tool IN ('".implode("','",$tools)."') AND course_code = access_cours_code AND access_url_id='".$current_url_id."' ".
@ -458,12 +471,12 @@ class Statistics {
/**
* Show some stats about the number of courses per language
*/
static function print_course_by_language_stats() {
global $_configuration;
static function print_course_by_language_stats()
{
$table = Database :: get_main_table(TABLE_MAIN_COURSE);
$access_url_rel_course_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$current_url_id = api_get_current_access_url_id();
if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$sql = "SELECT course_language, count( c.code ) AS number_of_courses ".
"FROM $table as c, $access_url_rel_course_table as u
WHERE u.course_code=c.code AND access_url_id='".$current_url_id."'
@ -483,12 +496,12 @@ class Statistics {
/**
* Shows the number of users having their picture uploaded in Dokeos.
*/
static function print_user_pictures_stats() {
global $_configuration;
static function print_user_pictures_stats()
{
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
$access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$current_url_id = api_get_current_access_url_id();
if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$url_condition = ", $access_url_rel_user_table as url WHERE url.user_id=u.user_id AND access_url_id='".$current_url_id."'";
$url_condition2 = " AND url.user_id=u.user_id AND access_url_id='".$current_url_id."'";
$table = ", $access_url_rel_user_table as url ";
@ -506,10 +519,12 @@ class Statistics {
Statistics::print_stats(get_lang('CountUsers').' ('.get_lang('UserPicture').')',$result,true);
}
static function print_activities_stats() {
/**
* Important activities
*/
static function print_activities_stats()
{
echo '<h4>'.get_lang('ImportantActivities').'</h4>';
// Create a search-box
$form = new FormValidator('search_simple','get',api_get_path(WEB_CODE_PATH).'admin/statistics/index.php','','width=200px',false);
$renderer =& $form->defaultRenderer();
@ -544,8 +559,8 @@ class Statistics {
/**
* Shows statistics about the time of last visit to each course.
*/
static function print_course_last_visit() {
global $_configuration;
static function print_course_last_visit()
{
$access_url_rel_course_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$current_url_id = api_get_current_access_url_id();
@ -577,7 +592,7 @@ class Statistics {
$values = $form->exportValues();
$date_diff = $values['date_diff'];
$table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$sql = "SELECT * FROM $table, $access_url_rel_course_table WHERE course_code = access_cours_code AND access_url_id='".$current_url_id."' ".
"GROUP BY access_cours_code ".
"HAVING access_cours_code <> '' ".
@ -619,8 +634,8 @@ class Statistics {
* @param string Type of message: 'sent' or 'received'
* @return array Message list
*/
static function get_messages($message_type) {
global $_configuration;
static function get_messages($message_type)
{
$message_table = Database::get_main_table(TABLE_MAIN_MESSAGE);
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$access_url_rel_user_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
@ -635,8 +650,7 @@ class Statistics {
$field = 'user_receiver_id';
break;
}
if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$sql = "SELECT lastname, firstname, username, COUNT($field) AS count_message ".
"FROM ".$access_url_rel_user_table." as url, ".$message_table." m ".
"LEFT JOIN ".$user_table." u ON m.$field = u.user_id ".
@ -663,14 +677,14 @@ class Statistics {
/**
* Count the number of friends for social network users
*/
static function get_friends() {
global $_configuration;
static function get_friends()
{
$user_friend_table = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$current_url_id = api_get_current_access_url_id();
if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$sql = "SELECT lastname, firstname, username, COUNT(friend_user_id) AS count_friend ".
"FROM ".$access_url_rel_user_table." as url, ".$user_friend_table." uf ".
"LEFT JOIN ".$user_table." u ON uf.user_id = u.user_id ".
@ -695,14 +709,14 @@ class Statistics {
/**
* Print the number of users that didn't login for a certain period of time
*/
static function print_users_not_logged_in_stats() {
global $_configuration;
static function print_users_not_logged_in_stats()
{
$total_logins = array();
$table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$current_url_id = api_get_current_access_url_id();
$total = self::count_users();
if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$table_url = ", $access_url_rel_user_table";
$where_url = " AND login_user_id=user_id AND access_url_id='".$current_url_id."'";
} else {

@ -11,7 +11,6 @@
*
* @package chamilo.library
*/
/* INIT SECTION */
$TABLETRACK_LOGIN = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$TABLETRACK_OPEN = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_OPEN);
@ -24,21 +23,20 @@ $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK
$TABLETRACK_LASTACCESS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS); //for "what's new" notification
$TABLETRACK_DEFAULT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
/* FUNCTIONS */
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @desc Record information for open event (when homepage is opened)
*/
function event_open() {
function event_open()
{
global $_configuration;
global $TABLETRACK_OPEN;
// @getHostByAddr($_SERVER['REMOTE_ADDR']) : will provide host and country information
// $_SERVER['HTTP_USER_AGENT'] : will provide browser and os information
// $_SERVER['HTTP_REFERER'] : provide information about refering url
if(isset($_SERVER['HTT_REFERER']))
{
if (isset($_SERVER['HTT_REFERER'])) {
$referer = Database::escape_string($_SERVER['HTTP_REFERER']);
} else {
$referer = '';
@ -70,14 +68,13 @@ function event_open() {
* @desc Record information for login event
* (when an user identifies himself with username & password)
*/
function event_login() {
global $_user;
function event_login()
{
global $TABLETRACK_LOGIN;
$reallyNow = api_get_utc_datetime();
$sql = "INSERT INTO ".$TABLETRACK_LOGIN." (login_user_id, login_ip, login_date, logout_date) VALUES
('".$_user['user_id']."',
('".api_get_user_id()."',
'".Database::escape_string(api_get_real_ip())."',
'".$reallyNow."',
'".$reallyNow."'
@ -149,9 +146,9 @@ function event_access_course() {
*
* Functionality for "what's new" notification is added by Toon Van Hoecke
*/
function event_access_tool($tool, $id_session=0) {
function event_access_tool($tool, $id_session = 0)
{
global $_configuration;
global $_user;
global $_cid;
global $TABLETRACK_ACCESS;
global $_course;
@ -160,7 +157,7 @@ function event_access_tool($tool, $id_session=0) {
$id_session = api_get_session_id();
$tool = Database::escape_string($tool);
$reallyNow = api_get_utc_datetime();
$user_id = $_user['user_id'] ? "'".$_user['user_id']."'" : "0"; // no one
$user_id = api_get_user_id();
// record information
// only if user comes from the course $_cid
//if( eregi($_configuration['root_web'].$_cid,$_SERVER['HTTP_REFERER'] ) )
@ -212,7 +209,8 @@ function event_access_tool($tool, $id_session=0) {
* and later again.
* Doing this twice causes an error, I remove one of them.
*/
function event_download($doc_url) {
function event_download($doc_url)
{
$tbl_stats_downloads = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
$doc_url = Database::escape_string($doc_url);
@ -244,15 +242,11 @@ function event_download($doc_url) {
* @desc Record information for link event (when an user click on an added link)
* it will be used in a redirection page
*/
function event_link($link_id) {
global $_user, $TABLETRACK_LINKS;
function event_link($link_id)
{
global $TABLETRACK_LINKS;
$reallyNow = api_get_utc_datetime();
if (isset($_user['user_id']) && $_user['user_id']!='') {
$user_id = "'".Database::escape_string($_user['user_id'])."'";
} else {
// anonymous
$user_id = "0";
}
$user_id = api_get_user_id();
$sql = "INSERT INTO ".$TABLETRACK_LINKS."
( links_user_id,
links_cours_id,
@ -286,9 +280,11 @@ function event_link($link_id) {
* @author Julio Montoya Armas <gugli100@gmail.com> Reworked 2010
* @desc Record result of user when an exercice was done
*/
function update_event_exercice($exeid, $exo_id, $score, $weighting, $session_id, $learnpath_id = 0, $learnpath_item_id = 0, $learnpath_item_view_id = 0, $duration = 0, $question_list = array(), $status = '', $remind_list = array() , $end_date = null) {
function update_event_exercice($exeid, $exo_id, $score, $weighting, $session_id, $learnpath_id = 0, $learnpath_item_id = 0, $learnpath_item_view_id = 0, $duration = 0, $question_list = array(), $status = '', $remind_list = array() , $end_date = null)
{
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
global $debug;
if ($debug) error_log('Called to update_event_exercice');
if ($debug) error_log('duration:' . $duration);
@ -357,9 +353,11 @@ function update_event_exercice($exeid, $exo_id, $score, $weighting, $session_id,
* @desc Record result of user when an exercice was done
* @deprecated this function seems to be deprecated
*/
function create_event_exercice($exo_id) {
if (empty($exo_id) or (intval($exo_id)!=$exo_id)) { return false; }
//error_log('create_event_exercice');
function create_event_exercice($exo_id)
{
if (empty($exo_id) or (intval($exo_id)!=$exo_id)) {
return false;
}
$tbl_track_exe = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$tbl_exe = Database::get_course_table(TABLE_QUIZ_TEST);
$uid = api_get_user_id();
@ -410,7 +408,8 @@ function create_event_exercice($exo_id) {
* @param integer Position
* @return boolean Result of the insert query
*/
function exercise_attempt($score, $answer, $question_id, $exe_id, $position, $exercise_id = 0, $nano = null) {
function exercise_attempt($score, $answer, $question_id, $exe_id, $position, $exercise_id = 0, $nano = null)
{
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
global $debug, $learnpath_id, $learnpath_item_id;
$score = Database::escape_string($score);
@ -424,7 +423,6 @@ function exercise_attempt($score, $answer, $question_id, $exe_id, $position, $ex
$TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
if ($debug) error_log("----- entering exercise_attempt() function ------");
if ($debug) error_log("answer: $answer");
if ($debug) error_log("score: $score");
if ($debug) error_log("question_id : $question_id");
@ -505,7 +503,8 @@ function exercise_attempt($score, $answer, $question_id, $exe_id, $position, $ex
* @return boolean Result of the insert query
* @uses Course code and user_id from global scope $_cid and $_user
*/
function exercise_attempt_hotspot($exe_id, $question_id, $answer_id, $correct, $coords, $exerciseId = 0) {
function exercise_attempt_hotspot($exe_id, $question_id, $answer_id, $correct, $coords, $exerciseId = 0)
{
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
global $safe_lp_id, $safe_lp_item_id;
//Validation in case of fraud with actived control time
@ -536,7 +535,8 @@ function exercise_attempt_hotspot($exe_id, $question_id, $answer_id, $correct, $
* @param string Course code (defaults to null)
* @assert ('','','') === false
*/
function event_system($event_type, $event_value_type, $event_value, $datetime = null, $user_id = null, $course_code = null) {
function event_system($event_type, $event_value_type, $event_value, $datetime = null, $user_id = null, $course_code = null)
{
global $TABLETRACK_DEFAULT;
if (empty($event_type)) {
return false;
@ -583,12 +583,8 @@ function event_system($event_type, $event_value_type, $event_value, $datetime =
$user_id = intval($user_id);
$sql = "INSERT INTO $TABLETRACK_DEFAULT ".
" (default_user_id, default_cours_code, c_id, ".
" default_date, default_event_type, default_value_type, default_value ".
" ) VALUES( ".
" '$user_id', '$course_code', '$course_id', ".
" '$datetime', '$event_type', '$event_value_type', '$event_value')";
$sql = "INSERT INTO $TABLETRACK_DEFAULT (default_user_id, default_cours_code, c_id, default_date, default_event_type, default_value_type, default_value)
VALUES ('$user_id', '$course_code', '$course_id', '$datetime', '$event_type', '$event_value_type', '$event_value')";
Database::query($sql);
return true;
}
@ -627,7 +623,8 @@ function get_all_event_types() {
*/
function get_users_subscribed_to_event($event_name) {
$event_name = Database::escape_string($event_name);
$sql = 'SELECT u.* FROM '. Database::get_main_table(TABLE_MAIN_USER).' u,'
$sql = 'SELECT u.*
FROM '.Database::get_main_table(TABLE_MAIN_USER).' u,'
.Database::get_main_table(TABLE_MAIN_EVENT_TYPE).' e,'
.Database::get_main_table(TABLE_EVENT_TYPE_REL_USER).' ue
WHERE ue.user_id = u.user_id
@ -642,18 +639,21 @@ function get_users_subscribed_to_event($event_name) {
*
* @param string $event_name
*/
function get_event_users($event_name) {
function get_event_users($event_name)
{
$event_name = Database::escape_string($event_name);
$sql = 'SELECT user.user_id, user.firstname, user.lastname FROM '.Database::get_main_table(TABLE_MAIN_USER).' user JOIN '.Database::get_main_table(TABLE_EVENT_TYPE_REL_USER).' relUser
ON relUser.user_id = user.user_id
WHERE user.status <> '.ANONYMOUS.' AND relUser.event_type_name = "'.$event_name.'"';
//For tests
//$sql = 'SELECT user.user_id, user.firstname, user.lastname FROM '.Database::get_main_table(TABLE_MAIN_USER);
$user_list = Database::store_result(Database::query($sql), 'ASSOC');
return json_encode($user_list);
}
/**
* @param int $user_id
* @param string $event_type
* @return array|bool
*/
function get_events_by_user_and_type($user_id, $event_type) {
global $TABLETRACK_DEFAULT;
$user_id = intval($user_id);
@ -671,6 +671,11 @@ function get_events_by_user_and_type($user_id, $event_type) {
return false;
}
/**
* @param int $user_id
* @param string $event_type
* @return mixed
*/
function get_latest_event_by_user_and_type($user_id, $event_type) {
$result = get_events_by_user_and_type($user_id, $event_type);
if ($result && !empty($result)) {
@ -688,7 +693,8 @@ function get_latest_event_by_user_and_type($user_id, $event_type) {
* @param string $eventMessageLanguage
* @param int $activated
*/
function save_event_type_message($event_name, $users, $message, $subject, $event_message_language, $activated) {
function save_event_type_message($event_name, $users, $message, $subject, $event_message_language, $activated)
{
$event_name = Database::escape_string($event_name);
$activated = intval($activated);
$event_message_language = Database::escape_string($event_message_language);
@ -737,6 +743,12 @@ function save_event_type_message($event_name, $users, $message, $subject, $event
Database::query($sql);
}
/**
* @param $etId
* @param $users
* @param $message
* @param $subject
*/
function eventType_mod($etId, $users, $message, $subject) {
$etId = intval($etId);
@ -759,8 +771,12 @@ function eventType_mod($etId, $users, $message, $subject) {
/**
* Gets the last attempt of an exercise based in the exe_id
*
* @param $exe_id
* @return mixed
*/
function get_last_attempt_date_of_exercise($exe_id) {
function get_last_attempt_date_of_exercise($exe_id)
{
$exe_id = intval($exe_id);
$track_attempts = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
@ -807,9 +823,15 @@ function get_attempt_count($user_id, $exerciseId, $lp_id, $lp_item_id,$lp_item_v
}
}
function get_attempt_count_not_finished($user_id, $exerciseId, $lp_id, $lp_item_id) {
/**
* @param int $user_id
* @param int $exerciseId
* @param int $lp_id
* @param int $lp_item_id
* @return int
*/
function get_attempt_count_not_finished($user_id, $exerciseId, $lp_id, $lp_item_id)
{
$stat_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$user_id = intval($user_id);
$exerciseId = intval($exerciseId);
@ -835,8 +857,12 @@ function get_attempt_count_not_finished($user_id, $exerciseId, $lp_id, $lp_item_
}
}
/**
* @param int $user_id
* @param int $lp_id
* @param array $course
* @param int $session_id
*/
function delete_student_lp_events($user_id, $lp_id, $course, $session_id) {
$lp_view_table = Database::get_course_table(TABLE_LP_VIEW);
@ -897,7 +923,8 @@ function delete_student_lp_events($user_id, $lp_id, $course, $session_id) {
* @param string course code
* @param int session id
*/
function delete_all_incomplete_attempts($user_id, $exercise_id, $course_code, $session_id = 0) {
function delete_all_incomplete_attempts($user_id, $exercise_id, $course_code, $session_id = 0)
{
$track_e_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$user_id = intval($user_id);
$exercise_id = intval($exercise_id);
@ -915,7 +942,6 @@ function delete_all_incomplete_attempts($user_id, $exercise_id, $course_code, $s
* @param string course code
* @param int session id
* @return array with the results
*
*/
function get_all_exercise_results($exercise_id, $course_code, $session_id = 0, $load_question_list = true, $user_id = null) {
$TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
@ -953,7 +979,6 @@ function get_all_exercise_results($exercise_id, $course_code, $session_id = 0, $
return $list;
}
/**
* Gets all exercise results (NO Exercises in LPs ) from a given exercise id, course, session
* @param string course code
@ -961,7 +986,8 @@ function get_all_exercise_results($exercise_id, $course_code, $session_id = 0, $
* @return array with the results
*
*/
function get_all_exercise_results_by_course($course_code, $session_id = 0, $get_count = true) {
function get_all_exercise_results_by_course($course_code, $session_id = 0, $get_count = true)
{
$table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$course_code = Database::escape_string($course_code);
@ -998,7 +1024,8 @@ function get_all_exercise_results_by_course($course_code, $session_id = 0, $get_
* @return array with the results
*
*/
function get_all_exercise_results_by_user($user_id, $course_code, $session_id = 0) {
function get_all_exercise_results_by_user($user_id, $course_code, $session_id = 0)
{
$table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$course_code = Database::escape_string($course_code);
@ -1030,7 +1057,8 @@ function get_all_exercise_results_by_user($user_id, $course_code, $session_id =
* @return array with the results
*
*/
function get_exercise_results_by_attempt($exe_id) {
function get_exercise_results_by_attempt($exe_id)
{
$table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$table_track_attempt_recording = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
@ -1073,7 +1101,8 @@ function get_exercise_results_by_attempt($exe_id) {
* @return array with the results
*
*/
function get_exercise_results_by_user($user_id, $exercise_id, $course_code, $session_id = 0, $lp_id = 0, $lp_item_id = 0, $order = null) {
function get_exercise_results_by_user($user_id, $exercise_id, $course_code, $session_id = 0, $lp_id = 0, $lp_item_id = 0, $order = null)
{
$table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$table_track_attempt_recording = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
@ -1128,7 +1157,8 @@ function get_exercise_results_by_user($user_id, $exercise_id, $course_code, $ses
* @return array with the results
*
*/
function count_exercise_attempts_by_user($user_id, $exercise_id, $course_code, $session_id = 0) {
function count_exercise_attempts_by_user($user_id, $exercise_id, $course_code, $session_id = 0)
{
$TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$course_code = Database::escape_string($course_code);
$exercise_id = intval($exercise_id);
@ -1155,7 +1185,8 @@ function count_exercise_attempts_by_user($user_id, $exercise_id, $course_code, $
* @todo rename this function
*
*/
function get_best_exercise_results_by_user($exercise_id, $course_code, $session_id = 0) {
function get_best_exercise_results_by_user($exercise_id, $course_code, $session_id = 0)
{
$table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$course_code = Database::escape_string($course_code);
@ -1188,7 +1219,8 @@ function get_best_exercise_results_by_user($exercise_id, $course_code, $session_
return $best_score_return;
}
function get_best_attempt_exercise_results_per_user($user_id, $exercise_id, $course_code, $session_id = 0) {
function get_best_attempt_exercise_results_per_user($user_id, $exercise_id, $course_code, $session_id = 0)
{
$table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
//$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$course_code = Database::escape_string($course_code);
@ -1209,12 +1241,7 @@ function get_best_attempt_exercise_results_per_user($user_id, $exercise_id, $cou
$res = Database::query($sql);
$list = array();
while($row = Database::fetch_array($res,'ASSOC')) {
$list[$row['exe_id']] = $row; /*
$sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}";
$res_question = Database::query($sql);
while($row_q = Database::fetch_array($res_question,'ASSOC')) {
$list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
} */
$list[$row['exe_id']] = $row;
}
//Getting the best results of every student
$best_score_return = array();
@ -1232,9 +1259,14 @@ function get_best_attempt_exercise_results_per_user($user_id, $exercise_id, $cou
return $best_score_return;
}
function count_exercise_result_not_validated($exercise_id, $course_code, $session_id = 0) {
/**
* @param int $exercise_id
* @param string $course_code
* @param int $session_id
* @return mixed
*/
function count_exercise_result_not_validated($exercise_id, $course_code, $session_id = 0)
{
$table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
$course_code = Database::escape_string($course_code);
@ -1251,12 +1283,9 @@ function count_exercise_result_not_validated($exercise_id, $course_code, $sessio
orig_lp_item_id = 0 ORDER BY e.exe_id";
$res = Database::query($sql);
$row = Database::fetch_array($res,'ASSOC');
return $row['count'];
}
/**
* Gets all exercise BEST results attempts (NO Exercises in LPs ) from a given exercise id, course, session per user
* @param int exercise id
@ -1265,13 +1294,17 @@ function count_exercise_result_not_validated($exercise_id, $course_code, $sessio
* @return array with the results
*
*/
function get_count_exercises_attempted_by_course($course_code, $session_id = 0) {
function get_count_exercises_attempted_by_course($course_code, $session_id = 0)
{
$table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$course_code = Database::escape_string($course_code);
$session_id = intval($session_id);
$sql = "SELECT DISTINCT exe_exo_id, exe_user_id FROM $table_track_exercises WHERE status = '' AND exe_cours_id = '$course_code' AND session_id = $session_id AND orig_lp_id =0 AND orig_lp_item_id = 0 ORDER BY exe_id";
$sql = "SELECT DISTINCT exe_exo_id, exe_user_id
FROM $table_track_exercises
WHERE status = '' AND exe_cours_id = '$course_code' AND session_id = $session_id AND orig_lp_id =0 AND orig_lp_item_id = 0
ORDER BY exe_id";
$res = Database::query($sql);
$count = 0;
if (Database::num_rows($res) > 0) {
@ -1288,14 +1321,16 @@ function get_count_exercises_attempted_by_course($course_code, $session_id = 0)
* @param int session id
* @return array
*/
function get_all_exercise_event_from_lp($exercise_id, $course_code, $session_id = 0) {
function get_all_exercise_event_from_lp($exercise_id, $course_code, $session_id = 0)
{
$table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$course_code = Database::escape_string($course_code);
$exercise_id = intval($exercise_id);
$session_id = intval($session_id);
$sql = "SELECT * FROM $table_track_exercises WHERE status = '' AND exe_cours_id = '$course_code' AND exe_exo_id = '$exercise_id' AND session_id = $session_id AND orig_lp_id !=0 AND orig_lp_item_id != 0";
$sql = "SELECT * FROM $table_track_exercises
WHERE status = '' AND exe_cours_id = '$course_code' AND exe_exo_id = '$exercise_id' AND session_id = $session_id AND orig_lp_id !=0 AND orig_lp_item_id != 0";
$res = Database::query($sql);
$list = array();
@ -1310,8 +1345,13 @@ function get_all_exercise_event_from_lp($exercise_id, $course_code, $session_id
return $list;
}
function get_all_exercises_from_lp($lp_id, $course_id) {
/**
* @param int $lp_id
* @param int $course_id
* @return array
*/
function get_all_exercises_from_lp($lp_id, $course_id)
{
$lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
$course_id = intval($course_id);
$lp_id = intval($lp_id);
@ -1326,7 +1366,6 @@ function get_all_exercises_from_lp($lp_id, $course_id) {
return $my_exercise_list;
}
/**
* This function gets the comments of an exercise
*
@ -1334,7 +1373,8 @@ function get_all_exercises_from_lp($lp_id, $course_id) {
* @param int $question_id
* @return str the comment
*/
function get_comments($exe_id, $question_id) {
function get_comments($exe_id, $question_id)
{
$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$sql = "SELECT teacher_comment FROM ".$table_track_attempt."
WHERE exe_id='".Database::escape_string($exe_id)."' AND question_id = '".Database::escape_string($question_id)."' ORDER by question_id";
@ -1343,8 +1383,12 @@ function get_comments($exe_id, $question_id) {
return $comm;
}
function get_all_exercise_event_by_exe_id($exe_id) {
/**
* @param int $exe_id
* @return array
*/
function get_all_exercise_event_by_exe_id($exe_id)
{
$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$exe_id = intval($exe_id);
$list = array();
@ -1358,8 +1402,15 @@ function get_all_exercise_event_by_exe_id($exe_id) {
return $list;
}
function delete_attempt($exe_id, $user_id, $course_code, $session_id, $question_id) {
/**
* @param int $exe_id
* @param int $user_id
* @param string $course_code
* @param int $session_id
* @param int $question_id
*/
function delete_attempt($exe_id, $user_id, $course_code, $session_id, $question_id)
{
$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$exe_id = intval($exe_id);
@ -1368,10 +1419,17 @@ function delete_attempt($exe_id, $user_id, $course_code, $session_id, $question_
$session_id = intval($session_id);
$question_id = intval($question_id);
$sql = "DELETE FROM $table_track_attempt WHERE exe_id = $exe_id AND user_id = $user_id AND course_code = '$course_code' AND session_id = $session_id AND question_id = $question_id ";
$sql = "DELETE FROM $table_track_attempt
WHERE exe_id = $exe_id AND user_id = $user_id AND course_code = '$course_code' AND session_id = $session_id AND question_id = $question_id ";
Database::query($sql);
}
/**
* @param int $exe_id
* @param int $user_id
* @param string $course_code
* @param int $question_id
*/
function delete_attempt_hotspot($exe_id, $user_id, $course_code, $question_id) {
$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
@ -1381,12 +1439,16 @@ function delete_attempt_hotspot($exe_id, $user_id, $course_code, $question_id) {
//$session_id = intval($session_id);
$question_id = intval($question_id);
$sql = "DELETE FROM $table_track_attempt WHERE hotspot_exe_id = $exe_id AND hotspot_user_id = $user_id AND hotspot_course_code = '$course_code' AND hotspot_question_id = $question_id ";
$sql = "DELETE FROM $table_track_attempt
WHERE hotspot_exe_id = $exe_id AND hotspot_user_id = $user_id AND hotspot_course_code = '$course_code' AND hotspot_question_id = $question_id ";
Database::query($sql);
}
/**
* User logs in for the first time to a course
* @param string $course_code
* @param int $user_id
* @param int $session_id
*/
function event_course_login($course_code, $user_id, $session_id) {
global $course_tracking_table;
@ -1402,7 +1464,6 @@ function event_course_login($course_code, $user_id, $session_id) {
VALUES('".$course_code."', '".$user_id."', '$time', '$time', '1', '".$session_id."')";
Database::query($sql);
// Course catalog stats modifications see #4191
CourseManager::update_course_ranking(null, null, null, null, true, false);
}
@ -1415,7 +1476,8 @@ function event_course_login($course_code, $user_id, $session_id) {
* @param string $event_name
* @param array $params
*/
function event_send_mail($event_name, $params) {
function event_send_mail($event_name, $params)
{
EventsMail::send_mail($event_name, $params);
}
@ -1439,9 +1501,7 @@ function check_if_mail_already_sent($event_name, $user_from, $user_to = null) {
}
/*
*
* Filter EventEmailTemplate Filters see the main/inc/conf/events.conf.dist.php
*
*/
/**
@ -1473,9 +1533,4 @@ function portal_homepage_edited_event_send_mail_filter_func(&$values) {
return $res;
}
/**
*
*/
/* End of filters */

Loading…
Cancel
Save