This commit is contained in:
2022-01-13 18:41:03 +01:00
commit 0fb9f639da
159 changed files with 13183 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Entity;
abstract class AbstractEntity
{
}

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,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;
}
}

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,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;
}
}
?>

View 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;
}
}
?>

View 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;
}
?>

View 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;
}
?>

View 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;
}
?>

View 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;
}
}
?>

View 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;
}
}
?>

View 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;
}
}
?>

View 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;
}
}
?>

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

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