コード例 #1
0
 public function getPossibleBookings($url, $movie)
 {
     $this->movie = $movie;
     $this->convertedDay = $this->convertDay();
     $this->convertedTime = $this->convertTime();
     $availableForBooking = array();
     try {
         $scraper = new \models\Scraper($url);
         $this->result = $scraper->scrape($url);
         $dom = $scraper->getDOMDocument($this->result);
         $checkDays = $dom->query('//p[@class="MsoNormal"]//input[@type="radio"]');
         foreach ($checkDays as $day) {
             $dayToCheckFor = $day->getAttribute("value")[0] . $day->getAttribute("value")[1];
             $startTime = mb_substr($day->getAttribute("value"), 3, 2);
             if ($dayToCheckFor == $this->convertedDay) {
                 if ($startTime >= $this->convertedTime + 2) {
                     $possibleObject = new \models\PossibleDate($this->movie->getDay(), $day->getAttribute("value"), $this->movie->getName());
                     array_push($availableForBooking, serialize($possibleObject));
                 }
             }
         }
     } catch (\Exception $e) {
         $e->getMessage();
     }
     return $availableForBooking;
 }
コード例 #2
0
 /**
  * called in $this->getPossibleMovies()
  * @param $baseUrl
  * @param $selectedDays
  * @param $selectedMovies
  * @return array array with possible movies that fits $daysToMeet
  * @throws Exception
  */
 private function getMovies($baseUrl, $selectedDays, $selectedMovies)
 {
     $possibleMovies = array();
     //foreach selected day check movies on that day
     //if movie is not sold out ($value["status"] == 0)
     //than create a PossibleDate pobject
     foreach ($selectedDays as $key => $day) {
         foreach ($selectedMovies as $movie) {
             $url = $baseUrl . "/check?day=" . $day["value"] . "&movie=" . $movie["value"];
             try {
                 $scraper = new \models\Scraper($url);
                 $result = $scraper->scrape($url);
                 $json = $scraper->getJSON($result);
                 foreach ($json as $value) {
                     if (!$value["status"] == 0) {
                         $possibleDateObject = new \models\PossibleDate($day["day"], $value["time"], $movie["name"]);
                         array_push($possibleMovies, $possibleDateObject);
                     }
                 }
             } catch (\Exception $e) {
                 $e->getMessage();
             }
         }
     }
     return $possibleMovies;
 }
コード例 #3
0
ファイル: BookTable.php プロジェクト: js223kz/PHP_WEBSCRAPER
 public function getBookingForm($url)
 {
     try {
         $scraper = new \models\Scraper($url);
         $result = $scraper->scrape($url);
         // $dom = $scraper->getDOMDocument($this->result);
     } catch (\Exception $e) {
         $e->getMessage();
     }
     return $result;
 }
コード例 #4
0
 /**
  * called in $this->getCalendars()
  * @param $newUrl
  * @throws Exception
  */
 private function setCalendars($newUrl)
 {
     $newDay = new Day();
     try {
         $scraper = new \models\Scraper($newUrl);
         $result = $scraper->scrape($newUrl);
         $dom = $scraper->getDOMDocument($result);
     } catch (\Exception $e) {
         $e->getMessage();
     }
     $days = $dom->query('//table//thead//tr/th');
     $statuses = $dom->query('//table//tbody//tr/td');
     foreach ($days as $day) {
         $dayToUpper = strtoupper($day->nodeValue);
         foreach ($statuses as $status) {
             $statusToUpper = strtoupper($status->nodeValue);
             if ($statusToUpper == 'OK') {
                 $newDay->day = $dayToUpper;
                 $newDay->available = $statusToUpper;
             }
         }
     }
     array_push($this->days, $newDay);
 }
コード例 #5
0
 private function getUrls($url)
 {
     try {
         $scraper = new \models\Scraper();
         $result = $scraper->scrape($url);
         $dom = $scraper->getDOMDocument($result);
     } catch (\Exception $e) {
         $e->getMessage();
     }
     $items = $dom->query('//ol//li/a');
     foreach ($items as $item) {
         $trimmed = trim($item->getAttribute('href'), " /");
         $newUrl = $url . $trimmed;
         if ($trimmed == 'calendar') {
             $this->calendarUrl = $newUrl;
         }
         if ($trimmed == 'cinema') {
             $this->movieUrl = $newUrl;
         }
         if ($trimmed == 'dinner') {
             $this->restaurantUrl = $newUrl;
         }
     }
 }