2019-02-12 11:21:35 +00:00
|
|
|
<?php
|
2019-04-03 16:06:10 +00:00
|
|
|
namespace App\Http\Controllers\Publish;
|
2019-02-12 11:21:35 +00:00
|
|
|
|
2019-04-08 16:31:40 +00:00
|
|
|
use App\Exceptions\GeneralException;
|
|
|
|
use App\Http\Controllers\Controller;
|
2020-01-07 17:49:53 +00:00
|
|
|
use App\Http\Requests\DocumentRequest;
|
2019-02-12 11:21:35 +00:00
|
|
|
use App\Models\Dataset;
|
2020-01-07 17:49:53 +00:00
|
|
|
use App\Models\DatasetReference;
|
|
|
|
use App\Models\Description;
|
|
|
|
use App\Models\File;
|
|
|
|
use App\Models\License;
|
|
|
|
// use Illuminate\View\View;
|
2020-01-16 17:28:28 +00:00
|
|
|
use App\Models\Person;
|
2020-01-07 17:49:53 +00:00
|
|
|
// for edit actions:
|
2020-01-16 17:28:28 +00:00
|
|
|
use App\Models\Project;
|
2020-01-07 17:49:53 +00:00
|
|
|
use App\Models\Subject;
|
|
|
|
use App\Models\Title;
|
2019-04-08 16:31:40 +00:00
|
|
|
use App\Models\User;
|
2020-02-25 12:09:49 +00:00
|
|
|
use App\Rules\RdrFilesize;
|
|
|
|
use App\Rules\RdrFiletypes;
|
2020-01-07 17:49:53 +00:00
|
|
|
use Exception;
|
2019-04-08 16:31:40 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Illuminate\Http\Request;
|
2019-02-21 13:07:00 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2019-08-27 09:15:23 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2020-01-07 17:49:53 +00:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2019-08-27 09:15:23 +00:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
2020-01-07 17:49:53 +00:00
|
|
|
use Illuminate\Support\Facades\View;
|
2020-05-04 11:50:23 +00:00
|
|
|
use Illuminate\Support\Facades\Config;
|
2019-02-12 11:21:35 +00:00
|
|
|
|
2019-04-11 16:52:10 +00:00
|
|
|
class SubmitController extends Controller
|
2019-02-12 11:21:35 +00:00
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
//$this->middleware('auth');
|
|
|
|
}
|
|
|
|
|
2019-12-20 10:44:40 +00:00
|
|
|
public function index(): \Illuminate\Contracts\View\View
|
2019-04-08 16:31:40 +00:00
|
|
|
{
|
|
|
|
$user = Auth::user();
|
|
|
|
$user_id = $user->id;
|
|
|
|
|
|
|
|
$builder = Dataset::query();
|
|
|
|
$myDatasets = $builder
|
2020-01-07 17:49:53 +00:00
|
|
|
//->orderBy('server_state')
|
|
|
|
->whereIn('server_state', ['inprogress',
|
2019-08-27 09:15:23 +00:00
|
|
|
'released', 'editor_accepted', 'approved', 'reviewed', 'rejected_editor', 'rejected_reviewer'])
|
2019-04-10 08:54:15 +00:00
|
|
|
->where('account_id', $user_id)
|
2019-04-08 16:31:40 +00:00
|
|
|
->with('user:id,login')
|
2019-05-21 16:28:18 +00:00
|
|
|
->orderBy('server_date_modified', 'desc')
|
2019-04-08 16:31:40 +00:00
|
|
|
->get();
|
2019-12-20 10:44:40 +00:00
|
|
|
return View::make('workflow.submitter.index', [
|
2019-04-08 16:31:40 +00:00
|
|
|
'datasets' => $myDatasets,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-01-07 17:49:53 +00:00
|
|
|
/**
|
2019-08-27 09:15:23 +00:00
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-12-20 10:44:40 +00:00
|
|
|
public function edit($id): \Illuminate\Contracts\View\View
|
2019-08-27 09:15:23 +00:00
|
|
|
{
|
2020-05-04 11:50:23 +00:00
|
|
|
// $dataset = Dataset::findOrFail($id);
|
|
|
|
$dataset = Dataset::where('id', $id)
|
|
|
|
->with('contributors')->first();
|
|
|
|
|
|
|
|
$dataset->load('licenses', 'authors', 'titles', 'abstracts', 'files', 'coverage', 'subjects', 'references');
|
2019-08-27 09:15:23 +00:00
|
|
|
|
2020-04-08 14:59:41 +00:00
|
|
|
$titleTypes = ['Main' => 'Main', 'Sub' => 'Sub', 'Alternative' => 'Alternative',
|
|
|
|
'Translated' => 'Translated', 'Other' => 'Other'];
|
|
|
|
$descriptionTypes = ['Abstract' => 'Abstract', 'Methods' => 'Methods',
|
|
|
|
'Series_information' => 'Series_information',
|
2020-02-25 12:09:49 +00:00
|
|
|
'Technical_info' => 'Technical_info', 'Translated' => 'Translated', 'Other' => 'Other'];
|
2020-01-08 14:14:33 +00:00
|
|
|
$languages = DB::table('languages')
|
|
|
|
->where('active', true)
|
|
|
|
->pluck('part1', 'part1');
|
2020-05-04 11:50:23 +00:00
|
|
|
|
|
|
|
$contributorTypes = Config::get('enums.contributor_types');
|
2020-10-22 14:36:43 +00:00
|
|
|
$nameTypes = Config::get('enums.name_types');
|
2020-02-25 12:09:49 +00:00
|
|
|
|
2020-01-28 16:59:52 +00:00
|
|
|
$messages = DB::table('messages')
|
2020-02-25 12:09:49 +00:00
|
|
|
->pluck('help_text', 'metadata_element');
|
2020-01-08 14:14:33 +00:00
|
|
|
|
2019-08-27 09:15:23 +00:00
|
|
|
$projects = Project::pluck('label', 'id');
|
|
|
|
|
|
|
|
$datum = date('Y-m-d');
|
|
|
|
$nowYear = substr($datum, 0, 4);
|
|
|
|
$years = array();
|
|
|
|
for ($jahr = 1990; $jahr <= $nowYear; $jahr++) {
|
|
|
|
$years[$jahr] = $jahr;
|
|
|
|
}
|
|
|
|
|
|
|
|
$languages = DB::table('languages')
|
|
|
|
->where('active', true)
|
|
|
|
->pluck('part1', 'part1');
|
2020-01-07 17:49:53 +00:00
|
|
|
|
2019-12-20 10:44:40 +00:00
|
|
|
// $options = License::all('id', 'name_long');
|
|
|
|
$licenses = License::select('id', 'name_long', 'link_licence')
|
|
|
|
->orderBy('sort_order')
|
|
|
|
->get();
|
|
|
|
// $checkeds = $dataset->licenses->pluck('id')->toArray();
|
|
|
|
$checkeds = $dataset->licenses->first()->id;
|
2020-01-07 17:49:53 +00:00
|
|
|
|
2019-08-27 09:15:23 +00:00
|
|
|
$keywordTypes = ['uncontrolled' => 'uncontrolled', 'swd' => 'swd'];
|
|
|
|
|
2021-06-07 08:05:22 +00:00
|
|
|
$referenceTypes = ["DOI", "Handle", "ISBN", "ISSN", "URL", "URN"];
|
2019-08-27 09:15:23 +00:00
|
|
|
$referenceTypes = array_combine($referenceTypes, $referenceTypes);
|
|
|
|
|
2020-04-08 14:59:41 +00:00
|
|
|
$relationTypes = ["IsSupplementTo", "IsSupplementedBy", "IsContinuedBy", "Continues",
|
|
|
|
"IsNewVersionOf", "IsPartOf", "HasPart", "Compiles", "IsVariantFormOf"];
|
2019-08-27 09:15:23 +00:00
|
|
|
$relationTypes = array_combine($relationTypes, $relationTypes);
|
|
|
|
|
2019-12-20 10:44:40 +00:00
|
|
|
return View::make(
|
2019-08-27 09:15:23 +00:00
|
|
|
'workflow.submitter.edit',
|
|
|
|
compact(
|
|
|
|
'dataset',
|
2020-01-08 14:14:33 +00:00
|
|
|
'titleTypes',
|
|
|
|
'descriptionTypes',
|
2020-05-04 11:50:23 +00:00
|
|
|
'contributorTypes',
|
2020-10-22 14:36:43 +00:00
|
|
|
'nameTypes',
|
2020-01-08 14:14:33 +00:00
|
|
|
'languages',
|
2020-01-28 16:59:52 +00:00
|
|
|
'messages',
|
2019-08-27 09:15:23 +00:00
|
|
|
'projects',
|
2019-12-20 10:44:40 +00:00
|
|
|
'licenses',
|
2019-08-27 09:15:23 +00:00
|
|
|
'checkeds',
|
|
|
|
'years',
|
|
|
|
'languages',
|
|
|
|
'keywordTypes',
|
|
|
|
'referenceTypes',
|
|
|
|
'relationTypes'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-07 17:49:53 +00:00
|
|
|
//https://stackoverflow.com/questions/17480200/using-laravel-how-do-i-create-a-view-that-will-update-a-one-to-many-relationshi?rq=1
|
2019-08-27 09:15:23 +00:00
|
|
|
// https://laravel.io/forum/06-11-2014-how-to-save-eloquent-model-with-relations-in-one-go
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function update(DocumentRequest $request, $id): RedirectResponse
|
|
|
|
{
|
|
|
|
$rules = [
|
2020-01-23 16:52:26 +00:00
|
|
|
'type' => 'required|min:3',
|
|
|
|
'titles.*.value' => 'required|min:4|max:255',
|
|
|
|
'titles.*.language' => 'required',
|
|
|
|
'descriptions.*.value' => 'required|min:4|max:2500',
|
|
|
|
'descriptions.*.language' => 'required',
|
|
|
|
'coverage.x_min' => [
|
|
|
|
'required',
|
2020-02-25 12:09:49 +00:00
|
|
|
'regex:/^[-]?((((1[0-7][0-9])|([0-9]?[0-9]))\.(\d+))|180(\.0+)?)$/',
|
2019-08-27 09:15:23 +00:00
|
|
|
],
|
2020-01-23 16:52:26 +00:00
|
|
|
'coverage.y_min' => [
|
|
|
|
'required',
|
2020-02-25 12:09:49 +00:00
|
|
|
'regex:/^[-]?(([0-8]?[0-9])\.(\d+))|(90(\.0+)?)$/',
|
2019-08-27 09:15:23 +00:00
|
|
|
],
|
2020-01-23 16:52:26 +00:00
|
|
|
'coverage.x_max' => [
|
|
|
|
'required',
|
2020-02-25 12:09:49 +00:00
|
|
|
'regex:/^[-]?((((1[0-7][0-9])|([0-9]?[0-9]))\.(\d+))|180(\.0+)?)$/',
|
2019-08-27 09:15:23 +00:00
|
|
|
],
|
2020-01-23 16:52:26 +00:00
|
|
|
'coverage.y_max' => [
|
|
|
|
'required',
|
2020-02-25 12:09:49 +00:00
|
|
|
'regex:/^[-]?(([0-8]?[0-9])\.(\d+))|(90(\.0+)?)$/',
|
2019-08-27 09:15:23 +00:00
|
|
|
],
|
2020-02-25 12:09:49 +00:00
|
|
|
'subjects' => 'required|array|min:3',
|
2020-01-23 16:52:26 +00:00
|
|
|
'subjects.*.value' => 'required|string',
|
|
|
|
'subjects.*.type' => 'required|string',
|
2020-02-25 12:09:49 +00:00
|
|
|
'files' => 'required|array|min:1',
|
2019-12-20 10:44:40 +00:00
|
|
|
'files.*.label' => 'required|string',
|
|
|
|
];
|
|
|
|
$customMessages = [
|
2020-01-23 16:52:26 +00:00
|
|
|
'subjects.min' => 'Minimal three keywords are required.',
|
|
|
|
'subjects.*.type.required' => 'The types of all keywords are required.',
|
|
|
|
'files.min' => 'Minimal one file is required.',
|
2019-08-27 09:15:23 +00:00
|
|
|
];
|
2020-01-16 17:28:28 +00:00
|
|
|
if (null != $request->file('files')) {
|
|
|
|
$data = $request->all();
|
|
|
|
$files = count($request->input('files')) - 1;
|
|
|
|
foreach (range(0, $files) as $index) {
|
|
|
|
// $rules['files.' . $index] = 'image|max:2048';
|
|
|
|
$rules['files.' . $index . '.file'] = [new RdrFilesize($index + 1), 'file', new RdrFiletypes()];
|
|
|
|
}
|
|
|
|
}
|
2019-12-20 10:44:40 +00:00
|
|
|
$validator = Validator::make($request->all(), $rules, $customMessages);
|
|
|
|
if (!$validator->fails()) {
|
2019-08-27 09:15:23 +00:00
|
|
|
$dataset = Dataset::findOrFail($id);
|
|
|
|
$data = $request->all();
|
2020-01-08 14:14:33 +00:00
|
|
|
$input = $request->except(
|
|
|
|
'abstracts',
|
|
|
|
'licenses',
|
2020-01-23 16:52:26 +00:00
|
|
|
'authors',
|
|
|
|
'contributors',
|
2020-01-08 14:14:33 +00:00
|
|
|
'titles',
|
|
|
|
'coverage',
|
|
|
|
'subjects',
|
|
|
|
'references',
|
|
|
|
'files'
|
|
|
|
);
|
2020-01-07 17:49:53 +00:00
|
|
|
|
2019-08-27 09:15:23 +00:00
|
|
|
$licenses = $request->input('licenses');
|
|
|
|
//$licenses = $input['licenses'];
|
|
|
|
$dataset->licenses()->sync($licenses);
|
|
|
|
|
2020-01-09 17:42:09 +00:00
|
|
|
$dataset->authors()->sync([]);
|
|
|
|
//store authors
|
|
|
|
if (isset($data['authors'])) {
|
|
|
|
// $data_to_sync = [];
|
|
|
|
$index = 0;
|
|
|
|
foreach ($request->get('authors') as $key => $person) {
|
|
|
|
$pivot_data = ['role' => 'author', 'sort_order' => $index + 1, 'allow_email_contact' => false];
|
|
|
|
// if ($galery_id == $request->get('mainPicture')) $pivot_data = ['main' => 1];
|
|
|
|
if (isset($person['id'])) {
|
|
|
|
// $data_to_sync[$person['id']] = $pivot_data;
|
|
|
|
$dataset->persons()->attach($person['id'], $pivot_data);
|
|
|
|
} else {
|
|
|
|
$dataPerson = new Person($person);
|
|
|
|
$dataPerson->status = true;
|
2020-10-22 14:36:43 +00:00
|
|
|
// $dataPerson->name_type = "Organizational";
|
2020-01-09 17:42:09 +00:00
|
|
|
$dataset->persons()->save($dataPerson, $pivot_data);
|
|
|
|
}
|
|
|
|
$index++;
|
|
|
|
}
|
|
|
|
// $dataset->persons()->sync($data_to_sync);
|
|
|
|
}
|
|
|
|
|
|
|
|
$dataset->contributors()->sync([]);
|
|
|
|
//store contributors
|
|
|
|
if (isset($data['contributors'])) {
|
|
|
|
// $data_to_sync = [];
|
|
|
|
$index = 0;
|
|
|
|
foreach ($request->get('contributors') as $key => $person) {
|
|
|
|
$pivot_data = ['role' => 'contributor', 'sort_order' => $index + 1, 'allow_email_contact' => false];
|
2020-05-05 20:13:10 +00:00
|
|
|
$pivot_data = array_merge($pivot_data, $person['pivot']);
|
2020-01-09 17:42:09 +00:00
|
|
|
// if ($galery_id == $request->get('mainPicture')) $pivot_data = ['main' => 1];
|
|
|
|
if (isset($person['id'])) {
|
|
|
|
// $data_to_sync[$person['id']] = $pivot_data;
|
|
|
|
$dataset->persons()->attach($person['id'], $pivot_data);
|
|
|
|
} else {
|
|
|
|
$dataPerson = new Person($person);
|
|
|
|
$dataPerson->status = true;
|
2020-10-22 14:36:43 +00:00
|
|
|
// $dataPerson->name_type = "Organizational";
|
2020-01-09 17:42:09 +00:00
|
|
|
$dataset->persons()->save($dataPerson, $pivot_data);
|
|
|
|
}
|
|
|
|
$index++;
|
|
|
|
}
|
|
|
|
// $dataset->persons()->sync($data_to_sync);
|
|
|
|
}
|
|
|
|
|
2019-08-27 09:15:23 +00:00
|
|
|
//save the titles:
|
|
|
|
$titles = $request->input('titles');
|
|
|
|
if (is_array($titles) && count($titles) > 0) {
|
|
|
|
foreach ($titles as $key => $formTitle) {
|
2020-01-16 17:28:28 +00:00
|
|
|
// if (isset($key) && $key != 'undefined') {
|
|
|
|
if (isset($formTitle['id'])) {
|
|
|
|
$title = Title::findOrFail($formTitle['id']);
|
2020-01-08 14:14:33 +00:00
|
|
|
$title->value = $formTitle['value'];
|
|
|
|
$title->language = $formTitle['language'];
|
|
|
|
$title->type = $formTitle['type'];
|
|
|
|
if ($title->isDirty()) {
|
|
|
|
$title->save();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$title = new Title($formTitle);
|
|
|
|
$dataset->titles()->save($title);
|
2019-12-20 10:44:40 +00:00
|
|
|
}
|
2019-08-27 09:15:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//save the abstracts:
|
|
|
|
$abstracts = $request->input('abstracts');
|
|
|
|
if (is_array($abstracts) && count($abstracts) > 0) {
|
|
|
|
foreach ($abstracts as $key => $formAbstract) {
|
2020-01-16 17:28:28 +00:00
|
|
|
// if (isset($key) && $key != 'undefined') {
|
|
|
|
if (isset($formAbstract['id'])) {
|
|
|
|
$abstract = Description::findOrFail($formAbstract['id']);
|
2020-01-08 14:14:33 +00:00
|
|
|
$abstract->value = $formAbstract['value'];
|
|
|
|
$abstract->language = $formAbstract['language'];
|
|
|
|
if ($abstract->isDirty()) {
|
|
|
|
$abstract->save();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$abstract = new Description($formAbstract);
|
|
|
|
$dataset->abstracts()->save($abstract);
|
2019-12-20 10:44:40 +00:00
|
|
|
}
|
2019-08-27 09:15:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//save the references:
|
|
|
|
$references = $request->input('references');
|
|
|
|
if (is_array($references) && count($references) > 0) {
|
|
|
|
foreach ($references as $key => $formReference) {
|
2020-01-16 17:28:28 +00:00
|
|
|
// if (isset($key) && $key != 'undefined') {
|
|
|
|
if (isset($formReference['id'])) {
|
|
|
|
$reference = DatasetReference::findOrFail($formReference['id']);
|
2020-01-07 17:49:53 +00:00
|
|
|
$reference->value = $formReference['value'];
|
|
|
|
$reference->label = $formReference['label'];
|
|
|
|
$reference->type = $formReference['type'];
|
|
|
|
$reference->relation = $formReference['relation'];
|
|
|
|
if ($reference->isDirty()) {
|
|
|
|
$reference->save();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$reference = new DatasetReference($formReference);
|
|
|
|
$dataset->references()->save($reference);
|
2019-12-20 10:44:40 +00:00
|
|
|
}
|
2019-08-27 09:15:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//save the keywords:
|
2019-12-20 10:44:40 +00:00
|
|
|
$keywords = $request->input('subjects');
|
2019-08-27 09:15:23 +00:00
|
|
|
if (is_array($keywords) && count($keywords) > 0) {
|
|
|
|
foreach ($keywords as $key => $formKeyword) {
|
2020-01-16 17:28:28 +00:00
|
|
|
if (isset($formKeyword['id'])) {
|
|
|
|
$subject = Subject::findOrFail($formKeyword['id']);
|
2020-01-07 17:49:53 +00:00
|
|
|
$subject->value = $formKeyword['value'];
|
|
|
|
$subject->type = $formKeyword['type'];
|
|
|
|
if ($subject->isDirty()) {
|
|
|
|
$subject->save();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$subject = new Subject($formKeyword);
|
|
|
|
$dataset->subjects()->save($subject);
|
2019-12-20 10:44:40 +00:00
|
|
|
}
|
2019-08-27 09:15:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//save the files:
|
2020-01-16 17:28:28 +00:00
|
|
|
$files = $request->get('files');
|
2020-01-23 16:52:26 +00:00
|
|
|
// $files = $request->file('files');
|
2019-08-27 09:15:23 +00:00
|
|
|
if (is_array($files) && count($files) > 0) {
|
2020-01-16 17:28:28 +00:00
|
|
|
$index = 1;
|
2019-08-27 09:15:23 +00:00
|
|
|
foreach ($files as $key => $formFile) {
|
2020-01-16 17:28:28 +00:00
|
|
|
// if (isset($key) && $key != 'undefined') {
|
|
|
|
if (isset($formFile['id'])) {
|
|
|
|
$file = File::findOrFail($formFile['id']);
|
|
|
|
$file->label = $formFile['label'];
|
|
|
|
if ($file->isDirty()) {
|
|
|
|
$file->save();
|
|
|
|
}
|
|
|
|
} else {
|
2020-01-23 16:52:26 +00:00
|
|
|
$uploads = $request->file('uploads');
|
|
|
|
$fileIndex = $formFile['file'];
|
|
|
|
$file = $uploads[$fileIndex];
|
|
|
|
|
|
|
|
// $file = new \Illuminate\Http\UploadedFile($file);
|
2020-01-16 17:28:28 +00:00
|
|
|
$label = urldecode($formFile['label']);
|
2020-02-25 12:09:49 +00:00
|
|
|
$sort_order = $index; //$formFile['sort_order'];
|
2020-01-16 17:28:28 +00:00
|
|
|
$fileName = "file-" . time() . '.' . $file->getClientOriginalExtension();
|
|
|
|
$mimeType = $file->getMimeType();
|
|
|
|
$datasetFolder = 'files/' . $dataset->id;
|
|
|
|
$path = $file->storeAs($datasetFolder, $fileName);
|
|
|
|
$size = Storage::size($path);
|
|
|
|
//$path = Storage::putFile('files', $image, $fileName);
|
|
|
|
$fileDb = new File([
|
|
|
|
'path_name' => $path,
|
|
|
|
'file_size' => $size,
|
|
|
|
'mime_type' => $mimeType,
|
|
|
|
'label' => $label,
|
|
|
|
'sort_order' => $sort_order,
|
|
|
|
'visible_in_frontdoor' => 1,
|
2020-02-25 12:09:49 +00:00
|
|
|
'visible_in_oai' => 1,
|
2020-01-16 17:28:28 +00:00
|
|
|
]);
|
|
|
|
//$test = $file->path_name;
|
|
|
|
$dataset->files()->save($fileDb);
|
|
|
|
$fileDb->createHashValues();
|
2019-12-20 10:44:40 +00:00
|
|
|
}
|
2020-01-16 17:28:28 +00:00
|
|
|
$index++;
|
2019-08-27 09:15:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save coverage
|
2019-12-20 10:44:40 +00:00
|
|
|
if (isset($data['coverage']) && !$this->containsOnlyNull($data['coverage'])) {
|
2019-08-27 09:15:23 +00:00
|
|
|
$formCoverage = $request->input('coverage');
|
|
|
|
$coverage = $dataset->coverage()->updateOrCreate(
|
|
|
|
['dataset_id' => $dataset->id],
|
|
|
|
$formCoverage
|
|
|
|
);
|
2020-01-07 17:49:53 +00:00
|
|
|
} elseif (isset($data['coverage']) && $this->containsOnlyNull($data['coverage'])
|
|
|
|
&& !is_null($dataset->coverage)) {
|
2019-12-20 10:44:40 +00:00
|
|
|
$dataset->coverage()->delete();
|
2019-08-27 09:15:23 +00:00
|
|
|
}
|
|
|
|
|
2019-12-20 10:44:40 +00:00
|
|
|
$dataset->fill($input);
|
|
|
|
// $dataset->creating_corporation = "Peter";
|
|
|
|
|
|
|
|
if (!$dataset->isDirty()) {
|
2019-08-27 09:15:23 +00:00
|
|
|
$time = new \Illuminate\Support\Carbon();
|
|
|
|
$dataset->setUpdatedAt($time);
|
|
|
|
}
|
|
|
|
// $dataset->save();
|
|
|
|
if ($dataset->update($input)) {
|
|
|
|
//event(new DatasetUpdated($dataset));
|
|
|
|
session()->flash('flash_message', 'You have updated 1 dataset!');
|
|
|
|
return redirect()->route('publish.workflow.submit.index');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//TODO Handle validation error
|
|
|
|
//pass validator errors as errors object for ajax response
|
|
|
|
// return response()->json([
|
|
|
|
// 'success' => false,
|
|
|
|
// 'errors' => $validator->errors()->all(),
|
|
|
|
// ], 422);
|
2020-01-23 16:52:26 +00:00
|
|
|
// $errors = $validator->errors();
|
|
|
|
return back()->withErrors($validator);
|
2020-02-25 12:09:49 +00:00
|
|
|
// return redirect()->route('publish.workflow.submit.edit', ['id' => $id])->withInput()
|
|
|
|
// ->withErrors($validator);
|
2019-08-27 09:15:23 +00:00
|
|
|
}
|
|
|
|
throw new GeneralException(trans('exceptions.backend.dataset.update_error'));
|
|
|
|
}
|
|
|
|
|
2019-12-20 10:44:40 +00:00
|
|
|
private function containsOnlyNull($input)
|
|
|
|
{
|
|
|
|
return empty(array_filter($input, function ($a) {
|
|
|
|
return $a !== null;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2019-04-08 16:31:40 +00:00
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2019-12-20 10:44:40 +00:00
|
|
|
public function release($id): \Illuminate\Contracts\View\View
|
2019-04-08 16:31:40 +00:00
|
|
|
{
|
|
|
|
$dataset = Dataset::with('user:id,login')->findOrFail($id);
|
2020-01-07 17:49:53 +00:00
|
|
|
|
2019-04-11 16:52:10 +00:00
|
|
|
$editors = User::whereHas('roles', function ($q) {
|
|
|
|
$q->where('name', 'editor');
|
|
|
|
})->pluck('login', 'id');
|
|
|
|
//$editors = Role::where('name', 'editor')->first()->users()->get();
|
2019-04-08 16:31:40 +00:00
|
|
|
|
2019-12-20 10:44:40 +00:00
|
|
|
return View::make('workflow.submitter.release', [
|
2019-04-08 16:31:40 +00:00
|
|
|
'dataset' => $dataset,
|
|
|
|
'editors' => $editors,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function releaseUpdate(Request $request, $id)
|
|
|
|
{
|
|
|
|
$dataset = Dataset::findOrFail($id);
|
2019-05-22 12:02:16 +00:00
|
|
|
if ($dataset->files->count() == 0) {
|
2020-01-07 17:49:53 +00:00
|
|
|
return back()
|
|
|
|
->withErrors(['datasets_count' => ['At least one dataset is required.']]);
|
2019-05-22 12:02:16 +00:00
|
|
|
}
|
2019-04-08 16:31:40 +00:00
|
|
|
|
|
|
|
$input = $request->all();
|
2019-05-22 12:02:16 +00:00
|
|
|
//immer released setzen
|
2019-04-08 16:31:40 +00:00
|
|
|
$input['server_state'] = 'released';
|
2019-05-22 12:02:16 +00:00
|
|
|
//editor wieder löschen falls rejected
|
|
|
|
if ($dataset->editor_id !== null) {
|
|
|
|
$input['editor_id'] = null;
|
|
|
|
}
|
2019-04-08 16:31:40 +00:00
|
|
|
|
2019-05-22 12:02:16 +00:00
|
|
|
if ($dataset->reject_editor_note != null) {
|
|
|
|
$input['reject_editor_note'] = null;
|
|
|
|
}
|
2020-01-23 16:52:26 +00:00
|
|
|
if ($dataset->reviewer_id !== null) {
|
|
|
|
$input['reviewer_id'] = null;
|
|
|
|
}
|
2019-05-28 17:02:21 +00:00
|
|
|
if ($dataset->reject_reviewer_note != null) {
|
|
|
|
$input['reject_reviewer_note'] = null;
|
|
|
|
}
|
2020-01-07 17:49:53 +00:00
|
|
|
|
2019-04-08 16:31:40 +00:00
|
|
|
if ($dataset->update($input)) {
|
|
|
|
// event(new PageUpdated($page));
|
|
|
|
return redirect()
|
2019-05-21 16:28:18 +00:00
|
|
|
->route('publish.workflow.submit.index')
|
2019-04-08 16:31:40 +00:00
|
|
|
->with('flash_message', 'You have released your dataset!');
|
|
|
|
}
|
|
|
|
throw new GeneralException(trans('exceptions.publish.release.update_error'));
|
|
|
|
}
|
|
|
|
|
2020-01-07 17:49:53 +00:00
|
|
|
/**
|
2019-08-27 09:15:23 +00:00
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2019-12-20 10:44:40 +00:00
|
|
|
public function delete($id): \Illuminate\Contracts\View\View
|
2019-08-27 09:15:23 +00:00
|
|
|
{
|
|
|
|
$dataset = Dataset::with('user:id,login')->findOrFail($id);
|
2020-01-07 17:49:53 +00:00
|
|
|
|
2019-12-20 10:44:40 +00:00
|
|
|
return View::make('workflow.submitter.delete', [
|
2020-01-07 17:49:53 +00:00
|
|
|
'dataset' => $dataset,
|
2019-08-27 09:15:23 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-04-08 16:31:40 +00:00
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-08-27 09:15:23 +00:00
|
|
|
public function deleteUpdate($id): RedirectResponse
|
2019-04-08 16:31:40 +00:00
|
|
|
{
|
|
|
|
$dataset = Dataset::with('files')->findOrFail($id);
|
2019-07-03 16:32:41 +00:00
|
|
|
if ($dataset->server_state == "inprogress" || $dataset->server_state == "rejected_editor") {
|
2019-04-08 16:31:40 +00:00
|
|
|
if ($dataset->files->count() > 0) {
|
|
|
|
foreach ($dataset->files as $file) {
|
|
|
|
if (isset($file->path_name)) {
|
|
|
|
Storage::delete($file->path_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$dataset->delete();
|
2019-04-09 17:05:03 +00:00
|
|
|
session()->flash('flash_message', 'You have deleted 1 dataset!');
|
2019-07-03 16:32:41 +00:00
|
|
|
return redirect()->route('publish.workflow.submit.index');
|
|
|
|
} else {
|
|
|
|
session()->flash(
|
|
|
|
'flash_message',
|
|
|
|
'You cannot delete this datastet!'
|
|
|
|
. ' There status of this dataset is '
|
|
|
|
. $dataset->server_state
|
|
|
|
. ' !'
|
|
|
|
);
|
|
|
|
return redirect()->route('publish.workflow.submit.index');
|
2019-04-08 16:31:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-12 11:21:35 +00:00
|
|
|
public function changestate($id, $targetState)
|
|
|
|
{
|
|
|
|
// $docId = $this->getRequest()->getParam('docId');
|
|
|
|
// $targetState = $this->getRequest()->getParam('targetState');
|
|
|
|
|
|
|
|
//$document = $this->_documentsHelper->getDocumentForId($docId);
|
|
|
|
$dataset = Dataset::findOrFail($id);
|
|
|
|
|
|
|
|
// Check if valid target state
|
|
|
|
// if (!$this->_workflowHelper->isValidState($targetState)) {
|
|
|
|
|
|
|
|
// }
|
|
|
|
try {
|
|
|
|
//$this->_workflowHelper->changeState($document, $targetState);
|
|
|
|
$dataset->setServerState($targetState);
|
|
|
|
|
2019-02-15 12:55:14 +00:00
|
|
|
if ($targetState == 'published') {
|
|
|
|
//$this->_sendNotification($document, $form);
|
|
|
|
$time = new \Illuminate\Support\Carbon();
|
2019-04-08 16:31:40 +00:00
|
|
|
$dataset->server_date_published = $time;
|
2019-02-21 13:07:00 +00:00
|
|
|
session()->flash('flash_message', 'You have puplished 1 dataset!');
|
2019-02-15 12:55:14 +00:00
|
|
|
}
|
2019-02-12 11:21:35 +00:00
|
|
|
$dataset->save();
|
2019-04-10 08:54:15 +00:00
|
|
|
//return redirect()->back();
|
2019-02-21 13:07:00 +00:00
|
|
|
//return redirect()->route('settings.review.index');
|
2019-02-12 11:21:35 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
//return $this->_redirectTo('index', array('failure' => $e->getMessage()), 'documents', 'admin');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|