/** * Parses the Theaters from the result div. * * @param bool $includeShowtimes * @return array|null */ public function parseTheaters($includeShowtimes = true) { $theatersDivs = $this->crawler->filter('#movie_results .theater'); $count = $theatersDivs->count(); if ($count == 0) { return null; } if ($count = 1) { $justOneTheaterFound = true; } $theaters = $theatersDivs->each(function (Crawler $theaterDiv, $i) use($includeShowtimes, $justOneTheaterFound) { $resultItemParser = new ResultItemParser($theaterDiv); if ($justOneTheaterFound) { $firstLeftNavLink = $this->getFirstLeftNavLink(); $fallbackUrl = $firstLeftNavLink->attr('href'); $theater = $resultItemParser->parseResultTheaterItem($fallbackUrl); } else { $theater = $resultItemParser->parseResultTheaterItem(); } if (!$theater) { return null; } if ($includeShowtimes) { $theater->setShowtimeInfo($this->parseShowtimeInfo($theaterDiv)); } return $theater; }); $theaters = array_filter($theaters, function ($item) { return $item != null; }); return $theaters; }
public function parseTheaters($includeShowtimes = true) { $theaters = []; $theatersDivs = $this->crawler->filter('#movie_results .theater'); $count = $theatersDivs->count(); if ($count == 0) { return null; } foreach ($theatersDivs as $i => $contents) { $theaterDiv = new Crawler($contents); $resultItemParser = new ResultItemParser($theaterDiv); $theater = $resultItemParser->parseResultTheaterItem(); if ($theater == null) { break; } if ($includeShowtimes) { $theater->setShowtimeInfo($this->parseShowtimeInfo($theaterDiv)); } $theaters[] = $theater; } return $theaters; }