Merge pull request #4 from stof/orm

Implemented the ORM transformer
This commit is contained in:
Thibault Duplessis 2011-05-09 16:13:50 -07:00
commit cae2ebf20f
3 changed files with 12 additions and 4 deletions

View file

@ -81,7 +81,7 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
* @param string $class the model class
* @param string $identifierField like 'id'
* @param array $identifierValues ids values
* @param mixed $hydrate whether or not to hydrate the objects, false returns arrays
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
* @return array of objects or arrays
*/
protected abstract function findByIdentifiers($class, $identifierField, array $identifierValues, $hydrate);

View file

@ -18,7 +18,7 @@ class ElasticaToModelTransformer extends AbstractElasticaToModelTransformer
* @param string $class the model class
* @param string $identifierField like 'id'
* @param array $identifierValues ids values
* @param mixed $hydrate whether or not to hydrate the objects, false returns arrays
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
* @return array of objects or arrays
*/
protected function findByIdentifiers($class, $identifierField, array $identifierValues, $hydrate)

View file

@ -2,7 +2,9 @@
namespace FOQ\ElasticaBundle\Doctrine\ORM;
use FOQ\ElasticaBundle\Doctrine\AbstractElasticaToModelTransformer;
use Elastica_Document;
use Doctrine\ORM\Query;
/**
* Maps Elastica documents with Doctrine objects
@ -17,11 +19,17 @@ class ElasticaToModelTransformer extends AbstractElasticaToModelTransformer
* @param string $class the model class
* @param string $identifierField like 'id'
* @param array $identifierValues ids values
* @param mixed $hydrate whether or not to hydrate the objects, false returns arrays
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
* @return array of objects or arrays
*/
protected function findByIdentifiers($class, $identifierField, array $identifierValues, $hydrate)
{
throw new \Exception('Not implemented yet. Implement me! See ElasticaToModelDoctrineMongoDBTransformer as an example.');
$hydratationMode = $hydrate ? Query::HYDRATE_OBJECT : Query::HYDRATE_ARRAY;
$qb = $this->objectManager
->getRepository($class)
->createQueryBuilder('o');
$qb->where($qb->expr()->in('o.'.$identifierField, $identifierValues));
return $qb->getQuery()->setHydrationMode($hydrationMode)->execute();
}
}