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,8 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Entity;
abstract class AbstractEntity
{
use \Nette\SmartObject;
}

View 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();
}
}

View File

@@ -0,0 +1,29 @@
<?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
*
* @property int $id
*/
private $id;
public function getId(): int
{
return $this->id;
}
public function __clone()
{
$this->id = null;
}
}

View 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();
}
}

View File

@@ -0,0 +1,50 @@
<?php declare(strict_types = 1);
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(repositoryClass="App\Model\Database\Repository\DictTypeRepository")
* @ORM\HasLifecycleCallbacks
*
* @property int $id
* @property String $shortName
* @property String $fullName
*/
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;
}
}
?>

View File

@@ -0,0 +1,94 @@
<?php declare(strict_types = 1);
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(repositoryClass="App\Model\Database\Repository\DictionaryRepository")
* @ORM\Table(name="`dictionary`")
* @ORM\HasLifecycleCallbacks
*
* @property int $id
* @property String $name
* @property String $fullname
* @property Term $terms
* @property Language $lang1
* @property Language $lang2
*/
class Dictionary extends AbstractEntity
{
use Tid;
public function __construct($name,$fullname)
{
$this->name = $name;
$this->fullName = $fullname;
$this->translations = new ArrayCollection();
}
/**
* @ORM\OneToMany(targetEntity="\App\Model\Database\Entity\Translation", mappedBy="dictionary", cascade={"persist"})
* @var Collection&iterable<Translation>
*/
protected Collection $translations;
public function getTranslations()
{
return $this->translations;
}
/**
* @ORM\OnetoMany(targetEntity="\App\Model\Database\Entity\Term", mappedBy="dictionary")
* @var Collection&iterable<Term>
*/
protected Collection $terms;
/**
* @ORM\ManyToOne(targetEntity="Language", inversedBy="dictionaries1")
* @ORM\JoinColumn(name="lang1_id", referencedColumnName="id")
*/
protected ?Language $lang1;
/**
* @ORM\ManyToOne(targetEntity="Language", inversedBy="dictionaries2")
* @ORM\JoinColumn(name="lang2_id", referencedColumnName="id")
*/
protected ?Language $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;
}
}
?>

View File

@@ -0,0 +1,65 @@
<?php declare(strict_types = 1);
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(repositoryClass="App\Model\Database\Repository\LanguageRepository")
* @ORM\HasLifecycleCallbacks
*
* @property int $id
* @property String $name
* @property String $shortName
* @property Dictionary $dictionaries1
* @property Dictionary $dictionaries2
*
*/
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;
}
/*
* @var Collection&iterable<Dictionary>
* @ORM\OneToMany(targetEntity="Dictionary", mappedBy="language")
*/
protected Collection $dictionaries1;
/*
* @var Collection&iterable<Dictionary>
* @ORM\OneToMany(targetEntity="Dictionary", mappedBy="language")
*/
protected Collection $dictionaries2;
}
?>

View File

@@ -0,0 +1,85 @@
<?php
namespace App\Model\Database\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Model\Database\Entity\Attributes\TId;
/**
* @ORM\Entity(repositoryClass="App\Model\Database\Repository\PronunciationRepository")
* @ORM\HasLifecycleCallbacks
*
* @property int $id
* @property Term $terms
* @property PronunciationType $type
* @property String $ipa
* @property String $filename
*/
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;
/**
* Get the value of filename
*/
public function getFilename()
{
return $this->filename;
}
/**
* Get the value of terms
*/
public function getTerms()
{
return $this->terms;
}
/**
* Get the value of ipa
*/
public function getIpa()
{
return $this->ipa;
}
/**
* Get the value of type
*/
public function getType()
{
return $this->type;
}
}
?>

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Model\Database\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Model\Database\Entity\Attributes\Tid;
/**
* @ORM\Entity(repositoryClass="App\Model\Database\Repository\PronunciationTypeRepository")
* @ORM\HasLifecycleCallbacks
*
* @property int $id
* @property String $name
* @property String $fullName
*/
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;
}
?>

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Model\Database\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Model\Database\Entity\Attributes\TId;
/**
* @ORM\Entity(repositoryClass="App\Model\Database\Repository\SuffixRepository")
* @ORM\HasLifecycleCallbacks
*
* @property int $id
* @property String $text
*/
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;
}
}
?>

View File

