mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 15:44:11 -08:00
64d649be7f
* Extract a handlesimages trait to centralize logic for parsing/storing images on upload in create/edit methods. * Use same image upload/layout in accessories as consum+components. * Monster: Cleanup/Refactor http controllers. This cleans up docblocks, pulls most non-crudy actions into their own controllers, and does general cleanup/logic refactoring. There /should/ be no functional changes, but we all know how should works.. Extract checkin/checkout functions to a separate controller for accessories. Move controllers to subdirectory. Cleanup AssetModelsController Extract component checkin/checkout Assorted cleanups/doc/formatting in controllers. Refactor LicenseController. Refactor UsersController Update viewassetscontroller. * Codacy cleanups * More codacy cleanups. Extract a LicenseCheckout Form request as well. * A bit more refactor/cleaning of the license checkout method. * Review Related Cleanups * Fix most of the item_not_found translations. In many cases, the string being generated did not even use the id parameter. Where it does, pass it as id instead of as a different value. * Remove some old $data arrays from when we manually sent emails from the controllers. This has been superseeded by the notification system (yay!) * Bugfix: Only log the checkin of an accessory if the checkin completes sucessfully.
72 lines
2.8 KiB
PHP
72 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Accessories;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Accessory;
|
|
use App\Models\User;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Input;
|
|
|
|
class AccessoryCheckinController extends Controller
|
|
{
|
|
/**
|
|
* Check the accessory back into inventory
|
|
*
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
* @param Request $request
|
|
* @param integer $accessoryUserId
|
|
* @param string $backto
|
|
* @return View
|
|
* @internal param int $accessoryId
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
*/
|
|
public function create($accessoryUserId = null, $backto = null)
|
|
{
|
|
// Check if the accessory exists
|
|
if (is_null($accessory_user = DB::table('accessories_users')->find($accessoryUserId))) {
|
|
// Redirect to the accessory management page with error
|
|
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.not_found'));
|
|
}
|
|
|
|
$accessory = Accessory::find($accessory_user->accessory_id);
|
|
$this->authorize('checkin', $accessory);
|
|
return view('accessories/checkin', compact('accessory'))->with('backto', $backto);
|
|
}
|
|
|
|
/**
|
|
* Check in the item so that it can be checked out again to someone else
|
|
*
|
|
* @uses Accessory::checkin_email() to determine if an email can and should be sent
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
* @param null $accessoryUserId
|
|
* @param string $backto
|
|
* @return Redirect
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
* @internal param int $accessoryId
|
|
*/
|
|
public function store($accessoryUserId = null, $backto = null)
|
|
{
|
|
// Check if the accessory exists
|
|
if (is_null($accessory_user = DB::table('accessories_users')->find($accessoryUserId))) {
|
|
// Redirect to the accessory management page with error
|
|
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
|
|
}
|
|
|
|
$accessory = Accessory::find($accessory_user->accessory_id);
|
|
|
|
$this->authorize('checkin', $accessory);
|
|
|
|
// Was the accessory updated?
|
|
if (DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) {
|
|
$return_to = e($accessory_user->assigned_to);
|
|
$accessory->logCheckin(User::find($return_to), e(Input::get('note')));
|
|
|
|
return redirect()->route("accessories.show", $accessory->id)->with('success', trans('admin/accessories/message.checkin.success'));
|
|
}
|
|
// Redirect to the accessory management page with error
|
|
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.checkin.error'));
|
|
}
|
|
}
|