1 | <?php |
||
28 | class Operation extends Component |
||
29 | 1 | { |
|
30 | const ID = 'operations'; |
||
31 | |||
32 | /** @var array callback on operation submit */ |
||
33 | public $onSubmit; |
||
34 | |||
35 | /** @var string */ |
||
36 | protected $primaryKey; |
||
37 | |||
38 | /** |
||
39 | * @param \Grido\Grid $grid |
||
40 | * @param array $operations |
||
41 | * @param callback $onSubmit - callback after operation submit |
||
42 | */ |
||
43 | public function __construct($grid, array $operations, $onSubmit) |
||
61 | |||
62 | /** |
||
63 | * Sets client side confirm for operation. |
||
64 | * @param string $operation |
||
65 | * @param string $message |
||
66 | * @return Operation |
||
67 | */ |
||
68 | public function setConfirm($operation, $message) |
||
77 | |||
78 | /** |
||
79 | * Sets primary key. |
||
80 | * @param string $primaryKey |
||
81 | * @return Operation |
||
82 | */ |
||
83 | public function setPrimaryKey($primaryKey) |
||
84 | { |
||
85 | $this->primaryKey = $primaryKey; |
||
86 | return $this; |
||
87 | } |
||
88 | |||
89 | /**********************************************************************************************/ |
||
90 | |||
91 | /** |
||
92 | * @return string |
||
93 | */ |
||
94 | public function getPrimaryKey() |
||
102 | |||
103 | /**********************************************************************************************/ |
||
104 | |||
105 | /** |
||
106 | * @param \Nette\Forms\Controls\SubmitButton $button |
||
107 | * @internal |
||
108 | */ |
||
109 | public function handleOperations(\Nette\Forms\Controls\SubmitButton $button) |
||
110 | { |
||
111 | $grid = $this->getGrid(); |
||
112 | !empty($grid->onRegistered) && $grid->onRegistered($grid); |
||
113 | $form = $button->getForm(); |
||
114 | $this->addCheckers($form[self::ID]); |
||
115 | |||
116 | $values = $form[self::ID]->values; |
||
117 | if (empty($values[self::ID])) { |
||
118 | $httpData = $form->getHttpData(); |
||
119 | if (!empty($httpData[self::ID][self::ID]) && $operation = $httpData[self::ID][self::ID]) { |
||
120 | $grid->__triggerUserNotice("Operation with name '$operation' does not exist."); |
||
121 | } |
||
122 | |||
123 | $grid->reload(); |
||
124 | } |
||
125 | |||
126 | $ids = []; |
||
127 | $operation = $values[self::ID]; |
||
128 | unset($values[self::ID]); |
||
129 | |||
130 | foreach ($values as $key => $val) { |
||
131 | if ($val) { |
||
132 | $ids[] = $key; |
||
133 | } |
||
134 | } |
||
135 | |||
136 | $this->onSubmit($operation, $ids); |
||
137 | $grid->page = 1; |
||
138 | |||
139 | if ($this->presenter->isAjax()) { |
||
140 | $grid['form'][self::ID][self::ID]->setValue(NULL); |
||
141 | $grid->getData(TRUE, FALSE); |
||
142 | } |
||
143 | |||
144 | $grid->reload(); |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * @param \Nette\Forms\Container $container |
||
149 | * @throws Exception |
||
150 | * @internal |
||
151 | */ |
||
152 | public function addCheckers(\Nette\Forms\Container $container) |
||
172 | } |
||
173 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.