Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jul 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 36 additions & 49 deletions api/courses/router_classes.php
Original file line number Diff line number Diff line change
@@ -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
));
}

Expand All @@ -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);
Expand All @@ -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
));
}

Expand All @@ -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) {

Expand Down Expand Up @@ -165,4 +151,5 @@ function delete($category_id) {
}
}


?>
8 changes: 4 additions & 4 deletions api/courses/urls.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
?>
?>
101 changes: 39 additions & 62 deletions api/instructors/router_classes.php
Original file line number Diff line number Diff line change
@@ -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
));
}

Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -156,6 +144,8 @@ function delete($instructor_id) {
"query_id_existence_array" => $query_id_existence_array
));
}

}
}

class CourseInstructorList {
Expand Down Expand Up @@ -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);

Expand All @@ -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
));
}
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions api/instructors/urls.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
Expand Down
Loading