Completed
Branch FET-10586-integer-input (3bc5de)
by
unknown
148:55 queued 104:13
created

EE_Display_Strategy_Base::attribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2
/**
3
 * Class EE_Display_Strategy_Base
4
 *
5
 * @package 			Event Espresso
6
 * @subpackage    core
7
 * @author 				Mike Nelson, Brent Christensen
8
 * @since               	4.6
9
 *
10
 */
11
abstract class EE_Display_Strategy_Base extends EE_Form_Input_Strategy_Base{
12
	/**
13
	 * returns HTML and javascript related to the displaying of this input
14
	 * @return string
15
	 */
16
	abstract public function display();
17
18
19
20
	/**
21
	 * _remove_chars - takes an incoming string, and removes the string $chars from the end of it, but only if $chars is already there
22
	 *
23
	 * @param string $string - the string being processed
24
	 * @param string $chars - exact string of characters to remove
25
	 * @return string
26
	 */
27
	protected function _remove_chars( $string = '', $chars = '-' ) {
28
		$char_length = strlen( $chars ) * -1;
29
		// if last three characters of string is  " - ", then remove it
30
		return substr( $string, $char_length ) === $chars ? substr( $string, 0, $char_length ) : $string;
31
	}
32
33
34
35
	/**
36
	 * _append_chars - takes an incoming string, and adds the string $chars to the end of it, but only if $chars is not already there
37
	 *
38
	 * @param string $string - the string being processed
39
	 * @param string $chars - exact string of characters to be added to end of string
40
	 * @return string
41
	 */
42
	protected function _append_chars( $string = '', $chars = '-' ) {
43
		return  $this->_remove_chars( $string, $chars ) . $chars;
44
	}
45
46
	/**
47
	 * Gets the HTML IDs of all the inputs
48
	 * @return array
49
	 */
50
	public function get_html_input_ids( $add_pound_sign = false ) {
51
		return array( $this->get_input()->html_id( $add_pound_sign ) );
52
	}
53
54
55
56
	/**
57
	 * Adds js variables for localization to the $other_js_data. These should be put
58
	 * in each form's "other_data" javascript object.
59
	 *
60
	 * @param array $other_js_data
61
	 * @return array
62
	 */
63
	public function get_other_js_data( $other_js_data = array() ) {
64
		return $other_js_data;
65
	}
66
67
	/**
68
	 * Opportunity for this display strategy to call wp_enqueue_script and wp_enqueue_style.
69
	 * This should be called during wp_enqueue_scripts
70
	 */
71
	public function enqueue_js() {}
72
73
74
75
    /**
76
     * returns string like: attribute="value"
77
     * returns an empty string if $value is null
78
     *
79
     * @param string $tag
80
     * @return string
81
     */
82
    protected function opening_tag($tag)
83
    {
84
        return "<{$tag}";
85
    }
86
87
88
89
    /**
90
     * returns string like: attribute="value"
91
     * returns an empty string if $value is null
92
     *
93
     * @param string $tag
94
     * @return string
95
     */
96
    protected function closing_tag($tag = '')
97
    {
98
        return ! empty($tag) ? "/{$tag}>" : '/>';
99
    }
100
101
102
103
    /**
104
     * returns string like: ' attribute="value"'
105
     * returns an empty string if $value is null
106
     *
107
     * @param string $attribute
108
     * @param string $value
109
     * @return string
110
     */
111
    protected function attribute($attribute, $value = '')
112
    {
113
        return $value !== null ? " {$attribute}=\"{$value}\"" : '';
114
    }
115
116
117
118
    /**
119
     * returns string like: ' attribute' if $add is true
120
     *
121
     * @param string  $attribute
122
     * @param boolean $add
123
     * @return string
124
     */
125
    protected function single_attribute($attribute, $add = true)
126
    {
127
        return $add ? " {$attribute}" : '';
128
    }
129
130
}