Exemplo n.º 1
0
 /**
  * Validate model for double posting.
  * @param string $attribute password attribute.
  */
 public function doublePostValidation($attribute)
 {
     /** @var Post $lastPost */
     $lastPost = Post::find()->where(['user_id' => Yii::$app->getUser()->getIdentity()->getId()])->orderBy('id DESC')->limit(1)->one();
     $duration = 15;
     $time = time();
     if ($lastPost->created_at > $time - $duration) {
         $left = $duration - ($time - $lastPost->created_at);
         $this->addError($attribute, 'Для отправки нового сообщения, подождите ' . $left . ' ' . Yii::$app->formatter->numberEnding($left, ['секунда', 'секунды', 'секунд']) . '!');
         return;
     }
 }
Exemplo n.º 2
0
 /**
  * Returns page number in topic by post.
  * @param Post $post post model.
  * @return integer
  */
 protected function getPostPage($post)
 {
     $rows = Post::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;
 }
Exemplo n.º 3
0
 /**
  * @return string
  */
 public function actionMention()
 {
     if (Yii::$app->getRequest()->getIsAjax()) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $id = substr(Yii::$app->getRequest()->get('id'), 1);
         $query = Yii::$app->getRequest()->get('query');
         if (is_numeric($id)) {
             $posts = Post::find()->with(['user' => function ($query) {
                 /** @var \yii\db\Query $query */
                 $query->andWhere(['not in', 'id', Yii::$app->getUser()->getId()]);
             }])->where(['topic_id' => $id])->orderBy(['created_at' => SORT_DESC])->asArray()->all();
             $users = ArrayHelper::getColumn($posts, 'user');
             $usernames = array_unique(ArrayHelper::getColumn($users, 'username'));
             $usernames = array_diff($usernames, ['']);
         } else {
             $usernames = User::find()->where(['like', 'username', $query . '%', false])->orderBy(['number_posts' => SORT_DESC])->limit(5)->asArray()->all();
             $usernames = ArrayHelper::getColumn($usernames, 'username');
         }
         $usernames = array_values($usernames);
         return $usernames;
     }
     throw new NotFoundHttpException();
 }
Exemplo n.º 4
0
 /**
  * @param $params
  * @return ActiveDataProvider
  * @throws \yii\base\InvalidConfigException
  */
 public static function getDataProvider($params)
 {
     $query = Post::find()->with('user', 'topic')->orderBy(['created_at' => SORT_ASC]);
     if ($params['topic_id']) {
         $query->andWhere(['topic_id' => $params['topic_id']]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['route' => '/topic/default/view', 'params' => ['id' => $params['topic_id'], 'page' => $params['page']], 'forcePageParam' => false, 'pageSizeLimit' => false, 'defaultPageSize' => Yii::$app->config->get('display_posts_count')]]);
     $dataProvider->prepare();
     return $dataProvider;
 }
Exemplo n.º 5
0
    ?>
            </tbody>
        </table>
    </div>
    <?php 
}
?>
    <div class="statistic">
        <div class="clearfix">
            <ul class="right">
                <li>Тем: <strong><?php 
echo $formatter->asInteger(\topic\models\Topic::countAll());
?>
</strong></li>
                <li>Сообщений: <strong><?php 
echo $formatter->asInteger(\post\models\Post::find()->count());
?>
</strong></li>
            </ul>
            <ul class="left">
                <li>Количество пользователей: <strong><?php 
echo $formatter->asInteger(User::find()->count());
?>
</strong></li>
                <li>Последним зарегистрировался: <a href="">X</a></li>
            </ul>
        </div>
        <div class="onlinelist">
            <span><strong>Сейчас на форуме: </strong> <?php 
echo UserOnline::countGuests();
?>