diff --git a/main/inc/lib/course_request.lib.php b/main/inc/lib/course_request.lib.php index 7deb22f569..d79ca8afc1 100644 --- a/main/inc/lib/course_request.lib.php +++ b/main/inc/lib/course_request.lib.php @@ -38,4 +38,79 @@ class CourseRequestManager { return $result['number'] > 0; } + /** + * Creates a new course request within the database. + * @param string $wanted_code The code for the created in the future course. + * @param string $title + * @param string $description + * @param string $category_code + * @param string $course_language + * @param string $objetives + * @param string $target_audience + * @return int/bool The database id of the newly created course request or FALSE on failure. + */ + public static function create_course_request($wanted_code, $title, $description, $category_code, $course_language, $objetives, $target_audience) { + + $wanted_code = Database::escape_string($wanted_code); + $title = Database::escape_string($title); + $description = Database::escape_string($description); + $objetives = str_replace('"', '', $objetives); + $target_audience = str_replace('"', '', $target_audience); + + $keys = define_course_keys($wanted_code, '', $_configuration['db_prefix']); + if (!count($keys)) { + return false; + } + $visual_code = $keys['currentCourseCode']; + $code = $keys['currentCourseId']; + $db_name = $keys['currentCourseDbName']; + $directory = $keys['currentCourseRepository']; + + $user_id = api_get_user_id(); + if ($user_id <= 0) { + return false; + } + $user_info = api_get_user_info($user_id); + $tutor_name = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, $course_language); + + $request_date = date('Y-m-d H:i:s'); // TODO: Use the time-zones way. + $status = COURSE_REQUEST_PENDING; + + $sql = sprintf('INSERT INTO %s ( + code, user_id, directory, db_name, + course_language, title, description, category_code, + tutor_name, visual_code, request_date, + objetives, target_audience, status) + VALUES ( + "%s","%s","%s","%s", + "%s","%s","%s","%s", + "%s","%s","%s", + "%s","%s","%s");', Database::get_main_table(TABLE_MAIN_COURSE_REQUEST), + $code, $user_id, $directory, $db_name, + $course_language, $title, $description, $category_code, + $tutor_name, $visual_code, $request_date, + $objetives, $target_audience, $status); + $result_sql = Database::query($sql); + + if (!$result_sql) { + return false; + } + return Database::get_last_insert_id(); + + } + + /** + * 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. + * @return array/bool Returns the requested data as an array of FALSE on failure. + */ + public static function get_course_request_info($id) { + $sql = "SELECT * FROM ".Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST)." WHERE id='".Database::escape_string($id)."'"; + $result = Database::query($sql); + if (Database::num_rows($result) > 0) { + return Database::fetch_array($result); + } + return false; + } + } \ No newline at end of file