use OCP\ITags::TAG_FAVORITE (requires NC19)
This commit is contained in:
parent
bb82a12362
commit
fc3829f895
|
@ -5,9 +5,12 @@ declare(strict_types=1);
|
||||||
namespace OCA\Notes\Service;
|
namespace OCA\Notes\Service;
|
||||||
|
|
||||||
use OCP\ITagManager;
|
use OCP\ITagManager;
|
||||||
|
use OCP\ITags;
|
||||||
|
|
||||||
class TagService {
|
class TagService {
|
||||||
|
/** @var ITags */
|
||||||
private $tagger;
|
private $tagger;
|
||||||
|
/** @var array */
|
||||||
private $cachedTags;
|
private $cachedTags;
|
||||||
|
|
||||||
public function __construct(ITagManager $tagManager) {
|
public function __construct(ITagManager $tagManager) {
|
||||||
|
@ -18,28 +21,12 @@ class TagService {
|
||||||
$this->cachedTags = $this->tagger->getTagsForObjects($fileIds);
|
$this->cachedTags = $this->tagger->getTagsForObjects($fileIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO NC19: replace this by OCP\ITags::TAG_FAVORITE
|
|
||||||
// OCP\ITags::TAG_FAVORITE was introduced in NC19
|
|
||||||
// https://github.com/nextcloud/server/pull/19412
|
|
||||||
/**
|
|
||||||
* @suppress PhanUndeclaredClassConstant
|
|
||||||
* @suppress PhanUndeclaredConstant
|
|
||||||
* @suppress PhanUndeclaredConstantOfClass
|
|
||||||
*/
|
|
||||||
private static function getTagFavorite() {
|
|
||||||
if (defined('OCP\ITags::TAG_FAVORITE')) {
|
|
||||||
return \OCP\ITags::TAG_FAVORITE;
|
|
||||||
} else {
|
|
||||||
return \OC\Tags::TAG_FAVORITE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isFavorite($fileId) : bool {
|
public function isFavorite($fileId) : bool {
|
||||||
$alltags = $this->cachedTags;
|
$alltags = $this->cachedTags;
|
||||||
if (!is_array($alltags)) {
|
if (!is_array($alltags)) {
|
||||||
$alltags = $this->tagger->getTagsForObjects([$fileId]);
|
$alltags = $this->tagger->getTagsForObjects([$fileId]);
|
||||||
}
|
}
|
||||||
return array_key_exists($fileId, $alltags) && in_array(self::getTagFavorite(), $alltags[$fileId]);
|
return array_key_exists($fileId, $alltags) && in_array(ITags::TAG_FAVORITE, $alltags[$fileId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setFavorite($fileId, $favorite) : void {
|
public function setFavorite($fileId, $favorite) : void {
|
||||||
|
|
Loading…
Reference in New Issue