/**
  * @see BackendAdapter::findByFinder
  */
 public function findByFinder(Finder $finder)
 {
     $resources = $this->classNameToResources[$finder->getResultClass()];
     $params = $this->finderParametersToInternalParameters($finder);
     $tableName = $resources['table'];
     $conn = $this->getConnection();
     $qb = $conn->createQueryBuilder();
     $qb->select("id")->from($tableName, 't');
     $bindParams = array();
     foreach ($params as $param => $value) {
         if ($value === null) {
             $qb->andWhere("t.{$param} IS NULL");
         } else {
             $qb->andWhere("t.{$param} = :{$param}");
             $bindParams[$param] = $value;
         }
     }
     $sql = $qb->getSQL();
     $stmt = $conn->prepare($sql);
     foreach ($bindParams as $param => $value) {
         $stmt->bindValue($param, $value);
     }
     $stmt->execute();
     $ret = $stmt->fetchAll(PDO::FETCH_ASSOC);
     return array_map(function ($ret) {
         return $ret['id'];
     }, $ret);
 }
Esempio n. 2
0
 /**
  * @param  Finder $finder
  * @return array
  */
 protected function finderParametersToInternalParameters(Finder $finder)
 {
     $ret = array();
     foreach ($finder->getParameters() as $key => $value) {
         $ret[$this->finderMap[$finder->getResultClass()][$key]] = $value;
     }
     return $ret;
 }
Esempio n. 3
0
 /**
  * @test
  */
 public function getResultClassShouldReturnCorrectClassName()
 {
     $expected = $this->getExpectedResultClass();
     $this->assertEquals($expected, $this->finder->getResultClass());
 }