App\Http\Controllers\StatuslabelsController Class Reference

This controller handles all actions related to Status Labels for the Snipe-IT Asset Management application. More...

Inheritance diagram for App\Http\Controllers\StatuslabelsController:
App\Http\Controllers\Controller

Public Member Functions

 getIndex ()
 Show a list of all the statuslabels. More...
 
 getCreate ()
 Statuslabel create. More...
 
 postCreate ()
 Statuslabel create form processing. More...
 
 store ()
 
 getEdit ($statuslabelId=null)
 Statuslabel update. More...
 
 postEdit ($statuslabelId=null)
 Statuslabel update form processing page. More...
 
 getDelete ($statuslabelId)
 Delete the given Statuslabel. More...
 
 getDatatable ()
 

Detailed Description

This controller handles all actions related to Status Labels for the Snipe-IT Asset Management application.

Version
v1.0

Definition at line 23 of file StatuslabelsController.php.

Member Function Documentation

App\Http\Controllers\StatuslabelsController::getCreate ( )

Statuslabel create.

Returns
View

Definition at line 43 of file StatuslabelsController.php.

44  {
45  // Show the page
46  $statuslabel = new Statuslabel;
47  $use_statuslabel_type = $statuslabel->getStatuslabelType();
48  $statuslabel_types = Helper::statusTypeList();
49 
50  return View::make('statuslabels/edit', compact('statuslabel_types', 'statuslabel'))->with('use_statuslabel_type', $use_statuslabel_type);
51  }
static statusTypeList()
Definition: Helper.php:109
App\Http\Controllers\StatuslabelsController::getDatatable ( )

Definition at line 210 of file StatuslabelsController.php.

