GroupsController.php
Go to the documentation of this file.
1 <?php
2 namespace App\Http\Controllers;
3 
4 use Config;
5 use Input;
6 use Lang;
7 use Redirect;
9 use Validator;
10 use View;
12 
20 {
30  public function getIndex()
31  {
32  // Show the page
33  return View::make('groups/index', compact('groups'));
34  }
35 
44  public function getCreate()
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  }
56 
65  public function postCreate()
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  }
82 
92  public function getEdit($id = null)
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  }
102 
112  public function postEdit($id = null)
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  }
135 
145  public function getDelete($id = null)
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  }
165 
166 
174  public function getDatatable()
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  }
244 }
getDatatable()
Generates the JSON used to display the User Group listing.
getEdit($id=null)
Returns a view that presents a form to edit a User Group.
getCreate()
Returns a view that displays a form to create a new User Group.
getDelete($id=null)
Validates and deletes the User Group.
This controller handles all actions related to User Groups for the Snipe-IT Asset Management applicat...
postEdit($id=null)
Validates and stores the updated User Group data.
postCreate()
Validates and stores the new User Group data.
getIndex()
Returns a view that invokes the ajax tables which actually contains the content for the user group li...