opensupports/server/controllers/staff/delete.php

69 lines
1.7 KiB
PHP
Raw Permalink Normal View History

<?php
use Respect\Validation\Validator as DataValidator;
use RedBeanPHP\Facade as RedBean;
2017-04-18 06:39:55 +02:00
/**
* @api {post} /staff/delete Delete staff
2022-01-04 17:24:06 +01:00
* @apiVersion 4.11.0
2017-04-18 06:39:55 +02:00
*
* @apiName Delete staff
2017-04-18 06:39:55 +02:00
*
* @apiGroup Staff
2017-04-18 06:39:55 +02:00
*
* @apiDescription This path deletes a staff member.
*
* @apiPermission staff3
2017-04-18 06:39:55 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiParam {Number} staffId The id of the staff member.
2017-04-18 06:39:55 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiUse NO_PERMISSION
* @apiUse INVALID_STAFF
2017-04-18 06:39:55 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiSuccess {Object} data Empty object
2017-04-18 06:39:55 +02:00
*
*/
DataValidator::with('CustomValidations', true);
class DeleteStaffController extends Controller {
const PATH = '/delete';
const METHOD = 'POST';
public function validations() {
return [
'permission' => 'staff_3',
'requestData' => [
2016-12-08 07:21:37 +01:00
'staffId' =>[
'validation' => DataValidator::dataStoreId('staff'),
'error' => ERRORS::INVALID_STAFF
]
]
];
}
public function handler() {
2016-12-07 21:24:42 +01:00
$staffId = Controller::request('staffId');
$staff = Staff::getDataStore($staffId);
2016-12-07 21:24:42 +01:00
if($staffId === Controller::getLoggedUser()->id) {
throw new RequestException(ERRORS::YOU_CAN_NOT_DELETE_YOURSELF);
}
2016-12-07 21:24:42 +01:00
foreach($staff->sharedTicketList as $ticket) {
$ticket->owner = null;
2019-06-27 03:04:56 +02:00
$ticket->unreadStaff = true;
2016-12-08 03:43:32 +01:00
$ticket->store();
2016-12-07 21:24:42 +01:00
}
2019-06-27 03:04:56 +02:00
foreach($staff->sharedDepartmentList as $department) {
$department->owners--;
$department->store();
}
2019-06-27 03:04:56 +02:00
RedBean::exec('DELETE FROM log WHERE author_staff_id = ?', [$staffId]);
$staff->delete();
Response::respondSuccess();
}
2019-06-27 03:04:56 +02:00
}