diff --git a/api/courses/router_classes.php b/api/courses/router_classes.php index a461bebf4..e97da716d 100644 --- a/api/courses/router_classes.php +++ b/api/courses/router_classes.php @@ -3,32 +3,33 @@ class Courses { function get($course_id) { - $clause = create_SQL_clause(array( - "c.title" => $_GET["title"], - "c.cat_id" => $_GET["category_id"], - "c.primary_language" => $_GET["primary_language"] - )); + if ($course_id) { + $sql_array = array( + "c.course_id" => $course_id + ); + } else { + $sql_array = array( + "c.title" => $_GET["title"], + "c.cat_id" => $_GET["category_id"], + "c.primary_language" => $_GET["primary_language"] + ); + } - $clause_with_id = create_SQL_clause(array( - "c.course_id" => $course_id - )); + $clause = create_SQL_clause($sql_array); $query = "SELECT c.course_id, c.cat_id, cc.cat_name, c.created_date, ". "c.title, c.description, c.notify, c.copyright, c.icon, c.release_date, c.primary_language, ". "c.end_date, c.banner FROM %scourses c ". - "INNER JOIN %scourse_cats cc ON c.cat_id = cc.cat_id "; + "INNER JOIN %scourse_cats cc ON c.cat_id = cc.cat_id ".$clause; $array = array(TABLE_PREFIX, TABLE_PREFIX); - $query .= $course_id ? $clause_with_id : $clause; - $one_row = $course_id ? true : false; - api_backbone(array( "request_type" => HTTP_GET, "access_level" => TOKEN_ACCESS_LEVEL, "query" => $query, "query_array" => $array, - "one_row" => $one_row + "one_row" => $course_id ? true : false )); } @@ -47,28 +48,31 @@ function delete($course_id) { class CourseCategories { function get($category_id){ - $clause = create_SQL_clause(array( - "cat_name" => $_REQUEST["name"], - "cat_parent" => $_REQUEST["parent"], - "theme" => $_REQUEST["theme"] - )); - $clause_with_id = create_SQL_clause(array( - "cat_id" => $category_id - )); + if ($category_id) { + $sql_array = array( + "cat_id" => $category_id + ); + } else { + $sql_array = array( + "cat_name" => $_REQUEST["name"], + "cat_parent" => $_REQUEST["parent"], + "theme" => $_REQUEST["theme"] + ); + } - $query = "SELECT cat_id, cat_name, cat_parent, theme FROM %scourse_cats "; - $array = array(TABLE_PREFIX); - $query .= $category_id ? $clause_with_id : $clause; - $one_row = $category_id ? true : false; + $clause = create_SQL_clause($sql_array); + + $query = "SELECT cat_id, cat_name, cat_parent, theme FROM %scourse_cats ".$clause; + $array = array(TABLE_PREFIX); api_backbone(array( "request_type" => HTTP_GET, "access_level" => TOKEN_ACCESS_LEVEL, "query" => $query, "query_array" => $array, - "one_row" => $one_row + "one_row" => $category_id ? true : false )); } diff --git a/api/instructors/router_classes.php b/api/instructors/router_classes.php index dca34f822..5e3dde95a 100644 --- a/api/instructors/router_classes.php +++ b/api/instructors/router_classes.php @@ -2,23 +2,25 @@ class Instructors { function get($instructor_id) { - $clause = create_SQL_clause(array( - "email" => $_GET["email"], - "first_name" => $_GET["first_name"], - "last_name" => $_GET["last_name"], - "login" => $_GET["login"] - ), "AND"); - $clause_with_id = create_SQL_clause(array( - "member_id" => $instructor_id - ), "AND"); + if ($instructor_id) { + $sql_array = array( + "member_id" => $instructor_id + ); + } else { + $sql_array = array( + "email" => $_GET["email"], + "first_name" => $_GET["first_name"], + "last_name" => $_GET["last_name"], + "login" => $_GET["login"] + ); + } + + $clause = create_SQL_clause($sql_array, "AND"); $query = "SELECT member_id, login, email, first_name, last_name, website, gender, address, ". "postal, city, province, country, phone, language, last_login, creation_date FROM %smembers ". - "WHERE status = %d "; - - $query .= $instructor_id ? $clause_with_id : $clause; - $one_row = $instructor_id ? true : false; + "WHERE status = %d ".$clause; $array = array(TABLE_PREFIX, INSTRUCTOR_ROLE); @@ -27,7 +29,7 @@ function get($instructor_id) { "access_level" => INSTRUCTOR_ACCESS_LEVEL, "query" => $query, "query_array" => $array, - "one_row" => $one_row + "one_row" => $instructor_id ? true : false )); } @@ -196,24 +198,27 @@ function get($instructor_id, $course_id) { class InstructorCourses { function get($instructor_id, $course_id) { - $clause = create_SQL_clause(array( - "c.title" => $_GET["title"], - "c.cat_id" => $_GET["category_id"], - "c.primary_language" => $_GET["primary_language"]), "AND"); - $clause_with_id = create_SQL_clause(array( - "c.course_id" => $course_id - ), "AND"); + if ($course_id) { + $sql_array = array( + "c.course_id" => $course_id + ); + } else { + $sql_array = array( + "c.title" => $_GET["title"], + "c.cat_id" => $_GET["category_id"], + "c.primary_language" => $_GET["primary_language"] + ); + } + + $clause = create_SQL_clause($sql_array, "AND"); $query = "SELECT c.course_id, c.cat_id, cc.cat_name, c.created_date, ". "c.title, c.description, c.notify, c.copyright, c.icon, c.release_date, c.primary_language, ". "c.end_date, c.banner FROM %scourses c ". "INNER JOIN %scourse_cats cc ON c.cat_id = cc.cat_id ". "INNER JOIN %scourse_enrollment ce ON c.course_id = ce.course_id ". - "WHERE ce.member_id = %d "; - - $query .= $course_id ? $clause_with_id : $clause; - $one_row = $course_id ? true : false; + "WHERE ce.member_id = %d ".$clause; $array = array(TABLE_PREFIX, TABLE_PREFIX, TABLE_PREFIX, $instructor_id); @@ -222,7 +227,7 @@ function get($instructor_id, $course_id) { "access_level" => INSTRUCTOR_ACCESS_LEVEL, "query" => $query, "query_array" => $array, - "one_row" => $one_row, + "one_row" => $course_id ? true : false, "member_id" => $instructor_id )); } diff --git a/api/students/router_classes.php b/api/students/router_classes.php index 961b3aad7..5354baee6 100644 --- a/api/students/router_classes.php +++ b/api/students/router_classes.php @@ -2,22 +2,25 @@ class Students { function get($student_id) { - $clause = create_SQL_clause(array( - "email" => $_GET["email"], - "first_name" => $_GET["first_name"], - "last_name" => $_GET["last_name"], - "login" => $_GET["login"]), "AND"); - $clause_with_id = create_SQL_clause(array( - "member_id" => $student_id - ), "AND"); + if ($student_id) { + $sql_array = array( + "member_id" => $student_id + ); + } else { + $sql_array = array( + "email" => $_GET["email"], + "first_name" => $_GET["first_name"], + "last_name" => $_GET["last_name"], + "login" => $_GET["login"] + ); + } + + $clause = create_SQL_clause($sql_array, "AND"); $query = "SELECT member_id, login, email, first_name, last_name, website, gender, address, ". "postal, city, province, country, phone, language, last_login, creation_date FROM %smembers ". - "WHERE status = %d "; - - $query .= $student_id ? $clause_with_id : $clause; - $one_row = $student_id ? true : false; + "WHERE status = %d ".$clause; $array = array(TABLE_PREFIX, STUDENT_ROLE); @@ -26,7 +29,7 @@ function get($student_id) { "access_level" => STUDENT_ACCESS_LEVEL, "query" => $query, "query_array" => $array, - "one_row" => $one_row + "one_row" => $student_id ? true : false )); } @@ -149,24 +152,27 @@ function delete($student_id) { class StudentCourses { function get($student_id, $course_id) { - $clause = create_SQL_clause(array( - "c.title" => $_GET["title"], - "c.cat_id" => $_GET["category_id"], - "c.primary_language" => $_GET["primary_language"]), "AND"); - $clause_with_id = create_SQL_clause(array( - "c.course_id" => $course_id - ), "AND"); + if ($course_id) { + $sql_array = array( + "c.course_id" => $course_id + ); + } else { + $sql_array = array( + "c.title" => $_GET["title"], + "c.cat_id" => $_GET["category_id"], + "c.primary_language" => $_GET["primary_language"] + ); + } + + $clause = create_SQL_clause($sql_array, "AND"); $query = "SELECT c.course_id, c.cat_id, cc.cat_name, c.created_date, ". "c.title, c.description, c.notify, c.copyright, c.icon, c.release_date, c.primary_language, ". "c.end_date, c.banner FROM %scourses c ". "INNER JOIN %scourse_cats cc ON c.cat_id = cc.cat_id ". "INNER JOIN %scourse_enrollment ce ON c.course_id = ce.course_id ". - "WHERE ce.member_id = %d "; - - $query .= $course_id ? $clause_with_id : $clause; - $one_row = $course_id ? true : false; + "WHERE ce.member_id = %d ".$clause; $array = array(TABLE_PREFIX, TABLE_PREFIX, TABLE_PREFIX, $student_id); @@ -175,7 +181,7 @@ function get($student_id, $course_id) { "access_level" => STUDENT_ACCESS_LEVEL, "query" => $query, "query_array" => $array, - "one_row" => $one_row, + "one_row" => $course_id ? true : false, "member_id" => $student_id )); }