<?php

namespace AppBundle\Entity\Product\Repository;
use AppBundle\Entity\Organization\Organization;
use AppBundle\Entity\Person\Person;
use AppBundle\Entity\Product\Equipment;
use AppBundle\Entity\Product\EquipmentList;
use Doctrine\ORM\EntityRepository;

/**
 * Description of EquipmentRepository
 *
 */
class EquipmentControlRepository extends EntityRepository
{

    public function findEquipmentControlOrganization(Organization $organization)
    {
        $qb = $this->createQueryBuilder('a')
            ->innerJoin(Equipment::class, 'equ', 'WITH', 'a.equipment= equ.id')
            ->andWhere('equ.organization=:organizationId')
            ->andWhere('a.startDate IS NOT NULL')
            ->orderBy('a.startDate', 'DESC')
            ->setParameter(':organizationId', $organization);
        return $qb->getQuery()->getResult();
    }

    public function findEquipmentAccessOwner(Organization $organization)
    {

        $qb = $this->createQueryBuilder('o');
        $qb->innerJoin('o.equipment', 'equ', 'WITH')
            ->innerJoin('equ.access','owner', 'WITH')
            ->innerJoin('owner.organizationFunction', 'organizationFunction')
            ->andWhere('owner.organization=:org')
            ->setParameter(':org', $organization);
        return $qb->getQuery()->getResult();
    }
}

?>
