Passed
Push — devel-3.0 ( 3dfe81...25adf3 )
by Rubén
03:07
created

DataGridActionSearch   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setOnSubmitFunction() 0 3 1
A __construct() 0 5 1
A getOnSubmit() 0 9 5
A setOnSubmitArgs() 0 3 1
1
<?php
2
/**
3
 * sysPass
4
 *
5
 * @author nuxsmin
6
 * @link https://syspass.org
7
 * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
8
 *
9
 * This file is part of sysPass.
10
 *
11
 * sysPass is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * sysPass is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 *  along with sysPass.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace SP\Html\DataGrid\Action;
26
27
defined('APP_ROOT') || die();
28
29
/**
30
 * Class DataGridActionSearch para definir una acción de búsqueda de datos
31
 *
32
 * @package SP\Html\DataGrid
33
 */
34
final class DataGridActionSearch extends DataGridActionBase
35
{
36
    /**
37
     * @var string
38
     */
39
    private $onSubmitFunction = '';
40
41
    /**
42
     * Los argumentos de la función OnSubmit
43
     *
44
     * @var array
45
     */
46
    private $onSubmitArgs = [];
47
48
    /**
49
     * DataGridActionSearch constructor.
50
     *
51
     * @param int $id EL id de la acción
52
     */
53
    public function __construct($id = null)
54
    {
55
        parent::__construct($id);
56
57
        $this->setSkip(true);
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getOnSubmit()
64
    {
65
        $args = [];
66
67
        foreach ($this->onSubmitArgs as $arg) {
68
            $args[] = (!is_numeric($arg) && $arg !== 'this') ? '\'' . $arg . '\'' : $arg;
69
        }
70
71
        return count($args) > 0 ? 'return ' . $this->onSubmitFunction . '(' . implode(',', $args) . ');' : $this->onSubmitFunction;
72
    }
73
74
    /**
75
     * @param string $onSubmitFunction
76
     */
77
    public function setOnSubmitFunction($onSubmitFunction)
78
    {
79
        $this->onSubmitFunction = $onSubmitFunction;
80
    }
81
82
    /**
83
     * @param array $args
84
     */
85
    public function setOnSubmitArgs($args)
86
    {
87
        $this->onSubmitArgs[] = $args;
88
    }
89
}