コード例 #1
0
ファイル: Manage.php プロジェクト: mpf-soft/social-modules
 /**
  * Edit groups, change default group and delete groups.
  */
 public function actionGroups()
 {
     if (isset($_POST['changedefaultvisitorsgroup'])) {
         if (ForumSection::findByPk($this->sectionId)->setDefaultGroup($_POST['group'], 'visitors')) {
             Messages::get()->success("Default group updated!");
             $this->goBack();
         }
     }
     if (isset($_POST['changedefaultmembersgroup'])) {
         if (ForumSection::findByPk($this->sectionId)->setDefaultGroup($_POST['group'], 'members')) {
             Messages::get()->success("Default group updated!");
             $this->goBack();
         }
     }
     $model = ForumUserGroup::model();
     $model->section_id = $this->sectionId;
     if (isset($_GET['ForumUserGroup'])) {
         $model->setAttributes($_GET['ForumUserGroup']);
     }
     $this->assign('model', $model);
 }
コード例 #2
0
ファイル: groups.php プロジェクト: mpf-soft/social-modules
</a>
    <?php 
echo \mpf\web\helpers\Form::get()->openForm(['method' => 'post', 'style' => 'display:none;']);
?>
    <?php 
echo \mpf\web\helpers\Form::get()->select('group', \mpf\helpers\ArrayHelper::get()->transform(\mpf\modules\forum\models\ForumUserGroup::findAllByAttributes(['section_id' => $this->sectionId]), ['id' => 'full_name']));
?>
    <input type="submit" name="changedefaultvisitorsgroup" value="Update"/>
    <?php 
echo \mpf\web\helpers\Form::get()->closeForm();
?>
</div>
<div class="forum-default-group-line">
    <span>Default Members Group:</span>
    <a href="#"><?php 
echo \mpf\modules\forum\models\ForumSection::findByPk($this->sectionId)->defaultMembersGroup->full_name;
?>
</a>
    <?php 
echo \mpf\web\helpers\Form::get()->openForm(['method' => 'post', 'style' => 'display:none;']);
?>
    <?php 
echo \mpf\web\helpers\Form::get()->select('group', \mpf\helpers\ArrayHelper::get()->transform(\mpf\modules\forum\models\ForumUserGroup::findAllByAttributes(['section_id' => $this->sectionId]), ['id' => 'full_name']));
?>
    <input type="submit" name="changedefaultmembersgroup" value="Update"/>
    <?php 
echo \mpf\web\helpers\Form::get()->closeForm();
?>
</div>

コード例 #3
0
 public function beforeAction($actionName)
 {
     $key = Config::value('FORUM_SECTION_ID_KEY');
     switch (Config::value('FORUM_SECTION_ID_SOURCE')) {
         case 'get':
             if (isset($_GET[$key])) {
                 $this->sectionId = $_GET[$key];
             }
             break;
         case 'post':
             if (isset($_POST[$key])) {
                 $this->sectionId = $_POST[$key];
             }
             break;
         case 'session':
             if (Session::get()->exists($key)) {
                 $this->sectionId = Session::get()->value($key);
             }
             break;
     }
     if (!in_array($actionName, ['notFound', 'accesDenied'])) {
         $section = ForumSection::findByPk($this->sectionId);
         if (!$section) {
             $this->goToPage('special', 'notFound');
         }
         $this->forumTitle = str_replace('__SECTION__', 'Main' == $section->name ? '' : $section->name . ' ', $this->forumTitle);
     }
     return parent::beforeAction($actionName);
 }
