Compare commits

...

2 Commits

Author SHA1 Message Date
Arno Kaimbacher
7d1406ee5c - array/string Helpers: Laravel Convert old array and string helpers into their modern class-based methods.
-  Use Laravel Carbon: Laravel provides an Illuminate\Support\Carbon class which wraps the underlying Carbon class. By using this class, you gain access to some additional testing methods and create separation between your code and underlying dependencies.
2022-08-12 07:53:27 +00:00
Arno Kaimbacher
50ceeb193b - Form Request array syntax: Convert pipe (|) delimited validation rules from strings into an array of validation rules while using Laravel Rule objects where available
- Streamline order methods: Streamline query builder orderBy calls with asc and desc arguments.
- delete some old Request-Clases
2022-08-12 06:52:06 +00:00
32 changed files with 161 additions and 145 deletions

View File

@ -53,7 +53,7 @@ class SitelinkController extends Controller
->whereYear('server_date_published', '>=', $from)
->whereYear('server_date_published', '<', $until);
$documents = $select->orderBy('publish_id', 'asc')
$documents = $select->orderBy('publish_id')
->get();
//$this->years = Dataset::select(DB::raw('YEAR(server_date_modified) as server_date_modified'))

View File

@ -13,7 +13,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use \Exception;
// use Carbon\Carbon;
// use Illuminate\Support\Carbon;
use \Illuminate\Support\Carbon;
class RequestController extends Controller

View File

@ -64,7 +64,7 @@ class DoiController extends Controller
{
$datasets = Dataset::query()
->has('identifier')
->orderBy('server_date_modified', 'desc')
->orderByDesc('server_date_modified')
->get();
return View::make('workflow.doi.index', [
'datasets' => $datasets,

View File

@ -18,7 +18,7 @@ use App\Models\User;
use App\Rules\RdrFilesize;
use App\Rules\RdrFiletypes;
// use Illuminate\View\View;
use Carbon\Carbon;
use Illuminate\Support\Carbon;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
@ -87,7 +87,7 @@ class EditorController extends Controller
$query->whereIn('server_state', ['editor_accepted', 'rejected_reviewer', 'reviewed', 'published'])
->where('editor_id', $user_id)->doesntHave('identifier', 'and');
})
->orderBy('server_date_modified', 'desc')
->orderByDesc('server_date_modified')
->get();
// return View::make('workflow.editor.index', compact('datasets'));
return View::make('workflow.editor.index', [

View File

@ -82,7 +82,7 @@ class ReviewController extends Controller
$fieldval = $fieldValue->{$property_name};
$value = $value . $fieldName . ": " . $fieldval . "; ";
}
} elseif ($fieldValue instanceof \Carbon\Carbon) {
} elseif ($fieldValue instanceof \Illuminate\Support\Carbon) {
$value = $value . " Year " . $fieldValue->year;
$value = $value . " Month " . $fieldValue->month;
$value = $value . " Day " . $fieldValue->day;

View File

@ -47,7 +47,7 @@ class SubmitController extends Controller
'released', 'editor_accepted', 'approved', 'reviewed', 'rejected_editor', 'rejected_reviewer'])
->where('account_id', $user_id)
->with('user:id,login')
->orderBy('server_date_modified', 'desc')
->orderByDesc('server_date_modified')
->get();
return View::make('workflow.submitter.index', [
'datasets' => $myDatasets,

View File

@ -30,7 +30,7 @@ class UserController extends Controller
//}
$users = User::with('roles')
->orderBy('id', 'DESC')
->orderByDesc('id')
->paginate(5);
return view('settings.access.user.user', compact('users'))
->with('i', ($request->input('page', 1) - 1) * 5);

View File

@ -27,8 +27,13 @@ class CollectionRequest extends Request
public function rules()
{
return [
'name' => 'required|max:255',
'role_id' => 'required',
'name' => [
'required',
'max:255',
],
'role_id' => [
'required',
],
];
}
}

View File

@ -24,8 +24,13 @@ class DocumentRequest extends Request
public function rules()
{
return [
'type' => 'required|min:3',
'server_state' => 'required',
'type' => [
'required',
'min:3',
],
'server_state' => [
'required',
],
// 'author' => 'required|min:4',
// 'stock' => 'required|integer',
// 'year' => 'required|integer|min:4'

View File

@ -24,15 +24,40 @@ class LicenseRequest extends Request
public function rules()
{
return [
'desc_text' => 'max:4000',
'language' => 'max:3',
'link_licence' => 'required|url:max:255',
'link_logo' => 'url|max:255',
'mime_type' => 'max:30',
'name_long' => 'required|min:5|max:255',
'sort_order' => 'required|integer',
'active' => 'required|boolean',
'pod_allowed' => 'required|boolean'
'desc_text' => [
'max:4000',
],
'language' => [
'max:3',
],
'link_licence' => [
'required',
'url:max:255',
],
'link_logo' => [
'url',
'max:255',
],
'mime_type' => [
'max:30',
],
'name_long' => [
'required',
'min:5',
'max:255',
],
'sort_order' => [
'required',
'integer',
],
'active' => [
'required',
'boolean',
],
'pod_allowed' => [
'required',
'boolean',
],
];
}
}

View File

@ -28,7 +28,10 @@ class UpdatePageRequest extends Request
public function rules()
{
return [
'en_title' => 'required|max:191'
'en_title' => [
'required',
'max:191',
],
// 'description_en' => 'required'
];
}

View File

@ -1,30 +0,0 @@
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
class PeminjamanRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

View File

@ -1,29 +0,0 @@
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
class PeriodeRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'days' => 'required|integer'
];
}
}

