tmdb_v3-PHP-API- icon indicating copy to clipboard operation
tmdb_v3-PHP-API- copied to clipboard

Num of episodes in seasons loop

Open ChrisTERiS opened this issue 4 years ago • 3 comments

Hello,

Any idea why the code below in infoTVShow.php return 0 as amount of episodes in seasons loop? echo '<li>Seasons: <ul>'; $seasons = $tvShow->getSeasons(); foreach ($seasons as $season) { echo '<li><a href="https://www.themoviedb.org/tv/season/'.$season->getID().'">Season '.$season->getSeasonNumber().'</a></li> <li>Air Date: '.$season->getAirDate().'</li> <li>Episodes: '.$season->getNumEpisodes().'</li> <li><img src="'. $tmdb->getImageURL('w185') . $season->getPoster() .'"/></li>'; } echo '</ul></li> I tried to pass as parameter: $season->getNumEpisodes($season->getID()) but I had no success.

Thank you Chris

ChrisTERiS avatar Oct 26 '20 07:10 ChrisTERiS

I found a trick to solve this, but I don't think that is a quality code. Added at the top of foreach loop $season_data = $tmdb->getSeason($tvShow->getID(), $season->getSeasonNumber()); and then: $season_data->getNumEpisodes()

ChrisTERiS avatar Oct 26 '20 07:10 ChrisTERiS

@ChrisTERiS

Added a getEpisodeCount() to Seasons when you are in a tvShow Scope. Your first solutions would be correct, when you fetch the Season Details but you are coming from tvShow Details. Therefore the season has not all detail information.

Pushed on my fork and created a merge request for that. Also added an example in infoTVShow.php how to iterate over $seasons and display episode count;

Your second solution would work aswell, but this is fetching season details for each.

bogdanfinn avatar Oct 29 '20 07:10 bogdanfinn

@ChrisTERiS

Added a getEpisodeCount() to Seasons when you are in a tvShow Scope. Your first solutions would be correct, when you fetch the Season Details but you are coming from tvShow Details. Therefore the season has not all detail information.

Pushed on my fork and created a merge request for that. Also added an example in infoTVShow.php how to iterate over $seasons and display episode count;

Your second solution would work aswell, but this is fetching season details for each.

I really appreciate your help and support. THANK YOU !!

ChrisTERiS avatar Oct 29 '20 07:10 ChrisTERiS