opensupports/server/controllers/article/get-all.php

44 lines
1.1 KiB
PHP
Raw Normal View History

2016-11-23 02:27:05 +01:00
<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
2017-04-18 02:40:44 +02:00
/**
* @api {post} /article/get-all Get all articles
2018-09-20 22:19:47 +02:00
* @apiVersion 4.3.0
2017-04-18 02:40:44 +02:00
*
* @apiName Get all articles
2017-04-18 02:40:44 +02:00
*
* @apiGroup Article
2017-04-18 02:40:44 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiDescription This path retrieves all the articles.
2017-04-18 02:40:44 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiPermission any or user
2017-04-18 02:40:44 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiUse NO_PERMISSION
2018-11-08 18:51:04 +01:00
*
2017-04-22 03:33:17 +02:00
* @apiSuccess {[Topic](#api-Data_Structures-ObjectTopic)[]} data Array of topics.
2017-04-18 02:40:44 +02:00
*/
2016-11-23 02:27:05 +01:00
class GetAllArticlesController extends Controller {
const PATH = '/get-all';
const METHOD = 'POST';
2016-11-23 02:27:05 +01:00
public function validations() {
return [
'permission' => (Controller::isUserSystemEnabled()) ? 'user' : 'any',
2016-11-23 02:27:05 +01:00
'requestData' => []
];
}
public function handler() {
$topics = Topic::getAll();
$topicsArray = [];
2018-11-08 18:51:04 +01:00
2016-11-23 02:27:05 +01:00
foreach($topics as $topic) {
2018-11-08 18:51:04 +01:00
Controller::isStaffLogged() ? $topicsArray[] = $topic->toArray() : ($topic->private*1 ? null : $topicsArray[] = $topic->toArray()) ;
2016-11-23 02:27:05 +01:00
}
2018-11-08 18:51:04 +01:00
2016-11-23 02:27:05 +01:00
Response::respondSuccess($topicsArray);
}
2018-11-08 18:51:04 +01:00
}