mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -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
|
||||
*
|
||||
* @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,20 +30,19 @@ class CheckoutKitController extends Controller
|
|||
public $kitService;
|
||||
use CheckInOutRequest;
|
||||
|
||||
|
||||
public function __construct(PredefinedKitCheckoutService $kitService)
|
||||
{
|
||||
$this->kitService = $kitService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
// METODO: добавить больше проверок, тут ещё и модель и прочее что мне надо бу
|
||||
$this->authorize('checkout', Asset::class);
|
||||
|
||||
$kit = PredefinedKit::findOrFail($kit_id);
|
||||
|
@ -54,8 +52,7 @@ class CheckoutKitController extends Controller
|
|||
/**
|
||||
* Validate and process the new Predefined Kit data.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @return Redirect
|
||||
*/
|
||||
public function store(Request $request, $kit_id)
|
||||
|
|
|
@ -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.
|
||||
* Returns a form view to create a new kit.
|
||||
*
|
||||
* @see AssetMaintenancesController::postCreate() method that stores the data
|
||||
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
||||
* @version v1.0
|
||||
* @since [v1.8]
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
* @return mixed
|
||||
*/
|
||||
public function create()
|
||||
|
@ -46,8 +48,7 @@ class PredefinedKitsController extends Controller
|
|||
/**
|
||||
* Validate and process the new Predefined Kit data.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @return Redirect
|
||||
*/
|
||||
public function store(ImageUploadRequest $request)
|
||||
|
@ -60,28 +61,7 @@ class PredefinedKitsController extends Controller
|
|||
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;
|
||||
});
|
||||
|
||||
$success = $kit->save();
|
||||
if (!$success) {
|
||||
return redirect()->back()->withInput()->withErrors($kit->getErrors());
|
||||
}
|
||||
|
@ -91,7 +71,7 @@ class PredefinedKitsController extends Controller
|
|||
/**
|
||||
* 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
|
||||
* @return View
|
||||
|
@ -113,7 +93,7 @@ class PredefinedKitsController extends Controller
|
|||
* Validates and processes form data from the edit
|
||||
* 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]
|
||||
* @param int $kit_id
|
||||
* @return Redirect
|
||||
|
@ -139,7 +119,7 @@ class PredefinedKitsController extends Controller
|
|||
* Validate and delete the given Predefined Kit.
|
||||
* Also delete all contained helping items
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @since [v1.0]
|
||||
* @param int $kit_id
|
||||
* @return Redirect
|
||||
|
@ -167,32 +147,21 @@ class PredefinedKitsController extends Controller
|
|||
/**
|
||||
* 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
|
||||
* @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]
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $kit_id
|
||||
* @return View
|
||||
*/
|
||||
|
@ -201,11 +170,6 @@ class PredefinedKitsController extends Controller
|
|||
$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;
|
||||
|
||||
return view('kits/model-edit', [
|
||||
'kit' => $kit,
|
||||
|
@ -219,12 +183,12 @@ class PredefinedKitsController extends Controller
|
|||
/**
|
||||
* Get the kit information to present to the kit view page
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $modelId
|
||||
* @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);
|
||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||
|
@ -250,12 +214,12 @@ class PredefinedKitsController extends Controller
|
|||
/**
|
||||
* Remove the model from set
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $modelId
|
||||
* @return View
|
||||
*/
|
||||
public function detachModel($kit_id, $model_id) {
|
||||
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
|
||||
|
@ -272,10 +236,9 @@ class PredefinedKitsController extends Controller
|
|||
/**
|
||||
* Returns a view containing attached license edit form.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $kit_id
|
||||
* @param int $licenseId
|
||||
* @param int $license_id
|
||||
* @return View
|
||||
*/
|
||||
public function editLicense($kit_id, $license_id)
|
||||
|
@ -298,13 +261,13 @@ class PredefinedKitsController extends Controller
|
|||
/**
|
||||
* Update attached licese
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $kit_id
|
||||
* @param int $licenseId
|
||||
* @param int $license_id
|
||||
* @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);
|
||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||
|
@ -328,14 +291,15 @@ class PredefinedKitsController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Remove the license from set
|
||||
*
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $licenseId
|
||||
* @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) {
|
||||
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
|
||||
|
@ -353,8 +317,7 @@ class PredefinedKitsController extends Controller
|
|||
/**
|
||||
* Returns a view containing attached accessory edit form.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $kit_id
|
||||
* @param int $accessoryId
|
||||
* @return View
|
||||
|
@ -379,13 +342,13 @@ class PredefinedKitsController extends Controller
|
|||
/**
|
||||
* Update attached accessory
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $kit_id
|
||||
* @param int $accessoryId
|
||||
* @param int $accessory_id
|
||||
* @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);
|
||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||
|
@ -409,14 +372,14 @@ class PredefinedKitsController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Remove the accessory from set
|
||||
*
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $accessoryId
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $accessory_id
|
||||
* @return View
|
||||
*/
|
||||
public function detachAccessory($kit_id, $accessory_id) {
|
||||
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
|
||||
|
@ -433,10 +396,9 @@ class PredefinedKitsController extends Controller
|
|||
/**
|
||||
* Returns a view containing attached consumable edit form.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $kit_id
|
||||
* @param int $consumableId
|
||||
* @param int $consumable_id
|
||||
* @return View
|
||||
*/
|
||||
public function editConsumable($kit_id, $consumable_id)
|
||||
|
@ -459,13 +421,13 @@ class PredefinedKitsController extends Controller
|
|||
/**
|
||||
* Update attached consumable
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @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) {
|
||||
public function updateConsumable(Request $request, $kit_id, $consumable_id)
|
||||
{
|
||||
|
||||
$this->authorize('update', PredefinedKit::class);
|
||||
if (is_null($kit = PredefinedKit::find($kit_id))) {
|
||||
|
@ -489,14 +451,14 @@ class PredefinedKitsController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Remove the consumable from set
|
||||
*
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @param int $consumableId
|
||||
* @author [D. Minaev] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @param int $consumable_id
|
||||
* @return View
|
||||
*/
|
||||
public function detachConsumable($kit_id, $consumable_id) {
|
||||
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
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,14 @@ namespace App\Http\Transformers;
|
|||
use App\Models\PredefinedKit;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Gate;
|
||||
use App\Helpers\Helper;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
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
|
||||
{
|
||||
|
||||
|
@ -39,6 +43,10 @@ class PredefinedKitsTransformer
|
|||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* transform collection of any elemets attached to kit
|
||||
* @return array
|
||||
*/
|
||||
public function transformElements(Collection $elements, $total) {
|
||||
$array = array();
|
||||
foreach ($elements as $element) {
|
||||
|
|
|
@ -11,11 +11,9 @@ use Watson\Validating\ValidatingTrait;
|
|||
use Illuminate\Validation\Rule;
|
||||
|
||||
/**
|
||||
* Model for Categories. Categories are a higher-level group
|
||||
* 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.
|
||||
* Model for predefined kits.
|
||||
*
|
||||
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @version v1.0
|
||||
*/
|
||||
class PredefinedKit extends SnipeModel
|
||||
|
@ -35,51 +33,69 @@ class PredefinedKit extends SnipeModel
|
|||
|
||||
public $modelRules = [
|
||||
'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',
|
||||
'pivot_id' => 'integer|exists:kits_models,id'
|
||||
];
|
||||
|
||||
public function makeModelRules($model_id, $new = false) {
|
||||
// return [
|
||||
// // 'model_id' => 'required|exists:models,id',
|
||||
// 'model_id' => [
|
||||
// 'required',
|
||||
// 'exists:models,id',
|
||||
// Rule::unique('kits_models')->whereNot('model_id', $model_id)->where('kit_id', $this->id)
|
||||
// ],
|
||||
// 'quantity' => 'required|integer|min:1',
|
||||
// 'pivot_id' => 'integer|exists:kits_models,id'
|
||||
// ];
|
||||
/**
|
||||
* this rules use in edit an attached asset model form
|
||||
* see PredefinedKit::_makeRuleHelper function for details
|
||||
* @param int $model_id
|
||||
* @param bool $new = true if append a new element to kit
|
||||
*/
|
||||
public function makeModelRules($model_id, $new = false)
|
||||
{
|
||||
return $this->_makeRuleHelper('models', 'kits_models', 'model_id', $model_id, $new);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public function makeConsumablesRules($consumable_id, $new = false) {
|
||||
/**
|
||||
* this rules use in edit an attached consumable form
|
||||
* see PredefinedKit::_makeRuleHelper function for details
|
||||
* @param int $consumable_id
|
||||
* @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);
|
||||
}
|
||||
|
||||
protected function _makeRuleHelper($table, $pivot_table, $pivot_elem_key, $element_id, $new) {
|
||||
// return [
|
||||
// $pivot_elem_key => [
|
||||
// 'required',
|
||||
// "exists:$table,id",
|
||||
// Rule::unique($pivot_table)->whereNot($pivot_elem_key, $element_id)->where('kit_id', $this->id)
|
||||
// ],
|
||||
// 'quantity' => 'required|integer|min:1',
|
||||
// 'pivot_id' => "integer|exists:$pivot_table,id"
|
||||
// ];
|
||||
/**
|
||||
* Make rules for validation kit attached elements via Illuminate\Validation\Rule
|
||||
* checks:
|
||||
* uniqueness of the record in table for this kit
|
||||
* existence of record in table
|
||||
* and simple types check
|
||||
* @param string $table element table name
|
||||
* @param string $pivot_table kit+element table name
|
||||
* @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 = [
|
||||
$pivot_elem_key => [
|
||||
'required',
|
||||
|
@ -95,13 +111,6 @@ class PredefinedKit extends SnipeModel
|
|||
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.
|
||||
*
|
||||
|
@ -114,14 +123,14 @@ class PredefinedKit extends SnipeModel
|
|||
use Searchable;
|
||||
|
||||
/**
|
||||
* The attributes that should be included when searching the model.
|
||||
* The attributes that should be included when searching the kit.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
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
|
||||
*/
|
||||
|
@ -130,9 +139,6 @@ class PredefinedKit extends SnipeModel
|
|||
|
||||
/**
|
||||
* Establishes the kits -> models relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function models()
|
||||
|
@ -147,9 +153,6 @@ class PredefinedKit extends SnipeModel
|
|||
|
||||
/**
|
||||
* Establishes the kits -> licenses relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.3]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function licenses()
|
||||
|
@ -159,9 +162,6 @@ class PredefinedKit extends SnipeModel
|
|||
|
||||
/**
|
||||
* Establishes the kits -> licenses relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.3]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function consumables()
|
||||
|
@ -171,9 +171,6 @@ class PredefinedKit extends SnipeModel
|
|||
|
||||
/**
|
||||
* Establishes the kits -> licenses relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.3]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function accessories()
|
||||
|
|
|
@ -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
|
||||
{
|
||||
/**
|
||||
* Json Column Layout for bootstrap table
|
||||
* Json Column Layout for bootstrap table of kits
|
||||
* @return string
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public static function dataTableAccessories()
|
||||
|
@ -195,7 +195,7 @@ class PredefinedKitPresenter extends Presenter
|
|||
"searchable" => true,
|
||||
"sortable" => true,
|
||||
"title" => 'Name', // TODO: trans
|
||||
"formatter" => "accessoriesLinkFormatter" // MYTODO: check
|
||||
"formatter" => "accessoriesLinkFormatter"
|
||||
], [
|
||||
"field" => "quantity",
|
||||
"searchable" => false,
|
||||
|
@ -207,7 +207,7 @@ class PredefinedKitPresenter extends Presenter
|
|||
"sortable" => false,
|
||||
"switchable" => false,
|
||||
"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
|
||||
*/
|
||||
public static function dataTableConsumables()
|
||||
|
@ -248,7 +248,7 @@ class PredefinedKitPresenter extends Presenter
|
|||
"searchable" => true,
|
||||
"sortable" => true,
|
||||
"title" => 'Name', // TODO: trans
|
||||
"formatter" => "consumablesLinkFormatter" // MYTODO: check
|
||||
"formatter" => "consumablesLinkFormatter"
|
||||
], [
|
||||
"field" => "quantity",
|
||||
"searchable" => false,
|
||||
|
@ -260,7 +260,7 @@ class PredefinedKitPresenter extends Presenter
|
|||
"sortable" => false,
|
||||
"switchable" => false,
|
||||
"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
|
||||
*/
|
||||
public function fullName()
|
||||
|
|
|
@ -12,12 +12,18 @@ use Illuminate\Support\Facades\DB;
|
|||
use App\Events\CheckoutableCheckedOut;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Class incapsulates checkout logic for reuse in different controllers
|
||||
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
||||
*/
|
||||
class PredefinedKitCheckoutService
|
||||
{
|
||||
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) {
|
||||
try {
|
||||
|
|
|
@ -20,8 +20,6 @@ class AddKitsLicensesTable extends Migration {
|
|||
$table->integer('quantity')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue