diff --git a/src/Controller/HeadwordController.php b/src/Controller/HeadwordController.php index 639e037a3a522bdecbbe449c585a58a8749df24c..55ca6c9e7ac626b2effdccd68277f992888e2194 100644 --- a/src/Controller/HeadwordController.php +++ b/src/Controller/HeadwordController.php @@ -6,7 +6,7 @@ use App\Entity\Entry; use App\Entity\Headword; use App\Entity\HeadwordUserInfo; use App\Entity\Label; -use App\Entity\LabelVisibility; +use App\Entity\LabelInvisibility; use App\Entity\Lexicon; use App\Entity\Log; use App\Entity\User; diff --git a/src/Controller/LabelController.php b/src/Controller/LabelController.php index 5bb54015652b25e748a4b5156bd1d028a9c4f38c..ef32df06be59bee44ba886ff05d5d657960e9ca6 100644 --- a/src/Controller/LabelController.php +++ b/src/Controller/LabelController.php @@ -6,7 +6,7 @@ use App\Entity\Entry; use App\Entity\Group; use App\Entity\Headword; use App\Entity\Label; -use App\Entity\LabelVisibility; +use App\Entity\LabelInvisibility; use App\Entity\Lexicon; use App\Entity\Log; use App\Form\CopyEntriesType; @@ -361,22 +361,22 @@ class LabelController extends AppBaseController */ public function toggleVisibility(ManagerRegistry $doctrine, Request $request, Label $label, Lexicon $lexicon): Response { - $currentVisibility = $doctrine->getRepository(LabelVisibility::class)->findOneBy([ + $currentInvisibility = $doctrine->getRepository(LabelInvisibility::class)->findOneBy([ 'label' => $label, 'lexicon' => $lexicon, 'user' => $this->getUser(), ]); - if ($currentVisibility) { - $doctrine->getManager()->remove($currentVisibility); - $label->removeLabelVisibility($currentVisibility); - $lexicon->removeLabelVisibility($currentVisibility); - $this->getUser()->removeLabelVisibility($currentVisibility); + if ($currentInvisibility) { + $doctrine->getManager()->remove($currentInvisibility); + $label->removeLabelInvisibility($currentInvisibility); + $lexicon->removeLabelInvisibility($currentInvisibility); + $this->getUser()->removeLabelInvisibility($currentInvisibility); } else { - $newVisibility = new LabelVisibility(); - $newVisibility->setLabel($label) + $newInvisibility = new LabelInvisibility(); + $newInvisibility->setLabel($label) ->setLexicon($lexicon) ->setUser($this->getUser()); - $doctrine->getManager()->persist($newVisibility); + $doctrine->getManager()->persist($newInvisibility); } $doctrine->getManager()->flush(); diff --git a/src/Entity/Label.php b/src/Entity/Label.php index 29de0893e47277450b002394b0e2eb4e2162fe19..88f3a75a122518cf75f81d6e4e49df36851b9284 100644 --- a/src/Entity/Label.php +++ b/src/Entity/Label.php @@ -145,9 +145,9 @@ class Label private $updateRequests; /** - * @ORM\OneToMany(targetEntity=LabelVisibility::class, mappedBy="label", cascade={"persist", "remove"}) + * @ORM\OneToMany(targetEntity=LabelInvisibility::class, mappedBy="label", cascade={"persist", "remove"}) */ - private $labelVisibilities; + private $labelInvisibilities; public function __construct($category) { @@ -155,7 +155,7 @@ class Label $this->setCategory($category); $this->headwords = new ArrayCollection(); $this->updateRequests = new ArrayCollection(); - $this->labelVisibilities = new ArrayCollection(); + $this->labelInvisibilities = new ArrayCollection(); } public function __toString() @@ -421,29 +421,29 @@ class Label } /** - * @return Collection<int, LabelVisibility> + * @return Collection<int, LabelInvisibility> */ - public function getLabelVisibilities(): Collection + public function getLabelInvisibilities(): Collection { - return $this->labelVisibilities; + return $this->labelInvisibilities; } - public function addLabelVisibility(LabelVisibility $labelVisibility): self + public function addLabelInvisibility(LabelInvisibility $labelInvisibility): self { - if (!$this->labelVisibilities->contains($labelVisibility)) { - $this->labelVisibilities[] = $labelVisibility; - $labelVisibility->setLabel($this); + if (!$this->labelInvisibilities->contains($labelInvisibility)) { + $this->labelInvisibilities[] = $labelInvisibility; + $labelInvisibility->setLabel($this); } return $this; } - public function removeLabelVisibility(LabelVisibility $labelVisibility): self + public function removeLabelInvisibility(LabelInvisibility $labelInvisibility): self { - if ($this->labelVisibilities->removeElement($labelVisibility)) { + if ($this->labelInvisibilities->removeElement($labelInvisibility)) { // set the owning side to null (unless already changed) - if ($labelVisibility->getLabel() === $this) { - $labelVisibility->setLabel(null); + if ($labelInvisibility->getLabel() === $this) { + $labelInvisibility->setLabel(null); } } diff --git a/src/Entity/LabelVisibility.php b/src/Entity/LabelInvisibility.php similarity index 87% rename from src/Entity/LabelVisibility.php rename to src/Entity/LabelInvisibility.php index 44e656f9fd45dfbb359d43066f750bd9e61743f3..d447fc847b6d026ed36a184bd8235857de84e905 100644 --- a/src/Entity/LabelVisibility.php +++ b/src/Entity/LabelInvisibility.php @@ -2,7 +2,7 @@ namespace App\Entity; -use App\Repository\LabelVisibilityRepository; +use App\Repository\LabelInvisibilityRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; @@ -10,10 +10,10 @@ use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; /** - * @ORM\Entity(repositoryClass=LabelVisibilityRepository::class) + * @ORM\Entity(repositoryClass=LabelInvisibilityRepository::class) * @ORM\HasLifecycleCallbacks */ -class LabelVisibility +class LabelInvisibility { /** * @ORM\Id @@ -33,20 +33,20 @@ class LabelVisibility private $updatedAt; /** - * @ORM\ManyToOne(targetEntity=User::class, inversedBy="labelVisibilities") - * @Groups({"labelVisibility:read"}) + * @ORM\ManyToOne(targetEntity=User::class, inversedBy="labelInvisibilities") + * @Groups({"labelInvisibility:read"}) */ private $user; /** - * @ORM\ManyToOne(targetEntity=Label::class, inversedBy="labelVisibilities") - * @Groups({"labelVisibility:read"}) + * @ORM\ManyToOne(targetEntity=Label::class, inversedBy="labelInvisibilities") + * @Groups({"labelInvisibility:read"}) */ private $label; /** - * @ORM\ManyToOne(targetEntity=Lexicon::class, inversedBy="labelVisibilities") - * @Groups({"labelVisibility:read"}) + * @ORM\ManyToOne(targetEntity=Lexicon::class, inversedBy="labelInvisibilities") + * @Groups({"labelInvisibility:read"}) */ private $lexicon; diff --git a/src/Entity/Lexicon.php b/src/Entity/Lexicon.php index 50435c54646517211fc776a1610aa0cf78c35e19..968c5a2452454d9faa8df5efd532668ddda43050 100644 --- a/src/Entity/Lexicon.php +++ b/src/Entity/Lexicon.php @@ -119,9 +119,9 @@ class Lexicon private $chatMessages; /** - * @ORM\OneToMany(targetEntity=LabelVisibility::class, mappedBy="lexicon") + * @ORM\OneToMany(targetEntity=LabelInvisibility::class, mappedBy="lexicon") */ - private $labelVisibilities; + private $labelInvisibilities; public function __toString() { @@ -139,7 +139,7 @@ class Lexicon $this->entries = new ArrayCollection(); $this->graphyLists = new ArrayCollection(); $this->logs = new ArrayCollection(); - $this->labelVisibilities = new ArrayCollection(); + $this->labelInvisibilities = new ArrayCollection(); $this->chatMessages = new ArrayCollection(); } @@ -435,29 +435,29 @@ class Lexicon } /** - * @return Collection<int, LabelVisibility> + * @return Collection<int, LabelInvisibility> */ - public function getLabelVisibilities(): Collection + public function getLabelInvisibilities(): Collection { - return $this->labelVisibilities; + return $this->labelInvisibilities; } - public function addLabelVisibility(LabelVisibility $labelVisibility): self + public function addLabelInvisibility(LabelInvisibility $labelInvisibility): self { - if (!$this->labelVisibilities->contains($labelVisibility)) { - $this->labelVisibilities[] = $labelVisibility; - $labelVisibility->setLexicon($this); + if (!$this->labelInvisibilities->contains($labelInvisibility)) { + $this->labelInvisibilities[] = $labelInvisibility; + $labelInvisibility->setLexicon($this); } return $this; } - public function removeLabelVisibility(LabelVisibility $labelVisibility): self + public function removeLabelInvisibility(LabelInvisibility $labelInvisibility): self { - if ($this->labelVisibilities->removeElement($labelVisibility)) { + if ($this->labelInvisibilities->removeElement($labelInvisibility)) { // set the owning side to null (unless already changed) - if ($labelVisibility->getLexicon() === $this) { - $labelVisibility->setLexicon(null); + if ($labelInvisibility->getLexicon() === $this) { + $labelInvisibility->setLexicon(null); } } diff --git a/src/Entity/User.php b/src/Entity/User.php index fb166b64e1018fcc6dc9d0ca144b890155ddb107..c68b3638a73c5cb22e54966c4eea5d7187daa29a 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -217,9 +217,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface private $votes; /** - * @ORM\OneToMany(targetEntity=LabelVisibility::class, mappedBy="user") + * @ORM\OneToMany(targetEntity=LabelInvisibility::class, mappedBy="user") */ - private $labelVisibilities; + private $labelInvisibilities; /** * @ORM\OneToMany(targetEntity=HeadwordUserInfo::class, mappedBy="user", orphanRemoval=true) @@ -269,7 +269,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface $this->metaInfos = new ArrayCollection(); $this->updateRequests = new ArrayCollection(); $this->votes = new ArrayCollection(); - $this->labelVisibilities = new ArrayCollection(); + $this->labelInvisibilities = new ArrayCollection(); $this->entries = new ArrayCollection(); $this->headwordUserInfos = new ArrayCollection(); $this->chatMessages = new ArrayCollection(); @@ -1039,29 +1039,29 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface } /** - * @return Collection<int, LabelVisibility> + * @return Collection<int, LabelInvisibility> */ - public function getLabelVisibilities(): Collection + public function getLabelInvisibilities(): Collection { - return $this->labelVisibilities; + return $this->labelInvisibilities; } - public function addLabelVisibility(LabelVisibility $labelVisibility): self + public function addLabelInvisibility(LabelInvisibility $labelInvisibility): self { - if (!$this->labelVisibilities->contains($labelVisibility)) { - $this->labelVisibilities[] = $labelVisibility; - $labelVisibility->setUser($this); + if (!$this->labelInvisibilities->contains($labelInvisibility)) { + $this->labelInvisibilities[] = $labelInvisibility; + $labelInvisibility->setUser($this); } return $this; } - public function removeLabelVisibility(LabelVisibility $labelVisibility): self + public function removeLabelInvisibility(LabelInvisibility $labelInvisibility): self { - if ($this->labelVisibilities->removeElement($labelVisibility)) { + if ($this->labelInvisibilities->removeElement($labelInvisibility)) { // set the owning side to null (unless already changed) - if ($labelVisibility->getUser() === $this) { - $labelVisibility->setUser(null); + if ($labelInvisibility->getUser() === $this) { + $labelInvisibility->setUser(null); } } diff --git a/src/Manager/EntryManager.php b/src/Manager/EntryManager.php index 0f3103adc654ae19fc9662536e0e69860b16fc4c..780df5367b052b429c293c303e8fe2d2b06a9895 100644 --- a/src/Manager/EntryManager.php +++ b/src/Manager/EntryManager.php @@ -6,7 +6,7 @@ use App\Entity\Entry; use App\Entity\Group; use App\Entity\Headword; use App\Entity\Label; -use App\Entity\LabelVisibility; +use App\Entity\LabelInvisibility; use App\Entity\Lexicon; use App\Entity\User; use App\Languages\LanguagesIso; diff --git a/src/Manager/LabelManager.php b/src/Manager/LabelManager.php index 4950a88465b17a1ed626a083611c5553cc2770f2..9d139ced81dffb426a2622f3addf9453b0ad6574 100644 --- a/src/Manager/LabelManager.php +++ b/src/Manager/LabelManager.php @@ -6,7 +6,7 @@ use App\Entity\Entry; use App\Entity\Group; use App\Entity\Headword; use App\Entity\Label; -use App\Entity\LabelVisibility; +use App\Entity\LabelInvisibility; use App\Entity\Lexicon; use App\Entity\User; use App\Languages\LanguagesIso; @@ -42,21 +42,21 @@ class LabelManager foreach ($labelDeleted->getHeadwords() as $headword) { $headword->addLabel($labelMerged); } - // pour chaque visibilité liée à labelDeleted, on regarde si on a une visibilité pour le même lexique dans labelMerged + // pour chaque invisibilité liée à labelDeleted, on regarde si on a une invisibilité pour le même lexique dans labelMerged // Si ce n'est pas le cas, on en ajoute une - foreach ($labelDeleted->getLabelVisibilities() as $labelVisibilityDeleted) { + foreach ($labelDeleted->getLabelInvisibilities() as $labelInvisibilityDeleted) { $labelMergedHasSameLexiconVisibility = false; - foreach ($labelMerged->getLabelVisibilities() as $labelVisibilityMerged) { - if ($labelVisibilityDeleted->getLexicon() == $labelVisibilityMerged->getLexicon()) { + foreach ($labelMerged->getLabelInvisibilities() as $labelInvisibilityMerged) { + if ($labelInvisibilityDeleted->getLexicon() == $labelInvisibilityMerged->getLexicon()) { $labelMergedHasSameLexiconVisibility = true; break; } } if (false === $labelMergedHasSameLexiconVisibility) { - $labelVisibility = new LabelVisibility(); - $labelVisibility->setLexicon($labelVisibilityDeleted->getLexicon()); - $labelVisibility->setLabel($labelMerged); - $labelVisibility->setUser($labelVisibilityDeleted->getUser()); - $this->doctrine->getManager()->persist($labelVisibility); + $labelInvisibility = new LabelInvisibility(); + $labelInvisibility->setLexicon($labelInvisibilityDeleted->getLexicon()); + $labelInvisibility->setLabel($labelMerged); + $labelInvisibility->setUser($labelInvisibilityDeleted->getUser()); + $this->doctrine->getManager()->persist($labelInvisibility); } } $this->doctrine->getManager()->remove($labelDeleted); @@ -86,13 +86,13 @@ class LabelManager // vrai si le label est visible pour user dans un lexique donné public function isVisible(Label $label, Lexicon $lexicon, User $user) { - return $this->doctrine->getRepository(LabelVisibility::class)->count( + return $this->doctrine->getRepository(LabelInvisibility::class)->count( [ 'label' => $label, 'lexicon' => $lexicon, 'user' => $user, ] - ) > 0; + ) == 0; } // Retourne les 5 derniers labels visibles par un user classés par date de création DESC diff --git a/src/Manager/LogManager.php b/src/Manager/LogManager.php index 8df1b1480ee585828f62bbeeff1272a1bc656b93..b48785aeeee25c02755e72aad8baf5339d3aa058 100644 --- a/src/Manager/LogManager.php +++ b/src/Manager/LogManager.php @@ -6,7 +6,7 @@ use App\Entity\Entry; use App\Entity\Group; use App\Entity\Headword; use App\Entity\Label; -use App\Entity\LabelVisibility; +use App\Entity\LabelInvisibility; use App\Entity\Lexicon; use App\Entity\Log; use App\Entity\User; diff --git a/src/Repository/LabelVisibilityRepository.php b/src/Repository/LabelInvisibilityRepository.php similarity index 57% rename from src/Repository/LabelVisibilityRepository.php rename to src/Repository/LabelInvisibilityRepository.php index db0f27415e6e6a1841201f63d9e59f308b01b744..cec9d59f97ba568f40963f091f75a4c844d29ffe 100644 --- a/src/Repository/LabelVisibilityRepository.php +++ b/src/Repository/LabelInvisibilityRepository.php @@ -2,26 +2,25 @@ namespace App\Repository; -use App\Entity\LabelVisibility; +use App\Entity\LabelInvisibility; 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) + * @method LabelInvisibility|null find($id, $lockMode = null, $lockVersion = null) + * @method LabelInvisibility|null findOneBy(array $criteria, array $orderBy = null) + * @method LabelInvisibility[] findAll() + * @method LabelInvisibility[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class LabelVisibilityRepository extends ServiceEntityRepository +class LabelInvisibilityRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { - parent::__construct($registry, LabelVisibility::class); + parent::__construct($registry, LabelInvisibility::class); } - public function add(LabelVisibility $entity, bool $flush = false): void + public function add(LabelInvisibility $entity, bool $flush = false): void { $this->getEntityManager()->persist($entity); @@ -30,7 +29,7 @@ class LabelVisibilityRepository extends ServiceEntityRepository } } - public function remove(LabelVisibility $entity, bool $flush = false): void + public function remove(LabelInvisibility $entity, bool $flush = false): void { $this->getEntityManager()->remove($entity); @@ -40,7 +39,7 @@ class LabelVisibilityRepository extends ServiceEntityRepository } // /** -// * @return LabelVisibility[] Returns an array of LabelVisibility objects +// * @return LabelInvisibility[] Returns an array of LabelInvisibility objects // */ // public function findByExampleField($value): array // { @@ -54,7 +53,7 @@ class LabelVisibilityRepository extends ServiceEntityRepository // ; // } -// public function findOneBySomeField($value): ?LabelVisibility +// public function findOneBySomeField($value): ?LabelInvisibility // { // return $this->createQueryBuilder('v') // ->andWhere('v.exampleField = :val') diff --git a/src/Repository/LabelRepository.php b/src/Repository/LabelRepository.php index 77b167d778b08338001e1064dc7f99ebf4685ac8..a0401cbdf3502d15061fd290df4d0e0c369886af 100644 --- a/src/Repository/LabelRepository.php +++ b/src/Repository/LabelRepository.php @@ -92,18 +92,25 @@ class LabelRepository extends ServiceEntityRepository */ public function getVisiblesByUserInLexicon(User $user, Lexicon $lexicon, $category = null): array { - $qb = $this->createQueryBuilder('l') - ->leftJoin('l.group', 'g') - ->leftJoin('g.groupMemberships', 'gms') - ->innerJoin('l.labelVisibilities', 'lv') + $qbInvisible = $this->createQueryBuilder('li') + ->innerJoin('li.labelInvisibilities', 'lv') ->andWhere('lv.user = :user') + ->setParameter('user', $user) ->andWhere('lv.lexicon = :lexicon') + ->setParameter('lexicon', $lexicon) + ; + + $qb = $this->createQueryBuilder('l'); + $qb ->leftJoin('l.group', 'g') + ->leftJoin('g.groupMemberships', 'gms') ->andWhere('l.category != :milestone OR l.user = :user OR gms.user = :user') - ->setParameter('user', $user) ->setParameter('milestone', Label::LABEL_CATEGORY_MILESTONE) - ->setParameter('lexicon', $lexicon) ->orderBy('l.category', 'ASC') ->addOrderBy('l.master', 'ASC') + // Params qbInvisible + ->andWhere($qb->expr()->notIn('l.id', $qbInvisible->getDQL())) + ->setParameter('user', $user) + ->setParameter('lexicon', $lexicon) ; if ($category) {