Ejemplo n.º 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 = CountryQuery::create();
     // sorting
     $sort = $params->getSort(Country::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]);
 }
Ejemplo n.º 2
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Currency::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['countries']));
     $resource = $resource->fields($params->getFields(['currency' => Currency::getSerializer()->getFields(), 'country' => Country::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
Ejemplo n.º 3
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = RegionType::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['countries', 'subdivisions', 'area']));
     $resource = $resource->fields($params->getFields(['region-type' => RegionType::getSerializer()->getFields(), 'country' => Country::getSerializer()->getFields(), 'subdivision' => Subdivision::getSerializer()->getFields(), 'area' => RegionArea::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
Ejemplo n.º 4
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $data = $payload->getModel();
     $serializer = Country::getSerializer();
     $resource = new Collection($data, $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);
     // 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());
 }
Ejemplo n.º 5
0
 /**
  * Filter the query by a related \keeko\core\model\Country object
  *
  * @param \keeko\core\model\Country|ObjectCollection $country the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildCurrencyQuery The current query, for fluid interface
  */
 public function filterByCountry($country, $comparison = null)
 {
     if ($country instanceof \keeko\core\model\Country) {
         return $this->addUsingAlias(CurrencyTableMap::COL_ID, $country->getCurrencyId(), $comparison);
     } elseif ($country instanceof ObjectCollection) {
         return $this->useCountryQuery()->filterByPrimaryKeys($country->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByCountry() only accepts arguments of type \\keeko\\core\\model\\Country or Collection');
     }
 }
Ejemplo n.º 6
0
 /**
  * @param ChildCountry $country The ChildCountry object to add.
  */
 protected function doAddCountry(ChildCountry $country)
 {
     $this->collCountries[] = $country;
     $country->setContinent($this);
 }
Ejemplo n.º 7
0
 /**
  * Exclude object from result
  *
  * @param   ChildCountry $country Object to remove from the list of results
  *
  * @return $this|ChildCountryQuery The current query, for fluid interface
  */
 public function prune($country = null)
 {
     if ($country) {
         $this->addUsingAlias(CountryTableMap::COL_ID, $country->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Ejemplo n.º 8
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);
 }
Ejemplo n.º 9
0
 /**
  * @param ChildCountry $country The ChildCountry object to add.
  */
 protected function doAddCountry(ChildCountry $country)
 {
     $this->collCountries[] = $country;
     $country->setCurrency($this);
 }
Ejemplo n.º 10
0
 /**
  * Filter the query by a related \keeko\core\model\Country object
  *
  * @param \keeko\core\model\Country|ObjectCollection $country 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 ChildSubdivisionQuery The current query, for fluid interface
  */
 public function filterByCountry($country, $comparison = null)
 {
     if ($country instanceof \keeko\core\model\Country) {
         return $this->addUsingAlias(SubdivisionTableMap::COL_COUNTRY_ID, $country->getId(), $comparison);
     } elseif ($country instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(SubdivisionTableMap::COL_COUNTRY_ID, $country->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByCountry() only accepts arguments of type \\keeko\\core\\model\\Country or Collection');
     }
 }
Ejemplo n.º 11
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);
 }