guillermo - add asign staff ticket [skip ci]

This commit is contained in:
ivan 2016-10-07 19:03:21 -03:00
parent 2eed29e910
commit db97ee09b7
5 changed files with 58 additions and 25 deletions

View File

@ -1,6 +1,6 @@
<?php
require_once 'staff/get.php';
require_once 'staff/assign.php';
require_once 'staff/assign-ticket.php';
$systemControllerGroup = new ControllerGroup();
$systemControllerGroup->setGroupPath('/staff');

View File

@ -0,0 +1,56 @@
<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
class AssignStaffController extends Controller {
const PATH = '/assign-ticket';
private $ticket;
private $user;
public function validations() {
return [
'permission' => 'staff_1',
'requestData' => [
'ticketNumber' => [
'validation' => DataValidator::validTicketNumber(),
'error' => ERRORS::INVALID_TICKET
]
]
];
}
public function handler() {
$ticketNumber = Controller::request('ticketNumber');
$this->user = Controller::getLoggedUser();
$this->ticket = Ticket::getByTicketNumber($ticketNumber);
if($this->ticket->owner) {
Response::respondError(ERRORS::TICKET_ALREADY_ASSIGNED);
return;
}
if(!$this->ticketHasStaffDepartment()) {
Response::respondError(ERRORS::INVALID_DEPARTMENT);
} else {
$this->user->sharedTicketList->add($this->ticket);
$this->ticket->owner = $this->user;
$this->ticket->store();
$this->user->store();
Response::respondSuccess();
}
}
public function ticketHasStaffDepartment() {
$departmentMatch = false;
foreach ($this->user->sharedDepartmentList as $department) {
if($this->ticket->department->id === $department->id) {
$departmentMatch = true;
}
}
return $departmentMatch;
}
}

View File

@ -1,23 +0,0 @@
<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
class AssignStaffController extends Controller {
const PATH = '/assign';
public function validations() {
return [
'permission' => 'staff_1',
'requestData' => [
'ticketNumber' => [
'validation' => DataValidator::validTicketNumber(),
'error' => ERRORS::INVALID_TICKET
]
]
];
}
public function handler() {
}
}

View File

@ -17,4 +17,5 @@ class ERRORS {
const INVALID_CAPTCHA = 'INVALID_CAPTCHA';
const INVALID_TICKET_EVENT = 'INVALID_TICKET_EVENT';
const INVALID_LANGUAGE = 'INVALID_LANGUAGE';
const TICKET_ALREADY_ASSIGNED = 'TICKET_ALREADY_ASSIGNED';
}

View File

@ -32,7 +32,6 @@ class Ticket extends DataStore {
public function getDefaultProps() {
return array(
'owner' => null,
'priority' => 'low',
'ticketNumber' => $this->generateUniqueTicketNumber()
);