tethys/app/Http/Controllers/Publish/ReviewController.php
Arno Kaimbacher faa68cc223 8. Minimum 4 char bei den Atributen Titel und zusätzliche Titel (server und clientseitig)
8.1. Minimum 4 Charactaer bei den Atributen Description und zusätzliche Beschreibungen (server und clientseitig)
9. einheitliches Löschsymbol bei (zusätliche Titel, zusätzliche Beschreibungen, Keywords, Files und Datas References
16. Reject note vom Editor und Reviewer maximal 500 Zeichen (client- und serverseitig)
 - Datenbankänderungen auch vorgenommen
18. Edit Button am Ende nachdem ein Datesatz angelegt wurde
23. Vue Component "PersonTable" auf TypeScript umgeschrieben
2020-06-10 21:09:27 +02:00

171 lines
6.1 KiB
PHP

<?php
namespace App\Http\Controllers\Publish;
use App\Exceptions\GeneralException;
use App\Http\Controllers\Controller;
use App\Models\Dataset;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
class ReviewController extends Controller
{
public function __construct()
{
//$this->middleware('auth');
}
/**
* Display a listing of released and accepted datasets.
*
* @return \Illuminate\Http\Response
*/
public function index() : View
{
$user = Auth::user();
$userId = $user->id;
$builder = Dataset::query();
//"select * from [documents] where [server_state] in (?) or ([server_state] = ? and [editor_id] = ?)"
$datasets = $builder
->where('server_state', 'approved')
->where('reviewer_id', $userId)
->get();
return view('workflow.review.index', [
'datasets' => $datasets
]);
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\View\View
*/
public function review($id): View
{
$dataset = Dataset::with('user:id,login')->findOrFail($id);
$dataset->fetchValues();
$fieldnames = $dataset->describe();
$fields = [];
foreach ($fieldnames as $fieldName) {
$field = $dataset->getField($fieldName);
$modelClass = $field->getValueModelClass();
$fieldValues = $field->getValue($fieldName);
$value = "";
if (null === $modelClass) {
$value = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/', "\xEF\xBF\xBD ", $fieldValues);
} else {
// $fieldName = $field->getName();
if (!is_array($fieldValues)) {
$fieldValues = array($fieldValues);
}
foreach ($fieldValues as $fieldValue) {
// if a field has no value then is nothing more to do
// TODO maybe must be there an other solution
// FIXME remove code duplication (duplicates Opus_Model_Xml_Version*)
if (is_null($fieldValue)) {
continue;
}
if ($fieldValue instanceof \Illuminate\Database\Eloquent\Model) {
//$this->_mapModelAttributes($value, $dom, $childNode);
$attributes = array_keys($fieldValue->getAttributes());
foreach ($attributes as $property_name) {
$fieldName = self::convertColumnToFieldname($property_name);
// $field = new Field($fieldName);
$fieldval = $fieldValue->{$property_name};
$value = $value . $fieldName . ": " . $fieldval . "; ";
}
} elseif ($fieldValue instanceof \Carbon\Carbon) {
$value = $value . " Year " . $fieldValue->year;
$value = $value . " Month " . $fieldValue->month;
$value = $value . " Day " . $fieldValue->day;
$value = $value . " Hour " . $fieldValue->hour;
$value = $value . " Minute " . $fieldValue->minute;
$value = $value . " Second " . $fieldValue->second;
$value = $value . " UnixTimestamp " . $fieldValue->timestamp;
$value = $value . " Timezone " . $fieldValue->tzName;
} elseif (is_array($fieldValue)) {
$attributes = $fieldValue;
$value = "<ul>";
foreach ($attributes as $property_name => $subValue) {
$value = $value . "<li>" . $property_name . " : " . $subValue . "</li>";
}
$value = $value . "</ul>";
}
}
}
if ($value != "") {
$fields[$fieldName] = $value;
}
}
return view('workflow.review.review', [
'dataset' => $dataset,
'fields' => $fields
]);
}
public function reviewUpdate(Request $request, $id)
{
$dataset = Dataset::findOrFail($id);
$input = $request->all();
$input['server_state'] = 'reviewed';
if ($dataset->update($input)) {
// event(new PageUpdated($page));
return redirect()
->route('publish.workflow.review.index')
->with('flash_message', 'You have successfully reviewed one dataset!');
}
throw new GeneralException(trans('exceptions.publish.review.update_error'));
}
/**
* Reject dataset back to editor
*
* @param int $id
* @return \Illuminate\View\View
*/
public function reject($id): View
{
$dataset = Dataset::with('user:id,login')->findOrFail($id);
return view('workflow.review.reject', [
'dataset' => $dataset,
]);
}
public function rejectUpdate(Request $request, $id)
{
$this->validate(request(), [
'reject_reviewer_note' => 'required|min:10|max:500',
'server_state' => 'required'
]);
$dataset = Dataset::findOrFail($id);
$input = $request->all();
//$input['server_state'] = 'rejected_reviewer';
if ($dataset->update($input)) {
// event(new PageUpdated($page));
return redirect()
->route('publish.workflow.review.index')
->with('flash_message', 'You have successfully rejected one dataset! The editor will be informed.');
}
throw new GeneralException(trans('exceptions.publish.review.update_error'));
}
//snakeToCamel
private static function convertColumnToFieldname($columnname)
{
//return lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $columnname))));
return ucwords(str_replace(['-', '_'], ' ', $columnname));
}
}