*/
private $user;
+ /**
+ * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\TaggingRule", mappedBy="config", cascade={"remove"})
+ */
+ private $taggingRules;
+
/*
* @param User $user
*/
public function __construct(\Wallabag\UserBundle\Entity\User $user)
{
$this->user = $user;
+ $this->taggingRules = new ArrayCollection();
}
/**
{
return $this->rssLimit;
}
+
+ /**
+ * @param TaggingRule $rule
+ *
+ * @return Config
+ */
+ public function addTaggingRule(TaggingRule $rule)
+ {
+ $this->taggingRules[] = $rule;
+
+ return $this;
+ }
+
+ /**
+ * @return ArrayCollection<TaggingRule>
+ */
+ public function getTaggingRules()
+ {
+ return $this->taggingRules;
+ }
}
--- /dev/null
+<?php
+
+namespace Wallabag\CoreBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+use Symfony\Component\Validator\Constraints as Assert;
+
+/**
+ * Config.
+ *
+ * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TaggingRuleRepository")
+ * @ORM\Table
+ * @ORM\Entity
+ */
+class TaggingRule
+{
+ /**
+ * @var int
+ *
+ * @ORM\Column(name="id", type="integer")
+ * @ORM\Id
+ * @ORM\GeneratedValue(strategy="AUTO")
+ */
+ private $id;
+
+ /**
+ * @var string
+ *
+ * @Assert\NotBlank()
+ * @ORM\Column(name="rule", type="string", nullable=false)
+ */
+ private $rule;
+
+ /**
+ * @var array
+ *
+ * @Assert\NotBlank()
+ * @ORM\Column(name="tags", type="simple_array", nullable=false)
+ */
+ private $tags = [];
+
+ /**
+ * @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\Config", inversedBy="taggingRules")
+ */
+ private $config;
+
+ /**
+ * Get id.
+ *
+ * @return int
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * Set rule.
+ *
+ * @param string $rule
+ *
+ * @return TaggingRule
+ */
+ public function setRule($rule)
+ {
+ $this->rule = $rule;
+
+ return $this;
+ }
+
+ /**
+ * Get rule.
+ *
+ * @return string
+ */
+ public function getRule()
+ {
+ return $this->rule;
+ }
+
+ /**
+ * Set tags.
+ *
+ * @param array<string> $tags
+ *
+ * @return TaggingRule
+ */
+ public function setTags(array $tags)
+ {
+ $this->tags = $tags;
+
+ return $this;
+ }
+
+ /**
+ * Get tags.
+ *
+ * @return array<string>
+ */
+ public function getTags()
+ {
+ return $this->tags;
+ }
+
+ /**
+ * Set config.
+ *
+ * @param Config $config
+ *
+ * @return TaggingRule
+ */
+ public function setConfig(Config $config)
+ {
+ $this->config = $config;
+
+ return $this;
+ }
+
+ /**
+ * Get config.
+ *
+ * @return Config
+ */
+ public function getConfig()
+ {
+ return $this->config;
+ }
+}
$rules = $this->getRulesForUser($entry->getUser());
foreach ($rules as $rule) {
- if (!$this->rulerz->satisfies($entry, $rule['rule'])) {
+ if (!$this->rulerz->satisfies($entry, $rule->getRule())) {
continue;
}
- foreach ($rule['tags'] as $label) {
+ foreach ($rule->getTags() as $label) {
$tag = $this->getTag($entry->getUser(), $label);
$entry->addTag($tag);
return $tag;
}
+ /**
+ * Retrieves the tagging rules for a given user.
+ *
+ * @param User $user
+ *
+ * @return array<TaggingRule>
+ */
private function getRulesForUser(User $user)
{
- return [
- [
- 'rule' => 'domainName = "github.com"',
- 'tags' => ['github'],
- ],
- [
- 'rule' => 'readingTime >= 15',
- 'tags' => ['long reading'],
- ],
- [
- 'rule' => 'readingTime <= 3 ',
- 'tags' => ['short reading'],
- ],
- ];
+ return $user->getConfig()->getTaggingRules();
}
}