mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-28 23:19:42 -08:00
638a7b2d91
* Extract method/cleanup * Remove apiStore method that is unusued since api controllers. * Use proper model exception * Remove old user importer. This is now supported by the general importer framework. * Refactor AssetsController methods. This is a giant diff without many functional changes, mostly cosmetic. I've pulled a number of methods out of assetscontroller, preferring instead to create some more targetted controllers for related actions. I think this cleans up the file some, and suggests some places for future targetted improvement. Fix weird missing things. * Fix Unit test failing after date changes. * Pass valid string to be translated. * Some method cleanup for codacy. * Extract trait for common checkout uses and codacy fixes.
57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Exceptions\CheckoutNotAllowed;
|
|
use App\Models\Asset;
|
|
use App\Models\Location;
|
|
use App\Models\User;
|
|
|
|
trait CheckInOutRequest
|
|
{
|
|
/**
|
|
* Find target for checkout
|
|
* @return SnipeModel Target asset is being checked out to.
|
|
*/
|
|
protected function determineCheckoutTarget()
|
|
{
|
|
// This item is checked out to a location
|
|
switch(request('checkout_to_type'))
|
|
{
|
|
case 'location':
|
|
return Location::findOrFail(request('assigned_location'));
|
|
case 'asset':
|
|
return Asset::findOrFail(request('assigned_asset'));
|
|
case 'user':
|
|
return User::findOrFail(request('assigned_user'));
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Update the location of the asset passed in.
|
|
* @param Asset $asset Asset being updated
|
|
* @param SnipeModel $target Target with location
|
|
* @return Asset Asset being updated
|
|
*/
|
|
protected function updateAssetLocation($asset, $target)
|
|
{
|
|
switch(request('checkout_to_type'))
|
|
{
|
|
case 'location':
|
|
$asset->location_id = $target->id;
|
|
break;
|
|
case 'asset':
|
|
$asset->location_id = $target->rtd_location_id;
|
|
// Override with the asset's location_id if it has one
|
|
if ($target->location_id!='') {
|
|
$asset->location_id = $target->location_id;
|
|
}
|
|
break;
|
|
case 'user':
|
|
$asset->location_id = $target->location_id;
|
|
break;
|
|
}
|
|
return $asset;
|
|
}
|
|
}
|