include_once "transavia.php";
include_once "countrycode.php";
include_once "recepten.php";
include_once "Allerhande.php";
include_once "countrycolors.php";
include_once "huemanager.php";
include_once "bolmanager.php";
include_once "spotify.php";
include_once "schiphol.php";
//Getting those annoying notices and warnings out of the way
error_reporting(0);
// ini_set('display_errors', 1);
$flightId = $_REQUEST['flightId'];
$numberOfRecipes = $_REQUEST['numberOfRecipes'];
$airportCode = Transavia::getCountryCodeForJourney($flightId);
$countryCode = CountryCode::getCountryCodeForIATA($airportCode);
$fileName = "cache/cache.json." . $flightId . $numberOfRecipes;
$jsonObject = new StdClass();
if (file_exists($fileName)) {
    $jsonObject = json_decode(file_get_contents($fileName));
} else {
    $jsonObject->recepten = Recepten::getReceptenForCountry($countryCode, $numberOfRecipes);
    $jsonObject->colors->RGB = CountryColors::getMainColors($countryCode);
    $jsonObject->colors->HUE = CountryColors::array_RGB_TO_HUE($jsonObject->colors->RGB);
    $jsonObject->producten = BolManager::getProductsForCountry($search = Countries::getDutchName($countryCode));
    //$jsonObject->bagbeltNumber = Schiphol::getBagbeltNumber($journeyCode);
    $jsonObject->spotify = Spotify::getTrack($countryCode);
    foreach ($jsonObject->recepten as &$r) {
        $r->receptimagehd = Allerhande::getHighResImage($r->recepturl);
    }
    file_put_contents($fileName, json_encode($jsonObject));
Beispiel #2
0
 /**
  * Returns a Country object based on a given alpha or numeric code.
  *
  * <code>
  *      $country = Country::find(300);
  *      $country = Country::find('GR');
  *      $country = Country::find('GRC');
  * </code>
  *
  * @param string|integer Alpha name or numeric code of a country 
  *
  * @return Country A Country object.
  */
 public static function find($name)
 {
     if (empty($name)) {
         throw new \InvalidArgumentException('Cannot lookup country for an empty name');
     }
     if (strlen($name) == 2 || strlen($name) == 3) {
         $upcase_name = strtoupper($name);
         $country_code = new CountryCode($name);
         $country_format = $country_code->getFormat();
         foreach (self::$COUNTRIES as $c) {
             if ($c[$country_format] == $upcase_name) {
                 $country = $c;
                 break;
             }
         }
     } else {
         foreach (self::$COUNTRIES as $c) {
             if ($c['name'] == $name) {
                 $country = $c;
                 break;
             }
         }
     }
     if (!isset($country)) {
         throw new \OutOfRangeException("No country could be found for name {$name}");
     }
     return new Country($country);
 }
Beispiel #3
0
 public static function getCountryNameById($countryId)
 {
     $inst = CountryCode::getInstance();
     return $inst->_getCountryNameById($countryId);
 }
Beispiel #4
0
 /**
  * @param self $other
  * @return bool
  */
 public function equals(self $other)
 {
     return $this->countryName === $other->name && $this->countryCode->equals($other->countryCode);
 }
Beispiel #5
0
 public function printRoutes()
 {
     foreach ($this->routePricingByCountryId as $key => $cr) {
         echo "Country name: " . CountryCode::getCountryNameById($cr->getCountryId()) . "\t" . $cr->getPrice() . "\n";
     }
 }
Beispiel #6
0
 /**
  * @dataProvider providerForInvalidCountryCode
  */
 public function testInvalidContryCodes($format, $input)
 {
     $rule = new CountryCode($format);
     $this->assertFalse($rule->validate($input));
 }