From ac9fec610a6485b39c856d9cb7d263ce8c5f1223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sun, 11 Oct 2015 17:14:50 +0200 Subject: Add TaggingRule entity --- src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php | 26 +++++++++------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'src/Wallabag/CoreBundle/Helper') diff --git a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php index 012450b6..bb933779 100644 --- a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php +++ b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php @@ -30,11 +30,11 @@ class RuleBasedTagger $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); @@ -62,21 +62,15 @@ class RuleBasedTagger return $tag; } + /** + * Retrieves the tagging rules for a given user. + * + * @param User $user + * + * @return array + */ 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(); } } -- cgit v1.2.3