Cleanup - Removed straight calls to MySQL functions or to similarly named functions

skala
Yannick Warnier 13 years ago
parent a04ca2da58
commit 28de63c1a6
  1. 4
      main/admin/user_list.php
  2. 2
      main/inc/global.inc.php
  3. 89
      main/inc/lib/database.lib.php
  4. 4
      main/inc/lib/display.lib.php
  5. 8
      main/inc/lib/main_api.lib.php
  6. 2
      main/inc/lib/usermanager.lib.php
  7. 4
      main/newscorm/learnpathItem.class.php

@ -539,7 +539,7 @@ function get_user_data($from, $number_of_items, $column, $direction) {
}
if ($user[7] == 1 && $user[9] != '0000-00-00 00:00:00') {
// check expiration date
$expiration_time = convert_mysql_date($user[9]);
$expiration_time = convert_sql_date($user[9]);
// if expiration date is passed, store a special value for active field
if ($expiration_time < $t) {
$user[7] = '-1';
@ -960,4 +960,4 @@ $tpl = new Template($tool_name);
$tpl->assign('actions', $actions);
$tpl->assign('message', $message);
$tpl->assign('content', $form.$table);
$tpl->display_one_col_template();
$tpl->display_one_col_template();

@ -564,7 +564,7 @@ if (!isset($_SESSION['login_as']) && isset($_user)) {
// is the latest logout_date still relevant?
$sql_logout_date = "SELECT logout_date FROM $tbl_track_login WHERE login_id=$i_id_last_connection";
$q_logout_date = Database::query($sql_logout_date);
$res_logout_date = convert_mysql_date(Database::result($q_logout_date,0,'logout_date'));
$res_logout_date = convert_sql_date(Database::result($q_logout_date,0,'logout_date'));
if ($res_logout_date < time() - $_configuration['session_lifetime']) {
// it isn't, we should create a fresh entry

@ -1,27 +1,26 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This is the main database library for Chamilo.
* Include/require it in your code to use its functionality.
* Because this library contains all the basic database calls, it could be
* replaced by another library for say, PostgreSQL, to actually use Chamilo
* with another database (this is not ready yet because a lot of code still
* uses the MySQL database functions extensively).
* This is the main database library for Chamilo.
* Include/require it in your code to use its functionality.
* Because this library contains all the basic database calls, it could be
* replaced by another library for say, PostgreSQL, to actually use Chamilo
* with another database (this is not ready yet because a lot of code still
* uses the MySQL database functions extensively).
*
* @package chamilo.library
* @todo the table constants have all to start with TABLE_
* This is because of the analogy with the tool constants TOOL_
* If trying to replicate the database layer, don't forget to look for "sql"
* named functions in main_api.lib.php
*
* @package chamilo.library
*/
/**
* Code
* Constants definition
*/
/* CONSTANTS */
require_once 'database.constants.inc.php';
/* DATABASE CLASS
The class and its methods
*/
/**
* Database class definition
* @package chamilo.database
*/
class Database {
/*
@ -106,7 +105,7 @@ class Database {
* Returns the database prefix.
* All created COURSE databases are prefixed with this string.
*
* TIP: This can be convenient e.g. if you have multiple system installations
* TIP: This can be convenient if you have multiple system installations
* on the same physical server.
*/
public static function get_database_name_prefix() {
@ -143,22 +142,24 @@ class Database {
/**
* A more generic method than the other get_main_xxx_table methods,
* This one returns the correct complete name of any table of the main database of which you pass
* the short name as a parameter.
* This one returns the correct complete name of any table of the main
* database of which you pass the short name as a parameter.
* Please, define table names as constants in this library and use them
* instead of directly using magic words in your tool code.
*
* @param string $short_table_name, the name of the table
*/
public static function get_main_table($short_table_name) {
return self::format_table_name(self::get_main_database(), $short_table_name);
return self::format_table_name(
self::get_main_database(),
$short_table_name);
}
/**
* A more generic method than the older get_course_xxx_table methods,
* This one can return the correct complete name of any course table of which you pass
* the short name as a parameter.
* This one can return the correct complete name of any course table of
* which you pass the short name as a parameter.
* Please, define table names as constants in this library and use them
* instead of directly using magic words in your tool code.
*
@ -166,9 +167,8 @@ class Database {
* @param string $database_name, optional, name of the course database
* - if you don't specify this, you work on the current course.
*/
//public static function get_course_table($short_table_name, $database_name = '') {
//forces fatal errors so we can debug more easily
public static function get_course_table($short_table_name, $extra = null) {
//forces fatal errors so we can debug more easily
if (!empty($extra)) {
var_dump($extra);
//@todo remove this
@ -184,7 +184,8 @@ class Database {
*
* @param string $course_code
* @param string $table the name of the table
* @todo this function should be deprecated use api_get_course_info() and then get_course_table()
* @todo this function should be deprecated use api_get_course_info()
* and then get_course_table()
*/
public static function get_course_table_from_code($course_code, $table) {
$course_table = self::get_main_table(TABLE_MAIN_COURSE);
@ -201,8 +202,8 @@ class Database {
}
/**
* This generic method returns the correct and complete name of any statistic table
* of which you pass the short name as a parameter.
* This generic method returns the correct and complete name of any
* statistic table of which you pass the short name as a parameter.
* Please, define table names as constants in this library and use them
* instead of directly using magic words in your tool code.
*
@ -257,7 +258,7 @@ class Database {
/**
* Returns an array with all database fields for the specified course.
*
* @param the real (system) code of the course (ID from inside the main course table)
* @param string The real (system) course code (main course table ID)
* @todo shouldn't this be in the course.lib.php script?
*/
public static function get_course_info($course_code) {
@ -269,13 +270,14 @@ class Database {
}
/**
* @param $user_id (integer): the id of the user
* @return $user_info (array): user_id, lastname, firstname, username, email, ...
* @author Patrick Cool <patrick.cool@UGent.be>, expanded to get info for any user
* @author Roan Embrechts, first version + converted to Database API
* @version 30 September 2004
* @desc find all the information about a specified user. Without parameter this is the current user.
* @todo shouldn't this be in the user.lib.php script?
* Gets user details from the "user" table
* @param $user_id (integer): the id of the user
* @return $user_info (array): user_id, lname, fname, username, email, ...
* @author Patrick Cool <patrick.cool@UGent.be>, expanded to get info for any user
* @author Roan Embrechts, first version + converted to Database API
* @version 30 September 2004
* @desc find all the information about a specified user. Without parameter this is the current user.
* @todo shouldn't this be in the user.lib.php script?
*/
public static function get_user_info_from_id($user_id = '') {
if (empty($user_id)) {
@ -309,8 +311,10 @@ class Database {
* @author Roan Embrechts
*
* @todo What's the use of this method. I think this is better removed.
* There should be consistency in the variable names and the use throughout the scripts
* for the database name we should consistently use or db_name or database (db_name probably being the better one)
* There should be consistency in the variable names and the
* use throughout the scripts
* for the database name we should consistently use or db_name
* or database (db_name probably being the better one)
*/
public static function generate_abstract_course_field_names($result_array) {
$visual_code = isset($result_array['visual_code']) ? $result_array['visual_code'] : null;
@ -441,18 +445,19 @@ class Database {
}
/**
* Returns the error number from the last operation done on the database server.
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
* @return int Returns the error number from the last database (operation, or 0 (zero) if no error occurred.
* Returns error number from the last operation done on the database server.
* @param resource $connection (optional) The database server connection,
* for detailed description see the method query().
* @return int Returns the error number from the last database (operation, or 0 (zero) if no error occurred.
*/
public static function errno($connection = null) {
return self::use_default_connection($connection) ? mysql_errno() : mysql_errno($connection);
}
/**
* Returns the error text from the last operation done on the database server.
* Returns error text from the last operation done on the database server.
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
* @return string Returns the error text from the last database operation, or '' (empty string) if no error occurred.
* @return string Returns the error text from the last database operation, or '' (empty string) if no error occurred.
*/
public static function error($connection = null) {
return self::use_default_connection($connection) ? mysql_error() : mysql_error($connection);

@ -1104,7 +1104,7 @@ class Display {
// Show all tool icons where there is something new.
$retvalue = '&nbsp;';
while (list($key, $notification) = each($notifications)) {
$lastDate = date('d/m/Y H:i', convert_mysql_date($notification['lastedit_date']));
$lastDate = date('d/m/Y H:i', convert_sql_date($notification['lastedit_date']));
$type = $notification['lastedit_type'];
if (empty($my_course['id_session'])) {
$my_course['id_session'] = 0;
@ -1314,4 +1314,4 @@ class Display {
return $html;
}
} //end class Display
} //end class Display

@ -2640,14 +2640,14 @@ function api_not_allowed($print_headers = false) {
in the user course list */
/**
* Gets a UNIX timestamp from a MySQL datetime format string
* Gets a UNIX timestamp from a database (MySQL) datetime format string
* @param $last_post_datetime standard output date in a sql query
* @return unix timestamp
* @author Toon Van Hoecke <Toon.VanHoecke@UGent.be>
* @version October 2003
* @desc convert sql date to unix timestamp
*/
function convert_mysql_date($last_post_datetime) {
function convert_sql_date($last_post_datetime) {
list ($last_post_date, $last_post_time) = split(' ', $last_post_datetime);
list ($year, $month, $day) = explode('-', $last_post_date);
list ($hour, $min, $sec) = explode(':', $last_post_time);
@ -2655,7 +2655,7 @@ function convert_mysql_date($last_post_datetime) {
}
/**
* Gets a MySQL datetime format string from a UNIX timestamp
* Gets a database (MySQL) datetime format string from a UNIX timestamp
* @param int UNIX timestamp, as generated by the time() function. Will be generated if parameter not provided
* @return string MySQL datetime format, like '2009-01-30 12:23:34'
*/
@ -5673,4 +5673,4 @@ function api_grading_model_functions($grading_model, $action = 'to_array') {
}
}
return $return;
}
}

@ -2889,7 +2889,7 @@ class UserManager {
while ($user = Database::fetch_row($res)) {
if ($user[7] == 1 && $user[9] != '0000-00-00 00:00:00') {
// check expiration date
$expiration_time = convert_mysql_date($user[9]);
$expiration_time = convert_sql_date($user[9]);
// if expiration date is passed, store a special value for active field
if ($expiration_time < $t) {
$user[7] = '-1';

@ -2414,8 +2414,8 @@ class learnpathItem {
$res = Database::query($sql);
$row_dates = Database::fetch_array($res);
$time_start_date = convert_mysql_date($row_dates['start_date']);
$time_exe_date = convert_mysql_date($row_dates['exe_date']);
$time_start_date = convert_sql_date($row_dates['start_date']);
$time_exe_date = convert_sql_date($row_dates['exe_date']);
$mytime = ((int)$time_exe_date-(int)$time_start_date);
$total_time =" total_time = ".$mytime.", ";
}

Loading…
Cancel
Save