public function __construct() { $this->middleware('admin'); $root = User::withTrashed()->find(User::ROOT_USER); if (!$root) { $root = new User(); $root->name = 'Root'; $root->acronym = 'root'; $root->display_name = 'Root User'; $root->user_id = null; $root->save(); $root->id = User::ROOT_USER; $root->save(); } else { if ($root->trashed()) { $root->restore(); } if ($root->user_id != null) { $root->user_id = null; $root->save(); } } $more = User::withTrashed()->whereUserId(null)->where('id', '<>', User::ROOT_USER); if ($more->count() > 0) { $more->update(['user_id' => User::ROOT_USER]); } }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { try { $model = $this->getModel($id); $users = [null => 'Empty'] + User::withTrashed()->lists('display_name', 'id'); return view($this->edit_view, compact(['model', 'users'])); } catch (Exception $e) { Flash::warning(trans($this->resource_name . 'not_found', ['model' => $this->model_name, 'id' => $id])); return $this->index(); } }
static function treeUsers($route_show, $id, $indent, $name) { if ($indent < 15) { $users = User::withTrashed()->whereUserId($id)->orderBy('name')->get(); if ($users->count() > 0) { static::$treeResult .= PHP_EOL . '<ul>'; foreach ($users as $user) { static::$treeResult .= PHP_EOL . '<li>' . link_to_route($route_show, $user->name, ['id' => $user->id]) . ' - ' . ($user->trashed() ? '<del>' . e($user->display_name) . '</del>' : e($user->display_name)); static::treeUsers($route_show, $user->id, $indent + 1, $user->name); static::$treeResult .= PHP_EOL . '</li>'; } static::$treeResult .= PHP_EOL . '</ul>'; } } }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { if ($id == Folder::ROOT_FOLDER) { Flash::error(trans($this->resource_name . 'forbidden')); return redirect(route($this->show_route, [$id])); } try { $model = $this->getModel($id); $excluded = $model->children()->lists('id'); $excluded[] = $model->id; $folders = Folder::ListItems($excluded); $users = User::withTrashed()->lists('display_name', 'id'); $roots = Folder::whereFolderId(Folder::ROOT_FOLDER)->orWhere('id', Folder::ROOT_FOLDER)->withTrashed()->lists('name', 'id'); return view($this->edit_view, compact(['model', 'folders', 'users', 'roots'])); } catch (Exception $e) { if ($e instanceof PDOException) { Flash::error($e->errorInfo[2]); } else { Flash::warning(trans($this->resource_name . 'not_found', ['model' => $this->model_name, 'id' => $id])); } return $this->index(); } }