mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
02c1a45025
* Add presenters for models. Move bootstrap table JSON generation to these presenters, which cleans up controllers a lot. Move view specific modifications from the models to the presenters as well. * Fix some issues found by travis and codacy * Fix a few more issues found while testing. * Attempt another acceptance test fix * Try something else * Maybe.. * Move conditionals out of the datatable method and into dedicated url methods.
70 lines
2.1 KiB
PHP
70 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Presenters;
|
|
|
|
|
|
use App\Helpers\Helper;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
/**
|
|
* Class ConsumablePresenter
|
|
* @package App\Presenters
|
|
*/
|
|
class ConsumablePresenter extends Presenter
|
|
{
|
|
|
|
/**
|
|
* Formatted JSON for data table.
|
|
* @return array
|
|
*/
|
|
public function forDataTable()
|
|
{
|
|
$actions = '<nobr>';
|
|
if (Gate::allows('checkout', $this->model)) {
|
|
$actions .= Helper::generateDatatableButton('checkout', route('checkout/consumable', $this->id), $this->numRemaining() > 0);
|
|
}
|
|
|
|
if (Gate::allows('update', $this->model)) {
|
|
$actions .= Helper::generateDatatableButton('edit', route('consumables.edit', $this->id));
|
|
}
|
|
if (Gate::allows('delete', $this->model)) {
|
|
$actions .= Helper::generateDatatableButton(
|
|
'delete',
|
|
route('consumables.destroy', $this->id),
|
|
true, /* enabled */
|
|
trans('admin/consumables/message.delete.confirm'),
|
|
$this->name
|
|
);
|
|
}
|
|
$actions .='</nobr>';
|
|
|
|
$results = [
|
|
'actions' => $actions,
|
|
'category' => $this->categoryUrl(),
|
|
'companyName' => $this->companyUrl(),
|
|
'id' => $this->id,
|
|
'item_no' => $this->item_no,
|
|
'location' => $this->locationUrl(),
|
|
'manufacturer' => $this->manufacturerUrl(),
|
|
'min_amt' => $this->min_amt,
|
|
'model_number' => $this->model_number,
|
|
'name' => $this->nameUrl(),
|
|
'numRemaining' => $this->numRemaining(),
|
|
'order_number' => $this->order_number,
|
|
'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost),
|
|
'purchase_date' => $this->purchase_date,
|
|
'qty' => $this->qty,
|
|
];
|
|
return $results;
|
|
}
|
|
|
|
/**
|
|
* Link to this consumables name
|
|
* @return string
|
|
*/
|
|
private function nameUrl()
|
|
{
|
|
return (string)link_to_route('consumables.show', $this->name, $this->id);
|
|
}
|
|
}
|