From 16121be571cbd8167049bd3b05074218d2fefd33 Mon Sep 17 00:00:00 2001 From: Ivan Tcholakov Date: Thu, 7 Oct 2010 23:20:13 +0300 Subject: [PATCH] Feature #2099 - New methods have been added to CourseRequestManager class. --- main/admin/course_request_accepted.php | 8 ++--- main/admin/course_request_rejected.php | 16 ++------- main/admin/course_request_review.php | 20 +++--------- main/create_course/add_course.php | 5 --- main/inc/lib/course_request.lib.php | 45 +++++++++++++++++++++++++- 5 files changed, 54 insertions(+), 40 deletions(-) diff --git a/main/admin/course_request_accepted.php b/main/admin/course_request_accepted.php index 4b6df1b731..a1b442cb90 100644 --- a/main/admin/course_request_accepted.php +++ b/main/admin/course_request_accepted.php @@ -39,14 +39,10 @@ require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; /** - * Get the number of courses which will be displayed + * Get the number of courses which will be displayed. */ function get_number_of_courses() { - $course_table = Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST); - $sql = "SELECT COUNT(code) AS total_number_of_items FROM $course_table WHERE status = ".COURSE_REQUEST_ACCEPTED; - $res = Database :: query($sql); - $obj = Database :: fetch_object($res); - return $obj->total_number_of_items; + return CourseRequestManager::count_course_requests(COURSE_REQUEST_ACCEPTED); } /** diff --git a/main/admin/course_request_rejected.php b/main/admin/course_request_rejected.php index 15849647ee..a1cf95778c 100644 --- a/main/admin/course_request_rejected.php +++ b/main/admin/course_request_rejected.php @@ -62,23 +62,14 @@ if (!empty($accept_course_request)) { * Sending to the teacher a request for additional information about the proposed course. */ if (!empty($request_info)) { - - // Marking the fact, that additional information has been requested. - $sql_info = "UPDATE ".Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST)." SET info = 1 WHERE id = ".$request_info; - $result_info = Database::query($sql_info); - - // TODO: Send the e-mail. + CourseRequestManager::ask_for_additional_info($request_info); } /** - * Get the number of courses which will be displayed + * Get the number of courses which will be displayed. */ function get_number_of_courses() { - $course_table = Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST); - $sql = "SELECT COUNT(code) AS total_number_of_items FROM $course_table WHERE status = ".COURSE_REQUEST_REJECTED; - $res = Database :: query($sql); - $obj = Database :: fetch_object($res); - return $obj->total_number_of_items; + return CourseRequestManager::count_course_requests(COURSE_REQUEST_REJECTED); } /** @@ -113,7 +104,6 @@ function get_course_data($from, $number_of_items, $column, $direction) { /** * Actions in the list: edit. */ - function modify_filter($id) { return ''.get_lang('Edit').' '.' '. diff --git a/main/admin/course_request_review.php b/main/admin/course_request_review.php index cb25e1955c..b083979619 100644 --- a/main/admin/course_request_review.php +++ b/main/admin/course_request_review.php @@ -75,25 +75,16 @@ if (isset($_GET['reject_course_request']) && $_GET['reject_course_request'] != ' * Sending to the teacher a request for additional information about the proposed course. */ if (!empty($request_info)) { - - // Marking the fact, that additional information has been requested. - $sql_info = "UPDATE ".Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST)." SET info = 1 WHERE id = ".$request_info; - $result_info = Database::query($sql_info); - - // TODO: Send the e-mail. + CourseRequestManager::ask_for_additional_info($request_info); } /** - * Funcion feita por nos para saber o numero de cursos na taboa temporal sen validar + * Get the number of courses which will be displayed. */ function get_number_of_courses() { - $course_table = Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST); - $sql = "SELECT COUNT(code) AS total_number_of_items FROM $course_table WHERE status = ".COURSE_REQUEST_PENDING; - $res = Database::query($sql); - $obj = Database::fetch_object($res); - return $obj->total_number_of_items; + return CourseRequestManager::count_course_requests(COURSE_REQUEST_PENDING); } /** @@ -138,13 +129,12 @@ function email_filter($teacher) { /** * Actions in the list: edit, accept, reject, request additional information. */ - function modify_filter($id) { /* return ''.get_lang('Edit').' '.' '.''.get_lang('Delete').''.' '.''.get_lang('cesga_AdminPedirInfo').' '.' '.''.get_lang('cesga_AdminValidar').' '; */ - $sql_request_info = "SELECT * FROM ".Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST)." WHERE (id = ".$id." AND info = 1 )"; + $sql_request_info = "SELECT * FROM ".Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST)." WHERE (id = ".$id." AND info = 1)"; $res_request_info = Database::query($sql_request_info); if (Database::num_rows($res_request_info) > 0) { //Si ya se le ha pedido informaciĆ³n, no se muestra esa opciĆ³n @@ -182,7 +172,7 @@ Display :: display_header($tool_name); //api_display_tool_title($tool_name); if (isset ($_GET['delete_course'])) { - CourseManager :: delete_course($_GET['delete_course']); + //CourseManager :: delete_course($_GET['delete_course']); } // Create a sortable table with the course data diff --git a/main/create_course/add_course.php b/main/create_course/add_course.php index 25cd58d4c4..f63da86e54 100755 --- a/main/create_course/add_course.php +++ b/main/create_course/add_course.php @@ -70,11 +70,6 @@ if (!api_is_allowed_to_create_course()) { exit; } -// Get necessary table definitions. -$table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY); -$table_course = Database :: get_main_table(TABLE_MAIN_COURSE); -$table_course_request = Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST); - global $_configuration; $dbnamelength = strlen($_configuration['db_prefix']); // Ensure the database prefix + database name do not get over 40 characters. diff --git a/main/inc/lib/course_request.lib.php b/main/inc/lib/course_request.lib.php index 783b8e77aa..8470754c06 100644 --- a/main/inc/lib/course_request.lib.php +++ b/main/inc/lib/course_request.lib.php @@ -33,7 +33,7 @@ class CourseRequestManager { } $table_course_request = Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST); $wanted_course_code = Database::escape_string($wanted_course_code); - $sql = sprintf('SELECT COUNT(*) AS number FROM %s WHERE visual_code = "%s"', $table_course_request, $wanted_course_code); + $sql = sprintf('SELECT COUNT(id) AS number FROM %s WHERE visual_code = "%s"', $table_course_request, $wanted_course_code); $result = Database::fetch_array(Database::query($sql)); return $result['number'] > 0; } @@ -109,6 +109,33 @@ class CourseRequestManager { } + /** + * Deletes a given course request. + * @param int/string $id The id (an integer number) of the corresponding database record. + * @return array/bool Returns TRUE on success or FALSE on failure. + */ + public static function delete_course_request($id) { + $id = (int)$id; + $sql = "DELETE FROM ".Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST)." WHERE id = ".$id; + $result = Database::query($sql); + return $result !== false; + } + + public static function count_course_requests($status = null) { + $course_table = Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST); + if (is_null($status)) { + $sql = "SELECT COUNT(id) AS number FROM ".$course_table; + } else { + $status = (int)$status; + $sql = "SELECT COUNT(id) AS number FROM ".$course_table." WHERE status = ".$status; + } + $result = Database::fetch_array(Database::query($sql)); + if (is_array($result)) { + return $result['number']; + } + return false; + } + /** * Gets all the information about a course request using its database id as access key. * @param int/string $id The id (an integer number) of the corresponding database record. @@ -203,4 +230,20 @@ class CourseRequestManager { return $result; } + /** + * Asks the author (through e-mail) for additional info about the given course request. + * @param int/string $id The database primary id of the given request. + * @return array/bool Returns TRUE on success or FALSE on failure. + */ + public static function ask_for_additional_info($id) { + + $id = (int)$id; + $sql = "UPDATE ".Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST)." SET info = 1 WHERE id = ".$id; + $result = Database::query($sql) !== false; + + // TODO: Send the e-mail. + + return $result; + } + }