App\Http\Controllers\GroupsController Class Reference

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

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

Public Member Functions

 getIndex ()
 Returns a view that invokes the ajax tables which actually contains the content for the user group listing, which is generated in getDatatable. More...
 
 getCreate ()
 Returns a view that displays a form to create a new User Group. More...
 
 postCreate ()
 Validates and stores the new User Group data. More...
 
 getEdit ($id=null)
 Returns a view that presents a form to edit a User Group. More...
 
 postEdit ($id=null)
 Validates and stores the updated User Group data. More...
 
 getDelete ($id=null)
 Validates and deletes the User Group. More...
 
 getDatatable ()
 Generates the JSON used to display the User Group listing. More...
 

Detailed Description

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

Version
v1.0

Definition at line 19 of file GroupsController.php.

Member Function Documentation

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

Returns a view that displays a form to create a new User Group.

Author
[A. Gianotto] [<snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
GroupsController::postCreate()
Since
[v1.0]
Returns
View

Definition at line 44 of file GroupsController.php.

45  {
46  $group = new Group;
47  // Get all the available permissions
48  $permissions = config('permissions');
49 
50 
51  $selectedPermissions = Input::old('permissions', array());
52 
53  // Show the page
54  return View::make('groups/edit', compact('permissions', 'selectedPermissions'))->with('group', $group);
55  }
App\Http\Controllers\GroupsController::getDatatable ( )

Generates the JSON used to display the User Group listing.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v2.0]
Returns
String JSON

Definition at line 174 of file GroupsController.php.

175  {
176 
177  if (Input::has('offset')) {
178  $offset = e(Input::get('offset'));
179  } else {
180  $offset = 0;
181  }
182 
183  if (Input::has('limit')) {
184  $limit = e(Input::get('limit'));
185  } else {
186  $limit = 50;
187  }
188 
189  if (Input::get('sort')=='name') {
190  $sort = 'first_name';
191  } else {
192  $sort = e(Input::get('sort'));
193  }
194 
195  // Grab all the groups
196  $groups = Group::with('users')->orderBy('name', 'ASC');
197  //$users = Company::scopeCompanyables($users);
198 
199  if (Input::has('search')) {
200  $groups = $users->TextSearch(e(Input::get('search')));
201  }
202 
203  $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
204 
205  $allowed_columns =
206  [
207  'name','created_at'
208  ];
209 
210  $sort = in_array($sort, $allowed_columns) ? $sort : 'name';
211  $groups = $groups->orderBy($sort, $order);
212 
213  $groupsCount = $groups->count();
214  $groups = $groups->skip($offset)->take($limit)->get();
215  $rows = array();
216 
217  foreach ($groups as $group) {
218  $group_names = '';
219  $inout = '';
220  $actions = '<nobr>';
221 
222  $actions .= '<a href="' . route('update/group', $group->id) . '" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> ';
223 
224  if (!config('app.lock_passwords')) {
225  $actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('delete/group', $group->id) . '" data-content="'.trans('admin/groups/message.delete.confirm').'" data-title="Delete ' . htmlspecialchars($group->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a> ';
226  } else {
227  $actions .= ' <span class="btn delete-asset btn-danger btn-sm disabled"><i class="fa fa-trash icon-white"></i></span>';
228  }
229 
230  $actions .= '</nobr>';
231 
232  $rows[] = array(
233  'id' => $group->id,
234  'name' => $group->name,
235  'users' => $group->users->count(),
236  'created_at' => $group->created_at->format('Y-m-d'),
237  'actions' => ($actions) ? $actions : '',
238  );
239  }
240 
241  $data = array('total'=>$groupsCount, 'rows'=>$rows);
242  return $data;
243  }
App\Http\Controllers\GroupsController::getDelete (   $id = null)

Validates and deletes the User Group.

Author
[A. Gianotto] [<snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
GroupsController::getEdit()
Parameters
int$id
Since
[v1.0]
Returns
Redirect

Definition at line 145 of file GroupsController.php.

146  {
147  if (!config('app.lock_passwords')) {
148  try {
149  // Get group information
150  $group = Sentry::getGroupProvider()->findById($id);
151 
152  // Delete the group
153  $group->delete();
154 
155  // Redirect to the group management page
156  return Redirect::route('groups')->with('success', trans('admin/groups/message.success.delete'));
157  } catch (GroupNotFoundException $e) {
158  // Redirect to the group management page
159  return Redirect::route('groups')->with('error', trans('admin/groups/message.group_not_found', compact('id')));
160  }
161  } else {
162  return Redirect::route('groups')->with('error', trans('general.feature_disabled'));
163  }
164  }
App\Http\Controllers\GroupsController::getEdit (   $id = null)

Returns a view that presents a form to edit a User Group.

Author
[A. Gianotto] [<snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
GroupsController::postEdit()
Parameters
int$id
Since
[v1.0]
Returns
View

Definition at line 92 of file GroupsController.php.

93  {
94  $group = Group::find($id);
95  $group->name = e(Input::get('name'));
96  $group->permissions = json_decode($group->permissions, true);
97  $permissions = config('permissions');
98 
99  // Show the page
100  return View::make('groups/edit', compact('group', 'permissions','allpermissions'));
101  }
App\Http\Controllers\GroupsController::getIndex ( )

Returns a view that invokes the ajax tables which actually contains the content for the user group listing, which is generated in getDatatable.

Author
[A. Gianotto] [<snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
GroupsController::getDatatable() method that generates the JSON response
Since
[v1.0]
Returns
View

Definition at line 30 of file GroupsController.php.

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

Validates and stores the new User Group data.

Author
[A. Gianotto] [<snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
GroupsController::getCreate()
Since
[v1.0]
Returns
Redirect

Definition at line 65 of file GroupsController.php.

66  {
67  // create a new group instance
68  $group = new Group();
69  // Update the consumable data
70  $group->name = e(Input::get('name'));
71 
72  // Was the consumable created?
73  if ($group->save()) {
74  // Redirect to the new consumable page
75  return Redirect::to("admin/groups")->with('success', trans('admin/groups/message.create.success'));
76  }
77 
78  return Redirect::back()->withInput()->withErrors($group->getErrors());
79 
80 
81  }
App\Http\Controllers\GroupsController::postEdit (   $id = null)

Validates and stores the updated User Group data.

Author
[A. Gianotto] [<snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
See also
GroupsController::getEdit()
Parameters
int$id
Since
[v1.0]
Returns
Redirect

Definition at line 112 of file GroupsController.php.

113  {
114 
115  if (!$group = Group::find($id)) {
116  return Redirect::route('groups')->with('error', trans('admin/groups/message.group_not_found', compact('id')));
117 
118  }
119  $group->name = e(Input::get('name'));
120 
121  if (!config('app.lock_passwords')) {
122 
123  // Was the consumable created?
124  if ($group->save()) {
125  // Redirect to the new consumable page
126  return Redirect::to("admin/groups")->with('success', trans('admin/groups/message.create.success'));
127  }
128  return Redirect::back()->withInput()->withErrors($group->getErrors());
129 
130  } else {
131  return Redirect::route('update/group', $id)->withInput()->with('error', 'Denied! Editing groups is not allowed in the demo.');
132  }
133 
134  }

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