Ejemplo n.º 1
0
 public function actionIndex()
 {
     $season = Season::findBySql('SELECT * FROM season WHERE invisible = 0 AND (unit1 != "" OR unit2 != "" OR unit3 != "" OR unit4 != "")')->all();
     $news = News::find()->where(['type' => '1'])->orderBy('id DESC')->one();
     $event = News::find()->where(['type' => '2'])->orderBy('id DESC')->one();
     $msgs = Chatmain::find()->orderBy('id DESC')->limit(50)->all();
     return $this->render('index', ['season' => $season, 'news' => $news, 'event' => $event, 'msgs' => $msgs]);
 }
Ejemplo n.º 2
0
 public function actionAjaxenterchatmain()
 {
     if (isset($_GET['text']) && $_GET['text'] != NULL) {
         $_GET['text'] = substr($_GET['text'], 0, 254);
         if (!Yii::$app->user->isGuest) {
             // проверка на спам.
             $check = Chatmain::findOne(['admin_id' => Yii::$app->user->id]);
             if ($check && $check['time'] < time() - 10) {
                 // создание новой записи
                 $model = new Chatmain();
                 $model->admin_id = Yii::$app->user->id;
                 $model->text = $_GET['text'];
                 $model->time = time();
                 if ($model->save()) {
                     echo '<div>
                     <span>' . User::name(Yii::$app->user->id) . ': </span>
                     <span>' . nl2br(HTML::encode($_GET['text'])) . '</span>
                 </div>';
                 } else {
                     echo '== данные не сохранились... ==';
                 }
             } else {
                 '<div class="grey">
                     <span>.User::name(Yii::$app->user->id): </span>
                     <span>' . nl2br(HTML::encode($_GET['text'])) . '</span>
                     <span> (Антиспам: сообщение не будет сохранено)</span>
                 </div>';
             }
         } else {
             echo '<div class="grey">
                 <span>Гость: </span>
                 <span>' . nl2br(HTML::encode($_GET['text'])) . '</span>
             </div>';
         }
     }
     //else echo '== данные не получены... ==';
 }