Completed
Branch fix-dummy-related-question-qst... (e5efcf)
by
unknown
07:49 queued 03:45
created
strategies/display/EE_Text_Input_Display_Strategy.strategy.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -14,59 +14,59 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Text_Input_Display_Strategy extends EE_Display_Strategy_Base
16 16
 {
17
-    /**
18
-     * The html "type" attribute value. default is "text"
19
-     * @var string
20
-     */
21
-    protected $_type;
17
+	/**
18
+	 * The html "type" attribute value. default is "text"
19
+	 * @var string
20
+	 */
21
+	protected $_type;
22 22
 
23 23
 
24 24
 
25
-    /**
26
-     * @param string $type
27
-     */
28
-    public function __construct($type = 'text')
29
-    {
30
-        $this->_type = $type;
31
-        parent::__construct();
32
-    }
25
+	/**
26
+	 * @param string $type
27
+	 */
28
+	public function __construct($type = 'text')
29
+	{
30
+		$this->_type = $type;
31
+		parent::__construct();
32
+	}
33 33
 
34 34
 
35 35
 
36
-    /**
37
-     * Gets the html "type" attribute's value
38
-     * @return string
39
-     */
40
-    public function get_type()
41
-    {
42
-        if (
43
-            $this->_type === 'email'
44
-            && ! apply_filters('FHEE__EE_Text_Input_Display_Strategy__use_html5_email', false)
45
-        ) {
46
-            return 'text';
47
-        }
48
-        return $this->_type;
49
-    }
36
+	/**
37
+	 * Gets the html "type" attribute's value
38
+	 * @return string
39
+	 */
40
+	public function get_type()
41
+	{
42
+		if (
43
+			$this->_type === 'email'
44
+			&& ! apply_filters('FHEE__EE_Text_Input_Display_Strategy__use_html5_email', false)
45
+		) {
46
+			return 'text';
47
+		}
48
+		return $this->_type;
49
+	}
50 50
 
51 51
 
52 52
 
53
-    /**
54
-     *
55
-     * @return string of html to display the field
56
-     */
57
-    public function display()
58
-    {
59
-        $input = '<input type="' . $this->get_type() . '"';
60
-        $input .= ' name="' . $this->_input->html_name() . '"';
61
-        $input .= ' id="' . $this->_input->html_id() . '"';
62
-        $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
63
-        $input .= ' class="' . $class . '"';
64
-        // add html5 required
65
-        $input .= $this->_input->required() ? ' required' : '';
66
-        $input .= ' value="' . $this->_input->raw_value_in_form() . '"';
67
-        $input .= ' style="' . $this->_input->html_style() . '"';
68
-        $input .= $this->_input->other_html_attributes();
69
-        $input .= '/>';
70
-        return $input;
71
-    }
53
+	/**
54
+	 *
55
+	 * @return string of html to display the field
56
+	 */
57
+	public function display()
58
+	{
59
+		$input = '<input type="' . $this->get_type() . '"';
60
+		$input .= ' name="' . $this->_input->html_name() . '"';
61
+		$input .= ' id="' . $this->_input->html_id() . '"';
62
+		$class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
63
+		$input .= ' class="' . $class . '"';
64
+		// add html5 required
65
+		$input .= $this->_input->required() ? ' required' : '';
66
+		$input .= ' value="' . $this->_input->raw_value_in_form() . '"';
67
+		$input .= ' style="' . $this->_input->html_style() . '"';
68
+		$input .= $this->_input->other_html_attributes();
69
+		$input .= '/>';
70
+		return $input;
71
+	}
72 72
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -56,15 +56,15 @@
 block discarded – undo
56 56
      */
57 57
     public function display()
58 58
     {
59
-        $input = '<input type="' . $this->get_type() . '"';
60
-        $input .= ' name="' . $this->_input->html_name() . '"';
61
-        $input .= ' id="' . $this->_input->html_id() . '"';
62
-        $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
63
-        $input .= ' class="' . $class . '"';
59
+        $input = '<input type="'.$this->get_type().'"';
60
+        $input .= ' name="'.$this->_input->html_name().'"';
61
+        $input .= ' id="'.$this->_input->html_id().'"';
62
+        $class = $this->_input->required() ? $this->_input->required_css_class().' '.$this->_input->html_class() : $this->_input->html_class();
63
+        $input .= ' class="'.$class.'"';
64 64
         // add html5 required
65 65
         $input .= $this->_input->required() ? ' required' : '';
66
-        $input .= ' value="' . $this->_input->raw_value_in_form() . '"';
67
-        $input .= ' style="' . $this->_input->html_style() . '"';
66
+        $input .= ' value="'.$this->_input->raw_value_in_form().'"';
67
+        $input .= ' style="'.$this->_input->html_style().'"';
68 68
         $input .= $this->_input->other_html_attributes();
69 69
         $input .= '/>';
70 70
         return $input;
Please login to merge, or discard this patch.
sensitive_data_removal/EE_CCV_Sensitive_Data_Removal.strategy.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,18 +11,18 @@
 block discarded – undo
11 11
  */
12 12
 class EE_CCV_Sensitive_Data_Removal extends EE_Sensitive_Data_Removal_Base
13 13
 {
14
-    public function remove_sensitive_data($normalized_value)
15
-    {
16
-        // Get the ccv Length
17
-        $ccv_lenght = strlen($normalized_value);
18
-        // Replace all characters of credit card except the last four and dashes
19
-        for ($i = 0; $i < $ccv_lenght; $i++) {
20
-            if ($normalized_value[ $i ] == '-') {
21
-                continue;
22
-            }
23
-            $normalized_value[ $i ] = 'X';
24
-        }
25
-        // Return the masked Credit Card #
26
-        return $normalized_value;
27
-    }
14
+	public function remove_sensitive_data($normalized_value)
15
+	{
16
+		// Get the ccv Length
17
+		$ccv_lenght = strlen($normalized_value);
18
+		// Replace all characters of credit card except the last four and dashes
19
+		for ($i = 0; $i < $ccv_lenght; $i++) {
20
+			if ($normalized_value[ $i ] == '-') {
21
+				continue;
22
+			}
23
+			$normalized_value[ $i ] = 'X';
24
+		}
25
+		// Return the masked Credit Card #
26
+		return $normalized_value;
27
+	}
28 28
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@
 block discarded – undo
17 17
         $ccv_lenght = strlen($normalized_value);
18 18
         // Replace all characters of credit card except the last four and dashes
19 19
         for ($i = 0; $i < $ccv_lenght; $i++) {
20
-            if ($normalized_value[ $i ] == '-') {
20
+            if ($normalized_value[$i] == '-') {
21 21
                 continue;
22 22
             }
23
-            $normalized_value[ $i ] = 'X';
23
+            $normalized_value[$i] = 'X';
24 24
         }
25 25
         // Return the masked Credit Card #
26 26
         return $normalized_value;
Please login to merge, or discard this patch.
sensitive_data_removal/EE_Credit_Card_Sensitive_Data_Removal.strategy.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,18 +11,18 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Credit_Card_Sensitive_Data_Removal extends EE_Sensitive_Data_Removal_Base
13 13
 {
14
-    public function remove_sensitive_data($normalized_value)
15
-    {
16
-        // Get the cc Length
17
-        $cc_length = strlen($normalized_value);
18
-        // Replace all characters of credit card except the last four and dashes
19
-        for ($i = 0; $i < $cc_length - 4; $i++) {
20
-            if ($normalized_value[ $i ] == '-') {
21
-                continue;
22
-            }
23
-            $normalized_value[ $i ] = 'X';
24
-        }
25
-        // Return the masked Credit Card #
26
-        return $normalized_value;
27
-    }
14
+	public function remove_sensitive_data($normalized_value)
15
+	{
16
+		// Get the cc Length
17
+		$cc_length = strlen($normalized_value);
18
+		// Replace all characters of credit card except the last four and dashes
19
+		for ($i = 0; $i < $cc_length - 4; $i++) {
20
+			if ($normalized_value[ $i ] == '-') {
21
+				continue;
22
+			}
23
+			$normalized_value[ $i ] = 'X';
24
+		}
25
+		// Return the masked Credit Card #
26
+		return $normalized_value;
27
+	}
28 28
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@
 block discarded – undo
17 17
         $cc_length = strlen($normalized_value);
18 18
         // Replace all characters of credit card except the last four and dashes
19 19
         for ($i = 0; $i < $cc_length - 4; $i++) {
20
-            if ($normalized_value[ $i ] == '-') {
20
+            if ($normalized_value[$i] == '-') {
21 21
                 continue;
22 22
             }
23
-            $normalized_value[ $i ] = 'X';
23
+            $normalized_value[$i] = 'X';
24 24
         }
25 25
         // Return the masked Credit Card #
26 26
         return $normalized_value;
Please login to merge, or discard this patch.
strategies/validation/EE_Max_Length_Validation_Strategy.strategy.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
     public function get_jquery_validation_rule_array()
45 45
     {
46 46
         if ($this->_max_length !== EE_INF) {
47
-            return array( 'maxlength' => $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) );
47
+            return array('maxlength' => $this->_max_length, 'messages' => array('maxlength' => $this->get_validation_error_message()));
48 48
         } else {
49 49
             return array();
50 50
         }
Please login to merge, or discard this patch.
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -11,41 +11,41 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Max_Length_Validation_Strategy extends EE_Validation_Strategy_Base
13 13
 {
14
-    protected $_max_length;
14
+	protected $_max_length;
15 15
 
16
-    public function __construct($validation_error_message = null, $max_length = EE_INF)
17
-    {
18
-        $this->_max_length = $max_length;
19
-        if ($validation_error_message === null) {
20
-            $validation_error_message = sprintf(esc_html__('Input is too long. Maximum number of characters is %1$s', 'event_espresso'), $max_length);
21
-        }
22
-        parent::__construct($validation_error_message);
23
-    }
16
+	public function __construct($validation_error_message = null, $max_length = EE_INF)
17
+	{
18
+		$this->_max_length = $max_length;
19
+		if ($validation_error_message === null) {
20
+			$validation_error_message = sprintf(esc_html__('Input is too long. Maximum number of characters is %1$s', 'event_espresso'), $max_length);
21
+		}
22
+		parent::__construct($validation_error_message);
23
+	}
24 24
 
25
-    /**
26
-     * @param $normalized_value
27
-     */
28
-    public function validate($normalized_value)
29
-    {
30
-        if (
31
-            $this->_max_length !== EE_INF &&
32
-                $normalized_value &&
33
-                is_string($normalized_value) &&
34
-                 strlen($normalized_value) > $this->_max_length
35
-        ) {
36
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'maxlength');
37
-        }
38
-    }
25
+	/**
26
+	 * @param $normalized_value
27
+	 */
28
+	public function validate($normalized_value)
29
+	{
30
+		if (
31
+			$this->_max_length !== EE_INF &&
32
+				$normalized_value &&
33
+				is_string($normalized_value) &&
34
+				 strlen($normalized_value) > $this->_max_length
35
+		) {
36
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'maxlength');
37
+		}
38
+	}
39 39
 
40
-    /**
41
-     * @return array
42
-     */
43
-    public function get_jquery_validation_rule_array()
44
-    {
45
-        if ($this->_max_length !== EE_INF) {
46
-            return array( 'maxlength' => $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) );
47
-        } else {
48
-            return array();
49
-        }
50
-    }
40
+	/**
41
+	 * @return array
42
+	 */
43
+	public function get_jquery_validation_rule_array()
44
+	{
45
+		if ($this->_max_length !== EE_INF) {
46
+			return array( 'maxlength' => $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) );
47
+		} else {
48
+			return array();
49
+		}
50
+	}
51 51
 }
Please login to merge, or discard this patch.
strategies/validation/EE_Min_Length_Validation_Strategy.strategy.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,6 +40,6 @@
 block discarded – undo
40 40
      */
41 41
     public function get_jquery_validation_rule_array()
42 42
     {
43
-        return array( 'minlength' => $this->_min_length, 'messages' => array( 'minlength' => $this->get_validation_error_message() ) );
43
+        return array('minlength' => $this->_min_length, 'messages' => array('minlength' => $this->get_validation_error_message()));
44 44
     }
45 45
 }
Please login to merge, or discard this patch.
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -11,34 +11,34 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Min_Length_Validation_Strategy extends EE_Validation_Strategy_Base
13 13
 {
14
-    protected $_min_length;
14
+	protected $_min_length;
15 15
 
16
-    public function __construct($validation_error_message = null, $min_length = 0)
17
-    {
18
-        $this->_min_length = $min_length;
19
-        parent::__construct($validation_error_message);
20
-    }
16
+	public function __construct($validation_error_message = null, $min_length = 0)
17
+	{
18
+		$this->_min_length = $min_length;
19
+		parent::__construct($validation_error_message);
20
+	}
21 21
 
22
-    /**
23
-     * @param $normalized_value
24
-     */
25
-    public function validate($normalized_value)
26
-    {
27
-        if (
28
-            $this->_min_length > 0 &&
29
-                $normalized_value &&
30
-                is_string($normalized_value) &&
31
-                strlen($normalized_value) < $this->_min_length
32
-        ) {
33
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'minlength');
34
-        }
35
-    }
22
+	/**
23
+	 * @param $normalized_value
24
+	 */
25
+	public function validate($normalized_value)
26
+	{
27
+		if (
28
+			$this->_min_length > 0 &&
29
+				$normalized_value &&
30
+				is_string($normalized_value) &&
31
+				strlen($normalized_value) < $this->_min_length
32
+		) {
33
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'minlength');
34
+		}
35
+	}
36 36
 
