Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
akiraz2 committed Sep 29, 2018
1 parent c22cfbf commit 2c4516f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
19 changes: 5 additions & 14 deletions controllers/TicketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,9 @@ public function actionView($id)
$reply->id_ticket = $model->id;
$reply->user_id = Yii::$app->user->id;
if ($reply->load(Yii::$app->request->post()) && $reply->save()) {
if (Yii::$app->user->id == $model->user_id) {
$model->status = Ticket::STATUS_OPEN;
$model->save();
} else {
$model->status = Ticket::STATUS_WAITING;
$model->save();
}
$model->status = \Yii::$app->user->id == $model->user_id ? Ticket::STATUS_OPEN : Ticket::STATUS_WAITING;
$model->save();

return $this->redirect([
'view',
'id' => $model->hash_id
Expand Down Expand Up @@ -164,14 +160,9 @@ public function actionCreate()
$model->setScenario('create');

if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect([
'view',
'id' => $model->hash_id
]);
return $this->redirect(['view', 'id' => $model->hash_id]);
} else {
return $this->render('create', [
'model' => $model,
]);
return $this->render('create', ['model' => $model,]);
}
}

Expand Down
14 changes: 11 additions & 3 deletions models/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function fields()
{
return [
'content',
'user_id',
'isOwn',
'Username',
'created_at' => function ($model) {
return date("d.m.y H:i:s", $model->created_at);//$date->format('Y-m-d H:i:s');
}
Expand Down Expand Up @@ -91,6 +92,13 @@ public function rules()
return [
[['id_ticket', 'content'], 'required'],
[['content'], 'string'],
[
'content',
'filter',
'filter' => function ($value) {
return \yii\helpers\HtmlPurifier::process($value);
}
],
[
['user_id'],
'exist',
Expand Down Expand Up @@ -167,13 +175,13 @@ public function getUsername()
{
$showUserSupport = $this->getModule()->showUsernameSupport;
$username = !empty($this->user_id) ? $this->user->{$this->getModule()->userName} : $this->ticket->getNameEmail();
if (!$this->isOwn() && !$showUserSupport) {
if (!$this->getIsOwn() && !$showUserSupport) {
$username = $this->getModule()->userNameSupport;
}
return $username;
}

public function isOwn()
public function getIsOwn()
{
return $this->user_id == $this->ticket->user_id;
}
Expand Down
7 changes: 5 additions & 2 deletions models/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public function rules()

/* custom */
[['content'], 'required', 'on' => ['create']],
[['user_contact', 'user_name'], 'string'],
];
}

Expand Down Expand Up @@ -256,7 +257,7 @@ public function beforeSave($insert)
}
}
}
return parent::beforeSave($insert); // TODO: Change the autogenerated stub
return parent::beforeSave($insert);
}

/**
Expand Down Expand Up @@ -288,6 +289,8 @@ public function afterSave($insert, $changedAttributes)
/**
* get ticket url
* @param bool $absolute
* @return
* @throws \yii\base\InvalidConfigException
*/
public function getUrl($absolute = false)
{
Expand All @@ -310,7 +313,7 @@ public function close()
$post = new Content();
$post->id_ticket = $this->id;
$post->user_id = null;
$post->content = \akiraz2\support\Module::t('support',
$post->content = \akiraz2\support\Module::t('support',/**/
'Ticket was closed automatically due to inactivity.');
if ($post->save()) {
$this->status = Ticket::STATUS_CLOSED;
Expand Down
2 changes: 1 addition & 1 deletion views/ticket/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<i class="fa fa-info-circle bg-aqua"></i>
<?php else: ?>
<?= Html::tag('i', '',
['class' => $post->isOwn() ? 'fa fa-comments bg-blue' : 'fa fa-comments bg-orange']) ?>
['class' => $post->getIsOwn() ? 'fa fa-comments bg-blue' : 'fa fa-comments bg-orange']) ?>
<?php endif; ?>

<div class="timeline-item">
Expand Down

0 comments on commit 2c4516f

Please sign in to comment.