예제 #1
0
 /**
  * @param REQUEST issue_id
  */
 public function respond()
 {
     // Load the issue
     try {
         $issue = new Issue($_REQUEST['issue_id']);
         $ticket = $issue->getTicket();
     } catch (\Exception $e) {
         $_SESSION['errorMessages'][] = $e;
         header('Location: ' . BASE_URL . '/tickets');
         exit;
     }
     // Handle what the user posts
     if (isset($_POST['contactMethod_id'])) {
         $r = new Response();
         $r->handleUpdate($_POST);
         try {
             $r->save();
             header('Location: ' . $ticket->getURL());
             exit;
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
         }
     }
     // Display the view
     $this->template->setFilename('tickets');
     $this->template->blocks['ticket-panel'][] = new Block('tickets/ticketInfo.inc', array('ticket' => $ticket));
     $this->template->blocks['history-panel'][] = new Block('tickets/history.inc', array('history' => $ticket->getHistory()));
     $this->template->blocks['issue-panel'][] = new Block('tickets/responseForm.inc', array('issue' => $issue));
     $this->addLocationInfoBlocks($ticket);
 }
 /**
  *
  */
 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));
 }
예제 #3
0
 /**
  * Does all the database work for TicketController::add
  *
  * Saves the ticket, the issue, and creates history entries
  * for the open and assignment actions.
  *
  * This function calls save() as needed.  After using this function,
  * there's no need to make an additional save() call.
  *
  * @param array $post
  */
 public function handleAdd($post)
 {
     $zend_db = Database::getConnection();
     $zend_db->getDriver()->getConnection()->beginTransaction();
     try {
         $this->handleUpdate($post);
         // We must add an issue to the ticket for validation to pass
         $issue = new Issue();
         $issue->handleUpdate($post);
         $this->issues = array($issue);
         if (!$this->getEnteredByPerson_id() && $issue->getReportedByPerson_id()) {
             $this->setEnteredByPerson_id($issue->getReportedByPerson_id());
         }
         $this->save();
         $issue->setTicket($this);
         $issue->save();
         // Create the entry in the history log
         $history = new TicketHistory();
         $history->setTicket($this);
         $history->setAction(new Action('open'));
         if ($this->getEnteredByPerson_id()) {
             $history->setEnteredByPerson_id($this->getEnteredByPerson_id());
         }
         $history->save();
         $history = new TicketHistory();
         $history->setTicket($this);
         $history->setAction(new Action('assignment'));
         $history->setActionPerson_id($this->getAssignedPerson_id());
         if (!empty($post['notes'])) {
             $history->setNotes($post['notes']);
         }
         if ($this->getEnteredByPerson_id()) {
             $history->setEnteredByPerson_id($this->getEnteredByPerson_id());
         }
         $history->save();
         $this->getCategory()->onTicketAdd($this);
     } catch (\Exception $e) {
         $zend_db->getDriver()->getConnection()->rollback();
         $search = new Search();
         $search->delete($this);
         $search->solrClient->commit();
         throw $e;
     }
     $zend_db->getDriver()->getConnection()->commit();
     $history->sendNotification($this);
 }