| 1: | <?php |
| 2: | namespace TIC\ListBundle\Repository; |
| 3: | |
| 4: | use Doctrine\ORM\EntityRepository; |
| 5: | |
| 6: | |
| 7: | |
| 8: | use TIC\DormBundle\Base\TICRepository as BaseRepository; |
| 9: | use Doctrine\ORM\QueryBuilder; |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | class ListInfoRepository extends BaseRepository |
| 16: | { |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | public $sortBy = array('ref' => 'ASC'); |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | public function qbFilters(array $filters = array(), $qb = null): QueryBuilder |
| 31: | { |
| 32: | $alias = is_string($qb) ? $qb : (isset($this->alias) ? $this->alias : 'a'); |
| 33: | if (! is_object($qb)) $qb = $this->createQueryBuilder($alias); |
| 34: | |
| 35: | foreach ($filters as $type => $value) switch ($type) { |
| 36: | case 'editable': |
| 37: | case 'valuable': |
| 38: | case 'referable': |
| 39: | case 'translatable': |
| 40: | case 'deactivatable': |
| 41: | case 'sortable': |
| 42: | case 'iconable': |
| 43: | if ($value !== null) $qb->andWhere($alias.'.'.$type.' = :'.$type)->setParameter($type, (bool)$value); |
| 44: | break; |
| 45: | case 'ref': |
| 46: | if ($value) $qb->andWhere($alias.'.ref = :ref')->setParameter('ref', $value); |
| 47: | break; |
| 48: | case 'items': |
| 49: | if ($value) $qb->leftJoin($alias.'.items', 'i')->addSelect('i'); |
| 50: | break; |
| 51: | case 'locale': |
| 52: | if ($value) $qb->leftJoin($alias.'.items', 'i')->addSelect('i'); |
| 53: | if ($value) $qb->leftJoin('i.translations', 't', 'WITH', 't.locale = :locale')->addSelect('t')->setParameter('locale', $value); |
| 54: | break; |
| 55: | } |
| 56: | return $qb; |
| 57: | } |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | public function listReferences() { |
| 64: | return $this->createQueryBuilder('a')->select('a.ref')->orderBy('a.ref')->getQuery()->getResult('column'); |
| 65: | } |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: | public function getChoices($ref, $all=false) { |
| 73: | $choices = array(); |
| 74: | |
| 75: | $list = $this->find($ref); |
| 76: | if ($list) foreach ($list->getItems() as $item) { |
| 77: | if (! $all && ! $item->getEnabled()) continue; |
| 78: | $choices[$item->getValue()] = $item->getLabel(); |
| 79: | } |
| 80: | |
| 81: | return $choices; |
| 82: | } |
| 83: | |
| 84: | |
| 85: | } |
| 86: | |