Skip to content

Commit

Permalink
get children snapshot order by position
Browse files Browse the repository at this point in the history
  • Loading branch information
Charley Maillot committed Aug 31, 2011
1 parent dc68072 commit 4de6298
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Entity/SnapshotManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public function load(SnapshotInterface $snapshot)
$page->setName($content['name']);
$page->setSlug($content['slug']);
$page->setTemplateCode($content['template_code']);
$page->setRequestMethod($content['request_method']);

$createdAt = new \DateTime;
$createdAt->setTimestamp($content['created_at']);
Expand Down Expand Up @@ -254,6 +255,7 @@ public function create(PageInterface $page)
$content['meta_description'] = $page->getMetaDescription();
$content['meta_keyword'] = $page->getMetaKeyword();
$content['template_code'] = $page->getTemplateCode();
$content['request_method'] = $page->getRequestMethod();
$content['created_at'] = $page->getCreatedAt()->format('U');
$content['updated_at'] = $page->getUpdatedAt()->format('U');
$content['slug'] = $page->getSlug();
Expand Down Expand Up @@ -297,7 +299,7 @@ public function createBlocks(BlockInterface $block)
* return a page with the given routeName
*
* @param string $routeName
* @return PageInterface|false
* @return \Sonata\PageBundle\Model\PageInterface|false
*/
public function getPageByName($routeName)
{
Expand All @@ -320,6 +322,12 @@ public function getPageByName($routeName)
return false;
}

/**
* Get snapshot
*
* @param integer $pageId
* @return \Sonata\PageBundle\Model\SnapshotInterface
*/
public function getSnapshotByPageId($pageId)
{
if (!$pageId) {
Expand Down Expand Up @@ -351,6 +359,8 @@ public function getSnapshotByPageId($pageId)
}

/**
* Get page by id
*
* @param integer $id
* @return \Sonata\PageBundle\Model\PageInterface
*/
Expand All @@ -361,6 +371,12 @@ public function getPageById($id)
return $snapshot ? new SnapshotPageProxy($this, $snapshot) : null;
}

/**
* Get children
*
* @param \Sonata\PageBundle\Model\PageInterface $parent
* @return Collection
*/
public function getChildren(PageInterface $parent)
{
if (!isset($this->children[$parent->getId()])) {
Expand All @@ -376,11 +392,13 @@ public function getChildren(PageInterface $parent)
->from('Application\Sonata\PageBundle\Entity\Snapshot', 's')
->where('s.parentId = :parentId and s.enabled = 1')
->andWhere('s.publicationDateStart <= :publicationDateStart AND ( s.publicationDateEnd IS NULL OR s.publicationDateEnd >= :publicationDateEnd )')
->orderBy('s.position')
->setParameters($parameters)
->getQuery()
->execute();

$pages = array();

foreach ($snapshots as $snapshot) {
$page = new SnapshotPageProxy($this, $snapshot);
$pages[$page->getId()] = $page;
Expand All @@ -405,7 +423,7 @@ public function getTemplates()
public function getTemplate($code)
{
if (!isset($this->templates[$code])) {
throw new \RunTimeException(sprintf('No template references whith the code : %s', $code));
throw new \RunTimeException(sprintf('No template references with the code : %s', $code));
}

return $this->templates[$code];
Expand Down

0 comments on commit 4de6298

Please sign in to comment.