View File

@ -24,17 +24,45 @@ class CreatePersonRequest extends Request
public function rules()
{
return [
'academic_title' => 'nullable|min:2|max:255',
'last_name' => 'required|min:3|max:255|unique_with:persons,first_name,date_of_birth',
'first_name' => 'required|min:3|max:255',
'email' => 'required|email|max:50|unique:persons,email',
'academic_title' => [
'nullable',
'min:2',
'max:255',
],
'last_name' => [
'required',
'min:3',
'max:255',
'unique_with:persons,first_name,date_of_birth',
],
'first_name' => [
'required',
'min:3',
'max:255',
],
'email' => [
'required',
'email',
'max:50',
'unique:persons,email',
],
// 'email' => [
// 'required', 'email', 'max:100',
// Rule::unique('persons')->ignore($user->id),
// ],
'identifier_orcid' => 'nullable|min:19|max:50',
'status' => 'required|boolean',
'date_of_birth' => 'nullable|date'
'identifier_orcid' => [
'nullable',
'min:19',
'max:50',
],
'status' => [
'required',
'boolean',
],
'date_of_birth' => [
'nullable',
'date',
],
];
}
}

View File

@ -26,17 +26,45 @@ class EditPersonRequest extends Request
public function rules()
{
return [
'academic_title' => 'nullable|min:2|max:255',
'last_name' => 'required|min:3|max:255|unique_with:persons,first_name,date_of_birth',
'first_name' => 'required|min:3|max:255',
'email' => 'required|email|max:50|unique:persons,email',
'academic_title' => [
'nullable',
'min:2',
'max:255',
],
'last_name' => [
'required',
'min:3',
'max:255',
'unique_with:persons,first_name,date_of_birth',
],
'first_name' => [
'required',
'min:3',
'max:255',
],
'email' => [
'required',
'email',
'max:50',
'unique:persons,email',
],
// 'email' => [
// 'required', 'email', 'max:100',
// Rule::unique('persons')->ignore($user->id),
// ],
'identifier_orcid' => 'nullable|min:19|max:50',
'status' => 'required|boolean',
'date_of_birth' => 'nullable|date'
'identifier_orcid' => [
'nullable',
'min:19',
'max:50',
],
'status' => [
'required',
'boolean',
],
'date_of_birth' => [
'nullable',
'date',
],
];
}
}

View File

@ -24,9 +24,19 @@ class ProjectRequest extends Request
{
return [
'name' => 'required|min:3|max:255',
'label' => 'required|min:3|max:20',
'description' => 'required'
'name' => [
'required',
'min:3',
'max:255',
],
'label' => [
'required',
'min:3',
'max:20',
],
'description' => [
'required',
],
];
}
}

View File

@ -1,30 +0,0 @@
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
class ShelfRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'shelf' => 'required'
];
}
}

View File

