コード例 #1
0
ファイル: ContinentDomainTrait.php プロジェクト: keeko/core
 /**
  * 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 = ContinentQuery::create();
     // sorting
     $sort = $params->getSort(Continent::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]);
 }
コード例 #2
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);
 }
コード例 #3
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = Continent::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['countries']));
     $resource = $resource->fields($params->getFields(['continent' => Continent::getSerializer()->getFields(), 'country' => Country::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #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());
 }
コード例 #5
0
ファイル: CountryQuery.php プロジェクト: keeko/core
 /**
  * Filter the query by a related \keeko\core\model\Continent object
  *
  * @param \keeko\core\model\Continent|ObjectCollection $continent 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 filterByContinent($continent, $comparison = null)
 {
     if ($continent instanceof \keeko\core\model\Continent) {
         return $this->addUsingAlias(CountryTableMap::COL_CONTINENT_ID, $continent->getId(), $comparison);
     } elseif ($continent instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(CountryTableMap::COL_CONTINENT_ID, $continent->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByContinent() only accepts arguments of type \\keeko\\core\\model\\Continent or Collection');
     }
 }
コード例 #6
0
ファイル: ContinentQuery.php プロジェクト: keeko/core
 /**
  * Exclude object from result
  *
  * @param   ChildContinent $continent Object to remove from the list of results
  *
  * @return $this|ChildContinentQuery The current query, for fluid interface
  */
 public function prune($continent = null)
 {
     if ($continent) {
         $this->addUsingAlias(ContinentTableMap::COL_ID, $continent->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
コード例 #7
0
ファイル: Country.php プロジェクト: keeko/core
 /**
  * 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);
 }