Init
This commit is contained in:
8
app/model/Database/Entity/AbstractEntity.php
Normal file
8
app/model/Database/Entity/AbstractEntity.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
abstract class AbstractEntity
|
||||
{
|
||||
|
||||
}
|
||||
33
app/model/Database/Entity/Attributes/TCreatedAt.php
Normal file
33
app/model/Database/Entity/Attributes/TCreatedAt.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database\Entity\Attributes;
|
||||
|
||||
use App\Model\Utils\DateTime;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
trait TCreatedAt
|
||||
{
|
||||
|
||||
/**
|
||||
* @var DateTime
|
||||
* @ORM\Column(type="datetime", nullable=FALSE)
|
||||
*/
|
||||
protected $createdAt;
|
||||
|
||||
public function getCreatedAt(): DateTime
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctrine annotation
|
||||
*
|
||||
* @ORM\PrePersist
|
||||
* @internal
|
||||
*/
|
||||
public function setCreatedAt(): void
|
||||
{
|
||||
$this->createdAt = new DateTime();
|
||||
}
|
||||
|
||||
}
|
||||
27
app/model/Database/Entity/Attributes/TId.php
Normal file
27
app/model/Database/Entity/Attributes/TId.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database\Entity\Attributes;
|
||||
|
||||
trait TId
|
||||
{
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Column(type="integer", nullable=FALSE)
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
*/
|
||||
private $id;
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->id = null;
|
||||
}
|
||||
|
||||
}
|
||||
33
app/model/Database/Entity/Attributes/TUpdatedAt.php
Normal file
33
app/model/Database/Entity/Attributes/TUpdatedAt.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database\Entity\Attributes;
|
||||
|
||||
use App\Model\Utils\DateTime;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
trait TUpdatedAt
|
||||
{
|
||||
|
||||
/**
|
||||
* @var DateTime|NULL
|
||||
* @ORM\Column(type="datetime", nullable=TRUE)
|
||||
*/
|
||||
protected $updatedAt;
|
||||
|
||||
public function getUpdatedAt(): ?DateTime
|
||||
{
|
||||
return $this->updatedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctrine annotation
|
||||
*
|
||||
* @ORM\PreUpdate
|
||||
* @internal
|
||||
*/
|
||||
public function setUpdatedAt(): void
|
||||
{
|
||||
$this->updatedAt = new DateTime();
|
||||
}
|
||||
|
||||
}
|
||||
48
app/model/Database/Entity/DictType.php
Normal file
48
app/model/Database/Entity/DictType.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class DictType extends AbstractEntity
|
||||
{
|
||||
use TId;
|
||||
|
||||
public function __construct($short_name,$full_name)
|
||||
{
|
||||
$this->shortName = $short_name;
|
||||
$this->fullName = $full_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $shortName;
|
||||
|
||||
public function getShortName()
|
||||
{
|
||||
return $this->shortName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $fullName;
|
||||
|
||||
public function getFullName()
|
||||
{
|
||||
return $this->fullName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
76
app/model/Database/Entity/Dictionary.php
Normal file
76
app/model/Database/Entity/Dictionary.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Dictionary extends AbstractEntity
|
||||
{
|
||||
|
||||
use Tid;
|
||||
|
||||
public function __construct($name,$fullname)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->fullName = $fullname;
|
||||
$this->translations = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Model\Database\Entity\Translation", mappedBy="dictionary", cascade={"persist"})
|
||||
* @var Article[]|\Doctrine\Common\Collections\ArrayCollection
|
||||
*/
|
||||
protected $translations;
|
||||
|
||||
public function getTranslations()
|
||||
{
|
||||
return $this->translations;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Language", inversedBy="lang1_dicionaries")
|
||||
*/
|
||||
protected $lang1;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Language", inversedBy="lang2_dicionaries")
|
||||
*/
|
||||
protected $lang2;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $fullName;
|
||||
|
||||
public function setLang1($lang1)
|
||||
{
|
||||
$this->lang1 = $lang1;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setLang2($lang2)
|
||||
{
|
||||
$this->lang2 = $lang2;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
54
app/model/Database/Entity/Language.php
Normal file
54
app/model/Database/Entity/Language.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Language extends AbstractEntity
|
||||
{
|
||||
|
||||
use Tid;
|
||||
|
||||
public function __construct($shortname,$name)
|
||||
{
|
||||
$this->shortName = $shortname;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string",length=2, unique=true, options={"fixed" = true})
|
||||
*/
|
||||
protected $shortName;
|
||||
|
||||
public function getShortName()
|
||||
{
|
||||
return $this->shortName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string",length=32)
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/*
|
||||
* @ORM\OneToMany(targetEntity="Dictionary", mappedBy="language")
|
||||
*/
|
||||
protected $dictionaries1;
|
||||
|
||||
/*
|
||||
* @ORM\OneToMany(targetEntity="Dictionary", mappedBy="language")
|
||||
*/
|
||||
protected $dictionaries2;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
46
app/model/Database/Entity/Pronunciation.php
Normal file
46
app/model/Database/Entity/Pronunciation.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Pronunciation extends AbstractEntity
|
||||
{
|
||||
|
||||
use Tid;
|
||||
|
||||
public function __construct($type,$ipa,$filename=null)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->ipa = $ipa;
|
||||
$this->filename = $filename;
|
||||
$this->terms = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Term", mappedBy="pronunciations")
|
||||
*/
|
||||
private $terms;
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="PronunciationType", inversedBy="pronunciations")
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string",nullable=true)
|
||||
*/
|
||||
protected $ipa;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
*/
|
||||
protected $filename;
|
||||
}
|
||||
|
||||
?>
|
||||
32
app/model/Database/Entity/PronunciationTypes.php
Normal file
32
app/model/Database/Entity/PronunciationTypes.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\Tid;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class PronunciationType extends AbstractEntity
|
||||
{
|
||||
use Tid;
|
||||
|
||||
public function __construct($name,$fullName)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->fullName = $fullName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $fullName;
|
||||
}
|
||||
|
||||
?>
|
||||
32
app/model/Database/Entity/Suffix.php
Normal file
32
app/model/Database/Entity/Suffix.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Suffix extends AbstractEntity
|
||||
{
|
||||
use Tid;
|
||||
|
||||
public function __construct($text)
|
||||
{
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $text;
|
||||
|
||||
|
||||
public function getText()
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
42
app/model/Database/Entity/Term.php
Normal file
42
app/model/Database/Entity/Term.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(indexes={@ORM\Index(columns={"string1"}, flags={"fulltext"}),
|
||||
@ORM\Index(columns={"string2"}, flags={"fulltext"})})
|
||||
*/
|
||||
class Term extends AbstractEntity
|
||||
{
|
||||
|
||||
use Tid;
|
||||
|
||||
public function __construct(Dictionary $dictionary,$string)
|
||||
{
|
||||
$this->dictionary = $dictionary;
|
||||
$this->string1 = $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Dictionary", inversedBy="fullDict",cascade={"persist", "remove" })
|
||||
*/
|
||||
protected $dictionary;
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
90
app/model/Database/Entity/TermFlag.php
Normal file
90
app/model/Database/Entity/TermFlag.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class TermFlag extends AbstractEntity
|
||||
{
|
||||
|
||||
use Tid;
|
||||
|
||||
public function __construct($id,$class,$language,$code,$description)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->class = $class;
|
||||
$this->language = $language;
|
||||
$this->code = $code;
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="WordClass", inversedBy="flags")
|
||||
*/
|
||||
protected $class;
|
||||
|
||||
public function getClass()
|
||||
{
|
||||
return $this->class;
|
||||
}
|
||||
|
||||
public function setClass($class)
|
||||
{
|
||||
$this->class = $class;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Language", inversedBy="flags")
|
||||
*/
|
||||
protected $language;
|
||||
|
||||
public function getLanguage()
|
||||
{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
public function setLanguage($language)
|
||||
{
|
||||
$this->language = $language;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $code;
|
||||
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function setCode($code)
|
||||
{
|
||||
$this->code = $code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
77
app/model/Database/Entity/Translation.php
Normal file
77
app/model/Database/Entity/Translation.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Translation extends AbstractEntity
|
||||
{
|
||||
|
||||
use Tid;
|
||||
|
||||
public function __construct($dictionary,$lang1,$lang2,$lang_name1,$lang_name2,$direction)
|
||||
{
|
||||
$this->dictionary = $dictionary;
|
||||
$this->lang1 = $lang1;
|
||||
$this->lang2 = $lang2;
|
||||
$this->lang_name1 = $lang_name1;
|
||||
$this->lang_name2 = $lang_name2;
|
||||
$this->direction = $direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Dictionary", inversedBy="translations")
|
||||
*/
|
||||
protected $dictionary;
|
||||
|
||||
public function getDictionary()
|
||||
{
|
||||
return $this->dictionary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Language", inversedBy="translations1")
|
||||
*/
|
||||
protected $lang1;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Language", inversedBy="translations2")
|
||||
*/
|
||||
protected $lang2;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $lang_name1;
|
||||
|
||||
public function getLangName1()
|
||||
{
|
||||
return $this->lang_name1;
|
||||
}
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $lang_name2;
|
||||
|
||||
public function getLangName2()
|
||||
{
|
||||
return $this->lang_name2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="smallint")
|
||||
*/
|
||||
protected $direction;
|
||||
|
||||
public function getDirection()
|
||||
{
|
||||
return $this->direction;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
205
app/model/Database/Entity/User.php
Normal file
205
app/model/Database/Entity/User.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass="App\Model\Database\Repository\UserRepository")
|
||||
* @ORM\Table(name="`user`")
|
||||
* @ORM\HasLifecycleCallbacks
|
||||
*/
|
||||
class User extends AbstractEntity
|
||||
{
|
||||
|
||||
public const ROLE_ADMIN = 'admin';
|
||||
public const ROLE_USER = 'user';
|
||||
|
||||
public const STATE_FRESH = 1;
|
||||
public const STATE_ACTIVATED = 2;
|
||||
public const STATE_BLOCKED = 3;
|
||||
|
||||
public const STATES = [self::STATE_FRESH, self::STATE_BLOCKED, self::STATE_ACTIVATED];
|
||||
|
||||
use TId;
|
||||
use TCreatedAt;
|
||||
use TUpdatedAt;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string", length=255, nullable=FALSE, unique=false)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string", length=255, nullable=FALSE, unique=false)
|
||||
*/
|
||||
private $surname;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string", length=255, nullable=FALSE, unique=TRUE)
|
||||
*/
|
||||
private $email;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string", length=255, nullable=FALSE, unique=TRUE)
|
||||
*/
|
||||
private $username;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Column(type="integer", length=10, nullable=FALSE)
|
||||
*/
|
||||
private $state;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string", length=255, nullable=FALSE)
|
||||
*/
|
||||
private $password;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string", length=255, nullable=FALSE)
|
||||
*/
|
||||
private $role;
|
||||
|
||||
/**
|
||||
* @var DateTime|NULL
|
||||
* @ORM\Column(type="datetime", nullable=TRUE)
|
||||
*/
|
||||
private $lastLoggedAt;
|
||||
|
||||
public function __construct(string $name, string $surname, string $email, string $username, string $passwordHash)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->surname = $surname;
|
||||
$this->email = $email;
|
||||
$this->username = $username;
|
||||
$this->password = $passwordHash;
|
||||
|
||||
$this->role = self::ROLE_USER;
|
||||
$this->state = self::STATE_FRESH;
|
||||
}
|
||||
|
||||
public function changeLoggedAt(): void
|
||||
{
|
||||
$this->lastLoggedAt = new DateTime();
|
||||
}
|
||||
|
||||
public function getEmail(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function getUsername(): string
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function changeUsername(string $username): void
|
||||
{
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
public function getLastLoggedAt(): ?DateTime
|
||||
{
|
||||
return $this->lastLoggedAt;
|
||||
}
|
||||
|
||||
public function getRole(): string
|
||||
{
|
||||
return $this->role;
|
||||
}
|
||||
|
||||
public function setRole(string $role): void
|
||||
{
|
||||
$this->role = $role;
|
||||
}
|
||||
|
||||
public function getPasswordHash(): string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function changePasswordHash(string $password): void
|
||||
{
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
public function block(): void
|
||||
{
|
||||
$this->state = self::STATE_BLOCKED;
|
||||
}
|
||||
|
||||
public function activate(): void
|
||||
{
|
||||
$this->state = self::STATE_ACTIVATED;
|
||||
}
|
||||
|
||||
public function isActivated(): bool
|
||||
{
|
||||
return $this->state === self::STATE_ACTIVATED;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getSurname(): string
|
||||
{
|
||||
return $this->surname;
|
||||
}
|
||||
|
||||
public function getFullname(): string
|
||||
{
|
||||
return $this->name . ' ' . $this->surname;
|
||||
}
|
||||
|
||||
public function rename(string $name, string $surname): void
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->surname = $surname;
|
||||
}
|
||||
|
||||
public function getState(): int
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
public function setState(int $state): void
|
||||
{
|
||||
if (!in_array($state, self::STATES)) {
|
||||
throw new InvalidArgumentException(sprintf('Unsupported state %s', $state));
|
||||
}
|
||||
|
||||
$this->state = $state;
|
||||
}
|
||||
|
||||
public function getGravatar(): string
|
||||
{
|
||||
return 'https://www.gravatar.com/avatar/' . md5($this->email);
|
||||
}
|
||||
|
||||
public function toIdentity(): Identity
|
||||
{
|
||||
return new Identity($this->getId(), [$this->role], [
|
||||
'email' => $this->email,
|
||||
'name' => $this->name,
|
||||
'surname' => $this->surname,
|
||||
'state' => $this->state,
|
||||
'gravatar' => $this->getGravatar(),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
49
app/model/Database/Entity/WordClass.php
Normal file
49
app/model/Database/Entity/WordClass.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class WordClass extends AbstractEntity
|
||||
{
|
||||
|
||||
use Tid;
|
||||
|
||||
public function __construct($id,$name)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
28
app/model/Database/EntityManager.php
Normal file
28
app/model/Database/EntityManager.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database;
|
||||
|
||||
use App\Model\Database\Repository\AbstractRepository;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
use Nettrine\ORM\EntityManagerDecorator;
|
||||
|
||||
class EntityManager extends EntityManagerDecorator
|
||||
{
|
||||
|
||||
use TRepositories;
|
||||
|
||||
/**
|
||||
* @param string $entityName
|
||||
* @return AbstractRepository<T>|ObjectRepository<T>
|
||||
* @internal
|
||||
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
|
||||
* @phpstan-template T of object
|
||||
* @phpstan-param class-string<T> $entityName
|
||||
* @phpstan-return ObjectRepository<T>
|
||||
*/
|
||||
public function getRepository($entityName): ObjectRepository
|
||||
{
|
||||
return parent::getRepository($entityName);
|
||||
}
|
||||
|
||||
}
|
||||
49
app/model/Database/Repository/AbstractRepository.php
Normal file
49
app/model/Database/Repository/AbstractRepository.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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());
|
||||
}
|
||||
|
||||
}
|
||||
38
app/model/Database/Repository/DictTypes.php
Normal file
38
app/model/Database/Repository/DictTypes.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace App;
|
||||
|
||||
use Kdyby;
|
||||
use Nette;
|
||||
|
||||
class DictTypes extends Nette\Object
|
||||
{
|
||||
private $em;
|
||||
private $dicttypes;
|
||||
|
||||
public function __construct(Kdyby\Doctrine\EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->dicttypes = $em->getRepository(DictType::class);
|
||||
}
|
||||
|
||||
public function find($value)
|
||||
{
|
||||
return $this->dicttypes->find($value);
|
||||
}
|
||||
|
||||
|
||||
public function findBy($criteria = [],$orderBy = [])
|
||||
{
|
||||
return $this->dicttypes->findBy($criteria,$orderBy);
|
||||
}
|
||||
|
||||
public function findPairs($criteria,$value,$orderBy,$key)
|
||||
{
|
||||
return $this->dicttypes->findPairs($criteria,$value,$orderBy,$key);
|
||||
}
|
||||
|
||||
public function findAssoc($criteria, $key = NULL)
|
||||
{
|
||||
return $this->dicttypes->findAssoc($criteria,$key);
|
||||
}
|
||||
}
|
||||
27
app/model/Database/Repository/Dictionaries.php
Normal file
27
app/model/Database/Repository/Dictionaries.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace App;
|
||||
|
||||
use Kdyby;
|
||||
use Nette;
|
||||
|
||||
class Dictionaries extends Nette\Object
|
||||
{
|
||||
private $em;
|
||||
private $dictionaries;
|
||||
|
||||
public function __construct(Kdyby\Doctrine\EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->dictionaries = $em->getRepository(Dictionary::class);
|
||||
}
|
||||
|
||||
public function findAll($criteria = [],$orderBy = [])
|
||||
{
|
||||
return $this->dictionaries->findBy($criteria,$orderBy);
|
||||
}
|
||||
|
||||
public function findPairs($criteria,$value,$orderBy,$key)
|
||||
{
|
||||
return $this->dictionaries->findPairs($criteria,$value,$orderBy,$key);
|
||||
}
|
||||
}
|
||||
33
app/model/Database/Repository/Pronunciations.php
Normal file
33
app/model/Database/Repository/Pronunciations.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace App;
|
||||
|
||||
use Kdyby;
|
||||
use Nette;
|
||||
|
||||
class Pronunciations extends Nette\Object
|
||||
{
|
||||
private $em;
|
||||
private $pronunciations;
|
||||
|
||||
public function __construct(Kdyby\Doctrine\EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->pronunciations = $em->getRepository(Pronunciation::class);
|
||||
}
|
||||
|
||||
public function find($value)
|
||||
{
|
||||
return $this->pronunciations->find($value);
|
||||
}
|
||||
|
||||
|
||||
public function findBy($criteria = [],$orderBy = [])
|
||||
{
|
||||
return $this->pronunciations->findBy($criteria,$orderBy);
|
||||
}
|
||||
|
||||
public function findPairs($criteria,$value,$orderBy,$key)
|
||||
{
|
||||
return $this->pronunciations->findPairs($criteria,$value,$orderBy,$key);
|
||||
}
|
||||
}
|
||||
37
app/model/Database/Repository/TermFlags.php
Normal file
37
app/model/Database/Repository/TermFlags.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace App;
|
||||
|
||||
use Kdyby;
|
||||
use Nette;
|
||||
|
||||
class TermFlags extends Nette\Object
|
||||
{
|
||||
private $em;
|
||||
private $termFlags;
|
||||
|
||||
public function __construct(Kdyby\Doctrine\EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->termFlags = $em->getRepository(TermFlag::class);
|
||||
}
|
||||
|
||||
public function find($value)
|
||||
{
|
||||
return $this->termFlags->find($value);
|
||||
}
|
||||
|
||||
public function findBy($criteria = [],$orderBy = [])
|
||||
{
|
||||
return $this->termFlags->findBy($criteria,$orderBy);
|
||||
}
|
||||
|
||||
public function findPairs($criteria,$value,$orderBy,$key)
|
||||
{
|
||||
return $this->termFlags->findPairs($criteria,$value,$orderBy,$key);
|
||||
}
|
||||
|
||||
public function findAssoc($criteria,$key)
|
||||
{
|
||||
return $this->termFlags->findAssoc($criteria,$key);
|
||||
}
|
||||
}
|
||||
46
app/model/Database/Repository/Terms.php
Normal file
46
app/model/Database/Repository/Terms.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace App;
|
||||
|
||||
use Kdyby;
|
||||
use Nette;
|
||||
|
||||
class Terms extends Nette\Object
|
||||
{
|
||||
private $em;
|
||||
private $termsDao;
|
||||
private $terms;
|
||||
|
||||
public function __construct(Kdyby\Doctrine\EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->terms = $em->getRepository(Term::class);
|
||||
$this->termsDao = $em->getDao(Term::class);
|
||||
}
|
||||
|
||||
public function findAll($criteria = [],$orderBy = [])
|
||||
{
|
||||
return $this->terms->findBy($criteria,$orderBy);
|
||||
}
|
||||
|
||||
public function findBy($criteria = [],$orderBy = [])
|
||||
{
|
||||
return $this->terms->findBy($criteria,$orderBy);
|
||||
}
|
||||
|
||||
public function find($id)
|
||||
{
|
||||
return $this->terms->find($id);
|
||||
}
|
||||
|
||||
|
||||
public function findPairs($criteria,$value,$orderBy,$key)
|
||||
{
|
||||
return $this->terms->findPairs($criteria,$value,$orderBy,$key);
|
||||
}
|
||||
|
||||
public function fetch($query)
|
||||
{
|
||||
return $this->termsDao->fetch($query);
|
||||
}
|
||||
|
||||
}
|
||||
33
app/model/Database/Repository/Translations.php
Normal file
33
app/model/Database/Repository/Translations.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace App;
|
||||
|
||||
use Kdyby;
|
||||
use Nette;
|
||||
|
||||
class Translations extends Nette\Object
|
||||
{
|
||||
private $em;
|
||||
private $translations;
|
||||
|
||||
public function __construct(Kdyby\Doctrine\EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->translations = $em->getRepository(Translation::class);
|
||||
}
|
||||
|
||||
public function find($value)
|
||||
{
|
||||
return $this->translations->find($value);
|
||||
}
|
||||
|
||||
|
||||
public function findBy($criteria = [],$orderBy = [])
|
||||
{
|
||||
return $this->translations->findBy($criteria,$orderBy);
|
||||
}
|
||||
|
||||
public function findPairs($criteria,$value,$orderBy,$key)
|
||||
{
|
||||
return $this->translations->findPairs($criteria,$value,$orderBy,$key);
|
||||
}
|
||||
}
|
||||
22
app/model/Database/Repository/UserRepository.php
Normal file
22
app/model/Database/Repository/UserRepository.php
Normal 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]);
|
||||
}
|
||||
|
||||
}
|
||||
19
app/model/Database/TRepositories.php
Normal file
19
app/model/Database/TRepositories.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database;
|
||||
|
||||
use App\Model\Database\Entity\User;
|
||||
use App\Model\Database\Repository\UserRepository;
|
||||
|
||||
/**
|
||||
* @mixin EntityManager
|
||||
*/
|
||||
trait TRepositories
|
||||
{
|
||||
|
||||
public function getUserRepository(): UserRepository
|
||||
{
|
||||
return $this->getRepository(User::class);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user