Example #1
0
 public function saveLocations($locations)
 {
     $user = User::thisUser();
     Location::deleteAll(['entity' => self::THIS_ENTITY, 'entity_id' => $this->id]);
     if (is_array($locations)) {
         $locations = array_slice($locations, 0, self::MAX_LOCATION_SCHOOL);
         foreach ($locations as $location) {
             $newLocation = new Location();
             $newLocation->user_id = $user->id;
             $newLocation->entity = self::THIS_ENTITY;
             $newLocation->entity_id = $this->id;
             $newLocation->title = $location['title'];
             $newLocation->description = $location['description'];
             $newLocation->lat = $location['lat'];
             $newLocation->lng = $location['lng'];
             $newLocation->zoom = $location['zoom'];
             $newLocation->type = $location['type'];
             $newLocation->save();
         }
     }
 }