Commit 8bfd70ae by san58

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

1 parent 9cf9b8b0
......@@ -57,7 +57,7 @@ class ScanController extends Controller
$csv_handle = fopen($csv_file ,'r');
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 = '';
$progress = 0;
while (($csv_data = fgetcsv($csv_handle, 1024, ';')) !== false)
......@@ -84,12 +84,16 @@ class ScanController extends Controller
);
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)
$csv_skip_row++;
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();
if ($db_request)
{
......@@ -107,7 +111,10 @@ class ScanController extends Controller
'domain' =>$host,
'created_at' => new Expression('NOW()'),
'csv_date' => $csv_datatime,
'status' => $status
'status' => Host::STATUS_ON,
'f1_status' => $status['1'],
'f2_status' => $status['2'],
'f3_status' => $status['3']
]
)->execute();
$rec['insert']++;
......@@ -118,7 +125,9 @@ class ScanController extends Controller
'{{%host}}',
[
'csv_date' => $csv_datatime,
'status' => $status
'f1_status' => $status['1'],
'f2_status' => $status['2'],
'f3_status' => $status['3']
],
[
'domain' => $host
......
......@@ -18,7 +18,7 @@ class Collection extends Component
}
//Фильтрация фомена
public static function domain_filter($domain, $filters)
public static function domain_filter($domain)
{
$out = false;
$host = str_replace(
......@@ -27,7 +27,7 @@ class Collection extends Component
utf8_encode($domain)
);
if (count( explode('.', $host) ) === 2)
$out = Collection::apply_filter($host, $filters);
$out = $host;
unset($host);
return $out;
}
......
......@@ -55,44 +55,51 @@ class AjaxController extends Controller
public function actionCalcStatus()
{
$count_update = [Host::STATUS_OFF => 0, Host::STATUS_ON => 0];
$update = [Host::STATUS_OFF => [], Host::STATUS_ON => []];
$filters = Collection::get_filter(Filter::TYPE_AFTER);
$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)];
$query = (new Query())->select('id, domain')->from('{{%host}}');
if ($query)
{
foreach ($query->batch(1000) as $hosts)
{
foreach ($filters as $filter_type=>$filter)
{
$update = [Host::STATUS_OFF=>[],Host::STATUS_ON=>[]];
foreach ($hosts as $host)
$update[
(
Collection::apply_filter($host['domain'], $filters) === false ?
Collection::apply_filter($host['domain'], $filter) === false ?
Host::STATUS_OFF :
Host::STATUS_ON
)
][] = $host['id'];
unset($host);
$filter_name = 'f'.($filter_type+1).'_status';
if (count($update[Host::STATUS_OFF])>0)
{
Yii::$app->db->createCommand()
->update('{{%host}}', ['status' => Host::STATUS_OFF], ['in', 'id', $update[Host::STATUS_OFF]])
->update('{{%host}}', [$filter_name => Host::STATUS_OFF], ['in', 'id', $update[Host::STATUS_OFF]])
->execute();
$count_update[Host::STATUS_OFF]+=count($update[Host::STATUS_OFF]);
$update[Host::STATUS_OFF] = [];
$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}}', ['status' => Host::STATUS_ON], ['in', 'id', $update[Host::STATUS_ON]])
->update('{{%host}}', [$filter_name => Host::STATUS_ON], ['in', 'id', $update[Host::STATUS_ON]])
->execute();
$count_update[Host::STATUS_ON]+=count($update[Host::STATUS_ON]);
$update[Host::STATUS_ON] = [];
$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($query);
unset($filters);
unset($update);
return [
'controller' => 'ajax',
'is_guest' => Yii::$app->user->isGuest,
......
......@@ -46,7 +46,7 @@ class HostFreeController extends Controller
*/
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);
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
const STATUS_OFF = 0; //выкл
const STATUS_ON = 1; //вкл
const TYPE_BEFORE = 0; //До добавления БД
const TYPE_AFTER = 1; //После добавления БД
const TYPE_1 = 0; //До добавления БД
const TYPE_2 = 1; //После добавления БД
const TYPE_3 = 2; //После добавления БД
/**
* {@inheritdoc}
......@@ -120,8 +121,9 @@ class Filter extends \yii\db\ActiveRecord
public static function getTypes($type = false)
{
$arr = [
self::TYPE_BEFORE => 'Before',
self::TYPE_AFTER => 'After'
self::TYPE_1 => 'Filter №1',
self::TYPE_2 => 'Filter №2',
self::TYPE_3 => 'Filter №3'
];
if (is_numeric($type)) {
if (array_key_exists($type, $arr)) {
......
......@@ -61,8 +61,11 @@ class Host extends \yii\db\ActiveRecord
return [
[['domain'], 'required'],
['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'],
[['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'], 'unique'],
];
......@@ -84,6 +87,9 @@ class Host extends \yii\db\ActiveRecord
'tix' => 'TIX',
'tix_status' => 'TIX status',
'tix_date' => 'Date TIX',
'f1_status' => 'Filter №1',
'f2_status' => 'Filter №2',
'f3_status' => 'Filter №3',
'status' => 'Status'
];
}
......@@ -97,6 +103,21 @@ class Host extends \yii\db\ActiveRecord
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)
{
$arr = [
......
......@@ -17,8 +17,8 @@ class HostSearch extends Host
public function rules()
{
return [
[['id', 'wis_status', 'tix', 'status', 'tix_status'], 'integer'],
[['domain', 'created_at', 'csv_date', 'wis_date','wis_status','domain_expire', 'status', 'tix_date', 'tix_status'], 'safe'],
[['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', 'f1_status','f2_status','f3_status'], 'safe'],
];
}
......@@ -65,6 +65,9 @@ class HostSearch extends Host
'wis_status' => $this->wis_status,
'tix_status' => $this->tix_status,
//'domain_expire' => $this->domain_expire,
'f1_status'=>$this->f1_status,
'f2_status'=>$this->f2_status,
'f3_status'=>$this->f3_status,
'tix' => $this->tix,
'status' => $this->status
]);
......
......@@ -31,9 +31,33 @@ $this->params['breadcrumbs'][] = $this->title;
'id',
'pattern:ntext',
'created',
'include',
'status',
//'type',
'include' =>
[
'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'],
],
......
......@@ -13,7 +13,7 @@ $this->params['breadcrumbs'][] = $this->title;
?>
<div class="filter-view">
<h1><?= Html::encode($this->title) ?></h1>
<h1>View filter shema №<?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
......
......@@ -21,8 +21,6 @@ use app\models\Host;
<?= $form->field($model, 'wis_date')->textInput() ?>
<?= $form->field($model, 'wis_status')->textInput() ?>
<?= $form->field($model, 'tix')->textInput() ?>
<?= $form->field($model, 'tix_date')->textInput() ?>
......@@ -31,6 +29,12 @@ use app\models\Host;
<?= $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()) ?>
<div class="form-group">
......
......@@ -66,6 +66,33 @@ $this->params['breadcrumbs'][] = $this->title;
},
],
'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' =>
[
'attribute' => 'status',
......
......@@ -54,6 +54,36 @@ $this->params['breadcrumbs'][] = $this->title;
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',
'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!