Completed
Push — master ( 02b993...3405ac )
by Mikołaj
02:38
created

AdminFields::dateInput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 5
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Rudolf\Component\Forms;
4
5
use Rudolf\Component\Hooks\Filter;
6
7
class AdminFields
8
{
9
    /**
10
     * Returns textarea.
11
     *
12
     * @param string $content
13
     * @param string $name
14
     * @param string $class
15
     * @param string $id
16
     * @param string $placeholder
17
     * @param int    $cols
18
     * @param int    $rows
19
     *
20
     * @return string
21
     */
22
    public function textarea($content, $name, $class, $id, $placeholder = '', $cols = 30, $rows = 10)
23
    {
24
        if (Filter::isHas('admin_textarea')) {
25
            return Filter::apply('admin_textarea', [
26
                'content' => $content,
27
                'name' => $name,
28
                'class' => $class,
29
                'id' => $id,
30
                'placeholder' => $placeholder,
31
                'cols' => $cols,
32
                'rows' => $rows,
33
            ]);
34
        }
35
36
        $html = sprintf(
37
            '<textarea name="%2$s" class="%3$s" id="%4$s" placeholder="%5$s" cols="%6$s" rows="%7$s">%1$s</textarea>',
38
            $content,
39
            $name,
40
            $class,
41
            $id,
42
            $placeholder,
43
            $cols,
44
            $rows
45
        );
46
47
        return $html;
48
    }
49
50
    /**
51
     * Returns input type date or datetime.
52
     *
53
     * @param string $date
54
     * @param string $name
55
     * @param string $class
56
     * @param string $id
57
     * @param string $placeholder
58
     *
59
     * @return string
60
     */
61
    public function dateInput($date, $name, $class, $id, $placeholder = '')
62
    {
63
        $html = sprintf(
64
            '<input type="text" value="%1$s" name="%2$s" class="%3$s" id="%4$s" placeholder="%5$s">',
65
            $date,
66
            $name,
67
            $class,
68
            $id,
69
            $placeholder
70
        );
71
72
        // to do: add hook
73
74
        return $html;
75
    }
76
77
    /**
78
     * Returns input with path to file.
79
     *
80
     * @param string $path
81
     * @param string $name
82
     * @param string $class
83
     * @param string $id
84
     * @param string $placeholder
85
     *
86
     * @return string
87
     */
88
    public function pathInput($path, $name, $class, $id, $placeholder = '')
89
    {
90
        if (Filter::isHas('admin_file_path_input')) {
91
            return Filter::apply('admin_file_path_input', [
92
                'path' => $path,
93
                'name' => $name,
94
                'class' => $class,
95
                'id' => $id,
96
                'placeholder' => $placeholder,
97
            ]);
98
        }
99
100
        $html = sprintf(
101
            '<input type="text" value="%1$s" name="%2$s" class="%3$s" id="%4$s" placeholder="%5$s">',
102
            $path,
103
            $name,
104
            $class,
105
            $id,
106
            $placeholder
107
        );
108
109
        return $html;
110
    }
111
}
112