namespace OC;
use OC\Tagging\TagMapper;
+use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IDBConnection;
+use OCP\ITagManager;
+use OCP\ITags;
+use OCP\IUserSession;
-class TagManager implements \OCP\ITagManager {
+class TagManager implements ITagManager {
- /**
- * User session
- *
- * @var \OCP\IUserSession
- */
+ /** @var TagMapper */
+ private $mapper;
+
+ /** @var IUserSession */
private $userSession;
- /**
- * TagMapper
- *
- * @var TagMapper
- */
- private $mapper;
+ /** @var IDBConnection */
+ private $connection;
- /**
- * Constructor.
- *
- * @param TagMapper $mapper Instance of the TagMapper abstraction layer.
- * @param \OCP\IUserSession $userSession the user session
- */
- public function __construct(TagMapper $mapper, \OCP\IUserSession $userSession) {
+ public function __construct(TagMapper $mapper, IUserSession $userSession, IDBConnection $connection) {
$this->mapper = $mapper;
$this->userSession = $userSession;
+ $this->connection = $connection;
}
/**
}
return new Tags($this->mapper, $userId, $type, $defaultTags);
}
+
+ /**
+ * Get all users who favorited an object
+ *
+ * @param string $objectType
+ * @param int $objectId
+ * @return array
+ */
+ public function getUsersFavoritingObject(string $objectType, int $objectId): array {
+ $query = $this->connection->getQueryBuilder();
+ $query->select('uid')
+ ->from('vcategory_to_object', 'o')
+ ->innerJoin('o', 'vcategory', 'c', $query->expr()->eq('o.categoryid', 'c.id'))
+ ->where($query->expr()->eq('objid', $query->createNamedParameter($objectId, IQueryBuilder::PARAM_INT)))
+ ->andWhere($query->expr()->eq('c.type', $query->createNamedParameter($objectType)))
+ ->andWhere($query->expr()->eq('c.category', $query->createNamedParameter(ITags::TAG_FAVORITE)));
+
+ return $query->execute()->fetchAll(\PDO::FETCH_COLUMN);
+ }
}
return $this->unTag($objid, ITags::TAG_FAVORITE);
}
- /**
- * Get all users who favorited an object
- */
- public function getUsersFavoritingObject($objId) {
- $entries = [];
-
- $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
- $query->select('uid')
- ->from('vcategory_to_object', 'o')
- ->innerJoin('o', 'vcategory', 'c', $query->expr()->eq('o.categoryid', 'c.id'))
- ->where($query->expr()->eq('objid', $query->createNamedParameter($objId, IQueryBuilder::PARAM_INT)))
- ->andWhere($query->expr()->eq('c.type', $query->createNamedParameter($this->type)))
- ->andWhere($query->expr()->eq('c.category', $query->createNamedParameter(ITags::TAG_FAVORITE)));
-
- return $query->execute()->fetchAll(\PDO::FETCH_COLUMN);
- }
-
/**
* Creates a tag/object relation.
*
$this->objectType = $this->getUniqueID('type_');
$this->tagMapper = new \OC\Tagging\TagMapper(\OC::$server->getDatabaseConnection());
- $this->tagMgr = new \OC\TagManager($this->tagMapper, $this->userSession);
+ $this->tagMgr = new \OC\TagManager($this->tagMapper, $this->userSession, \OC::$server->getDatabaseConnection());
}
protected function tearDown(): void {
->expects($this->any())
->method('getUser')
->willReturn(null);
- $this->tagMgr = new \OC\TagManager($this->tagMapper, $this->userSession);
+ $this->tagMgr = new \OC\TagManager($this->tagMapper, $this->userSession, \OC::$server->getDatabaseConnection());
$this->assertNull($this->tagMgr->load($this->objectType));
}