From 4f4f916f171eb589ac71f704c1ce5bbae53d77d0 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 29 Mar 2011 19:43:51 +0200 Subject: [PATCH] Avoiding warning messages if course does not exist --- .../tool_processors/link_processor.class.php | 49 ++++++++------- .../tool_processors/quiz_processor.class.php | 61 +++++++++---------- 2 files changed, 57 insertions(+), 53 deletions(-) mode change 100644 => 100755 main/inc/lib/search/tool_processors/link_processor.class.php mode change 100644 => 100755 main/inc/lib/search/tool_processors/quiz_processor.class.php diff --git a/main/inc/lib/search/tool_processors/link_processor.class.php b/main/inc/lib/search/tool_processors/link_processor.class.php old mode 100644 new mode 100755 index 9ed858d152..7be57dc0c3 --- a/main/inc/lib/search/tool_processors/link_processor.class.php +++ b/main/inc/lib/search/tool_processors/link_processor.class.php @@ -86,27 +86,32 @@ class link_processor extends search_processor { * Get document information */ private function get_information($course_id, $link_id) { - $item_property_table = Database::get_course_table_from_code($course_id, TABLE_ITEM_PROPERTY); - $link_id = Database::escape_string($link_id); - $sql = "SELECT insert_user_id FROM $item_property_table - WHERE ref = $link_id AND tool = '". TOOL_LINK ."' - LIMIT 1"; - - $name = get_lang('Links'); - $url = api_get_path(WEB_PATH) . 'main/link/link.php?cidReq=%s'; - $url = sprintf($url, $course_id); - // Get the image path - $thumbnail = api_get_path(WEB_CODE_PATH) .'img/link.gif'; - $image = $thumbnail; //FIXME: use big images - // get author - $author = ''; - $item_result = Database::query ($sql); - if ($row = Database::fetch_array ($item_result)) { - $user_data = api_get_user_info($row['insert_user_id']); - $author = api_get_person_name($user_data['firstName'], $user_data['lastName']); + $course_information = api_get_course_info($course_id); + if (!empty($course_information)) { + $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_information['db_name']); + + $link_id = Database::escape_string($link_id); + $sql = "SELECT insert_user_id FROM $item_property_table + WHERE ref = $link_id AND tool = '". TOOL_LINK ."' + LIMIT 1"; + + $name = get_lang('Links'); + $url = api_get_path(WEB_PATH) . 'main/link/link.php?cidReq=%s'; + $url = sprintf($url, $course_id); + // Get the image path + $thumbnail = api_get_path(WEB_CODE_PATH) .'img/link.gif'; + $image = $thumbnail; //FIXME: use big images + // get author + $author = ''; + $item_result = Database::query ($sql); + if ($row = Database::fetch_array ($item_result)) { + $user_data = api_get_user_info($row['insert_user_id']); + $author = api_get_person_name($user_data['firstName'], $user_data['lastName']); + } + + return array($thumbnail, $image, $name, $author, $url); + } else { + return array(); } - - return array($thumbnail, $image, $name, $author, $url); } -} -?> +} \ No newline at end of file diff --git a/main/inc/lib/search/tool_processors/quiz_processor.class.php b/main/inc/lib/search/tool_processors/quiz_processor.class.php old mode 100644 new mode 100755 index 481eef9a14..52dd177291 --- a/main/inc/lib/search/tool_processors/quiz_processor.class.php +++ b/main/inc/lib/search/tool_processors/quiz_processor.class.php @@ -96,37 +96,36 @@ class quiz_processor extends search_processor { * Get learning path information */ private function get_information($course_id, $exercise_id) { - $exercise_table = Database::get_course_table_from_code($course_id, TABLE_QUIZ_TEST); - $item_property_table = Database::get_course_table_from_code($course_id, TABLE_ITEM_PROPERTY); - $exercise_id = Database::escape_string($exercise_id); - $sql = "SELECT * FROM $exercise_table - WHERE id = $exercise_id - LIMIT 1"; - $dk_result = Database::query ($sql); - - //actually author isn't saved on exercise tool, but prepare for when it's ready - $sql = "SELECT insert_user_id - FROM $item_property_table - WHERE ref = $doc_id - AND tool = '". TOOL_DOCUMENT ."' - LIMIT 1"; - - $name = ''; - if ($row = Database::fetch_array ($dk_result)) { - // Get the image path - $thumbnail = api_get_path(WEB_PATH) . 'main/img/quiz.gif'; - $image = $thumbnail; //FIXME: use big images - $name = $row['title']; - // get author - $author = ''; - $item_result = Database::query ($sql); - if ($item_result !== FALSE && $row = Database::fetch_array ($item_result)) { - $user_data = api_get_user_info($row['insert_user_id']); - $author = api_get_person_name($user_data['firstName'], $user_data['lastName']); + $course_information = api_get_course_info($course_id); + if (!empty($course_information)) { + $exercise_table = Database::get_course_table(TABLE_QUIZ_TEST, $course_information['db_name']); + $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_information['db_name']); + $exercise_id = intval($exercise_id); + $sql = "SELECT * FROM $exercise_table WHERE id = $exercise_id LIMIT 1"; + $dk_result = Database::query($sql); + + //actually author isn't saved on exercise tool, but prepare for when it's ready + $sql = "SELECT insert_user_id FROM $item_property_table + WHERE ref = $doc_id AND tool = '". TOOL_DOCUMENT ."' + LIMIT 1"; + + $name = ''; + if ($row = Database::fetch_array ($dk_result)) { + // Get the image path + $thumbnail = api_get_path(WEB_PATH) . 'main/img/quiz.gif'; + $image = $thumbnail; //FIXME: use big images + $name = $row['title']; + // get author + $author = ''; + $item_result = Database::query($sql); + if ($item_result !== FALSE && $row = Database::fetch_array ($item_result)) { + $user_data = api_get_user_info($row['insert_user_id']); + $author = api_get_person_name($user_data['firstName'], $user_data['lastName']); + } } + return array($thumbnail, $image, $name, $author); + } else { + return array(); } - - return array($thumbnail, $image, $name, $author); } -} -?> +} \ No newline at end of file