foreach ($aa_winter_sports_points->features as $aa_winter_sports_point ){
// Convert stdClass object to associative array in php
// https://stackoverflow.com/questions/34428702/convert-stdclass-object-to-associative-array-in-php
$data = array($aa_winter_sports_point->properties);
$new_fill = json_decode(json_encode($data[0]), TRUE);
// find() will return an entity $existing_data. Works also in findAll();
$QgisResort = $this->QgisSkiResortModel->find($new_fill['id']);
//get list all permissable attributes that can go into the db
$attributes = $this->QgisSkiResortModel->allowedFields;
// filter new attributes in the new fill
$attributes_matching_from_new_fill = array_filter($new_fill, function ($value, $key) use ($attributes) {
if (in_array($key, $attributes)) {
return true;
}
}, ARRAY_FILTER_USE_BOTH);
// create a new record
if ($QgisResort === null){
$newSkiResort = new \App\Entities\QgisSkiResortEntity();
$newSkiResort->fill($attributes_matching_from_new_fill);
$this->QgisSkiResortModel->save($newSkiResort);
$resortNew++;
// record exists
} elseif($QgisResort){
$QgisResort->fill($attributes_matching_from_new_fill);
if ($QgisResort->hasChanged()){
if ($this->QgisSkiResortModel->save($attributes_matching_from_new_fill)){
$resortUpdated++;
}
}
if (!$QgisResort->hasChanged()){
$resortNothingToUpdate++;
echo $QgisResort->id.'</br>';
echo $QgisResort->{'name:en'}.'</br>';
echo '</br>';
}
}
$i++;
}