with('group', $group); } /** * Validates and stores the new User Group data. * * @author [A. Gianotto] [name = e(Input::get('name')); $group->permissions = json_encode(Input::get('permission')); if ($group->save()) { return redirect()->to("admin/groups")->with('success', trans('admin/groups/message.success.create')); } return redirect()->back()->withInput()->withErrors($group->getErrors()); } /** * Returns a view that presents a form to edit a User Group. * * @author [A. Gianotto] [decodePermissions(); $selected_array = Helper::selectedPermissionsArray($permissions, $groupPermissions); return View::make('groups/edit', compact('group', 'permissions', 'selected_array', 'groupPermissions')); } /** * Validates and stores the updated User Group data. * * @author [A. Gianotto] [route('groups')->with('error', trans('admin/groups/message.group_not_found', compact('id'))); } $group->name = e(Input::get('name')); $group->permissions = json_encode(Input::get('permission')); if (!config('app.lock_passwords')) { if ($group->save()) { return redirect()->to("admin/groups")->with('success', trans('admin/groups/message.success.update')); } return redirect()->back()->withInput()->withErrors($group->getErrors()); } else { return redirect()->route('update/group', $id)->withInput()->with('error', 'Denied! Editing groups is not allowed in the demo.'); } } /** * Validates and deletes the User Group. * * @author [A. Gianotto] [delete(); // Redirect to the group management page return redirect()->route('groups')->with('success', trans('admin/groups/message.success.delete')); } catch (GroupNotFoundException $e) { // Redirect to the group management page return redirect()->route('groups')->with('error', trans('admin/groups/message.group_not_found', compact('id'))); } } else { return redirect()->route('groups')->with('error', trans('general.feature_disabled')); } } /** * Generates the JSON used to display the User Group listing. * * @author [A. Gianotto] [] * @since [v2.0] * @return String JSON */ public function getDatatable() { if (Input::has('offset')) { $offset = e(Input::get('offset')); } else { $offset = 0; } if (Input::has('limit')) { $limit = e(Input::get('limit')); } else { $limit = 50; } if (Input::get('sort')=='name') { $sort = 'first_name'; } else { $sort = e(Input::get('sort')); } // Grab all the groups $groups = Group::with('users')->orderBy('name', 'ASC'); //$users = Company::scopeCompanyables($users); if (Input::has('search')) { $groups = $users->TextSearch(e(Input::get('search'))); } $order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $allowed_columns = [ 'name','created_at' ]; $sort = in_array($sort, $allowed_columns) ? $sort : 'name'; $groups = $groups->orderBy($sort, $order); $groupsCount = $groups->count(); $groups = $groups->skip($offset)->take($limit)->get(); $rows = array(); foreach ($groups as $group) { $group_names = ''; $inout = ''; $actions = ''; $actions .= ' '; if (!config('app.lock_passwords')) { $actions .= ' '; } else { $actions .= ' '; } $actions .= ''; $rows[] = array( 'id' => $group->id, 'name' => $group->name, 'users' => $group->users->count(), 'created_at' => $group->created_at->format('Y-m-d'), 'actions' => ($actions) ? $actions : '', ); } $data = array('total'=>$groupsCount, 'rows'=>$rows); return $data; } }