src/Repository/TaskRepository.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Company;
  4. use App\Entity\Project;
  5. use App\Entity\Task;
  6. use App\Entity\User;
  7. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. /**
  10.  * @method Task|null find($id, $lockMode = null, $lockVersion = null)
  11.  * @method Task|null findOneBy(array $criteria, array $orderBy = null)
  12.  * @method Task[]    findAll()
  13.  * @method Task[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  14.  */
  15. class TaskRepository extends ServiceEntityRepository
  16. {
  17.     public function __construct(ManagerRegistry $registry)
  18.     {
  19.         parent::__construct($registryTask::class);
  20.     }
  21.     public function findAllSortByDate()
  22.     {
  23.         return $this->createQueryBuilder('t')
  24.             ->orderBy('t.start_at','DESC')
  25.             ->getQuery()
  26.             ->getResult()
  27.             ;
  28.     }
  29.     public function findAllTasksOfAProject(Project $project)
  30.     {
  31.         return $this->createQueryBuilder('t')
  32.             ->andWhere('t.project = (:project)')
  33.             ->setParameter('project'$project)
  34.             ->getQuery()
  35.             ->getResult()
  36.         ;
  37.     }
  38.     public function findAllTasksOfAUser(User $user)
  39.     {
  40.         return $this->createQueryBuilder('t')
  41.             ->andWhere('t.user = (:user)')
  42.             ->setParameter('user'$user)
  43.             ->getQuery()
  44.             ->getResult()
  45.             ;
  46.     }
  47.     //Select all tasks that belong to a project of the company
  48.     public function findAllTasksOfCompany(Company $company$month$year)
  49.     {
  50.         return $this->createQueryBuilder('t')
  51.             ->andWhere('t.project in (:company)')
  52.             ->setParameter('company'$company->getProjects())
  53.             ->andWhere('MONTH(t.start_at) = :month')
  54.             ->setParameter('month'$month)
  55.             ->andWhere('Year(t.start_at) = :year')
  56.             ->setParameter('year'$year)
  57.             ->getQuery()
  58.             ->getResult()
  59.             ;
  60.     }
  61.     //Select all day that belong to a project of the company
  62.     //This function is use in order to retrieve all the different day of a month where a user made some tasks
  63.     public function findAllDayOfTaskForAMonthForAUser(User $user$month,$year)
  64.     {
  65.         return $this->createQueryBuilder('t')
  66.             ->select('Day(t.start_at)')
  67.             ->distinct()
  68.             ->andWhere('t.user in (:user)')
  69.             ->setParameter('user'$user)
  70.             ->andWhere('MONTH(t.start_at) = :month')
  71.             ->setParameter('month'$month)
  72.             ->andWhere('Year(t.start_at) = :year')
  73.             ->setParameter('year'$year)
  74.             ->getQuery()
  75.             ->getResult()
  76.             ;
  77.     }
  78.     //Select all tasks that belong of a user for a certain date , day, month, year
  79.     public function findAllTasksOfUserForADate(User $user$day$month$year)
  80.     {
  81.         return $this->createQueryBuilder('t')
  82.             ->andWhere('t.user in (:user)')
  83.             ->setParameter('user'$user)
  84.             ->andWhere('MONTH(t.start_at) = :month')
  85.             ->setParameter('month'$month)
  86.             ->andWhere('Year(t.start_at) = :year')
  87.             ->setParameter('year'$year)
  88.             ->andWhere('Day(t.start_at) = :day')
  89.             ->setParameter('day'$day)
  90.             ->orderBy('t.start_at','DESC')
  91.             ->getQuery()
  92.             ->getResult()
  93.             ;
  94.     }
  95.     //Select all tasks that belong of a user for a certain date month, year
  96.     public function findAllTasksOfUserForAMonth(User $user,$month$year)
  97.     {
  98.         return $this->createQueryBuilder('t')
  99.             ->andWhere('t.user in (:user)')
  100.             ->setParameter('user'$user)
  101.             ->andWhere('MONTH(t.start_at) = :month')
  102.             ->setParameter('month'$month)
  103.             ->andWhere('Year(t.start_at) = :year')
  104.             ->setParameter('year'$year)
  105.             ->orderBy('t.start_at','DESC')
  106.             ->getQuery()
  107.             ->getResult()
  108.             ;
  109.     }
  110.     ////// ABDEL - REPORTING //// $users And $companies are  array Objects/////Return List tasks from posted parameter///////
  111.     public function findAllTasksOfUsersAndCompaniesinPeriod($users,$companies$month=''$year='',$day_start='',$day_end='')
  112.         {
  113.             $query=$this->createQueryBuilder('t')
  114.             ->join('App\Entity\Project''p')
  115.             ->where('t.project = p.id')
  116.             ->andWhere('p.company IN (:companies)')
  117.             ->setParameter('companies'$companies)
  118.             ->andWhere('t.user IN (:users)')
  119.             ->setParameter('users'$users);
  120.             if($month!='' and $year!='' and $day_start=='' and $day_end=='') {
  121.                     $query->andWhere('MONTH(t.start_at) = :month')
  122.                     ->setParameter('month'$month)
  123.                     ->andWhere('Year(t.start_at) = :year')
  124.                     ->setParameter('year'$year);
  125.                 }
  126.             if($month=='' and $year=='' and $day_start!='' and $day_end!='') {
  127.                     $query->andWhere('t.start_at >= :day_start')
  128.                     ->setParameter('day_start'$day_start)
  129.                     ->andWhere('t.start_at <= :day_end')
  130.                     ->setParameter('day_end'$day_end)
  131.                     ->orderBy('t.start_at''DESC');
  132.     }
  133.                 ;
  134.     return ($query->getQuery()->getResult()) ;
  135.     //Debug Query;
  136.     // SHOW SQL:
  137.     //echo $query->getSQL();
  138.     //return $query ;
  139.         }
  140. ////// ABDEL///////////////// Reporting          Get list tasks in list ids tasks////////////
  141. public function findAllTasksInListIdsTasks($idstasks=array())
  142.     {
  143.      $query=$this->createQueryBuilder('t')
  144.      ->andWhere('t.id IN (:idstasks)')
  145.      ->setParameter('idstasks'$idstasks)
  146.      
  147.      
  148.      ;
  149.             return ($query->getQuery()->getResult()) ;
  150.     
  151.     }
  152. // ABDEL///////////////////
  153.     //Select all tasks that belong of a user and company  for a certain date month, year
  154.     public function findAllTasksOfUserCompanyForAMonth(User $user,Company $company,$month$year)
  155.     {
  156.         return $this->createQueryBuilder('t')
  157.             ->andWhere('t.user in (:user)')
  158.             ->setParameter('user'$user)
  159.             ->andWhere('t.project in (:company)')
  160.             ->setParameter('company'$company->getProjects())
  161.             ->andWhere('MONTH(t.start_at) = :month')
  162.             ->setParameter('month'$month)
  163.             ->andWhere('Year(t.start_at) = :year')
  164.             ->setParameter('year'$year)
  165.             ->orderBy('t.start_at','DESC')
  166.             ->getQuery()
  167.             ->getResult()
  168.             ;
  169.     }
  170. //  ///// ABDEL - REPORTING //// $users And $companies are  array Objects/////Return List tasks from posted parameter///////
  171.     public function findAllTasksOfUsersAndCompaniesForMonthAYear($users,$companies$month$year)
  172.         {
  173.             $query=$this->createQueryBuilder('t')
  174.             ->join('App\Entity\Project''p')
  175.             ->where('t.project = p.id')
  176.             ->andWhere('p.company IN (:companies)')
  177.             ->setParameter('companies'$companies)
  178.             ->andWhere('t.user IN (:users)')
  179.             ->setParameter('users'$users);
  180.             
  181.                     $query->andWhere('MONTH(t.start_at) = :month')
  182.                     ->setParameter('month'$month)
  183.                     ->andWhere('Year(t.start_at) = :year')
  184.                     ->setParameter('year'$year);
  185.                 
  186.             
  187.     return ($query->getQuery()->getResult()) ;
  188.     //Debug Query;
  189.     // SHOW SQL:
  190.     //echo $query->getSQL();
  191.     //return $query ;
  192.         }
  193. }