コード例 #1
0
 public function testCreateSearchDelete()
 {
     $comment = new TicketComment();
     $comment->setBody('TEST Ticket By David Lin');
     $ticket = new Ticket();
     $ticket->setComment($comment);
     $ticket->setSubject('Test Ticket Subject By David Lin 1');
     $ticket->setTags(array('test'));
     $this->client->save($ticket);
     $ticket = new Ticket();
     $ticket->setComment($comment);
     $ticket->setSubject('Test Ticket Subject By David Lin 2');
     $ticket->setTags(array('test'));
     $this->client->save($ticket);
     $ticket = new Ticket();
     $ticket->setComment($comment);
     $ticket->setSubject('Test Ticket Subject By David Lin 3');
     $ticket->setTags(array('test'));
     $this->client->save($ticket);
     sleep(5);
     //need to wait otherwise not searchable
     $filter = new TicketFilter();
     $filter->setSubject('Test David Lin');
     $searchResult = $this->client->search($filter);
     $count = $searchResult->getCount();
     $this->assertGreaterThanOrEqual(3, $count);
     //delete one
     $item = $searchResult->getItems();
     $this->client->delete($item[0]);
     $searchResult = $this->client->search($filter);
     $newCount = $searchResult->getCount();
     $this->assertEquals(--$count, $newCount);
     $this->client->deleteTickets($searchResult->getItems());
     $this->assertEquals(0, $this->client->search($filter)->getCount());
 }
コード例 #2
0
 public function newAction(Request $request)
 {
     $form = $this->createFormBuilder()->add('mail', 'email', array('constraints' => array(new NotBlank(), new Email())))->add('subject', 'text', array('constraints' => array(new NotBlank())))->add('description', 'textarea', array('constraints' => array(new NotBlank())))->add('submit', 'submit')->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $api = $this->get('dlin.zendesk')->getApi();
         $ticketComment = new TicketComment();
         $ticketComment->setBody($form->get('description')->getData());
         $ticket = new Ticket();
         $ticket->setSubject($form->get('subject')->getData());
         $ticket->setComment($ticketComment);
         $ticketRequester = new TicketRequester();
         $ticketRequester->setEmail($form->get('mail')->getData());
         $ticketRequester->setName($form->get('mail')->getData());
         $ticketClient = new TicketClient($api);
         $result = $ticketClient->save($ticket, $ticketRequester);
         $this->addFlash('notice', 'Votre demande a bien été envoyée !');
         return $this->redirect($this->generateUrl('home'));
     }
     return $this->render('DlinZendeskBundle:Request:request_new.html.twig', array('form' => $form->createView()));
 }