2015-01-22 16:18:56 +00:00
|
|
|
<?php
|
|
|
|
|
2015-01-23 15:28:37 +00:00
|
|
|
namespace Wallabag\CoreBundle\Entity;
|
2015-01-22 16:18:56 +00:00
|
|
|
|
2015-12-22 09:16:34 +00:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2015-01-22 16:18:56 +00:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2017-07-01 07:52:38 +00:00
|
|
|
use Gedmo\Mapping\Annotation as Gedmo;
|
2015-02-20 19:29:33 +00:00
|
|
|
use JMS\Serializer\Annotation\ExclusionPolicy;
|
|
|
|
use JMS\Serializer\Annotation\Expose;
|
2015-12-22 09:16:34 +00:00
|
|
|
use JMS\Serializer\Annotation\XmlRoot;
|
2015-01-22 16:18:56 +00:00
|
|
|
|
|
|
|
/**
|
2015-05-30 11:52:26 +00:00
|
|
|
* Tag.
|
2015-01-22 16:18:56 +00:00
|
|
|
*
|
2015-02-20 16:20:12 +00:00
|
|
|
* @XmlRoot("tag")
|
2019-05-11 18:07:38 +00:00
|
|
|
* @ORM\Table(
|
|
|
|
* name="`tag`",
|
|
|
|
* options={"collate"="utf8mb4_bin", "charset"="utf8mb4"},
|
|
|
|
* )
|
2015-02-20 16:20:12 +00:00
|
|
|
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository")
|
2015-02-20 19:29:33 +00:00
|
|
|
* @ExclusionPolicy("all")
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
2015-02-06 17:15:19 +00:00
|
|
|
class Tag
|
2015-01-22 16:18:56 +00:00
|
|
|
{
|
|
|
|
/**
|
2015-05-30 11:52:26 +00:00
|
|
|
* @var int
|
2015-01-22 16:18:56 +00:00
|
|
|
*
|
2015-02-20 19:29:33 +00:00
|
|
|
* @Expose
|
2015-02-06 17:15:19 +00:00
|
|
|
* @ORM\Column(name="id", type="integer")
|
2015-01-22 16:18:56 +00:00
|
|
|
* @ORM\Id
|
2015-02-06 17:15:19 +00:00
|
|
|
* @ORM\GeneratedValue(strategy="AUTO")
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*
|
2015-02-20 19:29:33 +00:00
|
|
|
* @Expose
|
2015-02-06 17:15:19 +00:00
|
|
|
* @ORM\Column(name="label", type="text")
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
2015-02-06 17:15:19 +00:00
|
|
|
private $label;
|
2015-01-22 16:18:56 +00:00
|
|
|
|
2015-10-14 19:30:25 +00:00
|
|
|
/**
|
2015-12-29 13:50:52 +00:00
|
|
|
* @Expose
|
2015-10-14 19:30:25 +00:00
|
|
|
* @Gedmo\Slug(fields={"label"})
|
|
|
|
* @ORM\Column(length=128, unique=true)
|
|
|
|
*/
|
|
|
|
private $slug;
|
|
|
|
|
2015-02-20 19:29:33 +00:00
|
|
|
/**
|
2015-02-24 06:42:09 +00:00
|
|
|
* @ORM\ManyToMany(targetEntity="Entry", mappedBy="tags", cascade={"persist"})
|
2015-02-20 19:29:33 +00:00
|
|
|
*/
|
|
|
|
private $entries;
|
|
|
|
|
2015-12-29 13:50:52 +00:00
|
|
|
public function __construct()
|
2015-02-24 06:42:09 +00:00
|
|
|
{
|
|
|
|
$this->entries = new ArrayCollection();
|
|
|
|
}
|
2015-06-02 16:54:34 +00:00
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return $this->label;
|
|
|
|
}
|
|
|
|
|
2015-01-22 16:18:56 +00:00
|
|
|
/**
|
2015-05-30 11:52:26 +00:00
|
|
|
* Get id.
|
2015-01-22 16:18:56 +00:00
|
|
|
*
|
2015-05-30 11:52:26 +00:00
|
|
|
* @return int
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-30 11:52:26 +00:00
|
|
|
* Set label.
|
|
|
|
*
|
|
|
|
* @param string $label
|
2015-01-22 16:18:56 +00:00
|
|
|
*
|
2015-02-06 17:15:19 +00:00
|
|
|
* @return Tag
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
2015-02-06 17:15:19 +00:00
|
|
|
public function setLabel($label)
|
2015-01-22 16:18:56 +00:00
|
|
|
{
|
2017-05-21 15:01:59 +00:00
|
|
|
$this->label = mb_convert_case($label, MB_CASE_LOWER);
|
2015-01-22 16:18:56 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-30 11:52:26 +00:00
|
|
|
* Get label.
|
2015-01-22 16:18:56 +00:00
|
|
|
*
|
2015-01-31 18:09:34 +00:00
|
|
|
* @return string
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
2015-02-06 17:15:19 +00:00
|
|
|
public function getLabel()
|
2015-01-22 16:18:56 +00:00
|
|
|
{
|
2015-02-20 15:38:24 +00:00
|
|
|
return $this->label;
|
2015-01-22 16:18:56 +00:00
|
|
|
}
|
2015-02-24 06:42:09 +00:00
|
|
|
|
2015-10-14 19:30:25 +00:00
|
|
|
public function getSlug()
|
|
|
|
{
|
|
|
|
return $this->slug;
|
|
|
|
}
|
|
|
|
|
2016-05-30 12:34:11 +00:00
|
|
|
/**
|
|
|
|
* @param Entry $entry
|
|
|
|
*/
|
2015-02-24 06:42:09 +00:00
|
|
|
public function addEntry(Entry $entry)
|
|
|
|
{
|
2016-05-30 12:34:11 +00:00
|
|
|
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);
|
2015-02-24 06:42:09 +00:00
|
|
|
}
|
2015-03-05 18:41:23 +00:00
|
|
|
|
2015-08-19 09:46:21 +00:00
|
|
|
public function hasEntry($entry)
|
|
|
|
{
|
|
|
|
return $this->entries->contains($entry);
|
|
|
|
}
|
2016-02-10 16:41:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get entries for this tag.
|
|
|
|
*
|
|
|
|
* @return ArrayCollection<Entry>
|
|
|
|
*/
|
|
|
|
public function getEntries()
|
|
|
|
{
|
|
|
|
return $this->entries;
|
|
|
|
}
|
2016-05-03 19:12:40 +00:00
|
|
|
|
2016-05-04 09:42:52 +00:00
|
|
|
public function getEntriesByUserId($userId)
|
2016-05-03 19:12:40 +00:00
|
|
|
{
|
|
|
|
$filteredEntries = new ArrayCollection();
|
|
|
|
foreach ($this->entries as $entry) {
|
|
|
|
if ($entry->getUser()->getId() === $userId) {
|
|
|
|
$filteredEntries->add($entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $filteredEntries;
|
|
|
|
}
|
2015-01-22 16:18:56 +00:00
|
|
|
}
|