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.
Completed
Push — master ( 1ba1f4...ea41a5 )
by Alexey
05:37
created

ParameterGridWidget::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %
Metric Value
dl 9
loc 9
rs 9.6666
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
/**
3
 * @author Alexey Tatarinov <[email protected]>
4
 * @link https://github.com/shogodev/argilla/
5
 * @copyright Copyright &copy; 2003-2015 Shogo
6
 * @license http://argilla.ru/LICENSE
7
 *
8
 * Пример подключения в формах
9
 * <div>
10
 *   <?php $form->widget('parameterGrid.ParameterGridWidget', array('model' => $model, 'header' => 'Цены и наличие'));?>
11
 * </div>
12
 */
13
14
/**
15
 * Class ParameterGridWidget
16
 */
17
class ParameterGridWidget extends CWidget
18
{
19
  public $header = 'Параметры';
20
21
  /**
22
   * @var $parameterKey - ключ параметра, если не указан брется с поведения parameterGridBehavior
23
   */
24
  public $parameterKey;
25
26
  /**
27
   * @var BProduct - модель продуктов с поведением parameterGridBehavior
28
   */
29
  public $model;
30
31
  /**
32
   * @var CDataProvider $dataProvider
33
   */
34
  private $dataProvider;
35
36
  public function init()
37
  {
38
39
    if( is_null($this->model) )
40
      throw new RequiredPropertiesException(get_class($this), 'model');
41
42
    if( is_null($this->model->asa('parameterGridBehavior')) )
43
      throw new CHttpException('500', 'Класс '.get_class($this->model).' должен иметь поведение parameterGridBehavior');
44
45
    $this->dataProvider = $this->model->getParametersDataProvider($this->parameterKey);
46
  }
47
48 View Code Duplication
  public function run()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
  {
50
    if( !$this->isAvailable() )
51
      return;
52
53
    echo '<tr><th><label>'.$this->header.'</label></th><td>';
54
    $this->renderGrid();
55
    echo '</td></tr>';
56
  }
57
58
  private function renderGrid()
59
  {
60
    $productParam = BProductParam::model();
61
    $columns = $productParam->getMetaData()->columns;
62
63
    $updateButtonClass = 'parameter_grid_button';
64
65
    $optionColumns = array(
66
      array('name' => 'variant.name', 'header' => 'Название'),
67
    );
68
69 View Code Duplication
    if( isset($columns['articul']) )
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
      $optionColumns[] = array(
72
        'name' => 'articul',
73
        'header' => 'Артикул',
74
        'class' => 'OnFlyEditField',
75
        'ajaxUrl' => Yii::app()->controller->createUrl('/product/parameterGrid/parameterGrid/onflyedit'),
76
        'htmlOptions' => array('class' => 'span5'),
77
      );
78
    }
79
80 View Code Duplication
    if( isset($columns['price']) )
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
    {
82
      $optionColumns[] = array(
83
        'name' => 'price',
84
        'header' => 'Цена',
85
        'class' => 'OnFlyEditField',
86
        'ajaxUrl' => Yii::app()->controller->createUrl('/product/parameterGrid/parameterGrid/onflyedit'),
87
        'htmlOptions' => array('class' => 'span2'),
88
      );
89
    }
90
91
    if( isset($columns['dump']) )
92
    {
93
      $optionColumns[] = array(
94
        'name' => 'dump',
95
        'class' => 'JToggleColumn',
96
        'action' => '/product/parameterGrid/parameterGrid/toggle',
97
        'header' => 'Наличие'
98
      );
99
    }
100
101
    $grid = $this->controller->widget('BGridView', array(
102
      'dataProvider' => $this->dataProvider,
103
      'template' => "{buttons}\n{items}\n{pager}\n{scripts}",
104
      'buttonsTemplate' => null,
105
      'columns' => $optionColumns
106
    ));
107
108
    $this->registerUpdateScript($grid->id, $updateButtonClass);
109
  }
110
111
  private function registerUpdateScript($widgetId, $updateButtonClass)
112
  {
113
    Yii::app()->clientScript->registerScript($updateButtonClass.'_script', "
114
      jQuery(document).on('click', '.{$updateButtonClass}', function(e) {
115
        e.preventDefault();
116
        assigner.open(this.href, {'updateGridId' : '{$widgetId}'});
117
      });
118
    ");
119
  }
120
121
  private function isAvailable()
122
  {
123
    return !$this->controller->popup && $this->controller->isUpdate() && $this->model->getParametersDataProvider()->getTotalItemCount() > 0;
124
  }
125
}