1 | <?php |
||
23 | class InputMaskPluginTwigExtension extends AbstractPluginTwigExtension { |
||
24 | |||
25 | /** |
||
26 | * Service name. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | const SERVICE_NAME = "webeweb.bundle.bootstrapbundle.twig.extension.plugin.inputmask"; |
||
31 | |||
32 | /** |
||
33 | * Constructor. |
||
34 | */ |
||
35 | public function __construct() { |
||
38 | |||
39 | /** |
||
40 | * Displays a jQuery input mask. |
||
41 | * |
||
42 | * @param array $args The arguments. |
||
43 | * @return string Returns the jQuery input mask. |
||
44 | */ |
||
45 | public function jQueryInputMaskFunction(array $args = []) { |
||
46 | return $this->jQueryInputMask(ArrayUtility::get($args, "selector"), ArrayUtility::get($args, "mask", ""), ArrayUtility::get($args, "scriptTag", false), ArrayUtility::get($args, "opts", [])); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Displays a jQuery input mask "Phone number". |
||
51 | * |
||
52 | * @param array $args The arguments. |
||
53 | * @return string Returns the jQuery input mask "Phone number". |
||
54 | */ |
||
55 | public function jQueryInputMaskPhoneNumberFunction(array $args = []) { |
||
56 | $defaultMask = "99 99 99 99 99"; |
||
57 | return $this->jQueryInputMask(ArrayUtility::get($args, "selector"), $defaultMask, ArrayUtility::get($args, "scriptTag", false), $this->prepareOptions($args, $defaultMask)); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Displays a jQuery input mask "SIRET number". |
||
62 | * |
||
63 | * @param array $args The arguments. |
||
64 | * @return string Returns the jQuery input mask "SIRET number". |
||
65 | */ |
||
66 | public function jQueryInputMaskSIRETNumberFunction(array $args = []) { |
||
67 | $defaultMask = "999 999 999 99999"; |
||
68 | return $this->jQueryInputMask(ArrayUtility::get($args, "selector"), $defaultMask, ArrayUtility::get($args, "scriptTag", false), $this->prepareOptions($args, $defaultMask)); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Displays a jQuery input mask "Social security number". |
||
73 | * |
||
74 | * @param array $args The arguments. |
||
75 | * @return string Returns the jQuery input mask "Social security number". |
||
76 | */ |
||
77 | public function jQueryInputMaskSocialSecurityNumberFunction(array $args = []) { |
||
78 | $defaultMask = "9 99 99 99 999 999 99"; |
||
79 | return $this->jQueryInputMask(ArrayUtility::get($args, "selector"), $defaultMask, ArrayUtility::get($args, "scriptTag", false), $this->prepareOptions($args, $defaultMask)); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Displays a jQuery input mask "Time 12 hour". |
||
84 | * |
||
85 | * @param array $args The arguments. |
||
86 | * @return string Returns the jQuery input mask "Time 12 hour". |
||
87 | */ |
||
88 | public function jQueryInputMaskTime12Function(array $args = []) { |
||
89 | $defaultMask = "hh:mm t"; |
||
90 | return $this->jQueryInputMask(ArrayUtility::get($args, "selector"), $defaultMask, ArrayUtility::get($args, "scriptTag", false), array_merge($this->prepareOptions($args, null), ["hourFormat" => "12", "placeholder" => "__:__ _m"])); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Displays a jQuery input mask "Time 24 hour". |
||
95 | * |
||
96 | * @param array $args The arguments. |
||
97 | * @return string Returns the jQuery input mask "Time 24 hour". |
||
98 | */ |
||
99 | public function jQueryInputMaskTime24Function(array $args = []) { |
||
100 | $defaultMask = "hh:mm"; |
||
101 | return $this->jQueryInputMask(ArrayUtility::get($args, "selector"), $defaultMask, ArrayUtility::get($args, "scriptTag", false), array_merge($this->prepareOptions($args, null), ["hourFormat" => "24", "placeholder" => "__:__"])); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Displays a jQuery input mask "VAT number". |
||
106 | * |
||
107 | * @param array $args The arguments. |
||
108 | * @return string Returns the jQuery input mask "VAT number". |
||
109 | */ |
||
110 | public function jQueryInputMaskVATNumberFunction(array $args = []) { |
||
111 | $defaultMask = "**999 999 999 99"; |
||
112 | return $this->jQueryInputMask(ArrayUtility::get($args, "selector"), $defaultMask, ArrayUtility::get($args, "scriptTag", false), $this->prepareOptions($args, $defaultMask)); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Get the Twig functions. |
||
117 | * |
||
118 | * @return array Returns the Twig functions. |
||
119 | */ |
||
120 | public function getFunctions() { |
||
131 | |||
132 | /** |
||
133 | * Prepare the arguments. |
||
134 | * |
||
135 | * @param array $args The arguments. |
||
136 | * @param string $defaultMask |
||
137 | * @return array Returns the prepared arguments. |
||
138 | */ |
||
139 | private function prepareOptions(array $args = [], $defaultMask) { |
||
153 | |||
154 | } |
||
155 |