public function testSaveAndDelete() { copy($this->origFile, $this->testFile); $media = new Media(); $media->setIssue_id($this->testIssueId); $media->setFile($this->FILE); $media->save(); $newFile = SITE_HOME . "/media/{$media->getDirectory()}/{$media->getInternalFilename()}"; $this->assertTrue(file_exists($newFile)); $this->assertEquals($this->testIssueId, $media->getIssue_id()); $this->assertNotEmpty($media->getId()); $media->delete(); $this->assertFalse(file_exists($newFile)); }
/** * @param POST issue_id * @param FILES attachment */ public function upload() { $issue = $this->loadIssue($_REQUEST['issue_id']); $ticket = $issue->getTicket(); if (isset($_FILES['attachment'])) { try { $media = new Media(); $media->setIssue($issue); $media->setFile($_FILES['attachment']); $media->save(); } catch (\Exception $e) { // Clean out any file that might have been saved $media->delete(); $_SESSION['errorMessages'][] = $e; } header('Location: ' . $ticket->getURL()); exit; } $this->template->setFilename('tickets'); $this->template->blocks['ticket-panel'][] = new Block('tickets/ticketInfo.inc', array('ticket' => $ticket, 'disableButtons' => 1)); $this->template->blocks['history-panel'][] = new Block('tickets/history.inc', array('history' => $ticket->getHistory())); $this->template->blocks['issue-panel'][] = new Block('media/uploadForm.inc', array('issue' => $issue)); $this->template->blocks['issue-panel'][] = new Block('tickets/issueInfo.inc', array('issue' => $issue, 'disableButtons' => 1)); }
/** * @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]); } } }