From 2b92b5fc89e42eec840f915fd73220ddc66c6861 Mon Sep 17 00:00:00 2001 From: Andrey Klochok Date: Thu, 14 May 2015 11:53:28 +0300 Subject: [PATCH] Sort and wathers --- controllers/TicketController.php | 48 +++++++++- views/ticket/_leftBlock.php | 157 ++++++++++++++++++++++--------- views/ticket/index.php | 31 +++++- views/ticket/view.php | 2 + 4 files changed, 188 insertions(+), 50 deletions(-) diff --git a/controllers/TicketController.php b/controllers/TicketController.php index cfe5580..4c1ac5a 100644 --- a/controllers/TicketController.php +++ b/controllers/TicketController.php @@ -7,15 +7,29 @@ namespace hipanel\modules\ticket\controllers; +use hipanel\modules\client\assets\combo2\Client; use Yii; use hipanel\modules\ticket\models\Thread; use hipanel\modules\ticket\models\TicketSettings; use common\models\File; use hiqdev\hiar\HiResException; +use yii\data\Sort; use yii\helpers\ArrayHelper; +use hipanel\helpers\ArrayHelper as AH; +use hipanel\modules\client\models\Client as ClientModel; /** * Class TicketController + * + * Usage: + * + * GridViewSortTool::widget([ + * 'sort' => $sort, // Sort object + * 'sortNames' => [ + * 'names_of_sorts', + * .... + * ] + * ]); * @package hipanel\modules\ticket\controllers */ class TicketController extends \hipanel\base\CrudController @@ -50,7 +64,36 @@ protected function prepareRefs() */ public function actionIndex() { - return parent::actionIndex($this->prepareRefs()); + $searchModel = static::searchModel(); + $sort = new Sort([ + 'attributes' => [ + 'create_time' => [ + 'label' => 'Create time', + ], + 'lastanswer' => [ + 'label' => 'Latest answer', + ], + 'time' => [ + 'label' => 'Time', + ], + 'subject' => [ + 'label' => 'Subject', + ], + 'spent' => [ + 'label' => 'Spent time', + ], + 'author' => [ + 'label' => 'Author', + ], + 'rescipient' => [ + 'label' => 'Recipient', + ], + ], + ]); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', AH::merge(compact('searchModel', 'dataProvider', 'sort'), $this->prepareRefs())); +// return parent::actionIndex($this->prepareRefs()); } /** @@ -61,7 +104,8 @@ public function actionIndex() public function actionView($id) { $model = $this->findModel(ArrayHelper::merge(compact('id'), ['with_answers' => 1, 'with_files' => 1]), ['scenario' => 'answer']); - return $this->render('view', ArrayHelper::merge(compact('model'), $this->prepareRefs())); + $client = ClientModel::find()->where(['id' => $model->author_id, 'with_contact' => 1])->asArray()->one(); + return $this->render('view', ArrayHelper::merge(compact('model', 'client'), $this->prepareRefs())); } /** diff --git a/views/ticket/_leftBlock.php b/views/ticket/_leftBlock.php index 0f42123..3f216e8 100644 --- a/views/ticket/_leftBlock.php +++ b/views/ticket/_leftBlock.php @@ -6,14 +6,18 @@ */ use cebe\gravatar\Gravatar; +use frontend\assets\FlagIconCssAsset; +use hipanel\modules\ticket\widgets\Topic; use hipanel\widgets\Box; use yii\helpers\Html; use yii\widgets\DetailView; +use yii\helpers\Url; + use hipanel\modules\ticket\widgets\Label; -use hipanel\modules\ticket\widgets\Topic; +//use hipanel\modules\ticket\widgets\Topic; //use hipanel\modules\ticket\widgets\Watcher; use hipanel\base\Re; - +FlagIconCssAsset::register($this); ?>
@@ -60,12 +64,40 @@ */ ?> + watchers)) : ?> + 'lead', 'style' => 'border-bottom: 1px solid #E1E1E1; margin-bottom: 0.5em;s']); ?> +
+ watchers as $watcherId => $watcher) : ?> + Url::toRoute(['/client/client/view', 'id' => $watcherId]), + ]); + print Gravatar::widget([ + 'emailHash' => $watcherEmailHash, + 'defaultImage' => 'identicon', + 'options' => [ + 'alt' => reset($piece), + 'class' => '', + 'title' => reset($piece) + ], + 'size' => 32, + ]); + print Html::endTag('a'); + } + ?> + +
+ beginFooter(); ?> - watcher) && in_array(Yii::$app->user->identity->username, $model->watcher)) : ?> -   '.Yii::t('app', 'Unsubscribe'), ['unsubscribe', 'id' => $model->id], ['class' => 'btn btn-default btn-block']) ?> + watchers) && array_key_exists(Yii::$app->user->identity->id, $model->watchers)) : ?> +   ' . Yii::t('app', 'Unsubscribe'), ['unsubscribe', 'id' => $model->id], ['class' => 'btn btn-default btn-block']) ?> -   '.Yii::t('app', 'Subscribe'), ['subscribe', 'id' => $model->id], ['class' => 'btn btn-default btn-block']) ?> +   ' . Yii::t('app', 'Subscribe'), ['subscribe', 'id' => $model->id], ['class' => 'btn btn-default btn-block']) ?> + endFooter(); ?> @@ -110,42 +142,42 @@ ]); ?>
- $model->author_email, - 'defaultImage' => 'identicon', - 'options' => [ - 'alt' => '', - 'class' => 'img-circle', - ], - 'size' => 160, - ]); ?> + author_email) { + print Gravatar::widget([ + 'emailHash' => $model->author_email, + 'defaultImage' => 'identicon', + 'options' => [ + 'alt' => '', + 'class' => 'img-circle', + ], + 'size' => 160, + ]); + } + ?>
author, ['class' => 'profile-user-name']); ?> author_seller, ['class' => 'profile-user-role']); ?>
beginFooter(); ?> $model, + 'model' => $client, 'attributes' => [ // 'subject', [ - 'attribute'=>'state', - 'format'=>'html', - 'value'=>Label::widget([ - 'type'=>'state', - 'label'=> Re::l($model->state_label), - 'value'=>$model->state, - ]), + 'attribute' => 'state', + 'format' => 'html', + 'value' => Html::tag('span', $client['state'], ['class' => 'label label-default']) ], [ - 'attribute' => 'topics', - 'format'=>'html', + 'attribute' => 'balance', + 'format' => 'html', 'value' => Topic::widget(['topics' => $model->topics]), 'visible' => $model->topics != null, ], [ - 'attribute'=>'priority', - 'format'=>'html', + 'attribute' => 'credit', + 'format' => 'html', 'value'=> Label::widget([ 'type'=>'priority', 'label'=> Re::l($model->priority_label), @@ -153,27 +185,64 @@ ]) ], [ - 'attribute'=>'author', - 'format'=>'html', - 'value'=>Html::a($model->author,['/client/client/view','id'=>$model->author_id]), - ], - [ - 'attribute'=>'responsible', - 'format'=>'html', - 'value'=>Html::a($model->responsible,['/client/client/view','id'=>$model->responsible_id]), - 'visible'=> $model->responsible != null, - ], - [ - 'attribute'=>'recipient', - 'format'=>'html', - 'value'=>Html::a($model->recipient,['/client/client/view','id'=>$model->recipient_id]), + 'attribute' => 'contact', + 'label' => Yii::t('app', 'Country'), + 'format' => 'html', + 'value' => Html::tag('span', '', ['class' => 'flag-icon flag-icon-' . $client['contact']['country']]) . '  ' . $client['contact']['country_name'] ], [ - 'attribute'=>'watcher', - 'format'=>'html', - // 'value'=> Watcher::widget(['watchers'=>$model->watcher]), - 'visible'=> is_array($model->watcher) + 'attribute' => 'contact', + 'label' => Yii::t('app', 'Email'), + 'format' => 'html', + 'value' => Html::mailto($client['contact']['email'], $client['contact']['email']) ], +// // 'subject', +// [ +// 'attribute'=>'state', +// 'format'=>'html', +// 'value'=>Label::widget([ +// 'type'=>'state', +// 'label'=> Re::l($model->state_label), +// 'value'=>$model->state, +// ]), +// ], +// [ +// 'attribute' => 'topics', +// 'format'=>'html', +// 'value' => Topic::widget(['topics' => $model->topics]), +// 'visible' => $model->topics != null, +// ], +// [ +// 'attribute'=>'priority', +// 'format'=>'html', +// 'value'=> Label::widget([ +// 'type'=>'priority', +// 'label'=> Re::l($model->priority_label), +// 'value'=>$model->priority, +// ]) +// ], +// [ +// 'attribute'=>'author', +// 'format'=>'html', +// 'value'=>Html::a($model->author,['/client/client/view','id'=>$model->author_id]), +// ], +// [ +// 'attribute'=>'responsible', +// 'format'=>'html', +// 'value'=>Html::a($model->responsible,['/client/client/view','id'=>$model->responsible_id]), +// 'visible'=> $model->responsible != null, +// ], +// [ +// 'attribute'=>'recipient', +// 'format'=>'html', +// 'value'=>Html::a($model->recipient,['/client/client/view','id'=>$model->recipient_id]), +// ], +// [ +// 'attribute'=>'watcher', +// 'format'=>'html', +// // 'value'=> Watcher::widget(['watchers'=>$model->watcher]), +// 'visible'=> is_array($model->watcher) +// ], ], ]); ?> endFooter(); ?> diff --git a/views/ticket/index.php b/views/ticket/index.php index df8b055..52c32ee 100644 --- a/views/ticket/index.php +++ b/views/ticket/index.php @@ -7,12 +7,13 @@ use hipanel\widgets\Gravatar; use hipanel\grid\ActionColumn; -use hipanel\grid\BoxedGridView; +use hipanel\grid\GridView; use hipanel\widgets\ActionBox; use hipanel\widgets\Select2; use hipanel\modules\ticket\widgets\Topic; use yii\helpers\Html; use yii\helpers\Url; +use hipanel\widgets\Box; $this->title = Yii::t('app', 'Tickets'); $this->params['breadcrumbs'][] = $this->title; @@ -69,8 +70,27 @@ ]); ?> - ['options' => ['class' => 'box-primary']], + false, 'options' => ['class' => 'box-primary']]); ?> +beginHeader(); ?> +renderTitle(' '); ?> +beginTools(); ?> + + $sort, + 'sortNames' => [ + 'create_time', + 'lastanswer', + 'time', + 'subject', + 'spent', + 'author', + 'rescipient', + ] +]); ?> + +endTools(); ?> +beginBody(); ?> + $dataProvider, 'filterModel' => $searchModel, 'id' => 'ticket-grid', @@ -294,4 +314,7 @@ ], 'checkbox', ], -]); ?> \ No newline at end of file +]); ?> +endBody(); ?> +endHeader(); ?> + \ No newline at end of file diff --git a/views/ticket/view.php b/views/ticket/view.php index e33b499..5cf48fa 100644 --- a/views/ticket/view.php +++ b/views/ticket/view.php @@ -20,6 +20,7 @@ margin: 1rem; } '); +//\yii\helpers\VarDumper::dump($model, 10, true); ?> render('_leftBlock', [ 'model' => $model, 'form' => $form, + 'client' => $client, 'topic_data' => $topic_data, 'state_data' => $state_data, 'priority_data' => $priority_data,