Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Commit

Permalink
Added all episode and all track listing for show and artist classes. …
Browse files Browse the repository at this point in the history
…Also added random episode and track retrieval for the show and artist classes.
  • Loading branch information
nickbart committed Dec 29, 2012
1 parent e6245f4 commit 0e1fa22
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Server/Library/Item/Artist.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,35 @@ public function getAlbum($polymorphicData)
{
return $this->getPolymorphicItem($polymorphicData);
}

/**
* Returns all the tracks for a given artist.
*
* @uses Plex_Server_Library::getItems()
* @uses Plex_Server_Library_ItemAbstract::buildAllLeavesEndpoint()
*
* @ return Plex_Server_Library_Item_Track[] Array of all the tracks for
* a given artist.
*/
public function getAllTracks()
{
return $this->getItems(
$this->buildAllLeavesEndpoint()
);
}

/**
* Returns a single random track for a given artist.
*
* @uses Plex_Server_Library_Item_Artist::getAllTracks()
*
* @return Plex_Server_Library_Item_Track A single random track.
*/
public function getRandomTrack()
{
$allTracks = $this->getAllTracks();
$ceiling = count($allTracks)-1;
$randomNumber = mt_rand(0, $ceiling);
return $allTracks[$randomNumber];
}
}
31 changes: 31 additions & 0 deletions Server/Library/Item/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,35 @@ public function getSeason($polymorphicData)
{
return $this->getPolymorphicItem($polymorphicData);
}

/**
* Returns all the episodes for a given show.
*
* @uses Plex_Server_Library::getItems()
* @uses Plex_Server_Library_ItemAbstract::buildAllLeavesEndpoint()
*
* @ return Plex_Server_Library_Item_Episode[] Array of all the episodes for
* a given show.
*/
public function getAllEpisodes()
{
return $this->getItems(
$this->buildAllLeavesEndpoint()
);
}

/**
* Returns a single random episode for a given show.
*
* @uses Plex_Server_Library_Item_Show::getAllEpisodes()
*
* @return Plex_Server_Library_Item_Episode A single random episode.
*/
public function getRandomEpisode()
{
$allEpisodes = $this->getAllEpisodes();
$ceiling = count($allEpisodes)-1;
$randomNumber = mt_rand(0, $ceiling);
return $allEpisodes[$randomNumber];
}
}

0 comments on commit 0e1fa22

Please sign in to comment.