/** * 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; }
public function actionNewTitle() { $model = new ForumTitle(); $model->section_id = $this->sectionId; if (isset($_POST['ForumTitle'])) { $model->setAttributes($_POST['ForumTitle']); if ($model->save()) { if (false != ($icon = $this->uploadImage("titles", 'icon', $model->id))) { if ($model->icon && $model->icon != "default.png" && $model->icon != $icon) { @unlink($this->getUploadFolder() . 'titles' . DIRECTORY_SEPARATOR . $model->icon); } $model->icon = $icon; if (!$model->save()) { @unlink($this->getUploadFolder() . 'titles' . DIRECTORY_SEPARATOR . $model->icon); } } Messages::get()->success("Title saved!"); $this->goToAction('titles'); } } $this->setPageLayout('title'); $this->assign('model', $model); }