opensupports/server/controllers/ticket/create.php

71 lines
2.0 KiB
PHP
Raw Normal View History

<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
class CreateController extends Controller {
const PATH = '/create';
private $title;
private $content;
private $departmentId;
private $language;
public function validations() {
return [
2016-08-01 05:34:55 +02:00
'permission' => 'user',
'requestData' => [
'title' => [
'validation' => DataValidator::length(3, 30),
'error' => ERRORS::INVALID_TITLE
],
'content' => [
'validation' => DataValidator::length(10, 500),
'error' => ERRORS::INVALID_CONTENT
],
'departmentId' => [
'validation' => DataValidator::dataStoreId('department'),
'error' => ERRORS::INVALID_DEPARTMENT
]
]
];
}
public function handler() {
$this->storeRequestData();
$this->storeTicket();
Response::respondSuccess();
}
private function storeRequestData() {
$this->title = Controller::request('title');
$this->content = Controller::request('content');
$this->departmentId = Controller::request('departmentId');
$this->language = Controller::request('language');
}
2016-08-04 06:37:23 +02:00
private function storeTicket() {
$department = Department::getDataStore($this->departmentId);
$author = Controller::getLoggedUser();
$ticket = new Ticket();
$ticket->setProperties(array(
'ticketId' => '',
'title' => $this->title,
'content' => $this->content,
'language' => $this->language,
'author' => $author,
'department' => $department,
'file' => '',
2016-08-01 05:34:55 +02:00
'date' => Date::getCurrentDate(),
'unread' => false,
'closed' => false,
));
$author->sharedTicketList->add($ticket);
$author->store();
$ticket->store();
}
}