Your IP : 216.73.217.79


Current Path : /var/www/v3.cesa.co.za/src/EventBundle/Repository/
Upload File :
Current File : /var/www/v3.cesa.co.za/src/EventBundle/Repository/SchoolCourseRepository.php

<?php

namespace App\EventBundle\Repository;

use App\EventBundle\Entity\SchoolCourse;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<SchoolCourse>
 *
 * @method SchoolCourse|null find($id, $lockMode = null, $lockVersion = null)
 * @method SchoolCourse|null findOneBy(array $criteria, array $orderBy = null)
 * @method SchoolCourse[]    findAll()
 * @method SchoolCourse[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class SchoolCourseRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, SchoolCourse::class);
    }

    public function findAllForAPI(int $limit = 0, int $offset = -1, $criteria = [])
    {
        $qb = $this->createQueryBuilder('sc')
            ->select('sc.id')
            // ->where('sc.currentlyOffered = :currentlyOffered')
            // ->setParameter('currentlyOffered', true)
            ->orderBy('sc.course_name', 'ASC');

        if (isset($criteria['training_provider_id']) && $criteria['training_provider_id'] > 0) {
            $qb->join('sc.training_provider', 'tp')
                ->andWhere('tp.id = :training_provider_id')
                ->setParameter('training_provider_id', $criteria['training_provider_id']);
        }

        if (isset($criteria['provider_id']) && $criteria['provider_id'] > 0) {
            $qb->join('sc.school_provider', 'sp')
                ->andWhere('sp.id = :provider_id')
                ->setParameter('provider_id', $criteria['provider_id']);
        }

        if ($offset >= 0) {
            $qb->setFirstResult($offset);
        }

        if ($limit > 0) {
            $qb->setMaxResults($limit);
        }

        return $qb
            ->getQuery()
            ->setHint(\Doctrine\ORM\Query::HINT_FORCE_PARTIAL_LOAD, true)
            ->getArrayResult();
    }

    //    /**
    //     * @return SchoolCourse[] Returns an array of SchoolCourse objects
    //     */
    //    public function findByExampleField($value): array
    //    {
    //        return $this->createQueryBuilder('s')
    //            ->andWhere('s.exampleField = :val')
    //            ->setParameter('val', $value)
    //            ->orderBy('s.id', 'ASC')
    //            ->setMaxResults(10)
    //            ->getQuery()
    //            ->getResult()
    //        ;
    //    }

    //    public function findOneBySomeField($value): ?SchoolCourse
    //    {
    //        return $this->createQueryBuilder('s')
    //            ->andWhere('s.exampleField = :val')
    //            ->setParameter('val', $value)
    //            ->getQuery()
    //            ->getOneOrNullResult()
    //        ;
    //    }
}