211  {
212  $statuslabels = Statuslabel::select(array('id','name','deployable','pending','archived'))
213  ->whereNull('deleted_at');
214 
215  if (Input::has('search')) {
216  $statuslabels = $statuslabels->TextSearch(e(Input::get('search')));
217  }
218 
219  if (Input::has('offset')) {
220  $offset = e(Input::get('offset'));
221  } else {
222  $offset = 0;
223  }
224 
225  if (Input::has('limit')) {
226  $limit = e(Input::get('limit'));
227  } else {
228  $limit = 50;
229  }
230 
231  $allowed_columns = ['id','name'];
232  $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
233  $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
234 
235  $statuslabels->orderBy($sort, $order);
236 
237  $statuslabelsCount = $statuslabels->count();
238  $statuslabels = $statuslabels->skip($offset)->take($limit)->get();
239 
240  $rows = array();
241 
242  foreach ($statuslabels as $statuslabel) {
243 
244  if ($statuslabel->deployable == 1) {
245  $label_type = trans('admin/statuslabels/table.deployable');
246  } elseif ($statuslabel->pending == 1) {
247  $label_type = trans('admin/statuslabels/table.pending');
248  } elseif ($statuslabel->archived == 1) {
249  $label_type = trans('admin/statuslabels/table.archived');
250  } else {
251  $label_type = trans('admin/statuslabels/table.undeployable');
252  }
253 
254  $actions = '<a href="'.route('update/statuslabel', $statuslabel->id).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><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/statuslabel', $statuslabel->id).'" data-content="'.trans('admin/statuslabels/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($statuslabel->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
255 
256  $rows[] = array(
257  'id' => e($statuslabel->id),
258  'type' => e($label_type),
259  'name' => e($statuslabel->name),
260  'actions' => $actions
261  );
262  }
263 
264  $data = array('total' => $statuslabelsCount, 'rows' => $rows);
265 
266  return $data;
267 
268  }
App\Http\Controllers\StatuslabelsController::getDelete (   $statuslabelId)

Delete the given Statuslabel.

Parameters
int$statuslabelId
Returns
Redirect

Definition at line 184 of file StatuslabelsController.php.

185  {
186  // Check if the Statuslabel exists
187  if (is_null($statuslabel = Statuslabel::find($statuslabelId))) {
188  // Redirect to the blogs management page
189  return Redirect::to('admin/settings/statuslabels')->with('error', trans('admin/statuslabels/message.not_found'));
190  }
191 
192 
193  if ($statuslabel->has_assets() > 0) {
194 
195  // Redirect to the asset management page
196  return Redirect::to('admin/settings/statuslabels')->with('error', trans('admin/statuslabels/message.assoc_users'));
197  } else {
198 
199  $statuslabel->delete();
200 
201  // Redirect to the statuslabels management page
202  return Redirect::to('admin/settings/statuslabels')->with('success', trans('admin/statuslabels/message.delete.success'));
203  }
204 
205 
206 
207  }
App\Http\Controllers\StatuslabelsController::getEdit (   $statuslabelId = null)

Statuslabel update.

Parameters
int$statuslabelId
Returns
View

Definition at line 124 of file StatuslabelsController.php.

125  {
126  // Check if the Statuslabel exists
127  if (is_null($statuslabel = Statuslabel::find($statuslabelId))) {
128  // Redirect to the blogs management page
129  return Redirect::to('admin/settings/statuslabels')->with('error', trans('admin/statuslabels/message.does_not_exist'));
130  }
131 
132  $use_statuslabel_type = $statuslabel->getStatuslabelType();
133 
134  $statuslabel_types = array('' => trans('admin/hardware/form.select_statustype')) + array('undeployable' => trans('admin/hardware/general.undeployable')) + array('pending' => trans('admin/hardware/general.pending')) + array('archived' => trans('admin/hardware/general.archived')) + array('deployable' => trans('admin/hardware/general.deployable'));
135 
136  return View::make('statuslabels/edit', compact('statuslabel', 'statuslabel_types'))->with('use_statuslabel_type', $use_statuslabel_type);
137  }
App\Http\Controllers\StatuslabelsController::getIndex ( )

Show a list of all the statuslabels.

Returns
View

Definition at line 31 of file StatuslabelsController.php.

32  {
33  // Show the page
34  return View::make('statuslabels/index', compact('statuslabels'));
35  }
App\Http\Controllers\StatuslabelsController::postCreate ( )

Statuslabel create form processing.

Returns
Redirect

Definition at line 59 of file StatuslabelsController.php.

60  {
61 
62  // create a new model instance
63  $statuslabel = new Statuslabel();
64  $statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types'));
65 
66  // Save the Statuslabel data
67  $statuslabel->name = e(Input::get('name'));
68  $statuslabel->user_id = Auth::user()->id;
69  $statuslabel->notes = e(Input::get('notes'));
70  $statuslabel->deployable = $statustype['deployable'];
71  $statuslabel->pending = $statustype['pending'];
72  $statuslabel->archived = $statustype['archived'];
73 
74 
75  // Was the asset created?
76  if ($statuslabel->save()) {
77  // Redirect to the new Statuslabel page
78  return Redirect::to("admin/settings/statuslabels")->with('success', trans('admin/statuslabels/message.create.success'));
79  }
80 
81  return Redirect::back()->withInput()->withErrors($statuslabel->getErrors());
82 
83  }
static getStatuslabelTypesForDB($type)
Definition: Statuslabel.php:45
App\Http\Controllers\StatuslabelsController::postEdit (   $statuslabelId = null)

Statuslabel update form processing page.

Parameters
int$statuslabelId
Returns
Redirect

Definition at line 146 of file StatuslabelsController.php.

147  {
148  // Check if the Statuslabel exists
149  if (is_null($statuslabel = Statuslabel::find($statuslabelId))) {
150  // Redirect to the blogs management page
151  return Redirect::to('admin/settings/statuslabels')->with('error', trans('admin/statuslabels/message.does_not_exist'));
152  }
153 
154 
155  // Update the Statuslabel data
156  $statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types'));
157  $statuslabel->name = e(Input::get('name'));
158  $statuslabel->notes = e(Input::get('notes'));
159  $statuslabel->deployable = $statustype['deployable'];
160  $statuslabel->pending = $statustype['pending'];
161  $statuslabel->archived = $statustype['archived'];
162 
163 
164  // Was the asset created?
165  if ($statuslabel->save()) {
166  // Redirect to the saved Statuslabel page
167  return Redirect::to("admin/settings/statuslabels/")->with('success', trans('admin/statuslabels/message.update.success'));
168  } else {
169  return Redirect::back()->withInput()->withErrors($statuslabel->getErrors());
170  }
171 
172 
173  // Redirect to the Statuslabel management page
174  return Redirect::to("admin/settings/statuslabels/$statuslabelId/edit")->with('error', trans('admin/statuslabels/message.update.error'));
175 
176  }
static getStatuslabelTypesForDB($type)
Definition: Statuslabel.php:45
App\Http\Controllers\StatuslabelsController::store ( )

Definition at line 85 of file StatuslabelsController.php.

86  {
87 
88  // create a new model instance
89  $statuslabel = new Statuslabel();
90  $statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('modal-statuslabel_types'));
91 
92  // attempt validation
93  if ($statuslabel->validate($new)) {
94 
95  // Save the Statuslabel data
96  $statuslabel->name = e(Input::get('name'));
97  $statuslabel->user_id = Auth::user()->id;
98  $statuslabel->notes = '';
99  $statuslabel->deployable = $statustype['deployable'];
100  $statuslabel->pending = $statustype['pending'];
101  $statuslabel->archived = $statustype['archived'];
102 
103  // Was the asset created?
104  if ($statuslabel->save()) {
105  // Redirect to the new Statuslabel page
106  return JsonResponse::create($statuslabel);
107  } else {
108  return JsonResponse::create(["error" => "Couldn't save Statuslabel"], 500);
109  }
110  } else {
111  // failure
112  $errors = $statuslabel->getErrors();
113  return JsonResponse::create(["error" => "Failed validation: ".print_r($errors->all('<li>:message</li>'), true)], 500);
114  }
115  }
static getStatuslabelTypesForDB($type)
Definition: Statuslabel.php:45

The documentation for this class was generated from the following file: