added QR code route for asset controller
added QR code inclusion on asset controller getView action/template
This commit is contained in:
@@ -20,6 +20,8 @@ use Response;
|
||||
|
||||
class AssetsController extends AdminController {
|
||||
|
||||
protected $qrCodeDimensions = array( 'height' => 160, 'width' => 160);
|
||||
|
||||
/**
|
||||
* Show a list of all the assets.
|
||||
*
|
||||
@@ -527,10 +529,20 @@ class AssetsController extends AdminController {
|
||||
$asset = Asset::find($assetId);
|
||||
|
||||
if (isset($asset->id)) {
|
||||
return View::make('backend/hardware/view', compact('asset'));
|
||||
|
||||
$settings = Setting::getSettings();
|
||||
|
||||
$qr_code = (object) array(
|
||||
'display' => $settings->qr_code === '1',
|
||||
'height' => $this->qrCodeDimensions['height'],
|
||||
'width' => $this->qrCodeDimensions['width'],
|
||||
'url' => route('qr_code/hardware', $asset->id)
|
||||
);
|
||||
|
||||
return View::make('backend/hardware/view', compact('asset', 'qr_code'));
|
||||
} else {
|
||||
// Prepare the error message
|
||||
$error = Lang::get('admin/hardware/message.does_not_exist', compact('id' ));
|
||||
$error = Lang::get('admin/hardware/message.does_not_exist', compact('id'));
|
||||
|
||||
// Redirect to the user management page
|
||||
return Redirect::route('assets')->with('error', $error);
|
||||
@@ -538,6 +550,34 @@ class AssetsController extends AdminController {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the QR code representing the asset
|
||||
*
|
||||
* @param int $assetId
|
||||
* @return View
|
||||
**/
|
||||
public function getQrCode($assetId = null)
|
||||
{
|
||||
$settings = Setting::getSettings();
|
||||
|
||||
if ($settings->qr_code === '1') {
|
||||
$asset = Asset::find($assetId);
|
||||
if (isset($asset->id)) {
|
||||
$renderer = new \BaconQrCode\Renderer\Image\Png;
|
||||
$renderer->setWidth(120)->setHeight(120);
|
||||
$writer = new \BaconQrCode\Writer($renderer);
|
||||
$content = $writer->writeString(route('view/hardware', $asset->id));
|
||||
|
||||
$response = Response::make($content, 200);
|
||||
$response->header('Content-Type', 'image/png');
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
$response = Response::make('', 404);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asset update.
|
||||
*
|
||||
|
||||
@@ -26,6 +26,7 @@ Route::group(array('prefix' => 'hardware'), function()
|
||||
Route::get('{assetId}/checkin', array('as' => 'checkin/hardware', 'uses' => 'Controllers\Admin\AssetsController@getCheckin'));
|
||||
Route::post('{assetId}/checkin', 'Controllers\Admin\AssetsController@postCheckin');
|
||||
Route::get('{assetId}/view', array('as' => 'view/hardware', 'uses' => 'Controllers\Admin\AssetsController@getView'));
|
||||
Route::get('{assetId}_qr_code.png', array('as' => 'qr_code/hardware', 'uses' => 'Controllers\Admin\AssetsController@getQrCode'));
|
||||
|
||||
|
||||
# Asset Model Management
|
||||
|
||||
@@ -154,6 +154,13 @@ View Asset {{ $asset->asset_tag }} ::
|
||||
<!-- side address column -->
|
||||
<div class="col-md-3 col-xs-12 address pull-right">
|
||||
|
||||
@if ($qr_code->display)
|
||||
<h6>QR Code</h6>
|
||||
<p>
|
||||
<img src="{{ $qr_code->url }}" height="{{ $qr_code->height }}" width="{{ $qr_code->width }}" />
|
||||
</p>
|
||||
@endif
|
||||
|
||||
@if ((isset($asset->assigned_to ) && ($asset->assigned_to > 0)))
|
||||
<h6><br>Checked Out To:</h6>
|
||||
<ul>
|
||||
|
||||
Reference in New Issue
Block a user