opensupports/server/controllers/system/add-department.php

59 lines
1.3 KiB
PHP
Raw Normal View History

<?php
use Respect\Validation\Validator as DataValidator;
2017-04-18 02:09:16 +02:00
/**
* @api {post} /system/add-department Add department
2019-10-08 01:21:43 +02:00
* @apiVersion 4.5.0
2017-04-18 02:09:16 +02:00
*
* @apiName Add department
*
* @apiGroup System
2017-04-18 02:09:16 +02:00
*
* @apiDescription This path create a new department.
*
* @apiPermission staff3
2017-04-18 02:09:16 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiParam {String} name Name of the new department.
2018-11-16 00:51:44 +01:00
* @apiParam {Boolean} private Indicates if the deparment is not shown to users.
2017-04-18 02:09:16 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiUse NO_PERMISSION
2017-04-18 02:09:16 +02:00
*
2017-04-22 03:33:17 +02:00
* @apiSuccess {Object} data Empty object
2017-04-18 02:09:16 +02:00
*
*/
class AddDepartmentController extends Controller {
const PATH = '/add-department';
const METHOD = 'POST';
public function validations() {
return [
'permission' => 'staff_3',
2018-11-16 00:51:44 +01:00
'requestData' => [
'name' => [
'validation' => DataValidator::length(2, 100),
'error' => ERRORS::INVALID_NAME
]
]
];
}
public function handler() {
2018-06-11 23:28:36 +02:00
$name = Controller::request('name');
2018-11-16 00:51:44 +01:00
$private = Controller::request('private');
2018-01-13 03:08:07 +01:00
$departmentInstance = new Department();
2018-01-13 03:08:07 +01:00
$departmentInstance->setProperties([
2018-11-16 00:51:44 +01:00
'name' => $name ,
'private' => $private ? 1 : 0
]);
$departmentInstance->store();
Log::createLog('ADD_DEPARTMENT', $name);
Response::respondSuccess();
}
2018-01-13 03:08:07 +01:00
}