Exemplo n.º 1
0
 public function add($params)
 {
     $category = new Category();
     $category->setCategoryName($params['category_name'])->setEnabled(1)->setParentId(0);
     $response = $this->save($category);
     return $response;
 }
Exemplo n.º 2
0
 public function testHandleUpdate()
 {
     $data = ['name' => 'Name', 'description' => 'Description', 'postingPermissionLevel' => 'test permission', 'displayPermissionLevel' => 'testing display', 'slaDays' => 2, 'notificationReplyEmail' => 'test@somewhere', 'autoResponseIsActive' => 1, 'autoResponseText' => 'auto response', 'autoCloseIsActive' => 1, 'department_id' => '', 'categoryGroup_id' => '', 'customFields' => '', 'autoCloseSubstatus_id' => ''];
     $category = new Category();
     $category->handleUpdate($data);
     foreach ($data as $f => $value) {
         $get = 'get' . ucfirst($f);
         $this->assertEquals($value, $category->{$get}());
     }
 }
Exemplo n.º 3
0
 public function testSaveCategories()
 {
     $test = new Category('Test Category');
     $another = new Category('Another Category');
     $department = new Department($this->unusedDepartment);
     $department->saveCategories([$test->getId(), $another->getId()]);
     $department = new Department($this->unusedDepartment);
     $categories = $department->getCategories();
     $this->assertEquals(2, count($categories));
     $this->assertTrue(in_array($test->getId(), array_keys($categories)));
     $this->assertTrue(in_array($another->getId(), array_keys($categories)));
     $department->saveActions([]);
     $department = new Department($this->unusedDepartment);
     $categories = $department->getCategories();
     $this->assertEquals(0, count($categories));
 }
Exemplo n.º 4
0
 public function testSave()
 {
     $name = 'Test Category';
     $category = new Category();
     $category->setName($name);
     $category->setCategoryGroup_id($this->testGroupId);
     $category->setDepartment_id($this->testDepartmentId);
     $category->save();
     $this->assertEquals($category->getName(), $name);
     $this->assertEquals($category->getCategoryGroup_id(), $this->testGroupId);
     $this->assertEquals($category->getDepartment_id(), $this->testDepartmentId);
 }
Exemplo n.º 5
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));
 }
Exemplo n.º 7
0
 /**
  * @param Category $category
  * @return bool
  */
 public function hasCategory(Category $category)
 {
     if ($this->getId()) {
         return in_array($category->getId(), array_keys($this->getCategories()));
     }
 }
 /**
  * A form for updating the SLA times for all categories at once
  */
 public function sla()
 {
     $this->template->setFilename('backend');
     if (isset($_POST['categories'])) {
         try {
             foreach ($_POST['categories'] as $id => $post) {
                 $category = new Category($id);
                 $category->setSlaDays($post['slaDays']);
                 $category->save();
             }
             header('Location: ' . BASE_URL . '/categories');
             exit;
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
         }
     }
     $t = new CategoryTable();
     $list = $t->find();
     $this->template->blocks[] = new Block('categories/slaForm.inc', ['categoryList' => $list]);
 }