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 - 2023 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace OCA\Music\Db; |
14
|
|
|
|
15
|
|
|
use OCP\IDBConnection; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Type hint a base class methdo to help Scrutinizer |
19
|
|
|
* @method PodcastEpisode updateOrInsert(PodcastEpisode $episode) |
20
|
|
|
* @phpstan-extends BaseMapper<PodcastEpisode> |
21
|
|
|
*/ |
22
|
|
|
class PodcastEpisodeMapper extends BaseMapper { |
23
|
|
|
public function __construct(IDBConnection $db) { |
24
|
|
|
parent::__construct($db, 'music_podcast_episodes', PodcastEpisode::class, 'title'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param int[] $channelIds |
29
|
|
|
* @return PodcastEpisode[] |
30
|
|
|
*/ |
31
|
|
|
public function findAllByChannel(array $channelIds, string $userId, ?int $limit=null, ?int $offset=null) : array { |
32
|
|
|
$channelCount = \count($channelIds); |
33
|
|
|
if ($channelCount === 0) { |
34
|
|
|
return []; |
35
|
|
|
} else { |
36
|
|
|
$condition = '`channel_id` IN ' . $this->questionMarks($channelCount); |
37
|
|
|
$sorting = 'ORDER BY `id` DESC'; |
38
|
|
|
$sql = $this->selectUserEntities($condition, $sorting); |
39
|
|
|
return $this->findEntities($sql, \array_merge([$userId], $channelIds), $limit, $offset); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function deleteByChannel(int $channelId, string $userId) : void { |
44
|
|
|
$this->deleteByCond('`channel_id` = ? AND `user_id` = ?', [$channelId, $userId]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function deleteByChannelExcluding(int $channelId, array $excludedIds, string $userId) : void { |
48
|
|
|
$excludeCount = \count($excludedIds); |
49
|
|
|
if ($excludeCount === 0) { |
50
|
|
|
$this->deleteByChannel($channelId, $userId); |
51
|
|
|
} else { |
52
|
|
|
$this->deleteByCond( |
53
|
|
|
'`channel_id` = ? AND `user_id` = ? AND `id` NOT IN ' . $this->questionMarks($excludeCount), |
54
|
|
|
\array_merge([$channelId, $userId], $excludedIds) |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Overridden from the base implementation to provide support for table-specific rules |
61
|
|
|
* |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
* @see BaseMapper::advFormatSqlCondition() |
64
|
|
|
*/ |
65
|
|
|
protected function advFormatSqlCondition(string $rule, string $sqlOp) : string { |
66
|
|
|
switch ($rule) { |
67
|
|
|
case 'podcast': return "`channel_id` IN (SELECT `id` FROM `*PREFIX*music_podcast_channels` `c` WHERE LOWER(`c`.`title`) $sqlOp LOWER(?))"; |
68
|
|
|
case 'time': return "`duration` $sqlOp ?"; |
69
|
|
|
case 'pubdate': return "`published` $sqlOp ?"; |
70
|
|
|
default: return parent::advFormatSqlCondition($rule, $sqlOp); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @see \OCA\Music\Db\BaseMapper::findUniqueEntity() |
76
|
|
|
* @param PodcastEpisode $episode |
77
|
|
|
* @return PodcastEpisode |
78
|
|
|
*/ |
79
|
|
|
protected function findUniqueEntity(Entity $episode) : Entity { |
80
|
|
|
$sql = $this->selectUserEntities("`guid_hash` = ? AND `channel_id` = ?"); |
81
|
|
|
return $this->findEntity($sql, [$episode->getUserId(), $episode->getGuidHash(), $episode->getChannelId()]); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.