Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions schema/patches/13.sql
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);
Comment on lines +10 to +11
Copy link
Member

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


alter table uryplayer.podcast_category
add constraint podcast_category_pk
primary key (podcast_category_id);
Comment on lines +13 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done in the create table (podcast_category_id SERIAL NOT NULL PRIMARY KEY


insert into uryplayer.podcast_category (category_name) values ('URY Podcast'), ('Music Team Interview');

alter table uryplayer.podcast
add category_id int;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be add category_id int references uryplayer.podcast_category (podcast_category_id)? Saves an extra ALTER.


alter table uryplayer.podcast
add constraint podcast_category__fk
foreign key (category_id) references uryplayer.podcast_category;

update uryplayer.podcast set category_id=1;
81 changes: 65 additions & 16 deletions src/Classes/ServiceAPI/MyRadio_Podcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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()
Expand Down Expand Up @@ -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]
);
Expand All @@ -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']);
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -485,7 +512,8 @@ public static function create(
$tags,
$file,
MyRadio_Show $show = null,
$credits = null
$credits = null,
$category_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might need to be before the optional parameters ($show and friends)

) {
//Validate the tags
$tags = CoreUtils::explodeTags($tags);
Expand All @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/Controllers/Podcast/editPodcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
$data['tags'],
$data['file']['tmp_name'],
empty($data['show']) ? null : MyRadio_Show::getInstance($data['show']),
$data['credits']
$data['credits'],
$data['category']
);
$return_message = "New Podcast Created";
} else {
Expand Down