コード例 #1
0
ファイル: CurrencyDomainTrait.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 = CurrencyQuery::create();
     // sorting
     $sort = $params->getSort(Currency::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 = 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);
 }
コード例 #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);
 }
コード例 #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
ファイル: CurrencyQuery.php プロジェクト: keeko/core
 /**
  * Exclude object from result
  *
  * @param   ChildCurrency $currency Object to remove from the list of results
  *
  * @return $this|ChildCurrencyQuery The current query, for fluid interface
  */
 public function prune($currency = null)
 {
     if ($currency) {
         $this->addUsingAlias(CurrencyTableMap::COL_ID, $currency->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
コード例 #6
0
ファイル: CountryQuery.php プロジェクト: keeko/core
 /**
  * Filter the query by a related \keeko\core\model\Currency object
  *
  * @param \keeko\core\model\Currency|ObjectCollection $currency 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 filterByCurrency($currency, $comparison = null)
 {
     if ($currency instanceof \keeko\core\model\Currency) {
         return $this->addUsingAlias(CountryTableMap::COL_CURRENCY_ID, $currency->getId(), $comparison);
     } elseif ($currency instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(CountryTableMap::COL_CURRENCY_ID, $currency->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByCurrency() only accepts arguments of type \\keeko\\core\\model\\Currency or Collection');
     }
 }
コード例 #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);
 }