Basic functionality
This commit is contained in:
124
app/model/Database/Facade/TermFacade.php
Executable file
124
app/model/Database/Facade/TermFacade.php
Executable file
@@ -0,0 +1,124 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database\Facade;
|
||||
|
||||
use App\Model\Database\Entity\Dictionary;
|
||||
use App\Model\Database\Entity\Term;
|
||||
use App\Model\Database\Entity\Translation;
|
||||
use App\Model\Database\EntityManager;
|
||||
|
||||
|
||||
class TermFacade
|
||||
{
|
||||
|
||||
/** @var EntityManager */
|
||||
private $em;
|
||||
private $direction;
|
||||
|
||||
public function __construct(
|
||||
EntityManager $em
|
||||
)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function setDirection(int $direction)
|
||||
{
|
||||
$this->direction = $direction;
|
||||
}
|
||||
/**
|
||||
* @param mixed[] $data
|
||||
*/
|
||||
public function findByString(String $term,Dictionary $d,String $clen = null)
|
||||
{
|
||||
$query = $this->em->createQueryBuilder('t')->select('t')
|
||||
->addSelect('s1')
|
||||
->addSelect('s2')
|
||||
->from(Term::class,'t')
|
||||
->leftJoin('t.suffix1','s1')
|
||||
->leftJoin('t.suffix2','s2');
|
||||
if ($this->direction == 1) {
|
||||
$query->where('t.string1 LIKE :str')->setParameter('str', $term."%");
|
||||
$query->orderBy('t.string1,t.id','ASC');
|
||||
} else if ($this->direction == 2) {
|
||||
$query->where('t.string2 LIKE :str')->setParameter('str', $term."%");
|
||||
$query->orderBy('t.string2','ASC');
|
||||
$query->addOrderBy('t.order2','ASC');
|
||||
}
|
||||
$query->andWhere('t.dictionary = :dict')->setParameter(':dict',$d->id);
|
||||
if ($clen)
|
||||
$query->andWhere('t.member LIKE :clen')->setParameter('clen','%'.$clen.'%');
|
||||
|
||||
return $query->getQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $data
|
||||
*/
|
||||
public function findByStringQuick(String $string, Dictionary $d, String $clen = null)
|
||||
{
|
||||
$query = $this->em->createQueryBuilder('t')->select('DISTINCT t.string1 AS str')->from(Term::class,'t');
|
||||
if ($this->direction == 1) {
|
||||
$query->where('t.string1 LIKE :str')->setParameter('str',$string."%");
|
||||
$query->orderBy('t.string1','ASC');
|
||||
} else if ($this->direction == 2) {
|
||||
$query->where('t.string2 LIKE :str')->setParameter('str', $string."%");
|
||||
$query->orderBy('t.string2','ASC');
|
||||
}
|
||||
$query->andWhere('t.dictionary = :dict')->setParameter(':dict',$d->id);
|
||||
|
||||
return $query->getQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $data
|
||||
*/
|
||||
public function findByStringFull(String $string, Dictionary $d, String $clen = null, $like = true)
|
||||
{
|
||||
|
||||
$search = $string;
|
||||
if ($like) $search = $search . "%";
|
||||
|
||||
$query = $this->em->createQueryBuilder('t')->select('t')
|
||||
->addSelect('s1')
|
||||
->addSelect('s2')
|
||||
->addSelect('p')
|
||||
->from(Term::class,'t')
|
||||
->leftJoin('t.suffix1','s1')
|
||||
->leftJoin('t.suffix2','s2')
|
||||
->leftJoin('t.pronunciations','p');
|
||||
if ($this->direction == 1) {
|
||||
$query->where('t.string1 LIKE :str')->setParameter('str',$search);
|
||||
$query->orderBy('t.id','ASC');
|
||||
$query->addOrderBy('p.id','ASC');
|
||||
} else if ($this->direction == 2) {
|
||||
$query->where('t.string2 LIKE :str')->setParameter('str', $search);
|
||||
$query->orderBy('t.string2','ASC');
|
||||
$query->addOrderBy('t.order2','ASC');
|
||||
}
|
||||
$query->andWhere('t.dictionary = :dict')->setParameter(':dict',$d->id);
|
||||
if ($clen)
|
||||
$query->andWhere('t.member LIKE :clen')->setParameter('clen','%'.$clen.'%');
|
||||
|
||||
return $query->getQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $data
|
||||
*/
|
||||
public function findByStringSimple(String $string, Dictionary $d, String $clen = null)
|
||||
{
|
||||
$query = $this->em->createQueryBuilder('t')->select('t')->from(Term::class,'t');
|
||||
if ($this->direction == 1) {
|
||||
$query->where('t.string1 LIKE :str')->setParameter('str',$string."%");
|
||||
$query->orderBy('t.id','ASC');
|
||||
} else if ($this->direction == 2) {
|
||||
$query->where('t.string2 LIKE :str')->setParameter('str', $string."%");
|
||||
$query->orderBy('t.string2','ASC');
|
||||
$query->addOrderBy('t.order2','ASC');
|
||||
}
|
||||
$query->andWhere('t.dictionary = :dict')->setParameter(':dict',$d->id);
|
||||
|
||||
return $query->getQuery();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user