/** * 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, 'sort' => ['defaultOrder' => ['date' => SORT_DESC]]]); $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, 'reply_to' => $this->reply_to, 'post_id' => $this->post_id, 'user_id' => $this->user_id, 'date' => $this->date, 'is_register' => $this->is_register, 'approve' => $this->approve]); $query->andFilterWhere(['like', 'text_raw', $this->text_raw])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'ip', $this->ip]); return $dataProvider; }
public static function getSiteSummary() { $today_begin = date("Y-m-d") . " 00:00:00"; $today_end = date("Y-m-d") . " 23:59:59"; $yesterday_begin = date("Y-m-d 00:00:00", time() - 86400); $yesterday_end = date("Y-m-d 23:59:59", time() - 86400); // Статьи $summary['postsCount'] = Post::find()->count(); $summary['postsToday'] = Post::find()->where(['between', 'date', $today_begin, $today_end])->count(); $summary['postsYesterday'] = Post::find()->where(['between', 'date', $yesterday_begin, $yesterday_end])->count(); // Пользователи $summary['usersCount'] = User::find()->count(); $summary['usersToday'] = User::find()->where(['between', 'created_at', strtotime($today_begin), strtotime($today_end)])->count(); $summary['usersYesterday'] = User::find()->where(['between', 'created_at', strtotime($yesterday_begin), strtotime($yesterday_end)])->count(); // Комментарии $summary['commentsCount'] = Comment::find()->count(); $summary['commentsToday'] = Comment::find()->where(['between', 'date', $today_begin, $today_end])->count(); $summary['commentsYesterday'] = Comment::find()->where(['between', 'date', $yesterday_begin, $yesterday_end])->count(); // Ошибки $summary['errorsCount'] = Log::find()->count(); $summary['errorsToday'] = Log::find()->where(['between', 'log_time', strtotime($today_begin), strtotime($today_end)])->count(); $summary['errorsYesterday'] = Log::find()->where(['between', 'log_time', strtotime($yesterday_begin), strtotime($yesterday_end)])->count(); return $summary; }
/** * Возвращает последние commNum комментариев из таблицы comment * @return array|\yii\db\ActiveRecord[] */ public function getComments() { return Comment::find()->with('user')->orderBy(['date' => SORT_DESC])->limit($this->commNum)->all(); }