Passed
Push — feature/786_podcasts ( f026ee )
by Pauli
11:46
created

PodcastEpisodeMapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
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
	 * @return PodcastEpisode[]
25
	 */
26
	public function findAllByChannel(int $channelId, string $userId) : array {
27
		$sql = $this->selectUserEntities("`channel_id` = ?");
28
		return $this->findEntities($sql, [$userId, $channelId]);
29
	}
30
31
	public function deleteByChannel(int $channelId, string $userId) : void {
32
		$this->deleteByCond('`channel_id` = ? AND `user_id` = ?', [$channelId, $userId]);
33
	}
34
35
	public function deleteByChannelExcluding(int $channelId, array $excludedIds, string $userId) : void {
36
		$excludeCount = \count($excludedIds);
37
		if ($excludeCount === 0) {
38
			$this->deleteByChannel($channelId, $userId);
39
		} else {
40
			$this->deleteByCond(
41
				'`channel_id` = ? AND `user_id` = ? AND `id` NOT IN ' . $this->questionMarks($excludeCount),
42
				\array_merge([$channelId, $userId], $excludedIds)
43
			);
44
		}
45
	}
46
47
	/**
48
	 * @see \OCA\Music\Db\BaseMapper::findUniqueEntity()
49
	 * @param PodcastEpisode $episode
50
	 * @return PodcastEpisode
51
	 */
52
	protected function findUniqueEntity(Entity $episode) : Entity {
53
		$sql = $this->selectUserEntities("`guid_hash` = ?");
54
		return $this->findEntity($sql, [$episode->getUserId(), $episode->getGuidHash()]);
55
	}
56
}
57