37
-    /**
38
-     * @return array
39
-     */
40
-    public function get_jquery_validation_rule_array()
41
-    {
42
-        return array( 'minlength' => $this->_min_length, 'messages' => array( 'minlength' => $this->get_validation_error_message() ) );
43
-    }
37
+	/**
38
+	 * @return array
39
+	 */
40
+	public function get_jquery_validation_rule_array()
41
+	{
42
+		return array( 'minlength' => $this->_min_length, 'messages' => array( 'minlength' => $this->get_validation_error_message() ) );
43
+	}
44 44
 }
Please login to merge, or discard this patch.
strategies/validation/EE_Text_Validation_Strategy.strategy.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
     public function validate($normalized_value)
30 30
     {
31 31
         $string_normalized_value = (string) $normalized_value;
32
-        if ($this->_regex &&  $string_normalized_value) {
33
-            if (! preg_match($this->_regex, $string_normalized_value)) {
32
+        if ($this->_regex && $string_normalized_value) {
33
+            if ( ! preg_match($this->_regex, $string_normalized_value)) {
34 34
                 throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
35 35
             }
36 36
         }
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     public function get_jquery_validation_rule_array()
43 43
     {
44 44
         if ($this->_regex !== null) {
45
-            return array( 'regex' => $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) );
45
+            return array('regex' => $this->regex_js(), 'messages' => array('regex' => $this->get_validation_error_message()));
46 46
         } else {
47 47
             return array();
48 48
         }
Please login to merge, or discard this patch.
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -10,53 +10,53 @@
 block discarded – undo
10 10
  */
11 11
 class EE_Text_Validation_Strategy extends EE_Validation_Strategy_Base
12 12
 {
13
-    protected $_regex = null;
14
-    /**
15
-     *
16
-     * @param string $validation_error_message
17
-     * @param string $regex a PHP regex; the javascript regex will be derived from this
18
-     */
19
-    public function __construct($validation_error_message = null, $regex = null)
20
-    {
21
-        $this->_regex = $regex;
22
-        parent::__construct($validation_error_message);
23
-    }
13
+	protected $_regex = null;
14
+	/**
15
+	 *
16
+	 * @param string $validation_error_message
17
+	 * @param string $regex a PHP regex; the javascript regex will be derived from this
18
+	 */
19
+	public function __construct($validation_error_message = null, $regex = null)
20
+	{
21
+		$this->_regex = $regex;
22
+		parent::__construct($validation_error_message);
23
+	}
24 24
 
25
-    /**
26
-     * @param $normalized_value
27
-     */
28
-    public function validate($normalized_value)
29
-    {
30
-        $string_normalized_value = (string) $normalized_value;
31
-        if ($this->_regex &&  $string_normalized_value) {
32
-            if (! preg_match($this->_regex, $string_normalized_value)) {
33
-                throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
34
-            }
35
-        }
36
-    }
25
+	/**
26
+	 * @param $normalized_value
27
+	 */
28
+	public function validate($normalized_value)
29
+	{
30
+		$string_normalized_value = (string) $normalized_value;
31
+		if ($this->_regex &&  $string_normalized_value) {
32
+			if (! preg_match($this->_regex, $string_normalized_value)) {
33
+				throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
34
+			}
35
+		}
36
+	}
37 37
 
38
-    /**
39
-     * @return array
40
-     */
41
-    public function get_jquery_validation_rule_array()
42
-    {
43
-        if ($this->_regex !== null) {
44
-            return array( 'regex' => $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) );
45
-        } else {
46
-            return array();
47
-        }
48
-    }
38
+	/**
39
+	 * @return array
40
+	 */
41
+	public function get_jquery_validation_rule_array()
42
+	{
43
+		if ($this->_regex !== null) {
44
+			return array( 'regex' => $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) );
45
+		} else {
46
+			return array();
47
+		}
48
+	}
49 49
 
50 50
 /**
51 51
  * Translates a PHP regex into a javscript regex (eg, PHP needs separate delimieters, whereas
52 52
  * javscript does not
53 53
  * @return string
54 54
  */
55
-    public function regex_js()
56
-    {
57
-        // first character must be the delimiter
58
-        $delimeter = $this->_regex[0];
59
-        $last_occurence_of_delimieter = strrpos($this->_regex, $delimeter);
60
-        return substr($this->_regex, 1, $last_occurence_of_delimieter - 1);
61
-    }
55
+	public function regex_js()
56
+	{
57
+		// first character must be the delimiter
58
+		$delimeter = $this->_regex[0];
59
+		$last_occurence_of_delimieter = strrpos($this->_regex, $delimeter);
60
+		return substr($this->_regex, 1, $last_occurence_of_delimieter - 1);
61
+	}
62 62
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/FormHandler.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      */
172 172
     public function form($for_display = false)
173 173
     {
174
-        if (! $this->formIsValid()) {
174
+        if ( ! $this->formIsValid()) {
175 175
             return null;
176 176
         }
177 177
         if ($for_display) {
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
      */
275 275
     public function setFormName($form_name)
276 276
     {
277
-        if (! is_string($form_name)) {
277
+        if ( ! is_string($form_name)) {
278 278
             throw new InvalidDataTypeException('$form_name', $form_name, 'string');
279 279
         }
280 280
         $this->form_name = $form_name;
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
      */
299 299
     public function setAdminName($admin_name)
300 300
     {
301
-        if (! is_string($admin_name)) {
301
+        if ( ! is_string($admin_name)) {
302 302
             throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
303 303
         }
304 304
         $this->admin_name = $admin_name;
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
      */
323 323
     public function setSlug($slug)
324 324
     {
325
-        if (! is_string($slug)) {
325
+        if ( ! is_string($slug)) {
326 326
             throw new InvalidDataTypeException('$slug', $slug, 'string');
327 327
         }
328 328
         $this->slug = $slug;
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
      */
346 346
     public function setSubmitBtnText($submit_btn_text)
347 347
     {
348
-        if (! is_string($submit_btn_text)) {
348
+        if ( ! is_string($submit_btn_text)) {
349 349
             throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
350 350
         }
351 351
         if (empty($submit_btn_text)) {
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
      */
375 375
     public function setFormAction($form_action)
376 376
     {
377
-        if (! is_string($form_action)) {
377
+        if ( ! is_string($form_action)) {
378 378
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
379 379
         }
380 380
         $this->form_action = $form_action;
@@ -493,11 +493,11 @@  discard block
 block discarded – undo
493 493
         $text = ! empty($text) ? $text : $this->submitBtnText();
494 494
         return new EE_Submit_Input(
495 495
             array(
496
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
497
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
496
+                'html_name'             => 'ee-form-submit-'.$this->slug(),
497
+                'html_id'               => 'ee-form-submit-'.$this->slug(),
498 498
                 'html_class'            => 'ee-form-submit',
499 499
                 'html_label'            => '&nbsp;',
500
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
500
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
501 501
                 'default'               => $text,
502 502
             )
503 503
         );
@@ -513,11 +513,11 @@  discard block
 block discarded – undo
513 513
      */
514 514
     public function appendSubmitButton($text = '')
515 515
     {
516
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
516
+        if ($this->form->subsection_exists($this->slug().'-submit-btn')) {
517 517
             return;
518 518
         }
519 519
         $this->form->add_subsections(
520
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
520
+            array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)),
521 521
             null,
522 522
             false
523 523
         );
@@ -534,11 +534,11 @@  discard block
 block discarded – undo
534 534
     {
535 535
         $cancel_button = new EE_Submit_Input(
536 536
             array(
537
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
538
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
537
+                'html_name'             => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!!
538
+                'html_id'               => 'ee-cancel-form-'.$this->slug(),
539 539
                 'html_class'            => 'ee-cancel-form',
540 540
                 'html_label'            => '&nbsp;',
541
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
541
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
542 542
                 'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
543 543
             )
544 544
         );
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
         $this->form->add_subsections(
559 559
             array(
560 560
                 'clear-submit-btn-float' => new EE_Form_Section_HTML(
561
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
561
+                    EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx()
562 562
                 ),
563 563
             ),
564 564
             null,
@@ -644,11 +644,11 @@  discard block
 block discarded – undo
644 644
      */
645 645
     public function process($submitted_form_data = array())
646 646
     {
647
-        if (! $this->form()->was_submitted($submitted_form_data)) {
647
+        if ( ! $this->form()->was_submitted($submitted_form_data)) {
648 648
             throw new InvalidFormSubmissionException($this->form_name);
649 649
         }
650 650
         $this->form(true)->receive_form_submission($submitted_form_data);
651
-        if (! $this->form()->is_valid()) {
651
+        if ( ! $this->form()->is_valid()) {
652 652
             throw new InvalidFormSubmissionException(
653 653
                 $this->form_name,
654 654
                 sprintf(
Please login to merge, or discard this patch.
Indentation   +638 added lines, -638 removed lines patch added patch discarded remove patch
@@ -28,642 +28,642 @@
 block discarded – undo
28 28
  */
29 29
 abstract class FormHandler implements FormHandlerInterface
30 30
 {
31
-    /**
32
-     * will add opening and closing HTML form tags as well as a submit button
33
-     */
34
-    const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
35
-
36
-    /**
37
-     * will add opening and closing HTML form tags but NOT a submit button
38
-     */
39
-    const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
40
-
41
-    /**
42
-     * will NOT add opening and closing HTML form tags but will add a submit button
43
-     */
44
-    const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
45
-
46
-    /**
47
-     * will NOT add opening and closing HTML form tags NOR a submit button
48
-     */
49
-    const DO_NOT_SETUP_FORM = 'do_not_setup_form';
50
-
51
-    /**
52
-     * if set to false, then this form has no displayable content,
53
-     * and will only be used for processing data sent passed via GET or POST
54
-     * defaults to true ( ie: form has displayable content )
55
-     *
56
-     * @var boolean $displayable
57
-     */
58
-    private $displayable = true;
59
-
60
-    /**
61
-     * @var string $form_name
62
-     */
63
-    private $form_name;
64
-
65
-    /**
66
-     * @var string $admin_name
67
-     */
68
-    private $admin_name;
69
-
70
-    /**
71
-     * @var string $slug
72
-     */
73
-    private $slug;
74
-
75
-    /**
76
-     * @var string $submit_btn_text
77
-     */
78
-    private $submit_btn_text;
79
-
80
-    /**
81
-     * @var string $form_action
82
-     */
83
-    private $form_action;
84
-
85
-    /**
86
-     * form params in key value pairs
87
-     * can be added to form action URL or as hidden inputs
88
-     *
89
-     * @var array $form_args
90
-     */
91
-    private $form_args = array();
92
-
93
-    /**
94
-     * value of one of the string constant above
95
-     *
96
-     * @var string $form_config
97
-     */
98
-    private $form_config;
99
-
100
-    /**
101
-     * whether or not the form was determined to be invalid
102
-     *
103
-     * @var boolean $form_has_errors
104
-     */
105
-    private $form_has_errors;
106
-
107
-    /**
108
-     * the absolute top level form section being used on the page
109
-     *
110
-     * @var EE_Form_Section_Proper $form
111
-     */
112
-    private $form;
113
-
114
-    /**
115
-     * @var EE_Registry $registry
116
-     */
117
-    protected $registry;
118
-
119
-    // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
120
-
121
-
122
-    /**
123
-     * Form constructor.
124
-     *
125
-     * @param string           $form_name
126
-     * @param string           $admin_name
127
-     * @param string           $slug
128
-     * @param string           $form_action
129
-     * @param string           $form_config
130
-     * @param EE_Registry|null $registry
131
-     */
132
-    public function __construct(
133
-        $form_name,
134
-        $admin_name,
135
-        $slug,
136
-        $form_action = '',
137
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
138
-        EE_Registry $registry = null
139
-    ) {
140
-        $this->setFormName($form_name);
141
-        $this->setAdminName($admin_name);
142
-        $this->setSlug($slug);
143
-        $this->setFormAction($form_action);
144
-        $this->setFormConfig($form_config);
145
-        $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
146
-        $this->registry = $registry;
147
-    }
148
-
149
-
150
-    /**
151
-     * @return array
152
-     */
153
-    public static function getFormConfigConstants()
154
-    {
155
-        return array(
156
-            FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
157
-            FormHandler::ADD_FORM_TAGS_ONLY,
158
-            FormHandler::ADD_FORM_SUBMIT_ONLY,
159
-            FormHandler::DO_NOT_SETUP_FORM,
160
-        );
161
-    }
162
-
163
-
164
-    /**
165
-     * @param bool $for_display
166
-     * @return EE_Form_Section_Proper
167
-     * @throws EE_Error
168
-     * @throws LogicException
169
-     */
170
-    public function form($for_display = false)
171
-    {
172
-        if (! $this->formIsValid()) {
173
-            return null;
174
-        }
175
-        if ($for_display) {
176
-            $form_config = $this->formConfig();
177
-            if (
178
-                $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
179
-                || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
180
-            ) {
181
-                $this->appendSubmitButton();
182
-                $this->clearFormButtonFloats();
183
-            }
184
-        }
185
-        return $this->form;
186
-    }
187
-
188
-
189
-    /**
190
-     * @return boolean
191
-     * @throws LogicException
192
-     */
193
-    public function formIsValid()
194
-    {
195
-        if ($this->form instanceof EE_Form_Section_Proper) {
196
-            return true;
197
-        }
198
-        $form = apply_filters(
199
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
200
-            $this->generate(),
201
-            $this
202
-        );
203
-        if ($this->verifyForm($form)) {
204
-            $this->setForm($form);
205
-        }
206
-        return true;
207
-    }
208
-
209
-
210
-    /**
211
-     * @param EE_Form_Section_Proper|null $form
212
-     * @return bool
213
-     * @throws LogicException
214
-     */
215
-    public function verifyForm(EE_Form_Section_Proper $form = null)
216
-    {
217
-        $form = $form !== null ? $form : $this->form;
218
-        if ($form instanceof EE_Form_Section_Proper) {
219
-            return true;
220
-        }
221
-        throw new LogicException(
222
-            sprintf(
223
-                esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
224
-                $this->form_name,
225
-                var_export($form, true)
226
-            )
227
-        );
228
-    }
229
-
230
-
231
-    /**
232
-     * @param EE_Form_Section_Proper $form
233
-     */
234
-    public function setForm(EE_Form_Section_Proper $form)
235
-    {
236
-        $this->form = $form;
237
-    }
238
-
239
-
240
-    /**
241
-     * @return boolean
242
-     */
243
-    public function displayable()
244
-    {
245
-        return $this->displayable;
246
-    }
247
-
248
-
249
-    /**
250
-     * @param boolean $displayable
251
-     */
252
-    public function setDisplayable($displayable = false)
253
-    {
254
-        $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
255
-    }
256
-
257
-
258
-    /**
259
-     * a public name for the form that can be displayed on the frontend of a site
260
-     *
261
-     * @return string
262
-     */
263
-    public function formName()
264
-    {
265
-        return $this->form_name;
266
-    }
267
-
268
-
269
-    /**
270
-     * @param string $form_name
271
-     * @throws InvalidDataTypeException
272
-     */
273
-    public function setFormName($form_name)
274
-    {
275
-        if (! is_string($form_name)) {
276
-            throw new InvalidDataTypeException('$form_name', $form_name, 'string');
277
-        }
278
-        $this->form_name = $form_name;
279
-    }
280
-
281
-
282
-    /**
283
-     * a public name for the form that can be displayed, but only in the admin
284
-     *
285
-     * @return string
286
-     */
287
-    public function adminName()
288
-    {
289
-        return $this->admin_name;
290
-    }
291
-
292
-
293
-    /**
294
-     * @param string $admin_name
295
-     * @throws InvalidDataTypeException
296
-     */
297
-    public function setAdminName($admin_name)
298
-    {
299
-        if (! is_string($admin_name)) {
300
-            throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
301
-        }
302
-        $this->admin_name = $admin_name;
303
-    }
304
-
305
-
306
-    /**
307
-     * a URL friendly string that can be used for identifying the form
308
-     *
309
-     * @return string
310
-     */
311
-    public function slug()
312
-    {
313
-        return $this->slug;
314
-    }
315
-
316
-
317
-    /**
318
-     * @param string $slug
319
-     * @throws InvalidDataTypeException
320
-     */
321
-    public function setSlug($slug)
322
-    {
323
-        if (! is_string($slug)) {
324
-            throw new InvalidDataTypeException('$slug', $slug, 'string');
325
-        }
326
-        $this->slug = $slug;
327
-    }
328
-
329
-
330
-    /**
331
-     * @return string
332
-     */
333
-    public function submitBtnText()
334
-    {
335
-        return $this->submit_btn_text;
336
-    }
337
-
338
-
339
-    /**
340
-     * @param string $submit_btn_text
341
-     * @throws InvalidDataTypeException
342
-     * @throws InvalidArgumentException
343
-     */
344
-    public function setSubmitBtnText($submit_btn_text)
345
-    {
346
-        if (! is_string($submit_btn_text)) {
347
-            throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
348
-        }
349
-        if (empty($submit_btn_text)) {
350
-            throw new InvalidArgumentException(
351
-                esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
352
-            );
353
-        }
354
-        $this->submit_btn_text = $submit_btn_text;
355
-    }
356
-
357
-
358
-    /**
359
-     * @return string
360
-     */
361
-    public function formAction()
362
-    {
363
-        return ! empty($this->form_args)
364
-            ? add_query_arg($this->form_args, $this->form_action)
365
-            : $this->form_action;
366
-    }
367
-
368
-
369
-    /**
370
-     * @param string $form_action
371
-     * @throws InvalidDataTypeException
372
-     */
373
-    public function setFormAction($form_action)
374
-    {
375
-        if (! is_string($form_action)) {
376
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
377
-        }
378
-        $this->form_action = $form_action;
379
-    }
380
-
381
-
382
-    /**
383
-     * @param array $form_args
384
-     * @throws InvalidDataTypeException
385
-     * @throws InvalidArgumentException
386
-     */
387
-    public function addFormActionArgs($form_args = array())
388
-    {
389
-        if (is_object($form_args)) {
390
-            throw new InvalidDataTypeException(
391
-                '$form_args',
392
-                $form_args,
393
-                'anything other than an object was expected.'
394
-            );
395
-        }
396
-        if (empty($form_args)) {
397
-            throw new InvalidArgumentException(
398
-                esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
399
-            );
400
-        }
401
-        $this->form_args = array_merge($this->form_args, $form_args);
402
-    }
403
-
404
-
405
-    /**
406
-     * @return string
407
-     */
408
-    public function formConfig()
409
-    {
410
-        return $this->form_config;
411
-    }
412
-
413
-
414
-    /**
415
-     * @param string $form_config
416
-     * @throws DomainException
417
-     */
418
-    public function setFormConfig($form_config)
419
-    {
420
-        if (
421
-            ! in_array(
422
-                $form_config,
423
-                array(
424
-                FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
425
-                FormHandler::ADD_FORM_TAGS_ONLY,
426
-                FormHandler::ADD_FORM_SUBMIT_ONLY,
427
-                FormHandler::DO_NOT_SETUP_FORM,
428
-                ),
429
-                true
430
-            )
431
-        ) {
432
-            throw new DomainException(
433
-                sprintf(
434
-                    esc_html__(
435
-                        '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
436
-                        'event_espresso'
437
-                    ),
438
-                    $form_config
439
-                )
440
-            );
441
-        }
442
-        $this->form_config = $form_config;
443
-    }
444
-
445
-
446
-    /**
447
-     * called after the form is instantiated
448
-     * and used for performing any logic that needs to occur early
449
-     * before any of the other methods are called.
450
-     * returns true if everything is ok to proceed,
451
-     * and false if no further form logic should be implemented
452
-     *
453
-     * @return boolean
454
-     */
455
-    public function initialize()
456
-    {
457
-        $this->form_has_errors = EE_Error::has_error(true);
458
-        return true;
459
-    }
460
-
461
-
462
-    /**
463
-     * used for setting up css and js
464
-     *
465
-     * @return void
466
-     * @throws LogicException
467
-     * @throws EE_Error
468
-     */
469
-    public function enqueueStylesAndScripts()
470
-    {
471
-        $this->form()->enqueue_js();
472
-    }
473
-
474
-
475
-    /**
476
-     * creates and returns the actual form
477
-     *
478
-     * @return EE_Form_Section_Proper
479
-     */
480
-    abstract public function generate();
481
-
482
-
483
-    /**
484
-     * creates and returns an EE_Submit_Input labeled "Submit"
485
-     *
486
-     * @param string $text
487
-     * @return EE_Submit_Input
488
-     */
489
-    public function generateSubmitButton($text = '')
490
-    {
491
-        $text = ! empty($text) ? $text : $this->submitBtnText();
492
-        return new EE_Submit_Input(
493
-            array(
494
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
495
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
496
-                'html_class'            => 'ee-form-submit',
497
-                'html_label'            => '&nbsp;',
498
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
499
-                'default'               => $text,
500
-            )
501
-        );
502
-    }
503
-
504
-
505
-    /**
506
-     * calls generateSubmitButton() and appends it onto the form along with a float clearing div
507
-     *
508
-     * @param string $text
509
-     * @return void
510
-     * @throws EE_Error
511
-     */
512
-    public function appendSubmitButton($text = '')
513
-    {
514
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
515
-            return;
516
-        }
517
-        $this->form->add_subsections(
518
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
519
-            null,
520
-            false
521
-        );
522
-    }
523
-
524
-
525
-    /**
526
-     * creates and returns an EE_Submit_Input labeled "Cancel"
527
-     *
528
-     * @param string $text
529
-     * @return EE_Submit_Input
530
-     */
531
-    public function generateCancelButton($text = '')
532
-    {
533
-        $cancel_button = new EE_Submit_Input(
534
-            array(
535
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
536
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
537
-                'html_class'            => 'ee-cancel-form',
538
-                'html_label'            => '&nbsp;',
539
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
540
-                'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
541
-            )
542
-        );
543
-        $cancel_button->set_button_css_attributes(false);
544
-        return $cancel_button;
545
-    }
546
-
547
-
548
-    /**
549
-     * appends a float clearing div onto end of form
550
-     *
551
-     * @return void
552
-     * @throws EE_Error
553
-     */
554
-    public function clearFormButtonFloats()
555
-    {
556
-        $this->form->add_subsections(
557
-            array(
558
-                'clear-submit-btn-float' => new EE_Form_Section_HTML(
559
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
560
-                ),
561
-            ),
562
-            null,
563
-            false
564
-        );
565
-    }
566
-
567
-
568
-    /**
569
-     * takes the generated form and displays it along with ony other non-form HTML that may be required
570
-     * returns a string of HTML that can be directly echoed in a template
571
-     *
572
-     * @return string
573
-     * @throws \InvalidArgumentException
574
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
575
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
576
-     * @throws LogicException
577
-     * @throws EE_Error
578
-     */
579
-    public function display()
580
-    {
581
-        $form_html = apply_filters(
582
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
583
-            ''
584
-        );
585
-        $form_config = $this->formConfig();
586
-        if (
587
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
588
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
589
-        ) {
590
-            $additional_props = $this->requiresMultipartEnctype()
591
-                ? ' enctype="multipart/form-data"'
592
-                : '';
593
-            $form_html .= $this->form()->form_open(
594
-                $this->formAction(),
595
-                'POST',
596
-                $additional_props
597
-            );
598
-        }
599
-        $form_html .= $this->form(true)->get_html();
600
-        if (
601
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
602
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
603
-        ) {
604
-            $form_html .= $this->form()->form_close();
605
-        }
606
-        $form_html .= apply_filters(
607
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
608
-            ''
609
-        );
610
-        return $form_html;
611
-    }
612
-
613
-    /**
614
-     * Determines if this form needs "enctype='multipart/form-data'" or not.
615
-     * @since 4.9.80.p
616
-     * @return bool
617
-     * @throws EE_Error
618
-     */
619
-    public function requiresMultipartEnctype()
620
-    {
621
-        foreach ($this->form()->inputs_in_subsections() as $input) {
622
-            if ($input instanceof EE_File_Input) {
623
-                return true;
624
-            }
625
-        }
626
-        return false;
627
-    }
628
-
629
-
630
-    /**
631
-     * handles processing the form submission
632
-     * returns true or false depending on whether the form was processed successfully or not
633
-     *
634
-     * @param array $submitted_form_data
635
-     * @return array
636
-     * @throws \InvalidArgumentException
637
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
638
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
639
-     * @throws EE_Error
640
-     * @throws LogicException
641
-     * @throws InvalidFormSubmissionException
642
-     */
643
-    public function process($submitted_form_data = array())
644
-    {
645
-        if (! $this->form()->was_submitted($submitted_form_data)) {
646
-            throw new InvalidFormSubmissionException($this->form_name);
647
-        }
648
-        $this->form(true)->receive_form_submission($submitted_form_data);
649
-        if (! $this->form()->is_valid()) {
650
-            throw new InvalidFormSubmissionException(
651
-                $this->form_name,
652
-                sprintf(
653
-                    esc_html__(
654
-                        'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
655
-                        'event_espresso'
656
-                    ),
657
-                    $this->form_name,
658
-                    '<br />',
659
-                    implode('<br />', $this->form()->get_validation_errors_accumulated())
660
-                )
661
-            );
662
-        }
663
-        return apply_filters(
664
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data',
665
-            $this->form()->valid_data(),
666
-            $this
667
-        );
668
-    }
31
+	/**
32
+	 * will add opening and closing HTML form tags as well as a submit button
33
+	 */
34
+	const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
35
+
36
+	/**
37
+	 * will add opening and closing HTML form tags but NOT a submit button
38
+	 */
39
+	const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
40
+
41
+	/**
42
+	 * will NOT add opening and closing HTML form tags but will add a submit button
43
+	 */
44
+	const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
45
+
46
+	/**
47
+	 * will NOT add opening and closing HTML form tags NOR a submit button
48
+	 */
49
+	const DO_NOT_SETUP_FORM = 'do_not_setup_form';
50
+
51
+	/**
52
+	 * if set to false, then this form has no displayable content,
53
+	 * and will only be used for processing data sent passed via GET or POST
54
+	 * defaults to true ( ie: form has displayable content )
55
+	 *
56
+	 * @var boolean $displayable
57
+	 */
58
+	private $displayable = true;
59
+
60
+	/**
61
+	 * @var string $form_name
62
+	 */
63
+	private $form_name;
64
+
65
+	/**
66
+	 * @var string $admin_name
67
+	 */
68
+	private $admin_name;
69
+
70
+	/**
71
+	 * @var string $slug
72
+	 */
73
+	private $slug;
74
+
75
+	/**
76
+	 * @var string $submit_btn_text
77
+	 */
78
+	private $submit_btn_text;
79
+
80
+	/**
81
+	 * @var string $form_action
82
+	 */
83
+	private $form_action;
84
+
85
+	/**
86
+	 * form params in key value pairs
87
+	 * can be added to form action URL or as hidden inputs
88
+	 *
89
+	 * @var array $form_args
90
+	 */
91
+	private $form_args = array();
92
+
93
+	/**
94
+	 * value of one of the string constant above
95
+	 *
96
+	 * @var string $form_config
97
+	 */
98
+	private $form_config;
99
+
100
+	/**
101
+	 * whether or not the form was determined to be invalid
102
+	 *
103
+	 * @var boolean $form_has_errors
104
+	 */
105
+	private $form_has_errors;
106
+
107
+	/**
108
+	 * the absolute top level form section being used on the page
109
+	 *
110
+	 * @var EE_Form_Section_Proper $form
111
+	 */
112
+	private $form;
113
+
114
+	/**
115
+	 * @var EE_Registry $registry
116
+	 */
117
+	protected $registry;
118
+
119
+	// phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
120
+
121
+
122
+	/**
123
+	 * Form constructor.
124
+	 *
125
+	 * @param string           $form_name
126
+	 * @param string           $admin_name
127
+	 * @param string           $slug
128
+	 * @param string           $form_action
129
+	 * @param string           $form_config
130
+	 * @param EE_Registry|null $registry
131
+	 */
132
+	public function __construct(
133
+		$form_name,
134
+		$admin_name,
135
+		$slug,
136
+		$form_action = '',
137
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
138
+		EE_Registry $registry = null
139
+	) {
140
+		$this->setFormName($form_name);
141
+		$this->setAdminName($admin_name);
142
+		$this->setSlug($slug);
143
+		$this->setFormAction($form_action);
144
+		$this->setFormConfig($form_config);
145
+		$this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
146
+		$this->registry = $registry;
147
+	}
148
+
149
+
150
+	/**
151
+	 * @return array
152
+	 */
153
+	public static function getFormConfigConstants()
154
+	{
155
+		return array(
156
+			FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
157
+			FormHandler::ADD_FORM_TAGS_ONLY,
158
+			FormHandler::ADD_FORM_SUBMIT_ONLY,
159
+			FormHandler::DO_NOT_SETUP_FORM,
160
+		);
161
+	}
162
+
163
+
164
+	/**
165
+	 * @param bool $for_display
166
+	 * @return EE_Form_Section_Proper
167
+	 * @throws EE_Error
168
+	 * @throws LogicException
169
+	 */
170
+	public function form($for_display = false)
171
+	{
172
+		if (! $this->formIsValid()) {
173
+			return null;
174
+		}
175
+		if ($for_display) {
176
+			$form_config = $this->formConfig();
177
+			if (
178
+				$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
179
+				|| $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
180
+			) {
181
+				$this->appendSubmitButton();
182
+				$this->clearFormButtonFloats();
183
+			}
184
+		}
185
+		return $this->form;
186
+	}
187
+
188
+
189
+	/**
190
+	 * @return boolean
191
+	 * @throws LogicException
192
+	 */
193
+	public function formIsValid()
194
+	{
195
+		if ($this->form instanceof EE_Form_Section_Proper) {
196
+			return true;
197
+		}
198
+		$form = apply_filters(
199
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
200
+			$this->generate(),
201
+			$this
202
+		);
203
+		if ($this->verifyForm($form)) {
204
+			$this->setForm($form);
205
+		}
206
+		return true;
207
+	}
208
+
209
+
210
+	/**
211
+	 * @param EE_Form_Section_Proper|null $form
212
+	 * @return bool
213
+	 * @throws LogicException
214
+	 */
215
+	public function verifyForm(EE_Form_Section_Proper $form = null)
216
+	{
217
+		$form = $form !== null ? $form : $this->form;
218
+		if ($form instanceof EE_Form_Section_Proper) {
219
+			return true;
220
+		}
221
+		throw new LogicException(
222
+			sprintf(
223
+				esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
224
+				$this->form_name,
225
+				var_export($form, true)
226
+			)
227
+		);
228
+	}
229
+
230
+
231
+	/**
232
+	 * @param EE_Form_Section_Proper $form
233
+	 */
234
+	public function setForm(EE_Form_Section_Proper $form)
235
+	{
236
+		$this->form = $form;
237
+	}
238
+
239
+
240
+	/**
241
+	 * @return boolean
242
+	 */
243
+	public function displayable()
244
+	{
245
+		return $this->displayable;
246
+	}
247
+
248
+
249
+	/**
250
+	 * @param boolean $displayable
251
+	 */
252
+	public function setDisplayable($displayable = false)
253
+	{
254
+		$this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
255
+	}
256
+
257
+
258
+	/**
259
+	 * a public name for the form that can be displayed on the frontend of a site
260
+	 *
261
+	 * @return string
262
+	 */
263
+	public function formName()
264
+	{
265
+		return $this->form_name;
266
+	}
267
+
268
+
269
+	/**
270
+	 * @param string $form_name
271
+	 * @throws InvalidDataTypeException
272
+	 */
273
+	public function setFormName($form_name)
274
+	{
275
+		if (! is_string($form_name)) {
276
+			throw new InvalidDataTypeException('$form_name', $form_name, 'string');
277
+		}
278
+		$this->form_name = $form_name;
279
+	}
280
+
281
+
282
+	/**
283
+	 * a public name for the form that can be displayed, but only in the admin
284
+	 *
285
+	 * @return string
286
+	 */
287
+	public function adminName()
288
+	{
289
+		return $this->admin_name;
290
+	}
291
+
292
+
293
+	/**
294
+	 * @param string $admin_name
295
+	 * @throws InvalidDataTypeException
296
+	 */
297
+	public function setAdminName($admin_name)
298
+	{
299
+		if (! is_string($admin_name)) {
300
+			throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
301
+		}
302
+		$this->admin_name = $admin_name;
303
+	}
304
+
305
+
306
+	/**
307
+	 * a URL friendly string that can be used for identifying the form
308
+	 *
309
+	 * @return string
310
+	 */
311
+	public function slug()
312
+	{
313
+		return $this->slug;
314
+	}
315
+
316
+
317
+	/**
318
+	 * @param string $slug
319
+	 * @throws InvalidDataTypeException
320
+	 */
321
+	public function setSlug($slug)
322
+	{
323
+		if (! is_string($slug)) {
324
+			throw new InvalidDataTypeException('$slug', $slug, 'string');
325
+		}
326
+		$this->slug = $slug;
327
+	}
328
+
329
+
330
+	/**
331
+	 * @return string
332
+	 */
333
+	public function submitBtnText()
334
+	{
335
+		return $this->submit_btn_text;
336
+	}
337
+
338
+
339
+	/**
340
+	 * @param string $submit_btn_text
341
+	 * @throws InvalidDataTypeException
342
+	 * @throws InvalidArgumentException
343
+	 */
344
+	public function setSubmitBtnText($submit_btn_text)
345
+	{
346
+		if (! is_string($submit_btn_text)) {
347
+			throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
348
+		}
349
+		if (empty($submit_btn_text)) {
350
+			throw new InvalidArgumentException(
351
+				esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
352
+			);
353
+		}
354
+		$this->submit_btn_text = $submit_btn_text;
355
+	}
356
+
357
+
358
+	/**
359
+	 * @return string
360
+	 */
361
+	public function formAction()
362
+	{
363
+		return ! empty($this->form_args)
364
+			? add_query_arg($this->form_args, $this->form_action)
365
+			: $this->form_action;
366
+	}
367
+
368
+
369
+	/**
370
+	 * @param string $form_action
371
+	 * @throws InvalidDataTypeException
372
+	 */
373
+	public function setFormAction($form_action)
374
+	{
375
+		if (! is_string($form_action)) {
376
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
377
+		}
378
+		$this->form_action = $form_action;
379
+	}
380
+
381
+
382
+	/**
383
+	 * @param array $form_args
384
+	 * @throws InvalidDataTypeException
385
+	 * @throws InvalidArgumentException
386
+	 */
387
+	public function addFormActionArgs($form_args = array())
388
+	{
389
+		if (is_object($form_args)) {
390
+			throw new InvalidDataTypeException(
391
+				'$form_args',
392
+				$form_args,
393
+				'anything other than an object was expected.'
394
+			);
395
+		}
396
+		if (empty($form_args)) {
397
+			throw new InvalidArgumentException(
398
+				esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
399
+			);
400
+		}
401
+		$this->form_args = array_merge($this->form_args, $form_args);
402
+	}
403
+
404
+
405
+	/**
406
+	 * @return string
407
+	 */
408
+	public function formConfig()
409
+	{
410
+		return $this->form_config;
411
+	}
412
+
413
+
414
+	/**
415
+	 * @param string $form_config
416
+	 * @throws DomainException
417
+	 */
418
+	public function setFormConfig($form_config)
419
+	{
420
+		if (
421
+			! in_array(
422
+				$form_config,
423
+				array(
424
+				FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
425
+				FormHandler::ADD_FORM_TAGS_ONLY,
426
+				FormHandler::ADD_FORM_SUBMIT_ONLY,
427
+				FormHandler::DO_NOT_SETUP_FORM,
428
+				),
429
+				true
430
+			)
431
+		) {
432
+			throw new DomainException(
433
+				sprintf(
434
+					esc_html__(
435
+						'"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
436
+						'event_espresso'
437
+					),
438
+					$form_config
439
+				)
440
+			);
441
+		}
442
+		$this->form_config = $form_config;
443
+	}
444
+
445
+
446
+	/**
447
+	 * called after the form is instantiated
448
+	 * and used for performing any logic that needs to occur early
449
+	 * before any of the other methods are called.
450
+	 * returns true if everything is ok to proceed,
451
+	 * and false if no further form logic should be implemented
452
+	 *
453
+	 * @return boolean
454
+	 */
455
+	public function initialize()
456
+	{
457
+		$this->form_has_errors = EE_Error::has_error(true);
458
+		return true;
459
+	}
460
+
461
+
462
+	/**
463
+	 * used for setting up css and js
464
+	 *
465
+	 * @return void
466
+	 * @throws LogicException
467
+	 * @throws EE_Error
468
+	 */
469
+	public function enqueueStylesAndScripts()
470
+	{
471
+		$this->form()->enqueue_js();
472
+	}
473
+
474
+
475
+	/**
476
+	 * creates and returns the actual form
477
+	 *
478
+	 * @return EE_Form_Section_Proper
479
+	 */
480
+	abstract public function generate();
481
+
482
+
483
+	/**
484
+	 * creates and returns an EE_Submit_Input labeled "Submit"
485
+	 *
486
+	 * @param string $text
487
+	 * @return EE_Submit_Input
488
+	 */
489
+	public function generateSubmitButton($text = '')
490
+	{
491
+		$text = ! empty($text) ? $text : $this->submitBtnText();
492
+		return new EE_Submit_Input(
493
+			array(
494
+				'html_name'             => 'ee-form-submit-' . $this->slug(),
495
+				'html_id'               => 'ee-form-submit-' . $this->slug(),
496
+				'html_class'            => 'ee-form-submit',
497
+				'html_label'            => '&nbsp;',
498
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
499
+				'default'               => $text,
500
+			)
501
+		);
502
+	}
503
+
504
+
505
+	/**
506
+	 * calls generateSubmitButton() and appends it onto the form along with a float clearing div
507
+	 *
508
+	 * @param string $text
509
+	 * @return void
510
+	 * @throws EE_Error
511
+	 */
512
+	public function appendSubmitButton($text = '')
513
+	{
514
+		if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
515
+			return;
516
+		}
517
+		$this->form->add_subsections(
518
+			array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
519
+			null,
520
+			false
521
+		);
522
+	}
523
+
524
+
525
+	/**
526
+	 * creates and returns an EE_Submit_Input labeled "Cancel"
527
+	 *
528
+	 * @param string $text
529
+	 * @return EE_Submit_Input
530
+	 */
531
+	public function generateCancelButton($text = '')
532
+	{
533
+		$cancel_button = new EE_Submit_Input(
534
+			array(
535
+				'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
536
+				'html_id'               => 'ee-cancel-form-' . $this->slug(),
537
+				'html_class'            => 'ee-cancel-form',
538
+				'html_label'            => '&nbsp;',
539
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
540
+				'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
541
+			)
542
+		);
543
+		$cancel_button->set_button_css_attributes(false);
544
+		return $cancel_button;
545
+	}
546
+
547
+
548
+	/**
549
+	 * appends a float clearing div onto end of form
550
+	 *
551
+	 * @return void
552
+	 * @throws EE_Error
553
+	 */
554
+	public function clearFormButtonFloats()
555
+	{
556
+		$this->form->add_subsections(
557
+			array(
558
+				'clear-submit-btn-float' => new EE_Form_Section_HTML(
559
+					EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
560
+				),
561
+			),
562
+			null,
563
+			false
564
+		);
565
+	}
566
+
567
+
568
+	/**
569
+	 * takes the generated form and displays it along with ony other non-form HTML that may be required
570
+	 * returns a string of HTML that can be directly echoed in a template
571
+	 *
572
+	 * @return string
573
+	 * @throws \InvalidArgumentException
574
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
575
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
576
+	 * @throws LogicException
577
+	 * @throws EE_Error
578
+	 */
579
+	public function display()
580
+	{
581
+		$form_html = apply_filters(
582
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
583
+			''
584
+		);
585
+		$form_config = $this->formConfig();
586
+		if (
587
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
588
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
589
+		) {
590
+			$additional_props = $this->requiresMultipartEnctype()
591
+				? ' enctype="multipart/form-data"'
592
+				: '';
593
+			$form_html .= $this->form()->form_open(
594
+				$this->formAction(),
595
+				'POST',
596
+				$additional_props
597
+			);
598
+		}
599
+		$form_html .= $this->form(true)->get_html();
600
+		if (
601
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
602
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
603
+		) {
604
+			$form_html .= $this->form()->form_close();
605
+		}
606
+		$form_html .= apply_filters(
607
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
608
+			''
609
+		);
610
+		return $form_html;
611
+	}
612
+
613
+	/**
614
+	 * Determines if this form needs "enctype='multipart/form-data'" or not.
615
+	 * @since 4.9.80.p
616
+	 * @return bool
617
+	 * @throws EE_Error
618
+	 */
619
+	public function requiresMultipartEnctype()
620
+	{
621
+		foreach ($this->form()->inputs_in_subsections() as $input) {
622
+			if ($input instanceof EE_File_Input) {
623
+				return true;
624
+			}
625
+		}
626
+		return false;
627
+	}
628
+
629
+
630
+	/**
631
+	 * handles processing the form submission
632
+	 * returns true or false depending on whether the form was processed successfully or not
633
+	 *
634
+	 * @param array $submitted_form_data
635
+	 * @return array
636
+	 * @throws \InvalidArgumentException
637
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
638
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
639
+	 * @throws EE_Error
640
+	 * @throws LogicException
641
+	 * @throws InvalidFormSubmissionException
642
+	 */
643
+	public function process($submitted_form_data = array())
644
+	{
645
+		if (! $this->form()->was_submitted($submitted_form_data)) {
646
+			throw new InvalidFormSubmissionException($this->form_name);
647
+		}
648
+		$this->form(true)->receive_form_submission($submitted_form_data);
649
+		if (! $this->form()->is_valid()) {
650
+			throw new InvalidFormSubmissionException(
651
+				$this->form_name,
652
+				sprintf(
653
+					esc_html__(
654
+						'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
655
+						'event_espresso'
656
+					),
657
+					$this->form_name,
658
+					'<br />',
659
+					implode('<br />', $this->form()->get_validation_errors_accumulated())
660
+				)
661
+			);
662
+		}
663
+		return apply_filters(
664
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data',
665
+			$this->form()->valid_data(),
666
+			$this
667
+		);
668
+	}
669 669
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/SequentialStepForm.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
     public function setOrder($order)
114 114
     {
115 115
         $order = absint($order);
116
-        if (! $order > 0) {
116
+        if ( ! $order > 0) {
117 117
             throw new InvalidArgumentException(
118 118
                 esc_html__('The form order property must be a positive integer.', 'event_espresso')
119 119
             );
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
      */
143 143
     public function setRedirectUrl($redirect_url)
144 144
     {
145
-        if (! is_string($redirect_url)) {
145
+        if ( ! is_string($redirect_url)) {
146 146
             throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
147 147
         }
148 148
         if (empty($redirect_url)) {
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
             );
200 200
         }
201 201
         foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
202
-            unset($this->redirect_args[ $redirect_arg_key ]);
202
+            unset($this->redirect_args[$redirect_arg_key]);
203 203
         }
204 204
     }
205 205
 
Please login to merge, or discard this patch.
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -18,224 +18,224 @@
 block discarded – undo
18 18
  */
19 19
 abstract class SequentialStepForm extends FormHandler implements SequentialStepFormInterface
20 20
 {
21
-    const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
22
-
23
-    const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
24
-
25
-    const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
26
-
27
-    const REDIRECT_TO_OTHER        = 'redirect_to_other';
28
-
29
-    /**
30
-     * numerical value used for sorting form steps
31
-     *
32
-     * @var int $order
33
-     */
34
-    private $order = 1;
35
-
36
-    /**
37
-     * a final URL with all form related parameters added
38
-     * that will be used to advance to the next step
39
-     *
40
-     * @var string $redirect_url
41
-     */
42
-    private $redirect_url = '';
43
-
44
-    /**
45
-     * URL params in key value pairs
46
-     *
47
-     * @var array $redirect_args
48
-     */
49
-    private $redirect_args = array();
50
-
51
-    /**
52
-     * Which step should be redirected to after form processing.
53
-     * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
54
-     * If a form is invalid and requires errors to be corrected,
55
-     * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
56
-     * Some form handlers do not have a form that is displayable,
57
-     * and only perform data processing, but if an error occurs,
58
-     * then this value needs to be set to REDIRECT_TO_PREV_STEP
59
-     * since the current step has no displayable content.
60
-     * if the form is completely finished, and needs to redirect to somewhere
61
-     * completely different, then this value will be REDIRECT_TO_OTHER
62
-     *
63
-     * @var string $redirect_to
64
-     */
65
-    private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
66
-
67
-
68
-    /**
69
-     * SequentialStepForm constructor
70
-     *
71
-     * @param int              $order
72
-     * @param string           $form_name
73
-     * @param string           $admin_name
74
-     * @param string           $slug
75
-     * @param string           $form_action
76
-     * @param string           $form_config
77
-     * @param EE_Registry|null $registry
78
-     */
79
-    public function __construct(
80
-        $order,
81
-        $form_name,
82
-        $admin_name,
83
-        $slug,
84
-        $form_action = '',
85
-        $form_config = 'add_form_tags_and_submit',
86
-        EE_Registry $registry = null
87
-    ) {
88
-        $this->setOrder($order);
89
-        parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
90
-    }
91
-
92
-
93
-
94
-    /**
95
-     * @return int
96
-     */
97
-    public function order()
98
-    {
99
-        return $this->order;
100
-    }
101
-
102
-
103
-
104
-    /**
105
-     * @param int $order
106
-     * @throws InvalidArgumentException
107
-     */
108
-    public function setOrder($order)
109
-    {
110
-        $order = absint($order);
111
-        if (! $order > 0) {
112
-            throw new InvalidArgumentException(
113
-                esc_html__('The form order property must be a positive integer.', 'event_espresso')
114
-            );
115
-        }
116
-        $this->order = $order;
117
-    }
118
-
119
-
120
-
121
-    /**
122
-     * @return string
123
-     */
124
-    public function redirectUrl()
125
-    {
126
-        return ! empty($this->redirect_args)
127
-            ? add_query_arg($this->redirect_args, $this->redirect_url)
128
-            : $this->redirect_url;
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * @param string $redirect_url
135
-     * @throws InvalidDataTypeException
136
-     * @throws InvalidArgumentException
137
-     */
138
-    public function setRedirectUrl($redirect_url)
139
-    {
140
-        if (! is_string($redirect_url)) {
141
-            throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
142
-        }
143
-        if (empty($redirect_url)) {
144
-            throw new InvalidArgumentException(
145
-                esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
146
-            );
147
-        }
148
-        $this->redirect_url = $redirect_url;
149
-    }
150
-
151
-
152
-
153
-    /**
154
-     * @param array $redirect_args
155
-     * @throws InvalidDataTypeException
156
-     * @throws InvalidArgumentException
157
-     */
158
-    public function addRedirectArgs($redirect_args = array())
159
-    {
160
-        if (is_object($redirect_args)) {
161
-            throw new InvalidDataTypeException(
162
-                '$redirect_args',
163
-                $redirect_args,
164
-                'anything other than an object was expected.'
165
-            );
166
-        }
167
-        if (empty($redirect_args)) {
168
-            throw new InvalidArgumentException(
169
-                esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
170
-            );
171
-        }
172
-        $this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args);
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     * @param array $redirect_arg_keys_to_remove
179
-     * @throws InvalidDataTypeException
180
-     * @throws InvalidArgumentException
181
-     */
182
-    public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
183
-    {
184
-        if (is_object($redirect_arg_keys_to_remove)) {
185
-            throw new InvalidDataTypeException(
186
-                '$redirect_arg_keys_to_remove',
187
-                $redirect_arg_keys_to_remove,
188
-                'anything other than an object was expected.'
189
-            );
190
-        }
191
-        if (empty($redirect_arg_keys_to_remove)) {
192
-            throw new InvalidArgumentException(
193
-                esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
194
-            );
195
-        }
196
-        foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
197
-            unset($this->redirect_args[ $redirect_arg_key ]);
198
-        }
199
-    }
200
-
201
-
202
-
203
-    /**
204
-     * @return string
205
-     */
206
-    public function redirectTo()
207
-    {
208
-        return $this->redirect_to;
209
-    }
210
-
211
-
212
-
213
-    /**
214
-     * @param string $redirect_to
215
-     * @throws InvalidDataTypeException
216
-     */
217
-    public function setRedirectTo($redirect_to)
218
-    {
219
-        if (
220
-            ! in_array(
221
-                $redirect_to,
222
-                array(
223
-                    SequentialStepForm::REDIRECT_TO_NEXT_STEP,
224
-                    SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
225
-                    SequentialStepForm::REDIRECT_TO_PREV_STEP,
226
-                    SequentialStepForm::REDIRECT_TO_OTHER,
227
-                ),
228
-                true
229
-            )
230
-        ) {
231
-            throw new InvalidDataTypeException(
232
-                'setRedirectTo()',
233
-                $redirect_to,
234
-                'one of the SequentialStepForm class constants was expected.'
235
-            );
236
-        }
237
-        $this->redirect_to = $redirect_to;
238
-    }
21
+	const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
22
+
23
+	const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
24
+
25
+	const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
26
+
27
+	const REDIRECT_TO_OTHER        = 'redirect_to_other';
28
+
29
+	/**
30
+	 * numerical value used for sorting form steps
31
+	 *
32
+	 * @var int $order
33
+	 */
34
+	private $order = 1;
35
+
36
+	/**
37
+	 * a final URL with all form related parameters added
38
+	 * that will be used to advance to the next step
39
+	 *
40
+	 * @var string $redirect_url
41
+	 */
42
+	private $redirect_url = '';
43
+
44
+	/**
45
+	 * URL params in key value pairs
46
+	 *
47
+	 * @var array $redirect_args
48
+	 */
49
+	private $redirect_args = array();
50
+
51
+	/**
52
+	 * Which step should be redirected to after form processing.
53
+	 * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
54
+	 * If a form is invalid and requires errors to be corrected,
55
+	 * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
56
+	 * Some form handlers do not have a form that is displayable,
57
+	 * and only perform data processing, but if an error occurs,
58
+	 * then this value needs to be set to REDIRECT_TO_PREV_STEP
59
+	 * since the current step has no displayable content.
60
+	 * if the form is completely finished, and needs to redirect to somewhere
61
+	 * completely different, then this value will be REDIRECT_TO_OTHER
62
+	 *
63
+	 * @var string $redirect_to
64
+	 */
65
+	private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
66
+
67
+
68
+	/**
69
+	 * SequentialStepForm constructor
70
+	 *
71
+	 * @param int              $order
72
+	 * @param string           $form_name
73
+	 * @param string           $admin_name
74
+	 * @param string           $slug
75
+	 * @param string           $form_action
76
+	 * @param string           $form_config
77
+	 * @param EE_Registry|null $registry
78
+	 */
79
+	public function __construct(
80
+		$order,
81
+		$form_name,
82
+		$admin_name,
83
+		$slug,
84
+		$form_action = '',
85
+		$form_config = 'add_form_tags_and_submit',
86
+		EE_Registry $registry = null
87
+	) {
88
+		$this->setOrder($order);
89
+		parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
90
+	}
91
+
92
+
93
+
94
+	/**
95
+	 * @return int
96
+	 */
97
+	public function order()
98
+	{
99
+		return $this->order;
100
+	}
101
+
102
+
103
+
104
+	/**
105
+	 * @param int $order
106
+	 * @throws InvalidArgumentException
107
+	 */
108
+	public function setOrder($order)
109
+	{
110
+		$order = absint($order);
111
+		if (! $order > 0) {
112
+			throw new InvalidArgumentException(
113
+				esc_html__('The form order property must be a positive integer.', 'event_espresso')
114
+			);
115
+		}
116
+		$this->order = $order;
117
+	}
118
+
119
+
120
+
121
+	/**
122
+	 * @return string
123
+	 */
124
+	public function redirectUrl()
125
+	{
126
+		return ! empty($this->redirect_args)
127
+			? add_query_arg($this->redirect_args, $this->redirect_url)
128
+			: $this->redirect_url;
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * @param string $redirect_url
135
+	 * @throws InvalidDataTypeException
136
+	 * @throws InvalidArgumentException
137
+	 */
138
+	public function setRedirectUrl($redirect_url)
139
+	{
140
+		if (! is_string($redirect_url)) {
141
+			throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
142
+		}
143
+		if (empty($redirect_url)) {
144
+			throw new InvalidArgumentException(
145
+				esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
146
+			);
147
+		}
148
+		$this->redirect_url = $redirect_url;
149
+	}
150
+
151
+
152
+
153
+	/**
154
+	 * @param array $redirect_args
155
+	 * @throws InvalidDataTypeException
156
+	 * @throws InvalidArgumentException
157
+	 */
158
+	public function addRedirectArgs($redirect_args = array())
159
+	{
160
+		if (is_object($redirect_args)) {
161
+			throw new InvalidDataTypeException(
162
+				'$redirect_args',
163
+				$redirect_args,
164
+				'anything other than an object was expected.'
165
+			);
166
+		}
167
+		if (empty($redirect_args)) {
168
+			throw new InvalidArgumentException(
169
+				esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
170
+			);
171
+		}
172
+		$this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args);
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 * @param array $redirect_arg_keys_to_remove
179
+	 * @throws InvalidDataTypeException
180
+	 * @throws InvalidArgumentException
181
+	 */
182
+	public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
183
+	{
184
+		if (is_object($redirect_arg_keys_to_remove)) {
185
+			throw new InvalidDataTypeException(
186
+				'$redirect_arg_keys_to_remove',
187
+				$redirect_arg_keys_to_remove,
188
+				'anything other than an object was expected.'
189
+			);
190
+		}
191
+		if (empty($redirect_arg_keys_to_remove)) {
192
+			throw new InvalidArgumentException(
193
+				esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
194
+			);
195
+		}
196
+		foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
197
+			unset($this->redirect_args[ $redirect_arg_key ]);
198
+		}
199
+	}
200
+
201
+
202
+
203
+	/**
204
+	 * @return string
205
+	 */
206
+	public function redirectTo()
207
+	{
208
+		return $this->redirect_to;
209
+	}
210
+
211
+
212
+
213
+	/**
214
+	 * @param string $redirect_to
215
+	 * @throws InvalidDataTypeException
216
+	 */
217
+	public function setRedirectTo($redirect_to)
218
+	{
219
+		if (
220
+			! in_array(
221
+				$redirect_to,
222
+				array(
223
+					SequentialStepForm::REDIRECT_TO_NEXT_STEP,
224
+					SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
225
+					SequentialStepForm::REDIRECT_TO_PREV_STEP,
226
+					SequentialStepForm::REDIRECT_TO_OTHER,
227
+				),
228
+				true
229
+			)
230
+		) {
231
+			throw new InvalidDataTypeException(
232
+				'setRedirectTo()',
233
+				$redirect_to,
234
+				'one of the SequentialStepForm class constants was expected.'
235
+			);
236
+		}
237
+		$this->redirect_to = $redirect_to;
238
+	}
239 239
 }
240 240
 // End of file SequentialStepForm.php
241 241
 // Location: /SequentialStepForm.php
Please login to merge, or discard this patch.
line_item_filters/EE_Specific_Registrations_Line_Item_Filter.class.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
                 'LIN_code'
74 74
             );
75 75
             if ($line_item_code) {
76
-                if (! isset($this->_line_item_registrations[ $line_item_code ])) {
77
-                    $this->_line_item_registrations[ $line_item_code ] = array();
76
+                if ( ! isset($this->_line_item_registrations[$line_item_code])) {
77
+                    $this->_line_item_registrations[$line_item_code] = array();
78 78
                 }
79
-                $this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration;
79
+                $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
80 80
             }
81 81
         }
82 82
     }
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
     public function process(EEI_Line_Item $line_item)
94 94
     {
95 95
         $this->_adjust_line_item_quantity($line_item);
96
-        if (! $line_item->children()) {
96
+        if ( ! $line_item->children()) {
97 97
             return $line_item;
98 98
         }
99 99
         // the original running total (taking ALL tickets into account)
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
                 $child_line_item->set_total(
121 121
                     $running_total_of_children_under_consideration * $percent_of_running_total
122 122
                 );
123
-                if (! $child_line_item->is_percent()) {
123
+                if ( ! $child_line_item->is_percent()) {
124 124
                     $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
125 125
                 }
126 126
             } elseif (
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
             $quantity = 0;
178 178
             // if this ticket is billable at this moment, then we should have a positive quantity
179 179
             if (
180
-                isset($this->_line_item_registrations[ $line_item->code() ])
181
-                && is_array($this->_line_item_registrations[ $line_item->code() ])
180
+                isset($this->_line_item_registrations[$line_item->code()])
181
+                && is_array($this->_line_item_registrations[$line_item->code()])
182 182
             ) {
183 183
                 // set quantity based on number of open registrations for this ticket
184
-                foreach ($this->_line_item_registrations[ $line_item->code() ] as $registration) {
184
+                foreach ($this->_line_item_registrations[$line_item->code()] as $registration) {
185 185
                     if (
186 186
                         $registration instanceof EE_Registration
187 187
                     ) {
Please login to merge, or discard this patch.
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -12,186 +12,186 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Specific_Registrations_Line_Item_Filter extends EE_Line_Item_Filter_Base
14 14
 {
15
-    /**
16
-     * array of line item codes and their corresponding quantities for registrations
17
-     *
18
-     * @type array $_line_item_registrations
19
-     */
20
-    protected $_line_item_registrations = array();
15
+	/**
16
+	 * array of line item codes and their corresponding quantities for registrations
17
+	 *
18
+	 * @type array $_line_item_registrations
19
+	 */
20
+	protected $_line_item_registrations = array();
21 21
 
22
-    /**
23
-     * Just kept in case we want it someday. Currently unused
24
-     *
25
-     * @var EE_Registration[]
26
-     */
27
-    protected $_registrations = array();
22
+	/**
23
+	 * Just kept in case we want it someday. Currently unused
24
+	 *
25
+	 * @var EE_Registration[]
26
+	 */
27
+	protected $_registrations = array();
28 28
 
29
-    /**
30
-     * @var EE_Registration
31
-     */
32
-    protected $_current_registration;
29
+	/**
30
+	 * @var EE_Registration
31
+	 */
32
+	protected $_current_registration;
33 33
 
34
-    /**
35
-     * these reg statuses should NOT increment the line item quantity
36
-     *
37
-     * @var array
38
-     */
39
-    protected $_closed_reg_statuses = array();
34
+	/**
35
+	 * these reg statuses should NOT increment the line item quantity
36
+	 *
37
+	 * @var array
38
+	 */
39
+	protected $_closed_reg_statuses = array();
40 40
 
41 41
 
42
-    /**
43
-     * EE_Billable_Line_Item_Filter constructor.
44
-     *
45
-     * @param EE_Registration[] $registrations
46
-     * @throws EE_Error
47
-     */
48
-    public function __construct($registrations)
49
-    {
50
-        $this->_registrations = $registrations;
51
-        $this->_calculate_registrations_per_line_item_code($registrations);
52
-        // these reg statuses should NOT increment the line item quantity
53
-        $this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
54
-    }
42
+	/**
43
+	 * EE_Billable_Line_Item_Filter constructor.
44
+	 *
45
+	 * @param EE_Registration[] $registrations
46
+	 * @throws EE_Error
47
+	 */
48
+	public function __construct($registrations)
49
+	{
50
+		$this->_registrations = $registrations;
51
+		$this->_calculate_registrations_per_line_item_code($registrations);
52
+		// these reg statuses should NOT increment the line item quantity
53
+		$this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
54
+	}
55 55
 
56 56
 
57
-    /**
58
-     * sets the _line_item_registrations from the provided registrations
59
-     *
60
-     * @param EE_Registration[] $registrations
61
-     * @return void
62
-     * @throws EE_Error
63
-     */
64
-    protected function _calculate_registrations_per_line_item_code($registrations)
65
-    {
66
-        foreach ($registrations as $registration) {
67
-            $line_item_code = EEM_Line_Item::instance()->get_var(
68
-                EEM_Line_Item::instance()->line_item_for_registration_query_params(
69
-                    $registration,
70
-                    array('limit' => 1)
71
-                ),
72
-                'LIN_code'
73
-            );
74
-            if ($line_item_code) {
75
-                if (! isset($this->_line_item_registrations[ $line_item_code ])) {
76
-                    $this->_line_item_registrations[ $line_item_code ] = array();
77
-                }
78
-                $this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration;
79
-            }
80
-        }
81
-    }
57
+	/**
58
+	 * sets the _line_item_registrations from the provided registrations
59
+	 *
60
+	 * @param EE_Registration[] $registrations
61
+	 * @return void
62
+	 * @throws EE_Error
63
+	 */
64
+	protected function _calculate_registrations_per_line_item_code($registrations)
65
+	{
66
+		foreach ($registrations as $registration) {
67
+			$line_item_code = EEM_Line_Item::instance()->get_var(
68
+				EEM_Line_Item::instance()->line_item_for_registration_query_params(
69
+					$registration,
70
+					array('limit' => 1)
71
+				),
72
+				'LIN_code'
73
+			);
74
+			if ($line_item_code) {
75
+				if (! isset($this->_line_item_registrations[ $line_item_code ])) {
76
+					$this->_line_item_registrations[ $line_item_code ] = array();
77
+				}
78
+				$this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration;
79
+			}
80
+		}
81
+	}
82 82
 
83 83
 
84
-    /**
85
-     * Creates a duplicate of the line item tree, except only includes billable items
86
-     * and the portion of line items attributed to billable things
87
-     *
88
-     * @param EEI_Line_Item $line_item
89
-     * @return EEI_Line_Item
90
-     * @throws EE_Error
91
-     */
92
-    public function process(EEI_Line_Item $line_item)
93
-    {
94
-        $this->_adjust_line_item_quantity($line_item);
95
-        if (! $line_item->children()) {
96
-            return $line_item;
97
-        }
98
-        // the original running total (taking ALL tickets into account)
99
-        $running_total_of_children = 0;
100
-        // the new running total (only taking the specified ticket quantities into account)
101
-        $running_total_of_children_under_consideration = 0;
102
-        // let's also track the quantity of tickets that pertain to the registrations
103
-        $total_child_ticket_quantity = 0;
104
-        foreach ($line_item->children() as $child_line_item) {
105
-            $original_li_total = $child_line_item->is_percent()
106
-                ? $running_total_of_children * $child_line_item->percent() / 100
107
-                : $child_line_item->unit_price() * $child_line_item->quantity();
108
-            $this->process($child_line_item);
109
-            // If this line item is a normal line item that isn't for a ticket,
110
-            // we want to modify its total (and unit price if not a percentage line item)
111
-            // so it reflects only that portion of the surcharge/discount shared by these registrations
112
-            if (
113
-                $child_line_item->type() === EEM_Line_Item::type_line_item
114
-                && $child_line_item->OBJ_type() !== 'Ticket'
115
-            ) {
116
-                $percent_of_running_total = $running_total_of_children
117
-                    ? $original_li_total / $running_total_of_children
118
-                    : 0;
119
-                $child_line_item->set_total(
120
-                    $running_total_of_children_under_consideration * $percent_of_running_total
121
-                );
122
-                if (! $child_line_item->is_percent()) {
123
-                    $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
124
-                }
125
-            } elseif (
84
+	/**
85
+	 * Creates a duplicate of the line item tree, except only includes billable items
86
+	 * and the portion of line items attributed to billable things
87
+	 *
88
+	 * @param EEI_Line_Item $line_item
89
+	 * @return EEI_Line_Item
90
+	 * @throws EE_Error
91
+	 */
92
+	public function process(EEI_Line_Item $line_item)
93
+	{
94
+		$this->_adjust_line_item_quantity($line_item);
95
+		if (! $line_item->children()) {
96
+			return $line_item;
97
+		}
98
+		// the original running total (taking ALL tickets into account)
99
+		$running_total_of_children = 0;
100
+		// the new running total (only taking the specified ticket quantities into account)
101
+		$running_total_of_children_under_consideration = 0;
102
+		// let's also track the quantity of tickets that pertain to the registrations
103
+		$total_child_ticket_quantity = 0;
104
+		foreach ($line_item->children() as $child_line_item) {
105
+			$original_li_total = $child_line_item->is_percent()
106
+				? $running_total_of_children * $child_line_item->percent() / 100
107
+				: $child_line_item->unit_price() * $child_line_item->quantity();
108
+			$this->process($child_line_item);
109
+			// If this line item is a normal line item that isn't for a ticket,
110
+			// we want to modify its total (and unit price if not a percentage line item)
111
+			// so it reflects only that portion of the surcharge/discount shared by these registrations
112
+			if (
113
+				$child_line_item->type() === EEM_Line_Item::type_line_item
114
+				&& $child_line_item->OBJ_type() !== 'Ticket'
115
+			) {
116
+				$percent_of_running_total = $running_total_of_children
117
+					? $original_li_total / $running_total_of_children
118
+					: 0;
119
+				$child_line_item->set_total(
120
+					$running_total_of_children_under_consideration * $percent_of_running_total
121
+				);
122
+				if (! $child_line_item->is_percent()) {
123
+					$child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
124
+				}
125
+			} elseif (
126 126
 // make sure this item's quantity and total matches its parent
127
-                $line_item->type() === EEM_Line_Item::type_line_item
128
-                && $line_item->OBJ_type() === 'Ticket'
129
-                // but not if it's a percentage modifier
130
-                && ! $child_line_item->is_percent()
131
-                && ! (
132
-                    // or a cancellation
133
-                    $child_line_item->is_cancelled()
134
-                    && ! (
135
-                        // unless it IS a cancellation and the current registration is cancelled
136
-                        $child_line_item->is_cancelled()
137
-                        && $this->_current_registration instanceof EE_Registration
138
-                        && in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
139
-                    )
140
-                )
141
-            ) {
142
-                $child_line_item->set_quantity($line_item->quantity());
143
-                $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
144
-            }
145
-            $running_total_of_children += $original_li_total;
146
-            $running_total_of_children_under_consideration += $child_line_item->total();
147
-            if ($child_line_item->OBJ_type() === 'Ticket') {
148
-                $total_child_ticket_quantity += $child_line_item->quantity();
149
-            }
150
-        }
151
-        $line_item->set_total($running_total_of_children_under_consideration);
152
-        if ($line_item->quantity()) {
153
-            $line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
154
-        } else {
155
-            $line_item->set_unit_price(0);
156
-        }
157
-        if ($line_item->OBJ_type() === 'Event') {
158
-            $line_item->set_quantity($total_child_ticket_quantity);
159
-        }
160
-        return $line_item;
161
-    }
127
+				$line_item->type() === EEM_Line_Item::type_line_item
128
+				&& $line_item->OBJ_type() === 'Ticket'
129
+				// but not if it's a percentage modifier
130
+				&& ! $child_line_item->is_percent()
131
+				&& ! (
132
+					// or a cancellation
133
+					$child_line_item->is_cancelled()
134
+					&& ! (
135
+						// unless it IS a cancellation and the current registration is cancelled
136
+						$child_line_item->is_cancelled()
137
+						&& $this->_current_registration instanceof EE_Registration
138
+						&& in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
139
+					)
140
+				)
141
+			) {
142
+				$child_line_item->set_quantity($line_item->quantity());
143
+				$child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
144
+			}
145
+			$running_total_of_children += $original_li_total;
146
+			$running_total_of_children_under_consideration += $child_line_item->total();
147
+			if ($child_line_item->OBJ_type() === 'Ticket') {
148
+				$total_child_ticket_quantity += $child_line_item->quantity();
149
+			}
150
+		}
151
+		$line_item->set_total($running_total_of_children_under_consideration);
152
+		if ($line_item->quantity()) {
153
+			$line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
154
+		} else {
155
+			$line_item->set_unit_price(0);
156
+		}
157
+		if ($line_item->OBJ_type() === 'Event') {
158
+			$line_item->set_quantity($total_child_ticket_quantity);
159
+		}
160
+		return $line_item;
161
+	}
162 162
 
163 163
 
164
-    /**
165
-     * Adjusts quantities for line items for tickets according to the registrations provided
166
-     * in the constructor
167
-     *
168
-     * @param EEI_Line_Item $line_item
169
-     * @return EEI_Line_Item
170
-     */
171
-    protected function _adjust_line_item_quantity(EEI_Line_Item $line_item)
172
-    {
173
-        // is this a ticket ?
174
-        if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
175
-            $this->_current_registration = null;
176
-            $quantity = 0;
177
-            // if this ticket is billable at this moment, then we should have a positive quantity
178
-            if (
179
-                isset($this->_line_item_registrations[ $line_item->code() ])
180
-                && is_array($this->_line_item_registrations[ $line_item->code() ])
181
-            ) {
182
-                // set quantity based on number of open registrations for this ticket
183
-                foreach ($this->_line_item_registrations[ $line_item->code() ] as $registration) {
184
-                    if (
185
-                        $registration instanceof EE_Registration
186
-                    ) {
187
-                        $quantity++;
188
-                        $this->_current_registration = $registration;
189
-                    }
190
-                }
191
-            }
192
-            $line_item->set_quantity($quantity);
193
-            $line_item->set_total($line_item->unit_price() * $line_item->quantity());
194
-        }
195
-        return $line_item;
196
-    }
164
+	/**
165
+	 * Adjusts quantities for line items for tickets according to the registrations provided
166
+	 * in the constructor
167
+	 *
168
+	 * @param EEI_Line_Item $line_item
169
+	 * @return EEI_Line_Item
170
+	 */
171
+	protected function _adjust_line_item_quantity(EEI_Line_Item $line_item)
172
+	{
173
+		// is this a ticket ?
174
+		if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
175
+			$this->_current_registration = null;
176
+			$quantity = 0;
177
+			// if this ticket is billable at this moment, then we should have a positive quantity
178
+			if (
179
+				isset($this->_line_item_registrations[ $line_item->code() ])
180
+				&& is_array($this->_line_item_registrations[ $line_item->code() ])
181
+			) {
182
+				// set quantity based on number of open registrations for this ticket
183
+				foreach ($this->_line_item_registrations[ $line_item->code() ] as $registration) {
184
+					if (
185
+						$registration instanceof EE_Registration
186
+					) {
187
+						$quantity++;
188
+						$this->_current_registration = $registration;
189
+					}
190
+				}
191
+			}
192
+			$line_item->set_quantity($quantity);
193
+			$line_item->set_total($line_item->unit_price() * $line_item->quantity());
194
+		}
195
+		return $line_item;
196
+	}
197 197
 }
Please login to merge, or discard this patch.