Пример #1
0
 /**
  * Ticket listing.
  */
 public function indexAction()
 {
     // Only get the current projects tickets
     $tickets = ticketQuery()->where('t.project_id = ?')->setParameter(0, $this->currentProject['id']);
     // Sort tickets by the projects sorting setting or by the users selection
     $this->sortTickets($tickets);
     // Filter tickets
     $filter = new TicketFilterQuery($tickets, $this->getFilters());
     $queryString = $filter->query;
     // Paginate tickets
     $pagination = new Pagination(Request::$query->get('page', 1), setting('tickets_per_page'), $tickets->execute()->rowCount(), $filter->query);
     if ($pagination->paginate) {
         $tickets->setFirstResult($pagination->limit);
         $tickets->setMaxResults(setting('tickets_per_page'));
     }
     // Fetch all tickets
     $tickets = $tickets->execute()->fetchAll();
     return $this->respondTo(function ($format) use($filter, $tickets, $pagination) {
         if ($format == 'html') {
             return $this->render('ticket_listing/index.phtml', ['filters' => $filter->filters, 'columns' => $this->getColumns(), 'tickets' => $tickets, 'pagination' => $pagination]);
         } elseif ($format == 'json') {
             return $this->jsonResponse(['page' => (int) $pagination->page, 'total_pages' => (int) $pagination->totalPages, 'filters' => $filter->filters, 'tickets' => $tickets]);
         }
     });
 }
Пример #2
0
 /**
  * Update ticket.
  *
  * @param integer $id id matching ticket_id
  */
 public function updateAction($id)
 {
     if (!$this->hasPermission('update_tickets') || !$this->hasPermission('comment_on_tickets')) {
         return $this->show403();
     }
     // Fetch the ticket, but filter it by ticket_id and project_id
     $ticket = ticketQuery()->addSelect('t.*')->where('t.ticket_id = ?')->andWhere('t.project_id = ?')->setParameter(0, $id)->setParameter(1, $this->currentProject['id'])->fetch();
     if ($this->hasPermission('update_tickets')) {
         $data = $this->ticketParamsUpdate();
         $changes = $this->makeChanges($ticket, $data);
     } else {
         $data = [];
         $changes = [];
     }
     if ($this->hasPermission('comment_on_tickets')) {
         $comment = empty(Request::$post->get('comment')) ? null : Request::$post->get('comment');
     }
     if (count($changes) || Request::$post->get('comment')) {
         $update = new TicketHistory(['user_id' => $this->currentUser['id'], 'ticket_id' => $ticket['id'], 'changes' => count($changes) ? $changes : null, 'comment' => isset($comment) ? $comment : null]);
         $ticket->set($data);
         if ($ticket->validate()) {
             $ticket->save();
             $update->save();
             // Which action is being performed?
             $status = Status::find($ticket->status_id)->name;
             if (!count($changes)) {
                 $action = 'ticket_comment';
                 $status = null;
             } elseif ($ticket->isClosing) {
                 $action = 'ticket_closed';
             } elseif ($ticket->isReopening) {
                 $action = 'ticket_reopened';
             } else {
                 $action = 'ticket_updated';
                 $status = null;
             }
             $timeline = Timeline::updateTicketEvent($this->currentUser, $ticket, $action, $status);
             $timeline->save();
             return $this->redirectTo('ticket', ['pslug' => $this->currentProject['slug'], $ticket['ticket_id']]);
         } else {
             $this->set('ticketModel', $ticket);
             return $this->render('tickets/update.phtml', ['ticket' => $ticket]);
         }
     } else {
         return $this->redirectTo('ticket', ['pslug' => $this->currentProject['slug'], $ticket['ticket_id']]);
     }
 }
Пример #3
0
 /**
  * Get tickets.
  *
  * @param array $ids
  *
  * @return array
  */
 protected function getTickets($ids)
 {
     if (!count($ids)) {
         return;
     }
     $query = ticketQuery();
     $query->andWhere($query->expr()->in('t.id', $ids));
     $tickets = [];
     foreach ($query->execute()->fetchAll() as $ticket) {
         $tickets[$ticket['id']] = $ticket;
     }
     return $tickets;
 }
Пример #4
0
 /**
  * Get rows from the specified table.
  *
  * @param array $ids
  *
  * @return array
  */
 protected function getRows($table, $ids)
 {
     if (!count($ids)) {
         return;
     }
     if ($table === 'tickets') {
         $query = ticketQuery();
         $query->andWhere($query->expr()->in('t.id', $ids));
     } else {
         $query = queryBuilder()->select('*')->from($this->db->prefix . $table);
         $query->where($query->expr()->in('id', $ids));
     }
     $rows = [];
     foreach ($query->execute()->fetchAll() as $row) {
         $rows[$row['id']] = $row;
     }
     return $rows;
 }