From 55ce4a434d75996f17c7a23b8aacb401e04b121a Mon Sep 17 00:00:00 2001 From: Julio Date: Fri, 13 May 2016 15:01:03 +0200 Subject: [PATCH] Remove unused code, format code, --- main/admin/resource_sequence.php | 3 +- main/blog/blog.php | 5 +- main/course_description/add.php | 5 +- main/forum/forumfunction.inc.php | 118 +------------- main/inc/lib/api.lib.php | 70 +-------- main/inc/lib/internationalization.lib.php | 16 +- main/link/link.php | 8 +- main/messages/new_message.php | 31 ++-- main/mySpace/myStudents.php | 29 +--- main/newscorm/learnpath.class.php | 13 +- main/webservices/cm_webservice.php | 163 +++++++++++--------- tests/main/forum/forumfunction.inc.test.php | 37 +---- 12 files changed, 124 insertions(+), 374 deletions(-) diff --git a/main/admin/resource_sequence.php b/main/admin/resource_sequence.php index 4b2fc183fd..e2df41b296 100644 --- a/main/admin/resource_sequence.php +++ b/main/admin/resource_sequence.php @@ -22,7 +22,7 @@ if (!empty($sessionListFromDatabase)) { } } -$formSequence = new FormValidator('sequence_form', 'post', api_get_self(),null,null,'inline'); +$formSequence = new FormValidator('sequence_form', 'post', api_get_self(), null, null, 'inline'); $formSequence->addText('name', get_lang('Sequence'), true, ['cols-size' => [3, 8, 1]]); $formSequence->addButtonCreate(get_lang('AddSequence'), 'submit_sequence', false, ['cols-size' => [3, 8, 1]]); @@ -78,7 +78,6 @@ $formSave = new FormValidator(''); $formSave->addHidden('sequence_type', 'session'); $formSave->addButton('save_resource', get_lang('SaveSettings'), 'floppy-o', 'success', null, null, ['cols-size' => [1, 10, 1]]); - $tpl->assign('create_sequence', $formSequence->returnForm()); $tpl->assign('select_sequence', $selectSequence->returnForm()); $tpl->assign('configure_sequence', $form->returnForm()); diff --git a/main/blog/blog.php b/main/blog/blog.php index 03cedec645..8b3d0a254b 100755 --- a/main/blog/blog.php +++ b/main/blog/blog.php @@ -13,8 +13,8 @@ if (empty($blog_id)) { api_not_allowed(true); } -$this_section = SECTION_COURSES; -$current_course_tool = TOOL_BLOGS; +$this_section = SECTION_COURSES; +$current_course_tool = TOOL_BLOGS; /* ACCESS RIGHTS */ // notice for unauthorized people. @@ -72,7 +72,6 @@ if (!empty($_POST['new_comment_submit'])) { } if (!empty($_POST['new_task_submit'])) { - Blog:: create_task( $blog_id, $safe_task_name, diff --git a/main/course_description/add.php b/main/course_description/add.php index eeecb0004b..e8882410d9 100755 --- a/main/course_description/add.php +++ b/main/course_description/add.php @@ -54,10 +54,9 @@ $form = new FormValidator( 'POST', 'index.php?action=add&'.api_get_cidreq() ); -$form->addElement('header', '', $header); +$form->addElement('header', $header); $form->addElement('hidden', 'description_type', $description_type); -$form->addElement('hidden', 'sec_token', $token); -$form->addText('title', get_lang('Title'), true, array('size'=>'width: 350px;')); +$form->addText('title', get_lang('Title'), true); $form->applyFilter('title', 'html_filter'); $form->addHtmlEditor( 'contentDescription', diff --git a/main/forum/forumfunction.inc.php b/main/forum/forumfunction.inc.php index ce6e86ad10..5d74e62799 100755 --- a/main/forum/forumfunction.inc.php +++ b/main/forum/forumfunction.inc.php @@ -3849,95 +3849,6 @@ function get_whats_new() } } -/** - * With this function we find the number of posts and topics in a given forum. - * - * @todo consider to call this function only once and let it return an array where the key is the forum id and the value is an array with number_of_topics and number of post - * as key of this array and the value as a value. This could reduce the number of queries needed (especially when there are more forums) - * @todo consider merging both in one query. - * - * @author Patrick Cool , Ghent University - * @version february 2006, dokeos 1.8 - * - * @deprecated the counting mechanism is now inside the function get_forums - */ -function get_post_topics_of_forum($forum_id) -{ - $table_posts = Database :: get_course_table(TABLE_FORUM_POST); - $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); - $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); - - $course_id = api_get_course_int_id(); - - if (api_is_allowed_to_edit(null, true)) { - $sql = "SELECT count(*) as number_of_posts - FROM $table_posts posts, $table_threads threads, $table_item_property item_property - WHERE - posts.c_id = $course_id AND - item_property.c_id = $course_id AND - posts.forum_id='".Database::escape_string($forum_id)."' - AND posts.thread_id=threads.thread_id - AND item_property.ref=threads.thread_id - AND item_property.visibility<>2 - AND item_property.tool='".TOOL_FORUM_THREAD."' - "; - } else { - $sql = "SELECT count(*) as number_of_posts - FROM $table_posts posts, $table_threads threads, $table_item_property item_property - WHERE - posts.c_id = $course_id AND - item_property.c_id = $course_id AND - posts.forum_id='".Database::escape_string($forum_id)."' - AND posts.thread_id=threads.thread_id - AND item_property.ref=threads.thread_id - AND item_property.visibility=1 - AND posts.visible=1 - AND item_property.tool='".TOOL_FORUM_THREAD."' - "; - } - $result = Database::query($sql); - $row = Database::fetch_array($result); - $number_of_posts = $row['number_of_posts']; - - // We could loop through the result array and count the number of different group_ids, but I have chosen to use a second sql statement. - if (api_is_allowed_to_edit(null, true)) { - $sql = "SELECT count(*) as number_of_topics - FROM $table_threads threads, $table_item_property item_property - WHERE - threads.c_id = $course_id AND - item_property.c_id = $course_id AND - threads.forum_id='".Database::escape_string($forum_id)."' - AND item_property.ref=threads.thread_id - AND item_property.visibility<>2 - AND item_property.tool='".TOOL_FORUM_THREAD."' - "; - } else { - $sql = "SELECT count(*) as number_of_topics - FROM $table_threads threads, $table_item_property item_property - WHERE - threads.c_id = $course_id AND - item_property.c_id = $course_id AND - threads.forum_id='".Database::escape_string($forum_id)."' - AND item_property.ref=threads.thread_id - AND item_property.visibility=1 - AND item_property.tool='".TOOL_FORUM_THREAD."' - "; - } - $result = Database::query($sql); - $row = Database::fetch_array($result); - $number_of_topics = $row['number_of_topics']; - if ($number_of_topics == '') { - $number_of_topics = 0; // Due to the nature of the group by this can result in an empty string. - } - - $return = array( - 'number_of_topics' => $number_of_topics, - 'number_of_posts' => $number_of_posts, - ); - - return $return; -} - /** * This function approves a post = change * @@ -5662,34 +5573,6 @@ function editAttachedFile($array, $id, $courseId = null) { return 0; } -/** - * Return a form to upload asynchronously attachments to forum post. - * @param int $forumId Forum ID from where the post are - * @param int $threadId Thread ID where forum post are - * @param int $postId Post ID to identify Post - * @deprecated this function seems to never been used - * @return string The Forum Attachment Ajax Form - * - */ -function getAttachmentAjaxForm($forumId, $threadId, $postId) -{ - $forumId = intval($forumId); - $postId = intval($postId); - $threadId = !empty($threadId) ? intval($threadId) : isset($_REQUEST['thread']) ? intval($_REQUEST['thread']) : ''; - if ($forumId === 0) { - // Forum Id must be defined - - return ''; - } - - $url = api_get_path(WEB_AJAX_PATH).'forum.ajax.php?'.api_get_cidreq().'&forum=' . $forumId . '&thread=' . $threadId . '&postId=' . $postId . '&a=upload_file'; - - $multipleForm = new FormValidator('post'); - $multipleForm->addMultipleUpload($url); - - return $multipleForm->returnForm(); -} - /** * Return a table where the attachments will be set * @param int $postId Forum Post ID @@ -5715,6 +5598,7 @@ function getAttachmentsAjaxTable($postId = null) } } } + // Get data to fill into attachment files table if (!empty($_SESSION['forum']['upload_file'][$courseId]) && is_array($_SESSION['forum']['upload_file'][$courseId]) diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index ec61c74cc5..7bd9946156 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -34,8 +34,7 @@ define('ANONYMOUS', 6); /** global status of a user: low security, necessary for inserting data from * the teacher through HTMLPurifier */ define('COURSEMANAGERLOWSECURITY', 10); - -//Soft user status +// Soft user status define('PLATFORM_ADMIN', 11); define('SESSION_COURSE_COACH', 12); define('SESSION_GENERAL_COACH', 13); @@ -273,7 +272,6 @@ define('REPEATED_SLASHES_PURIFIER', '/\/{2,}/'); // $path = p define('VALID_WEB_PATH', '/https?:\/\/[^\/]*(\/.*)?/i'); // $is_valid_path = preg_match(VALID_WEB_PATH, $path); define('VALID_WEB_SERVER_BASE', '/https?:\/\/[^\/]*/i'); // $new_path = preg_replace(VALID_WEB_SERVER_BASE, $new_base, $path); - // Constants for api_get_path() and api_get_path_type(), etc. - registered path types. // basic (leaf elements) define('REL_CODE_PATH', 'REL_CODE_PATH'); @@ -970,25 +968,13 @@ function api_valid_url($url, $absolute = false) { /** * Checks whether a given string looks roughly like an email address. - * Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator. - * Conforms approximately to RFC2822 - * @link http://www.hexillion.com/samples/#Regex Original pattern found here - * This function is an adaptation from the method PHPMailer::ValidateAddress(), PHPMailer module. - * @link http://phpmailer.worxware.com + * * @param string $address The e-mail address to be checked. * @return mixed Returns the e-mail if it is valid, FALSE otherwise. */ function api_valid_email($address) { return filter_var($address, FILTER_VALIDATE_EMAIL); - /* - // disable for now because the results are incoherent - YW 20110926 - - if (function_exists('filter_var')) { // Introduced in PHP 5.2. - return filter_var($address, FILTER_VALIDATE_EMAIL); - } else { - return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address) ? $address : false; - }*/ } @@ -1070,7 +1056,7 @@ function api_protect_course_script($print_headers = false, $allow_session_admins } } - //Check session visibility + // Check session visibility $session_id = api_get_session_id(); if (!empty($session_id)) { @@ -2310,56 +2296,6 @@ function api_get_session_condition( return $condition_session; } -/** - * This function returns information about coaches from a course in session - * @param int optional, session id - * @param int $courseId - * @return array array containing user_id, lastname, firstname, username - * @deprecated use CourseManager::get_coaches_from_course - */ -function api_get_coachs_from_course($session_id = 0, $courseId = '') -{ - if (!empty($session_id)) { - $session_id = intval($session_id); - } else { - $session_id = api_get_session_id(); - } - - if (!empty($courseId)) { - $courseId = intval($courseId); - } else { - $courseId = api_get_course_int_id(); - } - - $tbl_user = Database:: get_main_table(TABLE_MAIN_USER); - $tbl_session_course_user = Database:: get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - $coaches = array(); - - $sql = "SELECT - u.user_id, - u.lastname, - u.firstname, - u.username - FROM $tbl_user u, $tbl_session_course_user scu - WHERE - u.user_id = scu.user_id AND - scu.session_id = '$session_id' AND - scu.c_id = '$courseId' AND - scu.status = 2"; - $rs = Database::query($sql); - - if (Database::num_rows($rs) > 0) { - while ($row = Database::fetch_array($rs)) { - $coaches[] = $row; - } - - return $coaches; - } else { - - return false; - } -} - /** * Returns the value of a setting from the web-adjustable admin config settings. * diff --git a/main/inc/lib/internationalization.lib.php b/main/inc/lib/internationalization.lib.php index 0c304e0593..e8ff1f4759 100755 --- a/main/inc/lib/internationalization.lib.php +++ b/main/inc/lib/internationalization.lib.php @@ -57,15 +57,7 @@ define('PERSON_NAME_EMAIL_ADDRESS', PERSON_NAME_WESTERN_ORDER); // For backward compatibility this format has been set to Eastern order. define('PERSON_NAME_DATA_EXPORT', PERSON_NAME_EASTERN_ORDER); -// The following constants are used for tuning language detection functionality. -// We reduce the text for language detection to the given number of characters -// for increasing speed and to decrease memory consumption. -define('LANGUAGE_DETECT_MAX_LENGTH', 2000); -// Maximum allowed difference in so called delta-points for aborting certain language detection. -// The value 80000 is good enough for speed and detection accuracy. -// If you set the value of $max_delta too low, no language will be recognized. -// $max_delta = 400 * 350 = 140000 is the best detection with lowest speed. -define('LANGUAGE_DETECT_MAX_DELTA', 140000); + /** * Returns a translated (localized) string, called by its identificator. @@ -275,7 +267,8 @@ function api_get_language_isocode($language = null, $default_code = 'en') function api_get_platform_isocodes() { $iso_code = array(); - $sql = "SELECT isocode FROM ".Database::get_main_table(TABLE_MAIN_LANGUAGE)." ORDER BY isocode "; + $sql = "SELECT isocode FROM ".Database::get_main_table(TABLE_MAIN_LANGUAGE)." + ORDER BY isocode "; $sql_result = Database::query($sql); if (Database::num_rows($sql_result)) { while ($row = Database::fetch_array($sql_result)) {; @@ -976,9 +969,6 @@ function api_htmlentities($string, $quote_style = ENT_COMPAT, $encoding = 'UTF-8 } return mb_convert_encoding($string, 'HTML-ENTITIES', 'UTF-8'); -/* - return html_entity_decode($string, $quote_style, $encoding); - return mb_convert_encoding($string, 'HTML-ENTITIES', 'UTF-8');*/ } /** diff --git a/main/link/link.php b/main/link/link.php index add39b6932..bea138bd3a 100755 --- a/main/link/link.php +++ b/main/link/link.php @@ -16,17 +16,15 @@ * @author Patrick Cool * @author René Haentjens, added CSV file import (October 2004) * @package chamilo.link - */ -// Including libraries require_once '../inc/global.inc.php'; $current_course_tool = TOOL_LINK; $this_section = SECTION_COURSES; -api_protect_course_script(); +api_protect_course_script(true); -$htmlHeadXtra[] = ''; +'; // @todo change the $_REQUEST into $_POST or $_GET // @todo remove this code diff --git a/main/messages/new_message.php b/main/messages/new_message.php index d2fb084b1f..256989c1cd 100755 --- a/main/messages/new_message.php +++ b/main/messages/new_message.php @@ -25,7 +25,7 @@ $nameTools = api_xml_http_response_encode(get_lang('Messages')); /* Constants and variables */ $htmlHeadXtra[]=' -'; $nameTools = get_lang('ComposeMessage'); -/* FUNCTIONS */ /** * Shows the compose area + a list of users to select from. @@ -184,18 +177,20 @@ function manage_form($default, $select_from_user_list = null, $sent_to = null) } if (empty($group_id)) { - - $form->addElement('label', '', '
-
- - - - -
-
' + $form->addElement( + 'label', + '', + '
+
+ + + + +
+
' ); - $form->addElement('label', '', ''.get_lang('AddOneMoreFile').' ('.sprintf(get_lang('MaximunFileSizeX'),format_file_size(api_get_setting('message_max_upload_filesize'))).')'); + $form->addLabel('', ''.get_lang('AddOneMoreFile').' ('.sprintf(get_lang('MaximunFileSizeX'),format_file_size(api_get_setting('message_max_upload_filesize'))).')'); } $form->addButtonSend(get_lang('SendMessage'), 'compose'); diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php index d4aa888e32..08cb157867 100755 --- a/main/mySpace/myStudents.php +++ b/main/mySpace/myStudents.php @@ -435,29 +435,12 @@ if (!empty($student_id)) { $coachs_name = ''; $session_name = ''; - //$nb_login = Tracking :: count_login_per_student($user_info['user_id'], $courseInfo['real_id']); - //get coach and session_name if there is one and if session_mode is activated - /*if ($sessionId > 0) { - $session_info = api_get_session_info($sessionId); - $session_coach_id = $session_info['session_admin_id']; - $course_coachs = api_get_coachs_from_course($sessionId, $courseInfo['real_id']); - // $nb_login = ''; - if (!empty($course_coachs)) { - $info_tutor_name = array(); - foreach ($course_coachs as $course_coach) { - $info_tutor_name[] = api_get_person_name($course_coach['firstname'], $course_coach['lastname']); - } - $courseInfo['tutor_name'] = implode(",", $info_tutor_name); - } elseif ($session_coach_id != 0) { - $session_coach_id = intval($session_info['id_coach']); - $coach_info = api_get_user_info($session_coach_id); - $courseInfo['tutor_name'] = $coach_info['complete_name']; - } - $coachs_name = $courseInfo['tutor_name']; - $session_name = $session_info['name']; - } // end*/ - - $table_title = Display::return_icon('user.png', get_lang('User'), array(), ICON_SIZE_SMALL).$user_info['complete_name']; + $table_title = Display::return_icon( + 'user.png', + get_lang('User'), + array(), + ICON_SIZE_SMALL + ).$user_info['complete_name']; echo Display::page_subheader($table_title); diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 6a538610dc..e3d9718738 100755 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -1545,18 +1545,7 @@ class learnpath // TODO: Update the item object (can be ignored for now because refreshed). return true; } - - /** - * Escapes a string with the available database escape function - * @param string String to escape - * @return string String escaped - * @deprecated use Database::escape_string - */ - public function escape_string($string) - { - return Database::escape_string($string); - } - + /** * Static admin function exporting a learnpath into a zip file * @param string Export type (scorm, zip, cd) diff --git a/main/webservices/cm_webservice.php b/main/webservices/cm_webservice.php index 700c4c5190..e644b26e67 100755 --- a/main/webservices/cm_webservice.php +++ b/main/webservices/cm_webservice.php @@ -1,11 +1,14 @@ code = $code; $this->message = $message; } @@ -43,7 +47,8 @@ class WSCMError { * * @param WSErrorHandler Error handler */ - public static function setErrorHandler($handler) { + public static function setErrorHandler($handler) + { if($handler instanceof WSErrorHandler) { self::$_handler = $handler; } @@ -54,7 +59,8 @@ class WSCMError { * * @return WSErrorHandler Error handler */ - public static function getErrorHandler() { + public static function getErrorHandler() + { return self::$_handler; } @@ -63,7 +69,8 @@ class WSCMError { * * @return array Associative array with code and message */ - public function toArray() { + public function toArray() + { return array('code' => $this->code, 'message' => $this->message); } } @@ -71,7 +78,8 @@ class WSCMError { /** * Interface that must be implemented by any error handler */ -interface WSCMErrorHandler { +interface WSCMErrorHandler +{ /** * Handle method * @@ -83,7 +91,8 @@ interface WSCMErrorHandler { /** * Main class of the webservice. Webservice classes extend this class */ -class WSCM { +class WSCM +{ /** * Chamilo configuration * @@ -94,7 +103,8 @@ class WSCM { /** * Constructor */ - public function __construct() { + public function __construct() + { $this->_configuration = $GLOBALS['_configuration']; } @@ -104,7 +114,8 @@ class WSCM { * @param string Secret key * @return mixed WSError in case of failure, null in case of success */ - protected function verifyKey($secret_key) { + protected function verifyKey($secret_key) + { $ip = trim($_SERVER['REMOTE_ADDR']); // if we are behind a reverse proxy, assume it will send the // HTTP_X_FORWARDED_FOR header and use this IP instead @@ -121,73 +132,69 @@ class WSCM { } } - /** - * Verifies if the user is valid - * - * @param $username of the user in chamilo - * @param $pass of the same user (in MD5 of SHA) - * - * return "valid" if username e password are correct! Else, return a message error - */ + /** + * Verifies if the user is valid + * + * @param $username of the user in chamilo + * @param $pass of the same user (in MD5 of SHA) + * + * return "valid" if username e password are correct! Else, return a message error + */ - public function verifyUserPass($username, $pass) { - $login = $username; - $password = $pass; + public function verifyUserPass($username, $pass) + { + $login = $username; + $password = $pass; - //lookup the user in the main database - $user_table = Database::get_main_table(TABLE_MAIN_USER); - $sql = "SELECT user_id, username, password, auth_source, active, expiration_date - FROM $user_table - WHERE username = '".trim(addslashes($login))."'"; - $result = Database::query($sql); + //lookup the user in the main database + $user_table = Database::get_main_table(TABLE_MAIN_USER); + $sql = "SELECT user_id, username, password, auth_source, active, expiration_date + FROM $user_table + WHERE username = '".trim(addslashes($login))."'"; + $result = Database::query($sql); - if (Database::num_rows($result) > 0) { - $uData = Database::fetch_array($result); + if (Database::num_rows($result) > 0) { + $uData = Database::fetch_array($result); - if ($uData['auth_source'] == PLATFORM_AUTH_SOURCE) { - $password = trim(stripslashes($password)); - // Check the user's password - if ($password == $uData['password'] AND (trim($login) == $uData['username'])) { - // Check if the account is active (not locked) - if ($uData['active']=='1') { - // Check if the expiration date has not been reached - if ($uData['expiration_date']>date('Y-m-d H:i:s') OR $uData['expiration_date']=='0000-00-00 00:00:00') { - return "valid"; - } - else - return get_lang('AccountExpired'); - } - else - return get_lang('AccountInactive'); + if ($uData['auth_source'] == PLATFORM_AUTH_SOURCE) { + $password = trim(stripslashes($password)); + // Check the user's password + if ($password == $uData['password'] AND (trim($login) == $uData['username'])) { + // Check if the account is active (not locked) + if ($uData['active'] == '1') { + // Check if the expiration date has not been reached + if ($uData['expiration_date'] > date( + 'Y-m-d H:i:s' + ) OR $uData['expiration_date'] == '0000-00-00 00:00:00' + ) { + return "valid"; + } else { + return get_lang('AccountExpired'); } - else - return get_lang('InvalidId'); + } else { + return get_lang('AccountInactive'); } - else - return get_lang('AccountURLInactive'); + } else { + return get_lang('InvalidId'); } - return get_lang('InvalidId'); + } else { + return get_lang('AccountURLInactive'); + } } + return get_lang('InvalidId'); + } - /** - * Return the encrypted pass - * @deprecated - * @param $pass - * @return $pass encrypted - */ - /*public function encryptPass($pass){ - return api_get_encrypted_password($pass); - }*/ - - /** - * Gets the real user id based on the user id field name and value. Note that if the user id field name is "chamilo_user_id", it will use the user id + /** + * Gets the real user id based on the user id field name and value. + * Note that if the user id field name is "chamilo_user_id", it will use the user id * in the system database * * @param string User id field name * @param string User id value * @return mixed System user id if the user was found, WSError otherwise */ - protected function getUserId($user_id_field_name, $user_id_value) { + protected function getUserId($user_id_field_name, $user_id_value) + { if($user_id_field_name == "chamilo_user_id") { if(UserManager::is_user_id_valid(intval($user_id_value))) { return intval($user_id_value); @@ -205,14 +212,16 @@ class WSCM { } /** - * Gets the real course id based on the course id field name and value. Note that if the course id field name is "chamilo_course_id", it will use the course id + * Gets the real course id based on the course id field name and value. + * Note that if the course id field name is "chamilo_course_id", it will use the course id * in the system database * * @param string Course id field name * @param string Course id value * @return mixed System course id if the course was found, WSError otherwise */ - protected function getCourseId($course_id_field_name, $course_id_value) { + protected function getCourseId($course_id_field_name, $course_id_value) + { if($course_id_field_name == "chamilo_course_id") { if(CourseManager::get_course_code_from_course_id(intval($course_id_value)) != null) { return intval($course_id_value); @@ -230,7 +239,8 @@ class WSCM { } /** - * Gets the real session id based on the session id field name and value. Note that if the session id field name is "chamilo_session_id", it will use the session id + * Gets the real session id based on the session id field name and value. + * Note that if the session id field name is "chamilo_session_id", it will use the session id * in the system database * * @param string Session id field name @@ -264,7 +274,8 @@ class WSCM { * * @param WSError Error */ - protected function handleError($error) { + protected function handleError($error) + { $handler = WSCMError::getErrorHandler(); $handler->handle($error); } @@ -274,7 +285,8 @@ class WSCM { * * @return array Array with a code of 0 and a message 'Operation was successful' */ - protected function getSuccessfulResult() { + protected function getSuccessfulResult() + { return array('code' => 0, 'message' => 'Operation was successful'); } @@ -283,18 +295,19 @@ class WSCM { * * @return string Success */ - public function test() { + public function test() + { return "success"; } - /** - * *Strictly* reverts PHP's nl2br() effects (whether it was used in XHTML mode or not) - * @param $string - * @return $string - */ - public function nl2br_revert($string) { - return preg_replace('`([\\n\\r])`', '$1', $string); - } + /** + * *Strictly* reverts PHP's nl2br() effects (whether it was used in XHTML mode or not) + * @param $string + * @return $string + */ + public function nl2br_revert($string) { + return preg_replace('`([\\n\\r])`', '$1', $string); + } } diff --git a/tests/main/forum/forumfunction.inc.test.php b/tests/main/forum/forumfunction.inc.test.php index 41d0614aea..2706238517 100755 --- a/tests/main/forum/forumfunction.inc.test.php +++ b/tests/main/forum/forumfunction.inc.test.php @@ -303,20 +303,6 @@ class TestForumFunction extends UnitTestCase { //var_dump($res); } - /** - * This function retrieves all the information of a given forum_id - * @param $forum_id integer that indicates the forum - * @return array returns - * @deprecated this functionality is now moved to get_forums($forum_id) - */ - /* - function testget_forum_information() { - $forum_id = 1; - $res = get_forum_information($forum_id); - $this->assertTrue(is_array($res)); - //var_dump($res); - }*/ - /** * This function retrieves all the information of a given forumcategory id * @param $forum_id integer that indicates the forum @@ -514,28 +500,7 @@ class TestForumFunction extends UnitTestCase { } //var_dump($res); } - - /** - * With this function we find the number of posts and topics in a given forum. - * @param int - * @return array - * @todo consider to call this function only once and let it return an array where the key is the forum id and the value is an array with number_of_topics and number of post - * as key of this array and the value as a value. This could reduce the number of queries needed (especially when there are more forums) - * @todo consider merging both in one query. - * @deprecated the counting mechanism is now inside the function get_forums - */ - /* - function testget_post_topics_of_forum() { - $forum_id = 1; - $res = get_post_topics_of_forum($forum_id); - if(!is_null($res)){ - $this->assertTrue(is_array($res)); - } else { - $this->assertTrue(is_null($res)); - } - //var_dump($res); - }*/ - + /** * Retrieve all posts of a given thread * @param int $thread_id integer that indicates the forum