From 0f4777e7a40d303b126b965a3a9480408070b642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cduck7000=E2=80=9D?= <“ed@riethorst.net”> Date: Wed, 20 Mar 2024 16:45:10 +0100 Subject: [PATCH] added new methods, version bump --- doc/CHANGELOG | 5 +++ src/Imdb/MdbBase.php | 2 +- src/Imdb/Title.php | 91 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) diff --git a/doc/CHANGELOG b/doc/CHANGELOG index a9ef8445..d12b579a 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -2,6 +2,11 @@ History for IMDBPHP6 ==================== +v1.3.10 +------------------- +* Added popRank method to Title class, Gets the popularity rank of a title (all info is in the wiki) +* Added faq method to Title Class, Gets all frequent asked questions of this title (all info is in the wiki) + v1.3.9 ------------------- * Added sound method to Title class (all info is in the wiki) diff --git a/src/Imdb/MdbBase.php b/src/Imdb/MdbBase.php index 356f2706..2d12df81 100644 --- a/src/Imdb/MdbBase.php +++ b/src/Imdb/MdbBase.php @@ -21,7 +21,7 @@ */ class MdbBase extends Config { - public $version = '1.3.9'; + public $version = '1.3.10'; /** * @var CacheInterface diff --git a/src/Imdb/Title.php b/src/Imdb/Title.php index 58e8ca18..50f7cadb 100755 --- a/src/Imdb/Title.php +++ b/src/Imdb/Title.php @@ -316,6 +316,97 @@ public function metacritic() } } + #----------------------------------------------------------[ Popularity ]--- + /** + * Get movie popularity rank + * @return array(currentRank: int, changeDirection: enum (string?), difference: int) + * @see IMDB page / (TitlePage) + */ + public function popRank() + { + if (empty($this->main_rank)) { + $query = <<graphql->query($query, "Rank", ["id" => "tt$this->imdbID"]); + if (isset($data->title->meterRanking)) { + $this->main_rank['currentRank'] = isset($data->title->meterRanking->currentRank) ? + $data->title->meterRanking->currentRank : null; + + $this->main_rank['changeDirection'] = isset($data->title->meterRanking->rankChange->changeDirection) ? + $data->title->meterRanking->rankChange->changeDirection : null; + + $this->main_rank['difference'] = isset($data->title->meterRanking->rankChange->difference) ? + $data->title->meterRanking->rankChange->difference : null; + } else { + return $this->main_rank; + } + } + return $this->main_rank; + } + + #----------------------------------------------------------[ FAQ ]--- + /** + * Get movie frequently asked questions, it includes questions with and without answer + * @param $spoiler boolean (true or false) to include spoilers or not, isSpoiler indicates if this question is spoiler or not + * @return array of array(question: string, answer: string, isSpoiler: boolean) + * @see IMDB page / (Faq) + */ + public function faq($spoiler = false) + { + if (empty($this->faqs)) { + $spoiler = $spoiler === true ? "null" : "EXCLUDE_SPOILERS"; + $query = <<graphql->query($query, "Faq", ["id" => "tt$this->imdbID"]); + if ($data->title->faqs->edges != null) { + foreach ($data->title->faqs->edges as $edge) { + $this->faqs[] = array( + 'question' => isset($edge->node->question->plainText) ? $edge->node->question->plainText : '', + 'answer' => isset($edge->node->answer->plainText) ? $edge->node->answer->plainText : '', + 'isSpoiler' => $edge->node->isSpoiler + ); + } + } else { + return $this->faqs; + } + } + return $this->faqs; + } + #-------------------------------------------------------[ Recommendations ]--- /**