array('enabled'), ); return $list; } // }}} // {{{ findAllAuthors /** * Find all languages * * @return array */ public function findAllAuthors() { return $this->defineAllAuthorsQuery()->getResult(); } /** * Define query builder for findAllAuthors() * * @return \Doctrine\ORM\QueryBuilder */ protected function defineAllAuthorsQuery() { return $this->createQueryBuilder(); } // }}} // {{{ findActiveAuthors /** * Find all enabled languages * * @return array */ public function findActiveAuthors() { return $this->defineActiveAuthorsQuery()->getResult(); } /** * Define query builder for findActiveAuthors() * * @return \Doctrine\ORM\QueryBuilder */ protected function defineActiveAuthorsQuery() { // without 'm' one gets an error return $this->createQueryBuilder('m') ->where('m.enabled = :true') ->setParameter('true', true); } // }}} // {{{ findOneByName /** * Find author by name (any language) * * @param string $name Name * @param boolean $onlyActive Search only in enabled authors OPTIONAL * @param boolean $countOnly Count only OPTIONAL * * @return \XLite\Module\EdB\Librairie\Model\Author|void */ public function findOneByName($name, $onlyActive = true, $countOnly = false) { return $countOnly ? count($this->defineOneByNameQuery($name, $onlyActive)->getResult()) : $this->defineOneByNameQuery($name, $onlyActive)->getSingleResult(); } /** * Define query builder for findOneByName() method * * @param string $name Name * @param boolean $onlyActive Search only in enabled authors * * @return \Doctrine\ORM\QueryBuilder */ protected function defineOneByNameQuery($name, $onlyActive) { // let's put 'm' here just in case as well $qb = $this->createQueryBuilder('m') ->setParameter('name', $name) ->setMaxResults(1); if ($onlyActive) { $qb->andWhere('m.enabled = :true'); $qb->setParameter('true', true); } return $qb; } // }}} /** * Delete single entity * * @param \XLite\Model\AEntity $entity Entity to detach * * @return void */ protected function performDelete(\XLite\Model\AEntity $entity) { $alias = 'qd'; $qb = \XLite\Core\Database::getEM()->createQueryBuilder(); $qb->delete('XLite\Model\QuickData', $alias) ->andWhere($qb->expr()->eq("{$alias}.author", ':author')) ->setParameter('author', $entity); $qb->getQuery()->getResult(); parent::performDelete($entity); } /** * Insert single entity * * @param \XLite\Model\AEntity|array $entity Data to insert OPTIONAL * * @return void */ protected function performInsert($entity = null) { $entity = parent::performInsert($entity); if ($entity && !\XLite\Core\Database::getRepo('XLite\Model\Product')->getBlockQuickDataFlag()) { \XLite\Core\QuickData::getInstance()->updateAuthorData($entity); } return $entity; } }