public function reply($app, $id)
 {
     if (!$app->user->isLoggedIn()) {
         $app->output->redirect('/');
     }
     try {
         $id_dec = $app->hashids->decrypt($id);
         $ticket = SupportTicket::find('first', ['conditions' => ['id = ? AND status != ?', $id_dec, SupportTicket::STATUS_CLOSED], 'include' => ['user']]);
         if (!$ticket || !($app->user->isRank('Support Technician') || $app->user->id == $ticket->user_id)) {
             $app->output->redirect('/support');
         }
         $request = $app->router->flight->request();
         $reply = SupportReply::create(['support_id' => $ticket->id, 'user_id' => $app->user->id, 'body' => $request->data->body ? $request->data->body : '']);
         $reply->reload();
         $ticket->last_reply = $reply->created_at;
         $ticket->status = $app->user->isRank('Support Technician') && $app->user->id != $ticket->user_id ? SupportTicket::STATUS_CUSTOMERREPLY : SupportTicket::STATUS_STAFFREPLY;
         $ticket->save();
         if ($ticket->status == SupportTicket::STATUS_CUSTOMERREPLY) {
             $notification = Notification::create(['user_id' => $app->user->id, 'receiver_id' => $ticket->user_id, 'title' => 'SUPPORT', 'body' => 'A staff member has responded to your open support ticket ([#' . $app->hashids->encrypt($ticket->id) . '](' . $app->config->get('core.url') . '/support/view/' . $app->hashids->encrypt($ticket->id) . ')).']);
         } else {
             if ($ticket->status == SupportTicket::STATUS_STAFFREPLY) {
                 $replies = SupportReply::find('all', ['conditions' => ['support_id = ?', $ticket->id], 'order' => 'id ASC']);
                 $ticket_user = $ticket->user_id;
                 $staff = array_filter(array_unique(array_map(function ($reply) {
                     return $reply->user_id;
                 }, $replies)), function ($staff_member) use($ticket_user) {
                     return $staff_member != $ticket_user;
                 });
                 foreach ($staff as $idx => $staff_member) {
                     $notification = Notification::create(['user_id' => $ticket->user_id, 'receiver_id' => $staff_member, 'title' => 'SUPPORT', 'body' => 'A user has responded to an open support ticket ([#' . $app->hashids->encrypt($ticket->id) . '](' . $app->config->get('core.url') . '/support/view/' . $app->hashids->encrypt($ticket->id) . ')) that you have addressed.']);
                 }
             }
         }
         $app->output->redirect('/support/view/' . $id);
     } catch (Hashids_Invalid $e) {
         $app->logger->log('SupportTicket ID given was invalid', 'ERROR', array('object' => 'SupportTicket', 'id' => $id, 'pathway' => 'reply'), 'user');
         $app->output->notFound();
     }
 }
Example #2
0
 public function manageTickets($app)
 {
     if (!$app->user->isLoggedIn() || !$app->user->isRank('Support Technician')) {
         $app->logger->log('Unauthorized access to Admin CP', 'ALERT', array(), 'admin');
         $app->output->redirect('/');
     }
     $tickets = SupportTicket::find('all', array('order' => 'last_reply DESC'));
     $app->output->addBreadcrumb('admin', 'Dashboard');
     $app->output->addBreadcrumb('admin/tickets', 'Manage Support Tickets');
     $app->output->setTitle('Manage Support Tickets');
     $app->output->setActiveTab('admin');
     $app->output->render('admin.tickets', ['tickets' => $tickets]);
 }