@ -1,7 +1,7 @@
<?php
namespace App\Library\Util;
use Carbon\Carbon;
use Illuminate\Support\Carbon;
/**
* Describes local document as a match in context of a related search query.

View File

@ -234,7 +234,7 @@ trait DatasetExtension
if (true === empty($fieldval)) {
$fieldval = null;
} else {
$fieldval = new \Carbon\Carbon($fieldval);
$fieldval = new \Illuminate\Support\Carbon($fieldval);
}
}

View File

@ -157,7 +157,7 @@ class Strategy
if ($value instanceof \Illuminate\Database\Eloquent\Model) {
$this->_mapModelAttributes($value, $dom, $childNode);
} elseif ($value instanceof \Carbon\Carbon) {
} elseif ($value instanceof \Illuminate\Support\Carbon) {
$this->_mapDateAttributes($value, $dom, $childNode);
} elseif (is_array($value)) {
$this->_mapArrayAttributes($value, $dom, $childNode);
@ -181,7 +181,7 @@ class Strategy
return $dom->createElement($fieldName);
}
protected function _mapDateAttributes(\Carbon\Carbon $model, DOMDocument $dom, \DOMNode $rootNode)
protected function _mapDateAttributes(\Illuminate\Support\Carbon $model, DOMDocument $dom, \DOMNode $rootNode)
{
$rootNode->setAttribute("Year", $model->year);
$rootNode->setAttribute("Month", $model->month);

View File

@ -15,7 +15,7 @@ use App\Models\Title;
use App\Models\User;
use App\Models\XmlCache;
use App\Models\DatasetIdentifier;
use Carbon\Carbon;
use Illuminate\Support\Carbon;
// use App\Models\GeolocationBox;
use Illuminate\Database\Eloquent\Model;
@ -301,7 +301,7 @@ class Dataset extends Model
$result = Dataset::select('server_date_published')
->where('server_date_published', '<>', null)
->where('server_state', 'published')
->orderBy('server_date_published', 'asc')
->orderBy('server_date_published')
->first();
//->server_date_published;
return $result;

View File

@ -2,6 +2,7 @@
namespace App\Rules;
use Illuminate\Support\Arr;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\Config;
@ -102,7 +103,7 @@ class RdrFilesize implements Rule
private function getSize($attribute, $value)
{
if (is_numeric($value) && $hasNumeric) {
return array_get($this->data, $attribute);
return Arr::get($this->data, $attribute);
} elseif (is_array($value)) {
return count($value);
} elseif ($value instanceof File) {

View File

View File

@ -2,7 +2,7 @@
namespace Database\Seeders;
// use Carbon\Carbon;
// use Illuminate\Support\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

View File

@ -2,7 +2,7 @@
namespace Database\Seeders;
// use Carbon\Carbon;
// use Illuminate\Support\Carbon;
// use Database\DisableForeignKeys;
// use Database\TruncateTable;
use Illuminate\Database\Seeder;

View File

@ -2,7 +2,7 @@
namespace Database\Seeders;
use Carbon\Carbon;
use Illuminate\Support\Carbon;
// use Database\DisableForeignKeys;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

View File

@ -2,7 +2,7 @@
namespace Database\Seeders;
use Carbon\Carbon;
use Illuminate\Support\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

View File

@ -2,7 +2,7 @@
namespace Database\Seeders;
use Carbon\Carbon;
use Illuminate\Support\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

View File

@ -2,7 +2,7 @@
namespace Database\Seeders;
use Carbon\Carbon;
use Illuminate\Support\Carbon;
// use Database\DisableForeignKeys;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

View File

@ -93,7 +93,7 @@
{{-- <div class="form-group">
{!! Form::label('licenses[]', 'Licenses..') !!}
{!! Form::select('licenses[]', $options, array_pluck($document->licenses, 'id'), ['multiple' ]) !!}
{!! Form::select('licenses[]', $options, Arr::pluck($document->licenses, 'id'), ['multiple' ]) !!}
</div> --}}
<div class="pure-control-group checkboxlist">

View File

@ -48,7 +48,7 @@
<td>
{{-- @php
$dateDiff = $dataset['server_date_modified']->addDays(14);
$remainingDays = Carbon\Carbon::now()->diffInDays($dateDiff, false);
$remainingDays = Illuminate\Support\Carbon::now()->diffInDays($dateDiff, false);
@endphp --}}
{{ $dataset->remaining_time . ' days' }}

View File

@ -70,7 +70,7 @@ $appRoutes = function () {
->whereYear('server_date_published', '>=', $from)
->whereYear('server_date_published', '<', $until);
$documents = $select->orderBy('publish_id', 'asc')
$documents = $select->orderBy('publish_id')
->get();
return response()
->json($documents)
@ -118,7 +118,7 @@ $appRoutes = function () {
$query = $query->orderBy($sortCol, $sortDir);
}
} else {
$query = $query->orderBy('id', 'asc');
$query = $query->orderBy('id');
}
//handle filter