Skip to content

Commit

Permalink
Probable fix for multi theme handling per issue and language
Browse files Browse the repository at this point in the history
  • Loading branch information
m038 committed Jun 25, 2015
1 parent ad20e7c commit d714d20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,16 @@ public function getIssue($languageCode, $publication, $shortName = null)
return $qb->getQuery();
}

public function getLastPublishedByPublication($publicationId)
public function getLastPublishedByPublicationAndLanguage($publicationId, $languageId)
{
$query = $this->createQueryBuilder('i')
->select('i.id')
->select('i')
->where('i.publication = :publicationId')
->andWhere('i.workflowStatus = :publishStatus')
->andWhere('i.language = :languageId')
->setParameter('publicationId', $publicationId)
->setParameter('publishStatus', \Newscoop\Entity\Issue::STATUS_PUBLISHED)
->setParameter('languageId', $languageId)
->setMaxResults(1)
->orderBy('i.id', 'DESC');

Expand Down
20 changes: 13 additions & 7 deletions newscoop/library/Newscoop/Services/IssueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,43 +136,49 @@ public function issueResolver(Request $request)
}
}

// TODO: Check if we should add locale from request here
return $this->getLatestPublishedIssue();
}

/**
* {@inheritDoc}
*/
public function getLatestPublishedIssue()
public function getLatestPublishedIssue($language = null)
{
$publication = $this->publicationService->getPublication();
if (!$publication) {
return;
}

if (!($language instanceof \Newscoop\Entity\Language)) {
$language = $publication->getDefaultLanguage();
}

$publicationId = $publication->getId();
$languageId = $language->getId();
$cacheKey = $this->cacheService->getCacheKey(array(
'latest_published',
$publicationId,
$languageId,
), 'issue');

if ($this->cacheService->contains($cacheKey)) {
$issue = $this->cacheService->fetch($cacheKey);
} else {
$issue = $this->em
->getRepository('Newscoop\Entity\Issue')
->getLastPublishedByPublication($publicationId)
->getArrayResult();
->getLastPublishedByPublicationAndLanguage($publicationId, $languageId)
->getSingleResult();

$this->cacheService->save($cacheKey, $issue);
}

if (empty($issue)) {
if (!$issue) {
return;
}

$latestPublishedIssue = $this->em->getReference('Newscoop\Entity\Issue', $issue[0]['id']);
$this->setIssue($latestPublishedIssue);
$this->setIssue($issue);

return $latestPublishedIssue;
return $issue;
}
}

0 comments on commit d714d20

Please sign in to comment.