add coverage attributes

This commit is contained in:
Arno Kaimbacher 2019-03-20 18:40:14 +01:00
parent 9d195c450e
commit 6bfbbea060
8 changed files with 163 additions and 11 deletions

View file

@ -16,7 +16,7 @@ class SitelinkController extends Controller
->where('server_state', 'LIKE', "%" . $serverState . "%");
$select
->select(DB::raw('YEAR(published_date) as published_date'))
->select(DB::raw('YEAR(server_date_published) as published_date'))
->distinct(true);
$this->years = $select->pluck('published_date');

View file

@ -14,7 +14,6 @@ use App\Rules\RdrFiletypes;
use App\Rules\RdrFilesize;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use App\Models\DatasetReference;
@ -22,6 +21,7 @@ use App\Models\Subject;
use App\Models\GeolocationBox;
use App\Models\Page;
use Illuminate\Support\Facades\Auth;
use App\Models\Coverage;
class IndexController extends Controller
{
@ -416,13 +416,21 @@ class IndexController extends Controller
$formGeolocation['xmax'] !== null && $formGeolocation['ymax'] !== null) {
$geolocation = new GeolocationBox($formGeolocation);
$dataset->geolocation()->save($geolocation);
//$geolocation->dataset()->associate($dataset)->save();
}
}
if (isset($data['coverage'])) {
$formCoverage = $request->input('coverage');
$coverage = new Coverage($formCoverage);
$dataset->coverage()->save($coverage);
//$coverage->dataset()->associate($dataset)->save();
}
// Create relation between Dataset and actual User.
$user = Auth::user();
$dataset->user()->associate($user)->save();
// $error = 'Always throw this error';
// throw new \Exception($error);

25
app/Models/Coverage.php Normal file
View file

@ -0,0 +1,25 @@
<?php
namespace App\Models;
use App\Models\Dataset;
use Illuminate\Database\Eloquent\Model;
class Coverage extends Model
{
protected $table = 'coverage';
public $timestamps = true;
protected $fillable = [
'elevation_min',
'elevation_max',
'elevation_absolut',
'depth_min',
'depth_max',
'depth_absolut'
];
public function dataset()
{
return $this->belongsTo(Dataset::class, 'dataset_id', 'id');
}
}

View file

@ -15,6 +15,7 @@ use App\Models\File;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
use App\Models\GeolocationBox;
use App\Models\Coverage;
class Dataset extends Model
{
@ -69,7 +70,13 @@ class Dataset extends Model
return $this->hasOne(GeolocationBox::class, 'dataset_id', 'id');
}
/**
* Get the coverage that owns the dataset.
*/
public function coverage()
{
return $this->hasOne(Coverage::class, 'dataset_id', 'id');
}
/**
* Get the project that the dataset belongs to.