/** * Fetch a resource * * @param mixed $ticket_id * @return ApiProblem|TicketEntity */ public function fetch($ticket_id) { $hydrator = new ObjectProperty(); $ticket = new TicketEntity(); $response = $this->client->find($ticket_id); $ticket->exchangeArray($hydrator->extract($response->ticket)); return $ticket; }
/** * Returns a collection of items for a page. * * @param int $offset Page offset * @param int $itemCountPerPage Number of items per page * @return array */ public function getItems($offset, $itemCountPerPage) { $params = ['page' => $offset, 'per_page' => $itemCountPerPage]; $result = $this->client->findAll($params); $this->count = $result->count; if (is_array($result->tickets)) { $hydrator = new ObjectProperty(); $tickets = array_map(function ($ticket) use($hydrator) { $array = $hydrator->extract($ticket); $ticket = new TicketEntity(); $ticket->exchangeArray($array); return $ticket; }, $result->tickets); } else { $tickets = []; } return $tickets; }
public function createAction() { $emailValidator = new EmailAddress(); $m = $this->message(); $priorityList = ['urgent', 'high', 'normal', 'low']; $typeList = ['problem', 'incident', 'question', 'task']; $m->show('[info]What is you subject?[/info]'); $subject = $this->getConsole()->readLine(); $m->show('[info]Type[/info]'); $select = new Select('Which type?', $typeList); $type = $typeList[$select->show()]; $m->show('[info]What is your email?[/info]'); $email = $this->getConsole()->readLine(); $m->show('[info]What is your tags (separated by comma)?[/info]'); $tags = explode(',', $this->getConsole()->readLine()); $tags = array_map('trim', $tags); while (empty($description)) { $m->show('[info]What is your description[/info]'); $description = $this->getConsole()->readLine(); } $m->show('[info]Priority[/info]'); $select = new Select('Which priority?', $priorityList); $priority = $priorityList[$select->show()]; $extra = []; if ($emailValidator->isValid($email)) { $extra['requester'] = $email; } $extra['tags'] = is_array($tags) ? [] : $tags; $extra['priority'] = $priority; $extra['type'] = $type; $e = new Ticket(); $e->setSubject($subject); $e->setDescription($description); $e->setExtraFields($extra); $result = $this->client->create($e->getArrayCopy()); if ($result) { $e->exchangeArray((new ObjectProperty())->extract($result->ticket)); return json_encode($e->getArrayCopy(), JSON_PRETTY_PRINT); } return 0; }