/**
  * 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 = LanguageScriptQuery::create();
     // sorting
     $sort = $params->getSort(LanguageScript::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 = Language::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['sublanguages', 'parent', 'scope', 'type', 'script', 'family', 'localizations']));
     $resource = $resource->fields($params->getFields(['language' => Language::getSerializer()->getFields(), 'sublanguage' => Language::getSerializer()->getFields(), 'parent' => Language::getSerializer()->getFields(), 'scope' => LanguageScope::getSerializer()->getFields(), 'type' => LanguageType::getSerializer()->getFields(), 'script' => LanguageScript::getSerializer()->getFields(), 'family' => LanguageFamily::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 = Language::getSerializer();
     $resource = new Collection($data, $serializer);
     $resource = $resource->with($params->getInclude(['sublanguages', 'parent', 'scope', 'type', 'script', 'family', 'localizations']));
     $resource = $resource->fields($params->getFields(['language' => Language::getSerializer()->getFields(), 'sublanguage' => Language::getSerializer()->getFields(), 'parent' => Language::getSerializer()->getFields(), 'scope' => LanguageScope::getSerializer()->getFields(), 'type' => LanguageType::getSerializer()->getFields(), 'script' => LanguageScript::getSerializer()->getFields(), 'family' => LanguageFamily::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());
 }
 /**
  * @param mixed $model
  * @return Relationship
  */
 public function script($model)
 {
     $serializer = LanguageScript::getSerializer();
     $id = $serializer->getId($model->getScript());
     if ($id !== null) {
         $relationship = new Relationship(new Resource($model->getScript(), $serializer));
         $relationship->setLinks(['related' => '%apiurl%' . $serializer->getType(null) . '/' . $id]);
         return $this->addRelationshipSelfLink($relationship, $model, 'script');
     }
     return null;
 }
Beispiel #6
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->aParent) {
         $this->aParent->removeLocalizationRelatedById($this);
     }
     if (null !== $this->aLanguage) {
         $this->aLanguage->removeLocalizationRelatedByLanguageId($this);
     }
     if (null !== $this->aExtLang) {
         $this->aExtLang->removeLocalizationRelatedByExtLanguageId($this);
     }
     if (null !== $this->aScript) {
         $this->aScript->removeLocalization($this);
     }
     $this->id = null;
     $this->parent_id = null;
     $this->name = null;
     $this->locale = null;
     $this->language_id = null;
     $this->ext_language_id = null;
     $this->region = null;
     $this->script_id = null;
     $this->is_default = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Beispiel #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->aParent) {
         $this->aParent->removeSublanguage($this);
     }
     if (null !== $this->aScope) {
         $this->aScope->removeLanguage($this);
     }
     if (null !== $this->aType) {
         $this->aType->removeLanguage($this);
     }
     if (null !== $this->aScript) {
         $this->aScript->removeLanguage($this);
     }
     if (null !== $this->aFamily) {
         $this->aFamily->removeLanguage($this);
     }
     $this->id = null;
     $this->alpha_2 = null;
     $this->alpha_3t = null;
     $this->alpha_3b = null;
     $this->alpha_3 = null;
     $this->parent_id = null;
     $this->macrolanguage_status = null;
     $this->name = null;
     $this->native_name = null;
     $this->collate = null;
     $this->subtag = null;
     $this->prefix = null;
     $this->scope_id = null;
     $this->type_id = null;
     $this->family_id = null;
     $this->default_script_id = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Beispiel #8
0
 /**
  * Exclude object from result
  *
  * @param   ChildLanguageScript $languageScript Object to remove from the list of results
  *
  * @return $this|ChildLanguageScriptQuery The current query, for fluid interface
  */
 public function prune($languageScript = null)
 {
     if ($languageScript) {
         $this->addUsingAlias(LanguageScriptTableMap::COL_ID, $languageScript->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Beispiel #9
0
 /**
  * Filter the query by a related \keeko\core\model\LanguageScript object
  *
  * @param \keeko\core\model\LanguageScript|ObjectCollection $languageScript 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 ChildLanguageQuery The current query, for fluid interface
  */
 public function filterByScript($languageScript, $comparison = null)
 {
     if ($languageScript instanceof \keeko\core\model\LanguageScript) {
         return $this->addUsingAlias(LanguageTableMap::COL_DEFAULT_SCRIPT_ID, $languageScript->getId(), $comparison);
     } elseif ($languageScript instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(LanguageTableMap::COL_DEFAULT_SCRIPT_ID, $languageScript->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByScript() only accepts arguments of type \\keeko\\core\\model\\LanguageScript or Collection');
     }
 }