/** * {@inheritDoc} */ public function getThemePath() { $issue = $this->issueService->getIssue(); if (!$issue) { return; } $languageId = $issue->getLanguageId(); $publication = $this->publicationService->getPublication(); $cacheKeyThemePath = $this->cacheService->getCacheKey(array('getThemePath', $languageId, $publication->getId(), $issue->getNumber()), 'issue'); $themePath = null; $webOutput = null; $outSetIssues = null; if ($this->cacheService->contains($cacheKeyThemePath)) { $themePath = $this->cacheService->fetch($cacheKeyThemePath); } else { $cacheKeyWebOutput = $this->cacheService->getCacheKey(array('OutputService', 'Web'), 'outputservice'); if ($this->cacheService->contains($cacheKeyWebOutput)) { $webOutput = $this->cacheService->fetch($cacheKeyWebOutput); } else { $webOutput = $this->findByName('Web'); $this->cacheService->save($cacheKeyWebOutput, $webOutput); } $outSetIssues = $this->findByIssueAndOutput($issue->getId(), $webOutput); if (!is_null($outSetIssues)) { $themePath = $outSetIssues->getThemePath()->getPath(); } $this->cacheService->save($cacheKeyThemePath, $themePath); } return $themePath; }
/** * Paginate target and fill list items * * @param mixed $target * @param int $pageNumber * @param int $maxResults * @param ListResult $list * @param boolean $useCache * * @return ListResult */ protected function paginateList($target, $pageNumber, $maxResults, $list = null, $useCache = true) { if (!$list) { $list = new ListResult(); } if (!$pageNumber) { $pageNumber = $this->pageNumber; } $cacheId = $this->cacheService->getCacheKey(array($this->getCacheKey(), $this->getPageNumber()), $this->getName()); if ($this->cacheService->contains($cacheId) && $useCache) { $this->pagination = $this->cacheService->fetch($cacheId); } else { $this->pagination = $this->paginatorService->paginate($target, $pageNumber, $maxResults); $this->cacheService->save($cacheId, $this->pagination); } $list->count = count($this->pagination->getItems()); $list->items = $this->pagination->getItems(); return $list; }
/** * {@inheritDoc} */ public function getLatestPublishedIssue() { $publication = $this->publicationService->getPublication(); if (!$publication) { return; } $publicationId = $publication->getId(); $cacheKey = $this->cacheService->getCacheKey(array('latest_published', $publicationId), 'issue'); if ($this->cacheService->contains($cacheKey)) { $issue = $this->cacheService->fetch($cacheKey); } else { $issue = $this->em->getRepository('Newscoop\\Entity\\Issue')->getLastPublishedByPublication($publicationId)->getArrayResult(); $this->cacheService->save($cacheKey, $issue); } if (empty($issue)) { return; } $latestPublishedIssue = $this->em->getReference('Newscoop\\Entity\\Issue', $issue[0]['id']); $this->setIssue($latestPublishedIssue); return $latestPublishedIssue; }
/** * Resolve publication from provided data * * @param Request $request Request object * * @return Publication $publication Publication entity object */ public function publicationResolver(Request $request) { /** * By default try get publication alias from requested http_host */ $publication = $request->server->get('HTTP_HOST'); $this->publicationMetadata['source'] = 'request_http_host'; /** * If in request GET or POST params exists 'publication' use it. */ if ($request->query->has('__publication_alias_name') || $request->request->has('__publication_alias_name')) { $publication = $request->get('__publication_alias_name'); $this->publicationMetadata['source'] = 'optional_parameter'; } $cacheKey = $this->cacheService->getCacheKey(array('resolver', $publication, $this->publicationMetadata['source']), 'publication'); $alias = array(); if ($this->cacheService->contains($cacheKey)) { $alias = $this->cacheService->fetch($cacheKey); } else { $qb = $this->em->getRepository('Newscoop\\Entity\\Aliases')->createQueryBuilder('a'); $qb->select('a.id as aliasId', 'p.id as publicationId', 'a.name as alias', 'p.name as publicationName', 'l.id as languageId', 'l.code as languageCode')->leftJoin('a.publication', 'p')->leftJoin('p.language', 'l')->where('a.name = :name')->setParameter('name', $publication); $alias = $qb->getQuery()->getArrayResult(); $this->cacheService->save($cacheKey, $alias); } if (empty($alias)) { return null; } $this->publicationMetadata['alias'] = array('name' => $alias[0]['alias'], 'publication_id' => $alias[0]['publicationId']); $this->publicationMetadata['publication'] = array('name' => $alias[0]['publicationName'], 'id_default_language' => $alias[0]['languageId'], 'code_default_language' => $alias[0]['languageCode']); /** * Save publication metadata to into Request attributes. */ $request->attributes->set('_newscoop_publication_metadata', $this->publicationMetadata); $aliasObject = $this->em->getReference('Newscoop\\Entity\\Aliases', $alias[0]['aliasId']); $publicationObject = $this->em->getReference('Newscoop\\Entity\\Publication', $alias[0]['publicationId']); $this->setPublicationAlias($aliasObject); $this->setPublication($publicationObject); return $publicationObject; }
/** * {@inheritDoc} */ public function issueResolver(Request $request) { $uriParts = explode('/', $request->getRequestUri()); $uriPartsCount = count(array_filter($uriParts)); $issue = null; $publication = $this->publicationService->getPublication(); if ($publication && $uriPartsCount >= 2 && $uriPartsCount <= 5) { $cacheKey = $this->cacheService->getCacheKey(array('resolver', $publication->getId(), $uriParts[1], $uriParts[2]), 'issue'); if ($this->cacheService->contains($cacheKey)) { $issue = $this->cacheService->fetch($cacheKey); } else { $issue = $this->em->getRepository('Newscoop\\Entity\\Issue')->getIssue($uriParts[1], $publication, $uriParts[2])->getOneOrNullResult(); $this->cacheService->save($cacheKey, $issue); } if ($issue) { $this->issueMetadata = array('id' => $issue->getId(), 'number' => $issue->getNumber(), 'name' => $issue->getName(), 'shortName' => $issue->getShortName(), 'code_default_language' => $issue->getLanguage()->getCode(), 'id_default_language' => $issue->getLanguageId()); $request->attributes->set('_newscoop_issue_metadata', $this->issueMetadata); $this->setIssue($issue); return $issue; } } return $this->getLatestPublishedIssue(); }