diff --git a/server/controllers/ticket.php b/server/controllers/ticket.php index 95ab2dda..eaab3316 100644 --- a/server/controllers/ticket.php +++ b/server/controllers/ticket.php @@ -1,9 +1,11 @@ <?php include 'ticket/create.php'; +include 'ticket/comment.php'; $ticketControllers = new ControllerGroup(); $ticketControllers->setGroupPath('/ticket'); $ticketControllers->addController(new CreateController); +$ticketControllers->addController(new CommentController); $ticketControllers->finalize(); \ No newline at end of file diff --git a/server/controllers/ticket/comment.php b/server/controllers/ticket/comment.php new file mode 100644 index 00000000..58f7b40b --- /dev/null +++ b/server/controllers/ticket/comment.php @@ -0,0 +1,45 @@ +<?php +use RedBeanPHP\Facade as RedBean; + +class CommentController extends Controller { + const PATH = '/comment'; + + private $ticketId; + private $content; + + public function handler() { + /* + //$this->storeComment(); + $ticket = RedBean::load('tickets', Controller::request('ticketId')); + $comment = RedBean::dispense('comments'); + $comment->content = Controller::request('content'); + + $ticket->ownCommentsList[] = $comment; + + RedBean::store($ticket); + $ticket = RedBean::load('tickets', Controller::request('ticketId')); + + $string = ""; + $string += count($ticket->ownCommentsList); + + foreach( $ticket->ownCommentsList as $comment2 ) { + }*/ + } + + private function storeComment() { + $this->ticketId = Controller::request('ticketId'); + $this->content = Controller::request('content'); + $ticket = Ticket::getTicket($this->ticketId); + + $comment = new Comment(); + $comment->setProperties(array( + 'content' => $this->content + //'ticket' => $ticket->getBeanInstance() + )); + + $ticket->getBeanInstance()->ownCommentsList = [$comment->getBeanInstance()]; + $ticket->store(); + $ticket = Ticket::getTicket($this->ticketId); + Response::respondError(count($ticket->ownCommentsList)); + } +} \ No newline at end of file diff --git a/server/controllers/ticket/create.php b/server/controllers/ticket/create.php index 845b415c..f60dc85c 100644 --- a/server/controllers/ticket/create.php +++ b/server/controllers/ticket/create.php @@ -1,9 +1,10 @@ <?php +use RedBeanPHP\Facade as RedBean; class CreateController extends Controller { const PATH = '/create'; - private $title ; + private $title; private $content; private $departmentId; private $language; diff --git a/server/models/Ticket.php b/server/models/Ticket.php index f1bbe75a..03ae15a7 100644 --- a/server/models/Ticket.php +++ b/server/models/Ticket.php @@ -20,6 +20,10 @@ class Ticket extends DataStore { ); } + public static function getTicket($value, $property = 'id') { + return parent::getDataStore($value, $property); + } + protected function getDefaultProps() { return array(); }