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

Commit

Permalink
Added some recursive use of the polymorphic single item fetching to m…
Browse files Browse the repository at this point in the history
…ake sure we refetch a single item when we received it from a list to make sure the data is as complete as possible.
  • Loading branch information
nickbart committed Dec 25, 2012
1 parent d9e9dc8 commit 23e4920
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Server/Library/ItemAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ public function setAttributes($attribute)
* returned.
*
* @uses Plex_MachineAbstract::getCallingFunction()
* @uses Plex_Server_Library_SectionAbstract::getPolymorphicItem()
* @uses Plex_Server_Library::functionToType()
* @uses Plex_Server_Library_ItemAbstract::getIndex()
* @uses Plex_Server_Library_ItemAbstract::getRatingKey()
*
* @return Plex_Server_Library_ItemAbstract A single Plex library item.
*/
Expand All @@ -207,7 +209,15 @@ public function getItemByIndex($index)
if (method_exists($this, $getMethod)) {
foreach ($this->{$getMethod}() as $item) {
if ($item->getIndex() === $index) {
return $item;
// So, this might seem a bit recursive, but there's method
// to this madness. Once we have identified the correct item
// by its key, we use the parent item retrieval system to
// get the item by its rating key. We do this because Plex
// limits the amount of data that comes back with an item
// when you ask for more than one at a time. By asking for
// for it singularly here, we guarantee we get the most data
// back, like grandparent and parent keys and titles.
return parent::getPolymorphicItem($item->getRatingKey());
}
}
}
Expand Down
22 changes: 21 additions & 1 deletion Server/Library/SectionAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ protected function getItemsByYear($year)
* @uses Plex_Server_Library::ENDPOINT_METADATA
* @uses Plex_Server_Library::ENDPOINT_LIBRARY
* @uses Plex_Server_Library_ItemAbstract::getTitle()
* @uses Plex_Server_Library_ItemAbstract::getRatingKey()
* @uses Plex_Server_Library_SectionAbstract::getPolymorphicItem()
*
* @return Plex_Server_Library_ItemAbstract The request Plex library item.
*/
Expand Down Expand Up @@ -578,7 +580,25 @@ protected function getPolymorphicItem($polymorphicData, $scopedToItem = FALSE)
if (method_exists($this, $searchMethod)) {
foreach ($this->{$searchMethod}($polymorphicData) as $item) {
if ($item->getTitle() === $polymorphicData) {
return $item;
if ($scopedToItem) {
// So, this might seem a bit recursive, but there's
// method to this madness. If we are scoped to an
// item and we have identified the item by its
// title, we have to refetch the item singularly by
// its rating key. We do this because we have used a
// "get" method to find this item instead of a
// "search" method and Plex limits the amount of
// data that comes back with an item when you ask
// for more than one at a time. By asking for it
// singularly here, we guarantee we get the most
// data back, like grandparent and parent keys and
// titles.
return self::getPolymorphicItem(
$item->getRatingKey()
);
} else {
return $item;
}
}
}
}
Expand Down

0 comments on commit 23e4920

Please sign in to comment.