<commit_before><?php
/**
 * Domain plugin for HiPanel
 *
 * @link      https://github.com/hiqdev/hipanel-module-domain
 * @package   hipanel-module-domain
 * @license   BSD-3-Clause
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
 */

namespace hipanel\modules\domain\grid;

use hipanel\grid\ActionColumn;
use hipanel\grid\BoxedGridView;
use hipanel\grid\MainColumn;
use hipanel\grid\XEditableColumn;
use hipanel\modules\domain\menus\DomainActionsMenu;
use hipanel\modules\domain\menus\DomainStateMenu;
use hipanel\modules\domain\models\Domain;
use hipanel\modules\domain\widgets\Expires;
use hipanel\modules\domain\widgets\GetPremiumButton;
use hipanel\widgets\ArraySpoiler;
use hipanel\widgets\IconStateLabel;
use hiqdev\bootstrap_switch\BootstrapSwitchColumn;
use hiqdev\bootstrap_switch\LabeledAjaxSwitch;
use hiqdev\combo\StaticCombo;
use hiqdev\yii2\menus\grid\MenuColumn;
use hiqdev\yii2\menus\widgets\Menu;
use Yii;
use yii\helpers\Html;
use yii\helpers\Url;

class DomainGridView extends BoxedGridView
{
    public function columns()
    {
        return array_merge(parent::columns(), [
            'is_premium' => [
                'format' => 'raw',
                'value' => function ($model) {
                    $state = ($model->premium->is_active) ? Yii::t('hipanel.domain.premium', 'Active till {expires,date} ({days_left,plural,=0{# days} =1{# day} other{# days}} left)', [
                        'expires' => strtotime($model->premium->expires),
                        'days_left' => $model->premium->days_left,
                    ]) : Html::tag('span', Yii::t('hipanel.domain.premium', 'Not activated'), ['class' => 'text-danger']);

                    return $state . GetPremiumButton::widget(['model' => $model]);
                },
                'contentOptions' => [
                    'style' => 'display: flex; flex-direction: row; justify-content: space-between; flex-wrap: wrap;',
                ],
            ],
            'premium_autorenewal' => [
                'class' => BootstrapSwitchColumn::class,
                'attribute' => 'premium_autorenewal',
                'url' => Url::toRoute('@domain/set-paid-feature-autorenewal'),
                'filter' => false,
                'enableSorting' => false,
                'encodeLabel' => false,
                'label' => Html::tag('span', Yii::t('hipanel.domain.premium', 'Premium autorenewal')),
                'pluginOptions' => function ($model) {
                    return [
                        'readonly' => !(bool) $model->premium->is_active,
                    ];
                },
                'switchOptions' => [
                    'class' => LabeledAjaxSwitch::class,
                    'labels' => [
                        0 => [
                            'style' => 'display: none;',
                            'class' => 'text-danger md-pl-10',
                            'content' => Yii::t('hipanel.domain.premium', 'You can enable automatic renewal of the premium package for this domain.'),
                        ],
                        1 => [
                            'style' => 'display: none;',
                            'class' => 'small text-muted font-normal md-pl-10',
                            'content' => Yii::t('hipanel.domain.premium', 'Automatic renewal of the premium package for this domain is enabled.'),
                        ],
                    ],
                ],
            ],
            'transfer_attention' => [
                'label' => Yii::t('hipanel:domain', 'Attention'),
                'value' => function ($model) {
                    return $model->client_name;
                },
            ],
            'transfer_re' => [
                'attribute' => 'domain',
                'label' => Yii::t('hipanel:domain', 'Re'),
                'value' => function ($model) {
                    return Yii::t('hipanel:domain', 'Transfer of {domain}', ['domain' => strtoupper($model->domain)]);
                },
            ],
            'domain' => [
                'class' => MainColumn::class,
                'attribute' => 'domain',
                'note' => true,
                'filterAttribute' => 'domain_like',
                'filterOptions' => ['class' => 'narrow-filter'],
            ],
            'state' => [
                'format' => 'raw',
                'filter' => function ($grid, $model, $attribute) {
                    return StaticCombo::widget([
                        'model' => $model,
                        'attribute' => $attribute,
                        'data' => Domain::stateOptions(),
                        'hasId' => true,
                    ]);
                },
                'filterOptions' => ['class' => 'narrow-filter'],
                'enableSorting' => false,
                'value' => function ($model) {
                    return DomainStateMenu::widget(['model' => $model]);
                },
            ],
            'foa_sent_to' => [
                'format' => 'raw',
                'filter' => false,
                'visible' => function ($model) {
                    return $model->canSendFOA();
                },
                'value' => function ($model) {
                    return Html::tag('span', '', ['class' => Menu::iconClass('fa-envelope')]) . ' ' . Html::encode($model->foa_sent_to);
                },
            ],
            'whois_protected' => [ // don't forget to update `whois_protected_with_label` column as well
                'attribute' => 'whois_protected',
                'filter' => false,
                'contentOptions' => ['class' => 'text-center', 'style' => 'vertical-align: middle;'],
                'enableSorting' => false,
                'encodeLabel' => false,
                'label' => Html::tag('span', Yii::t('hipanel:domain', 'WHOIS protect')),
                'popover' => Yii::t('hipanel:domain', 'WHOIS protection'),
                'popoverOptions' => [
                    'placement' => 'bottom',
                    'selector' => 'span',
                ],
                'format' => 'raw',
                'value' => function ($model) {
                    return IconStateLabel::widget([
                        'model' => $model,
                        'attribute' => 'whois_protected',
                        'icons' => 'fa-shield',
                        'messages' => [
                            Yii::t('hipanel:domain', 'WHOIS protect is enabled'),
                            Yii::t('hipanel:domain', 'WHOIS protect is disabled'),
                        ],
                    ]);
                },
                'exportedValue' => function ($model) {
                    return $model->whois_protected ? 'ON' : 'OFF';
                }
            ],
            'whois_protected_with_label' => [
                'class' => PaidWPColumn::class,
            ],
            'is_secured' => [ // don't forget to update `is_secured_with_label` column as well
                'encodeLabel' => false,
                'filter' => false,
                'enableSorting' => false,
                'label' => Html::tag('span', Yii::t('hipanel:domain', 'Protection')),
                'attribute' => 'is_secured',
                'popover' => Yii::t('hipanel:domain', 'Protection from transfer'),
                'contentOptions' => ['class' => 'text-center', 'style' => 'vertical-align: middle;'],
                'popoverOptions' => [
                    'placement' => 'bottom',
                    'selector' => 'span',
                ],
                'exportedValue' => function ($model) {
                    return $model->is_secured ? 'ON' : 'OFF';
                },
                'value' => function ($model) {
                    return IconStateLabel::widget([
                        'model' => $model,
                        'attribute' => 'is_secured',
                        'icons' => ['fa-lock', 'fa-unlock'],
                        'messages' => [
                            Yii::t('hipanel:domain', 'Secure domain service is enabled'),
                            Yii::t('hipanel:domain', 'Secure domain service is disabled'),
                        ],
                    ]);
                },
            ],
            'is_secured_with_label' => [ // don't forget to update `is_secured` column as well
                'class' => BootstrapSwitchColumn::class,
                'encodeLabel' => false,
                'filter' => false,
                'enableSorting' => false,
                'label' => Html::tag('span', Yii::t('hipanel:domain', 'Protection')),
                'url' => Url::toRoute('@domain/set-lock'),
                'attribute' => 'is_secured',
                'popover' => Yii::t('hipanel:domain', 'Protection from transfer'),
                'popoverOptions' => [
                    'placement' => 'bottom',
                    'selector' => 'span',
                ],
                'pluginOptions' => function($model) {
                    return [
                        'readonly' => !$model->isSecureChangeable(),
                    ];
                },
                'switchOptions' => [
                    'class' => LabeledAjaxSwitch::class,
                    'labels' => [
                        0 => [
                            'style' => 'display: none;',
                            'class' => 'text-danger md-pl-10',
                            'content' => Yii::t('hipanel:domain', 'The domain can be transferred, edited or deleted'),
                        ],
                        1 => [
                            'style' => 'display: none;',
                            'class' => 'small text-muted font-normal md-pl-10',
                            'content' => Yii::t('hipanel:domain', 'The domain can not be transferred, edited or deleted'),
                        ],
                    ],
                ],
            ],
            'note' => [
                'class' => XEditableColumn::class,
                'attribute' => 'note',
                'filter' => true,
                'popover' => Yii::t('hipanel:domain', 'Make any notes for your convenience'),
                'pluginOptions' => [
                    'url' => 'set-note',
                ],
            ],
            'created_date' => [
                'attribute' => 'created_date',
                'format' => 'date',
                'filter' => false,
                'contentOptions' => ['class' => 'text-nowrap'],
            ],
            'expires' => [
                'format' => 'raw',
                'filter' => false,
                'headerOptions' => ['style' => 'width:1em'],
                'value' => function ($model) {
                    $html = Expires::widget(['model' => $model, 'labelOptions' => ['style' => 'line-height: inherit!important;']]);
                    if ($model->isExpiresSoon() && $model->canRenew()) {
                        $html = Html::tag('span',
                            $html . '&nbsp;' . Html::a(Html::tag('i', null, ['class' => 'fa fa-fw fa-forward']) .
                            Yii::t('hipanel:domain', 'Renew'), ['add-to-cart-renewal', 'model_id' => $model->id], ['class' => 'btn btn-success btn-xs']),
                            ['style' => 'display: flex; justify-content: flex-start;']
                        );
                    }

                    return $html;
                },
            ],
            'autorenewal' => [ // don't forget to update `autorenewal_with_label` column as well
                'label' => Html::tag('span', Yii::t('hipanel:domain', 'Auto renew')),
                'attribute' => 'autorenewal',
                'exportedValue' => function ($model) {
                    return $model->autorenewal ? 'ON' : 'OFF';
                },
                'value' => function ($model) {
                    return IconStateLabel::widget([
                        'model' => $model,
                        'attribute' => 'autorenewal',
                        'icons' => 'fa-refresh',
                        'messages' => [
                            Yii::t('hipanel:domain', 'Autorenewal is enabled'),
                            Yii::t('hipanel:domain', 'Autorenewal is disabled'),
                        ],
                    ]);
                },
                'filter' => false,<commit_msg>fix grid: use html\raw (#117)<commit_after><?php
/**
 * Domain plugin for HiPanel
 *
 * @link      https://github.com/hiqdev/hipanel-module-domain
 * @package   hipanel-module-domain
 * @license   BSD-3-Clause
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
 */

namespace hipanel\modules\domain\grid;

use hipanel\grid\ActionColumn;
use hipanel\grid\BoxedGridView;
use hipanel\grid\MainColumn;
use hipanel\grid\XEditableColumn;
use hipanel\modules\domain\menus\DomainActionsMenu;
use hipanel\modules\domain\menus\DomainStateMenu;
use hipanel\modules\domain\models\Domain;
use hipanel\modules\domain\widgets\Expires;
use hipanel\modules\domain\widgets\GetPremiumButton;
use hipanel\widgets\ArraySpoiler;
use hipanel\widgets\IconStateLabel;
use hiqdev\bootstrap_switch\BootstrapSwitchColumn;
use hiqdev\bootstrap_switch\LabeledAjaxSwitch;
use hiqdev\combo\StaticCombo;
use hiqdev\yii2\menus\grid\MenuColumn;
use hiqdev\yii2\menus\widgets\Menu;
use Yii;
use yii\helpers\Html;
use yii\helpers\Url;

class DomainGridView extends BoxedGridView
{
    public function columns()
    {
        return array_merge(parent::columns(), [
            'is_premium' => [
                'format' => 'raw',
                'value' => function ($model) {
                    $state = ($model->premium->is_active) ? Yii::t('hipanel.domain.premium', 'Active till {expires,date} ({days_left,plural,=0{# days} =1{# day} other{# days}} left)', [
                        'expires' => strtotime($model->premium->expires),
                        'days_left' => $model->premium->days_left,
                    ]) : Html::tag('span', Yii::t('hipanel.domain.premium', 'Not activated'), ['class' => 'text-danger']);

                    return $state . GetPremiumButton::widget(['model' => $model]);
                },
                'contentOptions' => [
                    'style' => 'display: flex; flex-direction: row; justify-content: space-between; flex-wrap: wrap;',
                ],
            ],
            'premium_autorenewal' => [
                'class' => BootstrapSwitchColumn::class,
                'attribute' => 'premium_autorenewal',
                'url' => Url::toRoute('@domain/set-paid-feature-autorenewal'),
                'filter' => false,
                'enableSorting' => false,
                'encodeLabel' => false,
                'label' => Html::tag('span', Yii::t('hipanel.domain.premium', 'Premium autorenewal')),
                'pluginOptions' => function ($model) {
                    return [
                        'readonly' => !(bool) $model->premium->is_active,
                    ];
                },
                'switchOptions' => [
                    'class' => LabeledAjaxSwitch::class,
                    'labels' => [
                        0 => [
                            'style' => 'display: none;',
                            'class' => 'text-danger md-pl-10',
                            'content' => Yii::t('hipanel.domain.premium', 'You can enable automatic renewal of the premium package for this domain.'),
                        ],
                        1 => [
                            'style' => 'display: none;',
                            'class' => 'small text-muted font-normal md-pl-10',
                            'content' => Yii::t('hipanel.domain.premium', 'Automatic renewal of the premium package for this domain is enabled.'),
                        ],
                    ],
                ],
            ],
            'transfer_attention' => [
                'label' => Yii::t('hipanel:domain', 'Attention'),
                'value' => function ($model) {
                    return $model->client_name;
                },
            ],
            'transfer_re' => [
                'attribute' => 'domain',
                'label' => Yii::t('hipanel:domain', 'Re'),
                'value' => function ($model) {
                    return Yii::t('hipanel:domain', 'Transfer of {domain}', ['domain' => strtoupper($model->domain)]);
                },
            ],
            'domain' => [
                'class' => MainColumn::class,
                'attribute' => 'domain',
                'note' => true,
                'filterAttribute' => 'domain_like',
                'filterOptions' => ['class' => 'narrow-filter'],
            ],
            'state' => [
                'format' => 'raw',
                'filter' => function ($grid, $model, $attribute) {
                    return StaticCombo::widget([
                        'model' => $model,
                        'attribute' => $attribute,
                        'data' => Domain::stateOptions(),
                        'hasId' => true,
                    ]);
                },
                'filterOptions' => ['class' => 'narrow-filter'],
                'enableSorting' => false,
                'value' => function ($model) {
                    return DomainStateMenu::widget(['model' => $model]);
                },
            ],
            'foa_sent_to' => [
                'format' => 'raw',
                'filter' => false,
                'visible' => function ($model) {
                    return $model->canSendFOA();
                },
                'value' => function ($model) {
                    return Html::tag('span', '', ['class' => Menu::iconClass('fa-envelope')]) . ' ' . Html::encode($model->foa_sent_to);
                },
            ],
            'whois_protected' => [ // don't forget to update `whois_protected_with_label` column as well
                'attribute' => 'whois_protected',
                'filter' => false,
                'contentOptions' => ['class' => 'text-center', 'style' => 'vertical-align: middle;'],
                'enableSorting' => false,
                'encodeLabel' => false,
                'label' => Html::tag('span', Yii::t('hipanel:domain', 'WHOIS protect')),
                'popover' => Yii::t('hipanel:domain', 'WHOIS protection'),
                'popoverOptions' => [
                    'placement' => 'bottom',
                    'selector' => 'span',
                ],
                'format' => 'raw',
                'value' => function ($model) {
                    return IconStateLabel::widget([
                        'model' => $model,
                        'attribute' => 'whois_protected',
                        'icons' => 'fa-shield',
                        'messages' => [
                            Yii::t('hipanel:domain', 'WHOIS protect is enabled'),
                            Yii::t('hipanel:domain', 'WHOIS protect is disabled'),
                        ],
                    ]);
                },
                'exportedValue' => function ($model) {
                    return $model->whois_protected ? 'ON' : 'OFF';
                }
            ],
            'whois_protected_with_label' => [
                'class' => PaidWPColumn::class,
            ],
            'is_secured' => [ // don't forget to update `is_secured_with_label` column as well
                'encodeLabel' => false,
                'filter' => false,
                'enableSorting' => false,
                'label' => Html::tag('span', Yii::t('hipanel:domain', 'Protection')),
                'format' => 'raw',
                'attribute' => 'is_secured',
                'popover' => Yii::t('hipanel:domain', 'Protection from transfer'),
                'contentOptions' => ['class' => 'text-center', 'style' => 'vertical-align: middle;'],
                'popoverOptions' => [
                    'placement' => 'bottom',
                    'selector' => 'span',
                ],
                'exportedValue' => function ($model) {
                    return $model->is_secured ? 'ON' : 'OFF';
                },
                'value' => function ($model) {
                    return IconStateLabel::widget([
                        'model' => $model,
                        'attribute' => 'is_secured',
                        'icons' => ['fa-lock', 'fa-unlock'],
                        'messages' => [
                            Yii::t('hipanel:domain', 'Secure domain service is enabled'),
                            Yii::t('hipanel:domain', 'Secure domain service is disabled'),
                        ],
                    ]);
                },
            ],
            'is_secured_with_label' => [ // don't forget to update `is_secured` column as well
                'class' => BootstrapSwitchColumn::class,
                'encodeLabel' => false,
                'filter' => false,
                'enableSorting' => false,
                'label' => Html::tag('span', Yii::t('hipanel:domain', 'Protection')),
                'url' => Url::toRoute('@domain/set-lock'),
                'attribute' => 'is_secured',
                'popover' => Yii::t('hipanel:domain', 'Protection from transfer'),
                'popoverOptions' => [
                    'placement' => 'bottom',
                    'selector' => 'span',
                ],
                'pluginOptions' => function($model) {
                    return [
                        'readonly' => !$model->isSecureChangeable(),
                    ];
                },
                'switchOptions' => [
                    'class' => LabeledAjaxSwitch::class,
                    'labels' => [
                        0 => [
                            'style' => 'display: none;',
                            'class' => 'text-danger md-pl-10',
                            'content' => Yii::t('hipanel:domain', 'The domain can be transferred, edited or deleted'),
                        ],
                        1 => [
                            'style' => 'display: none;',
                            'class' => 'small text-muted font-normal md-pl-10',
                            'content' => Yii::t('hipanel:domain', 'The domain can not be transferred, edited or deleted'),
                        ],
                    ],
                ],
            ],
            'note' => [
                'class' => XEditableColumn::class,
                'attribute' => 'note',
                'filter' => true,
                'popover' => Yii::t('hipanel:domain', 'Make any notes for your convenience'),
                'pluginOptions' => [
                    'url' => 'set-note',
                ],
            ],
            'created_date' => [
                'attribute' => 'created_date',
                'format' => 'date',
                'filter' => false,
                'contentOptions' => ['class' => 'text-nowrap'],
            ],
            'expires' => [
                'format' => 'raw',
                'filter' => false,
                'headerOptions' => ['style' => 'width:1em'],
                'value' => function ($model) {
                    $html = Expires::widget(['model' => $model, 'labelOptions' => ['style' => 'line-height: inherit!important;']]);
                    if ($model->isExpiresSoon() && $model->canRenew()) {
                        $html = Html::tag('span',
                            $html . '&nbsp;' . Html::a(Html::tag('i', null, ['class' => 'fa fa-fw fa-forward']) .
                            Yii::t('hipanel:domain', 'Renew'), ['add-to-cart-renewal', 'model_id' => $model->id], ['class' => 'btn btn-success btn-xs']),
                            ['style' => 'display: flex; justify-content: flex-start;']
                        );
                    }

                    return $html;
                },
            ],
            'autorenewal' => [ // don't forget to update `autorenewal_with_label` column as well
                'label' => Html::tag('span', Yii::t('hipanel:domain', 'Auto renew')),
                'attribute' => 'autorenewal',
                'format' => 'raw',
                'exportedValue' => function ($model) {
                    return $model->autorenewal ? 'ON' : 'OFF';
                },
                'value' => function ($model) {
                    return IconStateLabel::widget([
                        'model' => $model,
                        'attribute' => 'autorenewal',
                        'icons' => 'fa-refresh',
                        'messages' => [
                            Yii::t('hipanel:domain', 'Autorenewal is enabled'),
                            Yii::t('hipanel:domain', 'Autorenewal is disabled'),
                        ],
                    ]);
                },
                'filter' => false,
{'fraction_non_alphanumeric': 0.15339268527430222, 'fraction_numerical': 0.002205646454924607, 'mean_word_length': 1.3249114301696812, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 373, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3487828', 'n_tokens_mistral': 6799, 'n_tokens_neox': 6404, 'n_words': 1219}