コード例 #1
0
 public function actionViewOwnpostTopics()
 {
     // !!! need access check
     if (Yii::$app->getUser()->getIsGuest()) {
         throw new NotFoundHttpException();
     }
     $user = Yii::$app->getUser()->getIdentity();
     $posts = PostModels::find()->select(['topic_id', 'user_id'])->where('user_id = :user_id', [':user_id' => $user->id])->asArray()->all();
     $ids = ArrayHelper::getColumn($posts, 'topic_id');
     $uniqueIDs = array_unique($ids);
     $query = TopicModels::find()->where(['IN', 'id', $uniqueIDs])->andWhere('forum_id NOT LIKE 0')->with('forum')->orderBy(['last_post_created_at' => SORT_DESC]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['forcePageParam' => false, 'pageSizeLimit' => false, 'defaultPageSize' => Yii::$app->config->get('display_topics_count')]]);
     $topics = $dataProvider->getModels();
     return $this->render('topic_list', ['title' => 'Темы с вашим участием', 'dataProvider' => $dataProvider, 'topics' => $topics]);
 }
コード例 #2
0
 /**
  * @return string
  */
 public function actionMention()
 {
     if (Yii::$app->getRequest()->getIsAjax()) {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         $id = substr(Yii::$app->getRequest()->post('id'), 1);
         $posts = PostModels::find()->with('user')->where(['topic_id' => $id])->asArray()->all();
         $currentUser = Yii::$app->getUser()->getIdentity();
         $users = ArrayHelper::getColumn($posts, 'user');
         $usernames = array_unique(ArrayHelper::getColumn($users, 'username'));
         $key = array_search($currentUser->username, $usernames);
         if (is_array($usernames) && is_numeric($key) && array_key_exists($key, $usernames)) {
             unset($usernames[$key]);
         }
         $usernames = array_values($usernames);
         return $usernames;
     }
     throw new NotFoundHttpException();
 }
コード例 #3
0
?>
    <div class="statistic">
        <div class="clearfix">
            <ul class="right">
                <li><?php 
echo Yii::t('forum', 'Тем:');
?>
 <strong><?php 
echo $formatter->asInteger(TopicModels::countAll());
?>
</strong></li>
                <li><?php 
echo Yii::t('forum', 'Сообщений:');
?>
 <strong><?php 
echo $formatter->asInteger(PostModels::find()->count());
?>
</strong></li>
            </ul>
            <ul class="left">
                <li><?php 
echo Yii::t('forum', 'Количество пользователей:');
?>
 <strong><?php 
echo $formatter->asInteger(UserModels::find()->count());
?>
</strong></li>
                <li><?php 
echo Yii::t('forum', 'Последним зарегистрировался:');
?>
 <?php 
コード例 #4
0
 public function getPostPage($post)
 {
     $rows = PostModels::find()->select('id')->where(['topic_id' => $post->topic_id])->asArray()->all();
     $index = 1;
     foreach ($rows as $row) {
         if ($row['id'] == $post->id) {
             break;
         }
         $index++;
     }
     $page = ceil($index / Yii::$app->config->get('display_posts_count'));
     return $page;
 }