public function actionIndex() { $model = ForumUser2Section::model(); if (isset($_GET['ForumUser2Section'])) { $model->setAttributes($_GET['ForumUser2Section']); } $this->assign("model", $model); }
public function actionControlPanel() { if (WebApp::get()->user()->isGuest()) { $this->goToPage('user', 'login', [], ''); } $user = ForumUser2Section::findByAttributes(['user_id' => WebApp::get()->user()->id, 'section_id' => $this->sectionId]); $user->icon = $user->user->icon; if (isset($_POST['ForumUser2Section'])) { $user->signature = $_POST['ForumUser2Section']['signature']; $user->save(); $user->changeIcon(); $user->icon = $user->user->icon; WebApp::get()->user()->setState('icon', $user->user->icon); } $this->assign('model', $user); }
/** * @param $sectionId * @return ForumUser2Section */ public function getSectionUser($sectionId) { if (!$this->sectionUser) { $this->sectionUser = ForumUser2Section::findByAttributes(['section_id' => $sectionId, 'user_id' => $this->user_id], ['with' => ['group', 'title']]); if (!$this->sectionUser) { ForumUser2Section::makeVisitor($this->user_id, $sectionId); } } return $this->sectionUser; }
/** * Return list of relations for current model * @return array */ public static function getRelations() { return ['author' => [DbRelations::BELONGS_TO, '\\app\\models\\User', 'user_id'], 'thread' => [DbRelations::BELONGS_TO, '\\mpf\\modules\\forum\\models\\ForumThread', 'thread_id'], 'sectionAuthor' => DbRelation::belongsTo(ForumUser2Section::className(), 'user_id')->hasAttributeValue('section_id', 'currentSection'), 'editor' => [DbRelations::BELONGS_TO, '\\app\\models\\User', 'edit_user_id'], 'deletedBy' => [DbRelations::BELONGS_TO, '\\app\\models\\User', 'deleted_user_id'], 'authorGroup' => [DbRelations::BELONGS_TO, '\\mpf\\modules\\forum\\models\\ForumUserGroup', 'user_group_id'], 'replies' => [DbRelations::HAS_MANY, '\\mpf\\modules\\forum\\models\\ForumReplySecond', 'reply_id'], 'myVote' => DbRelation::hasOne(ForumReplyVote::className())->columnsEqual('id', 'reply_id')->hasValue('level', 1)->hasValue('user_id', WebApp::get()->user()->isConnected() ? WebApp::get()->user()->id : 0)]; }
/** * 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 actionUsers() { foreach (['muted', 'banned', 'group_id', 'title_id'] as $field) { if (isset($_POST[$field])) { ForumUser2Section::update($_POST['id'], [$field => $_POST[$field]]); Messages::get()->success("User saved!"); $this->goBack(); } } $model = ForumUser2Section::model(); $model->section_id = $this->sectionId; if (isset($_GET['ForumUser2Section'])) { $model->setAttributes($_GET['ForumUser2Section']); } $this->assign('model', $model); $this->assign('groups', ArrayHelper::get()->transform(ForumUserGroup::findAllBySection($this->sectionId), ['id' => 'full_name'])); $this->assign('titles', ArrayHelper::get()->transform(ForumTitle::findAll(), ['id' => 'title'])); }
public function reloadRights() { if (WebApp::get()->user()->isGuest()) { return false; // no rights to load if no user is logged in } Session::get()->delete($this->sessionKey); $user2Sections = ForumUser2Section::findAllByAttributes(['user_id' => WebApp::get()->user()->id]); $this->user2Sections = []; foreach ($user2Sections as $user) { $this->user2Sections[$user->section_id] = ['muted' => $user->muted, 'banned' => $user->banned, 'title_id' => $user->title_id, 'title_string' => $user->title ? $user->title->title : '', 'group_id' => $user->group_id, 'group_string' => $user->group->full_name, 'member_since' => $user->member_since, 'groupRights' => ['admin' => $user->group->admin, 'moderator' => $user->group->moderator, 'newthread' => $user->group->newthread, 'threadreply' => $user->group->threadreply, 'canread' => $user->group->canread]]; } Session::get()->set($this->sessionKey, ['user2Sections' => $this->user2Sections, 'userId' => WebApp::get()->user()->id]); }