nineskeletor/src/Repository/ChildRepository.php

173 lines
6.3 KiB
PHP

<?php
namespace App\Repository;
use App\Entity\Child;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
class ChildRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Child::class);
}
public function findPages($catparent, $idparent)
{
switch ($catparent) {
case 'blog':
// Rechercher la premiere page
$qb = $this->createQueryBuilder('c')->select('c')
->where('c.blog=:idblog AND c.childtype=:idchildtype')
->setParameter('idblog', $idparent)
->setParameter('idchildtype', 1)
->orderby('c.roworder', 'ASC');
$childs = $qb->getQuery()->getResult();
return $childs;
break;
case 'page':
// Rechercher la premiere page
$qb = $this->createQueryBuilder('c')->select('c')
->where('c.page=:idpage AND c.childtype=:idchildtype')
->setParameter('idpage', $idparent)
->setParameter('idchildtype', 1)
->orderby('c.roworder', 'ASC');
$childs = $qb->getQuery()->getResult();
return $childs;
break;
}
return null;
}
public function findFirstchild($catparent, $idparent)
{
switch ($catparent) {
case 'blog':
// Rechercher la premiere page
$qb = $this->createQueryBuilder('c')->select('c')
->where('c.blog=:idblog AND c.childtype=:idchildtype')
->setParameter('idblog', $idparent)
->setParameter('idchildtype', 1)
->orderby('c.roworder', 'ASC')
->setMaxResults(1);
$child = $qb->getQuery()->getOneOrNullResult();
if ($child) {
return $child;
}
break;
case 'page':
// Rechercher la premiere page
$qb = $this->createQueryBuilder('c')->select('c')
->where('c.page=:idpage AND c.childtype=:idchildtype')
->setParameter('idpage', $idparent)
->setParameter('idchildtype', 1)
->orderby('c.roworder', 'ASC')
->setMaxResults(1);
$child = $qb->getQuery()->getOneOrNullResult();
if ($child) {
return $child;
}
break;
}
return null;
}
public function findNext($catparent, $idparent, $tbchildtype, $roworder)
{
switch ($catparent) {
case 'blog':
$qb = $this->createQueryBuilder('c')
->select('c')
->where('c.blog=:idblog AND c.childtype IN(:tbchildtype) AND c.roworder>:roworder')
->setParameter('idblog', $idparent)
->setParameter('tbchildtype', $tbchildtype)
->setParameter('roworder', $roworder)
->orderby('c.roworder', 'ASC')
->setMaxResults(1);
break;
case 'page':
$qb = $this->createQueryBuilder('c')
->select('c')
->where('c.page=:idpage AND c.childtype IN(:tbchildtype) AND c.roworder>:roworder')
->setParameter('idpage', $idparent)
->setParameter('tbchildtype', $tbchildtype)
->setParameter('roworder', $roworder)
->orderby('c.roworder', 'ASC')
->setMaxResults(1);
break;
}
$child = $qb->getQuery()->getOneOrNullResult();
return $child;
}
public function findPrev($catparent, $idparent, $tbchildtype, $roworder)
{
switch ($catparent) {
case 'blog':
$qb = $this->createQueryBuilder('c')
->select('c')
->where('c.blog=:idblog AND c.childtype IN(:tbchildtype) AND c.roworder<:roworder')
->setParameter('idblog', $idparent)
->setParameter('tbchildtype', $tbchildtype)
->setParameter('roworder', $roworder)
->orderby('c.roworder', 'DESC')
->setMaxResults(1);
break;
case 'page':
$qb = $this->createQueryBuilder('c')
->select('c')
->where('c.page=:idpage AND c.childtype IN(:tbchildtype) AND c.roworder<:roworder')
->setParameter('idpage', $idparent)
->setParameter('tbchildtype', $tbchildtype)
->setParameter('roworder', $roworder)
->orderby('c.roworder', 'DESC')
->setMaxResults(1);
break;
}
$child = $qb->getQuery()->getOneOrNullResult();
return $child;
}
public function findOtherchilds($catparent, $idparent, $tbidchildtype, $idchild, $firstonly = false)
{
switch ($catparent) {
case 'blog':
$qb = $this->createQueryBuilder('c')->select('c')
->where('c.blog=:idblog AND c.childtype IN(:tbidchildtype) AND c.id!=:idchild')
->setParameter('idblog', $idparent)
->setParameter('tbidchildtype', $tbidchildtype)
->setParameter('idchild', $idchild)
->orderby('c.roworder', 'ASC');
break;
case 'page':
$qb = $this->createQueryBuilder('c')->select('c')
->where('c.page=:idpage AND c.childtype IN(:tbidchildtype) AND c.id!=:idchild')
->setParameter('idpage', $idparent)
->setParameter('tbidchildtype', $tbidchildtype)
->setParameter('idchild', $idchild)
->orderby('c.roworder', 'ASC');
break;
}
if ($firstonly) {
$qb->setMaxResults(1);
}
$childs = $qb->getQuery()->getResult();
return $childs;
}
}