コード例 #1
0
 public static function getOrCreate($theatreData, $locationInfo = null, $lookUpAddress = false, $computeDistance = false)
 {
     $manager = self::manager();
     $findWhere = (new \DbTableWhere())->where('name', $theatreData['name'])->where('address', $theatreData['address']);
     if ($foundTheatre = $manager->getEntityWhere($findWhere)) {
         TheatreNearby::getOrCreate($locationInfo, $foundTheatre, $computeDistance);
         return $foundTheatre;
     }
     if ($lookUpAddress && (!$theatreData['longitude'] || !$theatreData['latitude'])) {
         $geoCode = LocationService::instance()->addressLookup($theatreData['address']);
         if ($geoCode) {
             $theatreData['longitude'] = $geoCode->found_longitude;
             $theatreData['latitude'] = $geoCode->found_latitude;
         }
     }
     $theatreId = $manager->createEntity($theatreData)->save();
     if ($theatreId) {
         $theatre = $manager->getEntity($theatreId);
         TheatreNearby::getOrCreate($locationInfo, $theatre, $computeDistance);
         return $theatre;
     }
     return null;
 }