|
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 Pauli Järvinen <[email protected]> |
|
10
|
|
|
* @copyright Pauli Järvinen 2021 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace OCA\Music\Db; |
|
14
|
|
|
|
|
15
|
|
|
use \OCP\AppFramework\Db\Entity; |
|
16
|
|
|
use \OCP\IDBConnection; |
|
17
|
|
|
|
|
18
|
|
|
class PodcastEpisodeMapper extends BaseMapper { |
|
19
|
|
|
public function __construct(IDBConnection $db) { |
|
20
|
|
|
parent::__construct($db, 'music_podcast_episodes', '\OCA\Music\Db\PodcastEpisode', 'title'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param int[] $channelIds |
|
25
|
|
|
* @return PodcastEpisode[] |
|
26
|
|
|
*/ |
|
27
|
|
|
public function findAllByChannel(array $channelIds, string $userId, ?int $limit=null, ?int $offset=null) : array { |
|
28
|
|
|
$channelCount = \count($channelIds); |
|
29
|
|
|
if ($channelCount === 0) { |
|
30
|
|
|
return []; |
|
31
|
|
|
} else { |
|
32
|
|
|
$condition = '`channel_id` IN ' . $this->questionMarks($channelCount); |
|
33
|
|
|
$sorting = 'ORDER BY `id` DESC'; |
|
34
|
|
|
$sql = $this->selectUserEntities($condition, $sorting); |
|
35
|
|
|
return $this->findEntities($sql, \array_merge([$userId], $channelIds), $limit, $offset); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function deleteByChannel(int $channelId, string $userId) : void { |
|
40
|
|
|
$this->deleteByCond('`channel_id` = ? AND `user_id` = ?', [$channelId, $userId]); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function deleteByChannelExcluding(int $channelId, array $excludedIds, string $userId) : void { |
|
44
|
|
|
$excludeCount = \count($excludedIds); |
|
45
|
|
|
if ($excludeCount === 0) { |
|
46
|
|
|
$this->deleteByChannel($channelId, $userId); |
|
47
|
|
|
} else { |
|
48
|
|
|
$this->deleteByCond( |
|
49
|
|
|
'`channel_id` = ? AND `user_id` = ? AND `id` NOT IN ' . $this->questionMarks($excludeCount), |
|
50
|
|
|
\array_merge([$channelId, $userId], $excludedIds) |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @see \OCA\Music\Db\BaseMapper::findUniqueEntity() |
|
57
|
|
|
* @param PodcastEpisode $episode |
|
58
|
|
|
* @return PodcastEpisode |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function findUniqueEntity(Entity $episode) : Entity { |
|
61
|
|
|
$sql = $this->selectUserEntities("`guid_hash` = ?"); |
|
62
|
|
|
return $this->findEntity($sql, [$episode->getUserId(), $episode->getGuidHash()]); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|