/** * @param ListenerCollection $collection * @return EventCollection */ public function getListeners(ListenerCollection $collection) { /** @var Link $link */ foreach ($collection->getLinks() as $link) { if ($link->rel == 'self') { $self = $link; break; } } if (!isset($self)) { return $collection; } $raw = $this->getJSON($this->baseURL . $self->getUrl()); $collection->setItemTotalCount($raw->itemTotalCount); foreach ($raw->items as $item) { $listener = new Listener(); $listener->id = $item->id; $listener->scope = $item->scope; $listener->url = $item->url; $listener->method = $item->method; $listener->processor = $item->processor; $listener->requestTimeout = $item->requestTimeout; $listener->headers = $item->headers; $listener->async = $item->async; $listener->createdAt = $item->createdAt; $collection->addItem($listener); } return $collection; }
public function getListeners(ListenerCollection $collection) { $params = ['offset' => $collection->getOffset(), 'count' => $collection->getItemPerPage()]; $query = ' SELECT SQL_CALC_FOUND_ROWS l.`id` , l.`method` , l.`scope` , l.`url` , l.`headers` , l.`async` , l.`processor` , l.`retryCount` , l.`requestTimeout` , l.`createdAt` FROM `listener` l WHERE 1=1 '; if ($scope = $collection->getScope()) { $query .= ' AND :scope LIKE l.`scope`'; $params['scope'] = $scope; } if ($id = $collection->getId()) { $query .= ' AND l.`id` = :id'; $params['id'] = $id; } if ($sort = $collection->getSort()) { $query .= sprintf(' ORDER BY `%s` ', $sort); if ($dir = $collection->getDir()) { $query .= ' ' . $dir; } } $query .= ' LIMIT :offset, :count'; $stmt = $this->adapter->prepare($query); $stmt->execute($params); while ($row = $stmt->fetch()) { $collection->addItem(Helper::createListenerFromDTO($row)); } $collection->setItemTotalCount($this->adapter->query('SELECT FOUND_ROWS()')->fetch(PDO::FETCH_COLUMN)); return $collection; }