Egorka
6 years ago
13 changed files with 216 additions and 17 deletions
@ -0,0 +1,41 @@
|
||||
<?php |
||||
|
||||
use core\entities\Search; |
||||
use yii\helpers\Html; |
||||
use yii\grid\GridView; |
||||
use yii\helpers\StringHelper; |
||||
|
||||
/* @var $this yii\web\View */ |
||||
/* @var $provider yii\data\ActiveDataProvider */ |
||||
/* @var $form \core\forms\SearchForm */ |
||||
|
||||
$title = Yii::t('main', 'Search results'); |
||||
$this->title = $title . ' > ' . Html::encode($form->query); |
||||
$this->params['breadcrumbs'][] = $title; |
||||
?> |
||||
<div class="blog-post-index"> |
||||
|
||||
<div class="box"> |
||||
<div class="box-body"> |
||||
<?= GridView::widget([ |
||||
'dataProvider' => $provider, |
||||
'showHeader' => false, |
||||
'options' => [ |
||||
'style' => 'word-wrap:break-word;', |
||||
], |
||||
'tableOptions' => [ |
||||
'class' => 'table', |
||||
], |
||||
'columns' => [ |
||||
[ |
||||
'attribute' => 'title', |
||||
'value' => function (Search $model) { |
||||
return Html::a(Html::tag('h3', $model->title), [$model->url]) . StringHelper::truncateWords(strip_tags($model->content), 60, '...'); |
||||
}, |
||||
'format' => 'raw', |
||||
], |
||||
], |
||||
]); ?> |
||||
</div> |
||||
</div> |
||||
</div> |
@ -0,0 +1,20 @@
|
||||
<?php |
||||
/** |
||||
* Created by Error202 |
||||
* Date: 05.07.2018 |
||||
* |
||||
* Init / Update search mysql performance |
||||
*/ |
||||
|
||||
namespace console\controllers; |
||||
|
||||
use core\components\SearchPerformance; |
||||
use yii\console\Controller; |
||||
|
||||
class SearchInitController extends Controller { |
||||
|
||||
public function actionInit() { |
||||
SearchPerformance::init(); |
||||
echo "Search performance complete" . PHP_EOL; |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
<?php |
||||
/** |
||||
* Created by Error202 |
||||
* Date: 05.07.2018 |
||||
*/ |
||||
|
||||
namespace core\components; |
||||
|
||||
use Yii; |
||||
|
||||
class SearchPerformance { |
||||
public static function init() |
||||
{ |
||||
$connection = Yii::$app->getDb(); |
||||
$command = $connection->createCommand(" |
||||
CREATE OR REPLACE VIEW view_search AS " . implode(' UNION ', Yii::$app->params['search_rules'])); |
||||
$command->execute(); |
||||
} |
||||
} |
@ -0,0 +1,26 @@
|
||||
<?php |
||||
/** |
||||
* Created by Error202 |
||||
* Date: 05.07.2018 |
||||
*/ |
||||
|
||||
namespace core\entities; |
||||
|
||||
use yii\db\ActiveRecord; |
||||
|
||||
/** |
||||
* Class Search |
||||
* @package core\entities |
||||
* |
||||
* @property string $title |
||||
* @property string $content |
||||
* @property string $url |
||||
*/ |
||||
|
||||
class Search extends ActiveRecord |
||||
{ |
||||
public static function tableName(): string |
||||
{ |
||||
return '{{view_search}}'; |
||||
} |
||||
} |
@ -0,0 +1,21 @@
|
||||
<?php |
||||
/** |
||||
* Created by Error202 |
||||
* Date: 10.02.2018 |
||||
*/ |
||||
|
||||
namespace core\forms; |
||||
|
||||
use yii\base\Model; |
||||
|
||||
class SearchForm extends Model |
||||
{ |
||||
public $query; |
||||
|
||||
public function rules() { |
||||
return [ |
||||
['query', 'required'], |
||||
['query', 'string'], |
||||
]; |
||||
} |
||||
} |
Loading…
Reference in new issue