Fixes nette3
This commit is contained in:
@@ -4,6 +4,8 @@ namespace App\Model\Database\Entity;
|
||||
|
||||
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
|
||||
@@ -17,14 +19,14 @@ class Dictionary extends AbstractEntity
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->fullName = $fullname;
|
||||
$this->translations = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
$this->translations = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Model\Database\Entity\Translation", mappedBy="dictionary", cascade={"persist"})
|
||||
* @var Article[]|\Doctrine\Common\Collections\ArrayCollection
|
||||
* @var Collection&iterable<Translation>
|
||||
*/
|
||||
protected $translations;
|
||||
protected Collection $translations;
|
||||
|
||||
public function getTranslations()
|
||||
{
|
||||
@@ -33,14 +35,16 @@ class Dictionary extends AbstractEntity
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Language", inversedBy="lang1_dicionaries")
|
||||
* @ORM\ManyToOne(targetEntity="Language", inversedBy="dictionaries1")
|
||||
* @ORM\JoinColumn(name="lang1_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $lang1;
|
||||
protected ?Language $lang1;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Language", inversedBy="lang2_dicionaries")
|
||||
* @ORM\ManyToOne(targetEntity="Language", inversedBy="dictionaries2")
|
||||
* @ORM\JoinColumn(name="lang2_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $lang2;
|
||||
protected ?Language $lang2;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
@@ -40,14 +41,16 @@ class Language extends AbstractEntity
|
||||
}
|
||||
|
||||
/*
|
||||
* @var Collection&iterable<Dictionary>
|
||||
* @ORM\OneToMany(targetEntity="Dictionary", mappedBy="language")
|
||||
*/
|
||||
protected $dictionaries1;
|
||||
protected Collection $dictionaries1;
|
||||
|
||||
/*
|
||||
* @var Collection&iterable<Dictionary>
|
||||
* @ORM\OneToMany(targetEntity="Dictionary", mappedBy="language")
|
||||
*/
|
||||
protected $dictionaries2;
|
||||
protected Collection $dictionaries2;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -26,16 +26,94 @@ class Term extends AbstractEntity
|
||||
*/
|
||||
protected $dictionary;
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
public function getId()
|
||||
protected $string1;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $string2;
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Suffix")
|
||||
*/
|
||||
protected $suffix1;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Suffix")
|
||||
*/
|
||||
protected $suffix2;
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="DictType")
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Pronunciation", inversedBy="terms")
|
||||
* @ORM\JoinTable(name="terms_pronunciations")
|
||||
*/
|
||||
protected $pronunciations;
|
||||
|
||||
public function setType(DictType $type)
|
||||
{
|
||||
return $this->id;
|
||||
$this->type = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string",nullable=true)
|
||||
*/
|
||||
protected $member;
|
||||
|
||||
public function setMember($member)
|
||||
{
|
||||
$this->member = $member;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMember()
|
||||
{
|
||||
return $this->member;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="smallint",nullable=true)
|
||||
*/
|
||||
protected $order2;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="json_array",nullable=true)
|
||||
*/
|
||||
protected $flags;
|
||||
|
||||
public function getFlags()
|
||||
{
|
||||
return $this->flags;
|
||||
}
|
||||
|
||||
public function setFlags($flags)
|
||||
{
|
||||
$this->flags = $flags;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOrder2()
|
||||
{
|
||||
return $this->order2;
|
||||
}
|
||||
|
||||
public function setOrder2($order2)
|
||||
{
|
||||
$this->order2 = $order2;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
57
app/model/Database/Repository/Advanced/TermsQuery.php
Normal file
57
app/model/Database/Repository/Advanced/TermsQuery.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
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)
|
||||
@@ -12,5 +13,8 @@ use App\Model\Database\Entity\Translation;
|
||||
*/
|
||||
class TranslationRepository extends AbstractRepository
|
||||
{
|
||||
|
||||
public function findOneByEmail(string $email): ?Translation
|
||||
{
|
||||
return $this->findOneBy(['email' => $email]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,11 @@ namespace App\Model\Database;
|
||||
|
||||
use App\Model\Database\Entity\User;
|
||||
use App\Model\Database\Entity\Translation;
|
||||
use App\Model\Database\Entity\Term;
|
||||
use App\Model\Database\Entity\TermFlag;
|
||||
use App\Model\Database\Entity\Pronunciation;
|
||||
use App\Model\Database\Entity\DictType;
|
||||
use App\Model\Database\Entity\Dictionary;
|
||||
use App\Model\Database\Repository\UserRepository;
|
||||
use App\Model\Database\Repository\TranslationRepository;
|
||||
use App\Model\Database\Repository\TermRepository;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php declare(strict_types = 1);
|
||||
<?php //declare(strict_types = 1);
|
||||
|
||||
namespace App\Modules\Front\Home;
|
||||
|
||||
use App\Modules\Front\BaseFrontPresenter;
|
||||
use Nette;
|
||||
use Nette\Utils\Strings;
|
||||
use Nette\Application\UI;
|
||||
@@ -9,25 +10,16 @@ use Dict\OggResponse;
|
||||
use Nette\Application\Responses\JsonResponse;
|
||||
use AlesWita\VisualPaginator\VisualPaginator;
|
||||
use AlesWita\VisualPaginator\VisualPaginatorFactory;
|
||||
|
||||
use App\Modules\Front\BaseFrontPresenter;
|
||||
|
||||
use App\Model\Database\EntityManager;
|
||||
use App\Model\Database\Entity\Dictionary;
|
||||
use App\Model\Database\Entity\Translation;
|
||||
use App\Model\Database\Repository\TranslationRepository;
|
||||
final class HomePresenter extends BaseFrontPresenter
|
||||
{
|
||||
|
||||
|
||||
/** @inject @var \App\Translations */
|
||||
public $repoTranslations;
|
||||
/** @inject @var \App\Pronunciations */
|
||||
public $repoPronunciations;
|
||||
/** @inject @var \App\Dictionaries */
|
||||
public $repoDictionaries;
|
||||
/** @inject @var \App\DictTypes */
|
||||
public $repoDictTypes;
|
||||
/** @inject @var \App\Terms */
|
||||
public $repoTerms;
|
||||
/** @inject @var \App\TermFlags */
|
||||
public $repoTermFlags;
|
||||
/** @inject @var \App\Model\Database\EntityManager */
|
||||
public $em;
|
||||
|
||||
private $translations;
|
||||
private $dictionaries;
|
||||
@@ -42,8 +34,8 @@ final class HomePresenter extends BaseFrontPresenter
|
||||
|
||||
protected function startup()
|
||||
{
|
||||
$trs = $this->repoTranslations->findBy([],['id' => 'ASC','direction'=>'ASC']);
|
||||
$drs = $this->repoDictionaries->findPairs([],'name',[],'id');
|
||||
$trs = $this->em->getRepository(Translation::class)->findBy([],['id' => 'ASC','direction'=>'ASC']);
|
||||
$drs = $this->em->getRepository(Dictionary::class)->findPairs([],'name',[],'id');
|
||||
$select = [];
|
||||
foreach ($trs as $t) {
|
||||
$lang1 = $t->langName1;
|
||||
@@ -69,7 +61,7 @@ final class HomePresenter extends BaseFrontPresenter
|
||||
|
||||
protected function doSearch($query,$translation,$term,$clen = null,$paginate = true)
|
||||
{
|
||||
$t = $this->repoTranslations->find($translation);
|
||||
$t = $this->em->getTranslationRepository()->find($translation);
|
||||
|
||||
if ($term) $this->term = $term;
|
||||
if ($translation) $this->translation = $translation;
|
||||
@@ -125,7 +117,7 @@ final class HomePresenter extends BaseFrontPresenter
|
||||
$clen = $values->clen;
|
||||
$term = $values->string;
|
||||
|
||||
$result = $this->doSearch('\\App\\TermsQuery',$translation,$term,$clen);
|
||||
$result = $this->doSearch('\\App\\Model\\Database\\Repository\\TermsQuery',$translation,$term,$clen);
|
||||
|
||||
$this->template->result = $result;
|
||||
}
|
||||
@@ -153,7 +145,7 @@ final class HomePresenter extends BaseFrontPresenter
|
||||
|
||||
public function actionPlay($id = null)
|
||||
{
|
||||
$pron = $this->repoPronunciations->find(['id'=>$id]);
|
||||
$pron = $this->em->getPronunciationRepository()->find(['id'=>$id]);
|
||||
$basepath = $this->getHttpRequest()->url->basePath . "/media";
|
||||
$oggResp = new OggResponse($id,$pron->filename);
|
||||
return $this->sendResponse($oggResp);
|
||||
@@ -174,7 +166,7 @@ final class HomePresenter extends BaseFrontPresenter
|
||||
if ($this->getRequest()->isMethod('GET') && $this->term) {
|
||||
$this['searchForm']['string']->setValue($this->term);
|
||||
$t = $this->slugs[$this->slug];
|
||||
$result = $this->doSearch('\\App\\TermsQuery',$t->id,$this->term);
|
||||
$result = $this->doSearch('\\App\\Model\\Database\\Repository\\TermsQuery',$t->id,$this->term);
|
||||
if ($result) $this->template->result = $result;
|
||||
}
|
||||
|
||||
@@ -279,4 +271,4 @@ final class HomePresenter extends BaseFrontPresenter
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
39
app/modules/Ogg/OggResponse.php
Normal file
39
app/modules/Ogg/OggResponse.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Dict;
|
||||
use Nette;
|
||||
/**
|
||||
* CSV download response.
|
||||
* Under New BSD license.
|
||||
*
|
||||
* @package Nette\Application\Responses
|
||||
*/
|
||||
class OggResponse extends Nette\Object implements Nette\Application\IResponse
|
||||
{
|
||||
private $directory;
|
||||
private $contentType;
|
||||
private $addHeading;
|
||||
private $filename;
|
||||
private $id;
|
||||
|
||||
public function __construct($id = null,$filename = null, $basepath = __DIR__ . "/../../www", $addHeading = TRUE,$contentType = 'audio/ogg')
|
||||
{
|
||||
$this->contentType = $contentType;
|
||||
$this->addHeading = $addHeading;
|
||||
$this->directory = $basepath . "/media/";
|
||||
$this->filename = $this->directory . "/".$filename;
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
|
||||
{
|
||||
$httpResponse->setContentType($this->contentType);
|
||||
$attachment = 'attachment';
|
||||
if (!empty($this->id)) {
|
||||
$attachment .= '; filename="' . $this->id .".ogg" . '"';
|
||||
}
|
||||
$httpResponse->setHeader('Content-Disposition', $attachment);
|
||||
$httpResponse->setHeader('Content-Length', filesize($this->filename));
|
||||
readfile($this->filename);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user