/
CourseItem.php
118 lines (110 loc) · 2.85 KB
/
CourseItem.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
use Luracast\Restler\RestException;
class CourseItem
{
/**
* @smart-auto-routing false
*/
/**
* @url GET coursesection/{courseId}
*/
protected function getCourseSection($courseId)
{
if (\TTO::getRole() == 'admin') {
$statement = '
SELECT CS.*
FROM course_section AS CS
INNER JOIN course AS C
ON C.courseId = CS.courseId
WHERE CS.courseId = :courseId
ORDER BY CS.seq
';
$bind = array('courseId' => $courseId);
return \Db::getResult($statement, $bind);
} else {
throw new RestException(401, 'No Authorize or Invalid request !!!');
}
}
/**
* @url GET coursesectionItem/{courseId}/{courseSectionId}
*/
protected function getCourseSectionItem($courseId, $courseSectionId)
{
if (\TTO::getRole() == 'admin') {
$statement = '
SELECT *
FROM view_course_item AS CI
WHERE CI.courseId = :courseId
AND CI.courseSectionId = :courseSectionId
ORDER BY CI.courseItemId DESC
';
$bind = array('courseId' => $courseId, 'courseSectionId' => $courseSectionId);
return \Db::getResult($statement, $bind);
} else {
throw new RestException(401, 'No Authorize or Invalid request !!!');
}
}
/**
* @url POST newcourseitem
*/
protected function postNewCourseItem($courseId, array $itemList)
{
if (\TTO::getRole() == 'admin') {
foreach ($itemList as $item) {
$statement = '
INSERT INTO course_item (courseId, itemId)
VALUES (:courseId, :itemId)
';
$bind = array(
'courseId' => $courseId,
'itemId' => $item['itemId']
);
$row_insert = \Db::execute($statement, $bind);
$itemDetailId = \Db::getLastInsertId();
}
$response = new \stdClass();
$response->insert_status = 'done';
return $response;
} else {
throw new RestException(401, 'No Authorize or Invalid request !!!');
}
}
/**
* @url GET allcourseitem/{courseId}
*/
protected function getAllCourseItem($courseId)
{
$statement = '
SELECT *
FROM view_course_item AS VCI
WHERE VCI.courseId = :courseId
';
$bind = array('courseId' => $courseId);
return \Db::getResult($statement, $bind);
}
/**
* @url POST updateCourseItemLevel
*/
protected function postUpdateCourseItemLevel(array $courseItemList)
{
if (\TTO::getRole() == 'admin') {
foreach ($courseItemList as $courseItem) {
$statement = '
UPDATE course_item
SET level = :level
WHERE courseItemId = :courseItemId
';
$bind = array(
'level' => $courseItem['level'],
'courseItemId' => $courseItem['courseItemId']
);
$row_update = \Db::execute($statement, $bind);
}
$response = new \stdClass();
$response->update_status = 'done';
return $response;
} else {
throw new RestException(401, 'No Authorize or Invalid request !!!');
}
}
}