opensupports/server/controllers/article/edit.php

79 lines
2.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/edit Edit a article.
*
* @apiName Edit a article
*
* @apiGroup article
*
* @apiDescription This path edits a article.
*
* @apiPermission Staff level 2
*
2017-04-21 08:09:24 +02:00
* @apiParam {Number} articleId Id of the article.
* @apiParam {Number} topicId Id of the topic of the article.
* @apiParam {String} content The new content of the article.
* @apiParam {String} title The new title of the article.
* @apiParam {Number} position The new position of the article.
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 EditArticleController extends Controller {
const PATH = '/edit';
const METHOD = 'POST';
2016-11-23 02:27:05 +01:00
public function validations() {
return [
'permission' => 'staff_2',
'requestData' => [
'articleId' => [
'validation' => DataValidator::dataStoreId('article'),
'error' => ERRORS::INVALID_TOPIC
]
]
];
}
public function handler() {
$article = Article::getDataStore(Controller::request('articleId'));
if (Controller::request('topicId')) {
$newArticleTopic = Topic::getDataStore(Controller::request('topicId'));
if (!$newArticleTopic->isNull()) {
2016-11-23 02:27:05 +01:00
$article->topic = $newArticleTopic;
} else {
Response::respondError(ERRORS::INVALID_TOPIC);
return;
}
}
if(Controller::request('content')) {
$article->content = Controller::request('content', true);
2016-11-23 02:27:05 +01:00
}
if(Controller::request('title')) {
$article->title = Controller::request('title');
}
if(Controller::request('position')) {
$article->position = Controller::request('position');
}
$article->lastEdited = Date::getCurrentDate();
$article->store();
Log::createLog('EDIT_ARTICLE', $article->title);
2016-11-23 02:27:05 +01:00
Response::respondSuccess();
}
}