namespace Wallabag\CoreBundle\Entity;
+use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
-use JMS\Serializer\Annotation\XmlRoot;
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
+ * Tag.
*
* @XmlRoot("tag")
- * @ORM\Table(name="tag")
+ * @ORM\Table(name="`tag`")
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository")
* @ExclusionPolicy("all")
*/
class Tag
{
/**
- * @var integer
+ * @var int
*
* @Expose
* @ORM\Column(name="id", type="integer")
*/
private $label;
+ /**
+ * @Expose
+ * @Gedmo\Slug(fields={"label"})
+ * @ORM\Column(length=128, unique=true)
+ */
+ private $slug;
+
/**
* @ORM\ManyToMany(targetEntity="Entry", mappedBy="tags", cascade={"persist"})
*/
{
$this->entries = new ArrayCollection();
}
+
+ public function __toString()
+ {
+ return $this->label;
+ }
+
/**
- * Get id
+ * Get id.
*
- * @return integer
+ * @return int
*/
public function getId()
{
}
/**
- * Set label
+ * Set label.
+ *
+ * @param string $label
*
- * @param string $label
* @return Tag
*/
public function setLabel($label)
}
/**
- * Get label
+ * Get label.
*
* @return string
*/
return $this->label;
}
+ public function getSlug()
+ {
+ return $this->slug;
+ }
+
public function addEntry(Entry $entry)
{
$this->entries[] = $entry;
}
+
+ public function hasEntry($entry)
+ {
+ return $this->entries->contains($entry);
+ }
+
+ /**
+ * Get entries for this tag.
+ *
+ * @return ArrayCollection<Entry>
+ */
+ 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;
+ }
}