Code comments and format

This commit is contained in:
Dmitrii Minaev 2019-02-23 22:44:03 +03:00
parent 5f3a0bdea5
commit d3c320e56f
12 changed files with 297 additions and 429 deletions

View file

@ -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
*
*/

View file

@ -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
*
*/

View file

@ -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)
{

View file

@ -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
*/

View file

@ -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,14 +52,13 @@ 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)
{
$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

View file

@ -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)
@ -57,32 +58,11 @@ class PredefinedKitsController extends Controller
$kit = new PredefinedKit;
$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()
@ -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
@ -124,7 +104,7 @@ class PredefinedKitsController extends Controller
// 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');
@ -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,45 +147,29 @@ 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
*/
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,
@ -219,17 +183,17 @@ 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))) {
// 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));
@ -250,16 +214,16 @@ 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
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
@ -272,19 +236,18 @@ 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)
{
$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
}
@ -298,18 +261,18 @@ 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))) {
// 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));
@ -328,18 +291,19 @@ 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
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
@ -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
@ -362,10 +325,10 @@ class PredefinedKitsController extends Controller
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
}
@ -379,18 +342,18 @@ 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))) {
// 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));
@ -409,18 +372,18 @@ 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
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
@ -433,19 +396,18 @@ 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)
{
$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
}
@ -459,18 +421,18 @@ 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))) {
// 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));
@ -489,18 +451,18 @@ 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
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();
}
}

View file

@ -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) {

View file

@ -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',
@ -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.
*
@ -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()

View file

@ -1,11 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\Pivot;
class SnipeItPivot extends Pivot
{
use ValidatingTrait;
public $rules = [];
}

View file

@ -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()

View file

@ -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 {

View file

@ -20,8 +20,6 @@ class AddKitsLicensesTable extends Migration {
$table->integer('quantity')->default(1);
$table->timestamps();
});
}
/**