From 315f02905ab35173b0e6ce4d2d82135dfad43e49 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 12 Aug 2015 20:58:18 -0700 Subject: [PATCH] Pull all lists into helper functions for consistency --- app/controllers/admin/AssetsController.php | 73 +++++++--------------- app/helpers.php | 59 ++++++++++++++--- 2 files changed, 73 insertions(+), 59 deletions(-) diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index cd5b8bef72..6ff4bb4391 100755 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -55,26 +55,14 @@ class AssetsController extends AdminController */ public function getCreate($model_id = null) { - - $model_list = array('' => Lang::get('general.select_model')) + DB::table('models') - ->select(DB::raw('concat(name," / ",modelno) as name, id'))->orderBy('name', 'asc') - ->orderBy('modelno', 'asc') - ->whereNull('deleted_at') - ->lists('name', 'id'); - - - $supplier_list = array('' => Lang::get('general.select_supplier')) + Supplier::orderBy('name', 'asc')->lists('name', 'id'); - $assigned_to = array('' => Lang::get('general.select_user')) + DB::table('users')->select(DB::raw('concat(first_name," ",last_name) as full_name, id'))->whereNull('deleted_at')->lists('full_name', 'id'); - $location_list = array('' => Lang::get('general.select_location')) + Location::orderBy('name', 'asc')->lists('name', 'id'); - - - // Grab the dropdown list of status - $statuslabel_list = array('' => Lang::get('general.select_statuslabel')) + Statuslabel::orderBy('name', 'asc')->lists('name', 'id'); - - // grap dropdown lists for embedded create drop-downs - $manufacturer_list = array('' => 'Select One') + Manufacturer::lists('name', 'id'); - $category_list = array('' => '') + DB::table('categories')->whereNull('deleted_at')->lists('name', 'id'); - + // Grab the dropdown lists + $model_list = modelList(); + $statuslabel_list = statusLabelList(); + $location_list = locationsList(); + $manufacturer_list = manufacturerList(); + $category_list = categoryList(); + $supplier_list = suppliersList(); + $assigned_to = assignedToList(); $view = View::make('backend/hardware/edit'); $view->with('supplier_list',$supplier_list); @@ -216,21 +204,14 @@ class AssetsController extends AdminController return Redirect::to('hardware')->with('error', Lang::get('admin/hardware/message.does_not_exist')); } - - // Grab the dropdown list of models - $manufacturer_list = array('' => 'Select One') + Manufacturer::lists('name', 'id'); - $category_list = array('' => '') + DB::table('categories')->whereNull('deleted_at')->lists('name', 'id'); - - $model_list = array('' => Lang::get('general.select_model')) + DB::table('models') - ->select(DB::raw('concat(name," / ",modelno) as name, id'))->orderBy('name', 'asc') - ->orderBy('modelno', 'asc') - ->lists('name', 'id'); - $supplier_list = array('' => Lang::get('general.select_supplier')) + Supplier::orderBy('name', 'asc')->lists('name', 'id'); - $location_list = array('' => Lang::get('general.select_location')) + Location::orderBy('name', 'asc')->lists('name', 'id'); - $assigned_to = array('' => Lang::get('general.select_user')) + DB::table('users')->select(DB::raw('concat(first_name," ",last_name) as full_name, id'))->whereNull('deleted_at')->lists('full_name', 'id'); - - // Grab the dropdown list of status - $statuslabel_list = Statuslabel::orderBy('name', 'asc')->lists('name', 'id'); + // Grab the dropdown lists + $model_list = modelList(); + $statuslabel_list = statusLabelList(); + $location_list = locationsList(); + $manufacturer_list = manufacturerList(); + $category_list = categoryList(); + $supplier_list = suppliersList(); + $assigned_to = assignedToList(); return View::make('backend/hardware/edit', compact('asset')) ->with('model_list',$model_list) @@ -663,20 +644,14 @@ class AssetsController extends AdminController return Redirect::to('hardware')->with('error', Lang::get('admin/hardware/message.does_not_exist')); } - // Grab the dropdown list of models - $model_list = array('' => Lang::get('general.select_model')) + Model::lists('name', 'id'); - - // Grab the dropdown list of status - $statuslabel_list = Statuslabel::lists('name', 'id'); - - $location_list = array('' => Lang::get('general.select_location')) + Location::lists('name', 'id'); - - $manufacturer_list = array('' => 'Select One') + Manufacturer::lists('name', 'id'); - $category_list = array('' => '') + DB::table('categories')->whereNull('deleted_at')->lists('name', 'id'); - - // get depreciation list - $supplier_list = array('' => Lang::get('general.select_supplier')) + Supplier::orderBy('name', 'asc')->lists('name', 'id'); - $assigned_to = array('' => Lang::get('general.select_user')) + DB::table('users')->select(DB::raw('concat(first_name," ",last_name) as full_name, id'))->whereNull('deleted_at')->lists('full_name', 'id'); + // Grab the dropdown lists + $model_list = modelList(); + $statuslabel_list = statusLabelList(); + $location_list = locationsList(); + $manufacturer_list = manufacturerList(); + $category_list = categoryList(); + $supplier_list = suppliersList(); + $assigned_to = assignedToList(); $asset = clone $asset_to_clone; $asset->id = null; diff --git a/app/helpers.php b/app/helpers.php index e6586c20ee..768f368758 100755 --- a/app/helpers.php +++ b/app/helpers.php @@ -1,18 +1,57 @@ Lang::get('general.select_model')) + DB::table('models') + ->select(DB::raw('COALESCE(concat(name, " / ",modelno),name) as name, id'))->orderBy('name', 'asc') + ->orderBy('modelno', 'asc') + ->whereNull('deleted_at') + ->lists('name', 'id'); + return $model_list; +} + +function categoryList() { + $category_list = array('' => '') + DB::table('categories')->whereNull('deleted_at')->lists('name', 'id'); + return $category_list; +} + +function suppliersList() { + $supplier_list = array('' => Lang::get('general.select_supplier')) + Supplier::orderBy('name', 'asc')->lists('name', 'id'); + return $supplier_list; +} + +function assignedToList() { + $assigned_to = array('' => Lang::get('general.select_user')) + DB::table('users')->select(DB::raw('concat(first_name," ",last_name) as full_name, id'))->whereNull('deleted_at')->lists('full_name', 'id'); + return $assigned_to; +} + +function statusLabelList() { + $statuslabel_list = Statuslabel::lists('name', 'id'); + return $statuslabel_list; +} + +function locationsList() { + $location_list = array('' => Lang::get('general.select_location')) + Location::lists('name', 'id'); + return $location_list; +} + +function manufacturerList() { + $manufacturer_list = array('' => 'Select One') + Manufacturer::lists('name', 'id'); + return $manufacturer_list; +}