/** * @param int $limit * @return int */ public static function update($limit = 100) { \SystemLogger::setVerbose(true); \SystemLogger::info("Running location Update"); $where = (new \DbTableWhere())->whereOrString('distance_m <= 0')->whereOrString('distance_m IS NULL')->setOrderBy('created_on')->setLimitAndOffset($limit); $theatreNearBys = TheatreNearby::manager()->getEntitiesWhere($where); \SystemLogger::info("Nearbys found for update = ", count($theatreNearBys)); $locationService = LocationService::instance(); $seenTheatres = []; $successful = 0; foreach ($theatreNearBys as $theatreNearBy) { //var_dump($theatreNearBy);exit; $theatre = $theatreNearBy->theatre; $success = false; \SystemLogger::info("Updating Nearby with ID ", $theatreNearBy->id, " PostalCode/ISO", $theatreNearBy->postal_code, "/", $theatreNearBy->country_iso, "Theatre:", $theatre->name, $theatre->address); /* @var $theatre Theatre */ if ($theatre) { if (!($theatre->latitude && $theatre->longitude) && !in_array($theatre->id, $seenTheatres)) { $seenTheatres[] = $theatre->id; if ($theatre->address) { self::setTheatreLatLng($theatre); } } if ($theatre->address || $theatre->latitude && $theatre->longitude) { $geocodeCached = self::getGeocodeCached($theatreNearBy); if ($geocodeCached) { $distance = $locationService->computeDistance($theatre->getGeocode(), $geocodeCached->getGeocode()); if ($distance >= 0) { $success = $theatreNearBy->update(['distance_m' => max([$distance, 100])], 'id'); \SystemLogger::info("Distance computed as: ", $distance); } else { \SystemLogger::info("Distance could not be computed"); } } } } if (!$success) { $theatreNearBy->update(['distance_m' => self::DISTANCE_FAILED], 'id'); } else { $successful++; } } return $successful; }
private function __construct() { //load providers $serviceProvidersDir = __DIR__ . DS . 'showtimeproviders'; $namespace = __NAMESPACE__ . '\\' . 'showtimeproviders'; $scanner = new \PackageScanner($serviceProvidersDir, $namespace, ShowtimeServiceProvider::getClass()); foreach ($scanner->getAllInstantiable() as $provider) { $this->serviceProviderList[] = $provider->newInstance(); } if (!count($this->serviceProviderList)) { throw new InvalidArgumentException("There are no service providers defined for showtimes."); } //ComparableObjectSorter::sort($this->serviceProviderList, false, true); shuffle($this->serviceProviderList); //initialize showtime manager $this->showtimeManager = Showtime::manager(); $this->theatreManager = Theatre::manager(); $this->theatreNearByManager = TheatreNearby::manager(); }
protected function initRelations() { $this->setOneToMany('nearbys', TheatreNearby::manager(), 'distance_m')->setOneToMany('showtimes', Showtime::manager(), 'show_date DESC, show_time ASC'); }