diff --git a/main/inc/lib/course_request.lib.php b/main/inc/lib/course_request.lib.php index 13758d9e2a..7deb22f569 100644 --- a/main/inc/lib/course_request.lib.php +++ b/main/inc/lib/course_request.lib.php @@ -18,4 +18,24 @@ define(COURSE_REQUEST_REJECTED, 2); class CourseRequestManager { + /** + * Checks whether a given course code has been already occupied. + * @param string $wanted_course_code The code to be checked. + * @return string + * Returns TRUE if there is created: + * - a course with the same code OR visual_code (visualcode). + * - a course request with the same code as the given one, or + * Othewise returns FALSE. + */ + public static function course_code_exists($wanted_course_code) { + if ($code_exists = CourseManager::course_code_exists($wanted_course_code)) { + return $code_exists; + } + $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); + $result = Database::fetch_array(Database::query($sql)); + return $result['number'] > 0; + } + } \ No newline at end of file