Newer
Older
activity-manager / src / Repository / TaskRepository.php
<?php
namespace App\Repository;

use App\Entity\TaskEntity;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;

class TaskRepository extends EntityRepository
{

    /** @var array Default sorting */
    public const DEFAULT_ORDER = [
        'planifiedDate' => 'asc',
        'activity' => 'desc',
        'name' => 'asc',
    ];

    /**
     * {@inheritdoc}
     */
    public function find($id, $lockMode = null, $lockVersion = null): ?TaskEntity
    {
        return parent::find($id, $lockMode, $lockVersion);
    }

    /**
     * {@inheritdoc}
     */
    public function findBy(array $criteria, ?array $orderBy = self::DEFAULT_ORDER, $limit = null, $offset = null)
    {
        return parent::findBy($criteria, $orderBy, $limit, $offset);
    }

    /**
     * {@inheritdoc}
     */
    public function createQueryBuilder($alias, $indexBy = null): QueryBuilder
    {
        $queryBuilder = parent::createQueryBuilder($alias, $indexBy);
        foreach ($this::DEFAULT_ORDER as $field => $order) {
            $queryBuilder->addOrderBy($alias . '.' . $field, $order);
        }

        return $queryBuilder;
    }
}