Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contact force verification #2

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/views/client/view.php
Expand Up @@ -3,11 +3,13 @@
use hipanel\modules\client\grid\ClientGridView;
use hipanel\modules\client\grid\ContactGridView;
use hipanel\modules\client\menus\ClientDetailMenu;
use hipanel\modules\client\widgets\ForceVerificationBlock;
use hipanel\modules\document\widgets\StackedDocumentsView;
use hipanel\widgets\Box;
use hipanel\widgets\ClientSellerLink;
use hiqdev\assets\flagiconcss\FlagIconCssAsset;
use yii\helpers\Html;
use yii\helpers\Url;

/*
* @var $model Client
Expand Down Expand Up @@ -48,6 +50,10 @@
<?= ClientDetailMenu::widget(['model' => $model]) ?>
</div>
<?php Box::end() ?>

<?= ForceVerificationBlock::widget([
'model' => $model->contact
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

закидывай запятую в массивах, потом легче докидывать новые элементы

]) ?>
</div>

<div class="col-md-9">
Expand Down Expand Up @@ -113,10 +119,10 @@
<?php $box->beginBody() ?>
<?= StackedDocumentsView::widget([
'models' => $model->contact->documents
]); ?>
]) ?>
<?php $box->endBody() ?>
<?php $box->end() ?>
<?php endif; ?>
<?php endif ?>
</div>
</div>
</div>
Expand Down
29 changes: 4 additions & 25 deletions src/views/contact/view.php
Expand Up @@ -2,7 +2,7 @@

use hipanel\modules\client\grid\ContactGridView;
use hipanel\modules\client\menus\ContactDetailMenu;
use hipanel\modules\client\widgets\Verification;
use hipanel\modules\client\widgets\ForceVerificationBlock;
use hipanel\modules\document\widgets\StackedDocumentsView;
use hipanel\widgets\Box;
use hipanel\widgets\ClientSellerLink;
Expand Down Expand Up @@ -46,30 +46,9 @@
<?= ContactDetailMenu::widget(['model' => $model]) ?>
</div>
<?php Box::end() ?>

<?php if (Yii::$app->user->can('contact.force-verify')) : ?>
<?php $box = Box::begin(['renderBody' => false]) ?>
<?php $box->beginHeader() ?>
<?= $box->renderTitle(Yii::t('hipanel:client', 'Verification status')) ?>
<?php $box->endHeader() ?>
<?php $box->beginBody() ?>
<table class="table table-striped table-bordered">
<tbody>
<?php foreach (['name', 'address', 'email', 'voice_phone', 'fax_phone'] as $attribute) : ?>
<tr>
<th><?= $model->getAttributeLabel($attribute) ?></th>
<td>
<?= Verification::widget([
'model' => $model->getVerification($attribute),
]) ?>
</td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?php $box->endBody() ?>
<?php $box->end() ?>
<?php endif ?>
<?= ForceVerificationBlock::widget([
'model' => $model,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

у тебя тут отступ 8 пробелов - а у нас везде 4
проверь свои настройки что было 4

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

правильно. виджет находится между дивами. таб = 4 пробела

]) ?>
</div>

<div class="col-md-9">
Expand Down
77 changes: 77 additions & 0 deletions src/widgets/ForceVerificationBlock.php
@@ -0,0 +1,77 @@
<?php

/*
* Client module for HiPanel
*
* @link https://github.com/hiqdev/hipanel-module-client
* @package hipanel-module-client
* @license BSD-3-Clause
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
*/

namespace hipanel\modules\client\widgets;

use Yii;
use yii\base\InvalidConfigException;
use yii\base\Widget;
use yii\helpers\Html;
use hipanel\widgets\Box;

