/** * 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 = LanguageVariantQuery::create(); // sorting $sort = $params->getSort(LanguageVariant::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 = LanguageVariant::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $resource = $resource->with($params->getInclude(['localizations'])); $resource = $resource->fields($params->getFields(['language-variant' => LanguageVariant::getSerializer()->getFields(), 'localization' => Localization::getSerializer()->getFields()])); $document = new Document($resource); return new JsonResponse($document->toArray(), 200); }
/** * @param Request $request * @param Updated $payload */ public function updated(Request $request, Updated $payload) { $params = new Parameters($request->query->all()); $serializer = Localization::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $resource = $resource->with($params->getInclude(['localizations', 'parent', 'language', 'ext-lang', 'script', 'language-variants', 'application-uris'])); $resource = $resource->fields($params->getFields(['localization' => Localization::getSerializer()->getFields(), 'parent' => Localization::getSerializer()->getFields(), 'language' => Language::getSerializer()->getFields(), 'ext-lang' => Language::getSerializer()->getFields(), 'script' => LanguageScript::getSerializer()->getFields(), 'language-variant' => LanguageVariant::getSerializer()->getFields(), 'application-uri' => ApplicationUri::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 = LanguageVariant::getSerializer(); $resource = new Collection($data, $serializer); $resource = $resource->with($params->getInclude(['localizations'])); $resource = $resource->fields($params->getFields(['language-variant' => LanguageVariant::getSerializer()->getFields(), 'localization' => Localization::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()); }
/** * 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->aLocalization) { $this->aLocalization->removeLocalizationVariant($this); } if (null !== $this->aLanguageVariant) { $this->aLanguageVariant->removeLocalizationVariant($this); } $this->localization_id = null; $this->variant_id = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
/** * @param mixed $model * @return Relationship */ public function languageVariants($model) { $method = 'get' . $this->getCollectionMethodPluralName('language-variants'); $relationship = new Relationship(new Collection($model->{$method}(), LanguageVariant::getSerializer())); return $this->addRelationshipSelfLink($relationship, $model, 'language-variant'); }
/** * Exclude object from result * * @param ChildLanguageVariant $languageVariant Object to remove from the list of results * * @return $this|ChildLanguageVariantQuery The current query, for fluid interface */ public function prune($languageVariant = null) { if ($languageVariant) { $this->addUsingAlias(LanguageVariantTableMap::COL_ID, $languageVariant->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Filter the query by a related \keeko\core\model\LanguageVariant object * * @param \keeko\core\model\LanguageVariant|ObjectCollection $languageVariant 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 ChildLocalizationVariantQuery The current query, for fluid interface */ public function filterByLanguageVariant($languageVariant, $comparison = null) { if ($languageVariant instanceof \keeko\core\model\LanguageVariant) { return $this->addUsingAlias(LocalizationVariantTableMap::COL_VARIANT_ID, $languageVariant->getId(), $comparison); } elseif ($languageVariant instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(LocalizationVariantTableMap::COL_VARIANT_ID, $languageVariant->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByLanguageVariant() only accepts arguments of type \\keeko\\core\\model\\LanguageVariant or Collection'); } }