Skip to content

Commit

Permalink
API Merge - Cleaned code acc to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sdaityari committed Jul 14, 2014
1 parent 9ff0e2a commit 78dc07f
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 77 deletions.
56 changes: 30 additions & 26 deletions api/courses/router_classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
));
}

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

Expand Down
57 changes: 31 additions & 26 deletions api/instructors/router_classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

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

Expand All @@ -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
));
}
Expand Down
56 changes: 31 additions & 25 deletions api/students/router_classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

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

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

0 comments on commit 78dc07f

Please sign in to comment.