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;
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
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) {
|
|
|
|
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
|
|
|
}
|
2016-12-10 22:55:12 +01:00
|
|
|
|
|
|
|
foreach($staff->sharedDepartmentList as $department) {
|
|
|
|
$department->owners--;
|
|
|
|
$department->store();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|