|
1
|
|
|
<?php
|
|
2
|
|
|
|
|
3
|
|
|
namespace AtDataGrid\View\Helper;
|
|
4
|
|
|
|
|
5
|
|
|
use AtDataGrid\Row\Action;
|
|
6
|
|
|
use Zend\Db\ResultSet\ResultSet;
|
|
7
|
|
|
use Zend\View\Helper\AbstractHelper;
|
|
8
|
|
|
use Zend\View\View;
|
|
9
|
|
|
|
|
10
|
|
|
class RowAction extends AbstractHelper
|
|
11
|
|
|
{
|
|
12
|
|
|
/**
|
|
13
|
|
|
* @param Action $action
|
|
14
|
|
|
* @param $row
|
|
15
|
|
|
* @return string
|
|
16
|
|
|
*/
|
|
17
|
|
|
public function __invoke(Action $action, $row)
|
|
18
|
|
|
{
|
|
19
|
|
|
// Convert data to array
|
|
20
|
|
|
if (! is_array($row)) {
|
|
21
|
|
|
if ($row instanceof ResultSet) {
|
|
|
|
|
|
|
22
|
|
|
$row = $row->toArray();
|
|
23
|
|
|
} elseif ($row instanceof \ArrayIterator || $row instanceof \ArrayObject) {
|
|
24
|
|
|
$row = $row->getArrayCopy();
|
|
25
|
|
|
} else {
|
|
26
|
|
|
throw new \RuntimeException('Row data couldn\'t be converted to array');
|
|
27
|
|
|
}
|
|
28
|
|
|
}
|
|
29
|
|
|
|
|
30
|
|
|
/** @var View $view */
|
|
31
|
|
|
$view = $this->getView();
|
|
32
|
|
|
|
|
33
|
|
|
if ($url = $action->getUrl()) {
|
|
34
|
|
|
$p = [];
|
|
35
|
|
|
$v = [];
|
|
36
|
|
|
|
|
37
|
|
|
foreach ($row as $key => $val) {
|
|
38
|
|
|
$p[] = '%'. $key .'%';
|
|
39
|
|
|
$v[] = $val;
|
|
40
|
|
|
}
|
|
41
|
|
|
|
|
42
|
|
|
$actionUrl = str_replace($p, $v, $url);
|
|
43
|
|
|
} else {
|
|
44
|
|
|
$routeParams = array_merge($action->getRouteParams(), $row);
|
|
45
|
|
|
$actionUrl = $view->url($action->getRouteName(), $routeParams, $action->getRouteOptions());
|
|
|
|
|
|
|
46
|
|
|
}
|
|
47
|
|
|
|
|
48
|
|
|
$onClick = '';
|
|
49
|
|
|
if ($action->isConfirm()) {
|
|
50
|
|
|
$onClick = 'onclick="DataGrid.confirmAction(this, \''. $view->translate($action->getConfirmMessage()) . '\')"';
|
|
|
|
|
|
|
51
|
|
|
}
|
|
52
|
|
|
|
|
53
|
|
|
$disabledClass = '';
|
|
54
|
|
|
if ($action->isDisablable() && $callback = $action->getDisableCallback()) {
|
|
55
|
|
|
$result = call_user_func($callback, $row);
|
|
56
|
|
|
if ($result) {
|
|
57
|
|
|
$disabledClass = 'disabled';
|
|
58
|
|
|
}
|
|
59
|
|
|
}
|
|
60
|
|
|
|
|
61
|
|
|
$html = '<a class="action-' .$action->getName() .' btn btn-default '.$disabledClass.'" href="'. $actionUrl .'"'. $onClick .'>
|
|
62
|
|
|
<span title="'. $view->translate($action->getLabel()) .'"
|
|
|
|
|
|
|
63
|
|
|
class="'. $action->getClass().'">
|
|
64
|
|
|
</span>
|
|
65
|
|
|
</a>';
|
|
66
|
|
|
|
|
67
|
|
|
return $html;
|
|
68
|
|
|
}
|
|
69
|
|
|
} |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto 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
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.