class ForceVerificationBlock extends Widget
{
/**
* @var \hipanel\base\Model
*/
public $model;
/**
* options
*
* @var array
*/
public $options = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

кажется, это свойство не используется

/**
* @var string
*/
public $scenario;
/**
* @var string
*/
public $submitUrl;
/**
* @var array
*/
public $attributes;
/**
* @var string
*/
public $title;

public function init()
{
if ($this->model === null) {
throw new InvalidConfigException('Please specify the "model" property.');
}

if ($this->attributes === null) {
$this->attributes = ['name', 'address', 'email', 'voice_phone', 'fax_phone'];
}

if ($this->title === null) {
$this->title = Yii::t('hipanel:client', 'Verification status');
}
}

public function run()
{
if (Yii::$app->user->can('contact.force-verify')) {
return $this->render((new \ReflectionClass($this))->getShortName(), [
'attributes' => $this->attributes,
'model' => $this->model,
'title' => $this->title,
'scenario' => $this->scenario,
'submitUrl' => $this->submitUrl
]);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Методы должны иметь явно описанные возвращаемые данные. Предпочтительно использование условий для прерывания выполнения, вместо описания полезного кода внутри if. Это упрощает чтение кода.

        if (!Yii::$app->user->can('contact.force-verify')) {
             return;
        }
        
        return $this->render((new \ReflectionClass($this))->getShortName(), [
                 'attributes' => $this->attributes,
                 'model' => $this->model,
                 'title' => $this->title,
                 'scenario' => $this->scenario,
                 'submitUrl' => $this->submitUrl
             ]);
        }

}

}
23 changes: 21 additions & 2 deletions src/widgets/Verification.php
Expand Up @@ -30,6 +30,14 @@ class Verification extends Widget
* @var string
*/
public $type;
/**
* @var string
*/
public $submitUrl;
/**
* @var string
*/
public $title;

public function init()
{
Expand All @@ -44,6 +52,16 @@ public function init()
if ($this->type === null) {
$this->type = $this->model->type;
}

if ($this->submitUrl === null) {
$this->submitUrl = '@contact/set-confirmation';
}

if ($this->title === null) {
$this->title = Yii::t('hipanel:client', 'Verification level');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лишняя строка

}

}

public function run()
Expand All @@ -64,7 +82,7 @@ public function run()

protected function renderXEditable()
{
return\hipanel\widgets\XEditable::widget([
return \hipanel\widgets\XEditable::widget([
'model' => $this->model,
'attribute' => 'level',
'scenario' => $this->scenario,
Expand All @@ -73,9 +91,10 @@ protected function renderXEditable()
'data-attribute' => $this->type
],
'pluginOptions' => [
'url' => $this->submitUrl,
'selector' => '#' . $this->getId(),
'type' => 'select',
'title' => Yii::t('hipanel:client', 'Verification level'),
'title' => $this->title,
'source' => $this->model->getAvailableLevels(),
'params' => new JsExpression("function (params) {
params.type = $(this).attr('data-attribute');
Expand Down
32 changes: 32 additions & 0 deletions src/widgets/views/ForceVerificationBlock.php
@@ -0,0 +1,32 @@
<?php

use yii\helpers\Html;
use hipanel\widgets\Box;
use hipanel\modules\client\widgets\Verification;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В блоке PHPDoc мы описываем переменные, которые приходят извне.
Смотри пример тут https://github.com/hiqdev/hipanel-module-mailing/blob/master/src/views/prepare/index.php#L6-L14

?>
<?php $box = Box::begin(['renderBody' => false]) ?>
<?php $box->beginHeader() ?>
<?= $box->renderTitle($title) ?>
<?php $box->endHeader() ?>
<?php $box->beginBody() ?>
<table class='table table-striped table-borderetable table-striped table-bordered'>
<tbody>
<?php foreach ($attributes as $attribute) : ?>
<?php if (!empty($model->$attribute)) : ?>
<tr>
<th><?= $model->getAttributeLabel($attribute) ?></th>
<td>
<?= Verification::widget([
'model' => $model->getVerification($attribute),
'scenario' => $scenario,
'submitUrl' => $submitUrl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут тоже не хватает запятой

]) ?>
</td>
</tr>
<?php endif ?>
<?php endforeach ?>
</tbody>
</table>
<?php $box->endBody() ?>
<?php $box->end() ?>