-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
podcast categories #1060
base: master
Are you sure you want to change the base?
podcast categories #1060
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
create table uryplayer.podcast_category | ||
( | ||
podcast_category_id serial not null, | ||
category_name text not null | ||
); | ||
|
||
create unique index podcast_category_category_name_uindex | ||
on uryplayer.podcast_category (category_name); | ||
|
||
create unique index podcast_category_podcast_category_id_uindex | ||
on uryplayer.podcast_category (podcast_category_id); | ||
|
||
alter table uryplayer.podcast_category | ||
add constraint podcast_category_pk | ||
primary key (podcast_category_id); | ||
Comment on lines
+13
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be done in the |
||
|
||
insert into uryplayer.podcast_category (category_name) values ('URY Podcast'), ('Music Team Interview'); | ||
|
||
alter table uryplayer.podcast | ||
add category_id int; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be |
||
|
||
alter table uryplayer.podcast | ||
add constraint podcast_category__fk | ||
foreign key (category_id) references uryplayer.podcast_category; | ||
|
||
update uryplayer.podcast set category_id=1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,13 @@ class MyRadio_Podcast extends MyRadio_Metadata_Common | |
*/ | ||
private $show_id; | ||
|
||
/** | ||
* The category name of the podcast | ||
* | ||
* @var string | ||
*/ | ||
private $category; | ||
|
||
/** | ||
* Construct the API Key Object. | ||
* | ||
|
@@ -90,7 +97,7 @@ protected function __construct($podcast_id) | |
$this->podcast_id = (int) $podcast_id; | ||
|
||
$result = self::$db->fetchOne( | ||
'SELECT file, memberid, approvedid, submitted, suspended, show_id, ( | ||
'SELECT file, memberid, approvedid, submitted, suspended, show_id, category_name ( | ||
SELECT array_to_json(array( | ||
SELECT metadata_key_id FROM uryplayer.podcast_metadata | ||
WHERE podcast_id=$1 AND effective_from <= NOW() | ||
|
@@ -127,6 +134,7 @@ protected function __construct($podcast_id) | |
) AS credits | ||
FROM uryplayer.podcast | ||
LEFT JOIN schedule.show_podcast_link USING (podcast_id) | ||
INNER JOIN uryplayer.podcast_category ON podcast.category_id=podcast_category.podcast_category_id | ||
WHERE podcast_id=$1', | ||
[$podcast_id] | ||
); | ||
|
@@ -141,6 +149,7 @@ protected function __construct($podcast_id) | |
$this->submitted = strtotime($result['submitted']); | ||
$this->suspended = ($result['suspended'] === 't') ? true : false; | ||
$this->show_id = (int) $result['show_id']; | ||
$this->category = $result['category_name']; | ||
|
||
//Deal with the Credits arrays | ||
$credit_types = json_decode($result['credit_types']); | ||
|
@@ -171,6 +180,15 @@ protected function __construct($podcast_id) | |
} | ||
} | ||
|
||
/** | ||
* Get all podcast categories | ||
*/ | ||
public static function getPodcastCategories() { | ||
return self::$db->fetchAll( | ||
'SELECT podcast_category_id AS value, category_name AS text FROM uryplayer.podcast_category' | ||
); | ||
} | ||
|
||
/** | ||
* Get all the Podcasts that the User is Owner of Creditor of. | ||
* | ||
|
@@ -248,6 +266,15 @@ public static function getForm() | |
MyRadioFormField::TYPE_BLOCKTEXT, | ||
['label' => 'Description'] | ||
) | ||
)->addField( | ||
new MyRadioFormField( | ||
'category', | ||
MyRadioFormField::TYPE_SELECT, | ||
[ | ||
'label' => 'Category', | ||
'options' => MyRadio_Podcast::getPodcastCategories() | ||
] | ||
) | ||
)->addField( | ||
new MyRadioFormField( | ||
'tags', | ||
|
@@ -485,7 +512,8 @@ public static function create( | |
$tags, | ||
$file, | ||
MyRadio_Show $show = null, | ||
$credits = null | ||
$credits = null, | ||
$category_id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might need to be before the optional parameters ( |
||
) { | ||
//Validate the tags | ||
$tags = CoreUtils::explodeTags($tags); | ||
|
@@ -495,9 +523,9 @@ public static function create( | |
//Get an ID for the new Podcast | ||
$id = (int) self::$db->fetchColumn( | ||
'INSERT INTO uryplayer.podcast ' | ||
.'(memberid, approvedid, submitted) VALUES ($1, $1, NULL) ' | ||
.'(memberid, approvedid, submitted, category_id) VALUES ($1, $1, NULL, $2) ' | ||
.'RETURNING podcast_id', | ||
[MyRadio_User::getInstance()->getID()] | ||
[MyRadio_User::getInstance()->getID(), $category_id] | ||
)[0]; | ||
|
||
// DANGER WILL ROBINSON DANGER | ||
|
@@ -707,6 +735,17 @@ public function getWebpage() | |
return '/uryplayer/podcasts/'.$this->getID(); | ||
} | ||
|
||
/** | ||
* Get the podcast category | ||
* | ||
* @return string | ||
*/ | ||
|
||
public function getCategory() | ||
{ | ||
return $this->category; | ||
} | ||
|
||
/** | ||
* Set the suspended status of this podcast. | ||
* | ||
|
@@ -818,6 +857,7 @@ public function toDataSource($mixins = []) | |
'status' => $this->getStatus(), | ||
'time' => $this->getSubmitted(), | ||
'uri' => $this->getURI(), | ||
'category' => $this->getCategory(), | ||
'editlink' => [ | ||
'display' => 'icon', | ||
'value' => 'pencil', | ||
|
@@ -1027,27 +1067,36 @@ public function convert() | |
* @param int $page The page required. | ||
* @param bool $include_suspended Whether to include suspended podcasts in the result | ||
* @param bool $include_pending Whether to include pending (future publish/processing) podcasts in the result | ||
* | ||
* @param int | null $category_id - the ID number of the category of podcast to filter by | ||
* | ||
* @return Array[MyRadio_Podcast] | ||
*/ | ||
public static function getAllPodcasts( | ||
$include_suspended = false, | ||
$include_pending = false, | ||
$category_id = null, | ||
$num_results = 0, | ||
$page = 1 | ||
) { | ||
$where = ''; | ||
if (!$include_suspended || !$include_pending) { | ||
$where = 'WHERE '; | ||
if (!$include_suspended) { | ||
$where .= 'suspended = false'; | ||
} | ||
if (!$include_suspended && !$include_pending) { | ||
$where .= ' AND '; | ||
} | ||
if (!$include_pending) { | ||
$where .= 'submitted IS NOT NULL'; | ||
} | ||
$filter_strings = []; | ||
|
||
if (!$include_suspended) { | ||
array_push($filter_strings, 'suspended = false'); | ||
} | ||
|
||
if (!$include_pending) { | ||
array_push($filter_strings, 'submitted IS NOT NULL'); | ||
} | ||
|
||
if (!isNull($category_id)) { | ||
array_push($filter_strings, sprintf('category_id = %u', $category_id)); | ||
} | ||
|
||
$where = join(" AND ", $filter_strings); | ||
|
||
if ($where != "") { | ||
$where = 'WHERE ' . $where; | ||
} | ||
|
||
$filterLimit = $num_results == 0 ? 'ALL' : $num_results; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: redundant if it's already a primary key