Exemplo n.º 1
0
 public function testLatLngShouldNotAllowZeros()
 {
     $ticket = new Ticket();
     $ticket->handleAdd(array('description' => 'Testing', 'category_id' => $this->testCategoryId, 'latitude' => 0, 'longitude' => 0));
     $id = $ticket->getId();
     $zend_db = Database::getConnection();
     $result = $zend_db->query('select latitude,longitude from tickets where id=?')->execute([$id]);
     $row = $result->current();
     $this->assertNull($row['latitude']);
     $this->assertNull($row['longitude']);
 }
Exemplo n.º 2
0
 /**
  * @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]);
         }
     }
 }
 /**
  *
  */
 public function add()
 {
     $ticket = new Ticket();
     $issue = new Issue();
     // Categories are required before starting the process
     // Handle any Category choice passed in
     if (!empty($_REQUEST['category_id'])) {
         $category = new Category($_REQUEST['category_id']);
         if ($category->allowsPosting($_SESSION['USER'])) {
             $ticket->setCategory($category);
         } else {
             $_SESSION['errorMessages'][] = new \Exception('noAccessAllowed');
             header('Location: ' . BASE_URL);
             exit;
         }
     }
     // Handle any Location choice passed in
     if (!empty($_GET['location'])) {
         $ticket->setLocation($_GET['location']);
         $ticket->setAddressServiceData(AddressService::getLocationData($ticket->getLocation()));
     }
     // Handle any Person choice passed in
     if (!empty($_REQUEST['reportedByPerson_id'])) {
         $issue->setReportedByPerson_id($_REQUEST['reportedByPerson_id']);
     }
     // Handle any Department choice passed in
     // Choosing a department here will cause the assignment form
     // to pre-select that department's defaultPerson
     $currentDepartment = null;
     if (isset($_GET['department_id'])) {
         try {
             $currentDepartment = new Department($_GET['department_id']);
         } catch (\Exception $e) {
             // Ignore any bad departments passed in
         }
     }
     // If they haven't chosen a department, start by assigning
     // the ticket to the current User, and use the current user's department
     if (!isset($currentDepartment)) {
         $ticket->setAssignedPerson($_SESSION['USER']);
         if ($_SESSION['USER']->getDepartment()) {
             $currentDepartment = $_SESSION['USER']->getDepartment();
         }
     }
     // Process the ticket form when it's posted
     if (isset($_POST['category_id'])) {
         try {
             $ticket->handleAdd($_POST);
             // Calls save as needed - no need to save() again
             $this->redirectToTicketView($ticket);
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
         }
     }
     // Display all the forms
     $this->template->setFilename('ticketCreation');
     $this->template->blocks['right-top'][] = new Block('tickets/chooseLocation.inc', array('ticket' => $ticket));
     $this->template->blocks['right-bottom'][] = new Block('tickets/chooseReportedByPerson.inc', array('issue' => $issue));
     $this->template->blocks['left'][] = new Block('tickets/addTicketForm.inc', array('ticket' => $ticket, 'issue' => $issue, 'currentDepartment' => $currentDepartment));
 }