diff --git a/app/Console/Commands/Purge.php b/app/Console/Commands/Purge.php index 8abe6048c..d5f7cab50 100644 --- a/app/Console/Commands/Purge.php +++ b/app/Console/Commands/Purge.php @@ -65,7 +65,7 @@ class Purge extends Command $asset_maintenances = 0; foreach ($assets as $asset) { - $this->info('- Asset "'.$asset->showAssetName().'" deleted.'); + $this->info('- Asset "'.$asset->present()->name().'" deleted.'); $asset_assoc += $asset->assetlog()->count(); $asset->assetlog()->forceDelete(); $asset_maintenances += $asset->assetmaintenances()->count(); diff --git a/app/Console/Commands/SendExpirationAlerts.php b/app/Console/Commands/SendExpirationAlerts.php index 34a80ee27..e47b99eae 100644 --- a/app/Console/Commands/SendExpirationAlerts.php +++ b/app/Console/Commands/SendExpirationAlerts.php @@ -55,7 +55,7 @@ class SendExpirationAlerts extends Command foreach ($expiring_assets as $asset) { - $expires = $asset->warrantee_expires(); + $expires = $asset->present()->warrantee_expires(); $difference = round(abs(strtotime($expires) - strtotime($now))/86400); if ($difference > 30) { @@ -64,11 +64,11 @@ class SendExpirationAlerts extends Command $asset_data['email_content'] .= ''; } $asset_data['email_content'] .= ''; - $asset_data['email_content'] .= $asset->showAssetName().''.e($asset->asset_tag).''; - $asset_data['email_content'] .= ''.e($asset->warrantee_expires()).''; + $asset_data['email_content'] .= $asset->present()->name().''.e($asset->asset_tag).''; + $asset_data['email_content'] .= ''.e($asset->present()->warrantee_expires()).''; $asset_data['email_content'] .= ''.$difference.' '.trans('mail.days').''; $asset_data['email_content'] .= ''.($asset->supplier ? e($asset->supplier->name) : '').''; - $asset_data['email_content'] .= ''.($asset->assigneduser ? e($asset->assigneduser->fullName()) : '').''; + $asset_data['email_content'] .= ''.($asset->assigneduser ? e($asset->assigneduser->present()->fullName()) : '').''; $asset_data['email_content'] .= ''; } diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index b88314931..833278efa 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -139,7 +139,7 @@ class Helper $models = AssetModel::with('manufacturer')->get(); $model_array[''] = trans('general.select_model'); foreach ($models as $model) { - $model_array[$model->id] = $model->displayModelName(); + $model_array[$model->id] = $model->present()->modelName(); } return $model_array; } diff --git a/app/Http/Controllers/AccessoriesController.php b/app/Http/Controllers/AccessoriesController.php index 073b6bdc6..a361fd449 100755 --- a/app/Http/Controllers/AccessoriesController.php +++ b/app/Http/Controllers/AccessoriesController.php @@ -317,7 +317,7 @@ class AccessoriesController extends Controller 'fields' => [ [ 'title' => 'Checked Out:', - 'value' => 'Accessory <'.route('accessories.show', $accessory->id).'|'.$accessory->name.'> checked out to <'.route('users.show', $user->id).'|'.$user->fullName().'> by <'.route('users.show', $admin_user->id).'|'.$admin_user->fullName().'>.' + 'value' => 'Accessory <'.route('accessories.show', $accessory->id).'|'.$accessory->name.'> checked out to <'.route('users.show', $user->id).'|'.$user->present()->fullName().'> by <'.route('users.show', $admin_user->id).'|'.$admin_user->present()->fullName().'>.' ], [ 'title' => 'Note:', @@ -431,7 +431,7 @@ class AccessoriesController extends Controller 'fields' => [ [ 'title' => 'Checked In:', - 'value' => class_basename(strtoupper($logaction->item_type)).' <'.route('accessories.show', $accessory->id).'|'.e($accessory->name).'> checked in by <'.route('users.show', $admin_user->id).'|'.e($admin_user->fullName()).'>.' + 'value' => class_basename(strtoupper($logaction->item_type)).' <'.route('accessories.show', $accessory->id).'|'.e($accessory->name).'> checked in by <'.route('users.show', $admin_user->id).'|'.e($admin_user->present()->fullName()).'>.' ], [ 'title' => 'Note:', @@ -540,46 +540,7 @@ class AccessoriesController extends Controller $rows = array(); foreach ($accessories as $accessory) { - - $actions = ''; - if (Gate::allows('checkout', $accessory)) { - $actions .= Helper::generateDatatableButton( - 'checkout', - route('checkout/accessory', $accessory->id), - $accessory->numRemaining() > 0 - ); - } - if (Gate::allows('update', $accessory)) { - $actions .= Helper::generateDatatableButton('edit', route('accessories.update', $accessory->id)); - } - if (Gate::allows('delete', $accessory)) { - $actions .= Helper::generateDatatableButton( - 'delete', - route('accessories.destroy', $accessory->id), - $enabled = true, - trans('admin/accessories/message.delete.confirm'), - $accessory->name - ); - } - $actions .= ''; - $company = $accessory->company; - - $rows[] = array( - 'name' => ''. $accessory->name.'', - 'category' => ($accessory->category) ? (string)link_to('admin/settings/categories/'.$accessory->category->id.'/view', $accessory->category->name) : '', - 'model_number' => e($accessory->model_number), - 'qty' => e($accessory->qty), - 'order_number' => e($accessory->order_number), - 'min_amt' => e($accessory->min_amt), - 'location' => ($accessory->location) ? e($accessory->location->name): '', - 'purchase_date' => e($accessory->purchase_date), - 'purchase_cost' => Helper::formatCurrencyOutput($accessory->purchase_cost), - 'numRemaining' => $accessory->numRemaining(), - 'actions' => $actions, - 'companyName' => is_null($company) ? '' : e($company->name), - 'manufacturer' => $accessory->manufacturer ? (string) link_to(route('manufacturers.show', $accessory->manufacturer_id), $accessory->manufacturer->name) : '' - - ); + $rows[] = $accessory->present()->forDataTable(); } $data = array('total'=>$accessCount, 'rows'=>$rows); @@ -633,9 +594,9 @@ class AccessoriesController extends Controller } if (Gate::allows('view', $user)) { - $name = (string) link_to_route('users.show', e($user->fullName()), [$user->id]); + $name = (string) link_to_route('users.show', e($user->present()->fullName()), [$user->id]); } else { - $name = e($user->fullName()); + $name = e($user->present()->fullName()); } $rows[] = array( diff --git a/app/Http/Controllers/AssetMaintenancesController.php b/app/Http/Controllers/AssetMaintenancesController.php index 0c80a0413..bc45c5ca0 100644 --- a/app/Http/Controllers/AssetMaintenancesController.php +++ b/app/Http/Controllers/AssetMaintenancesController.php @@ -125,7 +125,7 @@ class AssetMaintenancesController extends Controller $rows[] = array( 'id' => $maintenance->id, - 'asset_name' => ($maintenance->asset) ? (string)link_to_route('maintenances.show', $maintenance->asset->showAssetName(), ['maintenance' => $maintenance->asset->id]) : 'Deleted Asset' , + 'asset_name' => ($maintenance->asset) ? (string)link_to_route('maintenances.show', $maintenance->asset->present()->Name(), ['maintenance' => $maintenance->asset->id]) : 'Deleted Asset' , 'title' => $maintenance->title, 'notes' => $maintenance->notes, 'supplier' => ($maintenance->supplier) ? (string)link_to_route('suppliers.show', $maintenance->supplier->name, ['maintenance'=>$maintenance->supplier->id]) : 'Deleted Supplier', @@ -134,7 +134,7 @@ class AssetMaintenancesController extends Controller 'start_date' => $maintenance->start_date, 'asset_maintenance_time' => $maintenance->asset_maintenance_time, 'completion_date' => $maintenance->completion_date, - 'user_id' => ($maintenance->admin) ? (string)link_to_route('users.show', $maintenance->admin->fullName(), ['user'=>$maintenance->admin->id]) : '', + 'user_id' => ($maintenance->admin) ? (string)link_to_route('users.show', $maintenance->admin->present()->fullName(), ['user'=>$maintenance->admin->id]) : '', 'actions' => $actions, 'companyName' => ($maintenance->asset->company) ? $maintenance->asset->company->name : '' ); diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index 548aeb1b8..b1852fa6b 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -1,6 +1,7 @@ TextSearch($request->input('search')); } @@ -412,34 +412,7 @@ class AssetModelsController extends Controller $rows = array(); foreach ($models as $model) { - $actions = '
'; - if ($model->deleted_at == '') { - $actions .= Helper::generateDatatableButton('clone', route('clone/model', $model->id)); - $actions .= Helper::generateDatatableButton('edit', route('models.edit', $model->id)); - $actions .= Helper::generateDatatableButton( - 'delete', - route('models.destroy', $model->id), - trans('admin/models/message.delete.confirm'), - $model->name - ); - } else { - $actions .= Helper::generateDatatableButton('restore', route('restore/model', $model->id)); - } - - $rows[] = array( - 'id' => $model->id, - 'manufacturer' => (string)link_to_route('manufacturers.show', $model->manufacturer->name, ['manufacturer' => $model->manufacturer->id]), - 'name' => (string)link_to_route('models.show',$model->name, ['model' => $model->id]), - 'image' => ($model->image!='') ? '' : '', - 'modelnumber' => $model->model_number, - 'numassets' => $model->assets->count(), - 'depreciation' => (($model->depreciation) && ($model->depreciation->id > 0)) ? $model->depreciation->name.' ('.$model->depreciation->months.')' : trans('general.no_depreciation'), - 'category' => ($model->category) ? (string)link_to_route('categories.show', $model->category->name, ['category' => $model->category->id]) : '', - 'eol' => ($model->eol) ? $model->eol.' '.trans('general.months') : '', - 'note' => $model->getNote(), - 'fieldset' => ($model->fieldset) ? (string)link_to_route('custom_fields/model', $model->fieldset->name, ['model' => $model->fieldset->id]) : '', - 'actions' => $actions - ); + $rows[] = $model->present()->forDataTable(); } $data = array('total' => $modelCount, 'rows' => $rows); @@ -480,29 +453,10 @@ class AssetModelsController extends Controller $rows = array(); - + $all_custom_fields = CustomField::all(); foreach ($assets as $asset) { - $actions = ''; - if ($asset->assetstatus) { - if ($asset->assetstatus->deployable != 0) { - if (($asset->assigned_to !='') && ($asset->assigned_to > 0)) { - $actions = Helper::generateDatatableButton('checkin', route('checkin/hardware', $asset->id)); - } else { - $actions = Helper::generateDatatableButton('checkout', route('checkout/hardware', $asset->id)); - } - } - } - - $rows[] = array( - 'id' => $asset->id, - 'name' => (string)link_to_route('hardware.show', $asset->showAssetName(), ['asset' => $asset->id]), - 'asset_tag' => (string)link_to_route('hardware.show', $asset->asset_tag, ['asset' => $asset->id]), - 'serial' => $asset->serial, - 'assigned_to' => ($asset->assigned_to) ? (string)link_to_route('users.show', $asset->assigneduser->fullName(), ['asset' =>$asset->assigned_to]) : '', - 'actions' => $actions, - 'companyName' => Company::getName($asset) - ); + $rows[] = $asset->present()->forDataTable($all_custom_fields); } $data = array('total' => $assetsCount, 'rows' => $rows); diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index 323f15674..23fab7b5c 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -587,9 +587,9 @@ class AssetsController extends Controller 'title' => 'Checked In:', 'value' => class_basename( strtoupper($logaction->item_type)) - .' asset <'.route('hardware.show', $asset->id).'|'.e($asset->showAssetName()) + .' asset <'.route('hardware.show', $asset->id).'|'.e($asset->present()->name()) .'> checked in by <'.route('users.show',Auth::user()->id) - .'|'.e(Auth::user()->fullName()).'>.' + .'|'.e(Auth::user()->present()->fullName()).'>.' ], [ 'title' => 'Note:', @@ -607,7 +607,7 @@ class AssetsController extends Controller $data['log_id'] = $logaction->id; $data['first_name'] = $user->first_name; - $data['item_name'] = $asset->showAssetName(); + $data['item_name'] = $asset->present()->name(); $data['checkin_date'] = $logaction->created_at; $data['item_tag'] = $asset->asset_tag; $data['item_serial'] = $asset->serial; @@ -1036,7 +1036,7 @@ class AssetsController extends Controller 'item_id' => $asset->id, 'item_type' => Asset::class, 'user_id' => Auth::user()->id, - 'note' => 'Checkout imported by '.Auth::user()->fullName().' from history importer', + 'note' => 'Checkout imported by '.Auth::user()->present()->fullName().' from history importer', 'target_id' => $item[$asset_tag][$batch_counter]['user_id'], 'target_type' => User::class, 'created_at' => $item[$asset_tag][$batch_counter]['checkout_date'], @@ -1081,7 +1081,7 @@ class AssetsController extends Controller 'item_id' => $asset_batch[$x]['asset_id'], 'item_type' => Asset::class, 'user_id' => Auth::user()->id, - 'note' => 'Checkin imported by ' . Auth::user()->fullName() . ' from history importer', + 'note' => 'Checkin imported by ' . Auth::user()->present()->fullName() . ' from history importer', 'target_id' => null, 'created_at' => $checkin_date, 'action_type' => 'checkin' @@ -1465,9 +1465,7 @@ class AssetsController extends Controller 'purchase_date', 'purchase_cost' ]; - $all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load - foreach ($all_custom_fields as $field) { $allowed_columns[]=$field->db_column_name(); } @@ -1510,108 +1508,8 @@ class AssetsController extends Controller $rows = array(); foreach ($assets as $asset) { - $inout = ''; - $actions = '
'; - if ($asset->deleted_at=='') { - if (Gate::allows('create', $asset)) { - $actions .= Helper::generateDatatableButton('clone', route('clone/hardware', $asset->id)); - } - if (Gate::allows('update', $asset)) { - $actions .= Helper::generateDatatableButton('edit', route('hardware.edit', $asset->id)); - } - if (Gate::allows('delete', $asset)) { - $actions .= Helper::generateDatatableButton( - 'delete', - route('hardware.destroy', $asset->id), - $enabled = true, - trans('admin/hardware/message.delete.confirm'), - $asset->asset_tag - ); - } - } elseif ($asset->model->deleted_at=='') { - $actions .= Helper::generateDatatableButton('restore', route('restore/hardware', $asset->id)); - } - $actions .= '
'; - - if (($asset->availableForCheckout())) - { - if (Gate::allows('checkout', $asset)) { - $inout = '' . trans('general.checkout') . ''; - } - - } else { - if (Gate::allows('checkin', $asset)) { - $inout = '' . trans('general.checkin') . ''; - } - } - $actions .= '
'; - $purchase_cost = Helper::formatCurrencyOutput($asset->purchase_cost); - - $row = array( - 'checkbox' =>'
', - 'id' => $asset->id, - 'image' => (($asset->image) && ($asset->image!='')) - ? '' - : ((($asset->model) && ($asset->model->image!='')) - ? '' - : '' - ), - 'name' => (string) link_to_route('hardware.show', e($asset->name), $asset->id), - 'asset_tag' => (string) link_to_route('hardware.show', e($asset->asset_tag), $asset->id), - 'serial' => e($asset->serial), - 'model' => ($asset->model) ? (string)link_to_route('models.show', e($asset->model->name), ['model' => $asset->model->id]) : 'No model', - 'model_number' => ($asset->model && $asset->model->model_number) ? (string)$asset->model->model_number : '', - 'status_label' => ($asset->assigneduser) ? 'Deployed' : ((e($asset->assetstatus)) ? e($asset->assetstatus->name) : ''), - 'assigned_to' => ($asset->assigneduser) ? (string)link_to_route('users.show', e($asset->assigneduser->fullName()), ['user' => $asset->assigned_to]) : '', - 'location' => (($asset->assigneduser) && ($asset->assigneduser->userloc!='')) - ? (string)link_to_route('locations.show', e($asset->assigneduser->userloc->name), ['location' => $asset->assigneduser->userloc->id]) - : (($asset->defaultLoc!='') - ? (string)link_to_route('locations.show', e($asset->defaultLoc->name), ['location' => $asset->defaultLoc->id]) - : '' - ), - 'category' => (($asset->model) && ($asset->model->category)) ?(string)link_to_route('categories.show', e($asset->model->category->name), ['category' => $asset->model->category->id]) : '', - 'manufacturer' => (($asset->model) && ($asset->model->manufacturer)) - ? (string)link_to_route('manufacturers.show', e($asset->model->manufacturer->name), ['manufacturer' => $asset->model->manufacturer->id]) - : '', - 'eol' => ($asset->eol_date()) ? $asset->eol_date() : '', - 'purchase_cost' => $purchase_cost, - 'purchase_date' => ($asset->purchase_date) ? $asset->purchase_date : '', - 'notes' => e($asset->notes), - 'order_number' => ($asset->order_number!='') ? ''.e($asset->order_number).'' : '', - 'last_checkout' => ($asset->last_checkout!='') ? e($asset->last_checkout) : '', - 'expected_checkin' => ($asset->expected_checkin!='') ? e($asset->expected_checkin) : '', - 'created_at' => ($asset->created_at!='') ? e($asset->created_at->format('F j, Y h:iA')) : '', - 'change' => ($inout) ? $inout : '', - 'actions' => ($actions) ? $actions : '', - 'companyName' => is_null($asset->company) ? '' : e($asset->company->name) - ); - foreach ($all_custom_fields as $field) { - $column_name = $field->db_column_name(); - - if ($field->isFieldDecryptable($asset->{$column_name})) { - - if (Gate::allows('admin')) { - if (($field->format=='URL') && ($asset->{$column_name}!='')) { - $row[$column_name] = ''.Helper::gracefulDecrypt($field, $asset->{$column_name}).''; - } else { - $row[$column_name] = Helper::gracefulDecrypt($field, $asset->{$column_name}); - } - - } else { - $row[$field->db_column_name()] = strtoupper(trans('admin/custom_fields/general.encrypted')); - } - } else { - if (($field->format=='URL') && ($asset->{$field->db_column_name()}!='')) { - $row[$field->db_column_name()] = ''.$asset->{$field->db_column_name()}.''; - } else { - $row[$field->db_column_name()] = e($asset->{$field->db_column_name()}); - } - } - - } + $row = $asset->present()->forDataTable($all_custom_fields); if (($request->has('report')) && ($request->get('report')=='true')) { $rows[]= Helper::stripTagsFromJSON($row); diff --git a/app/Http/Controllers/CategoriesController.php b/app/Http/Controllers/CategoriesController.php index f4816250a..dbbc908a4 100755 --- a/app/Http/Controllers/CategoriesController.php +++ b/app/Http/Controllers/CategoriesController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use App\Helpers\Helper; use App\Models\Category as Category; use App\Models\Company; +use App\Models\CustomField; use App\Models\Setting; use Auth; use DB; @@ -238,24 +239,7 @@ class CategoriesController extends Controller $rows = array(); foreach ($categories as $category) { - $actions = Helper::generateDatatableButton('edit', route('categories.edit', $category->id)); - $actions .= Helper::generateDatatableButton( - 'delete', - route('categories.destroy', $category->id), - $category->itemCount() == 0, /* enabled */ - trans('admin/categories/message.delete.confirm'), - $category->name - ); - - $rows[] = array( - 'id' => $category->id, - 'name' => (string)link_to_route('categories.show', $category->name, ['category' => $category->id]) , - 'category_type' => ucwords($category->category_type), - 'count' => $category->itemCount(), - 'acceptance' => ($category->require_acceptance=='1') ? '' : '', - 'eula' => ($category->getEula()) ? '' : '', - 'actions' => $actions - ); + $rows[] = $category->present()->forDataTable(); } $data = array('total' => $catCount, 'rows' => $rows); @@ -282,48 +266,10 @@ class CategoriesController extends Controller $count = $category_assets->count(); $category_assets = $category_assets->skip($offset)->take($limit)->get(); $rows = array(); + $all_custom_fields = CustomField::all(); foreach ($category_assets as $asset) { - $actions = ''; - $inout=''; - - if ($asset->deleted_at=='') { - $actions = '
'; - $actions .= Helper::generateDatatableButton('clone', route('clone/hardware', $asset->id)); - $actions .= Helper::generateDatatableButton('edit', route('hardware.edit', $asset->id)); - $actions .= Helper::generateDatatableButton( - 'delete', - route('hardware.destroy', $asset->id), - true, /* enabled */ - trans('admin/hardware/message.delete.confirm'), - $asset->asset_tag - ); - $actions .= '
'; - } elseif ($asset->deleted_at!='') { - $actions = Helper::generateDatatableButton('restore', route('restore/hardware', $asset->id)); - } - - if ($asset->availableForCheckout()) { - if (Gate::allows('checkout', $asset)) { - $inout = Helper::generateDatatableButton('checkout', route('checkout/hardware', $asset->id)); - } - } else { - if (Gate::allows('checkin', $asset)) { - $inout = Helper::generateDatatableButton('checkin', route('checkin/hardware', $asset->id)); - } - } - - $rows[] = array( - 'id' => $asset->id, - 'name' => (string)link_to_route('hardware.show', $asset->showAssetName(), ['hardware' => $asset->id]), - 'model' => ($asset->model) ? (string)link_to_route('models.show', $asset->model->name, ['model' => $asset->model->id]) : '', - 'asset_tag' => $asset->asset_tag, - 'serial' => $asset->serial, - 'assigned_to' => ($asset->assigneduser) ? (string)link_to_route('users.show', $asset->assigneduser->fullName(), ['user' => $asset->assigneduser->id]): '', - 'change' => $inout, - 'actions' => $actions, - 'companyName' => is_null($asset->company) ? '' : e($asset->company->name) - ); + $rows[] = $asset->present()->forDataTable($all_custom_fields); } $data = array('total' => $count, 'rows' => $rows); @@ -335,7 +281,7 @@ class CategoriesController extends Controller * @param $categoryID * @return array */ - public function getDataViewAccessories($categoryID) + public function getDataViewAccessories(Request $request, $categoryID) { $category = Category::with('accessories.company')->find($categoryID); @@ -358,27 +304,7 @@ class CategoriesController extends Controller $rows = array(); foreach ($category_accessories as $accessory) { - - $actions = ''; - - if ($accessory->deleted_at=='') { - $actions = '
'; - $actions .= Helper::generateDatatableButton('edit', route('accessories.update', $accessory->id)); - $actions .= Helper::generateDatatableButton('delete', - route('accessories.destroy', $accessory->id), - true, /* enabled */ - trans('admin/accessories/message.delete.confirm'), - $accessory->name - ); - $actions .= '
'; - } - - $rows[] = array( - 'id' => $asset->id, - 'name' => (string)link_to_route('view/accessory', $asset->name, [$asset->id]), - 'actions' => $actions, - 'companyName' => Company::getName($asset), - ); + $rows[] = $accessory->present()->forDataTable(); } $data = array('total' => $count, 'rows' => $rows); @@ -413,34 +339,14 @@ class CategoriesController extends Controller $rows = array(); foreach ($category_consumables as $consumable) { - - $actions = ''; - - if ($consumable->deleted_at=='') { - $actions = '
'; - $actions .= Helper::generateDatatableButton('edit', route('consumables.update', $consumable->id)); - $actions .= Helper::generateDatatableButton('delete', - route('consumables.destroy', $consumable->id), - true, /* enabled */ - trans('admin/consumables/message.delete.confirm'), - $consumable->name - ); - $actions .= '
'; - } - - $rows[] = array( - 'id' => $consumable->id, - 'name' => (string) link_to_route('consumables.show', $consumable->name, [$consumable->id]), - 'actions' => $actions, - 'companyName' => Company::getName($consumable), - ); + $rows[] = $consumable->present()->forDataTable(); } $data = array('total' => $count, 'rows' => $rows); return $data; } - public function getDataViewComponent($categoryID) + public function getDataViewComponent(Request $request, $categoryID) { $category = Category::with('accessories.company')->find($categoryID); @@ -462,27 +368,7 @@ class CategoriesController extends Controller $rows = array(); foreach ($category_components as $component) { - - $actions = ''; - - if ($component->deleted_at=='') { - $actions = '
'; - $actions .= Helper::generateDatatableButton('edit', route('components.edit', $component->id)); - $actions .= Helper::generateDatatableButton('delete', - route('components.destroy', $component->id), - true, /* enabled */ - trans('admin/components/message.delete.confirm'), - $component->name - ); - $actions .= '
'; - } - - $rows[] = array( - 'id' => $component->id, - 'name' => (string)link_to_route('view/accessory', $component->name, [$component->id]), - 'actions' => $actions, - 'companyName' => Company::getName($component), - ); + $rows[] = $component->present()->forDataTable(); } $data = array('total' => $count, 'rows' => $rows); diff --git a/app/Http/Controllers/ComponentsController.php b/app/Http/Controllers/ComponentsController.php index d520a54a2..b394996f1 100644 --- a/app/Http/Controllers/ComponentsController.php +++ b/app/Http/Controllers/ComponentsController.php @@ -5,6 +5,7 @@ use App\Helpers\Helper; use App\Models\Actionlog; use App\Models\Company; use App\Models\Component; +use App\Models\CustomField; use App\Models\Setting; use App\Models\User; use App\Models\Asset; @@ -338,8 +339,8 @@ class ComponentsController extends Controller 'title' => 'Checked Out:', 'value' => class_basename(strtoupper($logaction->item_type)) .' <'.route('components.show', ['component' => $component->id]).'|'.$component->name - .'> checked out to <'.route('hardware.show', $asset->id).'|'.$asset->showAssetName() - .'> by <'.route('users.show', $admin_user->id).'|'.$admin_user->fullName().'>.' + .'> checked out to <'.route('hardware.show', $asset->id).'|'.$asset->present()->name() + .'> by <'.route('users.show', $admin_user->id).'|'.$admin_user->present()->fullName().'>.' ], [ 'title' => 'Note:', @@ -404,44 +405,7 @@ class ComponentsController extends Controller $rows = array(); foreach ($components as $component) { - $actions = ''; - if (Gate::allows('checkout', $component)) { - $actions .= Helper::generateDatatableButton('checkout', route('checkout/component', $component->id), $component->numRemaining() > 0); - } - - if (Gate::allows('update', $component)) { - $actions .= Helper::generateDatatableButton('edit', route('components.edit', $component->id)); - } - - if (Gate::allows('delete', $component)) { - $actions .= Helper::generateDatatableButton( - 'delete', - route('components.destroy', $component->id), - true, /* enabled */ - trans('admin/components/message.delete.confirm'), - $component->name - ); - } - - $actions .=''; - $company = $component->company; - - $rows[] = array( - 'checkbox' =>'
', - 'id' => $component->id, - 'name' => (string)link_to_route('components.show', e($component->name), ['component' => $component->id]), - 'serial_number' => $component->serial, - 'location' => ($component->location) ? e($component->location->name) : '', - 'qty' => number_format($component->qty), - 'min_amt' => e($component->min_amt), - 'category' => ($component->category) ? e($component->category->name) : 'Missing category', - 'order_number' => e($component->order_number), - 'purchase_date' => e($component->purchase_date), - 'purchase_cost' => Helper::formatCurrencyOutput($component->purchase_cost), - 'numRemaining' => $component->numRemaining(), - 'actions' => $actions, - 'companyName' => is_null($company) ? '' : e($company->name), - ); + $rows[] = $component->present()->forDataTable(); } $data = array('total' => $componentsCount, 'rows' => $rows); @@ -472,13 +436,9 @@ class ComponentsController extends Controller $this->authorize('view', $component); $rows = array(); - + $all_custom_fields = CustomField::all(); // Cached for table; foreach ($component->assets as $component_assignment) { - $rows[] = array( - 'name' => (string)link_to_route('hardware.show', e($component_assignment->showAssetName()), ['hardware' => $component_assignment->id]), - 'qty' => e($component_assignment->pivot->assigned_qty), - 'created_at' => ($component_assignment->created_at->format('Y-m-d H:i:s')=='-0001-11-30 00:00:00') ? '' : $component_assignment->created_at->format('Y-m-d H:i:s'), - ); + $rows[] = $component_assignment->present()->forDataTable($all_custom_fields); } $componentCount = $component->assets->count(); diff --git a/app/Http/Controllers/ConsumablesController.php b/app/Http/Controllers/ConsumablesController.php index 40a03cd79..2df57c8a9 100644 --- a/app/Http/Controllers/ConsumablesController.php +++ b/app/Http/Controllers/ConsumablesController.php @@ -401,44 +401,7 @@ class ConsumablesController extends Controller $rows = array(); foreach ($consumables as $consumable) { - $actions = ''; - if (Gate::allows('checkout', $consumable)) { - $actions .= Helper::generateDatatableButton('checkout', route('checkout/consumable', $consumable->id), $consumable->numRemaining() > 0); - } - - if (Gate::allows('update', $consumable)) { - $actions .= Helper::generateDatatableButton('edit', route('consumables.edit', $consumable->id)); - } - if (Gate::allows('delete', $consumable)) { - $actions .= Helper::generateDatatableButton( - 'delete', - route('consumables.destroy', $consumable->id), - true, /* enabled */ - trans('admin/consumables/message.delete.confirm'), - $consumable->name - ); - } - $actions .=''; - - $company = $consumable->company; - - $rows[] = array( - 'id' => $consumable->id, - 'name' => (string)link_to_route('consumables.show', e($consumable->name), ['consumable' => $consumable->id]), - 'location' => ($consumable->location) ? e($consumable->location->name) : '', - 'min_amt' => e($consumable->min_amt), - 'qty' => e($consumable->qty), - 'manufacturer' => ($consumable->manufacturer) ? (string) link_to_route('manufacturers.show', $consumable->manufacturer->name, ['manufacturer' => $consumable->manufacturer_id]): '', - 'model_number' => e($consumable->model_number), - 'item_no' => e($consumable->item_no), - 'category' => ($consumable->category) ? (string) link_to_route('categories.show', $consumable->category->name, ['category' => $consumable->category_id]) : 'Missing category', - 'order_number' => e($consumable->order_number), - 'purchase_date' => e($consumable->purchase_date), - 'purchase_cost' => Helper::formatCurrencyOutput($consumable->purchase_cost), - 'numRemaining' => $consumable->numRemaining(), - 'actions' => $actions, - 'companyName' => is_null($company) ? '' : e($company->name), - ); + $rows[] = $consumable->present()->forDataTable(); } $data = array('total' => $consumCount, 'rows' => $rows); @@ -478,11 +441,11 @@ class ConsumablesController extends Controller $rows = array(); foreach ($consumable->consumableAssigments as $consumable_assignment) { - $rows[] = array( - 'name' => (string)link_to_route('users.show', e($consumable_assignment->user->fullName()), ['user' => $consumable_assignment->user->id]), - 'created_at' => ($consumable_assignment->created_at->format('Y-m-d H:i:s')=='-0001-11-30 00:00:00') ? '' : $consumable_assignment->created_at->format('Y-m-d H:i:s'), - 'admin' => ($consumable_assignment->admin) ? e($consumable_assignment->admin->fullName()) : '', - ); + $rows[] = [ + 'name' => $consumable_assignment->user->present()->nameUrl(), + 'created_at' => ($consumable_assignment->created_at->format('Y-m-d H:i:s')=='-0001-11-30 00:00:00') ? '' : $consumable_assignment->created_at->format('Y-m-d H:i:s'), + 'admin' => ($consumable_assignment->admin) ? $consumable_assignment->admin->present()->nameUrl() : '', + ]; } $consumableCount = $consumable->users->count(); diff --git a/app/Http/Controllers/DepreciationsController.php b/app/Http/Controllers/DepreciationsController.php index a17d1a89d..d3bad01fb 100755 --- a/app/Http/Controllers/DepreciationsController.php +++ b/app/Http/Controllers/DepreciationsController.php @@ -189,21 +189,7 @@ class DepreciationsController extends Controller $rows = array(); foreach ($depreciations as $depreciation) { - $actions = Helper::generateDatatableButton('edit', route('depreciations.edit', $depreciation->id)); - $actions .= Helper::generateDatatableButton( - 'delete', - route('depreciations.destroy', $depreciation->id), - true, /*enabled*/ - trans('admin/depreciations/message.delete.confirm'), - $depreciation->name - ); - - $rows[] = array( - 'id' => $depreciation->id, - 'name' => e($depreciation->name), - 'months' => e($depreciation->months), - 'actions' => $actions - ); + $rows[] = $depreciation->present()->forDataTable(); } $data = array('total' => $depreciationsCount, 'rows' => $rows); diff --git a/app/Http/Controllers/LicensesController.php b/app/Http/Controllers/LicensesController.php index ad0e9c8ce..c38704aad 100755 --- a/app/Http/Controllers/LicensesController.php +++ b/app/Http/Controllers/LicensesController.php @@ -520,12 +520,12 @@ class LicensesController extends Controller // Update the asset data if ($request->input('assigned_to') == '') { $slack_msg = 'License <'.route('licenses.show', $license->id).'|'.$license->name - .'> checked out to <'.route('hardware.show',$asset->id) .'|'.$asset->showAssetName() - .'> by <'.route('users.show', $user->id).'|'.$user->fullName().'>.'; + .'> checked out to <'.route('hardware.show',$asset->id) .'|'.$asset->present()->name() + .'> by <'.route('users.show', $user->id).'|'.$user->present()->fullName().'>.'; } else { $slack_msg = 'License <'.route('licenses.show', $license->id).'|'.$license->name - .'> checked out to <'.route('users.show', $user->id).'|'.$is_assigned_to->fullName() - .'> by <'.route('users.show', $user->id) .'|'.$user->fullName().'>.'; + .'> checked out to <'.route('users.show', $user->id).'|'.$is_assigned_to->present()->fullName() + .'> by <'.route('users.show', $user->id) .'|'.$user->present()->fullName().'>.'; } if ($settings->slack_endpoint) { @@ -665,7 +665,7 @@ class LicensesController extends Controller [ 'title' => 'Checked In:', 'value' => 'License: <'.route('licenses.show', $license->id).'|'.$license->name - .'> checked in by <'.route('users.show', $user->id).'|'.$user->fullName().'>.' + .'> checked in by <'.route('users.show', $user->id).'|'.$user->present()->fullName().'>.' ], [ 'title' => 'Note:', @@ -894,51 +894,7 @@ class LicensesController extends Controller $rows = array(); foreach ($licenses as $license) { - $actions = ''; - - if (Gate::allows('checkout', License::class)) { - $actions .= Helper::generateDatatableButton( - 'checkout', - route('licenses.freecheckout', $license->id), - $license->remaincount() > 0 - ); - } - - if (Gate::allows('create', $license)) { - $actions .= Helper::generateDatatableButton('clone', route('clone/license', $license->id)); - } - if (Gate::allows('update', $license)) { - $actions .= Helper::generateDatatableButton('edit', route('licenses.edit', $license->id)); - } - if (Gate::allows('delete', $license)) { - $actions .= Helper::generateDatatableButton( - 'delete', - route('licenses.destroy', $license->id), - true, /*enabled*/ - trans('admin/licenses/message.delete.confirm'), - $license->name - ); - } - $actions .=''; - - $rows[] = array( - 'id' => $license->id, - 'name' => (string) link_to('/licenses/'.$license->id, $license->name), - 'serial' => (string) link_to('/licenses/'.$license->id, mb_strimwidth($license->serial, 0, 50, "...")), - 'totalSeats' => $license->licenseSeatsCount, - 'remaining' => $license->remaincount(), - 'license_name' => e($license->license_name), - 'license_email' => e($license->license_email), - 'purchase_date' => ($license->purchase_date) ? $license->purchase_date : '', - 'expiration_date' => ($license->expiration_date) ? $license->expiration_date : '', - 'purchase_cost' => Helper::formatCurrencyOutput($license->purchase_cost), - 'purchase_order' => ($license->purchase_order) ? e($license->purchase_order) : '', - 'order_number' => ($license->order_number) ? e($license->order_number) : '', - 'notes' => ($license->notes) ? e($license->notes) : '', - 'actions' => $actions, - 'company' => is_null($license->company) ? '' : e($license->company->name), - 'manufacturer' => $license->manufacturer ? (string) link_to('settings/manufacturers/'.$license->manufacturer_id.'/view', $license->manufacturer->name) : '' - ); + $rows[] = $license->present()->forDataTable(); } $data = array('total' => $licenseCount, 'rows' => $rows); diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index 231041840..194a12b25 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -310,32 +310,7 @@ class LocationsController extends Controller $rows = array(); foreach ($locations as $location) { - $actions = ''; - $actions .= Helper::generateDatatableButton('edit', route('locations.edit', $location->id)); - $actions .= Helper::generateDatatableButton( - 'delete', - route('locations.destroy', $location->id), - true, /*enabled*/ - trans('admin/locations/message.delete.confirm'), - $location->name - ); - $actions .= ''; - - $rows[] = array( - 'id' => $location->id, - 'name' => (string)link_to_route('locations.show', e($location->name), ['location' => $location->id]), - 'parent' => ($location->parent) ? e($location->parent->name) : '', - // 'assets' => ($location->assets->count() + $location->assignedassets->count()), - 'assets_default' => $location->assignedassets->count(), - 'assets_checkedout' => $location->assets->count(), - 'address' => ($location->address) ? e($location->address): '', - 'city' => e($location->city), - 'state' => e($location->state), - 'zip' => e($location->zip), - 'country' => e($location->country), - 'currency' => e($location->currency), - 'actions' => $actions - ); + $rows[] = $location->present()->forDataTable(); } $data = array('total' => $locationsCount, 'rows' => $rows); @@ -369,7 +344,7 @@ class LocationsController extends Controller foreach ($users as $user) { $rows[] = array( - 'name' => (string)link_to_route('users.show', e($user->fullName()), ['user'=>$user->id]) + 'name' => (string)link_to_route('users.show', e($user->present()->fullName()), ['user'=>$user->id]) ); } @@ -406,7 +381,7 @@ class LocationsController extends Controller foreach ($assets as $asset) { $rows[] = [ - 'name' => (string)link_to_route('hardware.show', e($asset->showAssetName()), ['hardware' => $asset->id]), + 'name' => (string)link_to_route('hardware.show', e($asset->present()->name()), ['hardware' => $asset->id]), 'asset_tag' => e($asset->asset_tag), 'serial' => e($asset->serial), 'model' => e($asset->model->name), diff --git a/app/Http/Controllers/ManufacturersController.php b/app/Http/Controllers/ManufacturersController.php index 61a513737..f2afea9b1 100755 --- a/app/Http/Controllers/ManufacturersController.php +++ b/app/Http/Controllers/ManufacturersController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; use App\Helpers\Helper; +use App\Models\CustomField; use App\Models\Manufacturer; use Auth; use Exception; @@ -202,26 +203,7 @@ class ManufacturersController extends Controller $rows = array(); foreach ($manufacturers as $manufacturer) { - $actions = ''; - $actions .= Helper::generateDatatableButton('edit', route('manufacturers.edit', $manufacturer->id)); - $actions .= Helper::generateDatatableButton( - 'delete', - route('manufacturers.destroy'), - true, /*enabled*/ - trans('admin/manufacturers/message.delete.confirm'), - $manufacturer->name - ); - $actions .= ''; - - $rows[] = array( - 'id' => $manufacturer->id, - 'name' => (string)link_to_route('manufacturers.show', e($manufacturer->name),['manufacturer' => $manufacturer->id]), - 'assets' => $manufacturer->assets()->count(), - 'licenses' => $manufacturer->licenses()->count(), - 'accessories' => $manufacturer->accessories()->count(), - 'consumables' => $manufacturer->consumables()->count(), - 'actions' => $actions - ); + $rows[] = $manufacturer->present()->forDataTable(); } $data = array('total' => $manufacturersCount, 'rows' => $rows); @@ -281,47 +263,9 @@ class ManufacturersController extends Controller $count = $manufacturer_assets->count(); $manufacturer_assets = $manufacturer_assets->skip($offset)->take($limit)->get(); $rows = array(); - + $all_custom_fields = CustomField::all(); // cached; foreach ($manufacturer_assets as $asset) { - $actions = '
'; - if ($asset->deleted_at=='') { - $actions .= Helper::generateDatatableButton('clone', route('clone/hardware', $asset->id)); - $actions .= Helper::generateDatatableButton('edit', route('hardware.edit', $asset->id)); - $actions .= Helper::generateDatatableButton( - 'delete', - route('hardware.destroy', $asset->id), - true, /*enabled*/ - trans('admin/hardware/message.delete.confirm'), - $asset->asset_tag - ); - } elseif ($asset->deleted_at!='') { - $actions .= Helper::generateDatatableButton('restore', route('restore/hardware', $asset->id)); - } - $actions .= '
'; - if ($asset->availableForCheckout()) { - if (Gate::allows('checkout', $asset)) { - $inout = Helper::generateDatatableButton('checkout', route('checkout/hardware', $asset->id)); - } - } else { - if (Gate::allows('checkin', $asset)) { - $inout = Helper::generateDatatableButton('checkin', route('checkin/hardware', $asset->id)); - } - } - - $rows[] = array( - 'id' => $asset->id, - 'name' => (string)link_to_route('hardware.show', e($asset->showAssetName()), [$asset->id]), - 'model' => e($asset->model->name), - 'asset_tag' => e($asset->asset_tag), - 'serial' => e($asset->serial), - 'assigned_to' => ($asset->assigneduser) ? (string)link_to_route('users.show', e($asset->assigneduser->fullName()), [$asset->assigneduser->id]): '', - 'actions' => $actions, - 'companyName' => is_null($asset->company) ? '' : $asset->company->name - ); - - if (isset($inout)) { - $row['change'] = $inout; - } + $rows[] = $asset->present()->forDataTable($all_custom_fields); } $data = array('total' => $count, 'rows' => $rows); @@ -342,51 +286,7 @@ class ManufacturersController extends Controller $rows = array(); foreach ($licenses as $license) { - $actions = ''; - - if (Gate::allows('checkout', \App\Models\License::class)) { - $actions .= Helper::generateDatatableButton( - 'checkout', - route('licenses.freecheckout', $license->id), - $license->remaincount() > 0 - ); - } - - if (Gate::allows('create', $license)) { - $actions .= Helper::generateDatatableButton('clone', route('clone/license', $license->id)); - } - if (Gate::allows('update', $license)) { - $actions .= Helper::generateDatatableButton('edit', route('licenses.edit', $license->id)); - } - if (Gate::allows('delete', $license)) { - $actions .= Helper::generateDatatableButton( - 'delete', - route('licenses.destroy', $license->id), - true, /*enabled*/ - trans('admin/licenses/message.delete.confirm'), - $license->name - ); - } - $actions .=''; - - $rows[] = array( - 'id' => $license->id, - 'name' => (string) link_to_route('licenses.show', $license->name, [$license->id]), - 'serial' => (string) link_to_route('licenses.show', mb_strimwidth($license->serial, 0, 50, "..."), [$license->id]), - 'totalSeats' => $license->licenseSeatCount, - 'remaining' => $license->remaincount(), - 'license_name' => e($license->license_name), - 'license_email' => e($license->license_email), - 'purchase_date' => ($license->purchase_date) ? $license->purchase_date : '', - 'expiration_date' => ($license->expiration_date) ? $license->expiration_date : '', - 'purchase_cost' => ($license->purchase_cost) ? number_format($license->purchase_cost, 2) : '', - 'purchase_order' => ($license->purchase_order) ? e($license->purchase_order) : '', - 'order_number' => ($license->order_number) ? e($license->order_number) : '', - 'notes' => ($license->notes) ? e($license->notes) : '', - 'actions' => $actions, - 'companyName' => is_null($license->company) ? '' : e($license->company->name), - 'manufacturer' => $license->manufacturer ? (string) link_to_route('manufacturers.show', $license->manufacturer->name, [$license->manufacturer_id]) : '' - ); + $rows[] = $license->present()->forDataTable(); } $data = array('total' => $licenseCount, 'rows' => $rows); @@ -417,45 +317,7 @@ class ManufacturersController extends Controller $rows = array(); foreach ($accessories as $accessory) { - - $actions = ''; - if (Gate::allows('checkout', $accessory)) { - $actions .= Helper::generateDatatableButton( - 'checkout', - route('checkout/accessory', $accessory->id), - $accessory->numRemaining() > 0 - ); - } - if (Gate::allows('update', $accessory)) { - $actions .= Helper::generateDatatableButton('edit', route('accessories.update', $accessory->id)); - } - if (Gate::allows('delete', $accessory)) { - $actions .= Helper::generateDatatableButton( - 'delete', - route('accessories.destroy', $accessory->id), - $enabled = true, - trans('admin/accessories/message.delete.confirm'), - $accessory->name - ); - } - $actions .= ''; - $company = $accessory->company; - - $rows[] = array( - 'name' => (string)link_to_route('accessories.show', $accessory->name, [$accessory->id]), - 'category' => ($accessory->category) ? (string)link_to_route('categories.show', $accessory->category->name, [$accessory->category->id]) : '', - 'qty' => e($accessory->qty), - 'order_number' => e($accessory->order_number), - 'min_amt' => e($accessory->min_amt), - 'location' => ($accessory->location) ? e($accessory->location->name): '', - 'purchase_date' => e($accessory->purchase_date), - 'purchase_cost' => number_format($accessory->purchase_cost, 2), - 'numRemaining' => $accessory->numRemaining(), - 'actions' => $actions, - 'companyName' => is_null($company) ? '' : e($company->name), - 'manufacturer' => $accessory->manufacturer ? (string) link_to_route('manufacturers.show', $accessory->manufacturer->name, [$accessory->manufacturer_id]) : '' - - ); + $rows[] = $accessory->present()->forDataTable(); } $data = array('total'=>$accessCount, 'rows'=>$rows); @@ -487,45 +349,7 @@ class ManufacturersController extends Controller $rows = array(); foreach ($consumables as $consumable) { - $actions = ''; - if (Gate::allows('checkout', $consumable)) { - $actions .= Helper::generateDatatableButton('checkout', route('checkout/consumable', $consumable->id), $consumable->numRemaining() > 0); - } - - if (Gate::allows('update', $consumable)) { - $actions .= Helper::generateDatatableButton('edit', route('consumables.edit', $consumable->id)); - } - if (Gate::allows('delete', $consumable)) { - $actions .= Helper::generateDatatableButton( - 'delete', - route('consumables.destroy', $consumable->id), - true, /* enabled */ - trans('admin/consumables/message.delete.confirm'), - $consumable->name - ); - } - - $actions .=''; - - $company = $consumable->company; - - $rows[] = array( - 'id' => $consumable->id, - 'name' => (string)link_to_route('consumables.show', e($consumable->name), [$consumable->id]), - 'location' => ($consumable->location) ? e($consumable->location->name) : '', - 'min_amt' => e($consumable->min_amt), - 'qty' => e($consumable->qty), - 'manufacturer' => ($consumable->manufacturer) ? (string) link_to_route('manufacturers.show', $consumable->manufacturer->name, [$consumable->manufacturer_id]): '', - 'model_number' => e($consumable->model_number), - 'item_no' => e($consumable->item_no), - 'category' => ($consumable->category) ? (string) link_to_route('categories.show', $consumable->category->name, [$consumable->category_id]) : 'Missing category', - 'order_number' => e($consumable->order_number), - 'purchase_date' => e($consumable->purchase_date), - 'purchase_cost' => ($consumable->purchase_cost!='') ? number_format($consumable->purchase_cost, 2): '' , - 'numRemaining' => $consumable->numRemaining(), - 'actions' => $actions, - 'companyName' => is_null($company) ? '' : e($company->name), - ); + $rows[] = $consumable->present()->forDataTable(); } $data = array('total' => $consumCount, 'rows' => $rows); diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 572cb5a85..55d1a7702 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -160,7 +160,7 @@ class ReportsController extends Controller ($asset->purchase_cost > 0) ? Helper::formatCurrencyOutput($asset->purchase_cost) : '', ($asset->order_number) ? e($asset->order_number) : '', ($asset->supplier) ? e($asset->supplier->name) : '', - ($asset->assigneduser) ? e($asset->assigneduser->fullName()) : '', + ($asset->assigneduser) ? e($asset->assigneduser->present()->fullName()) : '', ($asset->last_checkout!='') ? e($asset->last_checkout) : '', ($asset->assigneduser && $asset->assigneduser->userloc!='') ? e($asset->assigneduser->userloc->name) : ( ($asset->defaultLoc!='') ? e($asset->defaultLoc->name) : ''), @@ -246,7 +246,7 @@ class ReportsController extends Controller if ($asset->assigned_to > 0) { $user = User::find($asset->assigned_to); - $row[] = e($user->fullName()); + $row[] = e($user->present()->fullName()); } else { $row[] = ''; // Empty string if unassigned } @@ -339,7 +339,7 @@ class ReportsController extends Controller foreach ($activitylogs as $activity) { if (($activity->item) && ($activity->itemType()=="asset")) { - $activity_item = ''.e($activity->item->asset_tag).' - '. e($activity->item->showAssetName()).''; + $activity_item = ''.e($activity->item->asset_tag).' - '. e($activity->item->present()->name()).''; $item_type = 'asset'; } elseif ($activity->item) { $activity_item = '' . e($activity->item->name) . ''; @@ -351,25 +351,25 @@ class ReportsController extends Controller if (($activity->user) && ($activity->action_type=="uploaded") && ($activity->itemType()=="user")) { - $activity_target = ''.$activity->user->fullName().''; + $activity_target = ''.$activity->user->present()->fullName().''; } elseif ($activity->target_type === "App\Models\Asset") { if($activity->target) { - $activity_target = ''.$activity->target->showAssetName().''; + $activity_target = ''.$activity->target->present()->name().''; } else { $activity_target = ""; } } elseif ( $activity->target_type === "App\Models\User") { if($activity->target) { - $activity_target = ''.$activity->target->fullName().''; + $activity_target = ''.$activity->target->present()->fullName().''; } else { $activity_target = ''; } } elseif (($activity->action_type=='accepted') || ($activity->action_type=='declined')) { - $activity_target = '' . e($activity->item->assigneduser->fullName()) . ''; + $activity_target = '' . e($activity->item->assigneduser->present()->fullName()) . ''; } elseif ($activity->action_type=='requested') { if ($activity->user) { - $activity_target = ''.$activity->user->fullName().''; + $activity_target = ''.$activity->user->present()->fullName().''; } else { $activity_target = ''; } @@ -386,7 +386,7 @@ class ReportsController extends Controller 'icon' => '', 'created_at' => date("M d, Y g:iA", strtotime($activity->created_at)), 'action_type' => strtolower(trans('general.'.str_replace(' ','_',$activity->action_type))), - 'admin' => $activity->user ? (string) link_to_route('users.show', $activity->user->fullName(), [$activity->user_id]) : '', + 'admin' => $activity->user ? (string) link_to_route('users.show', $activity->user->present()->fullName(), [$activity->user_id]) : '', 'target' => $activity_target, 'item' => $activity_item, 'item_type' => $item_type, @@ -613,7 +613,7 @@ class ReportsController extends Controller $row[] = '"' . Helper::formatCurrencyOutput($asset->purchase_cost) . '"'; } if (e(Input::get('eol')) == '1') { - $row[] = '"' .($asset->eol_date()) ? $asset->eol_date() : ''. '"'; + $row[] = '"' .($asset->present()->eol_date()) ? $asset->present()->eol_date() : ''. '"'; } if (e(Input::get('order')) == '1') { if ($asset->order_number) { @@ -652,7 +652,7 @@ class ReportsController extends Controller if (e(Input::get('assigned_to')) == '1') { if ($asset->assigneduser) { - $row[] = '"' .e($asset->assigneduser->fullName()). '"'; + $row[] = '"' .e($asset->assigneduser->present()->fullName()). '"'; } else { $row[] = ''; // Empty string if unassigned } @@ -688,7 +688,7 @@ class ReportsController extends Controller if (e(Input::get('warranty')) == '1') { if ($asset->warranty_months) { $row[] = $asset->warranty_months; - $row[] = $asset->warrantee_expires(); + $row[] = $asset->present()->warrantee_expires(); } else { $row[] = ''; $row[] = ''; @@ -857,9 +857,9 @@ class ReportsController extends Controller $row = [ ]; $row[] = str_replace(',', '', e($assetItem->assetlog->model->category->name)); $row[] = str_replace(',', '', e($assetItem->assetlog->model->name)); - $row[] = str_replace(',', '', e($assetItem->assetlog->showAssetName())); + $row[] = str_replace(',', '', e($assetItem->assetlog->present()->name())); $row[] = str_replace(',', '', e($assetItem->assetlog->asset_tag)); - $row[] = str_replace(',', '', e($assetItem->assetlog->assigneduser->fullName())); + $row[] = str_replace(',', '', e($assetItem->assetlog->assigneduser->present()->fullName())); $rows[] = implode($row, ','); } diff --git a/app/Http/Controllers/StatuslabelsController.php b/app/Http/Controllers/StatuslabelsController.php index e9ecc2d8c..1f557bdf1 100755 --- a/app/Http/Controllers/StatuslabelsController.php +++ b/app/Http/Controllers/StatuslabelsController.php @@ -281,7 +281,7 @@ class StatuslabelsController extends Controller $actions .= Helper::generateDatatableButton('edit', route('statuslabels.edit', $statuslabel->id)); $actions .= Helper::generateDatatableButton( 'delete', - route('statuslabels.destroy'), + route('statuslabels.destroy', $statuslabel->id), true, /*enabled*/ trans('admin/statuslabels/message.delete.confirm'), $statuslabel->name diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index 65da6528c..6b94c290d 100755 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -333,7 +333,7 @@ class UsersController extends Controller // Update the user $user->first_name = $request->input('first_name'); $user->last_name = $request->input('last_name'); - $user->two_factor_optin = $request->input('two_factor_optin'); + $user->two_factor_optin = $request->input('two_factor_optin') ?: 0; $user->locale = $request->input('locale'); $user->employee_num = $request->input('employee_num'); $user->activated = $request->input('activated', $user->activated); @@ -828,8 +828,23 @@ class UsersController extends Controller $sort = e(Input::get('sort')); } - $users = User::select(array('users.id','users.employee_num','users.two_factor_enrolled','users.jobtitle','users.email','users.username','users.location_id','users.manager_id','users.first_name','users.last_name','users.created_at','users.notes','users.company_id', 'users.deleted_at','users.activated')) - ->with('assets', 'accessories', 'consumables', 'licenses', 'manager', 'groups', 'userloc', 'company','throttle'); + $users = User::select([ + 'users.id', + 'users.employee_num', + 'users.two_factor_enrolled', + 'users.jobtitle', + 'users.email', + 'users.username', + 'users.location_id', + 'users.manager_id', + 'users.first_name', + 'users.last_name', + 'users.created_at', + 'users.notes', + 'users.company_id', + 'users.deleted_at', + 'users.activated' + ])->with('manager', 'groups', 'userloc', 'company','throttle'); $users = Company::scopeCompanyables($users); switch ($status) { @@ -869,70 +884,7 @@ class UsersController extends Controller $rows = array(); foreach ($users as $user) { - $group_names = ''; - $actions = ''; - - foreach ($user->groups as $group) { - $group_names .= '' . $group->name . ' '; - } - if (!is_null($user->deleted_at)) { - if (Gate::allows('delete', $user)) { - $actions .= Helper::generateDatatableButton('restore', route('restore/user', $user->id)); - } - } else { - if (Gate::allows('delete', $user)) { - if ($user->accountStatus() == 'suspended') { - $actions .= ' '; - } - } - if (Gate::allows('update', $user)) { - $actions .= Helper::generateDatatableButton('edit', route('users.edit', $user->id)); - $actions .= Helper::generateDatatableButton('clone', route('clone/user', $user->id)); - } - if (Gate::allows('delete', $user)) { - if ((Auth::user()->id !== $user->id) && (!config('app.lock_passwords'))) { - $actions .= Helper::generateDatatableButton( - 'delete', - route('users.destroy', $user->id), - true, /*enabled*/ - "Are you sure you wish to delete this user?", - $user->first_name - ); - } else { - $actions .= ' '; - } - } - } - - $actions .= ''; - - $rows[] = array( - 'id' => $user->id, - 'checkbox' => ($status!='deleted') ? '' : '', - 'name' => (string)link_to_route('users.show', e($user->fullName()), ['user' => $user->id]), - 'jobtitle' => e($user->jobtitle), - 'email' => ($user->email!='') ? - '' - .'' - .'' : '', - 'username' => e($user->username), - 'location' => ($user->userloc) ? e($user->userloc->name) : '', - 'manager' => ($user->manager) ? '' . e($user->manager->fullName()) . '' : '', - 'assets' => $user->assets->count(), - 'employee_num' => e($user->employee_num), - 'licenses' => $user->licenses->count(), - 'accessories' => $user->accessories->count(), - 'consumables' => $user->consumables->count(), - 'groups' => $group_names, - 'notes' => e($user->notes), - 'two_factor_enrolled' => ($user->two_factor_enrolled=='1') ? '' : '', - 'two_factor_optin' => (($user->two_factor_optin=='1') || (Setting::getSettings()->two_factor_enabled=='2') ) ? '' : '', - 'created_at' => ($user->created_at!='') ? e($user->created_at->format('F j, Y h:iA')) : '', - 'activated' => ($user->activated=='1') ? '' : '', - 'actions' => ($actions) ? $actions : '', - 'companyName' => is_null($user->company) ? '' : e($user->company->name) - ); + $rows[] = $user->present()->forDataTable(); } $data = array('total'=>$userCount, 'rows'=>$rows); @@ -1246,10 +1198,10 @@ class UsersController extends Controller ($user->company) ? $user->company->name : '', $user->jobtitle, $user->employee_num, - $user->fullName(), + $user->present()->fullName(), $user->username, $user->email, - ($user->manager) ? $user->manager->fullName() : '', + ($user->manager) ? $user->manager->present()->fullName() : '', ($user->userloc) ? $user->userloc->name : '', $user->assets->count(), $user->licenses->count(), diff --git a/app/Http/Controllers/ViewAssetsController.php b/app/Http/Controllers/ViewAssetsController.php index 680efacbf..76e13ce63 100755 --- a/app/Http/Controllers/ViewAssetsController.php +++ b/app/Http/Controllers/ViewAssetsController.php @@ -103,16 +103,16 @@ class ViewAssetsController extends Controller $logaction->target_id = $data['user_id'] = Auth::user()->id; $logaction->target_type = User::class; - $data['requested_by'] = $user->fullName(); + $data['requested_by'] = $user->present()->fullName(); $data['item_name'] = $item->name; $data['item_type'] = $itemType; if ($fullItemType == Asset::class) { $data['item_url'] = route('hardware.show', $item->id); - $slackMessage = ' Asset <'.url('/').'/hardware/'.$item->id.'/view'.'|'.$item->showAssetName().'> requested by <'.url('/').'/users/'.$item->user_id.'/view'.'|'.$user->fullName().'>.'; + $slackMessage = ' Asset <'.url('/').'/hardware/'.$item->id.'/view'.'|'.$item->present()->name().'> requested by <'.url('/').'/users/'.$item->user_id.'/view'.'|'.$user->present()->fullName().'>.'; } else { $data['item_url'] = route("view/${itemType}", $item->id); - $slackMessage = $quantity. ' ' . class_basename(strtoupper($logaction->item_type)).' <'.$data['item_url'].'|'.$item->name.'> requested by <'.url('/').'/user/'.$item->id.'/view'.'|'.$user->fullName().'>.'; + $slackMessage = $quantity. ' ' . class_basename(strtoupper($logaction->item_type)).' <'.$data['item_url'].'|'.$item->name.'> requested by <'.url('/').'/user/'.$item->id.'/view'.'|'.$user->present()->fullName().'>.'; } $settings = Setting::getSettings(); @@ -226,8 +226,8 @@ class ViewAssetsController extends Controller $logaction->target_type = User::class; $log = $logaction->logaction('requested'); - $data['requested_by'] = $user->fullName(); - $data['asset_name'] = $asset->showAssetName(); + $data['requested_by'] = $user->present()->fullName(); + $data['asset_name'] = $asset->present()->name(); $settings = Setting::getSettings(); @@ -259,7 +259,7 @@ class ViewAssetsController extends Controller 'fields' => [ [ 'title' => 'REQUESTED:', - 'value' => class_basename(strtoupper($logaction->item_type)).' asset <'.url('/').'/hardware/'.$asset->id.'/view'.'|'.$asset->showAssetName().'> requested by <'.url('/').'/hardware/'.$asset->id.'/view'.'|'.Auth::user()->fullName().'>.' + 'value' => class_basename(strtoupper($logaction->item_type)).' asset <'.url('/').'/hardware/'.$asset->id.'/view'.'|'.$asset->present()->name().'> requested by <'.url('/').'/hardware/'.$asset->id.'/view'.'|'.Auth::user()->present()->fullName().'>.' ] ] diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php index 6e0b4efe9..4d7b14dc6 100755 --- a/app/Models/Accessory.php +++ b/app/Models/Accessory.php @@ -1,9 +1,7 @@ text(e($this->category->eula_text)); } elseif ((Setting::getSettings()->default_eula_text) && ($this->category->use_default_eula=='1')) { return $Parsedown->text(e(Setting::getSettings()->default_eula_text)); - } else { - return null; } - + return null; } public function numRemaining() diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 9669e2ce9..b7abe88de 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1,21 +1,14 @@ 'min:2|max:255', @@ -62,7 +54,6 @@ class Asset extends Depreciable 'purchase_cost' => 'numeric|nullable', ]; - /** * The attributes that are mass assignable. * @@ -70,6 +61,10 @@ class Asset extends Depreciable */ protected $fillable = ['name','model_id','status_id','asset_tag']; + public function getDisplayNameAttribute() + { + return $this->present()->name(); + } public function company() { @@ -86,9 +81,16 @@ class Asset extends Depreciable ); } - /** - * Checkout asset - */ + /** + * Checkout asset + * @param User $user + * @param User $admin + * @param Carbon $checkout_at + * @param null $expected_checkin + * @param string $note + * @param null $name + * @return bool + */ public function checkOutToUser($user, $admin, $checkout_at = null, $expected_checkin = null, $note = null, $name = null) { if (!$user) { @@ -140,7 +142,7 @@ class Asset extends Depreciable $data['log_id'] = $log_id; $data['eula'] = $this->getEula(); $data['first_name'] = $user->first_name; - $data['item_name'] = $this->showAssetName(); + $data['item_name'] = $this->present()->name(); $data['checkout_date'] = $checkout_at; $data['expected_checkin'] = $expected_checkin; $data['item_tag'] = $this->asset_tag; @@ -178,9 +180,9 @@ class Asset extends Depreciable 'fields' => [ [ 'title' => 'Checked Out:', - 'value' => 'HARDWARE asset <'.route('hardware.show', $this->id).'|'.$this->showAssetName() - .'> checked out to <'.route('users.show', $this->assigned_to).'|'.$this->assigneduser->fullName() - .'> by <'.route('users.show', Auth::user()->id).'|'.$admin->fullName().'>.' + 'value' => 'HARDWARE asset <'.route('hardware.show', $this->id).'|'.$this->present()->name() + .'> checked out to <'.route('users.show', $this->assigned_to).'|'.$this->assigneduser->present()->fullName() + .'> by <'.route('users.show', Auth::user()->id).'|'.$admin->present()->fullName().'>.' ], [ 'title' => 'Note:', @@ -200,7 +202,7 @@ class Asset extends Depreciable public function getDetailedNameAttribute() { if ($this->assignedUser) { - $user_name = $this->assignedUser->fullName(); + $user_name = $this->assignedUser->present()->fullName(); } else { $user_name = "Unassigned"; } @@ -358,7 +360,6 @@ class Asset extends Depreciable */ public static function availassetcount() { - return Asset::RTD() ->whereNull('deleted_at') ->count(); @@ -385,35 +386,6 @@ class Asset extends Depreciable return $this->belongsTo('\App\Models\Statuslabel', 'status_id'); } - /** - * Get name for EULA - **/ - public function showAssetName() - { - - if ($this->name == '') { - if ($this->model) { - return $this->model->name.' ('.$this->asset_tag.')'; - } - return $this->asset_tag; - } else { - return $this->name; - } - } - - public function getDisplayNameAttribute() - { - return $this->showAssetName(); - } - - public function warrantee_expires() - { - $date = date_create($this->purchase_date); - date_add($date, date_interval_create_from_date_string($this->warranty_months . ' months')); - return date_format($date, 'Y-m-d'); - } - - public function model() { return $this->belongsTo('\App\Models\AssetModel', 'model_id')->withTrashed(); @@ -451,32 +423,7 @@ class Asset extends Depreciable return $this->belongsTo('\App\Models\Supplier', 'supplier_id'); } - public function months_until_eol() - { - $today = date("Y-m-d"); - $d1 = new DateTime($today); - $d2 = new DateTime($this->eol_date()); - - if ($this->eol_date() > $today) { - $interval = $d2->diff($d1); - } else { - $interval = null; - } - - return $interval; - } - - public function eol_date() - { - - if (( $this->purchase_date ) && ( $this->model )) { - $date = date_create($this->purchase_date); - date_add($date, date_interval_create_from_date_string($this->model->eol . ' months')); - return date_format($date, 'Y-m-d'); - } - - } /** * Get auto-increment @@ -507,7 +454,7 @@ class Asset extends Depreciable } -public function checkin_email() + public function checkin_email() { return $this->model->category->checkin_email; } diff --git a/app/Models/AssetModel.php b/app/Models/AssetModel.php index a730fc5b4..51562fe84 100755 --- a/app/Models/AssetModel.php +++ b/app/Models/AssetModel.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Models\Requestable; use App\Models\SnipeModel; +use App\Presenters\Presentable; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Watson\Validating\ValidatingTrait; @@ -16,7 +17,8 @@ use Watson\Validating\ValidatingTrait; class AssetModel extends SnipeModel { use SoftDeletes; - use Requestable; + protected $presenter = 'App\Presenters\AssetModelPresenter'; + use Requestable, Presentable; protected $dates = ['deleted_at']; protected $table = 'models'; @@ -46,8 +48,6 @@ class AssetModel extends SnipeModel */ protected $fillable = ['name','manufacturer_id','category_id','eol']; - - public function assets() { return $this->hasMany('\App\Models\Asset', 'model_id'); @@ -78,26 +78,6 @@ class AssetModel extends SnipeModel return $this->belongsTo('\App\Models\CustomFieldset', 'fieldset_id'); } - public function getNote() - { - - $Parsedown = new \Parsedown(); - - if ($this->note) { - return $Parsedown->text(e($this->note)); - } - - } - - public function displayModelName() - { - $name = $this->manufacturer->name.' '.$this->name; - if ($this->model_number) { - $name .=" / ".$this->model_number; - } - return $name; - } - /** * ----------------------------------------------- * BEGIN QUERY SCOPES diff --git a/app/Models/Category.php b/app/Models/Category.php index 52ffe2a27..aae469d44 100755 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Http\Traits\UniqueUndeletedTrait; use App\Models\SnipeModel; +use App\Presenters\Presentable; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Watson\Validating\ValidatingTrait; @@ -17,7 +18,8 @@ use Watson\Validating\ValidatingTrait; */ class Category extends SnipeModel { - + protected $presenter = 'App\Presenters\CategoryPresenter'; + use Presentable; use SoftDeletes; protected $dates = ['deleted_at']; protected $table = 'categories'; @@ -75,13 +77,13 @@ class Category extends SnipeModel { switch ($this->category_type) { case 'asset': - return $this->assets->count(); + return $this->assets()->count(); case 'accessory': - return $this->accessories->count(); + return $this->accessories()->count(); case 'component': - return $this->components->count(); + return $this->components()->count(); case 'consumable': - return $this->consumables->count(); + return $this->consumables()->count(); } return '0'; } diff --git a/app/Models/CheckoutRequest.php b/app/Models/CheckoutRequest.php index a3e5fb613..94d1cffb2 100644 --- a/app/Models/CheckoutRequest.php +++ b/app/Models/CheckoutRequest.php @@ -51,7 +51,7 @@ class CheckoutRequest extends Model public function name() { if ($this->itemType() == "asset") { - return $this->itemRequested()->showAssetName(); + return $this->itemRequested()->present()->name(); } return $this->itemRequested()->name; diff --git a/app/Models/Company.php b/app/Models/Company.php index a2609de6c..6479d3aca 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -2,6 +2,7 @@ namespace App\Models; use App\Models\SnipeModel; +use App\Presenters\Presentable; use Auth; use DB; use Illuminate\Database\Eloquent\Model; @@ -21,6 +22,8 @@ final class Company extends SnipeModel 'name' => 'required|min:1|max:255|unique:companies,name' ]; + protected $presenter = 'App\Presenters\CompanyPresenter'; + use Presentable; /** * Whether the model should inject it's identifier to the unique @@ -63,12 +66,6 @@ final class Company extends SnipeModel return $query->where($column, '=', $company_id); } - public static function getSelectList() - { - $select_company = trans('general.select_company'); - return ['0' => $select_company] + DB::table('companies')->orderBy('name', 'ASC')->lists('name', 'id'); - } - public static function getIdFromInput($unescaped_input) { $escaped_input = e($unescaped_input); @@ -116,7 +113,6 @@ final class Company extends SnipeModel public static function isCurrentUserAuthorized() { - return ((!static::isFullMultipleCompanySupportEnabled()) || (Auth::user()->isSuperUser())); } @@ -168,17 +164,6 @@ final class Company extends SnipeModel } } - public static function getName($companyable) - { - $company = $companyable->company; - - if (is_null($company)) { - return ''; - } else { - return e($company->name); - } - } - public function users() { return $this->hasMany(User::class); } diff --git a/app/Models/Component.php b/app/Models/Component.php index 9d8502311..2d4c40c81 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -1,15 +1,7 @@ 'required|min:3|max:255|unique:depreciations,name', diff --git a/app/Models/License.php b/app/Models/License.php index 18e270823..6bb93a586 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -3,15 +3,17 @@ namespace App\Models; use App\Models\Company; use App\Models\Loggable; +use App\Presenters\Presentable; use DB; use Illuminate\Database\Eloquent\SoftDeletes; use Watson\Validating\ValidatingTrait; class License extends Depreciable { + protected $presenter = 'App\Presenters\LicensePresenter'; use SoftDeletes; use CompanyableTrait; - use Loggable; + use Loggable, Presentable; protected $injectUniqueIdentifier = true; use ValidatingTrait; diff --git a/app/Models/Location.php b/app/Models/Location.php index ecf8bee31..174d4c577 100755 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -5,12 +5,15 @@ use App\Http\Traits\UniqueUndeletedTrait; use App\Models\Asset; use App\Models\SnipeModel; use App\Models\User; +use App\Presenters\Presentable; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Watson\Validating\ValidatingTrait; class Location extends SnipeModel { + protected $presenter = 'App\Presenters\LocationPresenter'; + use Presentable; use SoftDeletes; protected $dates = ['deleted_at']; protected $table = 'locations'; diff --git a/app/Models/Manufacturer.php b/app/Models/Manufacturer.php index 232d2a61d..c6c62883f 100755 --- a/app/Models/Manufacturer.php +++ b/app/Models/Manufacturer.php @@ -1,13 +1,14 @@ activated == 1) { - return true; - } else { - return false; - } - } - - - /** - * Returns the user full name, it simply concatenates - * the user first and last name. - * - * @return string - */ - public function fullName() - { - return "{$this->first_name} {$this->last_name}"; + return $this->activated ==1; } public function getFullNameAttribute() @@ -141,26 +122,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon return $this->last_name . ", " . $this->first_name . " (" . $this->username . ")"; } - /** - * Returns the user Gravatar image url. - * - * @return string - */ - public function gravatar() - { - if ($this->avatar) { - return config('app.url').'/uploads/avatars/'.$this->avatar; - } - - if ((Setting::getSettings()->load_remote=='1') && ($this->email!='')) { - $gravatar = md5(strtolower(trim($this->email))); - return "//gravatar.com/avatar/".$gravatar; - } - - return false; - - } /** * Get assets assigned to this user diff --git a/app/Presenters/AccessoryPresenter.php b/app/Presenters/AccessoryPresenter.php new file mode 100644 index 000000000..56d1992be --- /dev/null +++ b/app/Presenters/AccessoryPresenter.php @@ -0,0 +1,162 @@ + "companyName", + "searchable" => true, + "sortable" => true, + "switchable" => true, + "title" => trans('admin/companies/table.title'), + "visible" => false, + ], [ + "field" => "name", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/accessories/table.title'), + ], [ + "field" => "category", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/accessories/general.accessory_category'), + ], [ + "field" => "model_number", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/models/table.modelnumber'), + ], [ + "field" => "manufacturer", + "searchable" => true, + "sortable" => true, + "title" => trans('general.manufacturer'), + ], [ + "field" => "location", + "searchable" => true, + "sortable" => true, + "title" => trans('general.location'), + ], [ + "field" => "qty", + "searchable" => false, + "sortable" => false, + "title" => trans('admin/accessories/general.total'), + ], [ + "field" => "purchase_date", + "searchable" => true, + "sortable" => true, + "visible" => false, + "title" => trans('general.purchase_date'), + ], [ + "field" => "purchase_cost", + "searchable" => true, + "sortable" => true, + "title" => trans('general.purchase_cost'), + ], [ + "field" => "order_number", + "searchable" => true, + "sortable" => true, + "visible" => false, + "title" => trans('general.order_number'), + ], [ + "field" => "min_amt", + "searchable" => false, + "sortable" => true, + "title" => trans('general.min_amt'), + ], [ + "field" => "numRemaining", + "searchable" => false, + "sortable" => false, + "title" => trans('admin/accessories/general.remaining'), + ], [ + "field" => "actions", + "searchable" => false, + "sortable" => false, + "switchable" => false, + "title" => trans('table.actions'), + ] + ]; + + return json_encode($layout); + } + + /** + * JSON representation of Accessory for datatable. + * @return array + */ + public function forDataTable() + { + + $actions = ''; + if (Gate::allows('checkout', $this->model)) { + $actions .= Helper::generateDatatableButton( + 'checkout', + route('checkout/accessory', $this->id), + $this->numRemaining() > 0 + ); + } + if (Gate::allows('update', $this->model)) { + $actions .= Helper::generateDatatableButton('edit', route('accessories.update', $this->id)); + } + if (Gate::allows('delete', $this->model)) { + $actions .= Helper::generateDatatableButton( + 'delete', + route('accessories.destroy', $this->id), + true, /*enabled*/ + trans('admin/accessories/message.delete.confirm'), + $this->name + ); + } + $actions .= ''; + + $results = []; + $results['name'] = $this->nameUrl(); + $results['category'] = ''; + if($this->model->category) { + $results['category'] = $this->model->category->present()->nameUrl(); + } + $results['model_number'] = $this->model_number; + $results['qty'] = $this->qty; + $results['order_number'] = $this->order_number; + $results['min_amt'] = $this->min_amt; + $results['location'] = $this->model->location ? $this->model->location->present()->nameUrl() : ''; + $results['purchase_date'] = $this->purchase_date; + $results['purchase_cost'] = Helper::formatCurrencyOutput($this->purchase_cost); + $results['numRemaining'] = $this->numRemaining(); + $results['companyName'] = $this->model->company ? $this->model->company->present()->nameUrl() : ''; + $results['manufacturer'] = $this->model->manufacturer ? $this->model->manufacturer->present()->nameUrl() : ''; + $results['actions'] = $actions; + + return $results; + } + + /** + * Pregenerated link to this accessories view page. + * @return string + */ + public function nameUrl() + { + return (string) link_to_route('accessories.show', $this->name, $this->id); + } +} diff --git a/app/Presenters/AssetModelPresenter.php b/app/Presenters/AssetModelPresenter.php new file mode 100644 index 000000000..6938fcf58 --- /dev/null +++ b/app/Presenters/AssetModelPresenter.php @@ -0,0 +1,110 @@ +'; + if ($this->deleted_at == '') { + $actions .= Helper::generateDatatableButton('clone', route('clone/model', $this->id)); + $actions .= Helper::generateDatatableButton('edit', route('models.edit', $this->id)); + $actions .= Helper::generateDatatableButton( + 'delete', + route('models.destroy', $this->id), + trans('admin/models/message.delete.confirm'), + $this->name + ); + } else { + $actions .= Helper::generateDatatableButton('restore', route('restore/model', $this->id)); + } + $actions .=""; + + $results = []; + + $results['id'] = $this->id; + $results['manufacturer'] = $this->model->manufacturer->present()->nameUrl(); + $results['name'] = $this->nameUrl(); + $results['image'] = $this->imageUrl(); + $results['model_number'] = $this->model_number; + $results['numassets'] = $this->assets()->count(); + $results['depreciation'] = trans('general.no_depreciation'); + if(($depreciation = $this->model->depreciation) and $depreciation->id > 0) { + $results['depreciation'] = $depreciation->name.' ('.$depreciation->months.')'; + } + $results['category'] = $this->model->category ? $this->model->category->present()->nameUrl() : ''; + $results['eol'] = $this->eol ? $this->eol.' '.trans('general.months') : ''; + $results['note'] = $this->note(); + $results['fieldset'] = $this->model->fieldset ? link_to_route('custom_fields/model', $this->model->fieldset->name, $this->model->fieldset->id) : ''; + $results['actions'] = $actions; + + return $results; + } + + /** + * Formatted note for this model + * @return string + */ + public function note() + { + $Parsedown = new \Parsedown(); + + if ($this->model->note) { + return $Parsedown->text($this->model->note); + } + + } + + /** + * Pretty name for this model + * @return string + */ + public function modelName() + { + $name = $this->model->manufacturer->name.' '.$this->name; + if ($this->model_number) { + $name .=" / ".$this->model_number; + } + return $name; + } + + /** + * Standard url for use to view page. + * @return string + */ + public function nameUrl() + { + return (string) link_to_route('models.show',$this->name, $this->id); + } + + /** + * Generate img tag to this models image. + * @return string + */ + public function imageUrl() + { + if(!empty($this->image)) { + return ''; + } + return ''; + } +} diff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.php new file mode 100644 index 000000000..18d1a7606 --- /dev/null +++ b/app/Presenters/AssetPresenter.php @@ -0,0 +1,256 @@ +'; + if ($this->model->deleted_at=='') { + if (Gate::allows('create', $this->model)) { + $actions .= Helper::generateDatatableButton('clone', route('clone/hardware', $this->model->id)); + } + if (Gate::allows('update', $this->model)) { + $actions .= Helper::generateDatatableButton('edit', route('hardware.edit', $this->model->id)); + } + + if (Gate::allows('delete', $this->model)) { + $actions .= Helper::generateDatatableButton( + 'delete', + route('hardware.destroy', $this->model->id), + true, /*enabled*/ + trans('admin/hardware/message.delete.confirm'), + $this->model->asset_tag + ); + } + } elseif ($this->model->model->deleted_at=='') { + $actions .= Helper::generateDatatableButton('restore', route('restore/hardware', $this->model->id)); + } + + $actions .= ''; + + if (($this->model->availableForCheckout())) + { + if (Gate::allows('checkout', $this->model)) { + $inout = '' . trans('general.checkout') . ''; + } + + } else { + if (Gate::allows('checkin', $this->model)) { + $inout = '' . trans('general.checkin') . ''; + } + } + + $results = []; + $results['checkbox'] = '
'; + $results['id'] = $this->id; + + $results['name'] = $this->nameUrl(); + $results['asset_tag'] = $this->assetTagUrl(); + $results['serial'] = $this->serial; + $results['image'] = $this->imageUrl(); + // Presets for when conditionals fail. + $results['model'] = 'No Model'; + $results['model_number'] = ''; + $results['category'] = ''; + $results['manufacturer'] = ''; + if($model = $this->model->model) { + $results['model'] = $model->present()->nameUrl(); + + if(!empty($model->model_number)) { + $results['model_number'] = $model->model_number; + } + if ($model->category) { + $results['category'] = $model->category->present()->nameUrl(); + } + + if($model->manufacturer) { + $results['manufacturer'] = $model->manufacturer->present()->nameUrl(); + } + } + + $results['status_label'] = ''; + $results['assigned_to'] = ''; + if($assigned = $this->model->assigneduser) { + $results['status_label'] = 'Deployed'; + $results['assigned_to'] = (string) link_to_route('users.show', $assigned->present()->fullName(), $this->assigned_to ); + } else if($this->model->assetstatus) { + $results['status_label'] = $this->model->assetstatus->name; + } + $results['location'] = ''; + if (isset($assigned) and !empty($assignedLoc = $assigned->userloc)) { + $results['location'] = $assignedLoc->present()->nameUrl(); + } else if (!empty($this->model->defaultLoc)) { + $results['location'] = $this->model->defaultLoc->present()->nameUrl(); + } + + $results['eol'] = $this->eol_date() ?: ''; + $results['purchase_cost'] = Helper::formatCurrencyOutput($this->purchase_cost); + $results['purchase_date'] = $this->purchase_date ?: ''; + $results['notes'] = e($this->notes); + $results['order_number'] = ''; + if(!empty($this->order_number)) { + $results['order_number'] = link_to_route('hardware.index', $this->order_number, ['order_number' => $this->order_number]); + } + + $results['last_checkout'] = $this->last_checkout ?: ''; + $results['expected_checkin'] = $this->expected_checkin ?: ''; + $results['created_at'] = ''; + if(!empty($this->created_at)) { + $results['created_at'] = $this->created_at->format('F j, Y h:iA'); + } + $results['companyName'] = $this->model->company ? $this->model->company->name : ''; + $results['actions'] = $actions ?: ''; + $results['change'] = $inout ?: ''; + + + // Custom Field bits + foreach ($all_custom_fields as $field) { + $column_name = $field->db_column_name(); + + if ($field->isFieldDecryptable($this->model->{$column_name})) { + + if (Gate::allows('admin')) { + if (($field->format=='URL') && ($this->model->{$column_name}!='')) { + $row[$column_name] = ''.Helper::gracefulDecrypt($field, $this->model->{$column_name}).''; + } else { + $row[$column_name] = Helper::gracefulDecrypt($field, $this->model->{$column_name}); + } + + } else { + $row[$field->db_column_name()] = strtoupper(trans('admin/custom_fields/general.encrypted')); + } + } else { + if (($field->format=='URL') && ($this->model->{$field->db_column_name()}!='')) { + $row[$field->db_column_name()] = ''.$this->model->{$field->db_column_name()}.''; + } else { + $row[$field->db_column_name()] = e($this->model->{$field->db_column_name()}); + } + } + + } + + return $results; + } + + /** + * Generate html link to this items asset tag + * @return string + */ + public function assetTagUrl() + { + return (string) link_to_route('hardware.show', e($this->asset_tag), $this->id); + } + + /** + * Generate html link to this items name. + * @return string + */ + public function nameUrl() + { + return (string) link_to_route('hardware.show', e($this->name), $this->id); + } + + /** + * Generate img tag to this items image. + * @return mixed|string + */ + public function imageUrl() + { + $imagePath = ''; + if($this->image && !empty($this->image)) { + $imagePath = $this->image; + } else if ($this->model && !empty($this->model->image)) { + $imagePath = $this->model->image; + } + $url = config('app.url'); + if(!empty($imagePath)) { + $imagePath = ""; + } + return $imagePath; + } + + /** + * Get Displayable Name + * @return string + **/ + public function name() + { + + if (empty($this->name)) { + if (isset($this->model)) { + return $this->model->name.' ('.$this->asset_tag.')'; + } + return $this->asset_tag; + } else { + return $this->name; + } + } + + /** + * Returns the date this item hits EOL. + * @return false|string + */ + public function eol_date() + { + + if (( $this->purchase_date ) && ( $this->model )) { + $date = date_create($this->purchase_date); + date_add($date, date_interval_create_from_date_string($this->model->model->eol . ' months')); + return date_format($date, 'Y-m-d'); + } + + } + + /** + * How many months until this asset hits EOL. + * @return null + */ + public function months_until_eol() + { + + $today = date("Y-m-d"); + $d1 = new DateTime($today); + $d2 = new DateTime($this->eol_date()); + + if ($this->eol_date() > $today) { + $interval = $d2->diff($d1); + } else { + $interval = null; + } + + return $interval; + } + + /** + * Date the warantee expires. + * @return false|string + */ + public function warrantee_expires() + { + $date = date_create($this->purchase_date); + date_add($date, date_interval_create_from_date_string($this->warranty_months . ' months')); + return date_format($date, 'Y-m-d'); + } +} diff --git a/app/Presenters/CategoryPresenter.php b/app/Presenters/CategoryPresenter.php new file mode 100644 index 000000000..2c50720a9 --- /dev/null +++ b/app/Presenters/CategoryPresenter.php @@ -0,0 +1,48 @@ +id)); + $actions .= Helper::generateDatatableButton( + 'delete', + route('categories.destroy', $this->id), + $this->itemCount() == 0, /* enabled */ + trans('admin/categories/message.delete.confirm'), + $this->name + ); + $results = []; + $results['id'] = $this->id; + $results['name'] = $this->nameUrl(); + $results['category_type'] = ucwords($this->category_type); + $results['count'] = $this->itemCount(); + $results['acceptance'] = ($this->require_acceptance == '1') ? '' : ''; + $results['eula'] = $this->getEula() ? '' : ''; + $results['actions'] = $actions; + + return $results; + } + + /** + * Link to this categories name + * @return string + */ + public function nameUrl() + { + return (string) link_to_route('categories.show', $this->name, $this->id); + } +} diff --git a/app/Presenters/CompanyPresenter.php b/app/Presenters/CompanyPresenter.php new file mode 100644 index 000000000..3b5e47217 --- /dev/null +++ b/app/Presenters/CompanyPresenter.php @@ -0,0 +1,20 @@ +name, $this->id); + } +} diff --git a/app/Presenters/ComponentPresenter.php b/app/Presenters/ComponentPresenter.php new file mode 100644 index 000000000..6f965da90 --- /dev/null +++ b/app/Presenters/ComponentPresenter.php @@ -0,0 +1,71 @@ +'; + 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 .=''; + + $results = [ + 'checkbox' =>'
', + 'id' => $this->id, + 'name' => $this->nameUrl(), + 'serial_number' => $this->serial, + 'location' => ($this->model->location) ? $this->model->location->present()->nameUrl() : '', + 'qty' => number_format($this->qty), + 'min_amt' => e($this->min_amt), + 'category' => ($this->model->category) ? $this->model->category->present()->nameUrl() : 'Missing category', + 'order_number' => $this->order_number, + 'purchase_date' => $this->purchase_date, + 'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost), + 'numRemaining' => $this->numRemaining(), + 'actions' => $actions, + 'companyName' => $this->model->company ? $this->model->company->present()->nameUrl() : '', + ]; + + return $results; + } + + /** + * Link to this components name + * @return string + */ + public function nameUrl() + { + return (string) link_to_route('components.show', $this->name, $this->id); + } +} diff --git a/app/Presenters/ConsumablePresenter.php b/app/Presenters/ConsumablePresenter.php new file mode 100644 index 000000000..fe558b785 --- /dev/null +++ b/app/Presenters/ConsumablePresenter.php @@ -0,0 +1,69 @@ +'; + 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 .=''; + + $results = [ + 'id' => $this->id, + 'name' => $this->nameUrl(), + 'location' => ($this->model->location) ? $this->model->location->present()->nameUrl() : '', + 'min_amt' => $this->min_amt, + 'qty' => $this->qty, + 'manufacturer' => ($this->model->manufacturer) ? $this->model->manufacturer->present()->nameUrl() : '', + 'model_number' => $this->model_number, + 'item_no' => $this->item_no, + 'category' => ($this->model->category) ? $this->model->category->present()->nameUrl() : 'Missing category', + 'order_number' => $this->order_number, + 'purchase_date' => $this->purchase_date, + 'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost), + 'numRemaining' => $this->numRemaining(), + 'actions' => $actions, + 'companyName' => $this->model->company ? $this->model->company->present()->nameUrl() : '', + ]; + return $results; + } + + /** + * Link to this consumables name + * @return string + */ + private function nameUrl() + { + return (string)link_to_route('consumables.show', $this->name, $this->id); + } +} diff --git a/app/Presenters/DepreciationPresenter.php b/app/Presenters/DepreciationPresenter.php new file mode 100644 index 000000000..5e799f0da --- /dev/null +++ b/app/Presenters/DepreciationPresenter.php @@ -0,0 +1,38 @@ +id)); + $actions .= Helper::generateDatatableButton( + 'delete', + route('depreciations.destroy', $this->id), + true, /*enabled*/ + trans('admin/depreciations/message.delete.confirm'), + $this->name + ); + + $results = [ + 'id' => $this->id, + 'name' => $this->name, + 'months' => $this->months, + 'actions' => $actions + ]; + + return $results; + } +} diff --git a/app/Presenters/LicensePresenter.php b/app/Presenters/LicensePresenter.php new file mode 100644 index 000000000..8adc48b23 --- /dev/null +++ b/app/Presenters/LicensePresenter.php @@ -0,0 +1,87 @@ +'; + + if (Gate::allows('checkout', License::class)) { + $actions .= Helper::generateDatatableButton( + 'checkout', + route('licenses.freecheckout', $this->id), + $this->remaincount() > 0 + ); + } + + if (Gate::allows('create', $this->model)) { + $actions .= Helper::generateDatatableButton('clone', route('clone/license', $this->id)); + } + if (Gate::allows('update', $this->model)) { + $actions .= Helper::generateDatatableButton('edit', route('licenses.edit', $this->id)); + } + if (Gate::allows('delete', $this->model)) { + $actions .= Helper::generateDatatableButton( + 'delete', + route('licenses.destroy', $this->id), + true, /*enabled*/ + trans('admin/licenses/message.delete.confirm'), + $this->name + ); + } + $actions .=''; + + $results = [ + 'id' => $this->id, + 'name' => $this->nameUrl(), + 'serial' => $this->serialUrl(), + 'totalSeats' => $this->model->licenseSeatsCount, + 'remaining' => $this->remaincount(), + 'license_name' => $this->license_name, + 'license_email' => $this->license_email, + 'purchase_date' => ($this->purchase_date) ?: '', + 'expiration_date' => ($this->expiration_date) ?: '', + 'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost), + 'purchase_order' => ($this->purchase_order) ?: '', + 'order_number' => ($this->order_number) ?: '', + 'notes' => ($this->notes) ?: '', + 'actions' => $actions, + 'company' => $this->model->company ? e($this->model->company->present()->nameUrl()) : '', + 'manufacturer' => $this->model->manufacturer ? $this->model->manufacturer->present()->nameUrl() : '' + ]; + + return $results; + } + + /** + * Link to this licenses Name + * @return string + */ + public function nameUrl() + { + return (string)link_to_route('licenses.show', $this->name, $this->id); + } + + /** + * Link to this licenses serial + * @return string + */ + public function serialUrl() + { + return (string) link_to('/licenses/'.$this->id, mb_strimwidth($this->serial, 0, 50, "...")); + } +} diff --git a/app/Presenters/LocationPresenter.php b/app/Presenters/LocationPresenter.php new file mode 100644 index 000000000..9d1d40f11 --- /dev/null +++ b/app/Presenters/LocationPresenter.php @@ -0,0 +1,58 @@ +'; + $actions .= Helper::generateDatatableButton('edit', route('locations.edit', $this->id)); + $actions .= Helper::generateDatatableButton( + 'delete', + route('locations.destroy', $this->id), + true, /*enabled*/ + trans('admin/locations/message.delete.confirm'), + $this->name + ); + $actions .= ''; + + $results = [ + 'id' => $this->id, + 'name' => $this->nameUrl(), + 'parent' => ($this->model->parent) ? $this->model->parent->present()->nameUrl() : '', + // 'assets' => ($this->assets->count() + $this->assignedassets->count()), + 'assets_default' => $this->model->assignedassets()->count(), + 'assets_checkedout' => $this->model->assets()->count(), + 'address' => $this->address, + 'city' => $this->city, + 'state' => $this->state, + 'zip' => $this->zip, + 'country' => $this->country, + 'currency' => $this->currency, + 'actions' => $actions + ]; + + return $results; + } + + /** + * Link to this locations name + * @return string + */ + public function nameUrl() + { + return (string)link_to_route('locations.show', $this->name, $this->id); + } +} diff --git a/app/Presenters/ManufacturerPresenter.php b/app/Presenters/ManufacturerPresenter.php new file mode 100644 index 000000000..b25c7a019 --- /dev/null +++ b/app/Presenters/ManufacturerPresenter.php @@ -0,0 +1,53 @@ +'; + $actions .= Helper::generateDatatableButton('edit', route('manufacturers.edit', $this->id)); + $actions .= Helper::generateDatatableButton( + 'delete', + route('manufacturers.destroy', $this->id), + true, /*enabled*/ + trans('admin/manufacturers/message.delete.confirm'), + $this->name + ); + $actions .= ''; + + $results = [ + 'id' => $this->id, + 'name' => $this->nameUrl(), + 'assets' => $this->assets()->count(), + 'licenses' => $this->licenses()->count(), + 'accessories' => $this->accessories()->count(), + 'consumables' => $this->consumables()->count(), + 'actions' => $actions + ]; + + return $results; + } + + /** + * Link to this manufacturers name + * @return string + */ + public function nameUrl() + { + return (string) link_to_route('manufacturers.show', $this->name, $this->id); + } +} diff --git a/app/Presenters/Presentable.php b/app/Presenters/Presentable.php new file mode 100644 index 000000000..19e952659 --- /dev/null +++ b/app/Presenters/Presentable.php @@ -0,0 +1,24 @@ +presenter || !class_exists($this->presenter)) { + throw new \Exception('Presenter class does not exist'); + } + + if (!isset($this->presenterInterface)) { + $this->presenterInterface = new $this->presenter($this); + } + + return $this->presenterInterface; + + } +} diff --git a/app/Presenters/Presenter.php b/app/Presenters/Presenter.php new file mode 100644 index 000000000..ba8bbcfd9 --- /dev/null +++ b/app/Presenters/Presenter.php @@ -0,0 +1,37 @@ +model = $model; + } + + public function __get($property) + { + if( method_exists($this, $property)) { + return $this->{$property}(); + } + + return e($this->model->{$property}); + } + + public function __call($method, $args) + { + return $this->model->$method($args); + } +} diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.php new file mode 100644 index 000000000..c309cb685 --- /dev/null +++ b/app/Presenters/UserPresenter.php @@ -0,0 +1,135 @@ +'; + + foreach ($this->model->groups as $group) { + $group_names .= link_to_route('update/group', $group->name, $group->id, ['class' => 'label label-default']); + } + if (!is_null($this->model->deleted_at)) { + if (Gate::allows('delete', $this)) { + $actions .= Helper::generateDatatableButton('restore', route('restore/user', $this->id)); + } + } else { + if (Gate::allows('delete', $this)) { + if ($this->accountStatus() == 'suspended') { + $actions .= link_to_route( + 'unsuspend/user', + '"', + $this->id, + ['class' => 'btn btn-default btn-sm'] + ); + } + } + if (Gate::allows('update', $this)) { + $actions .= Helper::generateDatatableButton('edit', route('users.edit', $this->id)); + $actions .= Helper::generateDatatableButton('clone', route('clone/user', $this->id)); + } + if (Gate::allows('delete', $this)) { + if ((Auth::user()->id !== $this->id) && (!config('app.lock_passwords'))) { + $actions .= Helper::generateDatatableButton( + 'delete', + route('users.destroy', $this->id), + true, /*enabled*/ + "Are you sure you wish to delete this user?", + $this->first_name + ); + } else { + $actions .= ' '; + } + } + } + $actions .= ''; + $result = [ + 'id' => $this->id, + 'checkbox' => ($status!='deleted') ? '' : '', + 'name' => $this->present()->fullName(), + 'jobtitle' => $this->jobtitle, + 'email' => ($this->email!='') ? + '' + .'' + .'' : '', + 'username' => $this->username, + 'location' => ($this->model->userloc) ? $this->model->userloc->present()->nameUrl() : '', + 'manager' => ($this->model->manager) ? $this->manager->present()->nameUrl() : '', + 'employee_num' => $this->employee_num, + 'assets' => $this->model->assets()->count(), + 'licenses' => $this->model->licenses()->count(), + 'accessories' => $this->model->accessories()->count(), + 'consumables' => $this->model->consumables()->count(), + 'groups' => $group_names, + 'notes' => $this->notes, + 'two_factor_enrolled' => ($this->two_factor_enrolled=='1') ? '' : '', + 'two_factor_optin' => (($this->two_factor_optin=='1') || (Setting::getSettings()->two_factor_enabled=='2') ) ? '' : '', + 'created_at' => ($this->model->created_at!='') ? e($this->model->created_at->format('F j, Y h:iA')) : '', + 'activated' => ($this->activated=='1') ? '' : '', + 'actions' => $actions ?: '', + 'companyName' => $this->company ? $this->company->name : '' + + ]; + + return $result; + } + /** + * Returns the user full name, it simply concatenates + * the user first and last name. + * + * @return string + */ + public function fullName() + { + return "{$this->first_name} {$this->last_name}"; + } + + /** + * Returns the user Gravatar image url. + * + * @return string + */ + public function gravatar() + { + + if ($this->avatar) { + return config('app.url').'/uploads/avatars/'.$this->avatar; + } + + if ((Setting::getSettings()->load_remote=='1') && ($this->email!='')) { + $gravatar = md5(strtolower(trim($this->email))); + return "//gravatar.com/avatar/".$gravatar; + } + + return false; + + } + + /** + * Formatted url for use in tables. + * @return string + */ + public function nameUrl() + { + return (string) link_to_route('users.show', $this->fullName(), $this->id); + } +} diff --git a/resources/views/accessories/index.blade.php b/resources/views/accessories/index.blade.php index 592b0b8dc..1f9f04f94 100755 --- a/resources/views/accessories/index.blade.php +++ b/resources/views/accessories/index.blade.php @@ -30,23 +30,6 @@ data-cookie="true" data-click-to-select="true" data-cookie-id-table="accessoriesTable-{{ config('version.hash_version') }}"> - - - {{ trans('admin/companies/table.title') }} - {{ trans('admin/accessories/table.title') }} - {{ trans('admin/accessories/general.accessory_category') }} - {{ trans('admin/models/table.modelnumber') }} - {{ trans('general.manufacturer') }} - {{ trans('general.location') }} - {{ trans('admin/accessories/general.total') }} - {{ trans('general.purchase_date') }} - {{ trans('general.purchase_cost') }} - {{ trans('general.order_number') }} - {{ trans('general.min_amt') }} - {{ trans('admin/accessories/general.remaining') }} - {{ trans('table.actions') }} - - @@ -55,7 +38,11 @@ @section('moar_scripts') -@include ('partials.bootstrap-table', ['exportFile' => 'accessories-export', 'search' => true]) +@include ('partials.bootstrap-table', [ + 'exportFile' => 'accessories-export', + 'search' => true, + 'columns' => \App\Presenters\AccessoryPresenter::dataTableLayout() + ]) @stop diff --git a/resources/views/account/accept-asset.blade.php b/resources/views/account/accept-asset.blade.php index 6b9559ad5..d24901502 100644 --- a/resources/views/account/accept-asset.blade.php +++ b/resources/views/account/accept-asset.blade.php @@ -2,7 +2,7 @@ {{-- Page title --}} @section('title') - Accept {{ $item->showAssetName() }} + Accept {{ $item->present()->name() }} @parent @stop diff --git a/resources/views/account/view-assets.blade.php b/resources/views/account/view-assets.blade.php index 5210e6083..d4f0510a7 100755 --- a/resources/views/account/view-assets.blade.php +++ b/resources/views/account/view-assets.blade.php @@ -2,7 +2,7 @@ {{-- Page title --}} @section('title') -View Assets for {{ $user->fullName() }} +View Assets for {{ $user->present()->fullName() }} @parent @stop @@ -266,9 +266,9 @@ View Assets for {{ $user->fullName() }} @if (($log->item) && ($log->itemType()=="asset")) @if ($log->item->deleted_at=='') - {{ $log->item->showAssetName() }} + {{ $log->item->present()->name() }} @else - {{ $log->item->showAssetName() }} (deleted) + {{ $log->item->present()->name() }} (deleted) @endif @elseif ($log->item) @@ -284,7 +284,7 @@ View Assets for {{ $user->fullName() }} @if ($log->user) - {{ $log->user->fullName() }} + {{ $log->user->present()->fullName() }} @endif {{ $log->created_at }} diff --git a/resources/views/admin/requested-assets.blade.php b/resources/views/admin/requested-assets.blade.php index 3c7b56843..20d3b5f00 100644 --- a/resources/views/admin/requested-assets.blade.php +++ b/resources/views/admin/requested-assets.blade.php @@ -53,7 +53,7 @@ "N/A" @endif - {{ $request->requestingUser()->fullName() }} + {{ $request->requestingUser()->present()->fullName() }} {{$request->created_at}} diff --git a/resources/views/hardware/bulk-delete.blade.php b/resources/views/hardware/bulk-delete.blade.php index 0a139374c..665d31dcc 100644 --- a/resources/views/hardware/bulk-delete.blade.php +++ b/resources/views/hardware/bulk-delete.blade.php @@ -49,7 +49,7 @@ {{ $asset->id }} - {{ $asset->showAssetName() }} + {{ $asset->present()->name() }} @if ($asset->assetloc) {{ $asset->assetloc->name }} @@ -57,7 +57,7 @@ @if ($asset->assigneduser) - {{ $asset->assigneduser->fullName() }} ({{ $asset->assigneduser->username }}) + {{ $asset->assigneduser->present()->fullName() }} ({{ $asset->assigneduser->username }}) @endif diff --git a/resources/views/hardware/qr-view.blade.php b/resources/views/hardware/qr-view.blade.php index 6c67a28ea..921e8d4f7 100644 --- a/resources/views/hardware/qr-view.blade.php +++ b/resources/views/hardware/qr-view.blade.php @@ -111,8 +111,8 @@ {{ $asset->warranty_months }} {{ trans('admin/hardware/form.months') }} -
{{ trans('admin/hardware/form.expires') }}: - {{ $asset->warrantee_expires() }}
+
{{ trans('admin/hardware/form.expires') }}: + {{ $asset->present()->warrantee_expires() }}
@endif @if ($asset->depreciation) @@ -140,14 +140,14 @@ {{ trans('admin/hardware/form.months') }}
{{ trans('admin/hardware/form.eol_date') }}: - {{ $asset->eol_date() }} - @if ($asset->months_until_eol()) + {{ $asset->present()->eol_date() }} + @if ($asset->present()->months_until_eol()) ( - @if ($asset->months_until_eol()->y > 0) {{ $asset->months_until_eol()->y }} + @if ($asset->present()->months_until_eol()->y > 0) {{ $asset->present()->months_until_eol()->y }} {{ trans('general.years') }}, @endif - {{ $asset->months_until_eol()->m }} + {{ $asset->present()->months_until_eol()->m }} {{ trans('general.months') }} ) @endif @@ -273,7 +273,7 @@ {{ $log->created_at }} @if (isset($log->user_id)) - {{ $log->user->fullName() }} + {{ $log->user->present()->fullName() }} @endif {{ $log->action_type }} @@ -282,10 +282,10 @@ @if ($log->target->deleted_at=='') - {{ $log->user->fullName() }} + {{ $log->user->present()->fullName() }} @else - {{ $log->user->fullName() }} + {{ $log->user->present()->fullName() }} @endif @endif @@ -301,7 +301,7 @@ {{ $asset->created_at }} - @if (isset($asset->adminuser->id)) {{ $asset->adminuser->fullName() }} + @if (isset($asset->adminuser->id)) {{ $asset->adminuser->present()->fullName() }} @else {{ trans('general.unknown_admin') }} @endif @@ -345,8 +345,8 @@

