GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — packet_price_editor ( d1862f...6d17fd )
by
unknown
09:54
created

PacketPriceEditButton   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 77
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 9 2
A run() 0 14 1
A renderModal() 0 13 2
B regJS() 0 27 1
1
<?php
2
namespace app\modules\shop\widgets;
3
4
use Yii;
5
use yii\base\Widget;
6
use yii\helpers\Html;
7
use yii\helpers\Url;
8
use kartik\icons\Icon;
9
use app\modules\shop\assets\PacketPriceEditAsset;
10
use app\modules\shop\models\Currency;
11
12
/**
13
* Packet edit the prices
14
* @param $context string
15
* @param $btnHtmlOptions []
16
* @param $gridSelector string
17
* @param $modalFormId string
18
* @param $modalView string
19
*/
20
class PacketPriceEditButton extends Widget
21
{
22
	const PACKET_PRICE_EDIT = 'edit_prices';
23
24
	public $context;
25
	public $btnHtmlOptions = [];
26
	public $gridSelector = '.grid-view';
27
	public $modalFormId = 'packet-price-edit-form';
28
	public $modalView = '@app/modules/shop/widgets/views/PacketPriceEditModal';
29
30
	public function init()
31
	{
32
		$this->btnHtmlOptions['data-action'] = self::PACKET_PRICE_EDIT;
33
		if (!isset($this->btnHtmlOptions['class']))
34
			$this->btnHtmlOptions['class'] = 'btn btn-default';
35
36
		$this->regJS();
37
		PacketPriceEditAsset::register($this->view);
38
	}
39
40
	public function run()
41
	{
42
		// render modal form
43
		$modal = $this->renderModal();
44
45
		// render button
46
		$button = Html::button(
47
			Icon::show('usd') . ' ' .
48
			\Yii::t('app', 'Edit prices'),
49
			$this->btnHtmlOptions
50
		);
51
		
52
		return $button . "\n" . $modal;
53
	}
54
55
	protected function renderModal() {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
56
		$currencies = [];
57
		$arCurrency = Currency::find()->orderBy(['is_main' => SORT_DESC])->all();
58
		foreach ($arCurrency as $currency)
59
			$currencies[$currency->id] = $currency->iso_code;
60
61
62
		return	$this->view->render($this->modalView, [
63
					'modalFormId' => $this->modalFormId,
64
					'currencies' => $currencies,
65
					'contextId' => $this->context
66
				]);
67
	}
68
69
	protected function regJS() {
70
		$lang = [
71
			'confirm_edit' => Yii::t('app', 'The action is irreversible. Do you want to continue?'),
72
			'wait' => Yii::t('app', 'Waiting'),
73
			'total' => Yii::t('app', 'Total items'),
74
			'updated' => Yii::t('app', 'Updated at'),
75
			'missed' => Yii::t('app', 'Missed (difference between the currencies)'),
76
			'errors' => Yii::t('app', 'Number of errors'),
77
		];
78
79
		$this->view->registerJs("
80
			$(\"button[data-action='" . self::PACKET_PRICE_EDIT . "']\").click(function(){
81
				var items = $('{$this->gridSelector}').yiiGridView('getSelectedRows');
82
				if (items.length) {
83
					var modal = $('#{$this->modalFormId}'),
84
						action = $(this).data('action');
85
86
					modal.data('url', '" . Url::toRoute(['packet-price-edit']) . "')
87
						.data('items', items)
88
						.data('price-edit-action', action)
89
						.data('lang', " . json_encode($lang) . ")
90
						.modal('show');
91
				}
92
				return false;
93
			});
94
		");
95
	}
96
}
97