/** * Инициализация виджета */ public function init() { parent::init(); $this->model = new Comment(); $this->models = !empty($this->models) ? $this->models : Comment::find()->page()->approved()->all(); $this->publishAssets(); $this->buildCommentsArray(); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comment::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'user_id' => $this->user_id, 'likes' => $this->likes, 'status' => $this->status, 'notify' => $this->notify, 'created' => $this->created, 'updated' => $this->updated]); $query->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'ip', $this->ip]); $query->orderBy(['created' => SORT_DESC]); return $dataProvider; }
// array( // 'header' => 'Операции', // 'class'=>'CButtonColumn', // 'htmlOptions' => array( // 'width' => '70px', // 'style' => 'text-align: center;' // ), // ), // ), //)); ?> <p class="control"> Статус: <?php echo Html::dropDownList('status', '', Comment::getStatusArray(), $params = ['prompt' => '--Выберите статус--']); ?> <?php echo Html::submitButton('Применить', ['class' => 'ajaxUpdateStatus']); ?> <!-- --><?php //echo CHtml::ajaxSubmitButton('Применить', array('ajaxUpdateStatus'), array('success' => 'reloadGrid')); ?> | <?php echo Html::submitButton('Отметить прочитанными', ['class' => 'ajaxUpdateSetOld']); ?> <!-- --><?php //echo CHtml::ajaxSubmitButton('Отметить прочитанными', array('ajaxUpdateSetOld'), array('success' => 'reloadGrid')); ?> |
/** * Отправляет пачками письма пользователям о новых комментариях * @param $newComment */ protected function sendUserNotifies($newComment) { foreach (Comment::find()->page($newComment->url)->notify()->all() as $subscriber) { // Если email нового комментария (отправителя) совпадает с email подписчика, // то выходит что это один и тот же человек, ему уведомление не высылаем, пропускаем итерацию цикла if ($newComment->getEmail() === $subscriber->getEmail()) { continue; } $message = $this->renderPartial('../../extensions/comments_widget/views/email/notifyUser', ['newComment' => $newComment, 'userName' => $subscriber->getAuthor(), 'userEmail' => $subscriber->getEmail(), 'hash' => $subscriber->getHash()], true); $this->module->sendMail($subscriber->getEmail(), 'Новый комментарий на сайте "' . \Yii::$app->name . '"', $message); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Comment the loaded model * @throws \CHttpException */ public function findModel($id) { $model = Comment::findOne($id); if ($model === null) { throw new NotFoundHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * Кладёт массив лайков в сессию */ public function setLikesToSession() { $commentsLikes = Comment::getCommentsLikesFromSession(); if (isset($commentsLikes[$this->id])) { $commentsLikes[$this->id] = array('defaultLikes' => $commentsLikes[$this->id]['defaultLikes'], 'like' => $this->isLiked); } else { $commentsLikes[$this->id] = array('defaultLikes' => $this->oldLikes, 'like' => $this->isLiked); } // Кладём в сессию массив id моделей, для которой провелось голосование \Yii::$app->session['commentsLikes'] = $commentsLikes; }