public function actionMods($id = null)
    {
        $mod = null;
        $moderators = User::find()->where(['role' => User::ROLE_MODERATOR])->indexBy('id')->all();
        if (is_numeric($id) && $id > 0) {
            if (isset($moderators[$id])) {
                $mod = $moderators[$id];
            }
        } else {
            reset($moderators);
            $mod = current($moderators);
        }
        $searchModel = new ForumSearch();
        $dataProvider = $searchModel->searchForMods(Yii::$app->request->get());
        $postData = Yii::$app->request->post();
        if ($postData) {
            if (!User::can(Rbac::PERM_PROMOTE_USER)) {
                $this->error(Yii::t('podium/flash', 'You are not allowed to perform this action.'));
            } else {
                $mod_id = !empty($postData['mod_id']) && is_numeric($postData['mod_id']) && $postData['mod_id'] > 0 ? $postData['mod_id'] : 0;
                $selection = !empty($postData['selection']) ? $postData['selection'] : [];
                $pre = !empty($postData['pre']) ? $postData['pre'] : [];
                if ($mod_id == $mod->id) {
                    if ($mod->updateModeratorForMany($selection, $pre)) {
                        $this->success(Yii::t('podium/flash', 'Moderation list has been saved.'));
                    } else {
                        $this->error(Yii::t('podium/flash', 'Sorry! There was an error while saving the moderation list.'));
                    }
                    return $this->refresh();
                }
                $this->error(Yii::t('podium/flash', 'Sorry! There was an error while selecting the moderator ID.'));
            }
        }
        return $this->render('mods', [
            'moderators' => $moderators,
            'mod' => $mod,
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }
public function actionMods($id = null)
    {
        $mod = null;
        $moderators = User::find()->where(['role' => User::ROLE_MODERATOR])->indexBy('id')->all();
        if (is_numeric($id) && $id > 0) {
            if (isset($moderators[$id])) {
                $mod = $moderators[$id];
            }
        } else {
            reset($moderators);
            $mod = current($moderators);
        }
        $searchModel = new ForumSearch();
        $dataProvider = $searchModel->searchForMods(Yii::$app->request->get());
        $postData = Yii::$app->request->post();
        if ($postData) {
            if (!User::can(Rbac::PERM_PROMOTE_USER)) {
                $this->error(Yii::t('podium/flash', 'You are not allowed to perform this action.'));
            } else {
                $mod_id = !empty($postData['mod_id']) && is_numeric($postData['mod_id']) && $postData['mod_id'] > 0 ? $postData['mod_id'] : 0;
                $selection = !empty($postData['selection']) ? $postData['selection'] : [];
                $pre = !empty($postData['pre']) ? $postData['pre'] : [];
                if ($mod_id == $mod->id) {
                    if ($mod->updateModeratorForMany($selection, $pre)) {
                        $this->success(Yii::t('podium/flash', 'Moderation list has been saved.'));
                    } else {
                        $this->error(Yii::t('podium/flash', 'Sorry! There was an error while saving the moderation list.'));
                    }
                    return $this->refresh();
                }
                $this->error(Yii::t('podium/flash', 'Sorry! There was an error while selecting the moderator ID.'));
            }
        }
        return $this->render('mods', [
            'moderators' => $moderators,
            'mod' => $mod,
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }
public function actionMods ( $ id = null ) { $ mod = null ; $ moderators = User :: find ( ) -> where ( [ 'role' => User :: ROLE_MODERATOR ] ) -> indexBy ( 'id' ) -> all ( ) ; if ( is_numeric ( $ id ) && $ id > 0 ) { if ( isset ( $ moderators [ $ id ] ) ) { $ mod = $ moderators [ $ id ] ; } } else { reset ( $ moderators ) ; $ mod = current ( $ moderators ) ; } $ searchModel = new ForumSearch ( ) ; $ dataProvider = $ searchModel -> searchForMods ( Yii :: $ app -> request -> get ( ) ) ; $ postData = Yii :: $ app -> request -> post ( ) ; if ( $ postData ) { if ( ! User :: can ( Rbac :: PERM_PROMOTE_USER ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'You are not allowed to perform this action.' ) ) ; } else { $ mod_id = ! empty ( $ postData [ 'mod_id' ] ) && is_numeric ( $ postData [ 'mod_id' ] ) && $ postData [ 'mod_id' ] > 0 ? $ postData [ 'mod_id' ] : 0 ; $ selection = ! empty ( $ postData [ 'selection' ] ) ? $ postData [ 'selection' ] : [ ] ; $ pre = ! empty ( $ postData [ 'pre' ] ) ? $ postData [ 'pre' ] : [ ] ; if ( $ mod_id == $ mod -> id ) { if ( $ mod -> updateModeratorForMany ( $ selection , $ pre ) ) { $ this -> success ( Yii :: t ( 'podium/flash' , 'Moderation list has been saved.' ) ) ; } else { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There was an error while saving the moderation list.' ) ) ; } return $ this -> refresh ( ) ; } $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There was an error while selecting the moderator ID.' ) ) ; } } return $ this -> render ( 'mods' , [ 'moderators' => $ moderators , 'mod' => $ mod , 'searchModel' => $ searchModel , 'dataProvider' => $ dataProvider , ] ) ; }
Listing and updating moderation list for the forum of given ID.
@param int $id forum ID
@return string|Response
Listing and updating moderation list for the forum of given ID .