Your IP : 216.73.216.79


Current Path : /var/www/html/drsa/backend/modules/contentArticle/views/content-article/
Upload File :
Current File : /var/www/html/drsa/backend/modules/contentArticle/views/content-article/index.php

<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\ArrayHelper;
use backend\modules\contentArticle\models\ContentArticleTranslation;

/* @var $this yii\web\View */
/* @var $searchModel backend\modules\contentArticle\models\ContentArticleSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Articles Management');
$this->params['breadcrumbs'][] = $this->title;

if (!empty($searchModel->article_portal_category) && !empty($searchModel->article_category)) {
    $this->registerCssFile('@web/plugins/jquery-ui.css');
    $this->registerJsFile('@web/plugins/jquery-ui.js', ['depends' => [\yii\web\JqueryAsset::className()]]);
    $this->registerJs('$(document).ready(function() {
    var fixHelper = function fixWidthHelper(e, ui){
        ui.children().each(function() {
            $(this).width($(this).width());
        });
        return ui;
    }
    
        $(".table-custom tbody").sortable({
            helper: fixHelper,
            update: function (event, ui) {
                var output = "";
                $(".table-custom tbody tr").each(function (i) {
                    var data = $(this).attr("data-key");
                    output += data + ",";
                });

                $.ajax({
                    url: "sorting?data=" + output,
                    method: "GET",
                    success: function (response) {
                        location.reload();
                    }
                });

            }
        });
    });');
}
?>
<div class="wrapper wrapper-content">
    <p>
        <?= Html::a('Add New', ['create'], ['class' => 'btn btn-primary']) ?>
        <?php //= Html::a('<i class="fa fa-play"></i> ' . Yii::t('app', 'Video'), ['#'], ['class' => 'label label-default pull-right', 'style' => 'margin-left:5px;line-height:2.2;padding: 0px 4px;']) ?>
        <?php //= Html::a('<i class="fa fa-book"></i> ' . Yii::t('app', 'Manual'), ['#'], ['class' => 'label label-default pull-right', 'style' => 'margin-left:5px;line-height:2.2;padding: 0px 4px;']) ?>
        <?php //= Html::a('<i class="fa fa-question-circle"></i> ' . Yii::t('app', 'Help'), ['#'], ['class' => 'label label-default pull-right', 'style' => 'margin-left:5px;line-height:2.2;padding: 0px 4px;']) ?>
    </p>
    <div class="ibox animated fadeInRightx">
        <div class="mail-box b-r-md">
            <?=
            GridView::widget([
                'dataProvider' => $dataProvider,
                'filterModel' => $searchModel,
                'tableOptions' => ['class' => 'table table-hover table-mail table-custom',],
                'layout' => "<div class='gridview-top-wrapper'><div class='row'><div class='col-sm-6'>{summary}</div><div class='col-sm-6'>{pager}</div></div></div>\n{items}\n{pager}",
                'columns' => [
                    ['class' => 'yii\grid\SerialColumn'],
                    [
                        'class' => 'yii\grid\ActionColumn',
                        'header' => 'Action',
                        'template' => '{update}{delete}',
                        'headerOptions' => ['style' => 'text-align:center;'],
                        'contentOptions' => ['style' => 'text-align:center;'],
                        'buttons' => [
                            'view' => function($url, $model, $key) {
                                return Html::a('<span class="fa fa-eye"></span> ' . Yii::t('app', 'View'), [
                                            'view',
                                            'id' => $model->article_id], ['title' => Yii::t('app', 'View Data'), 'class' => 'label label-info label-button']);
                            },
                            'update' => function($url, $model, $key) {
                                return Html::a('<span class="fa fa-pencil"></span> ' . Yii::t('app', 'Edit'), ['update', 'id' => $model->article_id], ['title' => Yii::t('app', 'Edit Data'), 'class' => 'label label-info label-button']);
                            },
                            'delete' => function ($url, $model) {
                                return '<span class="label label-danger label-button" onclick="deletedata(' . $model->article_id . ')">
                                    <i class="fa fa-trash"></i> Delete
                                </span>';
                            },
                            'graph' => function($url, $model, $key) {
                                return Html::a('<span class="fa fa-line-chart"></span> Stats', [
                                            '/pageVisitLog/page-visit-log/article-details',
                                            'id' => $model->article_id], ['target' => '_blank', 'title' => 'Page Views Statistics', 'class' => 'label label-info label-button']);
                            },
                            'sort' => function ($url, $model) use ($searchModel) {
                                if (!empty($searchModel->article_portal_category) && !empty($searchModel->article_category)) {
                                    return Html::a('<i class="fa fa-arrows"></i> Sort', ['#'], ['title' => 'Sort', 'class' => 'label label-info label-button']);
                                } else {
                                    return '<a href="JavaScript:void(0);" class="label label-default label-button"><span data-toggle="tooltip" data-placement="top" title="Please specify category & portal display to use sorting function"><i class="fa fa-arrows"></i> Sort</span></a>';
                                }
                            },
                        ],
                    ],
                    'article_code',
                    [
                        'attribute' => 'article_title',
                        'value' => function ($model) {
                            if (($modeltranslation = ContentArticleTranslation::findOne(['article_translation_parent_id' => $model->article_id, 'article_translation_main' => 1])) !== null) {
                                return $modeltranslation->article_translation_title;
                            }
                        }
                    ],
                    /*[
                        'format' => 'raw',
                        'attribute' => 'article_portal_category',
                        'filter' => \backend\modules\refdynawebv2\models\Ref::getbranchlist(),
                        'value' => function ($model) {
                            $output = '';
                            if (!empty($model->article_portal_category)) {
                                $portal_arr = json_decode($model->article_portal_category);
                                if (!empty($portal_arr)) {
                                    foreach ($portal_arr as $portal_code) {

                                        $ref = (new \yii\db\Query())->select(['descr'])
                                                ->from('ref')
                                                ->where(['=', 'cat', 'PORTAL'])
                                                ->andwhere(['=', 'code', $portal_code])
                                                ->one();
                                        if (!empty($ref))
                                            $output .= '<span class="label label-button label-default">' . $ref['descr'] . '</span>';
                                    }
                                }
                            }
                            return $output;
                        }
                    ],*/
                    [
                        'attribute' => 'article_category',
                        'filter' => ArrayHelper::map(
                                (new \yii\db\Query())->select(['code', 'descr'])
                                        ->from('ref')
                                        ->where(['=', 'cat', 'ARTICLECATEGORY'])
                                        ->orderBy(['sort' => SORT_ASC])
                                        ->all(), 'code', 'descr'),
                        'value' => function ($model) {
                            $ref = (new \yii\db\Query())->select(['descr'])
                                    ->from('ref')
                                    ->where(['=', 'cat', 'ARTICLECATEGORY'])
                                    ->andwhere(['=', 'code', $model->article_category])
                                    ->one();
                            if (!empty($ref))
                                return $ref['descr'];
                        }
                    ],
                    [
                        'attribute' => 'article_status',
                        'filter' => ArrayHelper::map(
                                (new \yii\db\Query())->select(['code', 'descr'])
                                        ->from('ref')
                                        ->where(['=', 'cat', 'CONTENT_STATUS'])
                                        ->orderBy(['sort' => SORT_ASC])
                                        ->all(), 'code', 'descr'),
                        'value' => function ($model) {
                            $ref = (new \yii\db\Query())->select(['descr'])
                                    ->from('ref')
                                    ->where(['=', 'cat', 'CONTENT_STATUS'])
                                    ->andwhere(['=', 'code', $model->article_status])
                                    ->one();
                            if (!empty($ref))
                                return $ref['descr'];
                        }
                    ],
                    [
                        'header' => 'Language',
                        'format' => 'raw',
                        'headerOptions' => ['style' => 'width:10%'],
                        'value' => function ($model) {
                            $output = '';
                            $arr = ArrayHelper::map(
                                            (new \yii\db\Query())->select(['*'])
                                                    ->from('content_article_translation')
                                                    ->orderBy(['article_translation_language' => SORT_ASC])
                                                    ->groupby(['article_translation_language'])
                                                    ->all(), 'article_translation_language', 'article_translation_language');
                            if (!empty($arr)) {
                                foreach ($arr as $code) {
                                    $ref = (new \yii\db\Query())->select(['descr'])
                                            ->from('ref')
                                            ->where(['=', 'cat', 'CONTENT_LANGUAGE'])
                                            ->andwhere(['=', 'code', $code])
                                            ->one();
                                    if (!empty($ref)) {
                                        $label_class = 'label-dark';
                                        if (($modeltranslation = ContentArticleTranslation::findOne(['article_translation_parent_id' => $model->article_id, 'article_translation_language' => $code])) !== null) {
                                            $label_class = 'label-primary';
                                        }
                                        $output .= '<span class="label label-button ' . $label_class . '">' . $ref['descr'] . '</span>';
                                    }
                                }
                            }
                            return $output . Html::a('<i class="fa fa-plus" aria-hidden="true"></i> Translation', ['addtranslation', 'id' => $model->article_id], ['class' => 'label label-warning label-button']);
                        }
                    ]
                ],
            ]);
            ?>
        </div>
    </div>

    <div class="version">Version 1.0 (Last update on 4th May 2023)</div>

</div>

<script>
    function deletedata(id) {
        Swal.fire({
            title: 'Are you sure to delete this data?',
            text: "You won't be able to revert this!",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, delete it!'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: "/admin/contentArticle/content-article/delete",
                    method: "POST",
                    data: {"id": id},
                    success: function (response) {
                        if (response === 'success') {
                            swal.fire({
                                title: 'Deleted',
                                icon: 'success',
                                text: 'Data have been deleted',
                            }).then(function (result) {
                                location.reload();
                            });
                        }
                    },
                });
            }
        });
    }
</script>