コード例 #4
0
 /**
  * @param ForumUser2Section[] $sections
  * @param $limit
  * @param $offset
  * @param null $sectionId
  * @return array|static[]
  */
 protected static function _findRecent($sections, $limit, $offset, $sectionId = null)
 {
     $guest = false;
     $sectionsIds = [];
     if (1 === count($sections) && is_null($sections[0])) {
         if (is_null($sectionId)) {
             return [];
         }
         $sectionsIds = [$sectionId];
         $guest = true;
     } elseif (count($sections)) {
         $sectionsIds = ArrayHelper::get()->transform($sections, 'section_id');
     }
     $userId = WebApp::get()->user()->isConnected() ? WebApp::get()->user()->id : 0;
     $reload = !WebApp::get()->cache()->exists('User:'******':visibleSubcategories');
     $ids = [];
     if (!$reload) {
         $info = WebApp::get()->cache()->value('User:'******':visibleSubcategories');
         if ($info['time'] < time() - 720) {
             //force refresh once every 30m
             $reload = true;
         } else {
             $ids = $info['categories'];
         }
     }
     if ($reload) {
         $condition = new ModelCondition(['model' => ForumSubcategory::className()]);
         $condition->with = ['category'];
         if ($guest) {
             $groups = [ForumSection::findByPk($sectionId)->default_visitors_group_id];
         } else {
             $groups = ArrayHelper::get()->transform($sections, 'group_id');
         }
         if ($groups) {
             $groups = implode(', ', $groups);
             $condition->join = "LEFT JOIN forum_groups2categories ON (forum_groups2categories.category_id = category.id AND forum_groups2categories.group_id IN ({$groups}))";
             $condition->addCondition("forum_groups2categories.canread IS NULL OR forum_groups2categories.canread = 1");
             $condition->addInCondition('category.section_id', $sectionsIds);
             $categories = ForumSubcategory::findAll($condition);
         } else {
             $categories = [];
         }
         $ids = [];
         foreach ($categories as $cat) {
             if (!isset($ids[$cat->category->section_id])) {
                 $ids[$cat->category->section_id] = [];
             }
             $ids[$cat->category->section_id][] = $cat->id;
         }
         WebApp::get()->cache()->set('User:'******':visibleSubcategories', ['time' => time(), 'categories' => $ids]);
     }
     $finalIDs = [];
     if ($guest) {
         $finalIDs = $ids[$sectionId];
     } else {
         foreach ($sections as $s) {
             if (isset($ids[$s->section_id])) {
                 foreach ($ids[$s->section_id] as $id) {
                     $finalIDs[] = $id;
                 }
             }
         }
     }
     if (!$finalIDs) {
         return [];
     }
     $condition = new ModelCondition(['model' => __CLASS__]);
     $condition->with = ['category', 'subcategory', 'lastActiveUser', 'owner'];
     $condition->addInCondition('subcategory_id', $finalIDs);
     $condition->compareColumn('deleted', 0);
     $condition->order = "GREATEST(IFNULL(t.edit_time, t.create_time), IFNULL(t.last_reply_date, t.create_time)) DESC";
     $condition->limit = $limit;
     $condition->offset = $offset;
     return self::findAll($condition);
 }
コード例 #5
0
 /**
  * @param int $sectionId
  * @param int $categoryId
  * @return bool
  */
 public function canRead($sectionId, $categoryId = null)
 {
     if ($this->isSiteAdmin() || $this->isSiteModerator()) {
         return true;
     }
     if ($this->isBanned($sectionId)) {
         return false;
         // can't read if it's banned
     }
     if (isset($this->user2Sections[$sectionId])) {
         $groupId = $this->user2Sections[$sectionId]['group_id'];
         if (is_null($categoryId)) {
             return (bool) $this->user2Sections[$sectionId]['groupRights']['canread'];
         }
     } else {
         if (!isset($this->sections[$sectionId])) {
             $this->sections[$sectionId] = ForumSection::findByPk($sectionId);
         }
         if (!isset($this->sections[$sectionId])) {
             return false;
             // section doesn't exists
         }
         $groupId = $this->sections[$sectionId]->default_visitors_group_id;
     }
     if (is_null($categoryId)) {
         return (bool) ForumUserGroup::findByPk($groupId)->canread;
     }
     $categoryRights = ForumUserGroup::getDb()->table('forum_groups2categories')->where("group_id = :id AND category_id = :cat")->setParams([':id' => $groupId, ':cat' => $categoryId])->first();
     if (!$categoryRights) {
         return (bool) ForumUserGroup::findByPk($groupId)->canread;
     }
     return (bool) $categoryRights['canread'];
 }
コード例 #6
0
 public static function makeVisitor($userId, $sectionId)
 {
     $user = new self();
     $user->user_id = $userId;
     $user->section_id = $sectionId;
     $user->muted = $user->banned = $user->title_id = 1;
     $user->muted = $user->banned = $user->title_id = 0;
     $user->signature = '';
     $user->member_since = date('Y-m-d H:i:s');
     $section = ForumSection::findByPk($sectionId);
     $groupId = $section->default_visitors_group_id;
     App::get()->debug("User {$userId} assign to group {$groupId} from section {$sectionId}");
     $user->group_id = $groupId;
     return $user->save();
 }