src/Repository/Events/EventsRepository.php line 77

Open in your IDE?
  1. <?php
  2. namespace App\Repository\Events;
  3. use Doctrine\ORM\Query;
  4. use App\Entity\Events\Events;
  5. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. /**
  8.  * @method Events|null find($id, $lockMode = null, $lockVersion = null)
  9.  * @method Events|null findOneBy(array $criteria, array $orderBy = null)
  10.  * @method Events[]    findAll()
  11.  * @method Events[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  12.  */
  13. class EventsRepository extends ServiceEntityRepository
  14. {
  15.     public function __construct(ManagerRegistry $registry)
  16.     {
  17.         parent::__construct($registryEvents::class);
  18.     }
  19.     public function findByRange($startrange$endrange$status 'inactive') {
  20.         return $this->createQueryBuilder('e')
  21.         ->andWhere('e.start_day >= :starts AND e.start_day <= :ends AND e.status = :status')
  22.         ->setParameter('starts'$startrange)
  23.         ->setParameter('ends'$endrange)
  24.         ->setParameter('status'$status)
  25.         ->addOrderBy('e.start_day''ASC')
  26.         ->setMaxResults(500)
  27.         ->getQuery()
  28.         ->getResult(Query::HYDRATE_ARRAY)
  29.         ;
  30.     }
  31.     public function testGrouping($token) {
  32.         return $this->createQueryBuilder('e')
  33.             ->andWhere('e.token = :token')
  34.             ->setParameter('token'$token)
  35.             ->orderBy('e.start_day''ASC')
  36.             ->setMaxResults(1)
  37.             ->getQuery()
  38.             ->getOneOrNullResult()
  39.         ;
  40.     }
  41.     public function xtestGrouping($name$city$state) {
  42.         return $this->createQueryBuilder('e')
  43.             ->andWhere('e.name = :name')
  44.             ->setParameter('name'$name)
  45.             ->andWhere('e.city = :city')
  46.             ->setParameter('city'$city)
  47.             ->andWhere('e.state = :state')
  48.             ->setParameter('state'$state)
  49.             ->orderBy('e.start_day''ASC')
  50.             ->setMaxResults(1)
  51.             ->getQuery()
  52.             ->getOneOrNullResult()
  53.         ;
  54.     }
  55.     public function findByToken($name$city$startday) {
  56.         return $this->createQueryBuilder('e')
  57.             ->andWhere('e.token = :token')
  58.             ->setParameter('token'$this->makeSswToken($name$city4))
  59.             ->andWhere('e.city = :city')
  60.             ->setParameter('city'$city)
  61.             ->andWhere('e.start_day = :startday')
  62.             ->setParameter('startday'$startday)
  63.             ->orderBy('e.start_day''ASC')
  64.             ->setMaxResults(1)
  65.             ->getQuery()
  66.             ->getOneOrNullResult()
  67.         ;
  68.     }
  69.     public function makeSswToken($title ""$city$wcnt 5) {
  70.         // Creates a slugged token for comparisons
  71.         $stopwords = array("a","about","actually","almost","ain't","aren't","also","although","always","am","an","and","any","are","as","at","be","became","become","but","by","can","could","did","do","does","each","either","else","for","from","had","has","have","hence","how","i","if","in","is","it","its","just","may","maybe","me","might","mine","must","my","mine","must","my","neither","nor","not","of","oh","ok","or","that","the""then","when","where","whereas","wherever","whenever","whether","which","while","who","whom","whoever","whose","why","will","with","within","without","would","yes","yet","you","your");
  72.         //echo $title." now ";
  73.         $title html_entity_decode(strip_tags($title));
  74.         $title strtolower(str_replace("'s",''$title));
  75.         $title preg_replace("#[[:punct:]]#"""$title);
  76.         $words explode(' 'trim($title));
  77.         foreach ($words as $k => $word) {
  78.             if (strlen($word) <= 3) {
  79.                 unset($words[$k]);
  80.             }
  81.             if (in_array(strtolower($word), $stopwords)) { 
  82.                 unset($words[$k]);
  83.             }
  84.         }
  85.         $words array_slice(array_unique($words), 0$wcnt);
  86.         if(!empty($city)) {
  87.             array_push($wordspreg_replace('/[[:space:]]+/''-'trim($city)));
  88.         }
  89.         $preslug implode('-'$words);
  90.         $result strtolower(preg_replace('/[^a-zA-Z0-9-]/',''$preslug));
  91.         //echo $result."<br>";
  92.         return $result;
  93.     }
  94.     // /**
  95.     //  * @return Events[] Returns an array of Events objects
  96.     //  */
  97.     /*
  98.     public function findByExampleField($value)
  99.     {
  100.         return $this->createQueryBuilder('e')
  101.             ->andWhere('e.exampleField = :val')
  102.             ->setParameter('val', $value)
  103.             ->orderBy('e.id', 'ASC')
  104.             ->setMaxResults(10)
  105.             ->getQuery()
  106.             ->getResult()
  107.         ;
  108.     }
  109.     */
  110.     /*
  111.     public function findOneBySomeField($value): ?Events
  112.     {
  113.         return $this->createQueryBuilder('e')
  114.             ->andWhere('e.exampleField = :val')
  115.             ->setParameter('val', $value)
  116.             ->getQuery()
  117.             ->getOneOrNullResult()
  118.         ;
  119.     }
  120.     */
  121. }