2016-12-07 05:37:18 +01:00
|
|
|
<?php
|
|
|
|
use Respect\Validation\Validator as DataValidator;
|
2016-12-29 06:50:53 +01:00
|
|
|
use RedBeanPHP\Facade as RedBean;
|
|
|
|
|
2017-04-18 06:39:55 +02:00
|
|
|
/**
|
2017-05-12 06:58:40 +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
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiName Delete staff
|
2017-04-18 06:39:55 +02:00
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiGroup Staff
|
2017-04-18 06:39:55 +02:00
|
|
|
*
|
|
|
|
* @apiDescription This path deletes a staff member.
|
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-12-07 06:06:50 +01:00
|
|
|
DataValidator::with('CustomValidations', true);
|
2016-12-07 05:37:18 +01:00
|
|
|
|
|
|
|
class DeleteStaffController extends Controller {
|
|
|
|
const PATH = '/delete';
|
2017-02-08 19:09:15 +01:00
|
|
|
const METHOD = 'POST';
|
2016-12-07 05:37:18 +01:00
|
|
|
|
|
|
|
public function validations() {
|
|
|
|
return [
|
|
|
|
'permission' => 'staff_3',
|
2016-12-07 06:06:50 +01:00
|
|
|
'requestData' => [
|
2016-12-08 07:21:37 +01:00
|
|
|
'staffId' =>[
|
|
|
|
'validation' => DataValidator::dataStoreId('staff'),
|
|
|
|
'error' => ERRORS::INVALID_STAFF
|
|
|
|
]
|
2016-12-07 06:06:50 +01:00
|
|
|
]
|
2016-12-07 05:37:18 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-12-07 06:06:50 +01:00
|
|
|
public function handler() {
|
2016-12-07 21:24:42 +01:00
|
|
|
$staffId = Controller::request('staffId');
|
2016-12-07 06:06:50 +01:00
|
|
|
$staff = Staff::getDataStore($staffId);
|
2016-12-07 21:24:42 +01:00
|
|
|
|
2016-12-21 21:54:02 +01:00
|
|
|
if($staffId === Controller::getLoggedUser()->id) {
|
2020-09-30 22:35:32 +02:00
|
|
|
throw new RequestException(ERRORS::YOU_CAN_NOT_DELETE_YOURSELF);
|
2016-12-21 21:54:02 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2016-12-10 22:55:12 +01:00
|
|
|
foreach($staff->sharedDepartmentList as $department) {
|
|
|
|
$department->owners--;
|
|
|
|
$department->store();
|
|
|
|
}
|
2019-06-27 03:04:56 +02:00
|
|
|
|
2016-12-29 06:50:53 +01:00
|
|
|
RedBean::exec('DELETE FROM log WHERE author_staff_id = ?', [$staffId]);
|
2016-12-07 06:06:50 +01:00
|
|
|
$staff->delete();
|
|
|
|
Response::respondSuccess();
|
2016-12-07 05:37:18 +01:00
|
|
|
}
|
2019-06-27 03:04:56 +02:00
|
|
|
|
|
|
|
}
|