private static function getPairsAdvanced(EntityDao $dao, array $options) { $qb = $dao->createQueryBuilder('e')->select("e")->resetDQLPart('from')->from($dao->getClassName(), 'e', 'e.' . $options['key'])->autoJoinOrderBy((array) $options['orderBy']); foreach ($options['criteria'] as $key => $value) { if (is_numeric($key) && is_callable($value)) { $value($qb, 'e'); } else { $qb->whereCriteria([$key => $value]); } } $query = $qb->getQuery(); if (is_string($options['value'])) { $parts = explode('.', $options['value']); $callback = function ($value) use($parts) { foreach ($parts as $part) { $value = $value->{$part}; } return $value; }; } else { $callback = $options['value']; } $result = $query->getResult(); return array_map($callback, $result); }
public function getWebProfilesToPermitDatasource() { $c = new Criteria(); $c->where(Criteria::expr()->eq("status", WebProfileStatus::UPDATED)); $model = new Doctrine($this->webProfileDao->createQueryBuilder('u')->addCriteria($c)); return $model; }
public function getSelectAllSportGroups($id = null, $active = null) { $cache = $this->getEntityCache(); $data = $cache->load(self::SELECT_COLLECTION); try { if ($data === null) { $qb = $this->groupDao->createQueryBuilder("g"); if ($active !== null) { $qb->where("g.active = :act")->setParameter("act", $active); } $all = $qb->getQuery()->getResult(); $data = []; foreach ($all as $g) { $type = $g->getSportType(); $data = $data + [$g->getId() => $g->getName() . ($type !== null ? " ({$type->getName()})" : "")]; } $opt = [Cache::TAGS => [self::SELECT_COLLECTION]]; $cache->save(self::SELECT_COLLECTION, $data, $opt); } if ($id != null) { unset($data[$id]); } return $data; } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
public function getPaymentsDatasource(User $u = null) { $model = $this->paymentDao->createQueryBuilder('pa'); if ($u !== null) { $model->where("pa.owner = :id")->setParameter("id", $u->getId()); } return new Doctrine($model); }
public function getCurrentSeason() { try { return $this->seasonDao->createQueryBuilder("s")->where("s.current = true")->getQuery()->getSingleResult(); } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
/** * @param Brabijan\SeoComponents\Entity\Target $target * @param Brabijan\SeoComponents\Entity\Route $route */ public function setCurrentRouteForTarget(Brabijan\SeoComponents\Entity\Target $target, Brabijan\SeoComponents\Entity\Route $route) { $qb = $this->routeDao->createQueryBuilder("r")->update(); $qb->set("r.oneWay", ":oneWay")->setParameter(":oneWay", TRUE); $qb->where("r.target = :target")->setParameter(":target", $target); $qb->getQuery()->execute(); $route->oneWay = FALSE; $this->routeDao->save($route); }
public function getGroupStaticPages(SportGroup $g) { try { $q = $this->pageDao->createQueryBuilder("sp")->where("sp.group = :group")->setParameter("group", $g->getId())->getQuery(); return $q->getResult(); } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
/** * @return \Doctrine\ORM\QueryBuilder */ public function getDql() { $qb = $this->commentDao->createQueryBuilder('a'); if ($this->recipient) { $qb = $qb->andWhere('a.recipient = :recipient')->setParameter('recipient', $this->recipient); } else { $qb = $qb->andWhere('a.recipient IS NULL'); } return $qb; }
public function getEntriesDataSource(User $u = null) { $qb = $this->entryDao->createQueryBuilder("e"); if ($u === null) { $model = $qb; } else { $model = $qb->where("e.owner = :owner")->setParameter("owner", $u); } return new Doctrine($model); }
public function getSeasonTaxSG(Season $s, SportGroup $sg) { try { $res = $this->seasonTaxDao->createQueryBuilder("st")->where("st.season = :season")->setParameter("season", $s)->andWhere("st.sportGroup = :group")->setParameter("group", $sg)->getQuery()->getSingleResult(); return $res; } catch (NoResultException $ex) { $this->logWarning($ex->getMessage()); throw new Exceptions\NoResultException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
public function getNews() { try { $cache = $this->getEntityCache(); $data = $cache->load(self::COLLECTION_NEWS); if ($data === null) { $data = $this->articleDao->createQueryBuilder("a")->orderBy("a.created", "DESC")->setMaxResults($this->getDefaultRssLimit())->getQuery()->getResult(); $opts = [Cache::TAGS => [self::ENTITY_COLLECTION, self::SELECT_COLLECTION, self::COLLECTION_NEWS], Cache::SLIDING => true]; $cache->save(self::COLLECTION_NEWS, $data, $opts); } return $data; } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
public function getUsersApplication(User $u, Season $s) { try { $id = "{$this->getEntityClassName()}/{$u->getId()}-{$s->getId()}"; $cache = $this->getEntityCache(); $data = $cache->load($id); if ($data === null) { $data = $this->seasonApplicationDao->createQueryBuilder("a")->where("a.owner = :owner")->setParameter("owner", $u->getId())->andWhere("a.season = :season")->setParameter("season", $s->getId())->getQuery()->getSingleResult(); $opts = [Cache::TAGS => [self::ENTITY_COLLECTION, $id]]; $cache->save($id, $data, $opts); } return $data; } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
public function getUniqueRule(Role $r, $resource = null, $priv = null) { try { $qb = $this->aclRuleDao->createQueryBuilder("r")->where("r.role = :role")->setParameter("role", $r->getId()); if ($resource === null) { $qb->andWhere("r.resource IS NULL"); } else { $qb->andWhere("r.resource = :res")->setParameter("res", $resource); } if ($priv === null) { $qb->andWhere("r.privilege IS NULL"); } else { $qb->andWhere("r.privilege = :priv")->setParameter("priv", $priv); } return $qb->getQuery()->getSingleResult(); } catch (\Doctrine\ORM\NoResultException $e) { $this->logError($e); throw new Exceptions\NoResultException($e->getMessage(), $e->getCode(), $e->getPrevious()); } }
public function getPositionsWithinGroup(SportGroup $g, $useCache = true) { try { $qb = $this->positionDao->createQueryBuilder(); $qb->select("p")->from("App\\Model\\Entities\\Position", "p")->where("p.group = :group")->setParameter("group", $g); $q = $qb->getQuery(); if (!$useCache) { return $q->getResult(); } $id = User::getClassName() . "in" . SportGroup::getClassName() . "-" . $g->getId(); $cache = $this->getEntityCache(); $data = $cache->load($id); if ($data == null) { $data = $q->getResult(); $opts = [Cache::TAGS => [self::ENTITY_COLLECTION, self::STRANGER_COLLECTION, $id], Cache::SLIDING => true]; $cache->save($id, $data, $opts); } return $data; } catch (\Exception $e) { $this->logError($e); throw new Exceptions\DataErrorException($e->getMessage(), $e->getCode(), $e->getPrevious()); } }
/** * @param array $criteria * @param array $orderBy * @param null $limit * @param null $offset * @return \ArrayIterator */ public function findForApi(array $criteria, array $orderBy = null, $limit = null, $offset = null) { $query = $this->dao->createQueryBuilder('p')->whereCriteria($criteria)->autoJoinOrderBy((array) $orderBy)->leftJoin('p.tags', 'tt')->addSelect('tt')->getQuery(); $resultSet = new Kdyby\Doctrine\ResultSet($query); return $resultSet->applyPaging($offset, $limit)->getIterator(Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY); }
/** * @return \ArrayIterator */ public function findBy(array $criteria, array $orderBy = NULL, $limit = NULL, $offset = NULL) { $query = $this->dao->createQueryBuilder('p')->whereCriteria($criteria)->autoJoinOrderBy((array) $orderBy)->leftJoin('p.tags', 'tt')->addSelect('tt')->getQuery(); $resultSet = new Kdyby\Doctrine\ResultSet($query); return $resultSet->applyPaging($offset, $limit)->getIterator(); }
public function getRolesDatasource() { $model = new Doctrine($this->roleDao->createQueryBuilder('role')); return $model; }
public function getPartnersDatasource() { $model = new Doctrine($this->partnerDao->createQueryBuilder("p")); return $model; }
public function getSportTypeDataSource() { $model = new \Grido\DataSources\Doctrine($this->sportTypeDao->createQueryBuilder("type")); return $model; }
public function getUserEventsDatasource(User $u) { $model = new Doctrine($this->participationDao->createQueryBuilder()->select("ep, ev.title AS title, ev.takePlaceSince as takePlaceSince, ev.takePlaceTill AS takePlaceTill, ev.eventType AS eventType")->add("from", EventParticipation::getClassName() . " ep LEFT JOIN ep.event ev")->where("ep.owner = :owner")->setParameter("owner", $u->getId())); return $model; }
public function getForumDataSource() { $model = new Doctrine($this->forumDao->createQueryBuilder('f')); return $model; }
public function getWallPostsDatasource() { $model = new Doctrine($this->wallDao->createQueryBuilder('wp')); return $model; }
/** * @return \Doctrine\ORM\QueryBuilder */ public function getDql() { return $this->commentDao->createQueryBuilder('a')->andWhere('a.recipient IS NULL OR a.recipient = :recipient')->setParameter('recipient', $this->user->identity)->groupBy('a.tag')->addGroupBy('a.recipient'); }