-
Notifications
You must be signed in to change notification settings - Fork 0
/
Course.php
77 lines (71 loc) · 1.96 KB
/
Course.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
<?php
use Luracast\Restler\RestException;
class Course
{
/**
* @smart-auto-routing false
*/
/**
* @url GET
*/
protected function getCourseList($categoryId)
{
$statement = 'SELECT * FROM course WHERE categoryId = :categoryId';
$bind = array('categoryId' => $categoryId);
return \Db::getResult($statement, $bind);
}
/**
* @url GET user/{userId}
*/
protected function getUserCourseList($userId, $categoryId)
{
if ($userId == \TTO::getUserId() || \TTO::getRole() == 'admin') {
$statement = '
SELECT C.*, UC.userId, UC.coin, UC.point
FROM user_course AS UC
INNER JOIN course AS C
ON UC.courseId = C.courseId
WHERE UC.userId = :userId
AND C.categoryId = :categoryId
';
$bind = array('userId' => $userId, 'categoryId' => $categoryId);
return \Db::getResult($statement, $bind);
} else {
throw new RestException(401, 'No Authorize or Invalid request !!!');
}
}
/**
* @url PUT /{courseId}
* @url PUT /{courseId}/user/{userId}
*/
protected function updateCourse($courseId, $code, $categoryId, $name, $description, $coin, $status, $userId = null)
{
if (\TTO::getRole() == 'admin') {
$statement = '
UPDATE course
SET
code = :code,
categoryId = :categoryId,
name = :name,
description = :description,
coin = :coin,
status = :status
WHERE
courseId = :courseId
';
$bind = array(
'courseId' => $courseId,
'code' => $code,
'categoryId' => $categoryId,
'name' => $name,
'description' => $description,
'coin' => $coin,
'status' => $status
);
$row_update = \Db::execute($statement, $bind);
return;
} else {
throw new RestException(401, 'No Authorize or Invalid request !!!');
}
}
}