Skip to content

Commit

Permalink
Sort and wathers
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed May 14, 2015
1 parent 263e914 commit 2b92b5f
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 50 deletions.
48 changes: 46 additions & 2 deletions controllers/TicketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}

/**
Expand All @@ -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()));
}

/**
Expand Down
157 changes: 113 additions & 44 deletions views/ticket/_leftBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
?>
<div class="row page-ticket">
<div class="col-md-12">
Expand Down Expand Up @@ -60,12 +64,40 @@
<?php endif; ?>
*/ ?>

<?php if (is_array($model->watchers)) : ?>
<?= Html::tag('p', 'Watchers', ['class' => 'lead', 'style' => 'border-bottom: 1px solid #E1E1E1; margin-bottom: 0.5em;s']); ?>
<div class="margin-bottom">
<?php foreach ($model->watchers as $watcherId => $watcher) : ?>
<?php
$piece = explode(' ', $watcher);
$watcherEmailHash = array_pop(explode(' ', $watcher));
if ($watcherEmailHash) {
print Html::beginTag('a', [
'href' => 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');
}
?>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php $box->beginFooter(); ?>
<?php if (is_array($model->watcher) && in_array(Yii::$app->user->identity->username, $model->watcher)) : ?>
<?= Html::a('<i class="fa fa-eye-slash"></i>&nbsp;&nbsp;'.Yii::t('app', 'Unsubscribe'), ['unsubscribe', 'id' => $model->id], ['class' => 'btn btn-default btn-block']) ?>
<?php if (is_array($model->watchers) && array_key_exists(Yii::$app->user->identity->id, $model->watchers)) : ?>
<?= Html::a('<i class="fa fa-eye-slash"></i>&nbsp;&nbsp;' . Yii::t('app', 'Unsubscribe'), ['unsubscribe', 'id' => $model->id], ['class' => 'btn btn-default btn-block']) ?>
<?php else : ?>
<?= Html::a('<i class="fa fa-eye"></i>&nbsp;&nbsp;'.Yii::t('app', 'Subscribe'), ['subscribe', 'id' => $model->id], ['class' => 'btn btn-default btn-block']) ?>
<?= Html::a('<i class="fa fa-eye"></i>&nbsp;&nbsp;' . Yii::t('app', 'Subscribe'), ['subscribe', 'id' => $model->id], ['class' => 'btn btn-default btn-block']) ?>
<?php endif; ?>

<?php $box->endFooter(); ?>

<?php $box::end(); ?>
Expand Down Expand Up @@ -110,70 +142,107 @@
]); ?>
<div class="profile-block">
<div class="profile-photo">
<?= Gravatar::widget([
'emailHash' => $model->author_email,
'defaultImage' => 'identicon',
'options' => [
'alt' => '',
'class' => 'img-circle',
],
'size' => 160,
]); ?>
<?php
if ($model->author_email) {
print Gravatar::widget([
'emailHash' => $model->author_email,
'defaultImage' => 'identicon',
'options' => [
'alt' => '',
'class' => 'img-circle',
],
'size' => 160,
]);
}
?>
</div>
<?= Html::tag('div', $model->author, ['class' => 'profile-user-name']); ?>
<?= Html::tag('div', $model->author_seller, ['class' => 'profile-user-role']); ?>
</div>
<?php $box->beginFooter(); ?>
<?= DetailView::widget([
'model' => $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),
'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' => 'contact',
'label' => Yii::t('app', 'Country'),
'format' => 'html',
'value' => Html::tag('span', '', ['class' => 'flag-icon flag-icon-' . $client['contact']['country']]) . '&nbsp;&nbsp;' . $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)
// ],
],
]); ?>
<?php $box->endFooter(); ?>
Expand Down
31 changes: 27 additions & 4 deletions views/ticket/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,8 +70,27 @@
]); ?>
<?php $box::end(); ?>

<?= BoxedGridView::widget([
'boxOptions' => ['options' => ['class' => 'box-primary']],
<?php $box = Box::begin(['renderBody' => false, 'options' => ['class' => 'box-primary']]); ?>
<?php $box->beginHeader(); ?>
<?= $box->renderTitle('&nbsp;'); ?>
<?php $box->beginTools(); ?>

<?= \hipanel\widgets\GridViewSortTool::widget([
'sort' => $sort,
'sortNames' => [
'create_time',
'lastanswer',
'time',
'subject',
'spent',
'author',
'rescipient',
]
]); ?>

<?php $box->endTools(); ?>
<?php $box->beginBody(); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'id' => 'ticket-grid',
Expand Down Expand Up @@ -294,4 +314,7 @@
],
'checkbox',
],
]); ?>
]); ?>
<?php $box->endBody(); ?>
<?php $box->endHeader(); ?>
<?php $box::end(); ?>
2 changes: 2 additions & 0 deletions views/ticket/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
margin: 1rem;
}
');
//\yii\helpers\VarDumper::dump($model, 10, true);
?>

<?php $form = ActiveForm::begin([
Expand All @@ -34,6 +35,7 @@
<?= $this->render('_leftBlock', [
'model' => $model,
'form' => $form,
'client' => $client,
'topic_data' => $topic_data,
'state_data' => $state_data,
'priority_data' => $priority_data,
Expand Down

0 comments on commit 2b92b5f

Please sign in to comment.