opensupports/server/controllers/article/edit-topic.php

68 lines
1.8 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/edit-topic Edit topic
2018-11-29 17:35:14 +01:00
* @apiVersion 4.3.2
2017-04-18 02:40:44 +02:00
*
* @apiName Edit topic
*
* @apiGroup Article
2017-04-18 02:40:44 +02:00
*
* @apiDescription This path edits a topic.
*
* @apiPermission staff2
2017-04-18 02:40:44 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiParam {Number} topicId Id of the topic.
* @apiParam {String} name The new name of the topic. Optional.
* @apiParam {String} icon The new icon of the topic. Optional.
* @apiParam {String} iconColor The new Icon's color of the topic. Optional.
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_TOPIC
2017-04-18 02:40:44 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiSuccess {Object} data Empty object
2017-04-18 02:40:44 +02:00
*
*/
2016-11-23 02:27:05 +01:00
class EditTopicController extends Controller {
const PATH = '/edit-topic';
const METHOD = 'POST';
2016-11-23 02:27:05 +01:00
public function validations() {
return [
'permission' => 'staff_2',
'requestData' => [
'topicId' => [
'validation' => DataValidator::dataStoreId('topic'),
'error' => ERRORS::INVALID_TOPIC
]
]
];
}
public function handler() {
$topic = Topic::getDataStore(Controller::request('topicId'));
if(Controller::request('name')) {
$topic->name = Controller::request('name');
}
if(Controller::request('iconColor')) {
$topic->iconColor = Controller::request('iconColor');
}
if(Controller::request('icon')) {
$topic->icon = Controller::request('icon');
}
2018-11-16 03:52:46 +01:00
if (Controller::request('private') !== null) {
2018-11-08 18:51:04 +01:00
$topic->private = Controller::request('private');
}
2016-11-23 02:27:05 +01:00
$topic->store();
Response::respondSuccess();
}
2018-11-08 18:51:04 +01:00
}