API Merge: Merged get functions with and without id #26

Merged
merged 3 commits into from Jul 14, 2014
Jump to file or symbol
Failed to load files and symbols.
+124 −181
Diff settings

Always

Just for now

@@ -1,45 +1,35 @@
<?php
-class CourseList {
- function get() {
- $clause = create_SQL_clause(array(
- "c.title" => $_GET["title"],
- "c.cat_id" => $_GET["category_id"],
- "c.primary_language" => $_GET["primary_language"]
- ));
-
- $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 ".$clause;
-
- $array = array(TABLE_PREFIX, TABLE_PREFIX);
+class Courses {
+ function get($course_id) {
- api_backbone(array(
- "request_type" => HTTP_GET,
- "access_level" => TOKEN_ACCESS_LEVEL,
- "query" => $query,
- "query_array" => $array
- ));
- }
+ 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);
-class CourseDetails {
- function get($course_id) {
$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 WHERE course_id = %d";
+ "INNER JOIN %scourse_cats cc ON c.cat_id = cc.cat_id ".$clause;
- $array = array(TABLE_PREFIX, TABLE_PREFIX, $course_id);
+ $array = array(TABLE_PREFIX, TABLE_PREFIX);
api_backbone(array(
"request_type" => HTTP_GET,
"access_level" => TOKEN_ACCESS_LEVEL,
"query" => $query,
"query_array" => $array,
- "one_row" => true
+ "one_row" => $course_id ? true : false
));
}
@@ -57,12 +47,22 @@ function delete($course_id) {
}
class CourseCategories {
- function get(){
- $clause = create_SQL_clause(array(
- "cat_name" => $_REQUEST["name"],
- "cat_parent" => $_REQUEST["parent"],
- "theme" => $_REQUEST["theme"]
- ));
+ function get($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"]
+ );
+ }
+
+
+ $clause = create_SQL_clause($sql_array);
$query = "SELECT cat_id, cat_name, cat_parent, theme FROM %scourse_cats ".$clause;
$array = array(TABLE_PREFIX);
@@ -71,7 +71,8 @@ function get(){
"request_type" => HTTP_GET,
"access_level" => TOKEN_ACCESS_LEVEL,
"query" => $query,
- "query_array" => $array
+ "query_array" => $array,
+ "one_row" => $category_id ? true : false
));
}
@@ -95,21 +96,6 @@ function post(){
"returned_id_name" => true
));
}
-}
-
-class CourseCategoryDetails {
- function get($category_id) {
- $query = "SELECT cat_id, cat_name, cat_parent, theme FROM %scourse_cats WHERE cat_id = %d";
- $array = array(TABLE_PREFIX, $category_id);
-
- api_backbone(array(
- "request_type" => HTTP_GET,
- "access_level" => INSTRUCTOR_ACCESS_LEVEL,
- "query" => $query,
- "query_array" => $array,
- "one_row" => true
- ));
- }
function put($category_id) {
@@ -165,4 +151,5 @@ function delete($category_id) {
}
}
+
?>
View
@@ -7,11 +7,11 @@
$courses_url_prefix = "/courses";
$course_base_urls = array(
- "/" => "CourseList",
- "/:number" => "CourseDetails",
+ "/" => "Courses",
+ "/:number" => "Courses",
"/categories/" => "CourseCategories",
- "/categories/:number" => "CourseCategoryDetails"
+ "/categories/:number" => "CourseCategories"
);
$course_urls = generate_urls($course_base_urls, $courses_url_prefix);
-?>
+?>
@@ -1,26 +1,35 @@
<?php
class Instructors {
- function get() {
- // Get instructor list
- $clause = create_SQL_clause(array(
- "email" => $_GET["email"],
- "first_name" => $_GET["first_name"],
- "last_name" => $_GET["last_name"],
- "login" => $_GET["login"]
- ), "AND");
+ function get($instructor_id) {
+
+ 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 ". $clause;
+ "WHERE status = %d ".$clause;
$array = array(TABLE_PREFIX, INSTRUCTOR_ROLE);
api_backbone(array(
"request_type" => HTTP_GET,
"access_level" => INSTRUCTOR_ACCESS_LEVEL,
"query" => $query,
- "query_array" => $array
+ "query_array" => $array,
+ "one_row" => $instructor_id ? true : false
));
}
@@ -67,27 +76,6 @@ function post() {
"returned_id_name" => true
));
- }
-}
-
-class InstructorDetails {
- function get($instructor_id) {
- $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 AND member_id = %d";
-
- $array = array(TABLE_PREFIX, INSTRUCTOR_ROLE, $instructor_id);
-
- api_backbone(array(
- "request_type" => HTTP_GET,
- "access_level" => INSTRUCTOR_ACCESS_LEVEL,
- "query" => $query,
- "query_array" => $array,
- "one_row" => true,
- "member_id" => $instructor_id
- ));
- }
-
function put($instructor_id) {
$clause_check = create_SQL_clause(array(
login => $_REQUEST["login"],
@@ -156,6 +144,8 @@ function delete($instructor_id) {
"query_id_existence_array" => $query_id_existence_array
));
}
+
+ }
}
class CourseInstructorList {
@@ -206,19 +196,29 @@ function get($instructor_id, $course_id) {
}
}
-class InstructorCoursesList {
- function get($instructor_id) {
- $clause = create_SQL_clause(array(
- "c.title" => $_GET["title"],
- "c.cat_id" => $_GET["category_id"],
- "c.primary_language" => $_GET["primary_language"]), "AND");
+class InstructorCourses {
+ function get($instructor_id, $course_id) {
+
+ 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 ". $clause;
+ "WHERE ce.member_id = %d ".$clause;
$array = array(TABLE_PREFIX, TABLE_PREFIX, TABLE_PREFIX, $instructor_id);
@@ -227,6 +227,7 @@ function get($instructor_id) {
"access_level" => INSTRUCTOR_ACCESS_LEVEL,
"query" => $query,
"query_array" => $array,
+ "one_row" => $course_id ? true : false,
"member_id" => $instructor_id
));
}
@@ -268,30 +269,6 @@ function post($instructor_id) {
}
-}
-
-class InstructorCoursesDetails {
- function get($instructor_id, $course_id) {
- $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 ".
- "AND c.course_id = %d";
-
- $array = array(TABLE_PREFIX, TABLE_PREFIX, TABLE_PREFIX, $instructor_id, $course_id);
-
- api_backbone(array(
- "request_type" => HTTP_GET,
- "access_level" => INSTRUCTOR_ACCESS_LEVEL,
- "query" => $query,
- "query_array" => $array,
- "one_row" => true,
- "member_id" => $instructor_id
- ));
- }
-
function put($instructor_id, $course_id) {
$access_level = INSTRUCTOR_ACCESS_LEVEL;
View
@@ -8,9 +8,9 @@
$instructor_base_urls = array(
"/" => "Instructors",
- "/:number/" => "InstructorDetails",
- "/:number/courses/" => "InstructorCoursesList",
- "/:number/courses/:number" => "InstructorCoursesDetails",
+ "/:number/" => "Instructors",
+ "/:number/courses/" => "InstructorCourses",
+ "/:number/courses/:number" => "InstructorCourses",
"/:number/courses/:number/instructors" => "CourseInstructorList",
"/:number/courses/:number/students" => "CourseEnrolledList"
);
Oops, something went wrong.