|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @company MTE Telecom, Ltd. |
|
4
|
|
|
* @author Roman Malashin <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Nnx\DataGrid\Column\Action; |
|
8
|
|
|
|
|
9
|
|
|
use Nnx\DataGrid\RowDataAwareInterface; |
|
10
|
|
|
use Nnx\DataGrid\RowDataAwareTrait; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class SimpleAction |
|
14
|
|
|
* @package Nnx\DataGrid\Column\Action |
|
15
|
|
|
*/ |
|
16
|
|
|
class SimpleAction extends AbstractAction implements RowDataAwareInterface |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
use RowDataAwareTrait; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @return string |
|
23
|
|
|
*/ |
|
24
|
|
|
public function getUrl() |
|
25
|
|
|
{ |
|
26
|
|
|
$urlHelper = $this->getUrlHelper(); |
|
|
|
|
|
|
27
|
|
|
$route = $this->getRoute(); |
|
|
|
|
|
|
28
|
|
|
$routeName = array_key_exists('routeName', $route) ? $route['routeName'] : null; |
|
|
|
|
|
|
29
|
|
|
$routeParams = array_key_exists('routeParams', $route) ? $route['routeParams'] : null; |
|
|
|
|
|
|
30
|
|
|
$routeOptions = array_key_exists('routeOptions', $route) ? $route['routeOptions'] : []; |
|
31
|
|
|
$options = array_merge($routeOptions, $this->getRowData()); |
|
|
|
|
|
|
32
|
|
|
$url = preg_replace_callback('/:([a-zA-Z_]+)/', |
|
|
|
|
|
|
33
|
|
|
[$this, 'replaceCallback'], |
|
34
|
|
|
$urlHelper($routeName, $routeParams, $options) |
|
35
|
|
|
); |
|
36
|
|
|
return $url; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param array $matches |
|
41
|
|
|
* @return mixed|string |
|
42
|
|
|
*/ |
|
43
|
|
View Code Duplication |
protected function replaceCallback($matches) |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
$row = $this->getRowData(); |
|
|
|
|
|
|
46
|
|
|
$varName = $matches[1]; |
|
47
|
|
|
$value = ''; |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
if (array_key_exists($varName, $row)) { |
|
50
|
|
|
if ($varName !== 'backurl') { |
|
51
|
|
|
$value = urlencode($row[$varName]); |
|
52
|
|
|
} else { |
|
53
|
|
|
$value = $row[$varName]; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $value; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return bool|mixed |
|
62
|
|
|
*/ |
|
63
|
|
View Code Duplication |
public function validate() |
|
|
|
|
|
|
64
|
|
|
{ |
|
65
|
|
|
$res = true; |
|
66
|
|
|
if ($this->getValidationFunction()) { |
|
67
|
|
|
$res = call_user_func($this->getValidationFunction(), $this->getRowData(), $this); |
|
68
|
|
|
} |
|
69
|
|
|
return $res; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
|
|
|
|
|
72
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.