use OCP\ITags::TAG_FAVORITE (requires NC19)

This commit is contained in:
korelstar 2020-09-01 08:14:05 +02:00
parent bb82a12362
commit fc3829f895
1 changed files with 4 additions and 17 deletions

View File

@ -5,9 +5,12 @@ 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) {
@ -18,28 +21,12 @@ class TagService {
$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 {
$alltags = $this->cachedTags;
if (!is_array($alltags)) {
$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 {