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
|
|
|
/**
|
2017-05-12 06:58:40 +02:00
|
|
|
* @api {post} /article/add-topic Add topic
|
2019-03-06 16:47:24 +01:00
|
|
|
* @apiVersion 4.4.0
|
2017-04-18 02:40:44 +02:00
|
|
|
*
|
|
|
|
* @apiName Add topic
|
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiGroup Article
|
2017-04-18 02:40:44 +02:00
|
|
|
*
|
|
|
|
* @apiDescription This path adds a new topic.
|
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiPermission staff2
|
2017-04-18 02:40:44 +02:00
|
|
|
*
|
|
|
|
* @apiParam {String} name Name of the new topic.
|
2017-04-21 08:09:24 +02:00
|
|
|
* @apiParam {String} icon Icon of the new topic.
|
|
|
|
* @apiParam {String} iconColor Icon's color of the new topic.
|
2018-11-08 18:51:04 +01:00
|
|
|
* @apiParam {Boolean} private Indicates if the topic is not shown to users.
|
2017-04-18 02:40:44 +02:00
|
|
|
*
|
2017-04-21 08:09:24 +02:00
|
|
|
* @apiUse NO_PERMISSION
|
|
|
|
* @apiUse INVALID_NAME
|
2017-04-18 02:40:44 +02:00
|
|
|
*
|
2017-04-22 03:33:17 +02:00
|
|
|
* @apiSuccess {Object} data Topic info
|
|
|
|
* @apiSuccess {Number} data.topicId Topic id
|
2017-04-18 02:40:44 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-11-23 02:27:05 +01:00
|
|
|
class AddTopicController extends Controller {
|
|
|
|
const PATH = '/add-topic';
|
2017-02-08 19:09:15 +01:00
|
|
|
const METHOD = 'POST';
|
2016-11-23 02:27:05 +01:00
|
|
|
|
|
|
|
public function validations() {
|
|
|
|
return [
|
|
|
|
'permission' => 'staff_2',
|
|
|
|
'requestData' => [
|
|
|
|
'name' => [
|
2018-11-08 18:51:04 +01:00
|
|
|
'validation' => DataValidator::length(2, 100),
|
2016-11-23 02:27:05 +01:00
|
|
|
'error' => ERRORS::INVALID_NAME
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handler() {
|
|
|
|
$topic = new Topic();
|
|
|
|
$topic->setProperties([
|
|
|
|
'name' => Controller::request('name'),
|
|
|
|
'icon' => Controller::request('icon'),
|
2018-11-08 18:51:04 +01:00
|
|
|
'iconColor' => Controller::request('iconColor'),
|
|
|
|
'private' => Controller::request('private') ? 1 : 0
|
2016-11-23 02:27:05 +01:00
|
|
|
]);
|
|
|
|
|
2016-12-29 01:55:00 +01:00
|
|
|
Log::createLog('ADD_TOPIC', $topic->name);
|
|
|
|
|
2016-11-23 02:27:05 +01:00
|
|
|
Response::respondSuccess([
|
|
|
|
'topicId' => $topic->store()
|
|
|
|
]);
|
|
|
|
}
|
2018-11-08 18:51:04 +01:00
|
|
|
}
|