Basic functionality

This commit is contained in:
2022-03-12 16:25:30 +01:00
parent f3beaa64cf
commit acc21b7b24
137 changed files with 12647 additions and 5089 deletions

View File

@@ -0,0 +1,86 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Repository;
use Doctrine\ORM\EntityRepository;
/**
* @phpstan-template TEntityClass of object
* @phpstan-extends EntityRepository<TEntityClass>
*/
abstract class AbstractRepository extends EntityRepository
{
/**
* Fetches all records like $key => $value pairs
*
* @param mixed[] $criteria
* @param mixed[] $orderBy
* @return mixed[]
*/
public function findPairs(?string $key, string $value, array $criteria = [], array $orderBy = []): array
{
if ($key === null) {
$key = $this->getClassMetadata()->getSingleIdentifierFieldName();
}
$qb = $this->createQueryBuilder('e')
->select(['e.' . $value, 'e.' . $key])
->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);
}
}
foreach ($orderBy as $column => $order) {
$qb->addOrderBy($column, $order);
}
return array_map(function ($row) {
return reset($row);
}, $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);
}
}
}

View File

@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Repository;
use App\Model\Database\Entity\DictType;
/**
* @method DictType|NULL find($id, ?int $lockMode = NULL, ?int $lockVersion = NULL)
* @method DictType|NULL findOneBy(array $criteria, array $orderBy = NULL)
* @method DictType[] findAll()
* @method DictType[] findBy(array $criteria, array $orderBy = NULL, ?int $limit = NULL, ?int $offset = NULL)
* @extends AbstractRepository<DictType>
*/
class DictTypeRepository extends AbstractRepository
{
}

View File

@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Repository;
use App\Model\Database\Entity\Dictionary;
/**
* @method Dictionary|NULL find($id, ?int $lockMode = NULL, ?int $lockVersion = NULL)
* @method Dictionary|NULL findOneBy(array $criteria, array $orderBy = NULL)
* @method Dictionary[] findAll()
* @method Dictionary[] findBy(array $criteria, array $orderBy = NULL, ?int $limit = NULL, ?int $offset = NULL)
* @extends AbstractRepository<Dictionary>
*/
class DictionaryRepository extends AbstractRepository
{
}

View File

@@ -0,0 +1,16 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Repository;
use App\Model\Database\Entity\Pronunciation;
/**
* @method Pronunciation|NULL find($id, ?int $lockMode = NULL, ?int $lockVersion = NULL)
* @method Pronunciation|NULL findOneBy(array $criteria, array $orderBy = NULL)
* @method Pronunciation[] findAll()
* @method Pronunciation[] findBy(array $criteria, array $orderBy = NULL, ?int $limit = NULL, ?int $offset = NULL)
* @extends AbstractRepository<Pronunciation>
*/
class PronunciationRepository extends AbstractRepository
{
}

View File

@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Repository;
use App\Model\Database\Entity\TermFlag;
/**
* @method TermFlag|NULL find($id, ?int $lockMode = NULL, ?int $lockVersion = NULL)
* @method TermFlag|NULL findOneBy(array $criteria, array $orderBy = NULL)
* @method TermFlag[] findAll()
* @method TermFlag[] findBy(array $criteria, array $orderBy = NULL, ?int $limit = NULL, ?int $offset = NULL)
* @extends AbstractRepository<TermFlag>
*/
class TermFlagRepository extends AbstractRepository
{
}

View File

@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Repository;
use App\Model\Database\Entity\Term;
/**
* @method Term|NULL find($id, ?int $lockMode = NULL, ?int $lockVersion = NULL)
* @method Term|NULL findOneBy(array $criteria, array $orderBy = NULL)
* @method Term[] findAll()
* @method Term[] findBy(array $criteria, array $orderBy = NULL, ?int $limit = NULL, ?int $offset = NULL)
* @extends AbstractRepository<Term>
*/
class TermRepository extends AbstractRepository
{
}

View File

@@ -0,0 +1,57 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Repository;
use Doctrine\ORM\EntityRepository;
use App\Model\Database\Entity\Dictionary;
class TermsQuery extends EntityRepository
{
private Dictionary $dictionary;
private String $string;
private Int $direction;
private String $clen;
public function __construct(Dictionary $dict,String $string,Int $direction = 1)
{
$this->dictionary = $dict;
$this->string = $string;
$this->direction = $direction;
}
public function withClen(String $clen)
{
if ($clen != null && $clen != '')
$this->clen = $clen;
}
/**
* Fetches all records like $key => $value pairs
*
* @param mixed[] $criteria
* @param mixed[] $orderBy
* @return mixed[]
*/
protected function doCreateQuery()
{
$query = $this->createQueryBuilder('t')->select('t')
->addSelect('s1')
->addSelect('s2')
->leftJoin('t.suffix1','s1')
->leftJoin('t.suffix2','s2');
if ($this->direction == 1) {
$query->where('t.string1 LIKE :str')->setParameter('str',$this->string."%");
$query->orderBy('t.string1,t.id','ASC');
} else if ($this->direction == 2) {
$query->where('t.string2 LIKE :str')->setParameter('str', $this->string."%");
$query->orderBy('t.string2','ASC');
$query->addOrderBy('t.order2','ASC');
}
$query->andWhere('t.dictionary = :dict')->setParameter(':dict',$this->dictionary->id);
if ($this->clen)
$query->andWhere('t.member LIKE :clen')->setParameter('clen','%'.$this->clen.'%');
return $query;
}
}

View File

@@ -0,0 +1,20 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Repository;
use App\Model\Database\Entity\Translation;
/**
* @method Translation|NULL find($id, ?int $lockMode = NULL, ?int $lockVersion = NULL)
* @method Translation|NULL findOneBy(array $criteria, array $orderBy = NULL)
* @method Translation[] findAll()
* @method Translation[] findBy(array $criteria, array $orderBy = NULL, ?int $limit = NULL, ?int $offset = NULL)
* @extends AbstractRepository<Translation>
*/
class TranslationRepository extends AbstractRepository
{
public function findOneByEmail(string $email): ?Translation
{
return $this->findOneBy(['email' => $email]);
}
}

View File

@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Repository;
use App\Model\Database\Entity\User;
/**
* @method User|NULL find($id, ?int $lockMode = NULL, ?int $lockVersion = NULL)
* @method User|NULL findOneBy(array $criteria, array $orderBy = NULL)
* @method User[] findAll()
* @method User[] findBy(array $criteria, array $orderBy = NULL, ?int $limit = NULL, ?int $offset = NULL)
* @extends AbstractRepository<User>
*/
class UserRepository extends AbstractRepository
{
public function findOneByEmail(string $email): ?User
{
return $this->findOneBy(['email' => $email]);
}
}