1 | <?php |
||
20 | class TbEditableColumn extends TbDataColumn |
||
21 | { |
||
22 | /** |
||
23 | * @var array editable config options. |
||
24 | * @see TbEditableField config |
||
25 | */ |
||
26 | public $editable = array(); |
||
27 | |||
28 | protected function fetchKeys($dataProvider) { |
||
29 | $keys = array(); |
||
30 | $data = $dataProvider->getData(); |
||
31 | if(isset($data) && !empty($data)) |
||
32 | foreach($data[0] as $i=>$data) |
||
33 | $keys[]=$i; |
||
34 | return $keys; |
||
35 | } |
||
36 | |||
37 | public function init() |
||
38 | { |
||
39 | if (!$this->name) { |
||
40 | throw new CException('You should provide name for TbEditableColumn'); |
||
41 | } |
||
42 | |||
43 | parent::init(); |
||
44 | |||
45 | /** |
||
46 | * add a dummy object to the data provider and call render function to allow register |
||
47 | * required scripts if grid was initially empty... |
||
48 | */ |
||
49 | if(empty($this->grid->dataProvider->data)) { |
||
50 | if ($this->grid->dataProvider instanceof CActiveDataProvider) |
||
|
|||
51 | $dummy = new $this->grid->dataProvider->modelClass(); |
||
52 | else if ($this->grid->dataProvider instanceof CArrayDataProvider) { |
||
53 | $keys = $this->fetchKeys($this->grid->dataProvider); |
||
54 | $dummy = array(); |
||
55 | foreach ($keys as $key) { |
||
56 | $dummy[$key] = $key; // anyvalue; |
||
57 | } |
||
58 | } else { |
||
59 | $dummy = null; |
||
60 | } |
||
61 | $this->grid->dataProvider->data = array($dummy); |
||
62 | $this->editable['htmlOptions'] = array('style' => 'display: none;'); |
||
63 | $this->renderDataCellContent(0, $dummy); // this is the target line |
||
64 | $this->grid->dataProvider->data = array(); |
||
65 | } |
||
66 | //need to attach ajaxUpdate handler to refresh editables on pagination and sort |
||
67 | TbEditable::attachAjaxUpdateEvent($this->grid); |
||
68 | } |
||
69 | |||
70 | //protected was removed due to https://github.com/vitalets/x-editable-yii/issues/63 |
||
71 | public function renderDataCellContent($row, $data) |
||
72 | { |
||
73 | $isModel = $data instanceOf CModel; |
||
74 | |||
75 | if($isModel) { |
||
76 | $widgetClass = 'TbEditableField'; |
||
77 | $options = array( |
||
78 | 'model' => $data, |
||
79 | 'attribute' => empty($this->editable['attribute']) ? $this->name : $this->editable['attribute'], |
||
80 | ); |
||
81 | |||
82 | //if value defined in column config --> we should evaluate it |
||
83 | //and pass to widget via `text` option: set flag `passText` = true |
||
84 | $passText = !empty($this->value); |
||
85 | } else { |
||
86 | $widgetClass = 'TbEditable'; |
||
87 | $options = array( |
||
88 | 'pk' => $data[$this->grid->dataProvider->keyField], |
||
89 | 'name' => empty($this->editable['name']) ? $this->name : $this->editable['name'], |
||
90 | ); |
||
91 | |||
92 | $passText = true; |
||
93 | //if autotext will be applied, do not pass `text` option (pass `value` instead) |
||
94 | if(empty($this->value) && TbEditable::isAutotext($this->editable, isset($this->editable['type']) ? $this->editable['type'] : '')) { |
||
95 | $options['value'] = $data[$this->name]; |
||
96 | $passText = false; |
||
97 | } |
||
98 | } |
||
99 | |||
100 | //for live update |
||
101 | $options['liveTarget'] = $this->grid->id; |
||
102 | |||
103 | $options = CMap::mergeArray($this->editable, $options); |
||
104 | |||
105 | //if value defined for column --> use it as element text |
||
106 | if($passText) { |
||
107 | ob_start(); |
||
108 | parent::renderDataCellContent($row, $data); |
||
109 | $text = ob_get_clean(); |
||
110 | $options['text'] = $text; |
||
111 | $options['encode'] = false; |
||
112 | } |
||
113 | |||
114 | //apply may be a string expression, see https://github.com/vitalets/x-editable-yii/issues/33 |
||
115 | if (isset($options['apply']) && is_string($options['apply'])) { |
||
116 | $options['apply'] = $this->evaluateExpression($options['apply'], array('data'=>$data, 'row'=>$row)); |
||
117 | } |
||
118 | |||
119 | //evaluate htmlOptions inside editable config as they can depend on $data |
||
120 | //see https://github.com/vitalets/x-editable-yii/issues/40 |
||
121 | if (isset($options['htmlOptions']) && is_array($options['htmlOptions'])) { |
||
122 | foreach($options['htmlOptions'] as $k => $v) { |
||
123 | if(is_string($v) && (strpos($v, '$data') !== false || strpos($v, '$row') !== false)) { |
||
124 | $options['htmlOptions'][$k] = $this->evaluateExpression($v, array('data'=>$data, 'row'=>$row)); |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | |||
129 | $this->grid->controller->widget($widgetClass, $options); |
||
130 | } |
||
131 | |||
132 | /* |
||
133 | Require this overwrite to show bootstrap sort icons |
||
134 | */ |
||
135 | protected function renderHeaderCellContent() |
||
166 | |||
167 | /* |
||
168 | Require this overwrite to show bootstrap filter field |
||
169 | */ |
||
170 | public function renderFilterCell() |
||
180 | } |
||
181 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.