2016-12-29 22:23:36 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Presenters;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class CompanyPresenter
|
|
|
|
* @package App\Presenters
|
|
|
|
*/
|
|
|
|
class ActionlogPresenter extends Presenter
|
|
|
|
{
|
|
|
|
|
|
|
|
public function admin()
|
|
|
|
{
|
2016-12-30 11:44:47 -08:00
|
|
|
if ($user = $this->model->user) {
|
|
|
|
if(empty($user->deleted_at)) {
|
|
|
|
return $user->present()->nameUrl();
|
|
|
|
}
|
|
|
|
// The user was deleted
|
2017-05-23 14:31:44 -07:00
|
|
|
return '<del>'.$user->getFullNameAttribute()."</del> (deleted)";
|
2016-12-30 11:44:47 -08:00
|
|
|
}
|
|
|
|
return '';
|
2016-12-29 22:23:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function item()
|
2017-04-06 20:08:38 -07:00
|
|
|
{
|
2016-12-29 22:23:36 -08:00
|
|
|
if($this->action_type=='uploaded') {
|
|
|
|
return (string) link_to_route('show/userfile', $this->model->filename, [$this->model->item->id, $this->model->id]);
|
|
|
|
}
|
2016-12-30 11:44:47 -08:00
|
|
|
if ($item = $this->model->item) {
|
|
|
|
if (empty($item->deleted_at)) {
|
|
|
|
return $this->model->item->present()->nameUrl();
|
|
|
|
}
|
|
|
|
// The item was deleted
|
2017-05-23 14:31:44 -07:00
|
|
|
return '<del>'.$item->name.'</del> (deleted)';
|
2016-12-29 22:23:36 -08:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2017-05-23 14:31:44 -07:00
|
|
|
|
|
|
|
public function icon()
|
|
|
|
{
|
2017-05-23 15:53:39 -07:00
|
|
|
$itemicon = 'fa fa-paperclip';
|
|
|
|
|
2017-05-23 14:31:44 -07:00
|
|
|
if ($this->itemType() == "asset") {
|
|
|
|
$itemicon = 'fa fa-barcode';
|
|
|
|
} elseif ($this->itemType() == "accessory") {
|
|
|
|
$itemicon = 'fa fa-keyboard-o';
|
|
|
|
} elseif ($this->itemType()=="consumable") {
|
|
|
|
$itemicon = 'fa fa-tint';
|
|
|
|
} elseif ($this->itemType()=="license") {
|
|
|
|
$itemicon = 'fa fa-floppy-o';
|
|
|
|
} elseif ($this->itemType()=="component") {
|
|
|
|
$itemicon = 'fa fa-hdd-o';
|
2017-05-23 15:53:39 -07:00
|
|
|
}
|
2017-05-23 14:31:44 -07:00
|
|
|
|
|
|
|
return $itemicon;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function actionType() {
|
2018-01-20 00:27:45 -08:00
|
|
|
return mb_strtolower(trans('general.'.str_replace(' ', '_', $this->action_type)));
|
2017-05-23 14:31:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-12-29 22:23:36 -08:00
|
|
|
public function target()
|
|
|
|
{
|
2016-12-30 11:44:47 -08:00
|
|
|
$target = null;
|
2016-12-29 22:23:36 -08:00
|
|
|
// Target is messy.
|
|
|
|
// On an upload, the target is the item we are uploading to, stored as the "item" in the log.
|
|
|
|
if ($this->action_type=='uploaded') {
|
2016-12-30 11:44:47 -08:00
|
|
|
$target = $this->model->item;
|
|
|
|
} elseif (($this->action_type=='accepted') || ($this->action_type=='declined')) {
|
2016-12-29 22:23:36 -08:00
|
|
|
// If we are logging an accept/reject, the target is not stored directly,
|
|
|
|
// so we access it through who the item is assigned to.
|
|
|
|
// FIXME: On a reject it's not assigned to anyone.
|
2016-12-30 11:44:47 -08:00
|
|
|
$target = $this->model->item->assignedTo;
|
2016-12-29 22:23:36 -08:00
|
|
|
} elseif ($this->action_type=='requested') {
|
|
|
|
if ($this->model->user) {
|
2016-12-30 11:44:47 -08:00
|
|
|
$target = $this->model->user;
|
2016-12-29 22:23:36 -08:00
|
|
|
}
|
2016-12-30 11:44:47 -08:00
|
|
|
} elseif ($this->model->target) {
|
|
|
|
// Otherwise, we'll just take the target of the log.
|
|
|
|
$target = $this->model->target;
|
2016-12-29 22:23:36 -08:00
|
|
|
}
|
2016-12-30 11:44:47 -08:00
|
|
|
|
|
|
|
if($target) {
|
|
|
|
if (empty($target->deleted_at)) {
|
|
|
|
return $target->present()->nameUrl();
|
|
|
|
}
|
|
|
|
return '<del>'.$target->present()->name().'</del>';
|
2016-12-29 22:23:36 -08:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|