opensupports/server/controllers/staff/delete.php

68 lines
1.7 KiB
PHP
Raw 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 a staff member.
*
* @apiName Delete
*
* @apiGroup staff
*
* @apiDescription This path deletes a staff member.
*
* @apiPermission Staff level 3
*
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) {
Response::respondError(ERRORS::INVALID_STAFF);
return;
}
2016-12-07 21:24:42 +01:00
foreach($staff->sharedTicketList as $ticket) {
$ticket->owner = null;
2016-12-07 23:30:31 +01:00
$ticket->true = true;
2016-12-08 03:43:32 +01:00
$ticket->store();
2016-12-07 21:24:42 +01:00
}
foreach($staff->sharedDepartmentList as $department) {
$department->owners--;
$department->store();
}
RedBean::exec('DELETE FROM log WHERE author_staff_id = ?', [$staffId]);
$staff->delete();
Response::respondSuccess();
}
}