Closed duck7000 closed 11 months ago
I changed spouse() Separated comment and children, comment is string, children int
Now i will check it
Now Sometimes it does work. But somtimes gives this error:
in Person.php line 703 at HandleExceptions->handleError(2, 'Invalid argument supplied for foreach()', '/mnt/diskssd/web/site_copy/vendor/imdbphp/imdbphp/src/Imdb/Person.php', 703, array('query' => 'query Spouses($id: ID!) { name(id: $id) { spouses { spouse { name { id } asMarkdown { plainText } } timeRange { fromDate { dateComponents { day month year } } toDate { dateComponents { day month year } } } attributes { text } } }}', 'data' => object(stdClass)))in Person.php line 703 When it is like this: object(stdClass)#743 (1) { ["name"]=> object(stdClass)#742 (1) { ["spouses"]=> NULL } }
I have fixed it should be like this: if ($data != null && $data->name->spouses !=null)
There was another issues but i fixed at all. Last code:
#----------------------------------------------------------------[ Spouse ]---
/** Get spouse(s)
* @return array [0..n] of array spouses [string imdb, string name, array from,
* array to, string commentjs, int children where from/to are array
* [day,month,mon,year] (MonthName is the name, MonthInt the number of the month),
* @see IMDB person page /bio
*/
public function spouse()
{
if (empty($this->spouses)) {
$query = <<<EOF
query Spouses(\$id: ID!) {
name(id: \$id) {
spouses {
spouse {
name {
id
}
asMarkdown {
plainText
}
}
timeRange {
fromDate {
dateComponents {
day
month
year
}
}
toDate {
dateComponents {
day
month
year
}
}
}
attributes {
text
}
}
}
}
EOF;
$data = $this->graphql->query($query, "Spouses", ["id" => "nm$this->imdbID"]);
if ($data != null && $data->name->spouses !=null) {
foreach ($data->name->spouses as $spouse) {
// Spouse name
$name = isset($spouse->spouse->asMarkdown->plainText) ? $spouse->spouse->asMarkdown->plainText : '';
// Spouse id
$imdbId = '';
if ($spouse->spouse->name != null) {
if (isset($spouse->spouse->name->id)) {
$imdbId = str_replace('nm', '', $spouse->spouse->name->id);
}
}
// From date
$fromDateDay = isset($spouse->timeRange->fromDate->dateComponents->day) ? $spouse->timeRange->fromDate->dateComponents->day : '';
$fromDateMonthInt = isset($spouse->timeRange->fromDate->dateComponents->month) ? $spouse->timeRange->fromDate->dateComponents->month : '';
$fromDateMonthName = '';
if (!empty($fromDateMonthInt)) {
$fromDateMonthName = date("F", mktime(0, 0, 0, $fromDateMonthInt, 10));
}
$fromDateYear = isset($spouse->timeRange->fromDate->dateComponents->year) ? $spouse->timeRange->fromDate->dateComponents->year : '';
$fromDate = array(
"day" => $fromDateDay,
"month" => $fromDateMonthName,
"mon" => $fromDateMonthInt,
"year" => $fromDateYear
);
// To date
$toDateDay = isset($spouse->timeRange->toDate->dateComponents->day) ? $spouse->timeRange->toDate->dateComponents->day : '';
$toDateMonthInt = isset($spouse->timeRange->toDate->dateComponents->month) ? $spouse->timeRange->toDate->dateComponents->month : '';
$toDateMonthName = '';
if (!empty($toDateMonthInt)) {
$toDateMonthName = date("F", mktime(0, 0, 0, $toDateMonthInt, 10));
}
$toDateYear = isset($spouse->timeRange->toDate->dateComponents->year) ? $spouse->timeRange->toDate->dateComponents->year : '';
$toDate = array(
"day" => $toDateDay,
"month" => $toDateMonthName,
"mon" => $toDateMonthInt,
"year" => $toDateYear
);
// Comments (includes children)
$comment = '';
$children = 0;
if ($spouse->attributes != null) {
foreach ($spouse->attributes as $key => $attribute) {
if (stripos($attribute->text, "child") !== false) {
$children = (int) preg_replace('/[^0-9]/', '', $attribute->text);
} else {
$comment .= $attribute->text;
}
}
}
$this->spouses[] = array(
'imdb' => $imdbId,
'name' => $name,
'from' => $fromDate,
'to' => $toDate,
'comment' => $comment,
'children' => $children
);
}
}else{
}
}
return $this->spouses;
}
And bio_bio() it works very well
Thanks for testing
I did miss some checking i guess. It is fixed now.
If you find other methods with bugs, create a new issue for each of them.
Bio has not issue yet. It works very well. Step by step i will test them .
I did miss some checking i guess. It is fixed now.
You missed what-if conditions as marriage, mariage but no child , single. Thatswhy sometimes $comment undefined some times childre undefined and the last issue was about $data. You checked it's null or not. But you should check also $data->name->spouse null or not. All of these issues fixed by me
Body height works very well
$comment and $children undefind is fixed now too, i mist that too. Thanks!
closing this, this method works fine now
@Thomasdouscha
If you like i will discuss this issue here. Maybe we can work it out as it may benefit other users as well.