/** * Load meta object by provided type and parameters. * * @MetaLoaderDoc( * description="Article Media Loader loads article media from Content Repository", * parameters={ * article="COLLECTION| article Meta object" * } * ) * * @param string $type object type * @param array $parameters parameters needed to load required object type * @param int $responseType response type: collection of meta (LoaderInterface::COLLECTION) * * @return Meta[]|bool false if meta cannot be loaded, an array with Meta instances otherwise */ public function load($type, $parameters = [], $responseType = LoaderInterface::COLLECTION) { if ($responseType === LoaderInterface::COLLECTION) { $criteria = new Criteria(); if (array_key_exists('article', $parameters) && $parameters['article'] instanceof Meta) { $criteria->set('article', $parameters['article']->getValues()); } elseif (isset($this->context->article) && null !== $this->context->article) { $criteria->set('article', $this->context->article->getValues()); } else { return false; } $criteria = $this->applyPaginationToCriteria($criteria, $parameters); $media = $this->articleMediaProvider->getManyByCriteria($criteria); if ($media->count() > 0) { $metaCollection = new MetaCollection(); $metaCollection->setTotalItemsCount($this->articleMediaProvider->getCountByCriteria($criteria)); foreach ($media as $item) { $metaCollection->add($this->metaFactory->create($item)); } return $metaCollection; } } return false; }
/** * Load meta object by provided type and parameters. * * @MetaLoaderDoc( * description="Article Loader loads articles from Content Repository", * parameters={ * contentPath="SINGLE|required content path", * slug="SINGLE|required content slug", * pageName="COLLECTiON|name of Page for required articles" * } * ) * * @param string $type object type * @param array $parameters parameters needed to load required object type * @param int $responseType response type: single meta (LoaderInterface::SINGLE) or collection of metas (LoaderInterface::COLLECTION) * * @return Meta|Meta[]|bool false if meta cannot be loaded, a Meta instance otherwise * * @throws \Exception */ public function load($type, $parameters = [], $responseType = LoaderInterface::SINGLE) { $criteria = new Criteria(); if ($responseType === LoaderInterface::SINGLE) { if (array_key_exists('article', $parameters) && $parameters['article'] instanceof ArticleInterface) { $this->dm->detach($parameters['article']); $criteria->set('id', $parameters['article']->getId()); } elseif (array_key_exists('slug', $parameters)) { $criteria->set('slug', $parameters['slug']); } try { return $this->getArticleMeta($this->articleProvider->getOneByCriteria($criteria)); } catch (NotFoundHttpException $e) { return; } } elseif ($responseType === LoaderInterface::COLLECTION) { $currentPage = $this->context->getCurrentPage(); $route = null; if (null !== $currentPage) { $route = $currentPage->getValues(); } if (array_key_exists('route', $parameters)) { if (null === $route || $route instanceof RouteInterface && $route->getId() !== $parameters['route']) { if (is_int($parameters['route'])) { $route = $this->routeProvider->getOneById($parameters['route']); } elseif (is_string($parameters['route'])) { $route = $this->routeProvider->getOneByStaticPrefix($parameters['route']); } } } if ($route instanceof RouteInterface) { $criteria->set('route', $route); } else { return; } $criteria = $this->applyPaginationToCriteria($criteria, $parameters); $articles = $this->articleProvider->getManyByCriteria($criteria); if ($articles->count() > 0) { $metaCollection = new MetaCollection(); $metaCollection->setTotalItemsCount($this->articleProvider->getCountByCriteria($criteria)); foreach ($articles as $article) { $articleMeta = $this->getArticleMeta($article); if (null !== $articleMeta) { $metaCollection->add($articleMeta); } } unset($articles, $route, $criteria); return $metaCollection; } } return; }