Commit 8bfd70ae by san58

реализация фильтров 3-х типов

1 parent 9cf9b8b0
...@@ -57,7 +57,7 @@ class ScanController extends Controller ...@@ -57,7 +57,7 @@ class ScanController extends Controller
$csv_handle = fopen($csv_file ,'r'); $csv_handle = fopen($csv_file ,'r');
if ($csv_handle !== false) if ($csv_handle !== false)
{ {
$filters = ['before'=>Collection::get_filter(Filter::TYPE_BEFORE), 'after'=>Collection::get_filter(Filter::TYPE_AFTER)]; $filters = ['1'=>Collection::get_filter(Filter::TYPE_1), '2'=>Collection::get_filter(Filter::TYPE_2), '3'=>Collection::get_filter(Filter::TYPE_3)];
$csv_datatime = ''; $csv_datatime = '';
$progress = 0; $progress = 0;
while (($csv_data = fgetcsv($csv_handle, 1024, ';')) !== false) while (($csv_data = fgetcsv($csv_handle, 1024, ';')) !== false)
...@@ -84,12 +84,16 @@ class ScanController extends Controller ...@@ -84,12 +84,16 @@ class ScanController extends Controller
); );
elseif (isset($csv_data[1])===true) elseif (isset($csv_data[1])===true)
{ {
$host = Collection::domain_filter($csv_data[1], $filters['before']); $host = Collection::domain_filter($csv_data[1]);
if ($host === false) if ($host === false)
$csv_skip_row++; $csv_skip_row++;
else else
{ {
$status = (Collection::apply_filter($host, $filters['after'])===false?Host::STATUS_OFF:Host::STATUS_ON); $status = [
'1'=>(Collection::apply_filter($host, $filters['1'])===false?Host::STATUS_OFF:Host::STATUS_ON),
'2'=>(Collection::apply_filter($host, $filters['2'])===false?Host::STATUS_OFF:Host::STATUS_ON),
'3'=>(Collection::apply_filter($host, $filters['3'])===false?Host::STATUS_OFF:Host::STATUS_ON)
];
$db_request = Yii::$app->db->createCommand(); $db_request = Yii::$app->db->createCommand();
if ($db_request) if ($db_request)
{ {
...@@ -107,7 +111,10 @@ class ScanController extends Controller ...@@ -107,7 +111,10 @@ class ScanController extends Controller
'domain' =>$host, 'domain' =>$host,
'created_at' => new Expression('NOW()'), 'created_at' => new Expression('NOW()'),
'csv_date' => $csv_datatime, 'csv_date' => $csv_datatime,
'status' => $status 'status' => Host::STATUS_ON,
'f1_status' => $status['1'],
'f2_status' => $status['2'],
'f3_status' => $status['3']
] ]
)->execute(); )->execute();
$rec['insert']++; $rec['insert']++;
...@@ -118,7 +125,9 @@ class ScanController extends Controller ...@@ -118,7 +125,9 @@ class ScanController extends Controller
'{{%host}}', '{{%host}}',
[ [
'csv_date' => $csv_datatime, 'csv_date' => $csv_datatime,
'status' => $status 'f1_status' => $status['1'],
'f2_status' => $status['2'],
'f3_status' => $status['3']
], ],
[ [
'domain' => $host 'domain' => $host
......
...@@ -18,7 +18,7 @@ class Collection extends Component ...@@ -18,7 +18,7 @@ class Collection extends Component
} }
//Фильтрация фомена //Фильтрация фомена
public static function domain_filter($domain, $filters) public static function domain_filter($domain)
{ {
$out = false; $out = false;
$host = str_replace( $host = str_replace(
...@@ -27,7 +27,7 @@ class Collection extends Component ...@@ -27,7 +27,7 @@ class Collection extends Component
utf8_encode($domain) utf8_encode($domain)
); );
if (count( explode('.', $host) ) === 2) if (count( explode('.', $host) ) === 2)
$out = Collection::apply_filter($host, $filters); $out = $host;
unset($host); unset($host);
return $out; return $out;
} }
......
...@@ -55,44 +55,51 @@ class AjaxController extends Controller ...@@ -55,44 +55,51 @@ class AjaxController extends Controller
public function actionCalcStatus() public function actionCalcStatus()
{ {
$count_update = [Host::STATUS_OFF => 0, Host::STATUS_ON => 0]; $count_update = [Host::STATUS_OFF => 0, Host::STATUS_ON => 0];
$update = [Host::STATUS_OFF => [], Host::STATUS_ON => []]; $filters = [Filter::TYPE_1=>Collection::get_filter(Filter::TYPE_1), Filter::TYPE_2=>Collection::get_filter(Filter::TYPE_2), Filter::TYPE_3=>Collection::get_filter(Filter::TYPE_3)];
$filters = Collection::get_filter(Filter::TYPE_AFTER);
$query = (new Query())->select('id, domain')->from('{{%host}}'); $query = (new Query())->select('id, domain')->from('{{%host}}');
if ($query) if ($query)
{ {
foreach ($query->batch(1000) as $hosts) foreach ($query->batch(1000) as $hosts)
{ {
foreach ($hosts as $host) foreach ($filters as $filter_type=>$filter)
$update[
(
Collection::apply_filter($host['domain'], $filters) === false ?
Host::STATUS_OFF :
Host::STATUS_ON
)
][] = $host['id'];
unset($host);
if (count($update[Host::STATUS_OFF])>0)
{ {
Yii::$app->db->createCommand() $update = [Host::STATUS_OFF=>[],Host::STATUS_ON=>[]];
->update('{{%host}}', ['status' => Host::STATUS_OFF], ['in', 'id', $update[Host::STATUS_OFF]]) foreach ($hosts as $host)
->execute(); $update[
$count_update[Host::STATUS_OFF]+=count($update[Host::STATUS_OFF]); (
$update[Host::STATUS_OFF] = []; Collection::apply_filter($host['domain'], $filter) === false ?
} Host::STATUS_OFF :
if (count($update[Host::STATUS_ON])>0) Host::STATUS_ON
{ )
Yii::$app->db->createCommand() ][] = $host['id'];
->update('{{%host}}', ['status' => Host::STATUS_ON], ['in', 'id', $update[Host::STATUS_ON]]) unset($host);
->execute();
$count_update[Host::STATUS_ON]+=count($update[Host::STATUS_ON]); $filter_name = 'f'.($filter_type+1).'_status';
$update[Host::STATUS_ON] = []; if (count($update[Host::STATUS_OFF])>0)
{
Yii::$app->db->createCommand()
->update('{{%host}}', [$filter_name => Host::STATUS_OFF], ['in', 'id', $update[Host::STATUS_OFF]])
->execute();
$count_update[Host::STATUS_OFF]+=count($update[$filter_type][Host::STATUS_OFF]);
$update[$filter_type][Host::STATUS_OFF] = [];
}
if (count($update[Host::STATUS_ON])>0)
{
Yii::$app->db->createCommand()
->update('{{%host}}', [$filter_name => Host::STATUS_ON], ['in', 'id', $update[Host::STATUS_ON]])
->execute();
$count_update[Host::STATUS_ON]+=count($update[$filter_type][Host::STATUS_ON]);
$update[$filter_type][Host::STATUS_ON] = [];
}
unset($filter_name);
unset($update);
} }
unset($filter_type, $filter);
} }
unset($hosts); unset($hosts);
} }
unset($query); unset($query);
unset($filters); unset($filters);
unset($update);
return [ return [
'controller' => 'ajax', 'controller' => 'ajax',
'is_guest' => Yii::$app->user->isGuest, 'is_guest' => Yii::$app->user->isGuest,
......
...@@ -46,7 +46,7 @@ class HostFreeController extends Controller ...@@ -46,7 +46,7 @@ class HostFreeController extends Controller
*/ */
public function actionIndex() public function actionIndex()
{ {
$searchModel = new HostSearch(['wis_status' => Host::STATUS_WIS_FREE, 'status' => Filter::STATUS_ON]); $searchModel = new HostSearch(['wis_status' => Host::STATUS_WIS_FREE, 'status' => Filter::STATUS_ON, 'f1_status' => Filter::STATUS_ON, 'f2_status' => Filter::STATUS_ON, 'f3_status' => Filter::STATUS_ON]);
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [ return $this->render('index', [
......
<?php
use yii\db\Migration;
/**
* Class m210615_074539_add_filters_status
*/
class m210615_074539_add_filters_status extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('{{%host}}', 'f1_status', $this->tinyInteger(1)->notNull()->defaultValue(0)->comment('Статус проверки фильтра 1'));
$this->addColumn('{{%host}}', 'f2_status', $this->tinyInteger(1)->notNull()->defaultValue(0)->comment('Статус проверки фильтра 2'));
$this->addColumn('{{%host}}', 'f3_status', $this->tinyInteger(1)->notNull()->defaultValue(0)->comment('Статус проверки фильтра 3'));
$this->createIndex('idx-f1_status', '{{%host}}', 'f1_status');
$this->createIndex('idx-f2_status', '{{%host}}', 'f2_status');
$this->createIndex('idx-f3_status', '{{%host}}', 'f3_status');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropIndex('idx-f3_status', '{{%host}}');
$this->dropIndex('idx-f2_status', '{{%host}}');
$this->dropIndex('idx-f1_status', '{{%host}}');
$this->dropColumn('{{%host}}', 'f3_status');
$this->dropColumn('{{%host}}', 'f2_status');
$this->dropColumn('{{%host}}', 'f1_status');
}
}
...@@ -24,8 +24,9 @@ class Filter extends \yii\db\ActiveRecord ...@@ -24,8 +24,9 @@ class Filter extends \yii\db\ActiveRecord
const STATUS_OFF = 0; //выкл const STATUS_OFF = 0; //выкл
const STATUS_ON = 1; //вкл const STATUS_ON = 1; //вкл
const TYPE_BEFORE = 0; //До добавления БД const TYPE_1 = 0; //До добавления БД
const TYPE_AFTER = 1; //После добавления БД const TYPE_2 = 1; //После добавления БД
const TYPE_3 = 2; //После добавления БД
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -120,8 +121,9 @@ class Filter extends \yii\db\ActiveRecord ...@@ -120,8 +121,9 @@ class Filter extends \yii\db\ActiveRecord
public static function getTypes($type = false) public static function getTypes($type = false)
{ {
$arr = [ $arr = [
self::TYPE_BEFORE => 'Before', self::TYPE_1 => 'Filter №1',
self::TYPE_AFTER => 'After' self::TYPE_2 => 'Filter №2',
self::TYPE_3 => 'Filter №3'
]; ];
if (is_numeric($type)) { if (is_numeric($type)) {
if (array_key_exists($type, $arr)) { if (array_key_exists($type, $arr)) {
......
...@@ -61,8 +61,11 @@ class Host extends \yii\db\ActiveRecord ...@@ -61,8 +61,11 @@ class Host extends \yii\db\ActiveRecord
return [ return [
[['domain'], 'required'], [['domain'], 'required'],
['wis_status', 'in', 'range' => array_keys(self::getWisStatus())], ['wis_status', 'in', 'range' => array_keys(self::getWisStatus())],
['f1_status', 'in', 'range' => array_keys(self::getFStatus())],
['f2_status', 'in', 'range' => array_keys(self::getFStatus())],
['f3_status', 'in', 'range' => array_keys(self::getFStatus())],
[['created_at', 'csv_date', 'wis_date','domain_expire', 'tix_date'], 'safe'], [['created_at', 'csv_date', 'wis_date','domain_expire', 'tix_date'], 'safe'],
[['wis_status', 'tix', 'status', 'tix_status'], 'integer'], [['wis_status', 'tix', 'status', 'tix_status', 'f1_status', 'f2_status', 'f3_status'], 'integer'],
[['domain'], 'string', 'max' => 256], [['domain'], 'string', 'max' => 256],
[['domain'], 'unique'], [['domain'], 'unique'],
]; ];
...@@ -84,6 +87,9 @@ class Host extends \yii\db\ActiveRecord ...@@ -84,6 +87,9 @@ class Host extends \yii\db\ActiveRecord
'tix' => 'TIX', 'tix' => 'TIX',
'tix_status' => 'TIX status', 'tix_status' => 'TIX status',
'tix_date' => 'Date TIX', 'tix_date' => 'Date TIX',
'f1_status' => 'Filter №1',
'f2_status' => 'Filter №2',
'f3_status' => 'Filter №3',
'status' => 'Status' 'status' => 'Status'
]; ];
} }
...@@ -97,6 +103,21 @@ class Host extends \yii\db\ActiveRecord ...@@ -97,6 +103,21 @@ class Host extends \yii\db\ActiveRecord
return new HostQuery(get_called_class()); return new HostQuery(get_called_class());
} }
public static function getFStatus($status = false)
{
$arr = [
self::STATUS_OFF => 'Yes',
self::STATUS_ON => 'No'
];
if (is_numeric($status)) {
if (array_key_exists($status, $arr)) {
return $arr[$status];
}
return $status;
}
return $arr;
}
public static function getStatus($status = false) public static function getStatus($status = false)
{ {
$arr = [ $arr = [
......
...@@ -17,8 +17,8 @@ class HostSearch extends Host ...@@ -17,8 +17,8 @@ class HostSearch extends Host
public function rules() public function rules()
{ {
return [ return [
[['id', 'wis_status', 'tix', 'status', 'tix_status'], 'integer'], [['id', 'wis_status', 'tix', 'status', 'tix_status', 'f1_status','f2_status','f3_status'], 'integer'],
[['domain', 'created_at', 'csv_date', 'wis_date','wis_status','domain_expire', 'status', 'tix_date', 'tix_status'], 'safe'], [['domain', 'created_at', 'csv_date', 'wis_date','wis_status','domain_expire', 'status', 'tix_date', 'tix_status', 'f1_status','f2_status','f3_status'], 'safe'],
]; ];
} }
...@@ -65,6 +65,9 @@ class HostSearch extends Host ...@@ -65,6 +65,9 @@ class HostSearch extends Host
'wis_status' => $this->wis_status, 'wis_status' => $this->wis_status,
'tix_status' => $this->tix_status, 'tix_status' => $this->tix_status,
//'domain_expire' => $this->domain_expire, //'domain_expire' => $this->domain_expire,
'f1_status'=>$this->f1_status,
'f2_status'=>$this->f2_status,
'f3_status'=>$this->f3_status,
'tix' => $this->tix, 'tix' => $this->tix,
'status' => $this->status 'status' => $this->status
]); ]);
......
...@@ -31,9 +31,33 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -31,9 +31,33 @@ $this->params['breadcrumbs'][] = $this->title;
'id', 'id',
'pattern:ntext', 'pattern:ntext',
'created', 'created',
'include', 'include' =>
'status', [
//'type', 'attribute' => 'include',
'filter' => \app\models\Filter::getIncludes(),
'format' => 'raw',
'value' => function ($model) {
return $model::getIncludes($model->include);
},
],
'type' =>
[
'attribute' => 'type',
'filter' => \app\models\Filter::getTypes(),
'format' => 'raw',
'value' => function ($model) {
return $model::getTypes($model->type);
},
],
'status' =>
[
'attribute' => 'status',
'filter' => \app\models\Filter::getStatus(),
'format' => 'raw',
'value' => function ($model) {
return $model::getStatus($model->status);
},
],
['class' => 'yii\grid\ActionColumn'], ['class' => 'yii\grid\ActionColumn'],
], ],
......
...@@ -13,7 +13,7 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -13,7 +13,7 @@ $this->params['breadcrumbs'][] = $this->title;
?> ?>
<div class="filter-view"> <div class="filter-view">
<h1><?= Html::encode($this->title) ?></h1> <h1>View filter shema №<?= Html::encode($this->title) ?></h1>
<p> <p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
......
...@@ -21,8 +21,6 @@ use app\models\Host; ...@@ -21,8 +21,6 @@ use app\models\Host;
<?= $form->field($model, 'wis_date')->textInput() ?> <?= $form->field($model, 'wis_date')->textInput() ?>
<?= $form->field($model, 'wis_status')->textInput() ?>
<?= $form->field($model, 'tix')->textInput() ?> <?= $form->field($model, 'tix')->textInput() ?>
<?= $form->field($model, 'tix_date')->textInput() ?> <?= $form->field($model, 'tix_date')->textInput() ?>
...@@ -31,6 +29,12 @@ use app\models\Host; ...@@ -31,6 +29,12 @@ use app\models\Host;
<?= $form->field($model, 'wis_status', ['options' => ['class' => 'form-group']])->dropDownList(Host::getWisStatus()) ?> <?= $form->field($model, 'wis_status', ['options' => ['class' => 'form-group']])->dropDownList(Host::getWisStatus()) ?>
<?= $form->field($model, 'f1_status', ['options' => ['class' => 'form-group']])->dropDownList(Host::getFStatus()) ?>
<?= $form->field($model, 'f2_status', ['options' => ['class' => 'form-group']])->dropDownList(Host::getFStatus()) ?>
<?= $form->field($model, 'f3_status', ['options' => ['class' => 'form-group']])->dropDownList(Host::getFStatus()) ?>
<?= $form->field($model, 'status', ['options' => ['class' => 'form-group']])->dropDownList(Host::getStatus()) ?> <?= $form->field($model, 'status', ['options' => ['class' => 'form-group']])->dropDownList(Host::getStatus()) ?>
<div class="form-group"> <div class="form-group">
......
...@@ -66,6 +66,33 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -66,6 +66,33 @@ $this->params['breadcrumbs'][] = $this->title;
}, },
], ],
'tix_date', 'tix_date',
'f1_status' =>
[
'attribute' => 'f1_status',
'filter' => \app\models\Host::getFStatus(),
'format' => 'raw',
'value' => function ($model) {
return $model::getFStatus($model->f1_status);
},
],
'f2_status' =>
[
'attribute' => 'f2_status',
'filter' => \app\models\Host::getFStatus(),
'format' => 'raw',
'value' => function ($model) {
return $model::getFStatus($model->f2_status);
},
],
'f3_status' =>
[
'attribute' => 'f3_status',
'filter' => \app\models\Host::getFStatus(),
'format' => 'raw',
'value' => function ($model) {
return $model::getFStatus($model->f3_status);
},
],
'status' => 'status' =>
[ [
'attribute' => 'status', 'attribute' => 'status',
......
...@@ -54,6 +54,36 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -54,6 +54,36 @@ $this->params['breadcrumbs'][] = $this->title;
return $model::getTIXStatus($model->status); return $model::getTIXStatus($model->status);
}, },
], ],
'f1_status' =>
[
'attribute' => 'f1_status',
'filter' => Host::getFStatus(),
'format' => 'raw',
'value' => function ($model) {
return $model::getFStatus($model->f1_status);
},
],
'f2_status' =>
[
'attribute' => 'f2_status',
'filter' => Host::getFStatus(),
'format' => 'raw',
'value' => function ($model) {
return $model::getFStatus($model->f2_status);
},
],
'f3_status' =>
[
'attribute' => 'f3_status',
'filter' => Host::getFStatus(),
'format' => 'raw',
'value' => function ($model) {
return $model::getFStatus($model->f3_status);
},
],
[ [
'attribute' => 'status', 'attribute' => 'status',
'filter' => Host::getStatus(), 'filter' => Host::getStatus(),
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!