Example #1
0
 /**
  * Search for existing translation record or
  * it`s field translation only
  * 
  * @param EntityManager $em
  * @param mixed $entityId
  * @param string $entityClass
  * @param string $locale
  * @param string $field
  * @throws Translatable\Exception if unit of work has pending inserts
  *      to avoid infinite loop
  * @return mixed - null if nothing is found, Translation otherwise
  */
 protected function _findTranslation(EntityManager $em, $entityId, $entityClass, $locale, $field)
 {
     if ($em->getUnitOfWork()->hasPendingInsertions()) {
         throw Exception::pendingInserts();
     }
     $qb = $em->createQueryBuilder();
     $qb->select('trans')->from($this->getTranslationClass($entityClass), 'trans')->where('trans.foreignKey = :entityId', 'trans.locale = :locale', 'trans.field = :field', 'trans.entity = :entityClass');
     $q = $qb->getQuery();
     $result = $q->execute(compact('field', 'locale', 'entityId', 'entityClass'), Query::HYDRATE_OBJECT);
     if ($result) {
         return array_shift($result);
     }
     return null;
 }