public function addModerator()
 {
     $group = Group::name(request('groupname'))->firstOrFail();
     $user = User::name(request('username'))->firstOrFail();
     if (!user()->isAdmin($group)) {
         abort(403, 'Access denied');
     }
     if ($user->isModerator($group)) {
         return redirect()->route('group_moderators', $group->urlname);
     }
     if ($user->isBlocking($group)) {
         return redirect()->route('group_moderators', $group->urlname)->with('danger_msg', 'Nie możesz dodać wybranego użytkownika jako moderatora, ponieważ zablokował tą grupę.');
     }
     $moderator = new GroupModerator();
     $moderator->group()->associate($group);
     $moderator->user()->associate($user);
     $type = request('admin') == 'on' ? 'admin' : 'moderator';
     $moderator->type = $type;
     $moderator->save();
     // Send notification to new moderator
     /*
     $this->sendNotifications([$user->getKey()], function ($notification) use ($moderator, $group) {
         $notification->type = 'moderator';
     
         $positionTitle = $moderator->type == 'admin' ? 'administratorem' : 'moderatorem';
         $notification->setTitle('Zostałeś ' . $positionTitle . ' w grupie ' . $group->urlname);
     
         $notification->group()->associate($group);
         $notification->save();
     });
     */
     // Log this action
     $action = new ModeratorAction();
     $action->type = ModeratorAction::TYPE_MODERATOR_ADDED;
     $action->is_admin = $moderator->type == 'admin' ? true : false;
     $action->moderator()->associate(user());
     $action->target()->associate($user);
     $action->group()->associate($group);
     $action->save();
     \Cache::tags(['user.moderated-groups', 'u.' . $user->getKey()])->flush();
     return redirect()->route('group_moderators', $group->urlname);
 }
Beispiel #2
0
 public function createGroup(Request $request)
 {
     // Require 15 minutes break before creating next group
     $group = Group::where('creator_id', Auth::id())->orderBy('created_at', 'desc')->first();
     if ($group && $group->created_at->diffInMinutes() < 30) {
         Input::flash();
         $diff = 30 - $group->created_at->diffInMinutes();
         $minutes = Lang::choice('pluralization.minutes', $diff);
         return Redirect::action('GroupController@showCreateForm')->with('danger_msg', 'Kolejną grupę będziesz mógł utworzyć za ' . $minutes);
     }
     $this->validate($request, ['urlname' => 'required|min:3|max:32|unique:groups|reserved_groupnames|regex:/^[a-zA-Z0-9_żźćńółęąśŻŹĆĄŚĘŁÓŃ]+$/i', 'groupname' => 'required|min:3|max:50', 'desc' => 'max:255']);
     $group = new Group();
     $group->urlname = Input::get('urlname');
     $group->name = Input::get('groupname');
     $group->description = Input::get('description');
     $group->creator()->associate(Auth::user());
     $group->save();
     $moderator = new GroupModerator();
     $moderator->group()->associate($group);
     $moderator->user()->associate(Auth::user());
     $moderator->type = 'admin';
     $moderator->save();
     return Redirect::route('group_contents', $group->urlname)->with('success_msg', 'Nowa grupa o nazwie ' . $group->name . ' została utworzona.');
 }