/** * View a single location */ public function view() { // Make sure we have the location in the system $location = trim($_GET['location']); if (!$location) { header('Location: ' . BASE_URL . '/locations'); exit; } $table = new TicketTable(); $ticketList = $table->find(array('location' => $location)); $this->template->setFilename('locations'); $blocks = array('locationInfo', 'masterAddressData', 'locationPeople'); foreach ($blocks as $b) { $this->template->blocks['left'][] = new Block("locations/{$b}.inc", array('location' => $location, 'disableButtons' => isset($_GET['disableButtons']))); } $this->template->blocks['right'][] = new Block('tickets/ticketList.inc', array('ticketList' => $ticketList, 'title' => 'Cases Associated with this Location', 'disableLinks' => isset($_GET['disableLinks']), 'disableButtons' => isset($_GET['disableButtons']))); if (Person::isAllowed('tickets', 'merge') && !isset($_GET['disableLinks']) && count($ticketList) > 1) { $this->template->blocks['right'][] = new Block('tickets/ticketSelectForMergeForm.inc'); } }
/** * Adds a ticketList about the Person to the template * * @param string $panel * @param string $listType (enteredBy, assigned, reportedBy, referred) * @param string $title * @param Person $person * @param bool $disableLinks * * @return int The number of tickets displayed in the list */ private function addTicketList($panel, $listType, $title, Person $person, $disableLinks = false, $disableButtons = false) { $field = $listType . 'Person_id'; $table = new TicketTable(); $tickets = $table->find([$field => $person->getId()], 'tickets.enteredDate desc', true); $tickets->setCurrentPageNumber(1); $tickets->setItemCountPerPage(10); $numPages = count($tickets); if ($numPages) { $block = new Block('tickets/ticketList.inc', array('ticketList' => $tickets, 'title' => $title, 'disableLinks' => $disableLinks, 'disableButtons' => $disableButtons)); if ($numPages > 1) { $block->moreLink = BASE_URL . "/tickets?{$listType}Person_id={$person->getId()}"; } $this->template->blocks[$panel][] = $block; } return $numPages; }
/** * @param REQUEST service_request_id */ public function requests() { if (!empty($_REQUEST['service_code'])) { try { $category = new Category($_REQUEST['service_code']); } catch (\Exception $e) { header('HTTP/1.0 404 Not Found', true, 404); $_SESSION['errorMessages'][] = $e; return; } } // Display a single request if (!empty($_REQUEST['service_request_id'])) { try { $ticket = new Ticket($_REQUEST['service_request_id']); if ($ticket->allowsDisplay($this->person)) { $this->template->blocks[] = new Block('open311/requestInfo.inc', array('ticket' => $ticket)); } else { header('HTTP/1.0 403 Forbidden', true, 403); $_SESSION['errorMessages'][] = new \Exception('noAccessAllowed'); } } catch (\Exception $e) { // Unknown ticket header('HTTP/1.0 404 Not Found', true, 404); $_SESSION['errorMessages'][] = $e; return; } } elseif (isset($_POST['service_code'])) { try { $ticket = new Ticket(); $ticket->handleAdd(Open311Client::translatePostArray($_POST)); // Media can only be attached after the ticket is saved // It uses the issue_id in the directory structure if (isset($_FILES['media'])) { $issue = $ticket->getIssue(); try { $media = new Media(); $media->setIssue($issue); $media->setFile($_FILES['media']); $media->save(); } catch (\Exception $e) { // Just ignore any media errors for now } } $this->template->blocks[] = new Block('open311/requestInfo.inc', array('ticket' => $ticket)); } catch (\Exception $e) { $_SESSION['errorMessages'][] = $e; switch ($e->getMessage()) { case 'clients/unknownClient': header('HTTP/1.0 403 Forbidden', true, 403); break; default: header('HTTP/1.0 400 Bad Request', true, 400); } } } else { $search = array(); if (isset($category)) { if ($category->allowsDisplay($this->person)) { $search['category_id'] = $category->getId(); } else { header('HTTP/1.0 404 Not Found', true, 404); $_SESSION['errorMessages'][] = new \Exception('categories/unknownCategory'); return; } } if (!empty($_REQUEST['start_date'])) { $search['start_date'] = $_REQUEST['start_date']; } if (!empty($_REQUEST['end_date'])) { $search['end_date'] = $_REQUEST['end_date']; } if (!empty($_REQUEST['status'])) { $search['status'] = $_REQUEST['status']; } if (!empty($_REQUEST['updated_before'])) { $search['lastModified_before'] = $_REQUEST['updated_before']; } if (!empty($_REQUEST['updated_after'])) { $search['lastModified_after'] = $_REQUEST['updated_after']; } if (!empty($_REQUEST['bbox'])) { $search['bbox'] = $_REQUEST['bbox']; } $pageSize = 1000; if (!empty($_REQUEST['page_size'])) { $p = (int) $_REQUEST['page_size']; if ($p) { $pageSize = $p; } } // Pagination pages are one-based and will treat page=0 // as exactly the same as page=1 $page = 0; if (!empty($_REQUEST['page'])) { $p = (int) $_REQUEST['page']; if ($p) { $page = $p; } } $table = new TicketTable(); $tickets = $table->find($search, null, true); $tickets->setCurrentPageNumber($page); $tickets->setItemCountPerPage($pageSize); $this->template->blocks[] = new Block('open311/requestList.inc', array('ticketList' => $tickets)); if ($this->template->outputFormat == 'html') { $this->template->blocks[] = new Block('pageNavigation.inc', ['paginator' => $tickets]); } } }
/** * @param Ticket $ticket */ private function addStandardInfoBlocks(Ticket $ticket) { $this->template->blocks['history-panel'][] = new Block('tickets/history.inc', array('history' => $ticket->getHistory())); $this->template->blocks['issue-panel'][] = new Block('tickets/issueList.inc', array('issueList' => $ticket->getIssues(), 'ticket' => $ticket, 'disableButtons' => $ticket->getStatus() == 'closed')); if ($ticket->getLocation()) { $locationBlocks = array('locationInfo', 'masterAddressData', 'locationPeople'); foreach ($locationBlocks as $b) { $this->template->blocks['bottom-left'][] = new Block("locations/{$b}.inc", array('location' => $ticket->getLocation(), 'disableButtons' => true)); } $this->template->blocks['bottom-right'][] = new Block('tickets/ticketLocationInfo.inc', array('ticket' => $ticket)); $table = new TicketTable(); $list = $table->find(array('location' => $ticket->getLocation())); if (count($list) > 1) { $this->template->blocks['bottom-left'][] = new Block('tickets/ticketList.inc', array('ticketList' => $list, 'title' => 'Other cases for this location', 'filterTicket' => $ticket, 'disableButtons' => true)); } } }
/** * @param Ticket $ticket */ private function addLocationInfoBlocks(Ticket $ticket) { if ($ticket->getLocation()) { $this->template->blocks['bottom-left'][] = new Block('locations/locationInfo.inc', array('location' => $ticket->getLocation(), 'disableButtons' => true)); $table = new TicketTable(); $this->template->blocks['bottom-right'][] = new Block('tickets/ticketList.inc', array('ticketList' => $table->find(['location' => $ticket->getLocation()]), 'title' => 'Other tickets for this location', 'disableButtons' => true, 'filterTicket' => $ticket)); } }
/** * @param string $personField The field in Ticket that has this person embedded * @param array $fields Additional fields to filter the ticketList * @return TicketList */ public function getTickets($personFieldname, $fields = null) { if ($this->getId()) { $field = $personFieldname . 'Person_id'; if (is_array($fields)) { $search = $fields; $search[$field] = $this->getId(); } else { $search = array($field => $this->getId()); } $table = new TicketTable(); return $table->find($search); } }