* Sidebar-Widgets: Reisemagazin, Reiseführer, Angebote git-svn-id: http://78.47.251.156/svn/dev/sterntours-3@3301 f459cee4-fb09-11de-96c3-f9c5f16c3c76
133 lines
3.9 KiB
PHP
133 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace AppBundle\Entity;
|
|
|
|
use Gedmo\Tree\Entity\Repository\NestedTreeRepository;
|
|
use Doctrine\ORM\Query\Expr;
|
|
|
|
/**
|
|
* PageRepository
|
|
*
|
|
* This class was generated by the Doctrine ORM. Add your own custom
|
|
* repository methods below.
|
|
*/
|
|
class PageRepository extends NestedTreeRepository
|
|
{
|
|
/**
|
|
* @param Page $page
|
|
* @return Page[]|array
|
|
*
|
|
* @todo Optimize performance by adapting search algorithm's optimizations
|
|
*/
|
|
public function getChildrenWithTravelProgramsAndDates(Page $page)
|
|
{
|
|
$pages = $this->getChildrenQueryBuilder($page)
|
|
->leftJoin('node.travelProgram', 'tp')
|
|
->addSelect('tp')
|
|
->andWhere('tp.status > 0')
|
|
->andWhere('node.status > 0')
|
|
->orderBy('node.order')
|
|
->addOrderBy('tp.position')
|
|
->addOrderBy('node.title')
|
|
->getQuery()
|
|
->execute();
|
|
/** @var Page $childPage */
|
|
foreach ($pages as &$childPage)
|
|
{
|
|
if ($childPage->getTravelProgram())
|
|
{
|
|
$this->getEntityManager()->getRepository('AppBundle:TravelPeriod')->getTrueTravelPeriods(
|
|
$childPage->getTravelProgram());
|
|
}
|
|
}
|
|
return $pages;
|
|
}
|
|
|
|
public function findWithTravelProgramsOfCountry(TravelCountry $country)
|
|
{
|
|
return $this->createQueryBuilder('node')
|
|
->innerJoin('node.travelProgram', 'tp')
|
|
->innerJoin('tp.countries', 'c')
|
|
->where('c.id = '. $country->getId())
|
|
->getQuery()
|
|
->execute()
|
|
;
|
|
}
|
|
|
|
/**
|
|
* @return Page[]
|
|
*/
|
|
public function findOffers()
|
|
{
|
|
$ret = [];
|
|
$countries = $this->getEntityManager()->getRepository('AppBundle:TravelCountry')->findAll();
|
|
foreach ($countries as $country)
|
|
{
|
|
$ret = array_merge($ret, $this->createQueryBuilder('node')
|
|
->innerJoin('node.travelProgram', 'tp')
|
|
->addSelect('tp')
|
|
->innerJoin('tp.countries', 'c')
|
|
->where('c.id = '. $country->getId())
|
|
->andWhere('node.status > 0')
|
|
->andWhere('tp.status > 0')
|
|
->orderBy('node.order')
|
|
->addOrderBy('tp.position')
|
|
->addOrderBy('node.title')
|
|
->setMaxResults(3)
|
|
->getQuery()
|
|
->execute()
|
|
);
|
|
}
|
|
shuffle($ret);
|
|
return $ret;
|
|
}
|
|
|
|
public function findCountryPages()
|
|
{
|
|
return $this->createQueryBuilder('node')
|
|
->innerJoin('node.country', 'country')
|
|
->where('node.status > 0')
|
|
->andWhere('node.template = \'overview\'')
|
|
->andWhere('node.lvl = 0')
|
|
->orderBy('node.lft,node.title')
|
|
->getQuery()
|
|
->execute()
|
|
;
|
|
}
|
|
|
|
public function findTopCountryNavPages()
|
|
{
|
|
return $this->createQueryBuilder('node')
|
|
->innerJoin('node.country', 'country')
|
|
->leftJoin('node.children', 'childPage', Expr\Join::WITH, 'childPage.status > 0')
|
|
->addSelect('childPage')
|
|
->where('node.status > 0')
|
|
->andWhere('node.template = \'overview\'')
|
|
->andWhere('node.lvl = 0')
|
|
->orderBy('node.lft,node.title,childPage.lft,childPage.title')
|
|
->getQuery()
|
|
->execute()
|
|
;
|
|
}
|
|
|
|
/**
|
|
* @param Page $page
|
|
*
|
|
* @return Page[]|\Doctrine\Common\Collections\Collection
|
|
*/
|
|
public function getSiblings(Page $page)
|
|
{
|
|
$parent = $page->getParent();
|
|
if (!$parent)
|
|
{
|
|
// On purpose, we don't treat root pages as if they were siblings
|
|
return [];
|
|
}
|
|
$siblings = $parent->getChildren();
|
|
foreach ($siblings as &$sibling)
|
|
{
|
|
$sibling->setParent($parent);
|
|
}
|
|
return $siblings;
|
|
}
|
|
}
|