|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ownCloud - Music app |
|
5
|
|
|
* |
|
6
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
7
|
|
|
* later. See the COPYING file. |
|
8
|
|
|
* |
|
9
|
|
|
* @author Gavin E <[email protected]> |
|
10
|
|
|
* @author Pauli Järvinen <[email protected]> |
|
11
|
|
|
* @copyright Gavin E 2020 |
|
12
|
|
|
* @copyright Pauli Järvinen 2020, 2021 |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace OCA\Music\BusinessLayer; |
|
16
|
|
|
|
|
17
|
|
|
use \OCA\Music\AppFramework\BusinessLayer\BusinessLayer; |
|
18
|
|
|
use \OCA\Music\AppFramework\Core\Logger; |
|
19
|
|
|
|
|
20
|
|
|
use \OCA\Music\Db\BookmarkMapper; |
|
21
|
|
|
use \OCA\Music\Db\Bookmark; |
|
22
|
|
|
|
|
23
|
|
|
use \OCA\Music\Utility\Util; |
|
24
|
|
|
|
|
25
|
|
|
use \OCP\AppFramework\Db\DoesNotExistException; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Base class functions with the actually used inherited types to help IDE and Scrutinizer: |
|
29
|
|
|
* @method Bookmark find(int $bookmarkId, string $userId) |
|
30
|
|
|
* @method Bookmark[] findAll(string $userId, int $sortBy=SortBy::None, int $limit=null, int $offset=null) |
|
31
|
|
|
* @method Bookmark[] findAllByName(string $name, string $userId, bool $fuzzy=false, int $limit=null, int $offset=null) |
|
32
|
|
|
*/ |
|
33
|
|
|
class BookmarkBusinessLayer extends BusinessLayer { |
|
34
|
|
|
protected $mapper; // eclipse the definition from the base class, to help IDE and Scrutinizer to know the actual type |
|
35
|
|
|
private $logger; |
|
36
|
|
|
|
|
37
|
|
|
public function __construct(BookmarkMapper $bookmarkMapper, Logger $logger) { |
|
38
|
|
|
parent::__construct($bookmarkMapper); |
|
39
|
|
|
$this->mapper = $bookmarkMapper; |
|
40
|
|
|
$this->logger = $logger; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param int $type One of [Bookmark::TYPE_TRACK, Bookmark::TYPE_PODCAST_EPISODE] |
|
45
|
|
|
*/ |
|
46
|
|
|
public function addOrUpdate(string $userId, int $type, int $entryId, int $position, ?string $comment) : Bookmark { |
|
47
|
|
|
$bookmark = new Bookmark(); |
|
48
|
|
|
$bookmark->setUserId($userId); |
|
49
|
|
|
$bookmark->setType($type); |
|
50
|
|
|
$bookmark->setEntryId($entryId); |
|
51
|
|
|
$bookmark->setPosition($position); |
|
52
|
|
|
$bookmark->setComment(Util::truncate($comment, 256)); |
|
53
|
|
|
|
|
54
|
|
|
return $this->mapper->insertOrUpdate($bookmark); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param int $type One of [Bookmark::TYPE_TRACK, Bookmark::TYPE_PODCAST_EPISODE] |
|
59
|
|
|
* @throws DoesNotExistException if such bookmark does not exist |
|
60
|
|
|
*/ |
|
61
|
|
|
public function findByEntry(int $type, int $entryId, string $userId) : Bookmark { |
|
62
|
|
|
return $this->mapper->findByEntry($type, $entryId, $userId); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|