Code comments and format
This commit is contained in:
@@ -206,8 +206,6 @@ class AccessoriesController extends Controller
|
||||
/**
|
||||
* Gets a paginated collection for the select2 menus
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0.16]
|
||||
* @see \App\Http\Transformers\SelectlistTransformer
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -192,8 +192,6 @@ class ConsumablesController extends Controller
|
||||
/**
|
||||
* Gets a paginated collection for the select2 menus
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0.16]
|
||||
* @see \App\Http\Transformers\SelectlistTransformer
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -249,10 +249,7 @@ class LicensesController extends Controller
|
||||
/**
|
||||
* Gets a paginated collection for the select2 menus
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0.16]
|
||||
* @see \App\Http\Transformers\SelectlistTransformer
|
||||
*
|
||||
*/
|
||||
public function selectlist(Request $request)
|
||||
{
|
||||
|
||||
@@ -8,13 +8,14 @@ use App\Helpers\Helper;
|
||||
use App\Models\PredefinedKit;
|
||||
use App\Http\Transformers\PredefinedKitsTransformer;
|
||||
|
||||
/**
|
||||
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
||||
*/
|
||||
class PredefinedKitsController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
@@ -44,8 +45,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
@@ -65,8 +64,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
@@ -81,10 +78,8 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @param int $id kit id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
@@ -103,8 +98,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
@@ -128,8 +121,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Gets a paginated collection for the select2 menus
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0.16]
|
||||
* @see \App\Http\Transformers\SelectlistTransformer
|
||||
*
|
||||
*/
|
||||
@@ -154,8 +145,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
@@ -168,10 +157,8 @@ class PredefinedKitsController extends Controller
|
||||
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
* Store the specified resource.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
@@ -198,8 +185,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
@@ -220,8 +205,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param int $kit_id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
@@ -237,8 +220,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
@@ -250,10 +231,8 @@ class PredefinedKitsController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
* Store the specified resource.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
@@ -283,8 +262,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
@@ -305,8 +282,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param int $kit_id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
@@ -324,8 +299,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
@@ -338,10 +311,8 @@ class PredefinedKitsController extends Controller
|
||||
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
* Store the specified resource.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
@@ -368,8 +339,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
@@ -390,8 +359,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param int $kit_id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
@@ -408,8 +375,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
@@ -422,10 +387,8 @@ class PredefinedKitsController extends Controller
|
||||
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
* Store the specified resource.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
@@ -452,8 +415,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
@@ -474,8 +435,6 @@ class PredefinedKitsController extends Controller
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param int $kit_id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
|
||||
@@ -10,7 +10,6 @@ use Illuminate\Support\Facades\DB;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ImageUploadRequest;
|
||||
use App\Models\Accessory;
|
||||
use App\Models\SnipeItPivot;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\CheckInOutRequest;
|
||||
use App\Services\PredefinedKitCheckoutService;
|
||||
@@ -23,7 +22,7 @@ use App\Models\User;
|
||||
* This controller handles all access kits management:
|
||||
* list, add/remove/change
|
||||
*
|
||||
* @version v2.0
|
||||
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
||||
*/
|
||||
class CheckoutKitController extends Controller
|
||||
{
|
||||
@@ -31,37 +30,35 @@ class CheckoutKitController extends Controller
|
||||
public $kitService;
|
||||
use CheckInOutRequest;
|
||||
|
||||
|
||||
public function __construct(PredefinedKitCheckoutService $kitService)
|
||||
public function __construct(PredefinedKitCheckoutService $kitService)
|
||||
{
|
||||
$this->kitService = $kitService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show Bulk Checkout Page
|
||||
* @return View View to checkout multiple assets
|
||||
*/
|
||||
* Show Bulk Checkout Page
|
||||
*
|
||||
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @return View View to checkout
|
||||
*/
|
||||
public function showCheckout($kit_id)
|
||||
{
|
||||
// METODO: добавить больше проверок, тут ещё и модель и прочее что мне надо бу
|
||||
$this->authorize('checkout', Asset::class);
|
||||
|
||||
$kit = PredefinedKit::findOrFail($kit_id);
|
||||
return view('kits/checkout')->with('kit', $kit);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate and process the new Predefined Kit data.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @return Redirect
|
||||
*/
|
||||
* Validate and process the new Predefined Kit data.
|
||||
*
|
||||
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @return Redirect
|
||||
*/
|
||||
public function store(Request $request, $kit_id)
|
||||
{
|
||||
$user_id = e($request->get('user_id'));
|
||||
if ( is_null($user = User::find( $user_id )) ) {
|
||||
if (is_null($user = User::find($user_id))) {
|
||||
return redirect()->back()->with('error', trans('admin/users/message.user_not_found'));
|
||||
}
|
||||
|
||||
@@ -69,7 +66,7 @@ class CheckoutKitController extends Controller
|
||||
$kit->id = $kit_id;
|
||||
|
||||
$errors = $this->kitService->checkout($request, $kit, $user);
|
||||
if( count($errors) > 0 ) {
|
||||
if (count($errors) > 0) {
|
||||
return redirect()->back()->with('error', 'Checkout error')->with('error_messages', $errors); // TODO: trans
|
||||
}
|
||||
return redirect()->back()->with('success', 'Checkout was successfully'); // TODO: trans
|
||||
|
||||
@@ -10,7 +10,6 @@ use Illuminate\Support\Facades\DB;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ImageUploadRequest;
|
||||
use App\Models\Accessory;
|
||||
use App\Models\SnipeItPivot;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
@@ -18,23 +17,26 @@ use Illuminate\Http\Request;
|
||||
* This controller handles all access kits management:
|
||||
* list, add/remove/change
|
||||
*
|
||||
* @version v2.0
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
*/
|
||||
class PredefinedKitsController extends Controller
|
||||
{
|
||||
/**
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//$this->authorize('index', PredefinedKit::class);
|
||||
$this->authorize('index', PredefinedKit::class);
|
||||
return view('kits/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a form view to create a new asset maintenance.
|
||||
*
|
||||
* @see AssetMaintenancesController::postCreate() method that stores the data
|
||||
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
||||
* @version v1.0
|
||||
* @since [v1.8]
|
||||
* Returns a form view to create a new kit.
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
* @return mixed
|
||||
*/
|
||||
public function create()
|
||||
@@ -44,91 +46,69 @@ class PredefinedKitsController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate and process the new Predefined Kit data.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @return Redirect
|
||||
*/
|
||||
* Validate and process the new Predefined Kit data.
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @return Redirect
|
||||
*/
|
||||
public function store(ImageUploadRequest $request)
|
||||
{
|
||||
$this->authorize('create', PredefinedKit::class);
|
||||
// Create a new Predefined Kit
|
||||
$kit = new PredefinedKit;
|
||||
$kit->name = $request->input('name');
|
||||
$kit->name = $request->input('name');
|
||||
|
||||
if(!$kit->save()) {
|
||||
if (!$kit->save()) {
|
||||
return redirect()->back()->withInput()->withErrors($kit->getErrors());
|
||||
}
|
||||
// METODO: удалить
|
||||
$model_ids = $request->input('models');
|
||||
if (!is_array($model_ids)) {
|
||||
$model_ids = [];
|
||||
}
|
||||
$model_ids = array_filter($model_ids);
|
||||
|
||||
$license_ids = $request->get('selected_licenses');
|
||||
if (!is_array($license_ids)) {
|
||||
$license_ids = [];
|
||||
}
|
||||
$license_ids = array_filter($license_ids);
|
||||
|
||||
$success = DB::transaction(function() use($kit, $model_ids, $license_ids) {
|
||||
$ret = $kit->save();
|
||||
if($ret) {
|
||||
$kit->models()->attach($model_ids); // MYTODO: проверить, что работает перед сохранением
|
||||
$kit->licenses()->attach($license_ids);
|
||||
}
|
||||
return $ret;
|
||||
});
|
||||
|
||||
if(!$success) {
|
||||
$success = $kit->save();
|
||||
if (!$success) {
|
||||
return redirect()->back()->withInput()->withErrors($kit->getErrors());
|
||||
}
|
||||
return redirect()->route("kits.index")->with('success', 'Kit was successfully created.'); // TODO: trans()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a view containing the Predefined Kit edit form.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $kit_id
|
||||
* @return View
|
||||
*/
|
||||
* Returns a view containing the Predefined Kit edit form.
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @since [v1.0]
|
||||
* @param int $kit_id
|
||||
* @return View
|
||||
*/
|
||||
public function edit($kit_id = null)
|
||||
{
|
||||
$this->authorize('update', PredefinedKit::class);
|
||||
if ($kit = PredefinedKit::find($kit_id)) {
|
||||
return view('kits/edit')
|
||||
->with('item', $kit)
|
||||
->with('models', $kit->models)
|
||||
->with('licenses', $kit->licenses);
|
||||
->with('item', $kit)
|
||||
->with('models', $kit->models)
|
||||
->with('licenses', $kit->licenses);
|
||||
}
|
||||
return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validates and processes form data from the edit
|
||||
* Predefined Kit form based on the kit ID passed.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $kit_id
|
||||
* @return Redirect
|
||||
*/
|
||||
* Validates and processes form data from the edit
|
||||
* Predefined Kit form based on the kit ID passed.
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @since [v1.0]
|
||||
* @param int $kit_id
|
||||
* @return Redirect
|
||||
*/
|
||||
public function update(ImageUploadRequest $request, $kit_id = null)
|
||||
{
|
||||
$this->authorize('update', PredefinedKit::class);
|
||||
// Check if the kit exists
|
||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||
// Redirect to the kits management page
|
||||
return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans
|
||||
return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans
|
||||
}
|
||||
|
||||
$kit->name = $request->input('name');
|
||||
|
||||
$kit->name = $request->input('name');
|
||||
|
||||
if ($kit->save()) {
|
||||
return redirect()->route("kits.index")->with('success', 'Kit was successfully updated'); // TODO: trans
|
||||
}
|
||||
@@ -136,14 +116,14 @@ class PredefinedKitsController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate and delete the given Predefined Kit.
|
||||
* Also delete all contained helping items
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $kit_id
|
||||
* @return Redirect
|
||||
*/
|
||||
* Validate and delete the given Predefined Kit.
|
||||
* Also delete all contained helping items
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @since [v1.0]
|
||||
* @param int $kit_id
|
||||
* @return Redirect
|
||||
*/
|
||||
public function destroy($kit_id)
|
||||
{
|
||||
$this->authorize('delete', PredefinedKit::class);
|
||||
@@ -165,48 +145,32 @@ class PredefinedKitsController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the kit information to present to the kit view page
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $modelId
|
||||
* @return View
|
||||
*/
|
||||
* Get the kit information to present to the kit view page
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @since [v1.0]
|
||||
* @param int $modelId
|
||||
* @return View
|
||||
*/
|
||||
public function show($kit_id = null)
|
||||
{
|
||||
$this->authorize('view', PredefinedKit::class);
|
||||
$kit = PredefinedKit::find($kit_id);
|
||||
|
||||
if (isset($kit->id)) {
|
||||
return view('kits/view', compact('kit'));
|
||||
}
|
||||
// Prepare the error message
|
||||
$error = 'Kit does not exist.'; // TODO: trans
|
||||
|
||||
// Redirect to the user management page
|
||||
return redirect()->route('kits.index')->with('error', $error);
|
||||
return $this->edit($kit_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a view containing the Predefined Kit edit form.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $kit_id
|
||||
* @return View
|
||||
*/
|
||||
* Returns a view containing the Predefined Kit edit form.
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $kit_id
|
||||
* @return View
|
||||
*/
|
||||
public function editModel($kit_id, $model_id)
|
||||
{
|
||||
{
|
||||
$this->authorize('update', PredefinedKit::class);
|
||||
if ( ($kit = PredefinedKit::find($kit_id))
|
||||
&& ($model = $kit->models()->find($model_id)) ) {
|
||||
// $item = $model->pivot;
|
||||
// $item->name1 = 'tesn1';
|
||||
// dd($item);
|
||||
//dd($model->pivot);
|
||||
// $item = $model->pivot;
|
||||
|
||||
if (($kit = PredefinedKit::find($kit_id))
|
||||
&& ($model = $kit->models()->find($model_id))) {
|
||||
|
||||
return view('kits/model-edit', [
|
||||
'kit' => $kit,
|
||||
'model' => $model,
|
||||
@@ -217,19 +181,19 @@ class PredefinedKitsController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the kit information to present to the kit view page
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $modelId
|
||||
* @return View
|
||||
*/
|
||||
public function updateModel(Request $request, $kit_id, $model_id) {
|
||||
* Get the kit information to present to the kit view page
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $modelId
|
||||
* @return View
|
||||
*/
|
||||
public function updateModel(Request $request, $kit_id, $model_id)
|
||||
{
|
||||
|
||||
$this->authorize('update', PredefinedKit::class);
|
||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||
// Redirect to the kits management page
|
||||
return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans
|
||||
return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans
|
||||
}
|
||||
|
||||
$validator = \Validator::make($request->all(), $kit->makeModelRules($model_id));
|
||||
@@ -243,23 +207,23 @@ class PredefinedKitsController extends Controller
|
||||
$pivot->model_id = $request->input('model_id');
|
||||
$pivot->quantity = $request->input('quantity');
|
||||
$pivot->save();
|
||||
|
||||
|
||||
return redirect()->route('kits.edit', $kit_id)->with('success', 'Model updated successfully.'); // TODO: trans
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the model from set
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $modelId
|
||||
* @return View
|
||||
*/
|
||||
public function detachModel($kit_id, $model_id) {
|
||||
* Remove the model from set
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $modelId
|
||||
* @return View
|
||||
*/
|
||||
public function detachModel($kit_id, $model_id)
|
||||
{
|
||||
$this->authorize('update', PredefinedKit::class);
|
||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||
// Redirect to the kits management page
|
||||
return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans
|
||||
return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans
|
||||
}
|
||||
|
||||
// Delete childs
|
||||
@@ -270,24 +234,23 @@ class PredefinedKitsController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a view containing attached license edit form.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $kit_id
|
||||
* @param int $licenseId
|
||||
* @return View
|
||||
*/
|
||||
* Returns a view containing attached license edit form.
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $kit_id
|
||||
* @param int $license_id
|
||||
* @return View
|
||||
*/
|
||||
public function editLicense($kit_id, $license_id)
|
||||
{
|
||||
{
|
||||
$this->authorize('update', PredefinedKit::class);
|
||||
if( !($kit = PredefinedKit::find($kit_id)) ) {
|
||||
if (!($kit = PredefinedKit::find($kit_id))) {
|
||||
return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans
|
||||
}
|
||||
if( !($license = $kit->licenses()->find($license_id)) ) {
|
||||
if (!($license = $kit->licenses()->find($license_id))) {
|
||||
return redirect()->route('kits.index')->with('error', 'License does not exist'); // TODO: trans
|
||||
}
|
||||
|
||||
|
||||
return view('kits/license-edit', [
|
||||
'kit' => $kit,
|
||||
'license' => $license,
|
||||
@@ -296,20 +259,20 @@ class PredefinedKitsController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Update attached licese
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $kit_id
|
||||
* @param int $licenseId
|
||||
* @return View
|
||||
*/
|
||||
public function updateLicense(Request $request, $kit_id, $license_id) {
|
||||
* Update attached licese
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $kit_id
|
||||
* @param int $license_id
|
||||
* @return View
|
||||
*/
|
||||
public function updateLicense(Request $request, $kit_id, $license_id)
|
||||
{
|
||||
|
||||
$this->authorize('update', PredefinedKit::class);
|
||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||
// Redirect to the kits management page
|
||||
return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans
|
||||
return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans
|
||||
}
|
||||
|
||||
$validator = \Validator::make($request->all(), $kit->makeLicenseRules($license_id));
|
||||
@@ -323,23 +286,24 @@ class PredefinedKitsController extends Controller
|
||||
$pivot->license_id = $request->input('license_id');
|
||||
$pivot->quantity = $request->input('quantity');
|
||||
$pivot->save();
|
||||
|
||||
|
||||
return redirect()->route('kits.edit', $kit_id)->with('success', 'License updated successfully.'); // TODO: trans
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $licenseId
|
||||
* @return View
|
||||
*/
|
||||
public function detachLicense($kit_id, $license_id) {
|
||||
* Remove the license from set
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $kit_id
|
||||
* @param int $license_id
|
||||
* @return View
|
||||
*/
|
||||
public function detachLicense($kit_id, $license_id)
|
||||
{
|
||||
$this->authorize('update', PredefinedKit::class);
|
||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||
// Redirect to the kits management page
|
||||
return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans
|
||||
return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans
|
||||
}
|
||||
|
||||
// Delete childs
|
||||
@@ -349,26 +313,25 @@ class PredefinedKitsController extends Controller
|
||||
return redirect()->route('kits.edit', $kit_id)->with('success', 'License was successfully detached'); // TODO: trans
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a view containing attached accessory edit form.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $kit_id
|
||||
* @param int $accessoryId
|
||||
* @return View
|
||||
*/
|
||||
* Returns a view containing attached accessory edit form.
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $kit_id
|
||||
* @param int $accessoryId
|
||||
* @return View
|
||||
*/
|
||||
public function editAccessory($kit_id, $accessory_id)
|
||||
{
|
||||
{
|
||||
$this->authorize('update', PredefinedKit::class);
|
||||
if( !($kit = PredefinedKit::find($kit_id)) ) {
|
||||
if (!($kit = PredefinedKit::find($kit_id))) {
|
||||
return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans
|
||||
}
|
||||
if( !($accessory = $kit->accessories()->find($accessory_id)) ) {
|
||||
if (!($accessory = $kit->accessories()->find($accessory_id))) {
|
||||
return redirect()->route('kits.index')->with('error', 'Accessory does not exist'); // TODO: trans
|
||||
}
|
||||
|
||||
|
||||
return view('kits/accessory-edit', [
|
||||
'kit' => $kit,
|
||||
'accessory' => $accessory,
|
||||
@@ -377,20 +340,20 @@ class PredefinedKitsController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Update attached accessory
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $kit_id
|
||||
* @param int $accessoryId
|
||||
* @return View
|
||||
*/
|
||||
public function updateAccessory(Request $request, $kit_id, $accessory_id) {
|
||||
* Update attached accessory
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $kit_id
|
||||
* @param int $accessory_id
|
||||
* @return View
|
||||
*/
|
||||
public function updateAccessory(Request $request, $kit_id, $accessory_id)
|
||||
{
|
||||
|
||||
$this->authorize('update', PredefinedKit::class);
|
||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||
// Redirect to the kits management page
|
||||
return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans
|
||||
return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans
|
||||
}
|
||||
|
||||
$validator = \Validator::make($request->all(), $kit->makeAccessoryRules($accessory_id));
|
||||
@@ -404,23 +367,23 @@ class PredefinedKitsController extends Controller
|
||||
$pivot->accessory_id = $request->input('accessory_id');
|
||||
$pivot->quantity = $request->input('quantity');
|
||||
$pivot->save();
|
||||
|
||||
|
||||
return redirect()->route('kits.edit', $kit_id)->with('success', 'Accessory updated successfully.'); // TODO: trans
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $accessoryId
|
||||
* @return View
|
||||
*/
|
||||
public function detachAccessory($kit_id, $accessory_id) {
|
||||
* Remove the accessory from set
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $accessory_id
|
||||
* @return View
|
||||
*/
|
||||
public function detachAccessory($kit_id, $accessory_id)
|
||||
{
|
||||
$this->authorize('update', PredefinedKit::class);
|
||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||
// Redirect to the kits management page
|
||||
return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans
|
||||
return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans
|
||||
}
|
||||
|
||||
// Delete childs
|
||||
@@ -431,24 +394,23 @@ class PredefinedKitsController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a view containing attached consumable edit form.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $kit_id
|
||||
* @param int $consumableId
|
||||
* @return View
|
||||
*/
|
||||
* Returns a view containing attached consumable edit form.
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $kit_id
|
||||
* @param int $consumable_id
|
||||
* @return View
|
||||
*/
|
||||
public function editConsumable($kit_id, $consumable_id)
|
||||
{
|
||||
{
|
||||
$this->authorize('update', PredefinedKit::class);
|
||||
if( !($kit = PredefinedKit::find($kit_id)) ) {
|
||||
if (!($kit = PredefinedKit::find($kit_id))) {
|
||||
return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans
|
||||
}
|
||||
if( !($consumable = $kit->consumables()->find($consumable_id)) ) {
|
||||
if (!($consumable = $kit->consumables()->find($consumable_id))) {
|
||||
return redirect()->route('kits.index')->with('error', 'Consumable does not exist'); // TODO: trans
|
||||
}
|
||||
|
||||
|
||||
return view('kits/consumable-edit', [
|
||||
'kit' => $kit,
|
||||
'consumable' => $consumable,
|
||||
@@ -457,20 +419,20 @@ class PredefinedKitsController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Update attached consumable
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $kit_id
|
||||
* @param int $consumableId
|
||||
* @return View
|
||||
*/
|
||||
public function updateConsumable(Request $request, $kit_id, $consumable_id) {
|
||||
* Update attached consumable
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $kit_id
|
||||
* @param int $consumableId
|
||||
* @return View
|
||||
*/
|
||||
public function updateConsumable(Request $request, $kit_id, $consumable_id)
|
||||
{
|
||||
|
||||
$this->authorize('update', PredefinedKit::class);
|
||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||
// Redirect to the kits management page
|
||||
return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans
|
||||
return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans
|
||||
}
|
||||
|
||||
$validator = \Validator::make($request->all(), $kit->makeConsumableRules($consumable_id));
|
||||
@@ -484,23 +446,23 @@ class PredefinedKitsController extends Controller
|
||||
$pivot->consumable_id = $request->input('consumable_id');
|
||||
$pivot->quantity = $request->input('quantity');
|
||||
$pivot->save();
|
||||
|
||||
|
||||
return redirect()->route('kits.edit', $kit_id)->with('success', 'Consumable updated successfully.'); // TODO: trans
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $consumableId
|
||||
* @return View
|
||||
*/
|
||||
public function detachConsumable($kit_id, $consumable_id) {
|
||||
* Remove the consumable from set
|
||||
*
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $consumable_id
|
||||
* @return View
|
||||
*/
|
||||
public function detachConsumable($kit_id, $consumable_id)
|
||||
{
|
||||
$this->authorize('update', PredefinedKit::class);
|
||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||
// Redirect to the kits management page
|
||||
return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans
|
||||
return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans
|
||||
}
|
||||
|
||||
// Delete childs
|
||||
@@ -509,44 +471,4 @@ class PredefinedKitsController extends Controller
|
||||
// Redirect to the kit management page
|
||||
return redirect()->route('kits.edit', $kit_id)->with('success', 'Consumable was successfully detached'); // TODO: trans
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a fieldset is set, 'add default values' is ticked and if
|
||||
* any default values were entered into the form.
|
||||
*
|
||||
* @param array $input
|
||||
* @return boolean
|
||||
*/
|
||||
private function shouldAddDefaultValues(array $input)
|
||||
{
|
||||
return !empty($input['add_default_values'])
|
||||
&& !empty($input['default_values'])
|
||||
&& !empty($input['custom_fieldset']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds default values to a accessory (as long as they are truthy)
|
||||
*
|
||||
* @param AssetModel $model
|
||||
* @param array $defaultValues
|
||||
* @return void
|
||||
*/
|
||||
private function assignCustomFieldsDefaultValues(AssetModel $model, array $defaultValues)
|
||||
{
|
||||
foreach ($defaultValues as $customFieldId => $defaultValue) {
|
||||
if ($defaultValue) {
|
||||
$model->defaultValues()->attach($customFieldId, ['default_value' => $defaultValue]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all default values
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function removeCustomFieldsDefaultValues(AssetModel $model)
|
||||
{
|
||||
$model->defaultValues()->detach();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user