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;
|
2019-02-12 11:21:35 +00:00
|
|
|
// use App\Http\Requests\ProjectRequest;
|
|
|
|
// use App\Models\Project;
|
|
|
|
// use Illuminate\Http\RedirectResponse;
|
|
|
|
// use Illuminate\Http\Request;
|
2019-04-08 16:31:40 +00:00
|
|
|
use App\Http\Controllers\Controller;
|
2019-02-12 11:21:35 +00:00
|
|
|
use App\Models\Dataset;
|
2019-04-08 16:31:40 +00:00
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Illuminate\Http\Request;
|
2019-02-21 13:07:00 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2019-04-08 16:31:40 +00:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
use Illuminate\View\View;
|
2019-02-12 11:21:35 +00:00
|
|
|
|
|
|
|
class WorkflowController extends Controller
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
//$this->middleware('auth');
|
|
|
|
}
|
|
|
|
|
2019-04-08 16:31:40 +00:00
|
|
|
public function index(): View
|
|
|
|
{
|
|
|
|
$user = Auth::user();
|
|
|
|
$user_id = $user->id;
|
|
|
|
|
|
|
|
$builder = Dataset::query();
|
|
|
|
$myDatasets = $builder
|
2019-04-10 08:54:15 +00:00
|
|
|
->whereIn('server_state', ['inprogress', 'released', 'editor_accepted'])
|
|
|
|
->where('account_id', $user_id)
|
2019-04-08 16:31:40 +00:00
|
|
|
->with('user:id,login')
|
|
|
|
->get();
|
|
|
|
return view('workflow.index', [
|
|
|
|
'datasets' => $myDatasets,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function release($id): View
|
|
|
|
{
|
|
|
|
$dataset = Dataset::with('user:id,login')->findOrFail($id);
|
|
|
|
// $editors = User::whereHas('roles', function ($q) {
|
|
|
|
// $q->where('login', 'admin');
|
|
|
|
// })->pluck('login', 'id');
|
|
|
|
$editors = User::with(['roles' => function ($query) {
|
2019-04-09 17:05:03 +00:00
|
|
|
$query->where('name', 'editor');
|
2019-04-08 16:31:40 +00:00
|
|
|
}])
|
|
|
|
->pluck('login', 'id');
|
|
|
|
//$editors = Role::where('name', 'reviewer')->first()->users;
|
|
|
|
|
|
|
|
return view('workflow.release', [
|
|
|
|
'dataset' => $dataset,
|
|
|
|
'editors' => $editors,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function releaseUpdate(Request $request, $id)
|
|
|
|
{
|
|
|
|
$dataset = Dataset::findOrFail($id);
|
|
|
|
|
|
|
|
$input = $request->all();
|
|
|
|
$input['server_state'] = 'released';
|
|
|
|
|
|
|
|
if ($dataset->update($input)) {
|
|
|
|
// event(new PageUpdated($page));
|
|
|
|
return redirect()
|
|
|
|
->route('publish.workflow.index')
|
|
|
|
->with('flash_message', 'You have released your dataset!');
|
|
|
|
}
|
|
|
|
throw new GeneralException(trans('exceptions.publish.release.update_error'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function delete($id): RedirectResponse
|
|
|
|
{
|
|
|
|
$dataset = Dataset::with('files')->findOrFail($id);
|
|
|
|
if ($dataset->server_state != "inprogress") {
|
|
|
|
session()->flash(
|
|
|
|
'flash_message',
|
|
|
|
'You cannot delete this datastet!'
|
|
|
|
. ' There status of this dataset is '
|
|
|
|
. $dataset->server_state
|
|
|
|
. ' !'
|
|
|
|
);
|
|
|
|
return redirect()->route('settings.project');
|
|
|
|
} else {
|
|
|
|
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-04-08 16:31:40 +00:00
|
|
|
return redirect()->route('publish.workflow.index');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-12 11:21:35 +00:00
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-04-09 17:05:03 +00:00
|
|
|
public function editorIndex()
|
2019-02-12 11:21:35 +00:00
|
|
|
{
|
|
|
|
$builder = Dataset::query();
|
|
|
|
$datasets = $builder
|
|
|
|
//->where('server_state', 'inprogress')
|
2019-04-10 08:54:15 +00:00
|
|
|
->whereIn('server_state', ['released', 'editor_accepted'])
|
2019-02-12 11:21:35 +00:00
|
|
|
->get();
|
2019-04-09 17:05:03 +00:00
|
|
|
return view('workflow.editor_index', compact('datasets'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function accept($id): View
|
|
|
|
{
|
|
|
|
$dataset = Dataset::with('user:id,login')->findOrFail($id);
|
|
|
|
// $editors = User::whereHas('roles', function ($q) {
|
|
|
|
// $q->where('login', 'admin');
|
|
|
|
// })->pluck('login', 'id');
|
|
|
|
$editors = User::with(['roles' => function ($query) {
|
|
|
|
$query->where('name', 'editor');
|
|
|
|
}])
|
|
|
|
->pluck('login', 'id');
|
|
|
|
//$editors = Role::where('name', 'reviewer')->first()->users;
|
|
|
|
|
|
|
|
return view('workflow.accept', [
|
|
|
|
'dataset' => $dataset,
|
|
|
|
'editors' => $editors,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function acceptUpdate(Request $request, $id)
|
|
|
|
{
|
|
|
|
$dataset = Dataset::findOrFail($id);
|
2019-04-10 08:54:15 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
$dataset->setServerState("editor_accepted");
|
|
|
|
$user = Auth::user();
|
|
|
|
$dataset->editor()->associate($user)->save();
|
|
|
|
$dataset->save();
|
|
|
|
return redirect()->back();
|
|
|
|
//return redirect()->route('settings.review.index');
|
|
|
|
} catch (Exception $e) {
|
|
|
|
throw new GeneralException(trans('exceptions.publish.accept.update_error'));
|
|
|
|
}
|
2019-02-21 13:07:00 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 16:31:40 +00:00
|
|
|
// public function release()
|
|
|
|
// {
|
|
|
|
// $user = Auth::user();
|
|
|
|
// $user_id = $user->id;
|
2019-02-21 13:07:00 +00:00
|
|
|
|
2019-04-08 16:31:40 +00:00
|
|
|
// $builder = Dataset::query();
|
|
|
|
// $datasets = $builder
|
|
|
|
// ->where('server_state', 'inprogress')
|
|
|
|
// ->where('account_id', $user_id)
|
|
|
|
// ->get();
|
|
|
|
// return view('workflow.release', compact('datasets'));
|
|
|
|
// }
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|