First nett3.0 webpage version

This commit is contained in:
2022-01-17 16:40:13 +01:00
parent c801608fe8
commit 59d4ef9966
14 changed files with 1149 additions and 64 deletions

View File

@@ -46,4 +46,41 @@ abstract class AbstractRepository extends EntityRepository
}, $qb->getQuery()->getArrayResult());
}
/**
* Fetches all records and returns an associative array indexed by key
*
* @param array $criteria
* @param string $key
*
* @throws \Exception|QueryException
* @return array
*/
public function findAssoc(array $criteria = [],String $key = NULL)
{
if (!is_array($criteria)) {
$key = $criteria;
$criteria = [];
}
$qb = $this->createQueryBuilder('e')
->resetDQLPart('from')->from($this->getEntityName(), 'e', 'e.' . $key);
foreach ($criteria as $k => $v) {
if (is_array($v)) {
$qb->andWhere(sprintf('e.%s IN(:%s)', $k, $k))->setParameter($k, array_values($v));
} else {
$qb->andWhere(sprintf('e.%s = :%s', $k, $k))->setParameter($k, $v);
}
}
try {
return $qb->getQuery()->getResult();
} catch (\Exception $e) {
throw $this->handleException($e, $qb);
}
}
}