Example #1
0
 /**
  * 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 = RegionTypeQuery::create();
     // sorting
     $sort = $params->getSort(RegionType::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);
 }
Example #3
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Country::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['continent', 'currency', 'type', 'subtype', 'subordinates', 'country', 'subdivisions']));
     $resource = $resource->fields($params->getFields(['country' => Country::getSerializer()->getFields(), 'continent' => Continent::getSerializer()->getFields(), 'currency' => Currency::getSerializer()->getFields(), 'type' => RegionType::getSerializer()->getFields(), 'subtype' => RegionType::getSerializer()->getFields(), 'subordinate' => Country::getSerializer()->getFields(), 'subdivision' => Subdivision::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());
 }
Example #5
0
 /**
  * Filter the query by a related \keeko\core\model\RegionType object
  *
  * @param \keeko\core\model\RegionType|ObjectCollection $regionType the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildRegionAreaQuery The current query, for fluid interface
  */
 public function filterByType($regionType, $comparison = null)
 {
     if ($regionType instanceof \keeko\core\model\RegionType) {
         return $this->addUsingAlias(RegionAreaTableMap::COL_ID, $regionType->getAreaId(), $comparison);
     } elseif ($regionType instanceof ObjectCollection) {
         return $this->useTypeQuery()->filterByPrimaryKeys($regionType->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByType() only accepts arguments of type \\keeko\\core\\model\\RegionType or Collection');
     }
 }
Example #6
0
 /**
  * Filter the query by a related \keeko\core\model\RegionType object
  *
  * @param \keeko\core\model\RegionType|ObjectCollection $regionType 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 ChildCountryQuery The current query, for fluid interface
  */
 public function filterBySubtype($regionType, $comparison = null)
 {
     if ($regionType instanceof \keeko\core\model\RegionType) {
         return $this->addUsingAlias(CountryTableMap::COL_SUBTYPE_ID, $regionType->getId(), $comparison);
     } elseif ($regionType instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(CountryTableMap::COL_SUBTYPE_ID, $regionType->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterBySubtype() only accepts arguments of type \\keeko\\core\\model\\RegionType or Collection');
     }
 }
Example #7
0
 /**
  * Clears the current object, sets all attributes to their default values and removes
  * outgoing references as well as back-references (from other objects to this one. Results probably in a database
  * change of those foreign objects when you call `save` there).
  */
 public function clear()
 {
     if (null !== $this->aCountry) {
         $this->aCountry->removeSubdivision($this);
     }
     if (null !== $this->aType) {
         $this->aType->removeSubdivision($this);
     }
     $this->id = null;
     $this->code = null;
     $this->name = null;
     $this->native_name = null;
     $this->alt_names = null;
     $this->parent_id = null;
     $this->country_id = null;
     $this->type_id = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Example #8
0
 /**
  * @param ChildRegionType $type The ChildRegionType object to add.
  */
 protected function doAddType(ChildRegionType $type)
 {
     $this->collTypes[] = $type;
     $type->setArea($this);
 }
Example #9
0
 /**
  * Exclude object from result
  *
  * @param   ChildRegionType $regionType Object to remove from the list of results
  *
  * @return $this|ChildRegionTypeQuery The current query, for fluid interface
  */
 public function prune($regionType = null)
 {
     if ($regionType) {
         $this->addUsingAlias(RegionTypeTableMap::COL_ID, $regionType->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Example #10
0
 /**
  * Clears the current object, sets all attributes to their default values and removes
  * outgoing references as well as back-references (from other objects to this one. Results probably in a database
  * change of those foreign objects when you call `save` there).
  */
 public function clear()
 {
     if (null !== $this->aContinent) {
         $this->aContinent->removeCountry($this);
     }
     if (null !== $this->aCurrency) {
         $this->aCurrency->removeCountry($this);
     }
     if (null !== $this->aType) {
         $this->aType->removeCountryRelatedByTypeId($this);
     }
     if (null !== $this->aSubtype) {
         $this->aSubtype->removeCountryRelatedBySubtypeId($this);
     }
     if (null !== $this->aCountryRelatedBySovereignityId) {
         $this->aCountryRelatedBySovereignityId->removeSubordinate($this);
     }
     $this->id = null;
     $this->numeric = null;
     $this->alpha_2 = null;
     $this->alpha_3 = null;
     $this->short_name = null;
     $this->ioc = null;
     $this->tld = null;
     $this->phone = null;
     $this->capital = null;
     $this->postal_code_format = null;
     $this->postal_code_regex = null;
     $this->continent_id = null;
     $this->currency_id = null;
     $this->type_id = null;
     $this->subtype_id = null;
     $this->sovereignity_id = null;
     $this->formal_name = null;
     $this->formal_native_name = null;
     $this->short_native_name = null;
     $this->bbox_sw_lat = null;
     $this->bbox_sw_lng = null;
     $this->bbox_ne_lat = null;
     $this->bbox_ne_lng = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }