/** * Get the asset information to present to the model view detail page * * @author [A. Gianotto] [<*****@*****.**>] * @since [v2.0] * @param int $modelId * @return String JSON */ public function getDataView($modelID) { $assets = Asset::where('model_id', '=', $modelID)->with('company'); if (Input::has('search')) { $assets = $assets->TextSearch(e(Input::get('search'))); } if (Input::has('offset')) { $offset = e(Input::get('offset')); } else { $offset = 0; } if (Input::has('limit')) { $limit = e(Input::get('limit')); } else { $limit = 50; } $allowed_columns = ['name', 'serial', 'asset_tag']; $order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array(Input::get('sort'), $allowed_columns) ? e(Input::get('sort')) : 'created_at'; $assets = $assets->orderBy($sort, $order); $assetsCount = $assets->count(); $assets = $assets->skip($offset)->take($limit)->get(); $rows = array(); foreach ($assets as $asset) { $actions = ''; if ($asset->assetstatus) { if ($asset->assetstatus->deployable != 0) { if ($asset->assigned_to != '' && $asset->assigned_to > 0) { $actions = '<a href="' . route('checkin/hardware', $asset->id) . '" class="btn btn-primary btn-sm">' . trans('general.checkin') . '</a>'; } else { $actions = '<a href="' . route('checkout/hardware', $asset->id) . '" class="btn btn-info btn-sm">' . trans('general.checkout') . '</a>'; } } } $rows[] = array('id' => $asset->id, 'name' => (string) link_to('/hardware/' . $asset->id . '/view', $asset->showAssetName()), 'asset_tag' => (string) link_to('hardware/' . $asset->id . '/view', $asset->asset_tag), 'serial' => $asset->serial, 'assigned_to' => $asset->assigned_to ? (string) link_to('/admin/users/' . $asset->assigned_to . '/view', $asset->assigneduser->fullName()) : '', 'actions' => $actions, 'companyName' => Company::getName($asset)); } $data = array('total' => $assetsCount, 'rows' => $rows); return $data; }
public function getDataViewComponent($categoryID) { $category = Category::with('accessories.company')->find($categoryID); $category_assets = $category->components; if (Input::has('search')) { $category_assets = $category_assets->TextSearch(e(Input::get('search'))); } if (Input::has('offset')) { $offset = e(Input::get('offset')); } else { $offset = 0; } if (Input::has('limit')) { $limit = e(Input::get('limit')); } else { $limit = 50; } $order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $allowed_columns = ['id', 'name', 'serial', 'asset_tag']; $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at'; $count = $category_assets->count(); $rows = array(); foreach ($category_assets as $asset) { $actions = ''; $inout = ''; if ($asset->deleted_at == '') { $actions = '<div style=" white-space: nowrap;"><a href="' . route('update/component', $asset->id) . '" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('delete/component', $asset->id) . '" data-content="' . trans('admin/hardware/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($asset->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>'; } $rows[] = array('id' => $asset->id, 'name' => (string) link_to_route('view/accessory', $asset->name, [$asset->id]), 'actions' => $actions, 'companyName' => Company::getName($asset)); } $data = array('total' => $count, 'rows' => $rows); return $data; }
/** * Generates the JSON used to display the manufacturer detail. * This JSON returns data on all of the assets with the specified * manufacturer ID number. * * @author [A. Gianotto] [<*****@*****.**>] * @see ManufacturersController::getView() * @param int $manufacturerId * @since [v1.0] * @return String JSON */ public function getDataView($manufacturerId) { $manufacturer = Manufacturer::with('assets.company')->find($manufacturerId); $manufacturer_assets = $manufacturer->assets; if (Input::has('search')) { $manufacturer_assets = $manufacturer_assets->TextSearch(e(Input::get('search'))); } if (Input::has('offset')) { $offset = e(Input::get('offset')); } else { $offset = 0; } if (Input::has('limit')) { $limit = e(Input::get('limit')); } else { $limit = 50; } $order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $allowed_columns = ['id', 'name', 'serial', 'asset_tag']; $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at'; $count = $manufacturer_assets->count(); $rows = array(); foreach ($manufacturer_assets as $asset) { $actions = ''; if ($asset->deleted_at == '') { $actions = '<div style=" white-space: nowrap;"><a href="' . route('clone/hardware', $asset->id) . '" class="btn btn-info btn-sm" title="Clone asset"><i class="fa fa-files-o"></i></a> <a href="' . route('update/hardware', $asset->id) . '" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('delete/hardware', $asset->id) . '" data-content="' . trans('admin/hardware/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($asset->asset_tag) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>'; } elseif ($asset->deleted_at != '') { $actions = '<a href="' . route('restore/hardware', $asset->id) . '" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>'; } if ($asset->assetstatus) { if ($asset->assetstatus->deployable != 0) { if ($asset->assigned_to != '' && $asset->assigned_to > 0) { $inout = '<a href="' . route('checkin/hardware', $asset->id) . '" class="btn btn-primary btn-sm">' . trans('general.checkin') . '</a>'; } else { $inout = '<a href="' . route('checkout/hardware', $asset->id) . '" class="btn btn-info btn-sm">' . trans('general.checkout') . '</a>'; } } } $row = array('id' => $asset->id, 'name' => (string) link_to('/hardware/' . $asset->id . '/view', e($asset->showAssetName())), 'model' => e($asset->model->name), 'asset_tag' => e($asset->asset_tag), 'serial' => e($asset->serial), 'assigned_to' => $asset->assigneduser ? (string) link_to('/admin/users/' . $asset->assigneduser->id . '/view', e($asset->assigneduser->fullName())) : '', 'actions' => $actions, 'companyName' => e(Company::getName($asset))); if (isset($inout)) { $row['change'] = $inout; } $rows[] = $row; } $data = array('total' => $count, 'rows' => $rows); return $data; }