コード例 #1
0
ファイル: LanguageDomainTrait.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 = LanguageQuery::create();
     // sorting
     $sort = $params->getSort(Language::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 = LanguageScope::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['languages']));
     $resource = $resource->fields($params->getFields(['language-scope' => LanguageScope::getSerializer()->getFields(), 'language' => Language::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
コード例 #3
0
 /**
  * @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);
 }
コード例 #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 = LanguageScope::getSerializer();
     $resource = new Collection($data, $serializer);
     $resource = $resource->with($params->getInclude(['languages']));
     $resource = $resource->fields($params->getFields(['language-scope' => LanguageScope::getSerializer()->getFields(), 'language' => Language::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
 /**
  * @param mixed $model
  * @return Relationship
  */
 public function language($model)
 {
     $serializer = Language::getSerializer();
     $id = $serializer->getId($model->getLanguage());
     if ($id !== null) {
         $relationship = new Relationship(new Resource($model->getLanguage(), $serializer));
         $relationship->setLinks(['related' => '%apiurl%' . $serializer->getType(null) . '/' . $id]);
         return $this->addRelationshipSelfLink($relationship, $model, 'language');
     }
     return null;
 }
コード例 #6
0
ファイル: LanguageScopeQuery.php プロジェクト: keeko/core
 /**
  * Filter the query by a related \keeko\core\model\Language object
  *
  * @param \keeko\core\model\Language|ObjectCollection $language the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildLanguageScopeQuery The current query, for fluid interface
  */
 public function filterByLanguage($language, $comparison = null)
 {
     if ($language instanceof \keeko\core\model\Language) {
         return $this->addUsingAlias(LanguageScopeTableMap::COL_ID, $language->getScopeId(), $comparison);
     } elseif ($language instanceof ObjectCollection) {
         return $this->useLanguageQuery()->filterByPrimaryKeys($language->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByLanguage() only accepts arguments of type \\keeko\\core\\model\\Language or Collection');
     }
 }
コード例 #7
0
ファイル: LanguageFamily.php プロジェクト: keeko/core
 /**
  * @param ChildLanguage $language The ChildLanguage object to add.
  */
 protected function doAddLanguage(ChildLanguage $language)
 {
     $this->collLanguages[] = $language;
     $language->setFamily($this);
 }
コード例 #8
0
ファイル: Localization.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->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);
 }
コード例 #9
0
ファイル: Language.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->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);
 }
コード例 #10
0
ファイル: LanguageQuery.php プロジェクト: keeko/core
 /**
  * Exclude object from result
  *
  * @param   ChildLanguage $language Object to remove from the list of results
  *
  * @return $this|ChildLanguageQuery The current query, for fluid interface
  */
 public function prune($language = null)
 {
     if ($language) {
         $this->addUsingAlias(LanguageTableMap::COL_ID, $language->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
コード例 #11
0
ファイル: LocalizationQuery.php プロジェクト: keeko/core
 /**
  * Filter the query by a related \keeko\core\model\Language object
  *
  * @param \keeko\core\model\Language|ObjectCollection $language 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 ChildLocalizationQuery The current query, for fluid interface
  */
 public function filterByExtLang($language, $comparison = null)
 {
     if ($language instanceof \keeko\core\model\Language) {
         return $this->addUsingAlias(LocalizationTableMap::COL_EXT_LANGUAGE_ID, $language->getId(), $comparison);
     } elseif ($language instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(LocalizationTableMap::COL_EXT_LANGUAGE_ID, $language->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByExtLang() only accepts arguments of type \\keeko\\core\\model\\Language or Collection');
     }
 }