{{ trans('admin/hardware/form.checkedout_to') }}
@@ -74,7 +74,7 @@ Name - {{ $user->fullName() }} + {{ $user->present()->fullName() }} @if ($user->jobtitle) @@ -93,7 +93,7 @@ @if ($user->manager) Manager - {{ $user->manager->fullName() }} + {{ $user->manager->present()->fullName() }} @endif @@ -392,7 +392,7 @@ @if (($log->item) && ($log->itemType()=="asset")) - {{ $log->item->asset_tag }} - {{ $log->item->showAssetName() }} + {{ $log->item->asset_tag }} - {{ $log->item->present()->name() }} @elseif ($log->item) {{ $log->item->name }} @@ -405,7 +405,7 @@ @if ($log->action_type != 'requested') @if (isset($log->user)) - {{ $log->user->fullName() }} + {{ $log->user->present()->fullName() }} @else Deleted Admin @endif diff --git a/tests/_envs/testing-ci.yml b/tests/_envs/testing-ci.yml index c7f266c9d..5bfd0539c 100644 --- a/tests/_envs/testing-ci.yml +++ b/tests/_envs/testing-ci.yml @@ -9,10 +9,11 @@ # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. class_name: AcceptanceTester modules: - config: - WebDriver: - url: http://localhost:8000 - browser: phantomjs - Laravel5: - part: ORM - environment_file: .env + config: + WebDriver: + url: 'http://localhost:8000' + browser: 'phantomjs' + Laravel5: + part: ORM + environment_file: .env +