diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php index 6c8716e54e..27ebd42cdf 100644 --- a/app/Http/Controllers/Api/AccessoriesController.php +++ b/app/Http/Controllers/Api/AccessoriesController.php @@ -206,8 +206,6 @@ class AccessoriesController extends Controller /** * Gets a paginated collection for the select2 menus * - * @author [A. Gianotto] [] - * @since [v4.0.16] * @see \App\Http\Transformers\SelectlistTransformer * */ diff --git a/app/Http/Controllers/Api/ConsumablesController.php b/app/Http/Controllers/Api/ConsumablesController.php index a97f92771c..5221a03b97 100644 --- a/app/Http/Controllers/Api/ConsumablesController.php +++ b/app/Http/Controllers/Api/ConsumablesController.php @@ -192,8 +192,6 @@ class ConsumablesController extends Controller /** * Gets a paginated collection for the select2 menus * - * @author [A. Gianotto] [] - * @since [v4.0.16] * @see \App\Http\Transformers\SelectlistTransformer * */ diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.php index 9defee8cd6..49f0696d19 100644 --- a/app/Http/Controllers/Api/LicensesController.php +++ b/app/Http/Controllers/Api/LicensesController.php @@ -249,10 +249,7 @@ class LicensesController extends Controller /** * Gets a paginated collection for the select2 menus * - * @author [A. Gianotto] [] - * @since [v4.0.16] * @see \App\Http\Transformers\SelectlistTransformer - * */ public function selectlist(Request $request) { diff --git a/app/Http/Controllers/Api/PredefinedKitsController.php b/app/Http/Controllers/Api/PredefinedKitsController.php index 70d5c17a7c..f84c868453 100644 --- a/app/Http/Controllers/Api/PredefinedKitsController.php +++ b/app/Http/Controllers/Api/PredefinedKitsController.php @@ -8,13 +8,14 @@ use App\Helpers\Helper; use App\Models\PredefinedKit; use App\Http\Transformers\PredefinedKitsTransformer; +/** + * @author [D. Minaev.] [] + */ class PredefinedKitsController extends Controller { /** * Display a listing of the resource. * - * @author [A. Gianotto] [] - * @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] [] - * @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] [] - * @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] [] - * @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] [] - * @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] [] - * @since [v4.0.16] * @see \App\Http\Transformers\SelectlistTransformer * */ @@ -154,8 +145,6 @@ class PredefinedKitsController extends Controller /** * Display the specified resource. * - * @author [A. Gianotto] [] - * @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] [] - * @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] [] - * @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] [] - * @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] [] - * @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] [] - * @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] [] - * @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] [] - * @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] [] - * @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] [] - * @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] [] - * @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] [] - * @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] [] - * @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] [] - * @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] [] - * @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] [] - * @since [v4.0] * @param int $kit_id * @return \Illuminate\Http\Response */ diff --git a/app/Http/Controllers/Kits/CheckoutKitController.php b/app/Http/Controllers/Kits/CheckoutKitController.php index 36f0b6bda3..0007372a46 100644 --- a/app/Http/Controllers/Kits/CheckoutKitController.php +++ b/app/Http/Controllers/Kits/CheckoutKitController.php @@ -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.] [] */ class CheckoutKitController extends Controller { @@ -31,37 +30,35 @@ class CheckoutKitController extends Controller public $kitService; use CheckInOutRequest; - - public function __construct(PredefinedKitCheckoutService $kitService) + public function __construct(PredefinedKitCheckoutService $kitService) { $this->kitService = $kitService; } - /** - * Show Bulk Checkout Page - * @return View View to checkout multiple assets - */ + * Show Bulk Checkout Page + * + * @author [D. Minaev.] [] + * @return View View to checkout + */ public function showCheckout($kit_id) { - // METODO: добавить больше проверок, тут ещё и модель и прочее что мне надо бу $this->authorize('checkout', Asset::class); $kit = PredefinedKit::findOrFail($kit_id); return view('kits/checkout')->with('kit', $kit); } - + /** - * Validate and process the new Predefined Kit data. - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @return Redirect - */ + * Validate and process the new Predefined Kit data. + * + * @author [D. Minaev.] [] + * @return Redirect + */ public function store(Request $request, $kit_id) { $user_id = e($request->get('user_id')); - if ( is_null($user = User::find( $user_id )) ) { + if (is_null($user = User::find($user_id))) { return redirect()->back()->with('error', trans('admin/users/message.user_not_found')); } @@ -69,7 +66,7 @@ class CheckoutKitController extends Controller $kit->id = $kit_id; $errors = $this->kitService->checkout($request, $kit, $user); - if( count($errors) > 0 ) { + if (count($errors) > 0) { return redirect()->back()->with('error', 'Checkout error')->with('error_messages', $errors); // TODO: trans } return redirect()->back()->with('success', 'Checkout was successfully'); // TODO: trans diff --git a/app/Http/Controllers/Kits/PredefinedKitsController.php b/app/Http/Controllers/Kits/PredefinedKitsController.php index d71d99a602..533d6d2cb5 100644 --- a/app/Http/Controllers/Kits/PredefinedKitsController.php +++ b/app/Http/Controllers/Kits/PredefinedKitsController.php @@ -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] [] */ class PredefinedKitsController extends Controller { + /** + * @author [D. Minaev] [] + * @return \Illuminate\Contracts\View\View + * @throws \Illuminate\Auth\Access\AuthorizationException + */ public function index() { - //$this->authorize('index', PredefinedKit::class); + $this->authorize('index', PredefinedKit::class); return view('kits/index'); } /** - * Returns a form view to create a new asset maintenance. - * - * @see AssetMaintenancesController::postCreate() method that stores the data - * @author Vincent Sposato - * @version v1.0 - * @since [v1.8] + * Returns a form view to create a new kit. + * + * @author [D. Minaev] [] + * @throws \Illuminate\Auth\Access\AuthorizationException * @return mixed */ public function create() @@ -44,91 +46,69 @@ class PredefinedKitsController extends Controller } /** - * Validate and process the new Predefined Kit data. - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @return Redirect - */ + * Validate and process the new Predefined Kit data. + * + * @author [D. Minaev] [] + * @return Redirect + */ public function store(ImageUploadRequest $request) { $this->authorize('create', PredefinedKit::class); // Create a new Predefined Kit $kit = new PredefinedKit; - $kit->name = $request->input('name'); + $kit->name = $request->input('name'); - if(!$kit->save()) { + if (!$kit->save()) { return redirect()->back()->withInput()->withErrors($kit->getErrors()); } - // METODO: удалить - $model_ids = $request->input('models'); - if (!is_array($model_ids)) { - $model_ids = []; - } - $model_ids = array_filter($model_ids); - - $license_ids = $request->get('selected_licenses'); - if (!is_array($license_ids)) { - $license_ids = []; - } - $license_ids = array_filter($license_ids); - - $success = DB::transaction(function() use($kit, $model_ids, $license_ids) { - $ret = $kit->save(); - if($ret) { - $kit->models()->attach($model_ids); // MYTODO: проверить, что работает перед сохранением - $kit->licenses()->attach($license_ids); - } - return $ret; - }); - - if(!$success) { + $success = $kit->save(); + if (!$success) { return redirect()->back()->withInput()->withErrors($kit->getErrors()); } return redirect()->route("kits.index")->with('success', 'Kit was successfully created.'); // TODO: trans() } /** - * Returns a view containing the Predefined Kit edit form. - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $kit_id - * @return View - */ + * Returns a view containing the Predefined Kit edit form. + * + * @author [D. Minaev] [] + * @since [v1.0] + * @param int $kit_id + * @return View + */ public function edit($kit_id = null) { $this->authorize('update', PredefinedKit::class); if ($kit = PredefinedKit::find($kit_id)) { return view('kits/edit') - ->with('item', $kit) - ->with('models', $kit->models) - ->with('licenses', $kit->licenses); + ->with('item', $kit) + ->with('models', $kit->models) + ->with('licenses', $kit->licenses); } return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans } /** - * Validates and processes form data from the edit - * Predefined Kit form based on the kit ID passed. - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $kit_id - * @return Redirect - */ + * Validates and processes form data from the edit + * Predefined Kit form based on the kit ID passed. + * + * @author [D. Minaev] [] + * @since [v1.0] + * @param int $kit_id + * @return Redirect + */ public function update(ImageUploadRequest $request, $kit_id = null) { $this->authorize('update', PredefinedKit::class); // Check if the kit exists if (is_null($kit = PredefinedKit::find($kit_id))) { // Redirect to the kits management page - return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans + return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans } - $kit->name = $request->input('name'); - + $kit->name = $request->input('name'); + if ($kit->save()) { return redirect()->route("kits.index")->with('success', 'Kit was successfully updated'); // TODO: trans } @@ -136,14 +116,14 @@ class PredefinedKitsController extends Controller } /** - * Validate and delete the given Predefined Kit. - * Also delete all contained helping items - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $kit_id - * @return Redirect - */ + * Validate and delete the given Predefined Kit. + * Also delete all contained helping items + * + * @author [D. Minaev] [] + * @since [v1.0] + * @param int $kit_id + * @return Redirect + */ public function destroy($kit_id) { $this->authorize('delete', PredefinedKit::class); @@ -165,48 +145,32 @@ class PredefinedKitsController extends Controller } /** - * Get the kit information to present to the kit view page - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $modelId - * @return View - */ + * Get the kit information to present to the kit view page + * + * @author [D. Minaev] [] + * @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] [] - * @since [v1.0] - * @param int $kit_id - * @return View - */ + * Returns a view containing the Predefined Kit edit form. + * + * @author [D. Minaev] [] + * @param int $kit_id + * @return View + */ public function editModel($kit_id, $model_id) - { + { $this->authorize('update', PredefinedKit::class); - if ( ($kit = PredefinedKit::find($kit_id)) - && ($model = $kit->models()->find($model_id)) ) { - // $item = $model->pivot; - // $item->name1 = 'tesn1'; - // dd($item); - //dd($model->pivot); - // $item = $model->pivot; - + if (($kit = PredefinedKit::find($kit_id)) + && ($model = $kit->models()->find($model_id))) { + return view('kits/model-edit', [ 'kit' => $kit, 'model' => $model, @@ -217,19 +181,19 @@ class PredefinedKitsController extends Controller } /** - * Get the kit information to present to the kit view page - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $modelId - * @return View - */ - public function updateModel(Request $request, $kit_id, $model_id) { + * Get the kit information to present to the kit view page + * + * @author [D. Minaev] [] + * @param int $modelId + * @return View + */ + public function updateModel(Request $request, $kit_id, $model_id) + { $this->authorize('update', PredefinedKit::class); if (is_null($kit = PredefinedKit::find($kit_id))) { // Redirect to the kits management page - return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans + return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans } $validator = \Validator::make($request->all(), $kit->makeModelRules($model_id)); @@ -243,23 +207,23 @@ class PredefinedKitsController extends Controller $pivot->model_id = $request->input('model_id'); $pivot->quantity = $request->input('quantity'); $pivot->save(); - + return redirect()->route('kits.edit', $kit_id)->with('success', 'Model updated successfully.'); // TODO: trans } /** - * Remove the model from set - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $modelId - * @return View - */ - public function detachModel($kit_id, $model_id) { + * Remove the model from set + * + * @author [D. Minaev] [] + * @param int $modelId + * @return View + */ + public function detachModel($kit_id, $model_id) + { $this->authorize('update', PredefinedKit::class); if (is_null($kit = PredefinedKit::find($kit_id))) { // Redirect to the kits management page - return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans + return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans } // Delete childs @@ -270,24 +234,23 @@ class PredefinedKitsController extends Controller } /** - * Returns a view containing attached license edit form. - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $kit_id - * @param int $licenseId - * @return View - */ + * Returns a view containing attached license edit form. + * + * @author [D. Minaev] [] + * @param int $kit_id + * @param int $license_id + * @return View + */ public function editLicense($kit_id, $license_id) - { + { $this->authorize('update', PredefinedKit::class); - if( !($kit = PredefinedKit::find($kit_id)) ) { + if (!($kit = PredefinedKit::find($kit_id))) { return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans } - if( !($license = $kit->licenses()->find($license_id)) ) { + if (!($license = $kit->licenses()->find($license_id))) { return redirect()->route('kits.index')->with('error', 'License does not exist'); // TODO: trans } - + return view('kits/license-edit', [ 'kit' => $kit, 'license' => $license, @@ -296,20 +259,20 @@ class PredefinedKitsController extends Controller } /** - * Update attached licese - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $kit_id - * @param int $licenseId - * @return View - */ - public function updateLicense(Request $request, $kit_id, $license_id) { + * Update attached licese + * + * @author [D. Minaev] [] + * @param int $kit_id + * @param int $license_id + * @return View + */ + public function updateLicense(Request $request, $kit_id, $license_id) + { $this->authorize('update', PredefinedKit::class); if (is_null($kit = PredefinedKit::find($kit_id))) { // Redirect to the kits management page - return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans + return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans } $validator = \Validator::make($request->all(), $kit->makeLicenseRules($license_id)); @@ -323,23 +286,24 @@ class PredefinedKitsController extends Controller $pivot->license_id = $request->input('license_id'); $pivot->quantity = $request->input('quantity'); $pivot->save(); - + return redirect()->route('kits.edit', $kit_id)->with('success', 'License updated successfully.'); // TODO: trans } /** - * - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $licenseId - * @return View - */ - public function detachLicense($kit_id, $license_id) { + * Remove the license from set + * + * @author [D. Minaev] [] + * @param int $kit_id + * @param int $license_id + * @return View + */ + public function detachLicense($kit_id, $license_id) + { $this->authorize('update', PredefinedKit::class); if (is_null($kit = PredefinedKit::find($kit_id))) { // Redirect to the kits management page - return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans + return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans } // Delete childs @@ -349,26 +313,25 @@ class PredefinedKitsController extends Controller return redirect()->route('kits.edit', $kit_id)->with('success', 'License was successfully detached'); // TODO: trans } - + /** - * Returns a view containing attached accessory edit form. - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $kit_id - * @param int $accessoryId - * @return View - */ + * Returns a view containing attached accessory edit form. + * + * @author [D. Minaev] [] + * @param int $kit_id + * @param int $accessoryId + * @return View + */ public function editAccessory($kit_id, $accessory_id) - { + { $this->authorize('update', PredefinedKit::class); - if( !($kit = PredefinedKit::find($kit_id)) ) { + if (!($kit = PredefinedKit::find($kit_id))) { return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans } - if( !($accessory = $kit->accessories()->find($accessory_id)) ) { + if (!($accessory = $kit->accessories()->find($accessory_id))) { return redirect()->route('kits.index')->with('error', 'Accessory does not exist'); // TODO: trans } - + return view('kits/accessory-edit', [ 'kit' => $kit, 'accessory' => $accessory, @@ -377,20 +340,20 @@ class PredefinedKitsController extends Controller } /** - * Update attached accessory - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $kit_id - * @param int $accessoryId - * @return View - */ - public function updateAccessory(Request $request, $kit_id, $accessory_id) { + * Update attached accessory + * + * @author [D. Minaev] [] + * @param int $kit_id + * @param int $accessory_id + * @return View + */ + public function updateAccessory(Request $request, $kit_id, $accessory_id) + { $this->authorize('update', PredefinedKit::class); if (is_null($kit = PredefinedKit::find($kit_id))) { // Redirect to the kits management page - return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans + return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans } $validator = \Validator::make($request->all(), $kit->makeAccessoryRules($accessory_id)); @@ -404,23 +367,23 @@ class PredefinedKitsController extends Controller $pivot->accessory_id = $request->input('accessory_id'); $pivot->quantity = $request->input('quantity'); $pivot->save(); - + return redirect()->route('kits.edit', $kit_id)->with('success', 'Accessory updated successfully.'); // TODO: trans } /** - * - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $accessoryId - * @return View - */ - public function detachAccessory($kit_id, $accessory_id) { + * Remove the accessory from set + * + * @author [D. Minaev] [] + * @param int $accessory_id + * @return View + */ + public function detachAccessory($kit_id, $accessory_id) + { $this->authorize('update', PredefinedKit::class); if (is_null($kit = PredefinedKit::find($kit_id))) { // Redirect to the kits management page - return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans + return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans } // Delete childs @@ -431,24 +394,23 @@ class PredefinedKitsController extends Controller } /** - * Returns a view containing attached consumable edit form. - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $kit_id - * @param int $consumableId - * @return View - */ + * Returns a view containing attached consumable edit form. + * + * @author [D. Minaev] [] + * @param int $kit_id + * @param int $consumable_id + * @return View + */ public function editConsumable($kit_id, $consumable_id) - { + { $this->authorize('update', PredefinedKit::class); - if( !($kit = PredefinedKit::find($kit_id)) ) { + if (!($kit = PredefinedKit::find($kit_id))) { return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans } - if( !($consumable = $kit->consumables()->find($consumable_id)) ) { + if (!($consumable = $kit->consumables()->find($consumable_id))) { return redirect()->route('kits.index')->with('error', 'Consumable does not exist'); // TODO: trans } - + return view('kits/consumable-edit', [ 'kit' => $kit, 'consumable' => $consumable, @@ -457,20 +419,20 @@ class PredefinedKitsController extends Controller } /** - * Update attached consumable - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $kit_id - * @param int $consumableId - * @return View - */ - public function updateConsumable(Request $request, $kit_id, $consumable_id) { + * Update attached consumable + * + * @author [D. Minaev] [] + * @param int $kit_id + * @param int $consumableId + * @return View + */ + public function updateConsumable(Request $request, $kit_id, $consumable_id) + { $this->authorize('update', PredefinedKit::class); if (is_null($kit = PredefinedKit::find($kit_id))) { // Redirect to the kits management page - return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans + return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans } $validator = \Validator::make($request->all(), $kit->makeConsumableRules($consumable_id)); @@ -484,23 +446,23 @@ class PredefinedKitsController extends Controller $pivot->consumable_id = $request->input('consumable_id'); $pivot->quantity = $request->input('quantity'); $pivot->save(); - + return redirect()->route('kits.edit', $kit_id)->with('success', 'Consumable updated successfully.'); // TODO: trans } /** - * - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $consumableId - * @return View - */ - public function detachConsumable($kit_id, $consumable_id) { + * Remove the consumable from set + * + * @author [D. Minaev] [] + * @param int $consumable_id + * @return View + */ + public function detachConsumable($kit_id, $consumable_id) + { $this->authorize('update', PredefinedKit::class); if (is_null($kit = PredefinedKit::find($kit_id))) { // Redirect to the kits management page - return redirect()->route('kits.index')->with('error','Kit does not exist'); // TODO: trans + return redirect()->route('kits.index')->with('error', 'Kit does not exist'); // TODO: trans } // Delete childs @@ -509,44 +471,4 @@ class PredefinedKitsController extends Controller // Redirect to the kit management page return redirect()->route('kits.edit', $kit_id)->with('success', 'Consumable was successfully detached'); // TODO: trans } - - /** - * Returns true if a fieldset is set, 'add default values' is ticked and if - * any default values were entered into the form. - * - * @param array $input - * @return boolean - */ - private function shouldAddDefaultValues(array $input) - { - return !empty($input['add_default_values']) - && !empty($input['default_values']) - && !empty($input['custom_fieldset']); - } - - /** - * Adds default values to a accessory (as long as they are truthy) - * - * @param AssetModel $model - * @param array $defaultValues - * @return void - */ - private function assignCustomFieldsDefaultValues(AssetModel $model, array $defaultValues) - { - foreach ($defaultValues as $customFieldId => $defaultValue) { - if ($defaultValue) { - $model->defaultValues()->attach($customFieldId, ['default_value' => $defaultValue]); - } - } - } - - /** - * Removes all default values - * - * @return void - */ - private function removeCustomFieldsDefaultValues(AssetModel $model) - { - $model->defaultValues()->detach(); - } } diff --git a/app/Http/Transformers/PredefinedKitsTransformer.php b/app/Http/Transformers/PredefinedKitsTransformer.php index 4596f3e747..8ff4664f44 100644 --- a/app/Http/Transformers/PredefinedKitsTransformer.php +++ b/app/Http/Transformers/PredefinedKitsTransformer.php @@ -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] [] + * @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) { diff --git a/app/Models/PredefinedKit.php b/app/Models/PredefinedKit.php index 9044945ecb..81169aa75b 100644 --- a/app/Models/PredefinedKit.php +++ b/app/Models/PredefinedKit.php @@ -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.] [] * @version v1.0 */ class PredefinedKit extends SnipeModel @@ -25,61 +23,79 @@ class PredefinedKit extends SnipeModel protected $table = 'kits'; /** - * Category validation rules - */ + * Category validation rules + */ public $rules = array( - 'name' => 'required|min:1|max:255|unique' + 'name' => 'required|min:1|max:255|unique' ); use ValidatingTrait; 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', @@ -88,20 +104,13 @@ class PredefinedKit extends SnipeModel ], 'quantity' => 'required|integer|min:1' ]; - if(!$new) { + if (!$new) { $rule['pivot_id'] = "integer|exists:$pivot_table,id"; - + } 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. * @@ -112,16 +121,16 @@ 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] [] - * @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] [] - * @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] [] - * @since [v4.3] * @return \Illuminate\Database\Eloquent\Relations\Relation */ public function consumables() @@ -170,12 +170,9 @@ class PredefinedKit extends SnipeModel } /** - * Establishes the kits -> licenses relationship - * - * @author [A. Gianotto] [] - * @since [v4.3] - * @return \Illuminate\Database\Eloquent\Relations\Relation - */ + * Establishes the kits -> licenses relationship + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ public function accessories() { return $this->belongsToMany('\App\Models\Accessory', 'kits_accessories', 'kit_id', 'accessory_id')->withPivot('id', 'quantity'); diff --git a/app/Models/SnipeItPivot.php b/app/Models/SnipeItPivot.php deleted file mode 100644 index 1431854200..0000000000 --- a/app/Models/SnipeItPivot.php +++ /dev/null @@ -1,11 +0,0 @@ - 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() diff --git a/app/Services/PredefinedKitCheckoutService.php b/app/Services/PredefinedKitCheckoutService.php index decdb1db1c..096d806863 100644 --- a/app/Services/PredefinedKitCheckoutService.php +++ b/app/Services/PredefinedKitCheckoutService.php @@ -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.] [] + */ 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 { diff --git a/database/migrations/2018_10_18_191228_add_kits_licenses_table.php b/database/migrations/2018_10_18_191228_add_kits_licenses_table.php index b600cad3af..44ca2c0a24 100644 --- a/database/migrations/2018_10_18_191228_add_kits_licenses_table.php +++ b/database/migrations/2018_10_18_191228_add_kits_licenses_table.php @@ -20,8 +20,6 @@ class AddKitsLicensesTable extends Migration { $table->integer('quantity')->default(1); $table->timestamps(); }); - - } /**