public function actionNewGroup() { $model = new ForumUserGroup(); $model->section_id = $this->sectionId; if (!UserAccess::get()->isSectionAdmin($model->section_id)) { Messages::get()->error("Not enough rights to add a new user group for this forum!"); $this->goBack(); die; } if (isset($_POST['ForumUserGroup'])) { $model->setAttributes($_POST['ForumUserGroup']); if ($model->save()) { Messages::get()->success("Group saved!"); $this->goToAction('groups'); } } $this->setPageLayout('group'); $this->assign('model', $model); }
/** * Creates a new section + default user groups + a single user title. Use "Main" name if you only have one. * @param string $name * @param int $userId * @return int */ public static function createNew($name = "Main", $userId) { $section = new self(); $section->name = $name; $section->owner_user_id = $userId; if (!$section->save()) { return false; } if ("Main" == $name) { App::get()->debug("Main section detected. Setting ID to 0!"); $section->id = 0; $section->save(); } App::get()->debug("Section {$name}: #{$section->id} created!"); $group = new ForumUserGroup(); $group->section_id = $section->id; $group->full_name = 'Visitors'; $group->html_class = 'visitors'; $group->admin = $group->moderator = $group->newthread = $group->threadreply = 0; $group->canread = 1; $group->save(); App::get()->debug("Group {$group->full_name}: #{$group->id} created!"); $section->default_visitors_group_id = $group->id; $group->full_name = "Members"; $group->html_class = "members"; $group->newthread = $group->threadreply = 1; $group->saveAsNew(); App::get()->debug("Group {$group->full_name}: #{$group->id} created!"); $section->default_members_group_id = $group->id; $section->save(); App::get()->debug("Section updated with default group ids!"); $group->full_name = "Moderators"; $group->html_class = "moderators"; $group->moderator = 1; $group->saveAsNew(); App::get()->debug("Group {$group->full_name}: #{$group->id} created!"); $group->full_name = "Admins"; $group->html_class = "admins"; $group->admin = 1; $group->saveAsNew(); App::get()->debug("Group {$group->full_name}: #{$group->id} created!"); $title = new ForumTitle(); $title->section_id = $section->id; $title->title = "New Comer"; $title->icon = "default.png"; $title->description = $title->title; $title->save(); App::get()->debug("Title {$title->title}: #{$title->id} created!"); $user = new ForumUser2Section(); $user->user_id = $userId; $user->section_id = $section->id; $user->group_id = $group->id; $user->title_id = $title->id; $user->banned = $user->muted = 0; $user->signature = ''; $user->save(); App::get()->debug("User #{$userId} assigned to section as admin! (Group: #{$group->id})"); return $section->id; }