/
Category.php
46 lines (41 loc) · 918 Bytes
/
Category.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
<?php
use Luracast\Restler\RestException;
class Category
{
/**
* @smart-auto-routing false
*/
/**
* @url GET
*/
protected function getAllCategory()
{
$statement = 'SELECT * FROM category WHERE status = :status';
$bind = array('status' => 'active');
return \Db::getResult($statement, $bind);
}
/**
* @url GET user/{userId}
*/
protected function getUserCategory($userId)
{
if ($userId == \TTO::getUserId() || \TTO::getRole() == 'admin') {
$statement = '
SELECT *
FROM category AS CA
WHERE EXISTS (
SELECT 1
FROM user_course AS UC
INNER JOIN course AS C
ON UC.userId = :userId
AND UC.courseId = C.courseId
WHERE C.categoryId = CA.categoryId
)
';
$bind = array('userId' => $userId);
return \Db::getResult($statement, $bind);
} else {
throw new RestException(401, 'No Authorize or Invalid request !!!');
}
}
}