blob: e6c0cade2fb07e4f773812cd80da0a32730d5439 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
<?php
declare(strict_types=1);
namespace OCA\Notes\Service;
use OCP\ITagManager;
use OCP\ITags;
class TagService {
/** @var ITags */
private $tagger;
/** @var array */
private $cachedTags;
public function __construct(ITagManager $tagManager) {
$this->tagger = $tagManager->load('files');
}
public function loadTags(array $fileIds) : void {
$this->cachedTags = $this->tagger->getTagsForObjects($fileIds);
}
public function isFavorite($fileId) : bool {
$alltags = $this->cachedTags;
if (!is_array($alltags)) {
$alltags = $this->tagger->getTagsForObjects([$fileId]);
}
return array_key_exists($fileId, $alltags) && in_array(ITags::TAG_FAVORITE, $alltags[$fileId]);
}
public function setFavorite($fileId, $favorite) : void {
if ($favorite) {
$this->tagger->addToFavorites($fileId);
} else {
$this->tagger->removeFromFavorites($fileId);
}
}
}
|