Imdb\Title::awards PHP Метод

awards() публичный Метод

Get all awards this title was nominated for or won
См. также: IMDB page /awards
public awards ( boolean $compat = TRUE ) : array
$compat boolean whether stay backward compatible to the original format of Qvist. Default: TRUE
Результат array awards array[festivalName]['entries'][0..n] of array[year,won,category,award,people[],comment,outcome] e.g.
  [
   'Science Fiction and Fantasy Writers of America' =>
   [
     'entries' =>
     [
       [
         'year' => '2000',
         'won' => false,
         'category' => 'Best Script',
         'award' => 'Nebula Award',
         'people' =>
         [
             '0905154' => 'Lana Wachowski',
             '0905152' => 'Andy Wachowski',
         ],
         'outcome' => 'Nominated'
       ]
     ]
   ]
 ]
    public function awards($compat = TRUE)
    {
        if (empty($this->awards)) {
            $this->getPage("Awards");
            $row_s = strpos($this->page["Awards"], '<h1 class="header">Awards</h1>');
            $row_e = strpos($this->page["Awards"], '<div class="article"', $row_s);
            $block = substr($this->page["Awards"], $row_s, $row_e - $row_s);
            preg_match_all('!<h3>\\s*(?<festival>.+?)\\s*<a [^>]+>\\s*(?<year>\\d{4}).*?</h3>\\s*<table [^>]+>(?<table>.+?)</table>!ims', $block, $matches);
            $acount = count($matches[0]);
            for ($i = 0; $i < $acount; $i++) {
                $festival = $matches['festival'][$i];
                if (!preg_match_all('!<td class="(?<class>.+?)"[^>]*>\\s*(?<data>.*?)\\s*</td>!ims', $matches['table'][$i], $col)) {
                    continue;
                }
                $ccount = count($col[0]);
                for ($k = 0; $k < $ccount; ++$k) {
                    switch ($col['class'][$k]) {
                        case "title_award_outcome":
                            $have_title = TRUE;
                            $have_desc = FALSE;
                            preg_match('!(?<outcome>.+?)<br\\s*/>\\s*<span class="award_category">\\s*(?<award>.+?)</span>!ims', $col['data'][$k], $data);
                            $outcome = trim(strip_tags($data['outcome']));
                            $outcome == "Won" ? $won = TRUE : ($won = FALSE);
                            $award = trim($data['award']);
                            break;
                        case "award_description":
                            $desc = trim($col['data'][$k]);
                            if (preg_match_all('|<a href\\="/name/nm(\\d{7})[^"]*"\\s*>(.*?)</a>|s', $desc, $data)) {
                                $people = isset($data[0][0]) ? array_combine($data[1], $data[2]) : array();
                                preg_match('!(.+?)<br!ims', $desc, $data) ? $cat = $data[1] : ($cat = '');
                                if (substr($cat, 0, 3) == '<a ') {
                                    $cat = '';
                                }
                            } else {
                                $desc = preg_replace('#<div class="award_detail_notes">.+?</div>#s', '', $desc);
                                $cat = trim(strip_tags($desc));
                                $people = array();
                            }
                            if ($compat) {
                                $this->awards[$festival]['entries'][] = array('year' => $matches['year'][$i], 'won' => $won, 'category' => $cat, 'award' => $award, 'people' => $people, 'comment' => '', 'outcome' => $outcome);
                            } else {
                                $this->awards[$festival][] = array('year' => $matches['year'][$i], 'won' => $won, 'category' => $cat, 'award' => $award, 'people' => $people, 'outcome' => $outcome);
                            }
                            break;
                        default:
                            break;
                    }
                }
                continue;
            }
        }
        return $this->awards;
    }