From 00e4940863d46bad53555bc8ee097ce806f89a62 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Thu, 18 May 2017 08:56:21 +0200 Subject: [PATCH] Minor - format code. --- index.php | 16 +++-- main/inc/lib/course.lib.php | 68 ++++++++++-------- main/inc/lib/display.lib.php | 134 ++++++++++++----------------------- 3 files changed, 93 insertions(+), 125 deletions(-) diff --git a/index.php b/index.php index 967e0d16f3..edfefd8203 100755 --- a/index.php +++ b/index.php @@ -38,7 +38,10 @@ if (!empty($_GET['logout'])) { /** * Registers in the track_e_default table (view in important activities in admin * interface) a possible attempted break in, sending auth data through get. - * @todo This piece of code should probably move to local.inc.php where the actual login / logout procedure is handled. The real use of this code block should be seriously considered as well. This form should just use a security token and get done with it. + * @todo This piece of code should probably move to local.inc.php where the + * actual login / logout procedure is handled. + * The real use of this code block should be seriously considered as well. + * This form should just use a security token and get done with it. */ if (isset($_GET['submitAuth']) && $_GET['submitAuth'] == 1) { $i = api_get_anonymous_id(); @@ -68,12 +71,13 @@ if (!api_get_user_id() && CustomPages::enabled()) { } /** - * @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled. - * @todo Check if this code is used. I think this code is never executed because after clicking the submit button - * the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending - * on api_get_setting('page_after_login'). + * @todo This piece of code should probably move to local.inc.php where the + * actual login procedure is handled. + * @todo Check if this code is used. I think this code is never executed because + * after clicking the submit button the code does the stuff + * in local.inc.php and then redirects to index.php or user_portal.php depending + * on api_get_setting('page_after_login'). */ - if (!empty($_POST['submitAuth'])) { // The user has been already authenticated, we are now to find the last login of the user. if (isset($_user['user_id'])) { diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 3296e50391..6ece15eb2c 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -4868,8 +4868,8 @@ class CourseManager } - if ($access_link && in_array('enter', - $access_link) || $course_info['visibility'] == COURSE_VISIBILITY_OPEN_WORLD + if ($access_link && in_array('enter',$access_link) || + $course_info['visibility'] == COURSE_VISIBILITY_OPEN_WORLD ) { $my_course['go_to_course_button'] = Display::url( get_lang('GoToCourse').' '. @@ -4918,21 +4918,16 @@ class CourseManager //Description $my_course['description_button'] = ''; - /* if ($course_info['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || in_array($course_info['real_id'], - $my_course_code_list) - ) { */ - $my_course['description_button'] = Display::url( - Display::returnFontAwesomeIcon('info-circle'), - api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=show_course_information&code='.$course_info['code'], - [ - 'class' => 'btn btn-default btn-sm ajax', - 'data-title' => get_lang('Description'), - 'title' => get_lang('Description'), - 'aria-label' => get_lang('Description') - ] - ); - //} - /* get_lang('Description') */ + $my_course['description_button'] = Display::url( + Display::returnFontAwesomeIcon('info-circle'), + api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=show_course_information&code='.$course_info['code'], + [ + 'class' => 'btn btn-default btn-sm ajax', + 'data-title' => get_lang('Description'), + 'title' => get_lang('Description'), + 'aria-label' => get_lang('Description') + ] + ); $my_course['teachers'] = self::getTeachersFromCourse($course_info['real_id'], true); $point_info = self::get_course_ranking($course_info['real_id'], 0); @@ -5085,7 +5080,8 @@ class CourseManager $visibilityCondition = self::getCourseVisibilitySQLCondition('c', true); if (!empty($accessUrlId) && $accessUrlId == intval($accessUrlId)) { - $sql = "SELECT count(c.id) FROM $tableCourse c, $tableCourseRelAccessUrl u + $sql = "SELECT count(c.id) + FROM $tableCourse c, $tableCourseRelAccessUrl u WHERE c.id = u.c_id AND u.access_url_id = $accessUrlId AND @@ -5163,8 +5159,11 @@ class CourseManager $options[] = 'enter'; } - if ($course['visibility'] != COURSE_VISIBILITY_HIDDEN && empty($course['registration_code']) && $course['unsubscribe'] == UNSUBSCRIBE_ALLOWED && api_user_is_login($uid) && (in_array($course['real_id'], - $user_courses)) + if ($course['visibility'] != COURSE_VISIBILITY_HIDDEN && + empty($course['registration_code']) && + $course['unsubscribe'] == UNSUBSCRIBE_ALLOWED && + api_user_is_login($uid) && + in_array($course['real_id'], $user_courses) ) { $options[] = 'unsubscribe'; } @@ -5416,7 +5415,12 @@ class CourseManager // Create Database::insert( $courseSettingTable, - ['title' => $variable, 'value' => $value, 'c_id' => $courseId, 'variable' => $variable] + [ + 'title' => $variable, + 'value' => $value, + 'c_id' => $courseId, + 'variable' => $variable, + ] ); } return true; @@ -5444,9 +5448,10 @@ class CourseManager * Get information from the track_e_course_access table * @param int $sessionId * @param int $userId + * @param int $limit * @return array */ - public static function getCourseAccessPerSessionAndUser($sessionId, $userId, $limit = null) + public static function getCourseAccessPerSessionAndUser($sessionId, $userId, $limit = 0) { $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); @@ -5882,13 +5887,15 @@ class CourseManager " WHERE access_start_date = '$startDate' AND access_end_date = '$endDate')" : null; $visibility = ($includeClosed ? '' : 'visibility NOT IN (0, 4) AND '); - $query = "SELECT id, code, title - FROM " . Database::get_main_table(TABLE_MAIN_COURSE)." + $sql = "SELECT id, code, title + FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." WHERE $visibility code NOT IN ( - SELECT DISTINCT course_code FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE).$dateConditional.") + SELECT DISTINCT course_code + FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE).$dateConditional." + ) ORDER BY id"; - $result = Database::query($query); + $result = Database::query($sql); $courses = array(); while ($row = Database::fetch_array($result)) { $courses[] = $row; @@ -5940,7 +5947,6 @@ class CourseManager } $result = Database::query($sql); - while ($row = Database::fetch_assoc($result)) { $coursesList[] = $row; } @@ -6246,8 +6252,11 @@ class CourseManager * @param string $tableUserFieldValues The user extra field value table name * @return int The number of users with this extra field with a specific value */ - public static function getCountRegisteredUsersWithCourseExtraField($name, $tableExtraFields = '', $tableUserFieldValues = '') - { + public static function getCountRegisteredUsersWithCourseExtraField( + $name, + $tableExtraFields = '', + $tableUserFieldValues = '' + ) { if (empty($tableExtraFields)) { $tableExtraFields = Database::get_main_table(TABLE_EXTRA_FIELD); } @@ -6256,7 +6265,6 @@ class CourseManager } $registered_users_with_extra_field = 0; - if (!empty($name) && $name != '-') { $extraFieldType = EntityExtraField::COURSE_FIELD_TYPE; $name = Database::escape_string($name); diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 3b8cc784a8..3d55a241a9 100755 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -183,12 +183,12 @@ class Display /** * Displays a table * @param array $header Titles for the table header - * each item in this array can contain 3 values - * - 1st element: the column title - * - 2nd element: true or false (column sortable?) - * - 3th element: additional attributes for - * th-tag (eg for column-width) - * - 4the element: additional attributes for the td-tags + * each item in this array can contain 3 values + * - 1st element: the column title + * - 2nd element: true or false (column sortable?) + * - 3th element: additional attributes for + * th-tag (eg for column-width) + * - 4the element: additional attributes for the td-tags * @param array $content 2D-array with the tables content * @param array $sorting_options Keys are: * 'column' = The column to use as sort-key @@ -278,11 +278,11 @@ class Display * @param array header content * @param array array with the information to show * @param array $paging_options Keys are: - * 'per_page_default' = items per page when switching from - * full- list to per-page-view - * 'per_page' = number of items to show per page - * 'page_nr' = The page to display - * 'hide_navigation' = true to hide the navigation + * 'per_page_default' = items per page when switching from + * full- list to per-page-view + * 'per_page' = number of items to show per page + * 'page_nr' = The page to display + * 'hide_navigation' = true to hide the navigation * @param array $query_vars Additional variables to add in the query-string * @param array $form actions Additional variables to add in the query-string * @param mixed An array with bool values to know which columns show. @@ -319,11 +319,11 @@ class Display * @param array header content * @param array array with the information to show * @param array $paging_options Keys are: - * 'per_page_default' = items per page when switching from - * full- list to per-page-view - * 'per_page' = number of items to show per page - * 'page_nr' = The page to display - * 'hide_navigation' = true to hide the navigation + * 'per_page_default' = items per page when switching from + * full- list to per-page-view + * 'per_page' = number of items to show per page + * 'page_nr' = The page to display + * 'hide_navigation' = true to hide the navigation * @param array $query_vars Additional variables to add in the query-string * @param array $form actions Additional variables to add in the query-string * @param mixed An array with bool values to know which columns show. i.e: @@ -443,7 +443,7 @@ class Display */ public static function display_normal_message($message, $filter = true, $returnValue = false) { - $message = self::return_message($message, 'normal', $filter); + $message = self::return_message($message, 'normal', $filter); if ($returnValue) { return $message; } else { @@ -527,7 +527,7 @@ class Display } if ($filter) { - $message = api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : api_get_system_encoding()); + $message = api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : api_get_system_encoding()); } $class = ''; @@ -940,7 +940,7 @@ class Display if (!empty($name)) { $attributes['name'] = $name; } - return self::tag('button', $value, $attributes); + return self::tag('button', $value, $attributes); } /** @@ -1273,9 +1273,7 @@ class Display // Creating the jqgrid element. $json .= '$("#'.$div_id.'").jqGrid({'; //$json .= $beforeSelectRow; - $json .= $json_encode; - $json .= '});'; // Grouping headers option @@ -1575,50 +1573,8 @@ class Display } $active = true; } else { - /*$start = $stop = false; - $start_buffer = $stop_buffer = ''; - if ($session_info['access_start_date'] === '0000-00-00 00:00:00' || empty($session_info['access_start_date'])) { - $session_info['access_start_date'] = ''; - } else { - $start = true; - $start_buffer = $session_info['access_start_date']; - $session_info['access_start_date'] = $session_info['access_start_date']; - } - if ($session_info['access_end_date'] === '0000-00-00 00:00:00' || empty($session_info['access_end_date'])) { - $session_info['access_end_date'] = ''; - } else { - $stop = true; - $stop_buffer = $session_info['access_end_date']; - $session_info['access_end_date'] = $session_info['access_end_date']; - } - if ($start && $stop) { - $session['dates'] = sprintf( - get_lang('FromDateXToDateY'), - api_format_date($start_buffer), - api_format_date($stop_buffer) - ); - } else { - $start_buffer = $stop_buffer = null; - if (!empty($session_info['access_start_date'])) { - $start_buffer = sprintf( - get_lang('FromDateX'), - api_format_date(api_get_local_time($session_info['access_start_date'])) - ); - } - - if (!empty($session_info['access_end_date'])) { - $stop_buffer = sprintf( - get_lang('UntilDateX'), - api_format_date(api_get_local_time($session_info['access_end_date'])) - ); - }*/ - $dates = SessionManager::parseSessionDates($session_info, true); - - //$session['dates'] = $start_buffer . ' ' . $stop_buffer.'- julio '.$dates['access']; $session['dates'] = $dates['access']; - - if (api_get_setting('show_session_coach') === 'true') { $session['coach'] = api_get_person_name( $session_info['firstname'], @@ -1673,40 +1629,40 @@ class Display $point_info = [], $add_div_wrapper = true ) { - $number_of_users_who_voted = isset($point_info['users_who_voted']) ? $point_info['users_who_voted'] : null; - $percentage = isset($point_info['point_average']) ? $point_info['point_average'] : 0; + $number_of_users_who_voted = isset($point_info['users_who_voted']) ? $point_info['users_who_voted'] : null; + $percentage = isset($point_info['point_average']) ? $point_info['point_average'] : 0; - if (!empty($percentage)) { + if (!empty($percentage)) { $percentage = $percentage * 125 / 100; } - $accesses = isset($point_info['accesses']) ? $point_info['accesses'] : 0; - $star_label = sprintf(get_lang('XStarsOutOf5'), $point_info['point_average_star']); + $accesses = isset($point_info['accesses']) ? $point_info['accesses'] : 0; + $star_label = sprintf(get_lang('XStarsOutOf5'), $point_info['point_average_star']); $html = ''; +
  • +
  • 1
  • +
  • 2
  • +
  • 3
  • +
  • 4
  • +
  • 5
  • + '; - $labels = array(); + $labels = array(); - $labels[] = $number_of_users_who_voted == 1 ? $number_of_users_who_voted.' '.get_lang('Vote') : $number_of_users_who_voted.' '.get_lang('Votes'); - $labels[] = $accesses == 1 ? $accesses.' '.get_lang('Visit') : $accesses.' '.get_lang('Visits'); - $labels[] = $point_info['user_vote'] ? get_lang('YourVote').' ['.$point_info['user_vote'].']' : get_lang('YourVote').' [?] '; + $labels[] = $number_of_users_who_voted == 1 ? $number_of_users_who_voted.' '.get_lang('Vote') : $number_of_users_who_voted.' '.get_lang('Votes'); + $labels[] = $accesses == 1 ? $accesses.' '.get_lang('Visit') : $accesses.' '.get_lang('Visits'); + $labels[] = $point_info['user_vote'] ? get_lang('YourVote').' ['.$point_info['user_vote'].']' : get_lang('YourVote').' [?] '; - if (!$add_div_wrapper && api_is_anonymous()) { - $labels[] = self::tag('span', get_lang('LoginToVote'), array('class' => 'error')); - } + if (!$add_div_wrapper && api_is_anonymous()) { + $labels[] = self::tag('span', get_lang('LoginToVote'), array('class' => 'error')); + } $html .= self::div(implode(' | ', $labels), array('id' => 'vote_label_'.$id, 'class' => 'vote_label_info')); $html .= ' '.self::span(' ', array('id' => 'vote_label2_'.$id)); if ($add_div_wrapper) { - $html = self::div($html, array('id' => 'rating_wrapper_'.$id)); - } + $html = self::div($html, array('id' => 'rating_wrapper_'.$id)); + } return $html; } @@ -2124,6 +2080,7 @@ class Display return $html; } + /** * * @param int $itemId @@ -2149,7 +2106,7 @@ class Display $fixedValue = null, $linkAttributes = [] ) { - $defaultClass = "before"; + $defaultClass = 'before'; $class = $defaultClass; foreach ($conditions as $condition) { $array = isset($condition['items']) ? $condition['items'] : array(); @@ -2178,13 +2135,13 @@ class Display } } if ($isCurrent) { - $class = "before current"; + $class = 'before current'; } if ($isMedia && $isCurrent) { - $class = "before current"; + $class = 'before current'; } if (empty($link)) { - $link_to_show = "#"; + $link_to_show = '#'; } else { $link_to_show = $link.($nextValue + $localCounter); } @@ -2392,7 +2349,6 @@ class Display if (!$colsWidth) { $width = 12 / $col; - array_walk($content, function() use ($width, &$colsWidth) { $colsWidth[] = $width; });