/** * Returns a paginated result * * @param Parameters $params * @return PayloadInterface */ public function paginate(Parameters $params) { $sysPrefs = $this->getServiceContainer()->getPreferenceLoader()->getSystemPreferences(); $defaultSize = $sysPrefs->getPaginationSize(); $page = $params->getPage('number'); $size = $params->getPage('size', $defaultSize); $query = RegionAreaQuery::create(); // sorting $sort = $params->getSort(RegionArea::getSerializer()->getSortFields()); foreach ($sort as $field => $order) { $method = 'orderBy' . NameUtils::toStudlyCase($field); $query->{$method}($order); } // filtering $filter = $params->getFilter(); if (!empty($filter)) { $this->applyFilter($query, $filter); } // paginate if ($size == -1) { $model = $query->findAll(); } else { $model = $query->paginate($page, $size); } // run response return new Found(['model' => $model]); }
/** * @param Request $request * @param Found $payload */ public function found(Request $request, Found $payload) { $params = new Parameters($request->query->all()); $serializer = RegionArea::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $resource = $resource->with($params->getInclude(['types'])); $resource = $resource->fields($params->getFields(['region-area' => RegionArea::getSerializer()->getFields(), 'type' => RegionType::getSerializer()->getFields()])); $document = new Document($resource); return new JsonResponse($document->toArray(), 200); }
/** * @param Request $request * @param Found $payload */ public function found(Request $request, Found $payload) { $params = new Parameters($request->query->all()); $data = $payload->getModel(); $serializer = RegionArea::getSerializer(); $resource = new Collection($data, $serializer); $resource = $resource->with($params->getInclude(['types'])); $resource = $resource->fields($params->getFields(['region-area' => RegionArea::getSerializer()->getFields(), 'type' => RegionType::getSerializer()->getFields()])); $document = new Document($resource); // meta if ($params->getPage('size') != -1) { $document->setMeta(['total' => $data->getNbResults(), 'first' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getFirstPage()]]), 'next' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getNextPage()]]), 'previous' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getPreviousPage()]]), 'last' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getLastPage()]])]); } // return response return new JsonResponse($document->toArray()); }
/** * Exclude object from result * * @param ChildRegionArea $regionArea Object to remove from the list of results * * @return $this|ChildRegionAreaQuery The current query, for fluid interface */ public function prune($regionArea = null) { if ($regionArea) { $this->addUsingAlias(RegionAreaTableMap::COL_ID, $regionArea->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Filter the query by a related \keeko\core\model\RegionArea object * * @param \keeko\core\model\RegionArea|ObjectCollection $regionArea The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @throws \Propel\Runtime\Exception\PropelException * * @return ChildRegionTypeQuery The current query, for fluid interface */ public function filterByArea($regionArea, $comparison = null) { if ($regionArea instanceof \keeko\core\model\RegionArea) { return $this->addUsingAlias(RegionTypeTableMap::COL_AREA_ID, $regionArea->getId(), $comparison); } elseif ($regionArea instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(RegionTypeTableMap::COL_AREA_ID, $regionArea->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByArea() only accepts arguments of type \\keeko\\core\\model\\RegionArea or Collection'); } }