54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
<?php declare(strict_types = 1);
|
|
|
|
namespace App\Model\Database\Facade;
|
|
|
|
use App\Model\Database\Entity\Term;
|
|
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()
|
|
{
|
|
$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',"test"."%");
|
|
$query->orderBy('t.string1,t.id','ASC');
|
|
} else if ($this->direction == 2) {
|
|
$query->where('t.string2 LIKE :str')->setParameter('str', "test"."%");
|
|
$query->orderBy('t.string2','ASC');
|
|
$query->addOrderBy('t.order2','ASC');
|
|
}
|
|
$query->andWhere('t.dictionary = :dict')->setParameter(':dict',1);
|
|
//if ($this->clen)
|
|
// $query->andWhere('t.member LIKE :clen')->setParameter('clen','%'."".'%');
|
|
|
|
return $query->getQuery()->getResult();
|
|
}
|
|
|
|
}
|