public function init() { $this->name = "Список переходов"; $this->modelShowAttribute = "phrase"; $this->modelClassName = CmsSearchPhrase::className(); parent::init(); }
<?php /** * @author Semenov Alexander <*****@*****.**> * @link http://skeeks.com/ * @copyright 2010 SkeekS (СкикС) * @date 01.09.2015 */ ?> <?php echo \skeeks\cms\modules\admin\widgets\GridView::widget(['dataProvider' => new \yii\data\ActiveDataProvider(['query' => (new \yii\db\Query())->select(['id', 'phrase', 'count(*) as count'])->from(\skeeks\cms\models\CmsSearchPhrase::tableName())->groupBy(['phrase'])->orderBy(['count' => SORT_DESC])]), 'columns' => [['attribute' => 'phrase', 'label' => \Yii::t('app', 'Search Phrase')], ['attribute' => 'count', 'label' => \Yii::t('app', 'The number of requests')]]]); ?> <!-- -->
/** * Удаление старых поисковых запросов */ public function actionClearSearchPhrase() { if (\Yii::$app->cmsSearch->phraseLiveTime) { $deleted = CmsSearchPhrase::deleteAll(['<=', 'created_at', \Yii::$app->formatter->asTimestamp(time()) - (int) \Yii::$app->cmsSearch->phraseLiveTime]); \Yii::info("Удалено поисковых запросов: " . $deleted); } }
/** * @param ActiveDataProvider $dataProvider */ public function logResult(ActiveDataProvider $dataProvider) { $pages = 1; if ($dataProvider->totalCount > $dataProvider->pagination->pageSize) { $pages = round($dataProvider->totalCount / $dataProvider->pagination->pageSize); } $searchPhrase = new CmsSearchPhrase(['phrase' => $this->searchQuery, 'result_count' => $dataProvider->totalCount, 'pages' => $pages]); $searchPhrase->save(); }