@@ -0,0 +1,231 @@
<?php
namespace App\Model\Database\Entity;
use App\Model\Database\Entity\Attributes\TId;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Proxy\Proxy;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Model\Database\Repository\TermRepository")
* @ORM\HasLifecycleCallbacks
* @ORM\Table(indexes={@ORM\Index(columns={"string1"}, flags={"fulltext"}),@ORM\Index(columns={"string2"}, flags={"fulltext"})})
*
* @property int $id
* @property String $string1
* @property String $string2
* @property Dictionary $dictionary
* @property mixed $pronunciations
* @property Suffix $suffix1
* @property Suffix $suffix2
* @property DictType $type
* @property int $order2
* @property String $member
*/
class Term extends AbstractEntity
{
use Tid;
public function __construct(Dictionary $dictionary, $string)
{
$this->dictionary = $dictionary;
$this->string1 = $string;
}
/**
* @ORM\ManyToOne(targetEntity="\App\Model\Database\Entity\Dictionary", inversedBy="terms",cascade={"persist", "remove" })
*/
protected $dictionary;
/**
* @ORM\Column(type="string")
*/
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")
* @var Collection&iterable<Pronunciation>
*/
protected Collection $pronunciations;
/**
* @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;
}
/**
* Get the value of string1
*/
public function getString1()
{
return $this->string1;
}
/**
* Set the value of string1
*
* @return self
*/
public function setString1($string1)
{
$this->string1 = $string1;
return $this;
}
/**
* Get the value of string2
*/
public function getString2()
{
return $this->string2;
}
/**
* Set the value of string2
*
* @return self
*/
public function setString2($string2)
{
$this->string2 = $string2;
return $this;
}
/**
* Get the value of suffix1
*/
public function getSuffix1()
{
return $this->suffix1;
}
/**
* Set the value of suffix1
*
* @return self
*/
public function setSuffix1($suffix1)
{
$this->suffix1 = $suffix1;
return $this;
}
/**
* Get the value of suffix2
*/
public function getSuffix2()
{
return $this->suffix2;
}
/**
* Set the value of suffix2
*
* @return self
*/
public function setSuffix2($suffix2)
{
$this->suffix2 = $suffix2;
return $this;
}
/**
* Get the value of type
*/
public function getType()
{
return $this->type;
}
/**
* Set the value of type
*
* @return self
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get the value of pronunciations
*
* @return Collection&iterable<Pronunciation>
*/
public function getPronunciations()
{
return $this->pronunciations;
}
}

View File

@@ -0,0 +1,97 @@
<?php
namespace App\Model\Database\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Model\Database\Entity\Attributes\TId;
/**
* @ORM\Entity(repositoryClass="App\Model\Database\Repository\TermFlagRepository")
* @ORM\HasLifecycleCallbacks
*
* @property int $id
* @property WordClass $class
* @property Language $language
* @property String $code
* @property String $description
*/
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;
}
}
?>

View File

@@ -0,0 +1,87 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Model\Database\Entity\Attributes\TId;
/**
* @ORM\Entity(repositoryClass="App\Model\Database\Repository\TranslationRepository")
* @ORM\Table(name="`translation`")
* @ORM\HasLifecycleCallbacks
*
* @property int $id
* @property Dictionary $dictionary
* @property Language $lang1
* @property Language $lang2
* @property int $direction
*/
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="App\Model\Database\Entity\Dictionary", inversedBy="translations")
*/
protected $dictionary;
public function getDictionary()
{
return $this->dictionary;
}
/**
* @ORM\ManyToOne(targetEntity="App\Model\Database\Entity\Language", inversedBy="translations1")
*/
protected $lang1;
/**
* @ORM\ManyToOne(targetEntity="App\Model\Database\Entity\Language", inversedBy="translations2")
*/
protected $lang2;
/**
* @ORM\Column(type="string")
*/
protected $lang_name1;
public function getLangName1(): String
{
return $this->lang_name1;
}
/**
* @ORM\Column(type="string")
*/
protected $lang_name2;
public function getLangName2(): String
{
return $this->lang_name2;
}
/**
* @ORM\Column(type="smallint")
*/
protected $direction;
public function getDirection() : int
{
return $this->direction;
}
}
?>

View File

@@ -0,0 +1,214 @@
<?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 App\Model\Utils\Strings;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Model\Database\Repository\UserRepository")
* @ORM\Table(name="`user`")
* @ORM\HasLifecycleCallbacks
*
* @property int $id
* @property String $name
* @property String $surname
* @property String $email
* @property String $password
* @property String $role
* @property int $state
*/
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(),
]);
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Model\Database\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Model\Database\Entity\Attributes\TId;
/**
* @ORM\Entity(repositoryClass="App\Model\Database\Repository\WordClassRepository")
* @ORM\HasLifecycleCallbacks
*
* @property int $id
* @property String $name
*
*/
class WordClass extends AbstractEntity
{
use Tid;
public function __construct($id,$name)
{
$this->id = $id;
$this->name = $name;
}
/**
* @ORM\Column(type="string")
*/
protected $name;
public function getName()
{
return $this->id;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
}