diff --git a/server/controllers/staff.php b/server/controllers/staff.php index fff73e65..9967e9db 100644 --- a/server/controllers/staff.php +++ b/server/controllers/staff.php @@ -10,6 +10,7 @@ require_once 'staff/add.php'; require_once 'staff/get-all.php'; require_once 'staff/delete.php'; require_once 'staff/edit.php'; +require_once 'staff/last-events.php'; $systemControllerGroup = new ControllerGroup(); $systemControllerGroup->setGroupPath('/staff'); @@ -25,5 +26,6 @@ $systemControllerGroup->addController(new AddStaffController); $systemControllerGroup->addController(new GetAllStaffController); $systemControllerGroup->addController(new DeleteStaffController); $systemControllerGroup->addController(new EditStaffController); +$systemControllerGroup->addController(new LastEventsStaffController); $systemControllerGroup->finalize(); \ No newline at end of file diff --git a/server/controllers/staff/last-events.php b/server/controllers/staff/last-events.php new file mode 100644 index 00000000..6950bf47 --- /dev/null +++ b/server/controllers/staff/last-events.php @@ -0,0 +1,34 @@ + 'staff_1', + 'requestData' => [ + 'page' => [ + 'validation' => DataValidator::numeric(), + 'error' => ERRORS::INVALID_PAGE + ] + ] + ]; + } + + public function handler() { + $page = Controller::request('page'); + + $user = Controller::getLoggedUser(); + $query = ' ('; + foreach ($user->sharedTicketList as $ticket) { + $query .= 'ticket_id =' . $ticket->id . ' OR '; + } + $query = substr($query,0,-3); + $query .= ') ORDER BY id desc LIMIT ? OFFSET ?' ; + + $eventList = Ticketevent::find($query, [10, 10*($page-1)+1]); + + Response::respondSuccess($eventList->toArray()); + } +} \ No newline at end of file diff --git a/server/models/Ticketevent.php b/server/models/Ticketevent.php index 598eadb3..be1229bf 100644 --- a/server/models/Ticketevent.php +++ b/server/models/Ticketevent.php @@ -58,4 +58,17 @@ class Ticketevent extends DataStore { return new NullDataStore(); } + + public function toArray() { + $user = ($this->authorUser instanceof User) ? $this->authorUser : $this->authorStaff; + + return [ + 'type' => $this->type, + 'ticketNumber' => $this->ticket->ticketNumber, + 'author' => [ + 'name' => $user->name, + 'id' => $user->id + ] + ]; + } } \ No newline at end of file diff --git a/tests/init.rb b/tests/init.rb index 48ea0c17..a300a6fd 100644 --- a/tests/init.rb +++ b/tests/init.rb @@ -47,5 +47,4 @@ require './staff/get-all.rb' require './system/add-department.rb' require './system/edit-department.rb' require './system/delete-department.rb' - - +require './staff/last-events.rb'