diff --git a/server/controllers/article/add-topic.php b/server/controllers/article/add-topic.php index 8c0fc90a..3fef448a 100755 --- a/server/controllers/article/add-topic.php +++ b/server/controllers/article/add-topic.php @@ -4,7 +4,7 @@ DataValidator::with('CustomValidations', true); /** * @api {post} /article/add-topic Add topic - * @apiVersion 4.6.0 + * @apiVersion 4.6.1 * * @apiName Add topic * diff --git a/server/controllers/ticket.php b/server/controllers/ticket.php index bc046c51..c451e84a 100755 --- a/server/controllers/ticket.php +++ b/server/controllers/ticket.php @@ -25,5 +25,6 @@ $ticketControllers->addController(new GetTagsController); $ticketControllers->addController(new AddTagController); $ticketControllers->addController(new RemoveTagController); $ticketControllers->addController(new SearchController); +$ticketControllers->addController(new GetAuthorsController); $ticketControllers->finalize(); diff --git a/server/controllers/ticket/get-authors.php b/server/controllers/ticket/get-authors.php new file mode 100644 index 00000000..6e1c77a0 --- /dev/null +++ b/server/controllers/ticket/get-authors.php @@ -0,0 +1,104 @@ + 'staff_1', + 'requestData' => [ + 'query' => [ + 'validation' => DataValidator::oneOf(DataValidator::notBlank(),DataValidator::nullType()), + 'error' => ERRORS::INVALID_QUERY + ], + 'blackList' => [ + 'validation' => DataValidator::oneOf(DataValidator::notBlank(),DataValidator::nullType(),DataValidator::arrayType()), + 'error' => ERRORS::INVALID_BLACK_LIST + ] + ] + ]; + } + + public function handler() { + $query = Controller::request('query'); + + $idAuthorsQuery = "SELECT id,name,level FROM staff " . $this->GenerateAuthorsIdQuery($query) . " LIMIT 10"; + $authorsIdList = RedBean::getAll($idAuthorsQuery, [':query' => "%" .$query . "%",':query2' => $query . "%"] ); + $authorsList = []; + + foreach($authorsIdList as $item) { + if($item['level'] >=1 && $item['level'] <= 3){ + $author = Staff::getDataStore($item['id']*1); + } else { + $author = User::getDataStore($item['id']*1); + } + array_push($authorsList, $author->toArray()); + } + Response::respondSuccess([ + 'authors' => $authorsList + ]); + } + public function generateAuthorsIdQuery($query) { + if ($query){ + return "WHERE name LIKE :query " . $this->generateStaffBlackListQuery() . " UNION SELECT id,name,signup_date FROM user WHERE name LIKE :query " . $this->generateUserBlackListQuery() . " ORDER BY CASE WHEN (name LIKE :query2) THEN 1 ELSE 2 END ASC "; + } else { + return "WHERE 1=1 ". $this->generateStaffBlackListQuery() . " UNION SELECT id,name,signup_date FROM user WHERE 1=1". $this->generateUserBlackListQuery() ." ORDER BY id"; + } + } + + public function generateStaffBlackListQuery(){ + $StaffBlackList = $this->getBlackListFiltered(); + return $this->generateBlackListQuery($StaffBlackList); + } + + public function generateUserBlackListQuery(){ + $UserBlackList = $this->getBlackListFiltered(0); + return $this->generateBlackListQuery($UserBlackList); + } + + public function generateBlackListQuery($idList){ + $text = ""; + foreach ($idList as $id) { + $text .= " AND id != " . $id; + } + return $text; + } + + public function getBlackListFiltered($staff = 1){ + $blackList = json_decode(Controller::request('blackList')); + $idList = []; + if($blackList){ + foreach ($blackList as $item) { + if($staff == $item->staff) array_push($idList, $item->id); + } + } + return $idList; + } +} diff --git a/server/controllers/ticket/search.php b/server/controllers/ticket/search.php index 82a60a78..e433cda6 100644 --- a/server/controllers/ticket/search.php +++ b/server/controllers/ticket/search.php @@ -137,7 +137,6 @@ class SearchController extends Controller { $totalCount = RedBean::getAll("SELECT COUNT(*) FROM (SELECT COUNT(*) " . $query . " ) AS T2", [':query' => "%" . $inputs['query'] . "%"])[0]['COUNT(*)']; $ticketIdList = RedBean::getAll($queryWithOrder, [':query' => "%" . $inputs['query'] . "%"]); $ticketList = []; - foreach ($ticketIdList as $item) { $ticket = Ticket::getDataStore($item['id']); array_push($ticketList, $ticket->toArray()); diff --git a/server/data/ERRORS.php b/server/data/ERRORS.php index 7577e562..a1c35504 100755 --- a/server/data/ERRORS.php +++ b/server/data/ERRORS.php @@ -95,6 +95,10 @@ * @apiDefine INVALID_QUERY * @apiError {String} INVALID_QUERY The query is invalid. */ +/** + * @apiDefine INVALID_BLACK_LIST + * @apiError {String} INVALID_BLACK_LIST The black list is invalid. + */ /** * @apiDefine INVALID_TAG_FILTER * @apiError {String} INVALID_TAG_FILTER The tag filter is invalid. @@ -330,6 +334,7 @@ class ERRORS { const INVALID_PRIORITY = 'INVALID_PRIORITY'; const INVALID_PAGE = 'INVALID_PAGE'; const INVALID_QUERY = 'INVALID_QUERY'; + const INVALID_BLACK_LIST = 'INVALID_BLACK_LIST'; const INVALID_TAG_FILTER = 'INVALID_TAG_FILTER'; const INVALID_CLOSED_FILTER = 'INVALID_CLOSED_FILTER'; const INVALID_UNREAD_STAFF_FILTER = 'INVALID_UNREAD_STAFF_FILTER';