[AntonyAntonio] - Add functionality 'ticket/create' controller [skip ci]

This commit is contained in:
Ivan Diaz 2016-06-17 17:44:04 -03:00
parent 86fc4ab0b6
commit ba15c81178

View File

@ -3,34 +3,57 @@
class CreateController extends Controller { class CreateController extends Controller {
const PATH = '/create'; const PATH = '/create';
private $title ;
private $content;
private $departmentId;
private $language;
public function handler(){ public function handler(){
$title = Controller::request('title'); $this->requestTicketData();
$content = Controller::request('content');
$departmentId = Controller::request('departmentId'); $validateResult = $this->validateData();
$language = Controller::request('language');
if (strlen($title)<3 ){ if ($validateResult !== true) {
Response::respondError('title is so short'); Response::respondError($validateResult);
return; } else {
$this->storeTicket();
Response::respondSuccess();
} }
if (strlen($title)>30){ }
Response::respondError('title is so long');
return; private function requestTicketData(){
$this->title = Controller::request('title');
$this->content = Controller::request('content');
$this->departmentId = Controller::request('departmentId');
$this->language = Controller::request('language');
}
private function validateData() {
if (strlen($this->title)<3 ){
return 'title is so short';
} }
if (strlen($content)<5){ if (strlen($this->title)>30){
Response::respondError('content is so short'); return 'title is very long';
return;
} }
if (strlen($content)>100){ if (strlen($this->content)<5){
Response::respondError('content is so long'); return 'content is so short';
return;
} }
if (strlen($this->content)>100){
return 'content is very long';
}
return true;
}
private function storeTicket() {
$ticket = new Ticket(); $ticket = new Ticket();
$ticket->setProperties(array( $ticket->setProperties(array(
'ticketId' => '', 'ticketId' => '',
'title' => $title, 'title' => $this->title,
'content' => $content, 'content' => $this->content,
'language' => $language, 'language' => $this->language,
'department' => $departmentId, 'department' => $this->departmentId,
'file' => '', 'file' => '',
'date' => date("F j, Y, g:i a"), 'date' => date("F j, Y, g:i a"),
'unread' => false, 'unread' => false,
@ -39,9 +62,6 @@ class CreateController extends Controller {
'owner'=> '', 'owner'=> '',
'ownComments' => [] 'ownComments' => []
)); ));
$ticket->store(); $ticket->store();
Response::respondSuccess();
} }
} }