public function update($identifier, array $input) { $attributions = @$input['attribution']; // Process input (e.g. set default values to empty properties) $input = $this->processInput($input); $definition = $this->getByIdentifier($identifier); $source = $this->getDefinitionSource($definition['source_id'], $definition['source_type']); $type = ucfirst(strtolower($source['type'])); if (empty($definition)) { \App::abort(404, "The resource with identifier '{$identifier}' could not be found."); } $source_repository = $this->getSourceRepository($type); $this->validateType($input); $source_repository->update($source['id'], $input); $definition_model = \Definition::find($definition['id']); $definition_model->update(array_only($input, array_keys($this->getCreateParameters()))); if (!empty($input['title'])) { $definition_model->title = $input['title']; } if (!empty($input['description'])) { $definition_model->description = $input['description']; } // Update the facets for the definition $this->updateFacets($definition_model); //$definition_object = $this->getEloquentDefinition($identifier); // Add the rest of the properties $create_parameters = $this->getCreateParameters(); unset($create_parameters['geometry']); unset($create_parameters['label']); $definition_model->update(array_only($input, array_keys($create_parameters))); // Delete the locations and create again if geo meta-data is provided (= update) if (!empty($definition_model->location->id)) { $location = $definition_model->location; $location->geometry->delete(); $location->label->delete(); $location->delete(); $definition_model->save(); } $location = $this->createLocation($input); // Check for location meta-data if (!empty($location)) { $definition_model->location()->save($location); } if (!empty($definition_model->attributions)) { foreach ($definition_model->attributions as $attribution) { $attribution->delete(); } } // Add attributions if there are any if (!empty($attributions)) { $attribution_models = []; foreach ($attributions as $attribution) { $attribution_models[] = $this->createAttribution($attribution); } $definition_model->attributions()->saveMany($attribution_models); } $definition_model->save(); return $definition_model->toArray(); }
public function update($identifier, array $input) { // Process input (e.g. set default values to empty properties) $input = $this->processInput($input); $definition = $this->getByIdentifier($identifier); $source = $this->getDefinitionSource($definition['source_id'], $definition['source_type']); $type = ucfirst(strtolower($source['type'])); if (empty($definition)) { \App::abort(404, "The resource with identifier '{$identifier}' could not be found."); } $source_repository = $this->getSourceRepository($type); $this->validateType($input); $source_repository->update($source['id'], $input); $definition_object = \Definition::find($definition['id']); $definition_object->update(array_only($input, array_keys($this->getCreateParameters()))); return $definition_object->toArray(); }
/** * Admin.dataset.delete */ public function getDelete($id) { // Set permission Auth::requirePermissions('admin.dataset.delete'); if (is_numeric($id)) { $definition = \Definition::find($id); if ($definition) { // Delete it (with cascade) $definition->delete(); } } return \Redirect::to('api/admin/datasets'); }