public function __construct(EntityManager $em, Logger $logger) { parent::__construct($em, SportGroup::getClassName(), $logger); $this->groupDao = $em->getDao(SportGroup::getClassName()); $this->sportTypeDao = $em->getDao(SportType::getClassName()); }
public function getArticles(SportGroup $g = null, $limit = 20) { try { if (is_null($g)) { return $this->articleDao->createQueryBuilder("a")->andWhere("a.status = :state")->setParameter("state", ArticleStatus::PUBLISHED)->getQuery()->getResult(); } $id = SportGroup::getClassName() . "-" . $g->getId(); $cache = $this->getEntityCache(); $data = $cache->load($id); if ($data === null) { $qb = $this->articleDao->createQueryBuilder("a")->innerJoin('a.groups', 'g')->where('g.id = :gid')->setParameter("gid", $g->id)->andWhere("a.status = :state")->setParameter("state", ArticleStatus::PUBLISHED)->orderBy("a.updated", "DESC")->setMaxResults($limit); $data = $qb->getQuery()->getResult(); $opts = [Cache::TAGS => [self::ENTITY_COLLECTION, $id, self::SELECT_COLLECTION]]; $cache->save($id, $data, $opts); } return $data; } catch (\Doctrine\ORM\NoResultException $ex) { $this->logWarning($ex->getMessage()); throw new Exceptions\DataErrorException("No relations article -> group {$g} found"); } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException("Error reading articles according to related group {$g}"); } }
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()); } }