code:
<?php

namespace app\modules\yboard\controllers;

use app\modules\yboard\YBoard;
use app\modules\yboard\components\DateTimeCalculation;

use app\modules\yboard\models\YBoardBanSearch;
use app\modules\yboard\models\YBoardTopic;
use app\modules\yboard\models\YBoardPost;
use app\modules\yboard\models\YBoardForum;
use app\modules\yboard\models\YBoardMessage;
use app\modules\yboard\models\YBoardMember;
use app\modules\yboard\models\YBoardBan;
use yii\web\NotFoundHttpException;
use yii\web\ForbiddenHttpException;

use Yii;
use yii\data\ActiveDataProvider;

class ModeratorController extends \yii\web\Controller
{
    public $layout = "admin";
    /**
     * Lists all YBoardBan models.
     * @return mixed
     */
    public function actionIndex()
    {
        if(!Yii::$app->user->can('app.forum.moderator.index'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $pendingTopics = YBoardTopic::find()->where(['approved'=>0])->count();
        $pendingPosts = YBoardPost::find()->where(['approved'=>0])->count();

        $bannedUsers = YBoardBan::find()->activeScope()->userScope()->count();
        $bannedEmails = YBoardBan::find()->activeScope()->emailScope()->count();
        $bannedIps = YBoardBan::find()->activeScope()->ipScope()->count();

        return $this->render('index', [
            'pendingTopics'=>$pendingTopics,
            'pendingPosts'=>$pendingPosts,
            'bannedUsers'=>$bannedUsers,
            'bannedEmails'=>$bannedEmails,
            'bannedIps'=>$bannedIps,
        ]);
    }

    //approve pending posts and topics
    public function actionApprove()
    {
        if(!Yii::$app->user->can('app.forum.moderator.approve'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $topics = new ActiveDataProvider([
            'query' => YBoardTopic::find()->where(['approved'=>0]),
            'pagination' => [
                'pageSize' => 5,
            ],
        ]);

        $posts = new ActiveDataProvider([
            'query' => YBoardPost::find()->where(['approved'=>0]),
            'pagination' => [
                'pageSize' => 5,
            ],
        ]);

        return $this->render('approve', [
            'topicsProvider' => $topics,
            'postsProvider' => $posts,
        ]);
    }

    /** Approve Topic
     */
    public function actionApproveTopic($id)
    {
        if(!Yii::$app->user->can('app.forum.moderator.approve-topic'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        if(!Yii::$app->request->isAjax)
            Yii::$app->end();

        $json = [];
        $post = YBoardTopic::findOne($id);
        if($post==null)
        {
            $json['success'] = 'no';
            $json['error'] = YBoard::t('yboard', 'Could not approve Topic');
        }
        else
        {
            $post->approved =1;
            if($post->save())
            {
                $json['success'] = 'yes';
            }
            else
            {
                $json['success'] = 'no';
                $json['error'] = YBoard::t('yboard', 'Could not approve Topic!');
            }
        }
        echo json_encode($json);
        Yii::$app->end();
    }

    /** Approve Post
     */
    public function actionApprovePost($id)
    {
        if(!Yii::$app->user->can('app.forum.moderator.approve-post'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        if(!Yii::$app->request->isAjax)
            Yii::$app->end();

        $json = [];
        $post = YBoardPost::findOne($id);
        if($post==null)
        {
            $json['success'] = 'no';
            $json['error'] = YBoard::t('yboard', 'Could not approve Post');
        }
        else
        {
            $post->approved =1;
            if($post->save())
            {
                $json['success'] = 'yes';
            }
            else
            {
                $json['success'] = 'no';
                $json['error'] = YBoard::t('yboard', 'Could not approve Post!');
            }
        }
        echo json_encode($json);
        Yii::$app->end();
    }

    /**
     * Lists all YBoardBan models.
     * @return mixed
     */
    public function actionBans()
    {
        if(!Yii::$app->user->can('app.forum.moderator.bans'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $searchModel = new YBoardBanSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('ban', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

    /** Ban Specific User
     */
    public function actionBanUser($id)
    {
        if(!Yii::$app->user->can('app.forum.moderator.ban-user'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        if(!Yii::$app->request->isAjax)
            Yii::$app->end();

        $json = [];
        $user = YBoardBan::find()->where(['user_id'=>$id])->one();
        if($user==null)
             $user = new YBoardBan;

        $attribs = $_POST;
        $attribs['expires'] = strtotime($attribs['expires']);
        $attribs['user_id'] = $id;

        $user->attributes= $attribs;

        if($user->save())
        {
            $json['success'] = 'yes';
        }
        else
        {
            $json['success'] = 'no';
            $json['message'] = YBoard::t('yboard', 'Could Not Ban User!');
        }
        echo json_encode($json);
        Yii::$app->end();

    }

    /** Change Ban Time
     */
    public function actionChangeBanPeriod($id)
    {
        if(!Yii::$app->user->can('app.forum.moderator.change-ban-period'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        if(!Yii::$app->request->isAjax)
            Yii::$app->end();

        if(isset($_POST['hasEditable']) && isset($_POST['expires'])) {

            $attrib = $_POST['expires'];
            $attrib = strtotime($attrib);

            $model = YBoardBan::findOne($id);
            if($model==null)
            {
                echo json_encode(['output'=>'', 'message'=>'Could Not Update Field']);
                Yii::$app->end();
            }

            $model->expires = $attrib;

            if (!$model->save()) {
                // validation error
                echo json_encode(['output'=>'', 'message'=>'Could Not Update Field']);
            }
            // else if nothing to do always return an empty JSON encoded output
            else {
                // read or convert your posted information
                $value = DateTimeCalculation::short($model->expires);
                echo json_encode(['output'=>$value, 'message'=>'']);
            }
        }
        else
        {
            throw new ForbiddenHttpException(YBoard::t('yboard','This Action is forbidden!'));
        }
    }

    /** Lift Ban
     */
    public function actionBanLift($id)
    {
        if(!Yii::$app->user->can('app.forum.moderator.ban-lift'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        if(!Yii::$app->request->isAjax)
            Yii::$app->end();

        $json = [];
        $ban = YBoardBan::findOne($id);
        $ban->setAttribute('expires', time()-60);//expired one minute ago
        if($ban!=null && $ban->save())
        {
            $json['success'] = 'yes';
        }
        else
        {
            $json['success'] = 'no';
            $json['error'] = YBoard::t('yboard', 'Could Not Lift the Ban!');
        }
        echo json_encode($json);
        Yii::$app->end();

    }

    /**
	 * Ajax call for change, move or merge topic
	 */
	public function actionChangeTopic()
    {
        if(!Yii::$app->user->can('app.forum.moderator.change-topic'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $json = [];
		if(isset($_POST['YBoardTopic'])) {
			$model = YBoardTopic::findOne($_POST['YBoardTopic']['id']);
			$move = false;
			$merge = false;
			$sourceTopicId = $_POST['YBoardTopic']['id'];
			$sourceForumId = $model->forum_id;
			if($model->forum_id != $_POST['YBoardTopic']['forum_id']) {
				$move = true;
				$targetForumId = $_POST['YBoardTopic']['forum_id'];
			}
			if(!empty($_POST['YBoardTopic']['merge']) && $_POST['YBoardTopic']['id'] != $_POST['YBoardTopic']['merge']) {
				$merge = true;
				$targetTopicId = $_POST['YBoardTopic']['merge'];
			}
			$model->attributes=$_POST['YBoardTopic'];
			if($model->validate()) {
				$json['success'] = 'yes';
				if($merge || $move) {
                    $criteria = "topic_id = $sourceTopicId";
					$numberOfPosts = YBoardPost::find()->approvedScope()->count();
					if($move) {
						YBoardPost::updateAll(['forum_id'=>$targetForumId], $criteria);

						$forum = YBoardForum::findOne($sourceForumId);
						$forum->updateAllCounters(['num_topics'=>-1]);
						$forum->updateAllCounters(['num_posts'=>-$numberOfPosts]);

                        $forum = YBoardForum::findOne($targetForumId);
						$forum->updateAllCounters(['num_topics'=>1]);
						$forum->updateAllCounters(['num_posts'=>$numberOfPosts]);

                        $this->resetLastForumPost($sourceForumId);
						$this->resetLastForumPost($targetForumId);
					}
					if($merge) {
						YBoardPost::updateAll(['topic_id'=>$targetTopicId], $criteria);
						if($move) {
							$forum = YBoardForum::findOne($targetForumId);
						} else {
							$forum = YBoardForum::findOne($sourceForumId);
						}
						$forum->updateCounters(array('num_topics'=>-1));
						$topic = YBoardTopic::findOne($targetTopicId);
						$topic->updateCounters(array('num_replies'=>$numberOfPosts));
						$model->delete();
					} else {
						$model->save();
					}
				} else {	// no move or merge involved
					$model->save();
				}
			} else {
                if(!$model->validate())
                    $json['error'] = $model->errors;
			}
		}
		echo json_encode($json);
		Yii::$app->end();
    }

    /**
	 * Delete a post
	 */
	public function actionDelete($id) {
        if(!Yii::$app->user->can('app.forum.moderator.delete-post'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

		if(isset($_GET['id']))
			$id = $_GET['id'];

		$post = YBoardPost::findOne($id);
		if($post === null) {
			throw new NotFoundHttpException(YBoard::t('yboard', 'The requested post does not exist.'));
		}
		$forum = YBoardForum::findOne(YBoardTopic::findOne($post->topic_id)->forum_id);

        if($post->original_post==1) //main topic, delete all including replies
        {
            $postDeleted = 0;
            $modelsToDelete = YBoardPost::find()->where(['topic_id'=>$post->topic_id])->all();
            foreach($modelsToDelete as $modelDel)
            {
                $pid = $modelDel->post_id;

                if($modelDel->delete())
                {
                    $postDeleted = $postDeleted-1;
                    YBoardMessage::deleteAll(['post_id'=>$pid]); //delete all reports
                }
            }
            //decrement counts
            $forum->updateCounters(['num_topics'=>$postDeleted]);
            YBoardLogTopic::deleteAll(['topic_id'=>$post->topic_id]);  //delete record in log
            $topic = YBoardTopic::findOne($post->topic_id)->delete();
        }
        else
        {
            $forum->updateCounters(['num_posts'=>-1]);
            $post->delete();
            //Delete reports on the deleted post
            YBoardMessage::deleteAll(['post_id'=>$id]);
        }

		// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
		if(!isset($_GET['ajax']))
			$this->redirect(isset($_POST['returnUrl'])? $_POST['returnUrl'] : ['approval']);
		else
            echo  json_encode(['success'=>true]);
	}

    /**
	 * Disapprove a post
	 */
	public function actionDisapprove($id) {
        if(!Yii::$app->user->can('app.forum.moderator.delete-post'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

		if(isset($_GET['id']))
			$id = $_GET['id'];

		$post = YBoardPost::findOne($id);
		if($post === null) {
			throw new NotFoundHttpException(YBoard::t('yboard', 'The requested post does not exist.'));
		}
        $post->approved = 0;
        $post->save();

		// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
		if(!isset($_GET['ajax']))
			$this->redirect(isset($_POST['returnUrl'])? $_POST['returnUrl'] : ['approval']);
		else
            echo  json_encode(['success'=>true]);
	}

    public function actionReported()
    {
        if(!Yii::$app->user->can('app.forum.moderator.reported'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $count = [];

        $query = YBoardMessage::find()
            ->inboxScope()
            ->reportMsgScope();

        $count['reported'] = $query->count();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        return $this->render('report', [
            //'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
			'count'=>$count
        ]);
    }

    public function actionTopic() {
        if(!Yii::$app->user->can('app.forum.moderator.topic'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

		$json = [];
		if(isset($_POST['id'])) {
			$model = YBoardTopic::findOne($_POST['id']);
			if($model === null) {
				$json['success'] = 'no';
				$json['message'] = YBoard::t('yboard', 'Topic not found.');
			} else {
				$json['success'] = 'yes';
				$json['forum_id'] = $model->forum_id;
				$json['title'] = $model->title;
				$json['locked'] = $model->locked;
				$json['sticky'] = $model->sticky;
				$json['global'] = $model->global;
				$json['approved'] = $model->approved;
				$json['option'] = '<option value=""></option>';
				foreach(YBoardTopic::find()
                ->where(['forum_id' => $model->forum_id])
                ->all() as $topic) {
					$json['option'] .= '<option value="' . $topic->id. '">' . $topic->title . '</option>';
				}
			}
		} else {
			$json['success'] = 'no';
			$json['message'] = YBoard::t('yboard', 'Topic not found.');
		}

		echo json_encode($json);
		Yii::$app->end();
	}

    public function actionGetPost($id)
    {
        if(!Yii::$app->user->can('app.forum.moderator.get-post'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        if(!Yii::$app->user->can('app.forum.moderator.delete-post'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

		$json = [];
        $model = YBoardPost::findOne($id);
        if($model==null)
        {
			$json['success'] = 'no';
			$json['error'] = YBoard::t('yboard', 'Post not found.');
        }
        else
        {
            $html = $this->renderAjax('_post', ['post'=>$model]);
            $json['success'] = 'yes';
            $json['html'] = $html;
        }
		echo json_encode($json);
		Yii::$app->end();
    }

    public function actionChangePost()
    {
        if(!Yii::$app->user->can('app.forum.moderator.change-post'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

		$json = [];
        $id = $_POST['YBoardPost']['id'];

        $model = YBoardPost::findOne($id);

        if($model==null)
        {
			$json['success'] = 'no';
			$json['error'] = YBoard::t('yboard', 'Post not found.');
        }
        else
        {
            $model->attributes = $_POST['YBoardPost'];
            $model->change_reason = YBoard::t('yboard', 'Post modearated by {user}', ['user'=>YBoardMember::findOne(Yii::$app->user->id)->profile->username]);

            if($model->save())
            {
                $json['success'] = 'yes';
            }
            else
            {
                $json['success'] = 'no';
                $json['error'] = YBoard::t('yboard', 'Post was not updated.');
            }
        }
		echo json_encode($json);
		Yii::$app->end();
    }

    /*
     * Reset the last post of a forum
	 */
	private function resetLastForumPost($id) {
		$model = YBoardForum::findOne($id);
		$criteria = "forum_id = $id and approved = 1";
		$post = YBoardPost::find()
            ->where($criteria)
            ->orderBy('id DESC')
            ->one();

		if($post !== null) {
			$model->last_post_id = $post->id;
		} else {
			$model->last_post_id = null;
		}
		$model->save();
	}
}


code:
<?php

namespace app\modules\yboard\controllers;

use app\modules\yboard\YBoard;
use app\modules\yboard\models\YBoardSetting;
use app\modules\yboard\models\YBoardForum;
use app\modules\yboard\models\YBoardSpider;

use app\modules\yboard\models\YBoardSpiderSearch;
use app\modules\yboard\models\YBoardMembergroup;
use app\modules\yboard\models\YBoardRank;
use app\modules\yboard\models\YBoardVote;

use app\modules\yboard\models\YBoardMessage;
use app\modules\yboard\models\YBoardMember;
use app\modules\yboard\models\YBoardMemberSearch;

use app\modules\yboard\YBoardSettingsAsset;
use hosanna\profile\models\User;

use Yii;
use yii\filters\VerbFilter;
use yii\web\NotFoundHttpException;
use yii\web\ForbiddenHttpException;
use yii\data\ActiveDataProvider;

class SettingController extends \yii\web\Controller
{
    public $layout = "admin";

    public function init()
    {
        parent::init();
        YBoardSettingsAsset::register($this->view)->publish(\Yii::$app->assetManager); //register YBoard settings js
    }

    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }

    /**
     * Lists all YBoardSetting models.
     * @return mixed
     */
    public function actionIndex()
    {
        if(!Yii::$app->user->can('app.forum.setting.index'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $dataProvider = new ActiveDataProvider([
            'query' => YBoardSetting::find(),
        ]);

        return $this->render('index', [
            'dataProvider' => $dataProvider,
        ]);
    }

     /**
     * Creates a new YBoardSetting model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        if(!Yii::$app->user->can('app.forum.setting.create'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $json = [];
        $model = new YBoardSetting;

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $json['success'] = 'yes';
        }
        else {
            $json['error'] = YBoard::t('yboard', 'Could not add new setting');
        }
		echo json_encode($json);
		Yii::$app->end();
    }

    /**
     * Updates an existing YBoardSetting model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     */
    public function actionUpdate($id)
    {
        if(!Yii::$app->user->can('app.forum.setting.update'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $json = [];
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $json['success'] = 'yes';
        }
        else {
            $json['error'] = YBoard::t('yboard', 'Could not update setting');
        }
		echo json_encode($json);
		Yii::$app->end();
    }

    public function actionForum()
    {
        if(!Yii::$app->user->can('app.forum.setting.forum'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $model=new YBoardForum;
		$forum = [];
		$category = YBoardForum::find()->sortedScope()->categoryScope()->all();

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if($model->load(\Yii::$app->request->post()) && $model->save())
            return $this->redirect(['forum']);

		return $this->render('forum', [
			'model'=>$model,
			'category'=>$category,
		]);
    }

    public function actionGroup()
    {
        if(!Yii::$app->user->can('app.forum.setting.group'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $model=new YBoardMembergroup(['scenario'=>'search']);
		$model->setAttributes([]);  // clear any default values
        $model->load(Yii::$app->request->post());

		return $this->render('group', ['model'=>$model]);
    }

    /**
	 * handle Ajax call for sorting categories and forums
	 */
	public function actionAjaxSort() {
        if(!Yii::$app->user->can('app.forum.setting.ajax-sort'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

		if(isset($_POST['cat'])) {
			$number = 1;
			foreach($_POST['cat'] as $id) {
				$model = YBoardForum::findOne($id);
				$model->sort = $number++;
				$model->save();
			}
			$json = array('succes'=>'yes');
		} elseif(isset($_POST['frm'])) {
			$number = 1;
			foreach($_POST['frm'] as $id) {
				$model = YBoardForum::findOne($id);
				$model->sort = $number++;
				$model->save();
			}
			$json = array('succes'=>'yes');
		} else {
			$json = array('succes'=>'no');
		}
		echo json_encode($json);
		Yii::$app->end();
	}

    public function actionDeleteUser($id)
    {
        if(!Yii::$app->user->can('app.forum.setting.delete-user'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $model = YBoardMember::findOne($id);

        if($model!=null && $model->delete())
            echo json_encode(['success'=>'yes']);
        else
            echo json_encode(['success'=>'no', 'error'=>YBoard::t('yboard', 'Could not delete User')]);
    }

	/**
	 * handle Ajax call for deleting membergroup
	 */
	public function actionDeleteMembergroup() {
        if(!Yii::$app->user->can('app.forum.setting.delete-membergroup'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

		$json = array();
		if(isset($_POST['id'])) {
			if($_POST['id'] == 1) {
				$json['success'] = 'no';
				$json['message'] = YBoard::t('yboard', 'The default member group cannot be removed.');
			} else {
				YBoardMembergroup::findOne($_POST['id'])->delete();
				$json['success'] = 'yes';
			}
		}
		echo json_encode($json);
		Yii::$app->end();
	}

	/**
	 * handle Ajax call for deleting rank
	 */
	public function actionDeleteRank() {
        if(!Yii::$app->user->can('app.forum.setting.delete-rank'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

		$json = [];
		if(isset($_POST['id'])) {
            if(YBoardRank::findOne($_POST['id'])->delete())
                $json['success'] = 'yes';
            else
				$json['success'] = 'no';
				$json['message'] = YBoard::t('yboard', 'Could not delete Rank');
		}
		echo json_encode($json);
		Yii::$app->end();
	}

    /**
	 * handle Ajax call for deleting spider
	 */
	public function actionDeleteSpider() {
        if(!Yii::$app->user->can('app.forum.setting.delete-spider'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

		$json = [];
		if(isset($_POST['id'])) {
			if(YBoardSpider::findOne($_POST['id'])->delete())
                $json['success'] = 'yes';
            else
                $json['error'] = YBoard::t('yboard', 'Could Not delete Spider, try again');
		}
		echo json_encode($json);
		Yii::$app->end();
	}

    public function actionGetForum($id)
    {
        if(!Yii::$app->user->can('app.forum.setting.get-forum'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $json = [];
		if(isset($_GET['id'])) {
			$model = YBoardForum::findOne($_GET['id']);
			if($model !== null) {
				$json['id'] = $model->id;
				$json['name'] = $model->name;
				$json['sort'] = $model->sort;
				$json['subtitle'] = $model->subtitle;
				$json['cat_id'] = $model->cat_id;
				$json['type'] = $model->type;
				$json['locked'] = $model->locked;
				$json['public'] = $model->public;
				$json['moderated'] = $model->moderated;
				$json['membergroup_id'] = $model->membergroup_id;
				$json['poll'] = $model->poll;
			}
		}
		echo json_encode($json);
		Yii::$app->end();
    }

    /**
      * handle Ajax call for saving forum
	 */
	public function actionSaveForum() {
        if(!Yii::$app->user->can('app.forum.setting.save-forum'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

		$json = [];
		if(isset($_POST['YBoardForum'])) {
			$model = YBoardForum::findOne($_POST['YBoardForum']['id']);
			$model->load(Yii::$app->request->post());
			if($model->save()) {
				$json['success'] = 'yes';
			} else {
				$json['error'] = array_values($model->errors);
			}
		}
		echo json_encode($json);
		Yii::$app->end();
	}

    public function actionGetMembergroup()
    {
        if(!Yii::$app->user->can('app.forum.setting.get-membergroup'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $json = [];
		if(isset($_GET['id'])) {
			$model = YBoardMembergroup::findOne($_GET['id']);
			if($model !== null) {
				$json['id'] = $model->id;
				$json['name'] = $model->name;
				$json['description'] = $model->description;
				$json['color'] = $model->color;
				$json['group_role'] = $model->group_role;
				$json['image'] = $model->image;
			}
		}
		echo json_encode($json);
		Yii::$app->end();
    }

    public function actionGetRank()
    {
        if(!Yii::$app->user->can('app.forum.setting.get-rank'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $json = [];
		if(isset($_GET['id'])) {
			$model = YBoardRank::findOne($_GET['id']);
			if($model !== null) {
				$json['id'] = $model->id;
				$json['title'] = $model->title;
				$json['min_posts'] = $model->min_posts;
				$json['stars'] = $model->stars;
			}
		}
		echo json_encode($json);
		Yii::$app->end();
    }

    /**
	 * handle Ajax call for getting spider
	 */
	public function actionGetSpider() {
        if(!Yii::$app->user->can('app.forum.setting.get-spider'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

		$json = [];
		if(isset($_GET['id'])) {
			$model = YBoardSpider::findOne($_GET['id']);
			if($model !== null) {
				$json['id'] = $model->id;
				$json['name'] = $model->name;
				$json['user_agent'] = $model->user_agent;
			}
		}
		echo json_encode($json);
		Yii::$app->end();
	}

    /**
     * Lists all YBoardRank models.
     * @return mixed
     */
    public function actionRank()
    {
        if(!Yii::$app->user->can('app.forum.setting.rank'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $dataProvider = new ActiveDataProvider([
            'query' => YBoardRank::find(),
        ]);

        return $this->render('rank', [
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
	 * handle Ajax call for saving membergroup
	 */
	public function actionSaveMembergroup() {
        if(!Yii::$app->user->can('app.forum.setting.save-membergroup'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

		$json = [];
        $model = new YBoardMembergroup;

		if(isset($_POST[$model->formName()])) {
 			if($_POST[$model->formName()]['id'] != '') {
				$model = YBoardMembergroup::findOne($_POST[$model->formName()]['id']);
                //remove from the POST
                unset($_POST[$model->formName()]['id']);
			}

            if($model->load(Yii::$app->request->post()) && $model->save()) {
                $json['success'] = 'yes';
            } else {
                $json['error'] =  YBoard::t('yboard', 'Could not save Member Group!');
            }
		}
		echo json_encode($json);
		Yii::$app->end();
	}

    /**
	 * handle Ajax call for saving ranks
	 */
	public function actionSaveRank() {
        if(!Yii::$app->user->can('app.forum.setting.save-rank'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

		$json = [];
        $model = new YBoardRank;

		if(isset($_POST[$model->formName()])) {
 			if($_POST[$model->formName()]['id'] != '') {
				$model = YBoardRank::findOne($_POST[$model->formName()]['id']);
                //remove from the POST
                unset($_POST[$model->formName()]['id']);
			}

            if($model->load(Yii::$app->request->post()) && $model->save()) {
                $json['success'] = 'yes';
            } else {
                $json['error'] =  YBoard::t('yboard', 'Could not save Rank');
            }
		}
		echo json_encode($json);
		Yii::$app->end();
	}

    /*
     * handle Ajax call for saving spider
	 */
	public function actionSaveSpider() {
        if(!Yii::$app->user->can('app.forum.setting.save-spider'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

		$json = [];
        $model = new YBoardSpiderSearch;

		if(isset($_POST[$model->formName()])) {
 			if($_POST[$model->formName()]['id'] != '') {
				$model = YBoardSpiderSearch::findOne($_POST[$model->formName()]['id']);
                //remove from the POST
                unset($_POST[$model->formName()]['id']);
			}

            if($model->load(Yii::$app->request->post()) && $model->save()) {
                $json['success'] = 'yes';
            } else {
                $json['error'] =  YBoard::t('yboard', 'Could not save Spider!');
            }
		}
		echo json_encode($json);
		Yii::$app->end();
	}

    public function actionSpider() {
        if(!Yii::$app->user->can('app.forum.setting.spider'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $searchModel = new YBoardSpiderSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('spider', [
            'model' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
	}

    /**
     * Lists all YBoardMember models.
     * @return mixed
     */
    public function actionUsers()
    {
        if(!Yii::$app->user->can('app.forum.setting.users'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $user = new User;

        $qstring = Yii::$app->request->get($user->formName())['username'];

        $user->username = $qstring;

        $userIds =  User::find()
            ->select('id')
            ->asArray()
            ->filterWhere(['like','username',$qstring])
            ->andWhere('id<>'.Yii::$app->user->id)
            ->all();

        $query = YBoardMember::find();

        foreach($userIds as $id)
        {
            $query->orWhere(['id'=>$id['id']]);
        }

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        return $this->render('users', [
            'dataProvider' => $dataProvider,
            'searchModel' => $user,
        ]);
    }

    /**
     * Displays a single YBoardMember model for Editing and other bells.
     * @param string $id
     * @return mixed
     */
    public function actionEditProfile($id)
    {
        if(!Yii::$app->user->can('app.forum.setting.edit-profile'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $model = YBoardMember::findOne($id);
        if ($model== null) {
            throw new NotFoundHttpException('The requested User does not exist.');
        }
        return $this->render('profile', [
            'model' => $model,
        ]);
    }

    /**
     * Deletes an existing YBoardSetting model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     */
    public function actionDelete($id)
    {
        if(!Yii::$app->user->can('app.forum.setting.delete'))
            throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));

        $this->findModel($id)->delete();

        return $this->redirect(['index']);
    }

    /**
     * Finds the YBoardSetting model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return YBoardSetting the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = YBoardSetting::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }

}

license: mit


code:
-- MySQL Workbench Forward Engineering

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
-- Schema hosannah_site
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema hosannah_site
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `hosannah_site` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `hosannah_site` ;

-- -----------------------------------------------------
-- Table `hosannah_site`.`Users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`Users` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `fname` VARCHAR(250) NOT NULL,
  `lname` VARCHAR(250) NOT NULL,
  `birthdate` DATE NOT NULL,
  `gender` INT NOT NULL,
  `email` VARCHAR(64) NOT NULL,
  `username` VARCHAR(250) NOT NULL,
  `password` VARCHAR(64) NOT NULL,
  `mobile` VARCHAR(20) NOT NULL,
  `avatar` VARCHAR(255) NOT NULL DEFAULT 'defaultavatar',
  `regtime` INT(11) NOT NULL,
  `recoverycode` VARCHAR(64) NULL DEFAULT '\"\"',
  `codeexpiry` INT(11) NULL,
  `valtoken` VARCHAR(64) NULL DEFAULT NULL,
  `isactive` TINYINT(1) NOT NULL DEFAULT 0,
  `timezone` VARCHAR(80) NOT NULL,
  UNIQUE INDEX `username_UNIQUE` (`username` ASC),
  UNIQUE INDEX `email_UNIQUE` (`email` ASC),
  PRIMARY KEY (`id`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `hosannah_site`.`auth_rule`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`auth_rule` (
  `name` VARCHAR(64) NOT NULL,
  `data` TEXT NULL DEFAULT NULL,
  `created_at` INT NULL DEFAULT NULL,
  `updated_at` INT NULL DEFAULT NULL,
  PRIMARY KEY (`name`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `hosannah_site`.`auth_item`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`auth_item` (
  `name` VARCHAR(64) NOT NULL,
  `type` INT NOT NULL,
  `description` TEXT NULL DEFAULT NULL,
  `rule_name` VARCHAR(64) NULL DEFAULT NULL,
  `data` TEXT NULL DEFAULT NULL,
  `created_at` INT NULL DEFAULT NULL,
  `updated_at` INT NULL DEFAULT NULL,
  PRIMARY KEY (`name`),
  INDEX `type` (`type` ASC),
  INDEX `fk_ce6dd412-eef4-11e3-8f69-875bcd3ee3aa` (`rule_name` ASC),
  CONSTRAINT `fk_ce6dd412-eef4-11e3-8f69-875bcd3ee3aa`
    FOREIGN KEY (`rule_name`)
    REFERENCES `hosannah_site`.`auth_rule` (`name`)
    ON DELETE set null
    ON UPDATE cascade)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `hosannah_site`.`auth_item_child`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`auth_item_child` (
  `parent` VARCHAR(64) NOT NULL,
  `child` VARCHAR(64) NOT NULL,
  PRIMARY KEY (`parent`, `child`),
  INDEX `fk_ce6e2dcc-eef4-11e3-8f69-875bcd3ee3aa` (`child` ASC),
  CONSTRAINT `fk_ce6e27f0-eef4-11e3-8f69-875bcd3ee3aa`
    FOREIGN KEY (`parent`)
    REFERENCES `hosannah_site`.`auth_item` (`name`)
    ON DELETE cascade
    ON UPDATE cascade,
  CONSTRAINT `fk_ce6e2dcc-eef4-11e3-8f69-875bcd3ee3aa`
    FOREIGN KEY (`child`)
    REFERENCES `hosannah_site`.`auth_item` (`name`)
    ON DELETE cascade
    ON UPDATE cascade)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `hosannah_site`.`auth_assignment`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`auth_assignment` (
  `item_name` VARCHAR(64) NOT NULL,
  `user_id` VARCHAR(64) NOT NULL,
  `created_at` INT NULL DEFAULT NULL,
  PRIMARY KEY (`item_name`, `user_id`),
  CONSTRAINT `fk_ce6e6fd0-eef4-11e3-8f69-875bcd3ee3aa`
    FOREIGN KEY (`item_name`)
    REFERENCES `hosannah_site`.`auth_item` (`name`)
    ON DELETE cascade
    ON UPDATE cascade)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardChoice`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardChoice` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `choice` VARCHAR(200) NOT NULL,
  `poll_id` INT(10) UNSIGNED NOT NULL,
  `sort` SMALLINT(6) NOT NULL DEFAULT '0',
  `votes` INT(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  INDEX `idx_choice_poll` (`poll_id` ASC))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardForum`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardForum` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `cat_id` INT(10) UNSIGNED NULL DEFAULT NULL,
  `name` VARCHAR(255) NOT NULL,
  `subtitle` VARCHAR(255) NULL DEFAULT NULL,
  `type` TINYINT(4) NOT NULL DEFAULT '0',
  `public` TINYINT(4) NOT NULL DEFAULT '1',
  `locked` TINYINT(4) NOT NULL DEFAULT '0',
  `moderated` TINYINT(4) NOT NULL DEFAULT '0',
  `sort` SMALLINT(6) NOT NULL DEFAULT '0',
  `num_posts` INT(10) UNSIGNED NOT NULL DEFAULT '0',
  `num_topics` INT(10) UNSIGNED NOT NULL DEFAULT '0',
  `last_post_id` INT(10) UNSIGNED NULL DEFAULT NULL,
  `poll` TINYINT(4) NOT NULL DEFAULT '0',
  `membergroup_id` INT(10) UNSIGNED NULL DEFAULT 1,
  PRIMARY KEY (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardIPAddress`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardIPAddress` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `ip` VARCHAR(39) NULL DEFAULT NULL,
  `address` VARCHAR(255) NULL DEFAULT NULL,
  `source` TINYINT(4) NULL DEFAULT '0',
  `count` INT(11) NULL DEFAULT '0',
  `create_time` TIMESTAMP NULL DEFAULT NULL,
  `update_time` TIMESTAMP NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `ip_UNIQUE` (`ip` ASC))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardMemberGroup`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardMemberGroup` (
  `id` INT(10) NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(45) NOT NULL,
  `description` TEXT NULL DEFAULT NULL,
  `color` VARCHAR(7) NULL DEFAULT NULL,
  `image` VARCHAR(255) NULL DEFAULT NULL,
  `group_role` VARCHAR(64) NOT NULL DEFAULT 'member' COMMENT 'Group Role',
  PRIMARY KEY (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardRank`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardRank` (
  `id` INT(10) NOT NULL AUTO_INCREMENT,
  `title` VARCHAR(255) NOT NULL,
  `min_posts` MEDIUMINT(8) NOT NULL,
  `stars` MEDIUMINT(8) NOT NULL DEFAULT 5,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardMember`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardMember` (
  `id` INT(11) NOT NULL,
  `group_id` INT(10) NOT NULL DEFAULT 1,
  `rank_id` INT(10) NOT NULL DEFAULT 1,
  `location` VARCHAR(255) NULL DEFAULT NULL,
  `personal_text` VARCHAR(255) NULL DEFAULT NULL,
  `signature` TEXT NULL DEFAULT NULL,
  `show_online` TINYINT(4) NULL DEFAULT '1',
  `contact_email` TINYINT(4) NULL DEFAULT '0',
  `contact_pm` TINYINT(4) NULL DEFAULT '1',
  `first_visit` TIMESTAMP NULL DEFAULT NULL,
  `last_visit` TIMESTAMP NULL DEFAULT NULL,
  `ip` VARCHAR(255) NOT NULL,
  `blogger` VARCHAR(255) NULL DEFAULT NULL,
  `facebook` VARCHAR(255) NULL DEFAULT NULL,
  `skype` VARCHAR(255) NULL DEFAULT NULL,
  `google` VARCHAR(255) NULL DEFAULT NULL,
  `linkedin` VARCHAR(255) NULL DEFAULT NULL,
  `metacafe` VARCHAR(255) NULL DEFAULT NULL,
  `github` VARCHAR(255) NULL DEFAULT NULL,
  `orkut` VARCHAR(255) NULL DEFAULT NULL,
  `tumblr` VARCHAR(255) NULL DEFAULT NULL,
  `twitter` VARCHAR(255) NULL DEFAULT NULL,
  `website` VARCHAR(255) NULL DEFAULT NULL,
  `wordpress` VARCHAR(255) NULL DEFAULT NULL,
  `yahoo` VARCHAR(255) NULL DEFAULT NULL,
  `youtube` VARCHAR(255) NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_YBoardMember_Group_idx` (`group_id` ASC),
  INDEX `fk_YBoardMember_Rank_idx` (`rank_id` ASC),
  CONSTRAINT `fk_bbii_member_Profile`
    FOREIGN KEY (`id`)
    REFERENCES `hosannah_site`.`Users` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_YBoardMember_Group`
    FOREIGN KEY (`group_id`)
    REFERENCES `hosannah_site`.`YBoardMemberGroup` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_YBoardMember_Rank`
    FOREIGN KEY (`rank_id`)
    REFERENCES `hosannah_site`.`YBoardRank` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardTopic`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardTopic` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `forum_id` INT(10) UNSIGNED NOT NULL,
  `user_id` INT(11) UNSIGNED NOT NULL,
  `title` VARCHAR(255) NOT NULL,
  `first_post_id` INT(10) UNSIGNED NOT NULL,
  `last_post_id` INT(10) UNSIGNED NOT NULL,
  `num_replies` INT(10) UNSIGNED NOT NULL DEFAULT '0',
  `num_views` INT(10) UNSIGNED NOT NULL DEFAULT '0',
  `approved` TINYINT(4) NOT NULL DEFAULT '0',
  `locked` TINYINT(4) NOT NULL DEFAULT '0',
  `sticky` TINYINT(4) NOT NULL DEFAULT '0',
  `global` TINYINT(4) NOT NULL DEFAULT '0',
  `moved` INT(10) UNSIGNED NOT NULL DEFAULT '0',
  `upvoted` SMALLINT(6) NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  INDEX `forum_id_INDEX` (`forum_id` ASC),
  CONSTRAINT `fk_bbii_topic_forum`
    FOREIGN KEY (`forum_id`)
    REFERENCES `hosannah_site`.`YBoardForum` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
AUTO_INCREMENT = 5
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardLogTopic`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardLogTopic` (
  `member_id` INT(11) NOT NULL,
  `topic_id` INT(10) UNSIGNED NOT NULL,
  `forum_id` INT(10) UNSIGNED NOT NULL,
  `last_post_id` INT(10) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY (`member_id`, `topic_id`),
  INDEX `idx_log_forum_id` (`forum_id` ASC),
  INDEX `fk_bbii_log_topic_Topic_idx` (`topic_id` ASC),
  CONSTRAINT `fk_bbii_log_topic_1User`
    FOREIGN KEY (`member_id`)
    REFERENCES `hosannah_site`.`YBoardMember` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_bbii_log_topic_Topic`
    FOREIGN KEY (`topic_id`)
    REFERENCES `hosannah_site`.`YBoardTopic` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardMessage`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardMessage` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `sendfrom` INT(11) NOT NULL,
  `sendto` INT(11) NOT NULL,
  `post_id` INT(10) UNSIGNED NULL DEFAULT NULL,
  `subject` VARCHAR(255) NOT NULL,
  `content` TEXT NOT NULL,
  `create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `read_indicator` TINYINT(4) NOT NULL DEFAULT '0',
  `type` TINYINT(4) NOT NULL DEFAULT '0',
  `inbox` TINYINT(4) NOT NULL DEFAULT '1',
  `outbox` TINYINT(4) NOT NULL DEFAULT '1',
  `ip` VARCHAR(39) NOT NULL,
  INDEX `sendfrom_INDEX` (`sendfrom` ASC),
  INDEX `sendto_INDEX` (`sendto` ASC),
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_bbii_message_User_FROM`
    FOREIGN KEY (`sendfrom`)
    REFERENCES `hosannah_site`.`YBoardMember` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardPost`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardPost` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `subject` VARCHAR(255) NOT NULL,
  `content` TEXT NOT NULL,
  `user_id` INT(11) NOT NULL,
  `topic_id` INT(10) UNSIGNED NULL DEFAULT NULL,
  `forum_id` INT(10) UNSIGNED NULL DEFAULT NULL,
  `original_post` TINYINT(1) NOT NULL DEFAULT 0,
  `ip` VARCHAR(39) NULL DEFAULT NULL,
  `create_time` INT NULL DEFAULT NULL,
  `approved` TINYINT(4) NULL DEFAULT NULL,
  `change_id` INT(10) UNSIGNED NULL DEFAULT NULL,
  `change_time` INT NULL DEFAULT NULL,
  `change_reason` VARCHAR(255) NULL DEFAULT NULL,
  `upvoted` SMALLINT(6) NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  INDEX `user_id_INDEX` (`user_id` ASC),
  INDEX `topic_id_INDEX` (`topic_id` ASC),
  INDEX `create_time_INDEX` (`create_time` ASC),
  INDEX `fk_bbii_post_Forum_idx` (`forum_id` ASC),
  CONSTRAINT `fk_bbii_post_User`
    FOREIGN KEY (`user_id`)
    REFERENCES `hosannah_site`.`YBoardMember` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_bbii_post_Topic`
    FOREIGN KEY (`topic_id`)
    REFERENCES `hosannah_site`.`YBoardTopic` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_bbii_post_Forum`
    FOREIGN KEY (`forum_id`)
    REFERENCES `hosannah_site`.`YBoardForum` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
AUTO_INCREMENT = 23
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardPoll`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardPoll` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `question` VARCHAR(200) NOT NULL,
  `post_id` INT(10) UNSIGNED NOT NULL,
  `user_id` INT(11) NOT NULL,
  `expire_date` DATE NULL DEFAULT NULL,
  `allow_revote` TINYINT(4) NOT NULL DEFAULT '0',
  `allow_multiple` TINYINT(4) NOT NULL DEFAULT '0',
  `votes` INT(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  INDEX `idx_poll_post` (`post_id` ASC),
  INDEX `fk_bbii_poll_Member_idx` (`user_id` ASC),
  CONSTRAINT `fk_bbii_poll_Post`
    FOREIGN KEY (`post_id`)
    REFERENCES `hosannah_site`.`YBoardPost` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_bbii_poll_Member`
    FOREIGN KEY (`user_id`)
    REFERENCES `hosannah_site`.`YBoardMember` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardSession`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardSession` (
  `id` VARCHAR(128) NOT NULL,
  `last_visit` INT NOT NULL,
  `user_id` INT(11) NULL DEFAULT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardSetting`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardSetting` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `key` VARCHAR(50) NOT NULL,
  `value` VARCHAR(100) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `key_UNIQUE` (`key` ASC))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardSpider`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardSpider` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(45) NOT NULL,
  `user_agent` VARCHAR(255) NOT NULL,
  `hits` INT(10) UNSIGNED NOT NULL DEFAULT '0',
  `last_visit` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardUpvoted`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardUpvoted` (
  `member_id` INT(11) NOT NULL,
  `post_id` INT(10) UNSIGNED NOT NULL,
  `author` INT(11) NOT NULL,
  INDEX `idx_upvoted_member` (`member_id` ASC),
  INDEX `idx_upvoted_post` (`post_id` ASC),
  INDEX `fk_bbii_upvoted_Author_idx` (`author` ASC),
  CONSTRAINT `fk_bbii_upvoted_Member`
    FOREIGN KEY (`member_id`)
    REFERENCES `hosannah_site`.`YBoardMember` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_bbii_upvoted_Post`
    FOREIGN KEY (`post_id`)
    REFERENCES `hosannah_site`.`YBoardPost` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_bbii_upvoted_Author`
    FOREIGN KEY (`author`)
    REFERENCES `hosannah_site`.`YBoardMember` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardVote`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardVote` (
  `poll_id` INT(10) UNSIGNED NOT NULL,
  `choice_id` INT(10) UNSIGNED NOT NULL,
  `user_id` INT(11) NOT NULL,
  PRIMARY KEY (`poll_id`, `choice_id`, `user_id`),
  INDEX `idx_vote_poll` (`poll_id` ASC),
  INDEX `idx_vote_user` (`user_id` ASC),
  INDEX `idx_vote_choice` (`choice_id` ASC),
  CONSTRAINT `fk_bbii_vote_Poll`
    FOREIGN KEY (`poll_id`)
    REFERENCES `hosannah_site`.`YBoardPoll` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_bbii_vote_choice`
    FOREIGN KEY (`choice_id`)
    REFERENCES `hosannah_site`.`YBoardChoice` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_bbii_vote_User`
    FOREIGN KEY (`user_id`)
    REFERENCES `hosannah_site`.`YBoardMember` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

-- -----------------------------------------------------
-- Table `hosannah_site`.`YBoardBan`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `hosannah_site`.`YBoardBan` (
  `id` INT(10) NOT NULL AUTO_INCREMENT,
  `user_id` INT(11) NULL DEFAULT NULL,
  `ip` VARCHAR(255) NULL DEFAULT NULL,
  `email` VARCHAR(80) NULL DEFAULT NULL,
  `message` VARCHAR(255) NULL,
  `banned_on` INT(10) NULL,
  `expires` INT(10) NULL,
  `banned_by` INT(11) NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_YBoardBan_Burner_idx` (`banned_by` ASC),
  INDEX `fk_YBoardBan_User_idx` (`user_id` ASC),
  CONSTRAINT `fk_YBoardBan_Burner`
    FOREIGN KEY (`banned_by`)
    REFERENCES `hosannah_site`.`YBoardMember` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_YBoardBan_User`
    FOREIGN KEY (`user_id`)
    REFERENCES `hosannah_site`.`YBoardMember` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;


code:
<?php

/**
 * MailForm class.
 */
class MailForm extends \yii\base\Model
{
	public $member_id;
	public $member_name;
	public $subject;
	public $body;

	/**
	 * Declares the validation rules.
	 */
	public function rules()
	{
		return [
			// name, email, subject and body are required
			['member_id, subject, body', 'required'],
			['body','filter','filter'=>[$obj=new CHtmlPurifier(), 'purify']],
			['member_name', 'safe'],
		];
	}

	/**
	 * Declares customized attribute labels.
	 * If not declared here, an attribute would have a label that is
	 * the same as its name with the first letter in upper case.
	 */
	public function attributeLabels()
	{
		return array(
			'subject'=>YBoard::t('yboard','Subject'),
		);
	}
}


code:
<?php

namespace app\modules\yboard\models;

use Yii;
use app\modules\yboard\YBoard;

/**
 * This is the model class for table "YBoardBan".
 *
 * @property integer $id
 * @property integer $user_id
 * @property string $ip
 * @property string $email
 * @property string $message
 * @property integer $expires
 * @property integer $banned_by
 *
 * @property YBoardMember $bannedBy
 * @property YBoardMember $user
 */
class YBoardBan extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'YBoardBan';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'banned_on', 'expires', 'banned_by'], 'integer'],
            [['banned_by'], 'required'],
            [['ip', 'message'], 'string', 'max' => 255],
            [['email'], 'string', 'max' => 80]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => YBoard::t('yboard', 'ID'),
            'user_id' => YBoard::t('yboard', 'Member'),
            'ip' => YBoard::t('yboard', 'IP'),
            'email' => YBoard::t('yboard', 'Email'),
            'message' => YBoard::t('yboard', 'Reason'),
            'expires' => YBoard::t('yboard', 'Expires'),
            'banned_by' => YBoard::t('yboard', 'Banned By'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBannedByMe()
    {
        return $this->hasOne(YBoardMember::className(), ['id' => 'banned_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMember()
    {
        return $this->hasOne(YBoardMember::className(), ['id' => 'user_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBanner()
    {
        return $this->hasOne(YBoardMember::className(), ['id' => 'banned_by']);
    }

    public function beforeSave($insert)
    {
        if (parent::beforeSave($insert))
        {
            $this->banned_on = time();

            return true;
        }
        else
        {
            return false;
        }
    }

    /**
     * @inheritdoc
     * @return YBoardForumQuery
     */
    public static function find()
    {
        return new YBoardBanQuery(get_called_class());
    }
}


code:
<?php
//Scopes for YBoardForum et al
namespace app\modules\yboard\models;

class YBoardBanQuery extends \yii\db\ActiveQuery
{
    public function liftedScope()
    {
        $this->andWhere('expires<='.time()) ;
        return $this;
    }

    public function activeScope()
    {
        $this->andWhere('expires>'.time()) ;
        return $this;
    }

    public function userScope()
    {
        $this->andWhere("user_id IS NOT NULL");
        return $this;
    }

    public function emailScope()
    {
        $this->andWhere("email IS NOT NULL");
        return $this;
    }

    public function ipScope()
    {
        $this->andWhere("ip IS NOT NULL");
        return $this;
    }
}


code:
<?php

namespace app\modules\yboard\models;

use Yii;
use app\modules\yboard\YBoard;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\modules\yboard\models\YBoardBan;

/**
 * YBoardBanSearch represents the model behind the search form about `app\modules\yboard\models\YBoardBan`.
 */
class YBoardBanSearch extends YBoardBan
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'user_id', 'expires', 'banned_by'], 'integer'],
            [['ip', 'email', 'message'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params, $scope='active')
    {
        $query = YBoardBan::find();
        if($scope=='active')
            $query = $query->activeScope();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'user_id' => $this->user_id,
            'expires' => $this->expires,
            'banned_by' => $this->banned_by,
        ]);

        $query->andFilterWhere(['like', 'ip', $this->ip])
            ->andFilterWhere(['like', 'email', $this->email])
            ->andFilterWhere(['like', 'message', $this->message]);

        return $dataProvider;
    }
}


code:
<?php

namespace app\modules\yboard\models;

use Yii;
use app\modules\yboard\YBoard;

/**
 * This is the model class for table "yboard_choice".
 *
 * @property string $id
 * @property string $choice
 * @property string $poll_id
 * @property integer $sort
 * @property integer $votes
 *
 * @property YBoardVote $yboardVote
 */
class YBoardChoice extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'YBoardChoice';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['choice', 'poll_id'], 'required'],
            [['poll_id', 'sort', 'votes'], 'integer'],
            [['choice'], 'string', 'max' => 200]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => YBoard::t('yboard', 'ID'),
            'choice' => YBoard::t('yboard', 'Choice'),
            'poll_id' => YBoard::t('yboard', 'Poll ID'),
            'sort' => YBoard::t('yboard', 'Sort'),
            'votes' => YBoard::t('yboard', 'Votes'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getVote()
    {
        return $this->hasOne(YBoardVote::className(), ['choice_id' => 'id']);
    }

    public function beforeDelete()
    {
        if (parent::beforeDelete()) {

            YBoardVote::deleteAll(['choice_id'=>$this->id]);

            return true;
        } else {
            return false;
        }
    }
}


code:
<?php

namespace app\modules\yboard\models;

use Yii;
use app\modules\yboard\YBoard;

/**
 * This is the model class for table "yboard_forum".
 *
 * @property string $id
 * @property string $cat_id
 * @property string $name
 * @property string $subtitle
 * @property integer $type
 * @property integer $public
 * @property integer $locked
 * @property integer $moderated
 * @property integer $sort
 * @property string $num_posts
 * @property string $num_topics
 * @property string $last_post_id
 * @property integer $poll
 * @property string $membergroup_id
 *
 * @property YBoardMembergroup $membergroup
 * @property YBoardLogTopic[] $yboardLogTopics
 * @property YBoardPost[] $yboardPosts
 * @property YBoardTopic[] $yboardTopics
 */
class YBoardForum extends \yii\db\ActiveRecord
{
    public $uid = 0; //current user ID querying this model. For use with getForums relations
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'YBoardForum';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['cat_id', 'type', 'public', 'locked', 'moderated', 'sort', 'num_posts', 'num_topics', 'last_post_id', 'poll', 'membergroup_id'], 'integer'],
            [['cat_id'], 'required', 'message'=>Yii::t('app','Parent category is required'), 'when' => function($model) { return $model->type==1; /*Parent required for forum not parent*/}],
            [['name'], 'required'],
            [['name', 'subtitle'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => YBoard::t('yboard', 'Forum'),
            'cat_id' => YBoard::t('yboard', 'Category'),
            'name' => YBoard::t('yboard', 'Name'),
            'subtitle' => YBoard::t('yboard', 'Descriptions'),
            'type' => YBoard::t('yboard', 'Type'),
            'public' => YBoard::t('yboard', 'Public'),
            'locked' => YBoard::t('yboard', 'Locked'),
            'moderated' => YBoard::t('yboard', 'Moderated'),
            'sort' => YBoard::t('yboard', 'Sort'),
            'num_posts' => YBoard::t('yboard', 'Posts'),
            'num_topics' => YBoard::t('yboard', 'Topics'),
            'last_post_id' => YBoard::t('yboard', 'Last Post'),
            'poll' => YBoard::t('yboard', 'Poll'),
            'membergroup_id' => YBoard::t('yboard', 'Member Group'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCategory()
    {
        return $this->hasOne(YBoardForum::className(), ['id' => 'cat_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getForums()
    {
        return $this->hasMany(YBoardForum::className(), ['cat_id' => 'id'])
            ->andWhere('cat_id IS NOT NULL')
            ->memberGroupScope($this->uid)
            ->sortedScope();
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMembergroup()
    {
        return $this->hasOne(YBoardMembergroup::className(), ['id' => 'membergroup_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getLogTopics()
    {
        return $this->hasMany(YBoardLogTopic::className(), ['forum_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPosts()
    {
        return $this->hasMany(YBoardPost::className(), ['forum_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTopics()
    {
        return $this->hasMany(YBoardTopic::className(), ['forum_id' => 'id']);
    }

    /**
     * @inheritdoc
     * @return YBoardForumQuery
     */
    public static function find()
    {
        return new YBoardForumQuery(get_called_class());
    }

    public function membergroup($membergroup=0) {
		return $this->find()
                    ->orWhere(['membergroup_id' => 0])
                    ->orWhere(['membergroup_id' => $membergroup])->all();
	}

    public static function getForumOptions($isGuest, $uid) {
		$return = [];
		$category = YBoardForum::find()
                    ->where(['type'=>0])
                    ->orderBy('sort')
                    ->all();

		foreach($category as $group) {
 			$forum = YBoardForum::find()
                    ->where(['type'=>1])
                    ->andWhere(['cat_id'=>$group->id])
                    ->orderBy('sort')
                    ->all();

			foreach($forum as $option) {
				if($option->public || !$isGuest) {
					if($option->membergroup_id == 0) {
						$return[] = ['id'=>$option->id,'name'=>$option->name,'group'=>$group->name];
					}
                    else if(!$isGuest) {
						$groupId = YBoardMember::findOne($uid)->group_id;
						if($option->membergroup_id == $groupId) {
							$return[] = ['id'=>$option->id,'name'=>$option->name,'group'=>$group->name];
						}
					}
				}
			}
		}
		return $return;
	}

    /**
	 * @return array relational rules.
	 */
	public function getLastPost()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return  $this->hasOne(YBoardPost::className(), ['id'=>'last_post_id']);
	}
}


code:
<?php
//Scopes for YBoardForum et al
namespace app\modules\yboard\models;

class YBoardForumQuery extends \yii\db\ActiveQuery
{
    public function categoriesScope()
    {
        $this->andWhere(['type' => 0])
                    ->orderBy('sort');
        return $this;
    }

    public function categoryScope()
    {
        $this->andWhere(['type' => 0]) ;
        return $this;
    }

    public function forumScope()
    {
        return $this->andWhere(['type' => 1]) ;
    }

    public function publicScope()
    {
        $this->andWhere(['public' => 1]) ;
        return $this;
    }

    public function sortedScope()
    {
        $this->orderBy('sort') ;
        return $this;
    }

    public function memberGroupScope($member=0)
    {
        //-1 mean admin so he should see all groups.
        if($member!=-1)
        {
            $usr = YBoardMember::findOne(\Yii::$app->user->id);
            $this->andWhere(['membergroup_id' => 0]);
            if($usr!==null)
                $this->orWhere(['membergroup_id' => $usr->group_id]);
        }
        return $this;
    }
}


code:
<?php

namespace app\modules\yboard\models;

use Yii;
use app\modules\yboard\YBoard;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\modules\yboard\models\YBoardForum;

/**
 * YBoardForumSearch represents the model behind the search form about `app\modules\yboard\models\YBoardForum`.
 */
class YBoardForumSearch extends YBoardForum
{
    public function rules()
    {
        return [
            [['id', 'cat_id', 'type', 'public', 'locked', 'moderated', 'sort', 'num_posts', 'num_topics', 'last_post_id', 'poll', 'membergroup_id'], 'integer'],
            [['name', 'subtitle'], 'safe'],
        ];
    }

    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    public function search($params)
    {
        $query = YBoardForum::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'cat_id' => $this->cat_id,
            'type' => $this->type,
            'public' => $this->public,
            'locked' => $this->locked,
            'moderated' => $this->moderated,
            'sort' => $this->sort,
            'num_posts' => $this->num_posts,
            'num_topics' => $this->num_topics,
            'last_post_id' => $this->last_post_id,
            'poll' => $this->poll,
            'membergroup_id' => $this->membergroup_id,
        ]);

        $query->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'subtitle', $this->subtitle]);

        return $dataProvider;
    }
}


code:
<?php

namespace app\modules\yboard\models;

use Yii;
use app\modules\yboard\YBoard;

/**
 * This is the model class for table "yboard_ipaddress".
 *
 * @property string $id
 * @property string $ip
 * @property string $address
 * @property integer $source
 * @property integer $count
 * @property string $create_time
 * @property string $update_time
 */
class YBoardIpaddress extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'YBoardIPAddress';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['source', 'count'], 'integer'],
            [['create_time', 'update_time'], 'safe'],
            [['ip'], 'string', 'max' => 39],
            [['address'], 'string', 'max' => 255],
            [['ip'], 'unique'],
        ];
    }

    public static function blocked($ip) {
		$model = YBoardIpaddress::find()->where(['ip' => $ip])->one();
		if($model === null) {
			return false;
		} else {
			$model->updateCounters(['count'=>1]);					// method since Yii 1.1.8
			return true;
		}
	}

    public function beforeValidate() {
		if(strlen($this->ip) > 0 && $this->address == '') {
			$this->address = gethostbyaddr($this->ip);
		}
		return parent::beforeValidate();
	}

    public function beforeSave($insert) {
        $this->create_time = new \yii\db\Expression('NOW()');
        $this->update_time = new \yii\db\Expression('NOW()');
        $this->source = $this->count = 0;

		return parent::beforeSave($insert);
	}

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => YBoard::t('yboard', 'ID'),
            'ip' => YBoard::t('yboard', 'Ip'),
            'address' => YBoard::t('yboard', 'Address'),
            'source' => YBoard::t('yboard', 'Source'),
            'count' => YBoard::t('yboard', 'Count'),
            'create_time' => YBoard::t('yboard', 'Create Time'),
            'update_time' => YBoard::t('yboard', 'Update Time'),
        ];
    }
}


code:
<?php

namespace app\modules\yboard\models;

use Yii;
use app\modules\yboard\YBoard;

/**
 * This is the model class for table "yboard_log_topic".
 *
 * @property string $member_id
 * @property string $topic_id
 * @property string $forum_id
 * @property string $last_post_id
 *
 * @property YBoardMember $member
 * @property YBoardForum $forum
 * @property YBoardPost $lastPost
 * @property YBoardTopic $topic
 */
class YBoardLogTopic extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'YBoardLogTopic';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['member_id', 'topic_id', 'forum_id', 'last_post_id'], 'required'],
            [['member_id', 'topic_id', 'forum_id', 'last_post_id'], 'integer']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'member_id' => YBoard::t('yboard', 'Member ID'),
            'topic_id' => YBoard::t('yboard', 'Topic ID'),
            'forum_id' => YBoard::t('yboard', 'Forum ID'),
            'last_post_id' => YBoard::t('yboard', 'Last Post ID'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMember()
    {
        return $this->hasOne(YBoardMember::className(), ['id' => 'member_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getForum()
    {
        return $this->hasOne(YBoardForum::className(), ['id' => 'forum_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getLastPost()
    {
        return $this->hasOne(YBoardPost::className(), ['id' => 'last_post_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTopic()
    {
        return $this->hasOne(YBoardTopic::className(), ['id' => 'topic_id']);
    }
}


code:
<?php

namespace app\modules\yboard\models;

use app\modules\yboard\YBoard;

use Yii;
use yii\helpers\Html;
use hosanna\profile\models\User;

/**
 * This is the model class for table "yboard_member".
 *
 * @property integer $id
 * @property string $location
 * @property string $personal_text
 * @property string $signature
 * @property integer $show_online
 * @property integer $contact_email
 * @property integer $contact_pm
 * @property string $first_visit
 * @property string $last_visit
 * @property integer $ip
 * @property string $group_id
 * @property string $rank_id
 * @property integer $upvoted
 * @property string $blogger
 * @property string $facebook
 * @property string $skype
 * @property string $google
 * @property string $linkedin
 * @property string $skype
 * @property string $github
 * @property string $orkut
 * @property string $tumblr
 * @property string $twitter
 * @property string $website
 * @property string $wordpress
 * @property string $yahoo
 * @property string $youtube
 *
 * @property YBoardLogTopic[] $yboardLogTopics
 * @property YBoardTopic[] $topics
 * @property Users $profile
 * @property YBoardMembergroup $group
 * @property YBoardMessage[] $yboardMessages
 * @property YBoardPoll[] $yboardPolls
 * @property YBoardPost[] $yboardPosts
 * @property YBoardUpvoted[] $yboardUpvoteds
 * @property YBoardVote[] $yboardVotes
 */
class YBoardMember extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'YBoardMember';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'required'],
            [['id', 'show_online', 'contact_email', 'contact_pm', 'group_id', 'rank_id'], 'integer'],
            [['first_visit', 'last_visit'], 'safe'],
            [['signature'], 'string'],
            // an inline validator for IP
            ['ip', function ($attribute, $params) {
                if (filter_var($this->$attribute, FILTER_VALIDATE_IP)) {
                    $this->addError($attribute, YBoard::t('yboard', 'Invalid IP Address'));
                }
            }],
            [['location', 'personal_text', 'blogger', 'facebook', 'skype', 'google', 'linkedin', 'metacafe', 'github', 'orkut', 'tumblr', 'twitter', 'website', 'wordpress', 'yahoo', 'youtube'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => YBoard::t('yboard', 'Member'),
            'location' => YBoard::t('yboard', 'Location'),
            'personal_text' => YBoard::t('yboard', 'Personal Text'),
            'signature' => YBoard::t('yboard', 'Signature'),
            'show_online' => YBoard::t('yboard', 'Show Online'),
            'contact_email' => YBoard::t('yboard', 'Allow Sending Email'),
            'contact_pm' => YBoard::t('yboard', 'Allow Sending PM'),
            'timezone' => YBoard::t('yboard', 'Timezone'),
            'first_visit' => YBoard::t('yboard', 'First Visit'),
            'last_visit' => YBoard::t('yboard', 'Last Visit'),
            'ip' => YBoard::t('yboard', 'IP Address'),
            'rank_id' => YBoard::t('yboard', 'Rank'),
            'group_id' => YBoard::t('yboard', 'Group'),
            'blogger' => YBoard::t('yboard', 'Blogger'),
            'facebook' => YBoard::t('yboard', 'Facebook'),
            'skype' => YBoard::t('yboard', 'Skype'),
            'google' => YBoard::t('yboard', 'Google'),
            'linkedin' => YBoard::t('yboard', 'Linkedin'),
            'metacafe' => YBoard::t('yboard', 'Metacafe'),
            'github' => YBoard::t('yboard', 'Github'),
            'orkut' => YBoard::t('yboard', 'Orkut'),
            'tumblr' => YBoard::t('yboard', 'Tumblr'),
            'twitter' => YBoard::t('yboard', 'Twitter'),
            'website' => YBoard::t('yboard', 'Website'),
            'wordpress' => YBoard::t('yboard', 'Wordpress'),
            'yahoo' => YBoard::t('yboard', 'Yahoo'),
            'youtube' => YBoard::t('yboard', 'Youtube'),
        ];
    }

    public function isBanned()
    {
        return YBoardBan::find()->where(['user_id'=>$this->id])->exists();
    }

    public function getRecentTopics()
    {
        $posts = $this->hasMany(YBoardTopic::className(), ['id' => 'topic_id'])->viaTable('YBoardLogTopic', ['member_id' => 'id'])
            ->limit(5)
            ->orderBy('id DESC')
            ->all();
        $items = [];
        foreach($posts as $post)
        {
            $items[] = Html::a($post->title, ['forum/topic', 'id'=>$post->id]);
        }
        return Html::ul($items, ['encode'=>false]);
    }

    /**
     * Total Topics started by user
     */
    public function getStartedTopics()
    {
        return $this->hasMany(YBoardTopic::className(), ['id' => 'topic_id'])->viaTable('YBoardLogTopic', ['member_id' => 'id'])->count();
    }

    /**
     * Total Topics started by user
     */
    public function getTotalReplies()
    {
        return $this->hasMany(YBoardPost::className(), ['user_id' => 'id'])
            ->andWhere(['original_post'=>0])
            ->count();
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getLogTopics()
    {
        return $this->hasMany(YBoardLogTopic::className(), ['member_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTopics()
    {
        return $this->hasMany(YBoardTopic::className(), ['id' => 'topic_id'])->viaTable('YBoardLogTopic', ['member_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getProfile()
    {
        return $this->hasOne(User::className(), ['id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGroup()
    {
        return $this->hasOne(YBoardMembergroup::className(), ['id' => 'group_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getRank()
    {
        return $this->hasOne(YBoardRank::className(), ['id' => 'rank_id']);
    }

    /**
     * @return YBoardMembergroup
     */
    public function getStatus()
    {
        $isOnline = YBoardSession::find()->where(['user_id'=>$this->id])->count();

        if($this->show_online>0)
        {
            if($isOnline>0)
            {
                return YBoard::t('yboard', 'Online');
            }
            else
            {
                return YBoard::t('yboard', 'Offline');
            }
        }
        else
        {
            return YBoard::t('yboard', 'Hidden');
        }
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMessages()
    {
        return $this->hasMany(YBoardMessage::className(), ['sendto' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPolls()
    {
        return $this->hasMany(YBoardPoll::className(), ['user_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPosts()
    {
        return $this->hasMany(YBoardPost::className(), ['user_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUpvotes()
    {
        return $this->hasMany(YBoardUpvoted::className(), ['member_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getVotes()
    {
        return $this->hasMany(YBoardVote::className(), ['user_id' => 'id']);
    }

    /**
     * Number of Total Upvotes in All your posts
     */
    public function getAppreciations()
    {
        return YBoardUpvoted::find()->where(['author'=>$this->id])->count();
    }

    /**
     * @inheritdoc
     * @return YBoardMemberQuery
    */
    public static function find()
    {
        return new YBoardMemberQuery(get_called_class());
    }

    public function beforeDelete()
    {
        if (parent::beforeDelete()) {
            //delete: Messages(to/from), Ban History, UpVotes, LogTopic
            YBoardMessage::deleteAll(['or', 'sendfrom'=>$this->id, 'sendto'=>$this->id]);
            // Post(Polls and Votes)
            YBoardVote::deleteAll(['user_id'=>$this->id]);
            YBoardUpvoted::deleteAll(['member_id'=>$this->id]);
            YBoardPoll::deleteAll(['user_id'=>$this->id]);

            YBoardPost::deleteAll(['user_id'=>$this->id]);

            //log topic
            YBoardLogTopic::deleteAll(['member_id'=>$this->id]);

            //ban
            YBoardBan::deleteAll(['user_id'=>$this->id]);

            return true;
        } else {
            return false;
        }
    }
}


code:
<?php
//Scopes for YBoardMember et al
namespace app\modules\yboard\models;

class YBoardMemberQuery extends \yii\db\ActiveQuery
{
    public function approvedScope()
    {
        return $this->andWhere(['approved' => 1]);
    }

    public function showScope()
    {
        return $this->andWhere(['show_online' => 1]);
    }

    public function hiddenScope()
    {
        return $this->andWhere(['show_online' => 0]);
    }

    public function newestScope()
    {
        return $this->orderBy('id DESC')->limit(1);
    }

    public function presentScope()
    {
        $ids = YBoardSession::find()
            ->asArray()
            ->where('user_id IS NOT NULL')
            ->orderBy('last_visit DESC')
            ->all();

        $uids= [];

        foreach($ids as $id)
        {
            $uids[] = $id['user_id'];
        }

        return $this->andWhere(['id'=>$uids]);
    }
}


code:
<?php

namespace app\modules\yboard\models;

use Yii;
use app\modules\yboard\YBoard;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\modules\yboard\models\YBoardMember;

/**
 * YBoardMemberSearch represents the model behind the search form about `app\modules\yboard\models\YBoardMember`.
 */
class YBoardMemberSearch extends YBoardMember
{
    public function rules()
    {
        return [
            [['id', 'gender', 'show_online', 'contact_email', 'contact_pm', 'warning', 'posts', 'group_id', 'upvoted', 'moderator'], 'integer'],
            [['birthdate', 'location', 'personal_text', 'signature', 'avatar', 'timezone', 'first_visit', 'last_visit', 'blogger', 'facebook', 'github', 'google', 'linkedin', 'metacafe', 'skype', 'orkut', 'tumblr', 'twitter', 'website', 'wordpress', 'yahoo', 'youtube'], 'safe'],
        ];
    }

    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    public function search($params)
    {
        $query = YBoardMember::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'birthdate' => $this->birthdate,
            'show_online' => $this->show_online,
            'contact_email' => $this->contact_email,
            'contact_pm' => $this->contact_pm,
            'first_visit' => $this->first_visit,
            'last_visit' => $this->last_visit,
            'warning' => $this->warning,
            'posts' => $this->posts,
            'group_id' => $this->group_id,
            'upvoted' => $this->upvoted,
            'moderator' => $this->moderator,
        ]);

        $query->andFilterWhere(['like', 'location', $this->location])
            ->andFilterWhere(['like', 'personal_text', $this->personal_text])
            ->andFilterWhere(['like', 'signature', $this->signature])
            ->andFilterWhere(['like', 'avatar', $this->avatar])
            ->andFilterWhere(['like', 'timezone', $this->timezone])
            ->andFilterWhere(['like', 'blogger', $this->blogger])
            ->andFilterWhere(['like', 'facebook', $this->facebook])
            ->andFilterWhere(['like', 'github', $this->github])
            ->andFilterWhere(['like', 'google', $this->google])
            ->andFilterWhere(['like', 'linkedin', $this->linkedin])
            ->andFilterWhere(['like', 'metacafe', $this->metacafe])
            ->andFilterWhere(['like', 'skype', $this->skype])
            ->andFilterWhere(['like', 'orkut', $this->orkut])
            ->andFilterWhere(['like', 'tumblr', $this->tumblr])
            ->andFilterWhere(['like', 'twitter', $this->twitter])
            ->andFilterWhere(['like', 'website', $this->website])
            ->andFilterWhere(['like', 'wordpress', $this->wordpress])
            ->andFilterWhere(['like', 'yahoo', $this->yahoo])
            ->andFilterWhere(['like', 'youtube', $this->youtube]);

        return $dataProvider;
    }
}


code:
<?php

namespace app\modules\yboard\models;

use yii\data\ActiveDataProvider;
use Yii;
use app\modules\yboard\YBoard;

/**
 * This is the model class for table "YBoardMemberGroup".
 *
 * @property integer $id
 * @property string $name
 * @property string $description
 * @property string $color
 * @property string $image
 * @property string $group_role
 *
 * @property YBoardMember[] $yBoardMembers
 */
class YBoardMembergroup extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'YBoardMemberGroup';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['description'], 'string'],
            [['name'], 'string', 'max' => 45],
            [['color'], 'string', 'max' => 7],
            [['image'], 'string', 'max' => 255],
            [['group_role'], 'string', 'max' => 64]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => YBoard::t('yboard', 'ID'),
            'name' => YBoard::t('yboard', 'Name'),
            'description' => YBoard::t('yboard', 'Description'),
            'color' => YBoard::t('yboard', 'Color'),
            'image' => YBoard::t('yboard', 'Image'),
            'group_role' => YBoard::t('yboard', 'Group Role'),
        ];
    }

    public function search()
    {
        $query = YBoardMembergroup::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        //if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
       // }

        //$query->andFilterWhere([
        //    'id' => $this->id,
        //]);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMembers()
    {
        return $this->hasMany(YBoardMember::className(), ['group_id' => 'id']);
    }

     /**
     * @inheritdoc
     * @return YBoardMemberQuery
    */
    public static function find()
    {
        return new YBoardMembergroupQuery(get_called_class());
    }
}


code:
<?php
//Scopes for YBoardMembergroup et al
namespace app\modules\yboard\models;

class YBoardMembergroupQuery extends \yii\db\ActiveQuery
{
    public function specificScope()
    {
        return $this->andWhere('id > 0');
    }
}


code:
<?php

namespace app\modules\yboard\models;

use Yii;
use app\modules\yboard\YBoard;
use app\modules\yboard\components\Utils;

/**
 * This is the model class for table "yboard_message".
 *
 * @property integer $id
 * @property integer $sendfrom
 * @property integer $sendto
 * @property integer $post_id
 * @property string $subject
 * @property string $content
 * @property string $create_time
 * @property integer $read_indicator
 * @property integer $type
 * @property integer $inbox
 * @property integer $outbox
 * @property string $ip
 *
 * @property YBoardMember $sendfrom0
 * @property YBoardMember $sendto0
 */
class YBoardMessage extends \yii\db\ActiveRecord
{
    public $usernames = null;
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'YBoardMessage';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['sendfrom', 'sendto', 'subject', 'content'], 'required'],
            [['id', 'sendfrom', 'sendto', 'post_id', 'read_indicator', 'type', 'inbox', 'outbox'], 'integer'],
            [['content', 'usernames'], 'string'],
            [['create_time'], 'safe'],
            [['subject'], 'string', 'max' => 255],
            [['ip'], 'string', 'max' => 39],
            [['ip'], 'blocked'],
            [['sendto'], 'mailboxFull', 'on'=>'insert'],

        ];
    }

    public function blocked($attribute, $params) {
		if(YBoardIpaddress::blocked($this->ip)) {
			$this->addError('ip', YBoard::t('yboard','Your IP address has been blocked.'));
		}
	}

    public function mailboxFull($attr, $params) {
		$criteria = ['outbox'=> 1, 'sendfrom' =>Yii::$app->user->id];
		if(YBoardMessage::find()->where($criteria)->outbox()->count() >=Yii::$app->params['maxMessages']) {
			$this->addError('sendto', YBoard::t('yboard', 'Your outbox is full. Please make room before sending new messages.'));
		}
	}

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => YBoard::t('yboard', 'ID'),
            'sendfrom' => YBoard::t('yboard', 'From'),
            'sendto' => YBoard::t('yboard', 'To'),
            'post_id' => YBoard::t('yboard', 'Post'),
            'subject' => YBoard::t('yboard', 'Subject'),
            'content' => YBoard::t('yboard', 'Contents'),
            'create_time' => YBoard::t('yboard', 'Time'),
            'read_indicator' => YBoard::t('yboard', 'Read Indicator'),
            'type' => YBoard::t('yboard', 'Type'),
            'inbox' => YBoard::t('yboard', 'Inbox'),
            'outbox' => YBoard::t('yboard', 'Outbox'),
            'ip' => YBoard::t('yboard', 'IP Address'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getSender()
    {
        return $this->hasOne(YBoardMember::className(), ['id' => 'sendfrom']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getReceiver()
    {
        return $this->hasOne(YBoardMember::className(), ['id' => 'sendto']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPost()
    {
        return $this->hasOne(YBoardPost::className(), ['id' => 'post_id']);
    }

    /**
     * @inheritdoc
     * @return YBoardForumQuery
     */
    public static function find()
    {
        return new YBoardMessageQuery(get_called_class());
    }

    public function beforeSave($insert)
    {
        $this->content = Utils::cleanHtml($this->content);

        return parent::beforeSave($insert);
    }

}


code:
<?php
//Scopes for YBoardForum et al
namespace app\modules\yboard\models;

class YBoardMessageQuery extends \yii\db\ActiveQuery
{
    public function inboxScope()
    {
        return $this->andWhere(['inbox' => 1]);
    }

    public function outboxScope()
    {
        return $this->andWhere(['outbox' => 1]);
    }

    public function unreadScope()
    {
        return $this->andWhere(['read_indicator' => 0]);
    }

    public function reportScope()
    {
        return $this->andWhere(['sendto' => 0]);
    }

    public function reportMsgScope()
    {
        return $this->andWhere(['sendto' => 0]);
    }
}


code:
<?php

namespace app\modules\yboard\models;

use Yii;
use app\modules\yboard\YBoard;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\modules\yboard\models\YBoardMessage;

/**
 * YBoardMessageSearch represents the model behind the search form about `app\modules\yboard\models\YBoardMessage`.
 */
class YBoardMessageSearch extends YBoardMessage
{
    public function rules()
    {
        return [
            [['id', 'sendfrom', 'sendto', 'read_indicator', 'type', 'inbox', 'outbox', 'post_id'], 'integer'],
            [['subject', 'content', 'create_time', 'ip'], 'safe'],
        ];
    }

    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    public function search($params)
    {
        $query = YBoardMessage::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'sendfrom' => $this->sendfrom,
            'sendto' => $this->sendto,
            'create_time' => $this->create_time,
            'read_indicator' => $this->read_indicator,
            'type' => $this->type,
            'inbox' => $this->inbox,
            'outbox' => $this->outbox,
            'post_id' => $this->post_id,
        ]);

        $query->andFilterWhere(['like', 'subject', $this->subject])
            ->andFilterWhere(['like', 'content', $this->content])
            ->andFilterWhere(['like', 'ip', $this->ip]);

        return $dataProvider;
    }
}


code:
<?php

namespace app\modules\yboard\models;

use Yii;
use app\modules\yboard\YBoard;

/**
 * This is the model class for table "yboard_poll".
 *
 * @property string $id
 * @property string $question
 * @property string $post_id
 * @property string $user_id
 * @property string $expire_date
 * @property integer $allow_revote
 * @property integer $allow_multiple
 * @property integer $votes
 *
 * @property YBoardMember $user
 * @property YBoardPost $post
 * @property YBoardVote $yboardVote
 */
class YBoardPoll extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'YBoardPoll';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['question', 'post_id', 'user_id'], 'required'],
            [['post_id', 'user_id', 'allow_revote', 'allow_multiple', 'votes'], 'integer'],
            [['expire_date'], 'safe'],
            [['question'], 'string', 'max' => 200]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => YBoard::t('yboard', 'ID'),
            'question' => YBoard::t('yboard', 'Question'),
            'post_id' => YBoard::t('yboard', 'Post ID'),
            'user_id' => YBoard::t('yboard', 'User ID'),
            'expire_date' => YBoard::t('yboard', 'Expire Date'),
            'allow_revote' => YBoard::t('yboard', 'Allow Revote'),
            'allow_multiple' => YBoard::t('yboard', 'Allow Multiple'),
            'votes' => YBoard::t('yboard', 'Votes'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(YBoardMember::className(), ['id' => 'user_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPost()
    {
        return $this->hasOne(YBoardPost::className(), ['id' => 'post_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getVote()
    {
        return $this->hasOne(YBoardVote::className(), ['poll_id' => 'id']);
    }

    public function beforeDelete()
    {
        if (parent::beforeDelete()) {
            //delete all upvotes and polls
            YBoardUpvoted::deleteAll(['poll_id'=>$this->id]);

            return true;
        } else {
            return false;
        }
    }

}