mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 22:37:28 -08:00
Code comments and format
This commit is contained in:
parent
5f3a0bdea5
commit
d3c320e56f
|
@ -206,8 +206,6 @@ class AccessoriesController extends Controller
|
||||||
/**
|
/**
|
||||||
* Gets a paginated collection for the select2 menus
|
* Gets a paginated collection for the select2 menus
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0.16]
|
|
||||||
* @see \App\Http\Transformers\SelectlistTransformer
|
* @see \App\Http\Transformers\SelectlistTransformer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -192,8 +192,6 @@ class ConsumablesController extends Controller
|
||||||
/**
|
/**
|
||||||
* Gets a paginated collection for the select2 menus
|
* Gets a paginated collection for the select2 menus
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0.16]
|
|
||||||
* @see \App\Http\Transformers\SelectlistTransformer
|
* @see \App\Http\Transformers\SelectlistTransformer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -249,10 +249,7 @@ class LicensesController extends Controller
|
||||||
/**
|
/**
|
||||||
* Gets a paginated collection for the select2 menus
|
* Gets a paginated collection for the select2 menus
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0.16]
|
|
||||||
* @see \App\Http\Transformers\SelectlistTransformer
|
* @see \App\Http\Transformers\SelectlistTransformer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function selectlist(Request $request)
|
public function selectlist(Request $request)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,13 +8,14 @@ use App\Helpers\Helper;
|
||||||
use App\Models\PredefinedKit;
|
use App\Models\PredefinedKit;
|
||||||
use App\Http\Transformers\PredefinedKitsTransformer;
|
use App\Http\Transformers\PredefinedKitsTransformer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
||||||
|
*/
|
||||||
class PredefinedKitsController extends Controller
|
class PredefinedKitsController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
|
@ -44,8 +45,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
@ -65,8 +64,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
@ -81,10 +78,8 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param int $id
|
* @param int $id kit id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function update(Request $request, $id)
|
public function update(Request $request, $id)
|
||||||
|
@ -103,8 +98,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
@ -128,8 +121,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Gets a paginated collection for the select2 menus
|
* Gets a paginated collection for the select2 menus
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0.16]
|
|
||||||
* @see \App\Http\Transformers\SelectlistTransformer
|
* @see \App\Http\Transformers\SelectlistTransformer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -154,8 +145,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @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
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
@ -198,8 +185,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
|
@ -220,8 +205,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
@ -237,8 +220,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @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
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
@ -283,8 +262,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
|
@ -305,8 +282,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
@ -324,8 +299,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @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
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
@ -368,8 +339,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
|
@ -390,8 +359,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
@ -408,8 +375,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @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
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
@ -452,8 +415,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
|
@ -474,8 +435,6 @@ class PredefinedKitsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.0]
|
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -10,7 +10,6 @@ use Illuminate\Support\Facades\DB;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\ImageUploadRequest;
|
use App\Http\Requests\ImageUploadRequest;
|
||||||
use App\Models\Accessory;
|
use App\Models\Accessory;
|
||||||
use App\Models\SnipeItPivot;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\CheckInOutRequest;
|
use App\Http\Controllers\CheckInOutRequest;
|
||||||
use App\Services\PredefinedKitCheckoutService;
|
use App\Services\PredefinedKitCheckoutService;
|
||||||
|
@ -23,7 +22,7 @@ use App\Models\User;
|
||||||
* This controller handles all access kits management:
|
* This controller handles all access kits management:
|
||||||
* list, add/remove/change
|
* list, add/remove/change
|
||||||
*
|
*
|
||||||
* @version v2.0
|
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
||||||
*/
|
*/
|
||||||
class CheckoutKitController extends Controller
|
class CheckoutKitController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -31,20 +30,19 @@ class CheckoutKitController extends Controller
|
||||||
public $kitService;
|
public $kitService;
|
||||||
use CheckInOutRequest;
|
use CheckInOutRequest;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(PredefinedKitCheckoutService $kitService)
|
public function __construct(PredefinedKitCheckoutService $kitService)
|
||||||
{
|
{
|
||||||
$this->kitService = $kitService;
|
$this->kitService = $kitService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show Bulk Checkout Page
|
* Show Bulk Checkout Page
|
||||||
* @return View View to checkout multiple assets
|
*
|
||||||
*/
|
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
||||||
|
* @return View View to checkout
|
||||||
|
*/
|
||||||
public function showCheckout($kit_id)
|
public function showCheckout($kit_id)
|
||||||
{
|
{
|
||||||
// METODO: добавить больше проверок, тут ещё и модель и прочее что мне надо бу
|
|
||||||
$this->authorize('checkout', Asset::class);
|
$this->authorize('checkout', Asset::class);
|
||||||
|
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
|
@ -52,16 +50,15 @@ class CheckoutKitController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate and process the new Predefined Kit data.
|
* Validate and process the new Predefined Kit data.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @return Redirect
|
||||||
* @return Redirect
|
*/
|
||||||
*/
|
|
||||||
public function store(Request $request, $kit_id)
|
public function store(Request $request, $kit_id)
|
||||||
{
|
{
|
||||||
$user_id = e($request->get('user_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'));
|
return redirect()->back()->with('error', trans('admin/users/message.user_not_found'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +66,7 @@ class CheckoutKitController extends Controller
|
||||||
$kit->id = $kit_id;
|
$kit->id = $kit_id;
|
||||||
|
|
||||||
$errors = $this->kitService->checkout($request, $kit, $user);
|
$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('error', 'Checkout error')->with('error_messages', $errors); // TODO: trans
|
||||||
}
|
}
|
||||||
return redirect()->back()->with('success', 'Checkout was successfully'); // 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\Controllers\Controller;
|
||||||
use App\Http\Requests\ImageUploadRequest;
|
use App\Http\Requests\ImageUploadRequest;
|
||||||
use App\Models\Accessory;
|
use App\Models\Accessory;
|
||||||
use App\Models\SnipeItPivot;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,23 +17,26 @@ use Illuminate\Http\Request;
|
||||||
* This controller handles all access kits management:
|
* This controller handles all access kits management:
|
||||||
* list, add/remove/change
|
* list, add/remove/change
|
||||||
*
|
*
|
||||||
* @version v2.0
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
*/
|
*/
|
||||||
class PredefinedKitsController extends Controller
|
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()
|
public function index()
|
||||||
{
|
{
|
||||||
//$this->authorize('index', PredefinedKit::class);
|
$this->authorize('index', PredefinedKit::class);
|
||||||
return view('kits/index');
|
return view('kits/index');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a form view to create a new asset maintenance.
|
* Returns a form view to create a new kit.
|
||||||
*
|
*
|
||||||
* @see AssetMaintenancesController::postCreate() method that stores the data
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||||
* @version v1.0
|
|
||||||
* @since [v1.8]
|
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function create()
|
public function create()
|
||||||
|
@ -44,90 +46,68 @@ class PredefinedKitsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate and process the new Predefined Kit data.
|
* Validate and process the new Predefined Kit data.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @return Redirect
|
||||||
* @return Redirect
|
*/
|
||||||
*/
|
|
||||||
public function store(ImageUploadRequest $request)
|
public function store(ImageUploadRequest $request)
|
||||||
{
|
{
|
||||||
$this->authorize('create', PredefinedKit::class);
|
$this->authorize('create', PredefinedKit::class);
|
||||||
// Create a new Predefined Kit
|
// Create a new Predefined Kit
|
||||||
$kit = new PredefinedKit;
|
$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());
|
return redirect()->back()->withInput()->withErrors($kit->getErrors());
|
||||||
}
|
}
|
||||||
// METODO: удалить
|
$success = $kit->save();
|
||||||
$model_ids = $request->input('models');
|
if (!$success) {
|
||||||
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) {
|
|
||||||
return redirect()->back()->withInput()->withErrors($kit->getErrors());
|
return redirect()->back()->withInput()->withErrors($kit->getErrors());
|
||||||
}
|
}
|
||||||
return redirect()->route("kits.index")->with('success', 'Kit was successfully created.'); // TODO: trans()
|
return redirect()->route("kits.index")->with('success', 'Kit was successfully created.'); // TODO: trans()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view containing the Predefined Kit edit form.
|
* Returns a view containing the Predefined Kit edit form.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @since [v1.0]
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
* @return View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function edit($kit_id = null)
|
public function edit($kit_id = null)
|
||||||
{
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
if ($kit = PredefinedKit::find($kit_id)) {
|
if ($kit = PredefinedKit::find($kit_id)) {
|
||||||
return view('kits/edit')
|
return view('kits/edit')
|
||||||
->with('item', $kit)
|
->with('item', $kit)
|
||||||
->with('models', $kit->models)
|
->with('models', $kit->models)
|
||||||
->with('licenses', $kit->licenses);
|
->with('licenses', $kit->licenses);
|
||||||
}
|
}
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates and processes form data from the edit
|
* Validates and processes form data from the edit
|
||||||
* Predefined Kit form based on the kit ID passed.
|
* Predefined Kit form based on the kit ID passed.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @since [v1.0]
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
* @return Redirect
|
* @return Redirect
|
||||||
*/
|
*/
|
||||||
public function update(ImageUploadRequest $request, $kit_id = null)
|
public function update(ImageUploadRequest $request, $kit_id = null)
|
||||||
{
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
// Check if the kit exists
|
// Check if the kit exists
|
||||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||||
// Redirect to the kits management page
|
// 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()) {
|
if ($kit->save()) {
|
||||||
return redirect()->route("kits.index")->with('success', 'Kit was successfully updated'); // TODO: trans
|
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.
|
* Validate and delete the given Predefined Kit.
|
||||||
* Also delete all contained helping items
|
* Also delete all contained helping items
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @since [v1.0]
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
* @return Redirect
|
* @return Redirect
|
||||||
*/
|
*/
|
||||||
public function destroy($kit_id)
|
public function destroy($kit_id)
|
||||||
{
|
{
|
||||||
$this->authorize('delete', PredefinedKit::class);
|
$this->authorize('delete', PredefinedKit::class);
|
||||||
|
@ -165,47 +145,31 @@ class PredefinedKitsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the kit information to present to the kit view page
|
* Get the kit information to present to the kit view page
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @since [v1.0]
|
||||||
* @param int $modelId
|
* @param int $modelId
|
||||||
* @return View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function show($kit_id = null)
|
public function show($kit_id = null)
|
||||||
{
|
{
|
||||||
$this->authorize('view', PredefinedKit::class);
|
return $this->edit($kit_id);
|
||||||
$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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view containing the Predefined Kit edit form.
|
* Returns a view containing the Predefined Kit edit form.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @param int $kit_id
|
||||||
* @param int $kit_id
|
* @return View
|
||||||
* @return View
|
*/
|
||||||
*/
|
|
||||||
public function editModel($kit_id, $model_id)
|
public function editModel($kit_id, $model_id)
|
||||||
{
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
if ( ($kit = PredefinedKit::find($kit_id))
|
if (($kit = PredefinedKit::find($kit_id))
|
||||||
&& ($model = $kit->models()->find($model_id)) ) {
|
&& ($model = $kit->models()->find($model_id))) {
|
||||||
// $item = $model->pivot;
|
|
||||||
// $item->name1 = 'tesn1';
|
|
||||||
// dd($item);
|
|
||||||
//dd($model->pivot);
|
|
||||||
// $item = $model->pivot;
|
|
||||||
|
|
||||||
return view('kits/model-edit', [
|
return view('kits/model-edit', [
|
||||||
'kit' => $kit,
|
'kit' => $kit,
|
||||||
|
@ -217,19 +181,19 @@ class PredefinedKitsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the kit information to present to the kit view page
|
* Get the kit information to present to the kit view page
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @param int $modelId
|
||||||
* @param int $modelId
|
* @return View
|
||||||
* @return View
|
*/
|
||||||
*/
|
public function updateModel(Request $request, $kit_id, $model_id)
|
||||||
public function updateModel(Request $request, $kit_id, $model_id) {
|
{
|
||||||
|
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||||
// Redirect to the kits management page
|
// 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));
|
$validator = \Validator::make($request->all(), $kit->makeModelRules($model_id));
|
||||||
|
@ -248,18 +212,18 @@ class PredefinedKitsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the model from set
|
* Remove the model from set
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @param int $modelId
|
||||||
* @param int $modelId
|
* @return View
|
||||||
* @return View
|
*/
|
||||||
*/
|
public function detachModel($kit_id, $model_id)
|
||||||
public function detachModel($kit_id, $model_id) {
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||||
// Redirect to the kits management page
|
// 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
|
// Delete childs
|
||||||
|
@ -270,21 +234,20 @@ class PredefinedKitsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view containing attached license edit form.
|
* Returns a view containing attached license edit form.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @param int $kit_id
|
||||||
* @param int $kit_id
|
* @param int $license_id
|
||||||
* @param int $licenseId
|
* @return View
|
||||||
* @return View
|
*/
|
||||||
*/
|
|
||||||
public function editLicense($kit_id, $license_id)
|
public function editLicense($kit_id, $license_id)
|
||||||
{
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$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
|
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 redirect()->route('kits.index')->with('error', 'License does not exist'); // TODO: trans
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,20 +259,20 @@ class PredefinedKitsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update attached licese
|
* Update attached licese
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @param int $kit_id
|
||||||
* @param int $kit_id
|
* @param int $license_id
|
||||||
* @param int $licenseId
|
* @return View
|
||||||
* @return View
|
*/
|
||||||
*/
|
public function updateLicense(Request $request, $kit_id, $license_id)
|
||||||
public function updateLicense(Request $request, $kit_id, $license_id) {
|
{
|
||||||
|
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||||
// Redirect to the kits management page
|
// 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));
|
$validator = \Validator::make($request->all(), $kit->makeLicenseRules($license_id));
|
||||||
|
@ -328,18 +291,19 @@ class PredefinedKitsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Remove the license from set
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @param int $kit_id
|
||||||
* @param int $licenseId
|
* @param int $license_id
|
||||||
* @return View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function detachLicense($kit_id, $license_id) {
|
public function detachLicense($kit_id, $license_id)
|
||||||
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||||
// Redirect to the kits management page
|
// 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
|
// Delete childs
|
||||||
|
@ -351,21 +315,20 @@ class PredefinedKitsController extends Controller
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view containing attached accessory edit form.
|
* Returns a view containing attached accessory edit form.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @param int $kit_id
|
||||||
* @param int $kit_id
|
* @param int $accessoryId
|
||||||
* @param int $accessoryId
|
* @return View
|
||||||
* @return View
|
*/
|
||||||
*/
|
|
||||||
public function editAccessory($kit_id, $accessory_id)
|
public function editAccessory($kit_id, $accessory_id)
|
||||||
{
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$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
|
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 redirect()->route('kits.index')->with('error', 'Accessory does not exist'); // TODO: trans
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,20 +340,20 @@ class PredefinedKitsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update attached accessory
|
* Update attached accessory
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @param int $kit_id
|
||||||
* @param int $kit_id
|
* @param int $accessory_id
|
||||||
* @param int $accessoryId
|
* @return View
|
||||||
* @return View
|
*/
|
||||||
*/
|
public function updateAccessory(Request $request, $kit_id, $accessory_id)
|
||||||
public function updateAccessory(Request $request, $kit_id, $accessory_id) {
|
{
|
||||||
|
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||||
// Redirect to the kits management page
|
// 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));
|
$validator = \Validator::make($request->all(), $kit->makeAccessoryRules($accessory_id));
|
||||||
|
@ -409,18 +372,18 @@ class PredefinedKitsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Remove the accessory from set
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @param int $accessory_id
|
||||||
* @param int $accessoryId
|
* @return View
|
||||||
* @return View
|
*/
|
||||||
*/
|
public function detachAccessory($kit_id, $accessory_id)
|
||||||
public function detachAccessory($kit_id, $accessory_id) {
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||||
// Redirect to the kits management page
|
// 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
|
// Delete childs
|
||||||
|
@ -431,21 +394,20 @@ class PredefinedKitsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view containing attached consumable edit form.
|
* Returns a view containing attached consumable edit form.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @param int $kit_id
|
||||||
* @param int $kit_id
|
* @param int $consumable_id
|
||||||
* @param int $consumableId
|
* @return View
|
||||||
* @return View
|
*/
|
||||||
*/
|
|
||||||
public function editConsumable($kit_id, $consumable_id)
|
public function editConsumable($kit_id, $consumable_id)
|
||||||
{
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$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
|
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 redirect()->route('kits.index')->with('error', 'Consumable does not exist'); // TODO: trans
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,20 +419,20 @@ class PredefinedKitsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update attached consumable
|
* Update attached consumable
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @param int $kit_id
|
||||||
* @param int $kit_id
|
* @param int $consumableId
|
||||||
* @param int $consumableId
|
* @return View
|
||||||
* @return View
|
*/
|
||||||
*/
|
public function updateConsumable(Request $request, $kit_id, $consumable_id)
|
||||||
public function updateConsumable(Request $request, $kit_id, $consumable_id) {
|
{
|
||||||
|
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||||
// Redirect to the kits management page
|
// 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));
|
$validator = \Validator::make($request->all(), $kit->makeConsumableRules($consumable_id));
|
||||||
|
@ -489,18 +451,18 @@ class PredefinedKitsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Remove the consumable from set
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @since [v1.0]
|
* @param int $consumable_id
|
||||||
* @param int $consumableId
|
* @return View
|
||||||
* @return View
|
*/
|
||||||
*/
|
public function detachConsumable($kit_id, $consumable_id)
|
||||||
public function detachConsumable($kit_id, $consumable_id) {
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||||
// Redirect to the kits management page
|
// 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
|
// Delete childs
|
||||||
|
@ -509,44 +471,4 @@ class PredefinedKitsController extends Controller
|
||||||
// Redirect to the kit management page
|
// Redirect to the kit management page
|
||||||
return redirect()->route('kits.edit', $kit_id)->with('success', 'Consumable was successfully detached'); // TODO: trans
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,14 @@ namespace App\Http\Transformers;
|
||||||
use App\Models\PredefinedKit;
|
use App\Models\PredefinedKit;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Gate;
|
use Gate;
|
||||||
use App\Helpers\Helper;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use App\Models\SnipeModel;
|
use App\Models\SnipeModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* transforms collection of models to array with simple typres
|
||||||
|
*
|
||||||
|
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
class PredefinedKitsTransformer
|
class PredefinedKitsTransformer
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -39,6 +43,10 @@ class PredefinedKitsTransformer
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* transform collection of any elemets attached to kit
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function transformElements(Collection $elements, $total) {
|
public function transformElements(Collection $elements, $total) {
|
||||||
$array = array();
|
$array = array();
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
|
|
|
@ -11,11 +11,9 @@ use Watson\Validating\ValidatingTrait;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model for Categories. Categories are a higher-level group
|
* Model for predefined kits.
|
||||||
* than Asset Models, and handle things like whether or not
|
|
||||||
* to require acceptance from the user, whether or not to
|
|
||||||
* send a EULA to the user, etc.
|
|
||||||
*
|
*
|
||||||
|
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
||||||
* @version v1.0
|
* @version v1.0
|
||||||
*/
|
*/
|
||||||
class PredefinedKit extends SnipeModel
|
class PredefinedKit extends SnipeModel
|
||||||
|
@ -25,61 +23,79 @@ class PredefinedKit extends SnipeModel
|
||||||
protected $table = 'kits';
|
protected $table = 'kits';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Category validation rules
|
* Category validation rules
|
||||||
*/
|
*/
|
||||||
public $rules = array(
|
public $rules = array(
|
||||||
'name' => 'required|min:1|max:255|unique'
|
'name' => 'required|min:1|max:255|unique'
|
||||||
);
|
);
|
||||||
|
|
||||||
use ValidatingTrait;
|
use ValidatingTrait;
|
||||||
|
|
||||||
public $modelRules = [
|
public $modelRules = [
|
||||||
'model_id' => 'required|exists:models,id',
|
'model_id' => 'required|exists:models,id',
|
||||||
// 'model_id' => [
|
|
||||||
// 'required',
|
|
||||||
// 'exists:models,id',
|
|
||||||
// Rule::unique('kits_models')->where('model_id', $model_id)->whereNot('kit_id', $this->id)
|
|
||||||
// ],
|
|
||||||
'quantity' => 'required|integer|min:1',
|
'quantity' => 'required|integer|min:1',
|
||||||
'pivot_id' => 'integer|exists:kits_models,id'
|
'pivot_id' => 'integer|exists:kits_models,id'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function makeModelRules($model_id, $new = false) {
|
/**
|
||||||
// return [
|
* this rules use in edit an attached asset model form
|
||||||
// // 'model_id' => 'required|exists:models,id',
|
* see PredefinedKit::_makeRuleHelper function for details
|
||||||
// 'model_id' => [
|
* @param int $model_id
|
||||||
// 'required',
|
* @param bool $new = true if append a new element to kit
|
||||||
// 'exists:models,id',
|
*/
|
||||||
// Rule::unique('kits_models')->whereNot('model_id', $model_id)->where('kit_id', $this->id)
|
public function makeModelRules($model_id, $new = false)
|
||||||
// ],
|
{
|
||||||
// 'quantity' => 'required|integer|min:1',
|
return $this->_makeRuleHelper('models', 'kits_models', 'model_id', $model_id, $new);
|
||||||
// 'pivot_id' => 'integer|exists:kits_models,id'
|
}
|
||||||
// ];
|
|
||||||
|
/**
|
||||||
|
* this rules use in edit an attached license form
|
||||||
|
* see PredefinedKit::_makeRuleHelper function for details
|
||||||
|
* @param int $license_id
|
||||||
|
* @param bool $new = true if append a new element to kit
|
||||||
|
*/
|
||||||
|
public function makeLicenseRules($license_id, $new = false)
|
||||||
|
{
|
||||||
return $this->_makeRuleHelper('licenses', 'kits_licenses', 'license_id', $license_id, $new);
|
return $this->_makeRuleHelper('licenses', 'kits_licenses', 'license_id', $license_id, $new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function makeLicenseRules($license_id, $new = false) {
|
/**
|
||||||
return $this->_makeRuleHelper('licenses', 'kits_licenses', 'license_id', $license_id, $new);
|
* this rules use in edit an attached accessory form
|
||||||
|
* see PredefinedKit::_makeRuleHelper function for details
|
||||||
|
* @param int $accessoriy_id
|
||||||
|
* @param bool $new = true if append a new element to kit
|
||||||
|
*/
|
||||||
|
public function makeAccessoriesRules($accessory_id, $new = false)
|
||||||
|
{
|
||||||
|
return $this->_makeRuleHelper('accessories', 'kits_accessories', 'accessory_id', $accessory_id, $new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function makeAccessoriesRules($accessoriy_id, $new = false) {
|
/**
|
||||||
return $this->_makeRuleHelper('accessories', 'kits_accessories', 'accessoriy_id', $accessoriy_id, $new);
|
* this rules use in edit an attached consumable form
|
||||||
}
|
* see PredefinedKit::_makeRuleHelper function for details
|
||||||
|
* @param int $consumable_id
|
||||||
public function makeConsumablesRules($consumable_id, $new = false) {
|
* @param bool $new = true if append a new element to kit
|
||||||
|
*/
|
||||||
|
public function makeConsumablesRules($consumable_id, $new = false)
|
||||||
|
{
|
||||||
return $this->_makeRuleHelper('consumables', 'kits_consumables', 'consumable_id', $consumable_id, $new);
|
return $this->_makeRuleHelper('consumables', 'kits_consumables', 'consumable_id', $consumable_id, $new);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _makeRuleHelper($table, $pivot_table, $pivot_elem_key, $element_id, $new) {
|
/**
|
||||||
// return [
|
* Make rules for validation kit attached elements via Illuminate\Validation\Rule
|
||||||
// $pivot_elem_key => [
|
* checks:
|
||||||
// 'required',
|
* uniqueness of the record in table for this kit
|
||||||
// "exists:$table,id",
|
* existence of record in table
|
||||||
// Rule::unique($pivot_table)->whereNot($pivot_elem_key, $element_id)->where('kit_id', $this->id)
|
* and simple types check
|
||||||
// ],
|
* @param string $table element table name
|
||||||
// 'quantity' => 'required|integer|min:1',
|
* @param string $pivot_table kit+element table name
|
||||||
// 'pivot_id' => "integer|exists:$pivot_table,id"
|
* @param string $pivot_elem_key element key name inside pivot table
|
||||||
// ];
|
* @param int $element_id
|
||||||
|
* @param bool $new = true if append a new element to kit
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function _makeRuleHelper($table, $pivot_table, $pivot_elem_key, $element_id, $new)
|
||||||
|
{
|
||||||
$rule = [
|
$rule = [
|
||||||
$pivot_elem_key => [
|
$pivot_elem_key => [
|
||||||
'required',
|
'required',
|
||||||
|
@ -88,20 +104,13 @@ class PredefinedKit extends SnipeModel
|
||||||
],
|
],
|
||||||
'quantity' => 'required|integer|min:1'
|
'quantity' => 'required|integer|min:1'
|
||||||
];
|
];
|
||||||
if(!$new) {
|
if (!$new) {
|
||||||
$rule['pivot_id'] = "integer|exists:$pivot_table,id";
|
$rule['pivot_id'] = "integer|exists:$pivot_table,id";
|
||||||
|
|
||||||
}
|
}
|
||||||
return $rule;
|
return $rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public $licenseRules = [
|
|
||||||
// 'license_id' => 'required|exists:licenses,id',
|
|
||||||
// 'quantity' => 'required|integer|min:1',
|
|
||||||
// 'pivot_id' => 'integer|exists:kits_licenses,id'
|
|
||||||
// ];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes that are mass assignable.
|
* The attributes that are mass assignable.
|
||||||
*
|
*
|
||||||
|
@ -114,14 +123,14 @@ class PredefinedKit extends SnipeModel
|
||||||
use Searchable;
|
use Searchable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes that should be included when searching the model.
|
* The attributes that should be included when searching the kit.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $searchableAttributes = ['name'];
|
protected $searchableAttributes = ['name'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The relations and their attributes that should be included when searching the model.
|
* The relations and their attributes that should be included when searching the kit.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
@ -130,9 +139,6 @@ class PredefinedKit extends SnipeModel
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Establishes the kits -> models relationship
|
* Establishes the kits -> models relationship
|
||||||
*
|
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v2.0]
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||||
*/
|
*/
|
||||||
public function models()
|
public function models()
|
||||||
|
@ -147,9 +153,6 @@ class PredefinedKit extends SnipeModel
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Establishes the kits -> licenses relationship
|
* Establishes the kits -> licenses relationship
|
||||||
*
|
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.3]
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||||
*/
|
*/
|
||||||
public function licenses()
|
public function licenses()
|
||||||
|
@ -159,9 +162,6 @@ class PredefinedKit extends SnipeModel
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Establishes the kits -> licenses relationship
|
* Establishes the kits -> licenses relationship
|
||||||
*
|
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v4.3]
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||||
*/
|
*/
|
||||||
public function consumables()
|
public function consumables()
|
||||||
|
@ -170,12 +170,9 @@ class PredefinedKit extends SnipeModel
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Establishes the kits -> licenses relationship
|
* Establishes the kits -> licenses relationship
|
||||||
*
|
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
*/
|
||||||
* @since [v4.3]
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
|
||||||
*/
|
|
||||||
public function accessories()
|
public function accessories()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany('\App\Models\Accessory', 'kits_accessories', 'kit_id', 'accessory_id')->withPivot('id', 'quantity');
|
return $this->belongsToMany('\App\Models\Accessory', 'kits_accessories', 'kit_id', 'accessory_id')->withPivot('id', 'quantity');
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
|
||||||
|
|
||||||
class SnipeItPivot extends Pivot
|
|
||||||
{
|
|
||||||
|
|
||||||
use ValidatingTrait;
|
|
||||||
public $rules = [];
|
|
||||||
}
|
|
|
@ -12,7 +12,7 @@ use Illuminate\Support\Facades\Gate;
|
||||||
class PredefinedKitPresenter extends Presenter
|
class PredefinedKitPresenter extends Presenter
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Json Column Layout for bootstrap table
|
* Json Column Layout for bootstrap table of kits
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function dataTableLayout()
|
public static function dataTableLayout()
|
||||||
|
@ -59,7 +59,7 @@ class PredefinedKitPresenter extends Presenter
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Json Column Layout for bootstrap table
|
* Json Column Layout for bootstrap table of kit models
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function dataTableModels()
|
public static function dataTableModels()
|
||||||
|
@ -111,7 +111,7 @@ class PredefinedKitPresenter extends Presenter
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Json Column Layout for bootstrap table
|
* Json Column Layout for bootstrap table of kit licenses
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function dataTableLicenses()
|
public static function dataTableLicenses()
|
||||||
|
@ -163,7 +163,7 @@ class PredefinedKitPresenter extends Presenter
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Json Column Layout for bootstrap table
|
* Json Column Layout for bootstrap table of kit accessories
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function dataTableAccessories()
|
public static function dataTableAccessories()
|
||||||
|
@ -195,7 +195,7 @@ class PredefinedKitPresenter extends Presenter
|
||||||
"searchable" => true,
|
"searchable" => true,
|
||||||
"sortable" => true,
|
"sortable" => true,
|
||||||
"title" => 'Name', // TODO: trans
|
"title" => 'Name', // TODO: trans
|
||||||
"formatter" => "accessoriesLinkFormatter" // MYTODO: check
|
"formatter" => "accessoriesLinkFormatter"
|
||||||
], [
|
], [
|
||||||
"field" => "quantity",
|
"field" => "quantity",
|
||||||
"searchable" => false,
|
"searchable" => false,
|
||||||
|
@ -207,7 +207,7 @@ class PredefinedKitPresenter extends Presenter
|
||||||
"sortable" => false,
|
"sortable" => false,
|
||||||
"switchable" => false,
|
"switchable" => false,
|
||||||
"title" => trans('table.actions'),
|
"title" => trans('table.actions'),
|
||||||
"formatter" => "kits_accessoriesActionsFormatter", // MYTODO: check
|
"formatter" => "kits_accessoriesActionsFormatter",
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ class PredefinedKitPresenter extends Presenter
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Json Column Layout for bootstrap table
|
* Json Column Layout for bootstrap table of kit consumables
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function dataTableConsumables()
|
public static function dataTableConsumables()
|
||||||
|
@ -248,7 +248,7 @@ class PredefinedKitPresenter extends Presenter
|
||||||
"searchable" => true,
|
"searchable" => true,
|
||||||
"sortable" => true,
|
"sortable" => true,
|
||||||
"title" => 'Name', // TODO: trans
|
"title" => 'Name', // TODO: trans
|
||||||
"formatter" => "consumablesLinkFormatter" // MYTODO: check
|
"formatter" => "consumablesLinkFormatter"
|
||||||
], [
|
], [
|
||||||
"field" => "quantity",
|
"field" => "quantity",
|
||||||
"searchable" => false,
|
"searchable" => false,
|
||||||
|
@ -260,7 +260,7 @@ class PredefinedKitPresenter extends Presenter
|
||||||
"sortable" => false,
|
"sortable" => false,
|
||||||
"switchable" => false,
|
"switchable" => false,
|
||||||
"title" => trans('table.actions'),
|
"title" => trans('table.actions'),
|
||||||
"formatter" => "kits_consumablesActionsFormatter", // MYTODO: check
|
"formatter" => "kits_consumablesActionsFormatter",
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -278,7 +278,6 @@ class PredefinedKitPresenter extends Presenter
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link to this kit Name
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function fullName()
|
public function fullName()
|
||||||
|
|
|
@ -12,12 +12,18 @@ use Illuminate\Support\Facades\DB;
|
||||||
use App\Events\CheckoutableCheckedOut;
|
use App\Events\CheckoutableCheckedOut;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class incapsulates checkout logic for reuse in different controllers
|
||||||
|
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
||||||
|
*/
|
||||||
class PredefinedKitCheckoutService
|
class PredefinedKitCheckoutService
|
||||||
{
|
{
|
||||||
use AuthorizesRequests;
|
use AuthorizesRequests;
|
||||||
/**
|
/**
|
||||||
* @return array [string_error1, string_error2...]
|
* @param Request $request, this function works with fields: checkout_at, expected_checkin, note
|
||||||
|
* @param PredefinedKit $kit kit for checkout
|
||||||
|
* @param User $user checkout target
|
||||||
|
* @return array Empty array if all ok, else [string_error1, string_error2...]
|
||||||
*/
|
*/
|
||||||
public function checkout(Request $request, PredefinedKit $kit, User $user) {
|
public function checkout(Request $request, PredefinedKit $kit, User $user) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -20,8 +20,6 @@ class AddKitsLicensesTable extends Migration {
|
||||||
$table->integer('quantity')->default(1);
|
$table->integer('quantity')->default(1);
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue