Skip to content
Snippets Groups Projects
Commit 94a047f3 authored by Pierre Fleutot's avatar Pierre Fleutot
Browse files

Ajout entités LabelVisibility UpdateRequest Vote. Ajout champs master et...

Ajout entités LabelVisibility UpdateRequest Vote. Ajout champs master et source sur label. Modif catégories Label
parent f33dff44
No related branches found
No related tags found
No related merge requests found
Showing with 1820 additions and 12 deletions
......@@ -4,9 +4,11 @@ namespace App\Controller;
use App\Entity\Entry;
use App\Entity\Graphy;
use App\Entity\Group;
use App\Entity\Headword;
use App\Entity\Label;
use App\Entity\Lexicon;
use App\Entity\User;
use App\Manager\WiktionaryManager;
use App\Repository\LabelRepository;
use Doctrine\Persistence\ManagerRegistry;
......@@ -71,9 +73,11 @@ class ApiLabelController extends ApiBaseController
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* required={"name", "category"},
* required={"name", "category", "masters_type"},
* @OA\Property(property="name", type="string"),
* @OA\Property(property="category", type="string", example="morphological OR thematic OR list OR milestone"),
* @OA\Property(property="category", type="string", example="morphological OR general OR list OR milestone OR institutional"),
* @OA\Property(property="masters_type", type="string", example="user OR group OR public"),
* @OA\Property(property="master_id", type="integer"),
* @OA\Property(property="milestone", type="date")
* )
* )
......@@ -86,12 +90,16 @@ class ApiLabelController extends ApiBaseController
if (!$data) {
return $this->createJsonResponse(401, ['error' => sprintf("Json non valide")]);
}
if ($missingFields = $this->getMissingFields($data, ['name', 'category'])) {
if ($missingFields = $this->getMissingFields($data, ['name', 'category', 'masters_type'])) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez fournir une valeur pour: %s", implode(', ', $missingFields))]);
}
if (!in_array($data['category'], Label::LABEL_LIST_CATEGORIES)) {
return $this->createJsonResponse(401, ['error' => sprintf("La catégorie de label %s n'existe pas", $data['category'])]);
}
if (!in_array($data['masters_type'], Label::MASTERS_TYPES)) {
return $this->createJsonResponse(401, ['error' => sprintf("Le type de masters de label %s n'existe pas", $data['masters_type'])]);
}
$milestone = $data['milestone'] ?? null;
if ($data['category'] === Label::LABEL_CATEGORY_MILESTONE &&
(!$milestone || !date_create_from_format('Y-m-d', $milestone))) {
......@@ -99,7 +107,23 @@ class ApiLabelController extends ApiBaseController
}
$label = new Label($data['category']);
$label->setUser($this->getUser());
$mastersType = $data['mastersType'];
$masterId = $data['master_id'] ?? null;
if ($mastersType !== Label::MASTER_PUBLIC && !$masterId) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez fournir une valeur pour « master_id »")]);
}
if ($data['masters_type'] === Label::MASTER_GROUP) {
$group = $this->doctrine->getRepository(Group::class)->find($masterId);
if (!$group) return $this->createJsonResponse(401, ['error' => sprintf("Impossible de trouver le groupe pour l'id «%s»", $masterId)]);
$label->setGroup($group);
}
if ($data['masters_type'] === Label::MASTER_PERSONAL) {
$user = $this->doctrine->getRepository(User::class)->find($masterId);
if (!$user) return $this->createJsonResponse(401, ['error' => sprintf("Impossible de trouver l'utilisateur pour l'id «%s»", $masterId)]);
$label->setUser($user);
}
$label->setName($data['name']);
if ($label->isMilestone()) {
$label->setMilestone(date_create_from_format('Y-m-d', $milestone));
......
......@@ -72,6 +72,20 @@ class Headword
$this->labels = new ArrayCollection();
}
/**
* @return Label[]
*/
public function getInstitutionalLabels()
{
$result = [];
foreach ($this->getLabels() as $label) {
if ($label->isInstitutional()) {
$result[] = $label;
}
}
return $result;
}
/**
* @return Label[]
*/
......@@ -89,11 +103,11 @@ class Headword
/**
* @return Label[]
*/
public function getThematicLabels()
public function getGeneralLabels()
{
$result = [];
foreach ($this->getLabels() as $label) {
if ($label->isThematic()) {
if ($label->isGeneral()) {
$result[] = $label;
}
}
......
......@@ -7,6 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=LabelRepository::class)
......@@ -14,19 +15,31 @@ use Symfony\Component\Serializer\Annotation\Groups;
*/
class Label
{
const LABEL_CATEGORY_INSTITUTIONAL = 'institutional';
const LABEL_CATEGORY_MORPHOLOGICAL = 'morphological';
const LABEL_CATEGORY_THEMATIC = 'thematic';
const LABEL_CATEGORY_LIST = 'list';
const LABEL_CATEGORY_MILESTONE = 'milestone';
const LABEL_CATEGORY_GENERAL = 'general';
const LABEL_CATEGORY_LIST = 'list';
const LABEL_CATEGORY_SYSTEM = 'system';
const LABEL_LIST_CATEGORIES = [
self::LABEL_CATEGORY_INSTITUTIONAL => self::LABEL_CATEGORY_INSTITUTIONAL,
self::LABEL_CATEGORY_MORPHOLOGICAL => self::LABEL_CATEGORY_MORPHOLOGICAL,
self::LABEL_CATEGORY_THEMATIC => self::LABEL_CATEGORY_THEMATIC,
self::LABEL_CATEGORY_GENERAL => self::LABEL_CATEGORY_GENERAL,
self::LABEL_CATEGORY_LIST => self::LABEL_CATEGORY_LIST,
self::LABEL_CATEGORY_MILESTONE => self::LABEL_CATEGORY_MILESTONE,
];
const MASTER_PERSONAL = 'personal';
const MASTER_GROUP = 'group';
const MASTER_PUBLIC = 'public';
const MASTERS_TYPES = [
self::MASTER_GROUP => self::MASTER_GROUP,
self::MASTER_PERSONAL => self::MASTER_PERSONAL,
self::MASTER_PUBLIC => self::MASTER_PUBLIC,
];
const LABEL_MERGED = 'merged';
/**
......@@ -48,6 +61,13 @@ class Label
*/
private $category;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"label:read"})
* @Assert\Length(max=255)
*/
private $source;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"label:read"})
......@@ -87,10 +107,22 @@ class Label
*/
private $graphyList;
/**
* @ORM\OneToMany(targetEntity=UpdateRequest::class, mappedBy="label")
*/
private $updateRequests;
/**
* @ORM\OneToMany(targetEntity=LabelVisibility::class, mappedBy="label")
*/
private $labelVisibilities;
public function __construct($category)
{
$this->setCategory($category);
$this->headwords = new ArrayCollection();
$this->updateRequests = new ArrayCollection();
$this->labelVisibilities = new ArrayCollection();
}
public function __toString()
......@@ -98,6 +130,15 @@ class Label
return $this->getName();
}
public function getMasters()
{
if ($this->getUser() && ! $this->getGroup()) return self::MASTER_PERSONAL;
if ($this->getGroup() && $this->getUser()) return self::MASTER_GROUP;
if (! $this->getGroup() && ! $this->getUser()) return self::MASTER_PUBLIC;
throw new \LogicException("Cannot determine label masters type");
}
public function compareWith(Label $label)
{
$diffs = [];
......@@ -123,13 +164,17 @@ class Label
return $diffs;
}
public function isInstitutional()
{
return $this->getCategory() === self::LABEL_CATEGORY_INSTITUTIONAL;
}
public function isMorphological()
{
return $this->getCategory() === self::LABEL_CATEGORY_MORPHOLOGICAL;
}
public function isThematic()
public function isGeneral()
{
return $this->getCategory() === self::LABEL_CATEGORY_THEMATIC;
return $this->getCategory() === self::LABEL_CATEGORY_GENERAL;
}
public function isList()
{
......@@ -280,4 +325,76 @@ class Label
return $this;
}
public function getSource(): ?string
{
return $this->source;
}
public function setSource(string $source): self
{
$this->source = $source;
return $this;
}
/**
* @return Collection<int, UpdateRequest>
*/
public function getUpdateRequests(): Collection
{
return $this->updateRequests;
}
public function addUpdateRequest(UpdateRequest $updateRequest): self
{
if (!$this->updateRequests->contains($updateRequest)) {
$this->updateRequests[] = $updateRequest;
$updateRequest->setLabel($this);
}
return $this;
}
public function removeUpdateRequest(UpdateRequest $updateRequest): self
{
if ($this->updateRequests->removeElement($updateRequest)) {
// set the owning side to null (unless already changed)
if ($updateRequest->getLabel() === $this) {
$updateRequest->setLabel(null);
}
}
return $this;
}
/**
* @return Collection<int, LabelVisibility>
*/
public function getLabelVisibilities(): Collection
{
return $this->labelVisibilities;
}
public function addLabelVisibility(LabelVisibility $labelVisibility): self
{
if (!$this->labelVisibilities->contains($labelVisibility)) {
$this->labelVisibilities[] = $labelVisibility;
$labelVisibility->setLabel($this);
}
return $this;
}
public function removeLabelVisibility(LabelVisibility $labelVisibility): self
{
if ($this->labelVisibilities->removeElement($labelVisibility)) {
// set the owning side to null (unless already changed)
if ($labelVisibility->getLabel() === $this) {
$labelVisibility->setLabel(null);
}
}
return $this;
}
}
<?php
namespace App\Entity;
use App\Repository\LabelRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=VoteRepository::class)
* @ORM\HasLifecycleCallbacks
*/
class LabelVisibility
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private $updatedAt;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="labelVisibilities")
* @Groups({"labelVisibility:read"})
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity=Label::class, inversedBy="labelVisibilities")
* @Groups({"labelVisibility:read"})
*/
private $label;
/**
* @ORM\ManyToOne(targetEntity=Lexicon::class, inversedBy="labelVisibilities")
* @Groups({"labelVisibility:read"})
*/
private $lexicon;
public function getId(): ?int
{
return $this->id;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getLabel(): ?Label
{
return $this->label;
}
public function setLabel(?Label $label): self
{
$this->label = $label;
return $this;
}
public function getLexicon(): ?Lexicon
{
return $this->lexicon;
}
public function setLexicon(?Lexicon $lexicon): self
{
$this->lexicon = $lexicon;
return $this;
}
}
<?php
namespace App\Entity;
use App\Entity\LabelVisibility;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<LabelVisibility>
*
* @method LabelVisibility|null find($id, $lockMode = null, $lockVersion = null)
* @method LabelVisibility|null findOneBy(array $criteria, array $orderBy = null)
* @method LabelVisibility[] findAll()
* @method LabelVisibility[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class LabelVisibilityRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, LabelVisibility::class);
}
public function add(LabelVisibility $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(LabelVisibility $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return LabelVisibility[] Returns an array of LabelVisibility objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('v')
// ->andWhere('v.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('v.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?LabelVisibility
// {
// return $this->createQueryBuilder('v')
// ->andWhere('v.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
......@@ -106,6 +106,11 @@ class Lexicon
*/
private $logs;
/**
* @ORM\OneToMany(targetEntity=LabelVisibility::class, mappedBy="lexicon")
*/
private $labelVisibilities;
public function __toString()
{
switch ($this->getCategory()) {
......@@ -121,6 +126,7 @@ class Lexicon
$this->entries = new ArrayCollection();
$this->graphyLists = new ArrayCollection();
$this->logs = new ArrayCollection();
$this->labelVisibilities = new ArrayCollection();
}
public function isZero()
......@@ -341,4 +347,34 @@ class Lexicon
return $this;
}
/**
* @return Collection<int, LabelVisibility>
*/
public function getLabelVisibilities(): Collection
{
return $this->labelVisibilities;
}
public function addLabelVisibility(LabelVisibility $labelVisibility): self
{
if (!$this->labelVisibilities->contains($labelVisibility)) {
$this->labelVisibilities[] = $labelVisibility;
$labelVisibility->setLexicon($this);
}
return $this;
}
public function removeLabelVisibility(LabelVisibility $labelVisibility): self
{
if ($this->labelVisibilities->removeElement($labelVisibility)) {
// set the owning side to null (unless already changed)
if ($labelVisibility->getLexicon() === $this) {
$labelVisibility->setLexicon(null);
}
}
return $this;
}
}
<?php
namespace App\Entity;
use App\Repository\LabelRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=UpdateRequestRepository::class)
* @ORM\HasLifecycleCallbacks
*/
class UpdateRequest
{
const CATEGORY_RENAME = 'rename';
const CATEGORY_DELETE = 'delete';
const CATEGORY_LIST = [
self::CATEGORY_RENAME => self::CATEGORY_RENAME,
self::CATEGORY_DELETE => self::CATEGORY_DELETE,
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"updateRequest:read"})
*/
private $suggestedName;
/**
* @ORM\Column(type="string", length=80)
* @Groups({"updateRequest:read"})
*/
private $category;
/**
* @ORM\ManyToOne(targetEntity=Label::class, inversedBy="updateRequests")
*/
private $label;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private $updatedAt;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="updateRequests")
* @Groups({"updateRequest:read"})
*/
private $user;
/**
* @ORM\OneToMany(targetEntity=Vote::class, mappedBy="updateRequest")
* @Groups({"updateRequest:read"})
*/
private $votes;
public function __construct($category)
{
$this->setCategory($category);
$this->votes = new ArrayCollection();
}
public function __toString()
{
return sprintf("update request du %s label «%s» par %s", $this->getCreatedAt()->format('d/m/Y'), $this->getLabel(), $this->getUser());
}
public function getId(): ?int
{
return $this->id;
}
public function getSuggestedName(): ?string
{
return $this->suggestedName;
}
public function setSuggestedName(string $suggestedName): self
{
$this->suggestedName = $suggestedName;
return $this;
}
public function getCategory(): ?string
{
return $this->category;
}
public function setCategory(string $category): self
{
$this->category = $category;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getLabel(): ?Label
{
return $this->label;
}
public function setLabel(?Label $label): self
{
$this->label = $label;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection<int, Vote>
*/
public function getVotes(): Collection
{
return $this->votes;
}
public function addVote(Vote $vote): self
{
if (!$this->votes->contains($vote)) {
$this->votes[] = $vote;
$vote->setUpdateRequest($this);
}
return $this;
}
public function removeVote(Vote $vote): self
{
if ($this->votes->removeElement($vote)) {
// set the owning side to null (unless already changed)
if ($vote->getUpdateRequest() === $this) {
$vote->setUpdateRequest(null);
}
}
return $this;
}
}
<?php
namespace App\Entity;
use App\Entity\UpdateRequest;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<UpdateRequest>
*
* @method UpdateRequest|null find($id, $lockMode = null, $lockVersion = null)
* @method UpdateRequest|null findOneBy(array $criteria, array $orderBy = null)
* @method UpdateRequest[] findAll()
* @method UpdateRequest[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class UpdateRequestRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, UpdateRequest::class);
}
public function add(UpdateRequest $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(UpdateRequest $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return UpdateRequest[] Returns an array of UpdateRequest objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('u.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?UpdateRequest
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
......@@ -201,6 +201,21 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
*/
private $metaInfos;
/**
* @ORM\OneToMany(targetEntity=UpdateRequest::class, mappedBy="user")
*/
private $updateRequests;
/**
* @ORM\OneToMany(targetEntity=Vote::class, mappedBy="user")
*/
private $votes;
/**
* @ORM\OneToMany(targetEntity=LabelVisibility::class, mappedBy="user")
*/
private $labelVisibilities;
public function __toString()
{
return $this->getPseudo();
......@@ -222,6 +237,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
$this->labels = new ArrayCollection();
$this->createdGraphyLists = new ArrayCollection();
$this->logs = new ArrayCollection();
$this->traces = new ArrayCollection();
$this->metaInfos = new ArrayCollection();
$this->updateRequests = new ArrayCollection();
$this->votes = new ArrayCollection();
$this->labelVisibilities = new ArrayCollection();
}
/**
......@@ -808,4 +828,154 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this;
}
/**
* @return Collection<int, Trace>
*/
public function getTraces(): Collection
{
return $this->traces;
}
public function addTrace(Trace $trace): self
{
if (!$this->traces->contains($trace)) {
$this->traces[] = $trace;
$trace->setCreatedBy($this);
}
return $this;
}
public function removeTrace(Trace $trace): self
{
if ($this->traces->removeElement($trace)) {
// set the owning side to null (unless already changed)
if ($trace->getCreatedBy() === $this) {
$trace->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, MetaInfo>
*/
public function getMetaInfos(): Collection
{
return $this->metaInfos;
}
public function addMetaInfo(MetaInfo $metaInfo): self
{
if (!$this->metaInfos->contains($metaInfo)) {
$this->metaInfos[] = $metaInfo;
$metaInfo->setCreatedBy($this);
}
return $this;
}
public function removeMetaInfo(MetaInfo $metaInfo): self
{
if ($this->metaInfos->removeElement($metaInfo)) {
// set the owning side to null (unless already changed)
if ($metaInfo->getCreatedBy() === $this) {
$metaInfo->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, UpdateRequest>
*/
public function getUpdateRequests(): Collection
{
return $this->updateRequests;
}
public function addUpdateRequest(UpdateRequest $updateRequest): self
{
if (!$this->updateRequests->contains($updateRequest)) {
$this->updateRequests[] = $updateRequest;
$updateRequest->setUser($this);
}
return $this;
}
public function removeUpdateRequest(UpdateRequest $updateRequest): self
{
if ($this->updateRequests->removeElement($updateRequest)) {
// set the owning side to null (unless already changed)
if ($updateRequest->getUser() === $this) {
$updateRequest->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Vote>
*/
public function getVotes(): Collection
{
return $this->votes;
}
public function addVote(Vote $vote): self
{
if (!$this->votes->contains($vote)) {
$this->votes[] = $vote;
$vote->setUser($this);
}
return $this;
}
public function removeVote(Vote $vote): self
{
if ($this->votes->removeElement($vote)) {
// set the owning side to null (unless already changed)
if ($vote->getUser() === $this) {
$vote->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, LabelVisibility>
*/
public function getLabelVisibilities(): Collection
{
return $this->labelVisibilities;
}
public function addLabelVisibility(LabelVisibility $labelVisibility): self
{
if (!$this->labelVisibilities->contains($labelVisibility)) {
$this->labelVisibilities[] = $labelVisibility;
$labelVisibility->setUser($this);
}
return $this;
}
public function removeLabelVisibility(LabelVisibility $labelVisibility): self
{
if ($this->labelVisibilities->removeElement($labelVisibility)) {
// set the owning side to null (unless already changed)
if ($labelVisibility->getUser() === $this) {
$labelVisibility->setUser(null);
}
}
return $this;
}
}
<?php
namespace App\Entity;
use App\Repository\LabelRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=VoteRepository::class)
* @ORM\HasLifecycleCallbacks
*/
class Vote
{
const CATEGORY_YES = 'yes';
const CATEGORY_NO = 'no';
const CATEGORY_LIST = [
self::CATEGORY_YES => self::CATEGORY_YES,
self::CATEGORY_NO => self::CATEGORY_NO,
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=80)
* @Groups({"vote:read"})
*/
private $category;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private $updatedAt;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="votes")
* @Groups({"vote:read"})
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity=UpdateRequest::class, inversedBy="votes")
* @Groups({"vote:read"})
*/
private $updateRequest;
public function __construct($category)
{
$this->setCategory($category);
}
public function __toString()
{
return sprintf("vote %s du %s pour label «%s» par %s", $this->getCategory(), $this->getCreatedAt()->format('d/m/Y'), $this->getLabel(), $this->getUser());
}
public function getLabel()
{
return $this->getUpdateRequest()->getLabel();
}
public function getId(): ?int
{
return $this->id;
}
public function getCategory(): ?string
{
return $this->category;
}
public function setCategory(string $category): self
{
$this->category = $category;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getUpdateRequest(): ?UpdateRequest
{
return $this->updateRequest;
}
public function setUpdateRequest(?UpdateRequest $updateRequest): self
{
$this->updateRequest = $updateRequest;
return $this;
}
}
<?php
namespace App\Entity;
use App\Entity\Vote;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Vote>
*
* @method Vote|null find($id, $lockMode = null, $lockVersion = null)
* @method Vote|null findOneBy(array $criteria, array $orderBy = null)
* @method Vote[] findAll()
* @method Vote[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class VoteRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Vote::class);
}
public function add(Vote $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Vote $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Vote[] Returns an array of Vote objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('v')
// ->andWhere('v.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('v.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Vote
// {
// return $this->createQueryBuilder('v')
// ->andWhere('v.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
<?php
namespace App\Repository;
use App\Entity\UpdateRequest;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<UpdateRequest>
*
* @method UpdateRequest|null find($id, $lockMode = null, $lockVersion = null)
* @method UpdateRequest|null findOneBy(array $criteria, array $orderBy = null)
* @method UpdateRequest[] findAll()
* @method UpdateRequest[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class UpdateRequestRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, UpdateRequest::class);
}
public function add(UpdateRequest $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(UpdateRequest $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return UpdateRequest[] Returns an array of UpdateRequest objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('l')
// ->andWhere('l.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('l.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?UpdateRequest
// {
// return $this->createQueryBuilder('l')
// ->andWhere('l.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
<?php
namespace App\Repository;
use App\Entity\Vote;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Vote>
*
* @method Vote|null find($id, $lockMode = null, $lockVersion = null)
* @method Vote|null findOneBy(array $criteria, array $orderBy = null)
* @method Vote[] findAll()
* @method Vote[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class VoteRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Vote::class);
}
public function add(Vote $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Vote $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Vote[] Returns an array of Vote objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('l')
// ->andWhere('l.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('l.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Vote
// {
// return $this->createQueryBuilder('l')
// ->andWhere('l.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
This diff is collapsed.
......@@ -35,7 +35,7 @@
<tr>
<td>{{ entry }}</td>
<td>{% for label in entry.headword.morphologicalLabels %}<span class="badge bg-primary">{{ label }}</span> {% endfor %}</td>
<td>{% for label in entry.headword.thematicLabels %}<span class="badge bg-secondary">{{ label }}</span> {% endfor %}</td>
<td>{% for label in entry.headword.generalLabels %}<span class="badge bg-secondary">{{ label }}</span> {% endfor %}</td>
<td>{% for label in entry.headword.listLabels %}<span class="badge bg-info">{{ label }}</span> {% endfor %}</td>
<td>{% for label in entry.headword.milestoneLabels %}<span class="badge bg-warning">{{ label }}</span> {% endfor %}</td>
<td>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment