public function getQueryWhere() { $queryWhere = new \DbTableWhere(); $queryWhere->where('country_iso', $this->_data['country_iso']); if ($this->_data['postal_code']) { $queryWhere->where(new \DbTableFunction("REPLACE(postal_code, ' ', '')"), str_replace(' ', '', $this->_data['postal_code'])); } else { $queryWhere->where('city', $this->_data['city']); } return $queryWhere; }
/** * * @param int $movie_id * @param string $date * @param string|\DbTableFunction $order * @return Showtime[] */ public function getShowtimes($movie_id = null, $date = null, $order = null) { $showtimesWhere = new \DbTableWhere(); if ($movie_id) { $showtimesWhere->where('movie_id', $movie_id); } if ($date) { $showtimesWhere->where('show_date', $date); } if (!$order) { $order = new \DbTableFunction('type,show_date,show_time'); } $showtimesWhere->setOrderBy($order)->where('theatre_id', $this->_data['id']); return Showtime::manager()->getEntitiesWhere($showtimesWhere); }
/** * @param GeocodeCached $geocode * @param bool $forceUpdate * @return string timezone identifier */ public function getTimeZone(GeocodeCached $geocode, $forceUpdate = false) { if (!$forceUpdate && $geocode->timezone) { return $geocode->timezone; } $timezone = $this->checkSingleCountryTimezone($geocode); if (!$timezone) { $timezone = $this->lookupTimeZoneByGeoCode($geocode->getGeocode()); } //set time zone if ($timezone) { if ($geocode->city) { //update all cities wthin this country $where = \DbTableWhere::get()->where('country_iso', $geocode->country_iso)->where('city', $geocode->city); GeocodeCached::table()->update(['timezone' => $timezone], $where->getWhereString()); } else { $geocode->update(['timezone' => $timezone]); } } return $timezone; }
/** * * @param TheatreNearby $tnb * @return GeocodeCached * */ public static function getGeocodeCached(TheatreNearby $tnb) { $queryWhere = new \DbTableWhere(); $queryWhere->where('country_iso', $tnb->country_iso); if ($tnb->postal_code) { $queryWhere->where(new \DbTableFunction("REPLACE(postal_code, ' ', '')"), str_replace(' ', '', $tnb->postal_code)); } else { $queryWhere->where('city', $tnb->city); } $key = $queryWhere->getWhereString(); if (array_key_exists($key, self::$cachedGeocodes)) { return self::$cachedGeocodes[$key]; } else { return self::$cachedGeocodes[$key] = GeocodeCached::manager()->getEntityWhere($queryWhere); } }
/** * * @param string $postalCode * @param string $countryIso * @param string $city * @return \models\entities\GeocodeCached */ public function postalCodeLookup($postalCode, $countryIso, $city = null) { $lookupWhere = new \DbTableWhere(); $countryIso = LookupResult::remapIso($countryIso); $lookupWhere->where('country_iso', $countryIso); $postalCode = str_replace(' ', '', $postalCode); if ($postalCode) { $lookupWhere->where(new \DbTableFunction("REPLACE(postal_code, ' ', '')"), $postalCode); } elseif ($city) { $lookupWhere->where('city', $city); } //var_dump($lookupWhere);exit; $cached = $this->geocodeCachedManager->getEntityWhere($lookupWhere); if ($cached) { return $cached; } $country = LookupResult::$ISO_TABLE[$countryIso]; $address = preg_replace('/\\s+/', ' ', "{$postalCode} {$city}, {$country}"); return $this->addressLookup(trim($address), array('postal_code' => $postalCode, 'city' => $city, 'country_iso' => $countryIso)); }
public function getMovies(GeocodeCached $locationInfo, $currentDate = null, $theatre_id = null, $includeShowtimes = false, $includeTheatreIds = false, $dateOffset = 0, &$movieFields = []) { if (!$this->loadData($locationInfo, $currentDate, false, $dateOffset)) { return []; } $currentDate = Utilities::dateFromOffset($currentDate, $dateOffset); $where = $locationInfo->getQueryWhere()->where('s.show_date', $currentDate); if ($theatre_id) { $where->where('s.theatre_id', $theatre_id); } $idsQuery = Movie::table()->selectFrom('m.id', 'm')->innerJoin(['s' => Showtime::table()], 's.movie_id = m.id')->innerJoin(['tn' => TheatreNearby::table()], 's.theatre_id = tn.theatre_id', [new \DbTableFunction("GROUP_CONCAT(DISTINCT tn.theatre_id ORDER BY distance_m ASC) as theatres")])->where($where->setGroupBy("m.id"))->query(); $ids = []; $theatres = []; foreach ($idsQuery as $result) { $ids[] = $result['id']; $theatres[$result['id']] = explode(",", $result['theatres']); } $moviesWhere = \DbTableWhere::get()->whereInArray('id', $ids)->setOrderBy('title'); $movieList = Movie::manager()->getEntitiesWhere($moviesWhere); $movies = []; $movieFields = ['id', 'title', 'genre', 'user_rating', 'rated', 'critic_rating', 'runtime']; Movie::setToArrayFields($movieFields); foreach ($movieList as $movieInList) { /* @var $movieInList Movie */ $movie = $movieInList->toArray(); //$this->_filterObject($movie); //add showtimes ? if ($includeShowtimes) { $movie['showtimes'] = []; foreach ($movieInList->getShowtimes($theatre_id, $currentDate) as $showtime) { $movie['showtimes'][] = $showtime->toArray(0, 1, ['id', 'show_time', 'show_date', 'url', 'type']); } } if ($includeTheatreIds) { $movie['theatres'] = $theatres[$movieInList->id]; } $movies[] = ProxyMode::isCompact() ? $this->compactMovie($movie) : $movie; } if ($includeTheatreIds) { $movieFields[] = 'theatres'; } $this->_filterObject($movies); return $movies; }