First nett3.0 webpage version
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
<?php
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use App\Model\Database\Entity\Attributes\TCreatedAt;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
use App\Model\Database\Entity\Attributes\TUpdatedAt;
|
||||
use App\Model\Exception\Logic\InvalidArgumentException;
|
||||
use App\Model\Security\Identity;
|
||||
use App\Model\Utils\DateTime;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Entity(repositoryClass="App\Model\Database\Repository\DictTypeRepository")
|
||||
* @ORM\HasLifecycleCallbacks
|
||||
*/
|
||||
class DictType extends AbstractEntity
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user