Passed
Pull Request — master (#875)
by Pauli
05:02 queued 02:27
created

PodcastChannel::detailsToApi()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 14
rs 9.8333
c 0
b 0
f 0
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 \OCA\Music\Utility\Util;
17
18
/**
19
 * @method string getUserId()
20
 * @method void setUserId(string $userId)
21
 * @method string getRssUrl()
22
 * @method void setRssUrl(string $url)
23
 * @method string getRssHash()
24
 * @method void setRssHash(string $hash)
25
 * @method string getContentHash()
26
 * @method void setContentHash(string $hash)
27
 * @method string getUpdateChecked()
28
 * @method void setUpdateChecked(string $timestamp)
29
 * @method string getPublished()
30
 * @method void setPublished(string $timestamp)
31
 * @method string getTitle()
32
 * @method void setTitle(string $title)
33
 * @method string getLinkUrl()
34
 * @method void setLinkUrl(string $url)
35
 * @method string getLanguage()
36
 * @method void setLanguage(string $language)
37
 * @method string getCopyright()
38
 * @method void setCopyright(string $copyright)
39
 * @method string getAuthor()
40
 * @method void setAuthor(string $author)
41
 * @method string getDescription()
42
 * @method void setDescription(string $description)
43
 * @method string getImageUrl()
44
 * @method void setImageUrl(string $url)
45
 * @method string getCategory()
46
 * @method void setCategory(string $category)
47
 * @method string getStarred()
48
 * @method void setStarred(string $timestamp)
49
 * @method string getCreated()
50
 * @method void setCreated(string $timestamp)
51
 * @method string getUpdated()
52
 * @method void setUpdated(string $timestamp)
53
 * @method PodcastEpisode[] getEpisodes()
54
 * @method void setEpisodes(PodcastEpisode[] $episodes)
55
 */
56
class PodcastChannel extends Entity {
57
	public $userId;
58
	public $rssUrl;
59
	public $rssHash;
60
	public $contentHash;
61
	public $updateChecked;
62
	public $published;
63
	public $title;
64
	public $linkUrl;
65
	public $language;
66
	public $copyright;
67
	public $author;
68
	public $description;
69
	public $imageUrl;
70
	public $category;
71
	public $starred;
72
	public $created;
73
	public $updated;
74
75
	// not part of the default content, may be injected separately
76
	public $episodes;
77
78
	public function toApi() : array {
79
		$result = [
80
			'id' => $this->getId(),
81
			'title' => $this->getTitle(),
82
			'image' => $this->getImageUrl(),
83
			'hash' => $this->getContentHash()
84
		];
85
86
		if ($this->episodes !== null) {
87
			$result['episodes'] = Util::arrayMapMethod($this->episodes, 'toApi');
88
		}
89
90
		return $result;
91
	}
92
93
	public function detailsToApi() : array {
94
		return [
95
			'id' => $this->getId(),
96
			'title' => $this->getTitle(),
97
			'description' => $this->getDescription(),
98
			'image' => $this->getImageUrl(),
99
			'link_url' =>  $this->getLinkUrl(),
100
			'rss_url' => $this->getRssUrl(),
101
			'language' => $this->getLanguage(),
102
			'copyright' => $this->getCopyright(),
103
			'author' => $this->getAuthor(),
104
			'category' => $this->getCategory(),
105
			'published' => $this->getPublished(),
106
			'update_checked' => $this->getUpdateChecked(),
107
		];
108
	}
109
110
	public function toAmpacheApi() : array {
111
		$result = [
112
			'id' => (string)$this->getId(),
113
			'name' => $this->getTitle(),
114
			'description' => $this->getDescription(),
115
			'language' => $this->getLanguage(),
116
			'copyright' => $this->getCopyright(),
117
			'feed_url' => $this->getRssUrl(),
118
			'build_date' => $this->getPublished(), // TODO: not actually the lastBuildDate...; should we format this?
119
			'sync_date' => $this->getUpdateChecked(), // TODO: should we format this?
120
			'public_url' => $this->getLinkUrl(),
121
			'website' => $this->getLinkUrl(),
122
			'art' => $this->getImageUrl(),
123
			'flag' => empty($this->getStarred()) ? 0 : 1,
124
		];
125
126
		if ($this->episodes !== null) {
127
			$result['podcast_episode'] = Util::arrayMapMethod($this->episodes, 'toAmpacheApi');
128
		}
129
130
		return $result;
131
	}
132
133
	public function toSubsonicApi() : array {
134
		$result = [
135
			'id' => 'podcast_channel-' . $this->getId(),
136
			'url' => $this->getRssUrl(),
137
			'title' => $this->getTitle(),
138
			'description' => $this->getDescription(),
139
			'coverArt' => 'podcast_channel-' . $this->getId(),
140
			'originalImageUrl' => $this->getImageUrl(),
141
			'status' => 'completed'
142
		];
143
144
		if (!empty($this->starred)) {
145
			$result['starred'] = Util::formatZuluDateTime($this->starred);
146
		}
147
148
		if ($this->episodes !== null) {
149
			$result['episode'] = Util::arrayMapMethod($this->episodes, 'toSubsonicApi');
150
		}
151
152
		return $result;
153
	}
154
}
155