/** * @param QueryBuilder $qb * @param bool $includeView Trigger to include the documents with type == view * @param Contact $contact * * @return QueryBuilder $qb */ public function filterForAccess(QueryBuilder $qb, Contact $contact, $includeView = false) { //Filter based on the type access type $subSelect = $this->_em->createQueryBuilder(); $subSelect->select('type'); $subSelect->from('Project\\Entity\\Document\\Type', 'type'); $subSelect->join('type.access', 'access'); if (!$includeView) { $subSelect->andWhere($qb->expr()->in('access.access', array_merge_recursive([strtolower(Access::ACCESS_PUBLIC)], $contact->getRoles()))); } else { $subSelect->andWhere($qb->expr()->orX($qb->expr()->in('access.access', array_merge_recursive([strtolower(Access::ACCESS_PUBLIC)], $contact->getRoles())), $qb->expr()->in('type.view', DocumentType::VIEW))); } $qb->andWhere($qb->expr()->in('d.type', $subSelect->getDQL())); return $qb; }
/** * @param Entity\Contact $contact * * @return Entity\Facebook[] */ public function findFacebookByContact(Entity\Contact $contact) { //Select projects based on a type $queryBuilder = $this->_em->createQueryBuilder(); $queryBuilder->select('f'); $queryBuilder->from('Contact\\Entity\\Facebook', 'f'); $queryBuilder->leftJoin('f.access', 'a'); $queryBuilder->andWhere($queryBuilder->expr()->orX($queryBuilder->expr()->in('a.access', $contact->getRoles()), $queryBuilder->expr()->in('f.public', [Entity\Facebook::IS_PUBLIC]))); return $queryBuilder->getQuery()->getResult(); }
/** * @param ProjectEntity $project * @param Contact $contact * * @return ResultEntity[] */ public function findResultsByProjectAndContact(ProjectEntity $project, Contact $contact) { $qb = $this->_em->createQueryBuilder(); $qb->select('r'); $qb->from("Project\\Entity\\Result\\Result", 'r'); $qb->join('r.type', 't'); $qb->join('t.access', 'a'); $qb->where('r.project = ?1'); $qb->andWhere($qb->expr()->in('a.access', array_merge_recursive(['public'], $contact->getRoles()))); $qb->setParameter(1, $project); return $qb->getQuery()->getResult(); }
/** * @param QueryBuilder $qb * @param Contact $contact * * @return QueryBuilder $qb */ public function filterForAccess(QueryBuilder $qb, Contact $contact) { //Filter based on the type access type $subSelect = $this->_em->createQueryBuilder(); $subSelect->select('type'); $subSelect->from('Calendar\\Entity\\Type', 'type'); $subSelect->join('type.access', 'access'); $subSelect->andWhere($qb->expr()->in('access.access', array_merge([strtolower(Access::ACCESS_PUBLIC)], $contact->getRoles()))); $subSelectCalendarContact = $this->_em->createQueryBuilder(); $subSelectCalendarContact->select('calendar2'); $subSelectCalendarContact->from('Calendar\\Entity\\Calendar', 'calendar2'); $subSelectCalendarContact->join('calendar2.calendarContact', 'calenderContact2'); $subSelectCalendarContact->join('calenderContact2.contact', 'contact2'); $subSelectCalendarContact->andWhere('contact2.id = ' . $contact); $qb->andWhere($qb->expr()->orX($qb->expr()->in('c.type', $subSelect->getDQL()), $qb->expr()->in('c', $subSelectCalendarContact->getDQL()))); return $qb; }