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

OnFlyEditField::renderScript()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 18
rs 9.4286
cc 2
eloc 10
nc 2
nop 0
1
<?php
2
/**
3
 * @author Nikita Melnikov <[email protected]>
4
 * @author Vladimir Utenkov <[email protected]>
5
 * @link https://github.com/shogodev/argilla/
6
 * @copyright Copyright &copy; 2003-2014 Shogo
7
 * @license http://argilla.ru/LICENSE
8
 */
9
Yii::import('zii.widgets.grid.CGridColumn');
10
11
/**
12
 * Класс для получение возможности редактировать поле в CGridView с помощью ajax
13
 *
14
 * Класс должен инициализироваться вместе CGridView
15
 * @example
16
 * <code>
17
 *
18
 * $onFlyEdit = array(
19
 *  'name'        => 'notice',
20
 *  'htmlOptions' => array(),
21
 *  'class'       => 'OnFlyEditField',
22
 *  'header'      => 'FieldHeader',
23
 * );
24
 *
25
 * $this->widget('bootstrap.widgets.TbGridView', array(
26
 *  'columns' => array($onFlyEdit,))
27
 * );
28
 * </code>
29
 */
30
class OnFlyEditField extends BDataColumn
31
{
32
  /**
33
   * Имя свойства / поля в базе, используемое для вывода
34
   *
35
   * @var string
36
   */
37
  public $name;
38
39
  /**
40
   * Значение свойства
41
   *
42
   * @var string
43
   */
44
  public $value;
45
46
  /**
47
   * id грида
48
   *
49
   * @var string
50
   */
51
  public $gridId;
52
53
  /**
54
   * Массив значений для вывода поля в виде выпадающего списка
55
   *
56
   * @var array|null
57
   */
58
  public $dropDown = null;
59
60
  public $htmlOptions = array('class' => 'span1');
61
62
  public $elementOptions = array();
63
64
  public $action = 'onflyedit';
65
66
  public $gridUpdate = false;
67
68
  /**
69
   * URL для AJAX запроса.
70
   *
71
   * @var string
72
   */
73
  public $ajaxUrl;
74
75
  /**
76
   * Инициализация вывода свойства в столбец
77
   *
78
   * @override
79
   *
80
   * @return void
81
   */
82
  public function init()
83
  {
84
    parent::init();
85
86
    if( empty($this->ajaxUrl) )
87
      $this->ajaxUrl = Yii::app()->controller->createUrl(Yii::app()->controller->id."/$this->action");
88
89
    Yii::app()->clientScript->registerScript(
90
      'initOnFly'.$this->grid->id,
91
      '$(function() {
92
        Backend("onFly", function(box) {
93
          box.init(jQuery);
94
          jQuery.fn.yiiGridView.addObserver("'.$this->grid->id.'", function(id) { box.reinstall(jQuery); });
95
        });
96
      });',
97
      CClientScript::POS_END
98
    );
99
  }
100
101
  /**
102
   * Вывод значения свойтва в клетку
103
   *
104
   * @override
105
   *
106
   * @param int $row
107
   * @param object $data
108
   *
109
   * @return void
110
   */
111
  protected function renderDataCellContent($row, $data)
112
  {
113
    $htmlOptions = CMap::mergeArray(
114
      array(
115
        'data-grid-id' => $this->gridId,
116
        'data-grid-update' => $this->gridUpdate
117
      ),
118
      $this->elementOptions
119
    );
120
121
    $primaryKey = $data instanceof BActiveRecord ? $data->getPrimaryKey() : $data['id'];
122
123
    Yii::app()->controller->widget('OnFlyWidget', array(
124
      'ajaxUrl' => $this->ajaxUrl,
125
      'attribute' => $this->name,
126
      'primaryKey' => $primaryKey,
127
      'value' => $data[$this->name],
128
      'htmlOptions' => $htmlOptions
129
    ));
130
  }
131
132
  /**
133
   * Возвращает сгенерированную строку, содержащее значение свойства в теге <span>
134
   * с нужными параметрами для работы скрипта
135
   *
136
   * @param $fieldID
137
   * @param $value
138
   * @param null|string $name
139
   *
140
   * @return string
141
   */
142
  protected function prepareFieldData($fieldID, $value, $name = null)
143
  {
144
    if( $name === null )
145
    {
146
      $name = $this->name;
147
    }
148
149
    $commonAttributes = [
150
      'data-onflyedit' => $name.'-'.$fieldID,
151
      'data-ajax-url' => $this->ajaxUrl,
152
      'data-grid-id' => $this->gridId,
153
      'data-grid-update' => $this->gridUpdate
154
    ];
155
156
    if( empty($this->dropDown) )
157
    {
158
      return CHtml::tag('span', array_merge($commonAttributes, ['class' => 'onfly-edit'], $this->elementOptions), $value);
159
    }
160
    else
161
    {
162
      return CHtml::dropDownList('', $value, $this->dropDown,
163
        array_merge($commonAttributes, ['class' => 'onfly-edit-dropdown', 'style' => 'margin-bottom: 0px; width: auto;'], $this->elementOptions));
164
    }
165
  }
166
}