snipe-it/app/Presenters/ComponentPresenter.php
Daniel Meltzer cafafe851c Notification rework (#3103)
* Move slack integration to laravel5.3 style notifications, part 1.

* Fix consumable tab when active.

* Move the slack notifiable to the settings model.  Move all slack notifications into logCheckout/logCheckin.  Should think about refactoring this as an event at some point still.  Move Asset checkin/checkout to use the general loggable trait rather than it's own solution.

* Fix a logic error where assets with a non deployable status would show checkin instead of no button at all.

* Fix an html formatting error that resulted in us not closing a form.  This would cause the checkin page to try to submit a delete request (related to the modal form) rather than the desired checkin request.  Also fix formatting in this file.
2016-12-26 15:19:04 -08:00

80 lines
2.3 KiB
PHP

<?php
namespace App\Presenters;
use App\Helpers\Helper;
use Illuminate\Support\Facades\Gate;
/**
* Class ComponentPresenter
* @package App\Presenters
*/
class ComponentPresenter extends Presenter
{
/**
* Formatted JSON string for data table.
* @return array
*/
public function forDataTable()
{
$actions = '<nobr>';
if (Gate::allows('checkout', $this->model)) {
$actions .= Helper::generateDatatableButton('checkout', route('checkout/component', $this->id), $this->numRemaining() > 0);
}
if (Gate::allows('update', $this->model)) {
$actions .= Helper::generateDatatableButton('edit', route('components.edit', $this->id));
}
if (Gate::allows('delete', $this->model)) {
$actions .= Helper::generateDatatableButton(
'delete',
route('components.destroy', $this->id),
true, /* enabled */
trans('admin/components/message.delete.confirm'),
$this->name
);
}
$actions .='</nobr>';
$results = [
'checkbox' =>'<div class="text-center"><input type="checkbox" name="component['.$this->id.']" class="one_required"></div>',
'id' => $this->id,
'name' => $this->nameUrl(),
'serial_number' => $this->serial,
'location' => $this->locationUrl(),
'qty' => number_format($this->qty),
'min_amt' => e($this->min_amt),
'category' => $this->categoryUrl(),
'order_number' => $this->order_number,
'purchase_date' => $this->purchase_date,
'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost),
'numRemaining' => $this->numRemaining(),
'actions' => $actions,
'companyName' => $this->companyUrl(),
];
return $results;
}
/**
* Link to this components name
* @return string
*/
public function nameUrl()
{
return (string) link_to_route('components.show', $this->name, $this->id);
}
/**
* Url to view this item.
* @return string
*/
public function viewUrl()
{
return route('components.show', $this->id);
}
}