Format code, remove unused function String2Boolean, add intval

pull/2487/head
jmontoyaa 9 years ago
parent 9b0ad452d2
commit 683301b581
  1. 34
      main/inc/lib/api.lib.php
  2. 19
      main/inc/lib/usermanager.lib.php
  3. 6
      tests/main/inc/lib/main_api.lib.test.php

@ -2635,7 +2635,7 @@ function api_is_coach($session_id = 0, $courseId = null, $check_student_view = t
if (!empty($session_id)) {
$sql = "SELECT DISTINCT id, name, access_start_date, access_end_date
FROM $session_table
WHERE session.id_coach = '".$userId."' AND id = '$session_id'
WHERE session.id_coach = $userId AND id = $session_id
ORDER BY access_start_date, access_end_date, name";
$result = Database::query($sql);
if (!empty($sessionIsCoach)) {
@ -3015,7 +3015,6 @@ function api_is_coach_of_course_in_session($sessionId)
return false;
}
/**
* Checks if a student can edit contents in a session depending
* on the session visibility
@ -3054,7 +3053,6 @@ function api_is_allowed_to_session_edit($tutor = false, $coach = false)
case SESSION_AVAILABLE: //5
return true;
}
}
}
}
@ -3348,7 +3346,7 @@ function api_not_allowed($print_headers = false, $message = null)
$msg .= "<div style='display:none;'>";
}
$msg .= '<div class="well">';
$msg .= $form->return_form();
$msg .= $form->returnForm();
$msg .='</div>';
if ($casEnabled) {
$msg .= "</div>";
@ -3936,6 +3934,7 @@ function api_get_item_property_id($course_code, $tool, $ref, $sessionId = 0)
// Definition of tables.
$tableItemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
$course_id = $course_info['real_id'];
$sessionId = (int) $sessionId;
$sessionCondition = " AND session_id = $sessionId ";
if (empty($sessionId)) {
$sessionCondition = " AND (session_id = 0 OR session_id IS NULL) ";
@ -4072,7 +4071,6 @@ function api_get_item_property_info($course_id, $tool, $ref, $session_id = 0, $g
* (in some cases, like the indexing language picker, it can alter the presentation)
* @return string
*/
function api_get_languages_combo($name = 'language')
{
$ret = '';
@ -4433,23 +4431,6 @@ function api_max_sort_value($user_course_category, $user_id)
return 0;
}
/**
* This function converts the string "true" or "false" to a boolean true or false.
* This function is in the first place written for the Chamilo Config Settings (also named AWACS)
* @param string "true" or "false"
* @return boolean true or false
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*/
function api_string_2_boolean($string) {
if ($string == 'true') {
return true;
}
if ($string == 'false') {
return false;
}
return false;
}
/**
* Determines the number of plugins installed for a given location
*/
@ -4895,9 +4876,9 @@ function parse_info_file($filename) {
* Gets Chamilo version from the configuration files
* @return string A string of type "1.8.4", or an empty string if the version could not be found
*/
function api_get_version() {
global $_configuration;
return (string)$_configuration['system_version'];
function api_get_version()
{
return (string) api_get_configuration_value('system_version');
}
/**
@ -8078,7 +8059,7 @@ function api_is_date_in_date_range($startDate, $endDate, $currentDate = null)
$endDate = strtotime(api_get_local_time($endDate));
$currentDate = strtotime(api_get_local_time($currentDate));
if (($currentDate >= $startDate) && ($currentDate <= $endDate)) {
if ($currentDate >= $startDate && $currentDate <= $endDate) {
return true;
}
@ -8175,4 +8156,3 @@ function api_remove_uploaded_file($type, $file)
unlink($path);
}
}

@ -2776,7 +2776,7 @@ class UserManager
// This query is horribly slow when more than a few thousand
// users and just a few sessions to which they are subscribed
$personal_course_list_sql = "SELECT DISTINCT
$sql = "SELECT DISTINCT
course.code code,
course.title i,
".(api_is_western_name_order() ? "CONCAT(user.firstname,' ',user.lastname)" : "CONCAT(user.lastname,' ',user.firstname)")." t,
@ -2800,8 +2800,7 @@ class UserManager
OR session.id_coach = $user_id
)
ORDER BY i";
$course_list_sql_result = Database::query($personal_course_list_sql);
$course_list_sql_result = Database::query($sql);
while ($result_row = Database::fetch_array($course_list_sql_result, 'ASSOC')) {
$result_row['course_info'] = api_get_course_info($result_row['code']);
$key = $result_row['session_id'].' - '.$result_row['code'];
@ -2819,7 +2818,7 @@ class UserManager
/* This query is very similar to the above query,
but it will check the session_rel_course_user table if there are courses registered to our user or not */
$personal_course_list_sql = "SELECT DISTINCT
$sql = "SELECT DISTINCT
course.code code,
course.title i, CONCAT(user.lastname,' ',user.firstname) t,
email,
@ -2840,8 +2839,7 @@ class UserManager
WHERE session_course_user.user_id = $user_id
ORDER BY i";
$course_list_sql_result = Database::query($personal_course_list_sql);
$course_list_sql_result = Database::query($sql);
while ($result_row = Database::fetch_array($course_list_sql_result, 'ASSOC')) {
$result_row['course_info'] = api_get_course_info($result_row['code']);
$key = $result_row['session_id'].' - '.$result_row['code'];
@ -3036,15 +3034,18 @@ class UserManager
$return = "<h4>$course</h4>";
$return .= '<ul class="thumbnails">';
}
$extensionList = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'tif'];
foreach ($file_list as $file) {
if ($resourcetype == "all") {
$return .= '<li><a href="'.$web_path.urlencode($file).'" target="_blank">'.htmlentities($file).'</a></li>';
} elseif ($resourcetype == "images") {
//get extension
$ext = explode('.', $file);
if ($ext[1] == 'jpg' || $ext[1] == 'jpeg' || $ext[1] == 'png' || $ext[1] == 'gif' || $ext[1] == 'bmp' || $ext[1] == 'tif') {
$return .= '<li class="span2"><a class="thumbnail" href="'.$web_path.urlencode($file).'" target="_blank">
<img src="'.$web_path.urlencode($file).'" ></a>
if (isset($ext[1]) && in_array($ext[1], $extensionList)) {
$return .= '<li class="span2">
<a class="thumbnail" href="'.$web_path.urlencode($file).'" target="_blank">
<img src="'.$web_path.urlencode($file).'" >
</a>
</li>';
}
}

@ -454,12 +454,6 @@ class TestMainApi extends UnitTestCase {
//var_dump($res);
}
function testString2Boolean(){
global $string;
$res=api_string_2_boolean($string);
$this->assertFalse($res);
}
function testApiNumberOfPlugins(){
global $_plugins;
$location=2;

Loading…
Cancel
Save