X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FEntity%2FTag.php;h=95c47bbd08a379aa2f95d1ec61f2102c221909b8;hb=830cce45b3a3246c113423c52bcc580087ddebcd;hp=0689c7b31854fc0dbd58c40ca105d8a1c9c7cc68;hpb=fc73222723c7a0c9b577805d3ef51eb96b124b92;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php index 0689c7b3..95c47bbd 100644 --- a/src/Wallabag/CoreBundle/Entity/Tag.php +++ b/src/Wallabag/CoreBundle/Entity/Tag.php @@ -2,18 +2,21 @@ namespace Wallabag\CoreBundle\Entity; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; -use JMS\Serializer\Annotation\XmlRoot; +use Gedmo\Mapping\Annotation as Gedmo; use JMS\Serializer\Annotation\ExclusionPolicy; use JMS\Serializer\Annotation\Expose; -use Doctrine\Common\Collections\ArrayCollection; -use Gedmo\Mapping\Annotation as Gedmo; +use JMS\Serializer\Annotation\XmlRoot; /** * Tag. * * @XmlRoot("tag") - * @ORM\Table(name="`tag`") + * @ORM\Table( + * name="`tag`", + * options={"collate"="utf8mb4_bin", "charset"="utf8mb4"}, + * ) * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository") * @ExclusionPolicy("all") */ @@ -78,7 +81,7 @@ class Tag */ public function setLabel($label) { - $this->label = $label; + $this->label = mb_convert_case($label, MB_CASE_LOWER); return $this; } @@ -98,13 +101,56 @@ class Tag return $this->slug; } + /** + * @param Entry $entry + */ public function addEntry(Entry $entry) { - $this->entries[] = $entry; + if ($this->entries->contains($entry)) { + return; + } + + $this->entries->add($entry); + $entry->addTag($this); + } + + /** + * @param Entry $entry + */ + public function removeEntry(Entry $entry) + { + if (!$this->entries->contains($entry)) { + return; + } + + $this->entries->removeElement($entry); + $entry->removeTag($this); } public function hasEntry($entry) { return $this->entries->contains($entry); } + + /** + * Get entries for this tag. + * + * @return ArrayCollection + */ + public function getEntries() + { + return $this->entries; + } + + public function getEntriesByUserId($userId) + { + $filteredEntries = new ArrayCollection(); + foreach ($this->entries as $entry) { + if ($entry->getUser()->getId() === $userId) { + $filteredEntries->add($entry); + } + } + + return $filteredEntries; + } }