Skip to content

Commit

Permalink
added new methods, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
“duck7000” committed Mar 20, 2024
1 parent 7c4835d commit 0f4777e
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
5 changes: 5 additions & 0 deletions doc/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Imdb/MdbBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
class MdbBase extends Config
{
public $version = '1.3.9';
public $version = '1.3.10';

/**
* @var CacheInterface
Expand Down
91 changes: 91 additions & 0 deletions src/Imdb/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<<EOF
query Rank(\$id: ID!) {
title(id: \$id) {
meterRanking {
currentRank
rankChange {
changeDirection
difference
}
}
}
}
EOF;

$data = $this->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 = <<<EOF
query Faq(\$id: ID!) {
title(id: \$id) {
faqs(
first: 9999
filter: {
spoilers: $spoiler
}
) {
edges {
node {
question {
plainText
}
answer {
plainText
}
isSpoiler
}
}
}
}
}
EOF;
$data = $this->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 ]---

/**
Expand Down

0 comments on commit 0f4777e

Please sign in to comment.