コード例 #1
0
 /**
  * Generates the JSON response for accessory detail view.
  *
  * Example:
  * <code>
  * {
  * "rows": [
  * {
  * "actions": "(link to available actions)",
  * "name": "(link to user)"
  * }
  * ],
  * "total": 1
  * }
  * </code>
  *
  * The names of the fields in the returns JSON correspond directly to the the
  * names of the fields in the bootstrap-tables in the view.
  *
  * For debugging, see at /api/accessories/$accessoryID/view
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @param  int  $accessoryId
  * @return string JSON containing accessories and their associated atrributes.
  **/
 public function getDataView(Request $request, $accessoryID)
 {
     $accessory = Accessory::find($accessoryID);
     if (!Company::isCurrentUserHasAccess($accessory)) {
         return ['total' => 0, 'rows' => []];
     }
     $accessory_users = $accessory->users;
     $count = $accessory_users->count();
     $rows = array();
     foreach ($accessory_users as $user) {
         $actions = '<a href="' . route('checkin/accessory', $user->pivot->id) . '" class="btn btn-info btn-sm">Checkin</a>';
         $rows[] = array('name' => (string) link_to('/admin/users/' . $user->id . '/view', e($user->fullName())), 'actions' => $actions);
     }
     $data = array('total' => $count, 'rows' => $rows);
     return $data;
 }
コード例 #2
0
 public function getAcceptAsset($logID = null)
 {
     if (!($findlog = DB::table('asset_logs')->where('id', '=', $logID)->first())) {
         echo 'no record';
         //return redirect()->to('account')->with('error', trans('admin/hardware/message.does_not_exist'));
     }
     $user = Auth::user();
     if ($user->id != $findlog->checkedout_to) {
         return redirect()->to('account/view-assets')->with('error', trans('admin/users/message.error.incorrect_user_accepted'));
     }
     // Asset
     if ($findlog->asset_id != '' && $findlog->asset_type == 'hardware') {
         $item = Asset::find($findlog->asset_id);
         // software
     } elseif ($findlog->asset_id != '' && $findlog->asset_type == 'software') {
         $item = License::find($findlog->asset_id);
         // accessories
     } elseif ($findlog->accessory_id != '') {
         $item = Accessory::find($findlog->accessory_id);
         // consumable
     } elseif ($findlog->consumable_id != '') {
         $item = Consumable::find($findlog->consumable_id);
         // components
     } elseif ($findlog->component_id != '') {
         $item = Component::find($findlog->component_id);
     }
     // Check if the asset exists
     if (is_null($item)) {
         // Redirect to the asset management page
         return redirect()->to('account')->with('error', trans('admin/hardware/message.does_not_exist'));
     } elseif (!Company::isCurrentUserHasAccess($item)) {
         return redirect()->route('requestable-assets')->with('error', trans('general.insufficient_permissions'));
     } else {
         return View::make('account/accept-asset', compact('item'))->with('findlog', $findlog);
     }
 }