Completed
Pull Request — master (#952)
by
unknown
32:13
created
core/db_models/fields/EE_Money_Field.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
      * @param string $table_column
12 12
      * @param string $nicename
13 13
      * @param bool   $nullable
14
-     * @param null   $default_value
14
+     * @param integer   $default_value
15 15
      */
16 16
     public function __construct($table_column, $nicename, $nullable, $default_value = null, $whole_pennies_only = true)
17 17
     {
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         // now it's a float-style string or number
63 63
         $float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object);
64 64
         // round to the correctly number of decimal places for this  currency
65
-        return $this->_round_if_no_partial_pennies( $float_val );
65
+        return $this->_round_if_no_partial_pennies($float_val);
66 66
     }
67 67
 
68 68
     public function prepare_for_get($value_of_field_on_model_object)
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
      * @param type $amount 
107 107
      * @return float 
108 108
      */ 
109
-    protected function _round_if_no_partial_pennies( $amount )
109
+    protected function _round_if_no_partial_pennies($amount)
110 110
     { 
111
-        if($this->whole_pennies_only()) { 
111
+        if ($this->whole_pennies_only()) { 
112 112
             return EEH_Money::round_for_currency($amount, EE_Registry::instance()->CFG->currency->code); 
113 113
         } else { 
114 114
             return $amount; 
Please login to merge, or discard this patch.
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -6,119 +6,119 @@
 block discarded – undo
6 6
  */
7 7
 class EE_Money_Field extends EE_Float_Field
8 8
 {
9
-    protected $_whole_pennies_only;   
10
-    /**
11
-     * @param string $table_column
12
-     * @param string $nicename
13
-     * @param bool   $nullable
14
-     * @param null   $default_value
15
-     */
16
-    public function __construct($table_column, $nicename, $nullable, $default_value = null, $whole_pennies_only = true)
17
-    {
18
-        $this->_whole_pennies_only = $whole_pennies_only;
19
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
20
-        $this->setSchemaType('object');
21
-    }
9
+	protected $_whole_pennies_only;   
10
+	/**
11
+	 * @param string $table_column
12
+	 * @param string $nicename
13
+	 * @param bool   $nullable
14
+	 * @param null   $default_value
15
+	 */
16
+	public function __construct($table_column, $nicename, $nullable, $default_value = null, $whole_pennies_only = true)
17
+	{
18
+		$this->_whole_pennies_only = $whole_pennies_only;
19
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
20
+		$this->setSchemaType('object');
21
+	}
22 22
 
23 23
 
24
-    /**
25
-     * Schemas:
26
-     *    'localized_float': "3,023.00"
27
-     *    'no_currency_code': "$3,023.00"
28
-     *    null: "$3,023.00<span>USD</span>"
29
-     *
30
-     * @param string $value_on_field_to_be_outputted
31
-     * @param string $schema
32
-     * @return string
33
-     */
34
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
35
-    {
36
-        $pretty_float = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted);
24
+	/**
25
+	 * Schemas:
26
+	 *    'localized_float': "3,023.00"
27
+	 *    'no_currency_code': "$3,023.00"
28
+	 *    null: "$3,023.00<span>USD</span>"
29
+	 *
30
+	 * @param string $value_on_field_to_be_outputted
31
+	 * @param string $schema
32
+	 * @return string
33
+	 */
34
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
35
+	{
36
+		$pretty_float = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted);
37 37
 
38
-        if ($schema == 'localized_float') {
39
-            return $pretty_float;
40
-        }
41
-        if ($schema == 'no_currency_code') {
38
+		if ($schema == 'localized_float') {
39
+			return $pretty_float;
40
+		}
41
+		if ($schema == 'no_currency_code') {
42 42
 //          echo "schema no currency!";
43
-            $display_code = false;
44
-        } else {
45
-            $display_code = true;
46
-        }
47
-        // we don't use the $pretty_float because format_currency will take care of it.
48
-        return EEH_Template::format_currency(
49
-            $value_on_field_to_be_outputted,
50
-            false,
51
-            $display_code,
52
-            '',
53
-            'currency-code',
54
-            ! $this->_whole_pennies_only
55
-        );
56
-    }
43
+			$display_code = false;
44
+		} else {
45
+			$display_code = true;
46
+		}
47
+		// we don't use the $pretty_float because format_currency will take care of it.
48
+		return EEH_Template::format_currency(
49
+			$value_on_field_to_be_outputted,
50
+			false,
51
+			$display_code,
52
+			'',
53
+			'currency-code',
54
+			! $this->_whole_pennies_only
55
+		);
56
+	}
57 57
 
58
-    /**
59
-     * If provided with a string, strips out money-related formatting to turn it into a proper float.
60
-     * Rounds the float to the correct number of decimal places for this country's currency.
61
-     * Also, interprets periods and commas according to the country's currency settings.
62
-     * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
63
-     *
64
-     * @param string $value_inputted_for_field_on_model_object
65
-     * @return float
66
-     */
67
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
68
-    {
69
-        // now it's a float-style string or number
70
-        $float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object);
71
-        // round to the correctly number of decimal places for this  currency
72
-        return $this->_round_if_no_partial_pennies( $float_val );
73
-    }
58
+	/**
59
+	 * If provided with a string, strips out money-related formatting to turn it into a proper float.
60
+	 * Rounds the float to the correct number of decimal places for this country's currency.
61
+	 * Also, interprets periods and commas according to the country's currency settings.
62
+	 * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
63
+	 *
64
+	 * @param string $value_inputted_for_field_on_model_object
65
+	 * @return float
66
+	 */
67
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
68
+	{
69
+		// now it's a float-style string or number
70
+		$float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object);
71
+		// round to the correctly number of decimal places for this  currency
72
+		return $this->_round_if_no_partial_pennies( $float_val );
73
+	}
74 74
 
75
-    public function prepare_for_get($value_of_field_on_model_object)
76
-    {
77
-        return $this->_round_if_no_partial_pennies(parent::prepare_for_get($value_of_field_on_model_object));
78
-    }
75
+	public function prepare_for_get($value_of_field_on_model_object)
76
+	{
77
+		return $this->_round_if_no_partial_pennies(parent::prepare_for_get($value_of_field_on_model_object));
78
+	}
79 79
 
80
-    public function getSchemaProperties()
81
-    {
82
-        return array(
83
-            'raw' => array(
84
-                'description' =>  sprintf(
85
-                    __('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'),
86
-                    $this->get_nicename()
87
-                ),
88
-                'type' => 'number',
89
-            ),
90
-            'pretty' => array(
91
-                'description' =>  sprintf(
92
-                    __('%s - formatted for display in the set currency and decimal places.', 'event_espresso'),
93
-                    $this->get_nicename()
94
-                ),
95
-                'type' => 'string',
96
-                'format' => 'money'
97
-            )
98
-        );
99
-    }
80
+	public function getSchemaProperties()
81
+	{
82
+		return array(
83
+			'raw' => array(
84
+				'description' =>  sprintf(
85
+					__('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'),
86
+					$this->get_nicename()
87
+				),
88
+				'type' => 'number',
89
+			),
90
+			'pretty' => array(
91
+				'description' =>  sprintf(
92
+					__('%s - formatted for display in the set currency and decimal places.', 'event_espresso'),
93
+					$this->get_nicename()
94
+				),
95
+				'type' => 'string',
96
+				'format' => 'money'
97
+			)
98
+		);
99
+	}
100 100
 
101
-    /** 
102
-     * Returns whether or not this money field allows partial penny amounts 
103
-     * @return boolean 
104
-     */ 
105
-    public function whole_pennies_only()
106
-    {
107
-        return $this->_whole_pennies_only;
108
-    }
101
+	/** 
102
+	 * Returns whether or not this money field allows partial penny amounts 
103
+	 * @return boolean 
104
+	 */ 
105
+	public function whole_pennies_only()
106
+	{
107
+		return $this->_whole_pennies_only;
108
+	}
109 109
 
110
-    /** 
111
-     * If partial pennies allowed, leaves the amount as-is; if not, rounds it according 
112
-     * to the site's currency 
113
-     * @param type $amount 
114
-     * @return float 
115
-     */ 
116
-    protected function _round_if_no_partial_pennies( $amount )
117
-    { 
118
-        if($this->whole_pennies_only()) { 
119
-            return EEH_Money::round_for_currency($amount, EE_Registry::instance()->CFG->currency->code); 
120
-        } else { 
121
-            return $amount; 
122
-        } 
123
-    }
110
+	/** 
111
+	 * If partial pennies allowed, leaves the amount as-is; if not, rounds it according 
112
+	 * to the site's currency 
113
+	 * @param type $amount 
114
+	 * @return float 
115
+	 */ 
116
+	protected function _round_if_no_partial_pennies( $amount )
117
+	{ 
118
+		if($this->whole_pennies_only()) { 
119
+			return EEH_Money::round_for_currency($amount, EE_Registry::instance()->CFG->currency->code); 
120
+		} else { 
121
+			return $amount; 
122
+		} 
123
+	}
124 124
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_DMS_Core_4_9_0.dms.php 1 patch
Indentation   +291 added lines, -291 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@  discard block
 block discarded – undo
12 12
 $stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*');
13 13
 $class_to_filepath = array();
14 14
 foreach ($stages as $filepath) {
15
-    $matches = array();
16
-    preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches);
17
-    $class_to_filepath[ $matches[1] ] = $filepath;
15
+	$matches = array();
16
+	preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches);
17
+	$class_to_filepath[ $matches[1] ] = $filepath;
18 18
 }
19 19
 // give addons a chance to autoload their stages too
20 20
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath);
@@ -33,68 +33,68 @@  discard block
 block discarded – undo
33 33
 class EE_DMS_Core_4_9_0 extends EE_Data_Migration_Script_Base
34 34
 {
35 35
 
36
-    /**
37
-     * return EE_DMS_Core_4_9_0
38
-     *
39
-     * @param TableManager  $table_manager
40
-     * @param TableAnalysis $table_analysis
41
-     */
42
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
-    {
44
-        $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso");
45
-        $this->_priority = 10;
46
-        $this->_migration_stages = array(
47
-            new EE_DMS_4_9_0_Email_System_Question(),
48
-            new EE_DMS_4_9_0_Answers_With_No_Registration(),
49
-        );
50
-        parent::__construct($table_manager, $table_analysis);
51
-    }
36
+	/**
37
+	 * return EE_DMS_Core_4_9_0
38
+	 *
39
+	 * @param TableManager  $table_manager
40
+	 * @param TableAnalysis $table_analysis
41
+	 */
42
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
+	{
44
+		$this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso");
45
+		$this->_priority = 10;
46
+		$this->_migration_stages = array(
47
+			new EE_DMS_4_9_0_Email_System_Question(),
48
+			new EE_DMS_4_9_0_Answers_With_No_Registration(),
49
+		);
50
+		parent::__construct($table_manager, $table_analysis);
51
+	}
52 52
 
53 53
 
54 54
 
55
-    /**
56
-     * Whether to migrate or not.
57
-     *
58
-     * @param array $version_array
59
-     * @return bool
60
-     */
61
-    public function can_migrate_from_version($version_array)
62
-    {
63
-        $version_string = $version_array['Core'];
64
-        if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) {
65
-            //          echo "$version_string can be migrated from";
66
-            return true;
67
-        } elseif (! $version_string) {
68
-            //          echo "no version string provided: $version_string";
69
-            // no version string provided... this must be pre 4.3
70
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
71
-        } else {
72
-            //          echo "$version_string doesnt apply";
73
-            return false;
74
-        }
75
-    }
55
+	/**
56
+	 * Whether to migrate or not.
57
+	 *
58
+	 * @param array $version_array
59
+	 * @return bool
60
+	 */
61
+	public function can_migrate_from_version($version_array)
62
+	{
63
+		$version_string = $version_array['Core'];
64
+		if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) {
65
+			//          echo "$version_string can be migrated from";
66
+			return true;
67
+		} elseif (! $version_string) {
68
+			//          echo "no version string provided: $version_string";
69
+			// no version string provided... this must be pre 4.3
70
+			return false;// changed mind. dont want people thinking they should migrate yet because they cant
71
+		} else {
72
+			//          echo "$version_string doesnt apply";
73
+			return false;
74
+		}
75
+	}
76 76
 
77 77
 
78 78
 
79
-    /**
80
-     * @return bool
81
-     */
82
-    public function schema_changes_before_migration()
83
-    {
84
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
-        $now_in_mysql = current_time('mysql', true);
86
-        $table_name = 'esp_answer';
87
-        $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
79
+	/**
80
+	 * @return bool
81
+	 */
82
+	public function schema_changes_before_migration()
83
+	{
84
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
+		$now_in_mysql = current_time('mysql', true);
86
+		$table_name = 'esp_answer';
87
+		$sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
88 88
 					REG_ID int(10) unsigned NOT NULL,
89 89
 					QST_ID int(10) unsigned NOT NULL,
90 90
 					ANS_value text NOT NULL,
91 91
 					PRIMARY KEY  (ANS_ID),
92 92
 					KEY REG_ID (REG_ID),
93 93
 					KEY QST_ID (QST_ID)";
94
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
95
-        $table_name = 'esp_attendee_meta';
96
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email');
97
-        $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
94
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
95
+		$table_name = 'esp_attendee_meta';
96
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email');
97
+		$sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
98 98
 				ATT_ID bigint(20) unsigned NOT NULL,
99 99
 				ATT_fname varchar(45) NOT NULL,
100 100
 				ATT_lname varchar(45) NOT NULL,
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 				KEY ATT_email (ATT_email(191)),
112 112
 				KEY ATT_lname (ATT_lname),
113 113
 				KEY ATT_fname (ATT_fname)";
114
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
115
-        $table_name = 'esp_checkin';
116
-        $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
114
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
115
+		$table_name = 'esp_checkin';
116
+		$sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
117 117
 				REG_ID int(10) unsigned NOT NULL,
118 118
 				DTT_ID int(10) unsigned NOT NULL,
119 119
 				CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 				PRIMARY KEY  (CHK_ID),
122 122
 				KEY REG_ID (REG_ID),
123 123
 				KEY DTT_ID (DTT_ID)";
124
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
125
-        $table_name = 'esp_country';
126
-        $sql = "CNT_ISO varchar(2) NOT NULL,
124
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
125
+		$table_name = 'esp_country';
126
+		$sql = "CNT_ISO varchar(2) NOT NULL,
127 127
 				CNT_ISO3 varchar(3) NOT NULL,
128 128
 				RGN_ID tinyint(3) unsigned DEFAULT NULL,
129 129
 				CNT_name varchar(45) NOT NULL,
@@ -139,29 +139,29 @@  discard block
 block discarded – undo
139 139
 				CNT_is_EU tinyint(1) DEFAULT '0',
140 140
 				CNT_active tinyint(1) DEFAULT '0',
141 141
 				PRIMARY KEY  (CNT_ISO)";
142
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
143
-        $table_name = 'esp_currency';
144
-        $sql = "CUR_code varchar(6) NOT NULL,
142
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
143
+		$table_name = 'esp_currency';
144
+		$sql = "CUR_code varchar(6) NOT NULL,
145 145
 				CUR_single varchar(45) DEFAULT 'dollar',
146 146
 				CUR_plural varchar(45) DEFAULT 'dollars',
147 147
 				CUR_sign varchar(45) DEFAULT '$',
148 148
 				CUR_dec_plc varchar(1) NOT NULL DEFAULT '2',
149 149
 				CUR_active tinyint(1) DEFAULT '0',
150 150
 				PRIMARY KEY  (CUR_code)";
151
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
152
-        // note: although this table is no longer in use,
153
-        // it hasn't been removed because then queries to the model will have errors.
154
-        // but you should expect this table and its corresponding model to be removed in
155
-        // the next few months
156
-        $table_name = 'esp_currency_payment_method';
157
-        $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT,
151
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
152
+		// note: although this table is no longer in use,
153
+		// it hasn't been removed because then queries to the model will have errors.
154
+		// but you should expect this table and its corresponding model to be removed in
155
+		// the next few months
156
+		$table_name = 'esp_currency_payment_method';
157
+		$sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT,
158 158
 				CUR_code varchar(6) NOT NULL,
159 159
 				PMD_ID int(11) NOT NULL,
160 160
 				PRIMARY KEY  (CPM_ID),
161 161
 				KEY PMD_ID (PMD_ID)";
162
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
163
-        $table_name = 'esp_datetime';
164
-        $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
162
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
163
+		$table_name = 'esp_datetime';
164
+		$sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
165 165
 				EVT_ID bigint(20) unsigned NOT NULL,
166 166
 				DTT_name varchar(255) NOT NULL DEFAULT '',
167 167
 				DTT_description text NOT NULL,
@@ -178,25 +178,25 @@  discard block
 block discarded – undo
178 178
 				KEY DTT_EVT_start (DTT_EVT_start),
179 179
 				KEY EVT_ID (EVT_ID),
180 180
 				KEY DTT_is_primary (DTT_is_primary)";
181
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
182
-        $table_name = "esp_datetime_ticket";
183
-        $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
181
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
182
+		$table_name = "esp_datetime_ticket";
183
+		$sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
184 184
 				DTT_ID int(10) unsigned NOT NULL,
185 185
 				TKT_ID int(10) unsigned NOT NULL,
186 186
 				PRIMARY KEY  (DTK_ID),
187 187
 				KEY DTT_ID (DTT_ID),
188 188
 				KEY TKT_ID (TKT_ID)";
189
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
190
-        $table_name = 'esp_event_message_template';
191
-        $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
189
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
190
+		$table_name = 'esp_event_message_template';
191
+		$sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
192 192
 				EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0,
193 193
 				GRP_ID int(10) unsigned NOT NULL DEFAULT 0,
194 194
 				PRIMARY KEY  (EMT_ID),
195 195
 				KEY EVT_ID (EVT_ID),
196 196
 				KEY GRP_ID (GRP_ID)";
197
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
198
-        $table_name = 'esp_event_meta';
199
-        $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
197
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
198
+		$table_name = 'esp_event_meta';
199
+		$sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
200 200
 				EVT_ID bigint(20) unsigned NOT NULL,
201 201
 				EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1,
202 202
 				EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -211,34 +211,34 @@  discard block
 block discarded – undo
211 211
 				EVT_donations tinyint(1) NULL,
212 212
 				PRIMARY KEY  (EVTM_ID),
213 213
 				KEY EVT_ID (EVT_ID)";
214
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
215
-        $table_name = 'esp_event_question_group';
216
-        $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
214
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
215
+		$table_name = 'esp_event_question_group';
216
+		$sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
217 217
 				EVT_ID bigint(20) unsigned NOT NULL,
218 218
 				QSG_ID int(10) unsigned NOT NULL,
219 219
 				EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
220 220
 				PRIMARY KEY  (EQG_ID),
221 221
 				KEY EVT_ID (EVT_ID),
222 222
 				KEY QSG_ID (QSG_ID)";
223
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
224
-        $table_name = 'esp_event_venue';
225
-        $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
223
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
224
+		$table_name = 'esp_event_venue';
225
+		$sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
226 226
 				EVT_ID bigint(20) unsigned NOT NULL,
227 227
 				VNU_ID bigint(20) unsigned NOT NULL,
228 228
 				EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
229 229
 				PRIMARY KEY  (EVV_ID)";
230
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
231
-        $table_name = 'esp_extra_meta';
232
-        $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
230
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
231
+		$table_name = 'esp_extra_meta';
232
+		$sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
233 233
 				OBJ_ID int(11) DEFAULT NULL,
234 234
 				EXM_type varchar(45) DEFAULT NULL,
235 235
 				EXM_key varchar(45) DEFAULT NULL,
236 236
 				EXM_value text,
237 237
 				PRIMARY KEY  (EXM_ID),
238 238
 				KEY EXM_type (EXM_type,OBJ_ID,EXM_key)";
239
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
240
-        $table_name = 'esp_extra_join';
241
-        $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
239
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
240
+		$table_name = 'esp_extra_join';
241
+		$sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
242 242
 				EXJ_first_model_id varchar(6) NOT NULL,
243 243
 				EXJ_first_model_name varchar(20) NOT NULL,
244 244
 				EXJ_second_model_id varchar(6) NOT NULL,
@@ -246,9 +246,9 @@  discard block
 block discarded – undo
246 246
 				PRIMARY KEY  (EXJ_ID),
247 247
 				KEY first_model (EXJ_first_model_name,EXJ_first_model_id),
248 248
 				KEY second_model (EXJ_second_model_name,EXJ_second_model_id)";
249
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
250
-        $table_name = 'esp_line_item';
251
-        $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
249
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
250
+		$table_name = 'esp_line_item';
251
+		$sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
252 252
 				LIN_code varchar(245) NOT NULL DEFAULT '',
253 253
 				TXN_ID int(11) DEFAULT NULL,
254 254
 				LIN_name varchar(245) NOT NULL DEFAULT '',
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
 				KEY txn_type_timestamp (TXN_ID,LIN_type,LIN_timestamp),
270 270
 				KEY txn_obj_id_obj_type (TXN_ID,OBJ_ID,OBJ_type),
271 271
 				KEY obj_id_obj_type (OBJ_ID,OBJ_type)";
272
-        $this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID');
273
-        $this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code');
274
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
275
-        $table_name = 'esp_log';
276
-        $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
272
+		$this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID');
273
+		$this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code');
274
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
275
+		$table_name = 'esp_log';
276
+		$sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
277 277
 				LOG_time datetime DEFAULT NULL,
278 278
 				OBJ_ID varchar(45) DEFAULT NULL,
279 279
 				OBJ_type varchar(45) DEFAULT NULL,
@@ -284,12 +284,12 @@  discard block
 block discarded – undo
284 284
 				KEY LOG_time (LOG_time),
285 285
 				KEY OBJ (OBJ_type,OBJ_ID),
286 286
 				KEY LOG_type (LOG_type)";
287
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
288
-        $table_name = 'esp_message';
289
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to');
290
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from');
291
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject');
292
-        $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
287
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
288
+		$table_name = 'esp_message';
289
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to');
290
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from');
291
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject');
292
+		$sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
293 293
 				GRP_ID int(10) unsigned NULL,
294 294
 				MSG_token varchar(255) NULL,
295 295
 				TXN_ID int(10) unsigned NULL,
@@ -321,18 +321,18 @@  discard block
 block discarded – undo
321 321
 				KEY STS_ID (STS_ID),
322 322
 				KEY MSG_created (MSG_created),
323 323
 				KEY MSG_modified (MSG_modified)";
324
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
325
-        $table_name = 'esp_message_template';
326
-        $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
324
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
325
+		$table_name = 'esp_message_template';
326
+		$sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
327 327
 				GRP_ID int(10) unsigned NOT NULL,
328 328
 				MTP_context varchar(50) NOT NULL,
329 329
 				MTP_template_field varchar(30) NOT NULL,
330 330
 				MTP_content text NOT NULL,
331 331
 				PRIMARY KEY  (MTP_ID),
332 332
 				KEY GRP_ID (GRP_ID)";
333
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
334
-        $table_name = 'esp_message_template_group';
335
-        $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
333
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
334
+		$table_name = 'esp_message_template_group';
335
+		$sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
336 336
 				MTP_user_id int(10) NOT NULL DEFAULT '1',
337 337
 				MTP_name varchar(245) NOT NULL DEFAULT '',
338 338
 				MTP_description varchar(245) NOT NULL DEFAULT '',
@@ -344,9 +344,9 @@  discard block
 block discarded – undo
344 344
 				MTP_is_active tinyint(1) NOT NULL DEFAULT '1',
345 345
 				PRIMARY KEY  (GRP_ID),
346 346
 				KEY MTP_user_id (MTP_user_id)";
347
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
348
-        $table_name = 'esp_payment';
349
-        $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
347
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
348
+		$table_name = 'esp_payment';
349
+		$sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
350 350
 				TXN_ID int(10) unsigned DEFAULT NULL,
351 351
 				STS_ID varchar(3) DEFAULT NULL,
352 352
 				PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -363,9 +363,9 @@  discard block
 block discarded – undo
363 363
 				PRIMARY KEY  (PAY_ID),
364 364
 				KEY PAY_timestamp (PAY_timestamp),
365 365
 				KEY TXN_ID (TXN_ID)";
366
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
367
-        $table_name = 'esp_payment_method';
368
-        $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
366
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
367
+		$table_name = 'esp_payment_method';
368
+		$sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
369 369
 				PMD_type varchar(124) DEFAULT NULL,
370 370
 				PMD_name varchar(255) DEFAULT NULL,
371 371
 				PMD_desc text,
@@ -381,24 +381,24 @@  discard block
 block discarded – undo
381 381
 				PRIMARY KEY  (PMD_ID),
382 382
 				UNIQUE KEY PMD_slug_UNIQUE (PMD_slug),
383 383
 				KEY PMD_type (PMD_type)";
384
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
385
-        $table_name = "esp_ticket_price";
386
-        $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
384
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
385
+		$table_name = "esp_ticket_price";
386
+		$sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
387 387
 				TKT_ID int(10) unsigned NOT NULL,
388 388
 				PRC_ID int(10) unsigned NOT NULL,
389 389
 				PRIMARY KEY  (TKP_ID),
390 390
 				KEY TKT_ID (TKT_ID),
391 391
 				KEY PRC_ID (PRC_ID)";
392
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
393
-        $table_name = "esp_ticket_template";
394
-        $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
392
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
393
+		$table_name = "esp_ticket_template";
394
+		$sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
395 395
 				TTM_name varchar(45) NOT NULL,
396 396
 				TTM_description text,
397 397
 				TTM_file varchar(45),
398 398
 				PRIMARY KEY  (TTM_ID)";
399
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
400
-        $table_name = 'esp_question';
401
-        $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
399
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
400
+		$table_name = 'esp_question';
401
+		$sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
402 402
 				QST_display_text text NOT NULL,
403 403
 				QST_admin_label varchar(255) NOT NULL,
404 404
 				QST_system varchar(25) DEFAULT NULL,
@@ -412,18 +412,18 @@  discard block
 block discarded – undo
412 412
 				QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0,
413 413
 				PRIMARY KEY  (QST_ID),
414 414
 				KEY QST_order (QST_order)';
415
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
416
-        $table_name = 'esp_question_group_question';
417
-        $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
415
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
416
+		$table_name = 'esp_question_group_question';
417
+		$sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
418 418
 				QSG_ID int(10) unsigned NOT NULL,
419 419
 				QST_ID int(10) unsigned NOT NULL,
420 420
 				QGQ_order int(10) unsigned NOT NULL DEFAULT 0,
421 421
 				PRIMARY KEY  (QGQ_ID),
422 422
 				KEY QST_ID (QST_ID),
423 423
 				KEY QSG_ID_order (QSG_ID,QGQ_order)";
424
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
425
-        $table_name = 'esp_question_option';
426
-        $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
424
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
425
+		$table_name = 'esp_question_option';
426
+		$sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
427 427
 				QSO_value varchar(255) NOT NULL,
428 428
 				QSO_desc text NOT NULL,
429 429
 				QST_ID int(10) unsigned NOT NULL,
@@ -433,9 +433,9 @@  discard block
 block discarded – undo
433 433
 				PRIMARY KEY  (QSO_ID),
434 434
 				KEY QST_ID (QST_ID),
435 435
 				KEY QSO_order (QSO_order)";
436
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
437
-        $table_name = 'esp_registration';
438
-        $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
436
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
437
+		$table_name = 'esp_registration';
438
+		$sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
439 439
 				EVT_ID bigint(20) unsigned NOT NULL,
440 440
 				ATT_ID bigint(20) unsigned NOT NULL,
441 441
 				TXN_ID int(10) unsigned NOT NULL,
@@ -459,18 +459,18 @@  discard block
 block discarded – undo
459 459
 				KEY TKT_ID (TKT_ID),
460 460
 				KEY EVT_ID (EVT_ID),
461 461
 				KEY STS_ID (STS_ID)";
462
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
463
-        $table_name = 'esp_registration_payment';
464
-        $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
462
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
463
+		$table_name = 'esp_registration_payment';
464
+		$sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
465 465
 					  REG_ID int(10) unsigned NOT NULL,
466 466
 					  PAY_ID int(10) unsigned NULL,
467 467
 					  RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00',
468 468
 					  PRIMARY KEY  (RPY_ID),
469 469
 					  KEY REG_ID (REG_ID),
470 470
 					  KEY PAY_ID (PAY_ID)";
471
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
472
-        $table_name = 'esp_state';
473
-        $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
471
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
472
+		$table_name = 'esp_state';
473
+		$sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
474 474
 				CNT_ISO varchar(2) NOT NULL,
475 475
 				STA_abbrev varchar(24) NOT NULL,
476 476
 				STA_name varchar(100) NOT NULL,
@@ -478,9 +478,9 @@  discard block
 block discarded – undo
478 478
 				PRIMARY KEY  (STA_ID),
479 479
 				KEY STA_abbrev (STA_abbrev),
480 480
 				KEY CNT_ISO (CNT_ISO)";
481
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
482
-        $table_name = 'esp_status';
483
-        $sql = "STS_ID varchar(3) NOT NULL,
481
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
482
+		$table_name = 'esp_status';
483
+		$sql = "STS_ID varchar(3) NOT NULL,
484 484
 				STS_code varchar(45) NOT NULL,
485 485
 				STS_type varchar(45) NOT NULL,
486 486
 				STS_can_edit tinyint(1) NOT NULL DEFAULT 0,
@@ -488,9 +488,9 @@  discard block
 block discarded – undo
488 488
 				STS_open tinyint(1) NOT NULL DEFAULT 1,
489 489
 				UNIQUE KEY STS_ID_UNIQUE (STS_ID),
490 490
 				KEY STS_type (STS_type)";
491
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
492
-        $table_name = 'esp_transaction';
493
-        $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
491
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
492
+		$table_name = 'esp_transaction';
493
+		$sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
494 494
 				TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
495 495
 				TXN_total decimal(12,3) DEFAULT '0.00',
496 496
 				TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00',
@@ -502,9 +502,9 @@  discard block
 block discarded – undo
502 502
 				PRIMARY KEY  (TXN_ID),
503 503
 				KEY TXN_timestamp (TXN_timestamp),
504 504
 				KEY STS_ID (STS_ID)";
505
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
506
-        $table_name = 'esp_venue_meta';
507
-        $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
505
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
506
+		$table_name = 'esp_venue_meta';
507
+		$sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
508 508
 			VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0,
509 509
 			VNU_address varchar(255) DEFAULT NULL,
510 510
 			VNU_address2 varchar(255) DEFAULT NULL,
@@ -523,10 +523,10 @@  discard block
 block discarded – undo
523 523
 			KEY VNU_ID (VNU_ID),
524 524
 			KEY STA_ID (STA_ID),
525 525
 			KEY CNT_ISO (CNT_ISO)";
526
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
527
-        // modified tables
528
-        $table_name = "esp_price";
529
-        $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
526
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
527
+		// modified tables
528
+		$table_name = "esp_price";
529
+		$sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
530 530
 				PRT_ID tinyint(3) unsigned NOT NULL,
531 531
 				PRC_amount decimal(12,6) NOT NULL DEFAULT '0.000000',
532 532
 				PRC_name varchar(245) NOT NULL,
@@ -539,9 +539,9 @@  discard block
 block discarded – undo
539 539
 				PRC_parent int(10) unsigned DEFAULT 0,
540 540
 				PRIMARY KEY  (PRC_ID),
541 541
 				KEY PRT_ID (PRT_ID)";
542
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
543
-        $table_name = "esp_price_type";
544
-        $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
542
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
543
+		$table_name = "esp_price_type";
544
+		$sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
545 545
 				PRT_name varchar(45) NOT NULL,
546 546
 				PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1',
547 547
 				PRT_is_percent tinyint(1) NOT NULL DEFAULT '0',
@@ -550,9 +550,9 @@  discard block
 block discarded – undo
550 550
 				PRT_deleted tinyint(1) NOT NULL DEFAULT '0',
551 551
 				UNIQUE KEY PRT_name_UNIQUE (PRT_name),
552 552
 				PRIMARY KEY  (PRT_ID)";
553
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
554
-        $table_name = "esp_ticket";
555
-        $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
553
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
554
+		$table_name = "esp_ticket";
555
+		$sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
556 556
 				TTM_ID int(10) unsigned NOT NULL,
557 557
 				TKT_name varchar(245) NOT NULL DEFAULT '',
558 558
 				TKT_description text NOT NULL,
@@ -575,9 +575,9 @@  discard block
 block discarded – undo
575 575
 				TKT_deleted tinyint(1) NOT NULL DEFAULT '0',
576 576
 				PRIMARY KEY  (TKT_ID),
577 577
 				KEY TKT_start_date (TKT_start_date)";
578
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
579
-        $table_name = 'esp_question_group';
580
-        $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
578
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
579
+		$table_name = 'esp_question_group';
580
+		$sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
581 581
 				QSG_name varchar(255) NOT NULL,
582 582
 				QSG_identifier varchar(100) NOT NULL,
583 583
 				QSG_desc text NULL,
@@ -590,145 +590,145 @@  discard block
 block discarded – undo
590 590
 				PRIMARY KEY  (QSG_ID),
591 591
 				UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier),
592 592
 				KEY QSG_order (QSG_order)';
593
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
594
-        /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
595
-        $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
596
-        // (because many need to convert old string states to foreign keys into the states table)
597
-        $script_4_1_defaults->insert_default_states();
598
-        $script_4_1_defaults->insert_default_countries();
599
-        /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
600
-        $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
601
-        $script_4_5_defaults->insert_default_price_types();
602
-        $script_4_5_defaults->insert_default_prices();
603
-        $script_4_5_defaults->insert_default_tickets();
604
-        /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
605
-        $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
606
-        $script_4_6_defaults->add_default_admin_only_payments();
607
-        $script_4_6_defaults->insert_default_currencies();
608
-        /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */
609
-        $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0');
610
-        $script_4_8_defaults->verify_new_countries();
611
-        $script_4_8_defaults->verify_new_currencies();
612
-        $this->verify_db_collations();
613
-        $this->verify_db_collations_again();
614
-        return true;
615
-    }
593
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
594
+		/** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
595
+		$script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
596
+		// (because many need to convert old string states to foreign keys into the states table)
597
+		$script_4_1_defaults->insert_default_states();
598
+		$script_4_1_defaults->insert_default_countries();
599
+		/** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
600
+		$script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
601
+		$script_4_5_defaults->insert_default_price_types();
602
+		$script_4_5_defaults->insert_default_prices();
603
+		$script_4_5_defaults->insert_default_tickets();
604
+		/** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
605
+		$script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
606
+		$script_4_6_defaults->add_default_admin_only_payments();
607
+		$script_4_6_defaults->insert_default_currencies();
608
+		/** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */
609
+		$script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0');
610
+		$script_4_8_defaults->verify_new_countries();
611
+		$script_4_8_defaults->verify_new_currencies();
612
+		$this->verify_db_collations();
613
+		$this->verify_db_collations_again();
614
+		return true;
615
+	}
616 616
 
617 617
 
618 618
 
619
-    /**
620
-     * @return boolean
621
-     */
622
-    public function schema_changes_after_migration()
623
-    {
624
-        return true;
625
-    }
619
+	/**
620
+	 * @return boolean
621
+	 */
622
+	public function schema_changes_after_migration()
623
+	{
624
+		return true;
625
+	}
626 626
 
627 627
 
628 628
 
629
-    public function migration_page_hooks()
630
-    {
631
-    }
629
+	public function migration_page_hooks()
630
+	{
631
+	}
632 632
 
633 633
 
634 634
 
635
-    /**
636
-     * Verify all EE4 models' tables use utf8mb4 collation
637
-     *
638
-     * @return void
639
-     */
640
-    public function verify_db_collations()
641
-    {
642
-        global $wpdb;
643
-        // double-check we haven't already done it or that that the DB doesn't support utf8mb4
644
-        if ('utf8mb4' !== $wpdb->charset
645
-            || get_option('ee_verified_db_collations', false)) {
646
-            return;
647
-        }
648
-        // grab tables from each model
649
-        $tables_to_check = array();
650
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
651
-            if (method_exists($model_name, 'instance')) {
652
-                $model_obj = call_user_func(array($model_name, 'instance'));
653
-                if ($model_obj instanceof EEM_Base) {
654
-                    foreach ($model_obj->get_tables() as $table) {
655
-                        if (strpos($table->get_table_name(), 'esp_')
656
-                            && (is_main_site()// for main tables, verify global tables
657
-                                || ! $table->is_global()// if not the main site, then only verify non-global tables (avoid doubling up)
658
-                            )
659
-                            && function_exists('maybe_convert_table_to_utf8mb4')
660
-                        ) {
661
-                            $tables_to_check[] = $table->get_table_name();
662
-                        }
663
-                    }
664
-                }
665
-            }
666
-        }
667
-        // and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active
668
-        // when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead
669
-        // of hard-coding this
670
-        $addon_tables = array(
671
-            // mailchimp
672
-            'esp_event_mailchimp_list_group',
673
-            'esp_event_question_mailchimp_field',
674
-            // multisite
675
-            'esp_blog_meta',
676
-            // people
677
-            'esp_people_to_post',
678
-            // promotions
679
-            'esp_promotion',
680
-            'esp_promotion_object',
681
-        );
682
-        foreach ($addon_tables as $table_name) {
683
-                $tables_to_check[] = $table_name;
684
-        }
685
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
686
-        // ok and now let's remember this was done (without needing to check the db schemas all over again)
687
-        add_option('ee_verified_db_collations', true, null, 'no');
688
-        // seeing how this ran with the fix from 10435, no need to check again
689
-        add_option('ee_verified_db_collations_again', true, null, 'no');
690
-    }
635
+	/**
636
+	 * Verify all EE4 models' tables use utf8mb4 collation
637
+	 *
638
+	 * @return void
639
+	 */
640
+	public function verify_db_collations()
641
+	{
642
+		global $wpdb;
643
+		// double-check we haven't already done it or that that the DB doesn't support utf8mb4
644
+		if ('utf8mb4' !== $wpdb->charset
645
+			|| get_option('ee_verified_db_collations', false)) {
646
+			return;
647
+		}
648
+		// grab tables from each model
649
+		$tables_to_check = array();
650
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
651
+			if (method_exists($model_name, 'instance')) {
652
+				$model_obj = call_user_func(array($model_name, 'instance'));
653
+				if ($model_obj instanceof EEM_Base) {
654
+					foreach ($model_obj->get_tables() as $table) {
655
+						if (strpos($table->get_table_name(), 'esp_')
656
+							&& (is_main_site()// for main tables, verify global tables
657
+								|| ! $table->is_global()// if not the main site, then only verify non-global tables (avoid doubling up)
658
+							)
659
+							&& function_exists('maybe_convert_table_to_utf8mb4')
660
+						) {
661
+							$tables_to_check[] = $table->get_table_name();
662
+						}
663
+					}
664
+				}
665
+			}
666
+		}
667
+		// and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active
668
+		// when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead
669
+		// of hard-coding this
670
+		$addon_tables = array(
671
+			// mailchimp
672
+			'esp_event_mailchimp_list_group',
673
+			'esp_event_question_mailchimp_field',
674
+			// multisite
675
+			'esp_blog_meta',
676
+			// people
677
+			'esp_people_to_post',
678
+			// promotions
679
+			'esp_promotion',
680
+			'esp_promotion_object',
681
+		);
682
+		foreach ($addon_tables as $table_name) {
683
+				$tables_to_check[] = $table_name;
684
+		}
685
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
686
+		// ok and now let's remember this was done (without needing to check the db schemas all over again)
687
+		add_option('ee_verified_db_collations', true, null, 'no');
688
+		// seeing how this ran with the fix from 10435, no need to check again
689
+		add_option('ee_verified_db_collations_again', true, null, 'no');
690
+	}
691 691
 
692 692
 
693 693
 
694
-    /**
695
-     * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
696
-     * which meant some DB collations might not have been updated
697
-     * @return void
698
-     */
699
-    public function verify_db_collations_again()
700
-    {
701
-        global $wpdb;
702
-        // double-check we haven't already done this or that the DB doesn't support it
703
-        // compare to how WordPress' upgrade_430() function does this check
704
-        if ('utf8mb4' !== $wpdb->charset
705
-            || get_option('ee_verified_db_collations_again', false)) {
706
-            return;
707
-        }
708
-        $tables_to_check = array(
709
-            'esp_attendee_meta',
710
-            'esp_message'
711
-        );
712
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
713
-        add_option('ee_verified_db_collations_again', true, null, 'no');
714
-    }
694
+	/**
695
+	 * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
696
+	 * which meant some DB collations might not have been updated
697
+	 * @return void
698
+	 */
699
+	public function verify_db_collations_again()
700
+	{
701
+		global $wpdb;
702
+		// double-check we haven't already done this or that the DB doesn't support it
703
+		// compare to how WordPress' upgrade_430() function does this check
704
+		if ('utf8mb4' !== $wpdb->charset
705
+			|| get_option('ee_verified_db_collations_again', false)) {
706
+			return;
707
+		}
708
+		$tables_to_check = array(
709
+			'esp_attendee_meta',
710
+			'esp_message'
711
+		);
712
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
713
+		add_option('ee_verified_db_collations_again', true, null, 'no');
714
+	}
715 715
 
716 716
 
717 717
 
718
-    /**
719
-     * Runs maybe_convert_table_to_utf8mb4 on the specified tables
720
-     * @param $tables_to_check
721
-     * @return boolean true if logic ran, false if it didn't
722
-     */
723
-    protected function _verify_db_collations_for_tables($tables_to_check)
724
-    {
725
-        foreach ($tables_to_check as $table_name) {
726
-            $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
727
-            if (! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name)
728
-                && $this->_get_table_analysis()->tableExists($table_name)
729
-            ) {
730
-                maybe_convert_table_to_utf8mb4($table_name);
731
-            }
732
-        }
733
-    }
718
+	/**
719
+	 * Runs maybe_convert_table_to_utf8mb4 on the specified tables
720
+	 * @param $tables_to_check
721
+	 * @return boolean true if logic ran, false if it didn't
722
+	 */
723
+	protected function _verify_db_collations_for_tables($tables_to_check)
724
+	{
725
+		foreach ($tables_to_check as $table_name) {
726
+			$table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
727
+			if (! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name)
728
+				&& $this->_get_table_analysis()->tableExists($table_name)
729
+			) {
730
+				maybe_convert_table_to_utf8mb4($table_name);
731
+			}
732
+		}
733
+	}
734 734
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Money.helper.php 2 patches
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -12,239 +12,239 @@
 block discarded – undo
12 12
 class EEH_Money extends EEH_Base
13 13
 {
14 14
 
15
-    /**
16
-     * This removes all localized money formatting from the incoming value
17
-     * Note: uses this site's currency settings for deciding what is considered a
18
-     * "thousands separator" (usually the character "," )
19
-     * and what is a "decimal mark" (usually the character ".")
20
-     *
21
-     * @param int|float|string $money_value
22
-     * @param string           $CNT_ISO
23
-     * @return float
24
-     * @throws EE_Error
25
-     */
26
-    public static function strip_localized_money_formatting($money_value, $CNT_ISO = '')
27
-    {
28
-        $currency_config = EEH_Money::get_currency_config($CNT_ISO);
29
-        $money_value     = str_replace(
30
-            array(
31
-                $currency_config->thsnds,
32
-                $currency_config->dec_mrk,
33
-            ),
34
-            array(
35
-                '', // remove thousands separator
36
-                '.', // convert decimal mark to what PHP expects
37
-            ),
38
-            $money_value
39
-        );
40
-        $money_value     = filter_var(
41
-            $money_value,
42
-            FILTER_SANITIZE_NUMBER_FLOAT,
43
-            FILTER_FLAG_ALLOW_FRACTION
44
-        );
45
-        return $money_value;
46
-    }
15
+	/**
16
+	 * This removes all localized money formatting from the incoming value
17
+	 * Note: uses this site's currency settings for deciding what is considered a
18
+	 * "thousands separator" (usually the character "," )
19
+	 * and what is a "decimal mark" (usually the character ".")
20
+	 *
21
+	 * @param int|float|string $money_value
22
+	 * @param string           $CNT_ISO
23
+	 * @return float
24
+	 * @throws EE_Error
25
+	 */
26
+	public static function strip_localized_money_formatting($money_value, $CNT_ISO = '')
27
+	{
28
+		$currency_config = EEH_Money::get_currency_config($CNT_ISO);
29
+		$money_value     = str_replace(
30
+			array(
31
+				$currency_config->thsnds,
32
+				$currency_config->dec_mrk,
33
+			),
34
+			array(
35
+				'', // remove thousands separator
36
+				'.', // convert decimal mark to what PHP expects
37
+			),
38
+			$money_value
39
+		);
40
+		$money_value     = filter_var(
41
+			$money_value,
42
+			FILTER_SANITIZE_NUMBER_FLOAT,
43
+			FILTER_FLAG_ALLOW_FRACTION
44
+		);
45
+		return $money_value;
46
+	}
47 47
 
48 48
 
49
-    /**
50
-     * This converts an incoming localized money value into a standard float item (to three decimal places)
51
-     * Only use this if you know the $money_value follows your currency configuration's
52
-     * settings. Note: this uses this site's currency settings for deciding what is considered a
53
-     * "thousands separator" (usually the character "," )
54
-     * and what is a "decimal mark" (usually the character ".")
55
-     *
56
-     * @param int|string $money_value
57
-     * @return float
58
-     * @throws EE_Error
59
-     */
60
-    public static function convert_to_float_from_localized_money($money_value)
61
-    {
62
-        // float it! and round to three decimal places
63
-        return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3);
64
-    }
49
+	/**
50
+	 * This converts an incoming localized money value into a standard float item (to three decimal places)
51
+	 * Only use this if you know the $money_value follows your currency configuration's
52
+	 * settings. Note: this uses this site's currency settings for deciding what is considered a
53
+	 * "thousands separator" (usually the character "," )
54
+	 * and what is a "decimal mark" (usually the character ".")
55
+	 *
56
+	 * @param int|string $money_value
57
+	 * @return float
58
+	 * @throws EE_Error
59
+	 */
60
+	public static function convert_to_float_from_localized_money($money_value)
61
+	{
62
+		// float it! and round to three decimal places
63
+		return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3);
64
+	}
65 65
 
66 66
 
67
-    /**
68
-     * For comparing floats. Default operator is '=', but see the $operator below for all options.
69
-     * This should be used to compare floats instead of normal '==' because floats
70
-     * are inherently imprecise, and so you can sometimes have two floats that appear to be identical
71
-     * but actually differ by 0.00000001.
72
-     *
73
-     * @see http://biostall.com/php-function-to-compare-floating-point-numbers
74
-     * @param float  $float1
75
-     * @param float  $float2
76
-     * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne
77
-     * @return bool whether the equation is true or false
78
-     * @throws EE_Error
79
-     */
80
-    public static function compare_floats($float1, $float2, $operator = '=')
81
-    {
82
-        // Check numbers to 5 digits of precision
83
-        $epsilon = 0.00001;
84
-        $float1 = (float) $float1;
85
-        $float2 = (float) $float2;
86
-        switch ($operator) {
87
-            // equal
88
-            case "=":
89
-            case "==":
90
-            case "===":
91
-            case "eq":
92
-                if (abs($float1 - $float2) < $epsilon) {
93
-                    return true;
94
-                }
95
-                break;
96
-            // less than
97
-            case "<":
98
-            case "lt":
99
-                if (abs($float1 - $float2) < $epsilon) {
100
-                    return false;
101
-                } else {
102
-                    if ($float1 < $float2) {
103
-                        return true;
104
-                    }
105
-                }
106
-                break;
107
-            // less than or equal
108
-            case "<=":
109
-            case "lte":
110
-                if (self::compare_floats($float1, $float2, '<') || self::compare_floats($float1, $float2, '=')) {
111
-                    return true;
112
-                }
113
-                break;
114
-            // greater than
115
-            case ">":
116
-            case "gt":
117
-                if (abs($float1 - $float2) < $epsilon) {
118
-                    return false;
119
-                } else {
120
-                    if ($float1 > $float2) {
121
-                        return true;
122
-                    }
123
-                }
124
-                break;
125
-            // greater than or equal
126
-            case ">=":
127
-            case "gte":
128
-                if (self::compare_floats($float1, $float2, '>') || self::compare_floats($float1, $float2, '=')) {
129
-                    return true;
130
-                }
131
-                break;
132
-            case "<>":
133
-            case "!=":
134
-            case "ne":
135
-                if (abs($float1 - $float2) > $epsilon) {
136
-                    return true;
137
-                }
138
-                break;
139
-            default:
140
-                throw new EE_Error(
141
-                    sprintf(
142
-                        __(
143
-                            "Unknown operator %s in EEH_Money::compare_floats()",
144
-                            'event_espresso'
145
-                        ),
146
-                        $operator
147
-                    )
148
-                );
149
-        }
150
-        return false;
151
-    }
67
+	/**
68
+	 * For comparing floats. Default operator is '=', but see the $operator below for all options.
69
+	 * This should be used to compare floats instead of normal '==' because floats
70
+	 * are inherently imprecise, and so you can sometimes have two floats that appear to be identical
71
+	 * but actually differ by 0.00000001.
72
+	 *
73
+	 * @see http://biostall.com/php-function-to-compare-floating-point-numbers
74
+	 * @param float  $float1
75
+	 * @param float  $float2
76
+	 * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne
77
+	 * @return bool whether the equation is true or false
78
+	 * @throws EE_Error
79
+	 */
80
+	public static function compare_floats($float1, $float2, $operator = '=')
81
+	{
82
+		// Check numbers to 5 digits of precision
83
+		$epsilon = 0.00001;
84
+		$float1 = (float) $float1;
85
+		$float2 = (float) $float2;
86
+		switch ($operator) {
87
+			// equal
88
+			case "=":
89
+			case "==":
90
+			case "===":
91
+			case "eq":
92
+				if (abs($float1 - $float2) < $epsilon) {
93
+					return true;
94
+				}
95
+				break;
96
+			// less than
97
+			case "<":
98
+			case "lt":
99
+				if (abs($float1 - $float2) < $epsilon) {
100
+					return false;
101
+				} else {
102
+					if ($float1 < $float2) {
103
+						return true;
104
+					}
105
+				}
106
+				break;
107
+			// less than or equal
108
+			case "<=":
109
+			case "lte":
110
+				if (self::compare_floats($float1, $float2, '<') || self::compare_floats($float1, $float2, '=')) {
111
+					return true;
112
+				}
113
+				break;
114
+			// greater than
115
+			case ">":
116
+			case "gt":
117
+				if (abs($float1 - $float2) < $epsilon) {
118
+					return false;
119
+				} else {
120
+					if ($float1 > $float2) {
121
+						return true;
122
+					}
123
+				}
124
+				break;
125
+			// greater than or equal
126
+			case ">=":
127
+			case "gte":
128
+				if (self::compare_floats($float1, $float2, '>') || self::compare_floats($float1, $float2, '=')) {
129
+					return true;
130
+				}
131
+				break;
132
+			case "<>":
133
+			case "!=":
134
+			case "ne":
135
+				if (abs($float1 - $float2) > $epsilon) {
136
+					return true;
137
+				}
138
+				break;
139
+			default:
140
+				throw new EE_Error(
141
+					sprintf(
142
+						__(
143
+							"Unknown operator %s in EEH_Money::compare_floats()",
144
+							'event_espresso'
145
+						),
146
+						$operator
147
+					)
148
+				);
149
+		}
150
+		return false;
151
+	}
152 152
 
153 153
 
154
-    /**
155
-     * This returns a localized format string suitable for jQplot.
156
-     *
157
-     * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
158
-     *                         Otherwise will use currency settings for current active country on site.
159
-     * @return string
160
-     * @throws EE_Error
161
-     */
162
-    public static function get_format_for_jqplot($CNT_ISO = '')
163
-    {
164
-        // default format
165
-        $format          = 'f';
166
-        $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
167
-        // first get the decimal place and number of places
168
-        $format = "%'." . $currency_config->dec_plc . $format;
169
-        // currency symbol on right side.
170
-        $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
171
-        return $format;
172
-    }
154
+	/**
155
+	 * This returns a localized format string suitable for jQplot.
156
+	 *
157
+	 * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
158
+	 *                         Otherwise will use currency settings for current active country on site.
159
+	 * @return string
160
+	 * @throws EE_Error
161
+	 */
162
+	public static function get_format_for_jqplot($CNT_ISO = '')
163
+	{
164
+		// default format
165
+		$format          = 'f';
166
+		$currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
167
+		// first get the decimal place and number of places
168
+		$format = "%'." . $currency_config->dec_plc . $format;
169
+		// currency symbol on right side.
170
+		$format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
171
+		return $format;
172
+	}
173 173
 
174 174
 
175
-    /**
176
-     * This returns a localized format string suitable for usage with the Google Charts API format param.
177
-     *
178
-     * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
179
-     *                         Otherwise will use currency settings for current active country on site.
180
-     *                         Note: GoogleCharts uses ICU pattern set
181
-     *                         (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details)
182
-     * @return string
183
-     * @throws EE_Error
184
-     */
185
-    public static function get_format_for_google_charts($CNT_ISO = '')
186
-    {
187
-        $currency_config            = EEH_Money::get_currency_config($CNT_ISO);
188
-        $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0');
189
-        // first get the decimal place and number of places
190
-        $format = '#,##0.' . $decimal_places_placeholder;
191
-        // currency symbol on right side.
192
-        $format          = $currency_config->sign_b4
193
-            ? $currency_config->sign . $format
194
-            : $format
195
-              . $currency_config->sign;
196
-        $formatterObject = array(
197
-            'decimalSymbol'  => $currency_config->dec_mrk,
198
-            'groupingSymbol' => $currency_config->thsnds,
199
-            'fractionDigits' => $currency_config->dec_plc,
200
-        );
201
-        if ($currency_config->sign_b4) {
202
-            $formatterObject['prefix'] = $currency_config->sign;
203
-        } else {
204
-            $formatterObject['suffix'] = $currency_config->sign;
205
-        }
206
-        return array(
207
-            'format'          => $format,
208
-            'formatterObject' => $formatterObject,
209
-        );
210
-    }
175
+	/**
176
+	 * This returns a localized format string suitable for usage with the Google Charts API format param.
177
+	 *
178
+	 * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
179
+	 *                         Otherwise will use currency settings for current active country on site.
180
+	 *                         Note: GoogleCharts uses ICU pattern set
181
+	 *                         (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details)
182
+	 * @return string
183
+	 * @throws EE_Error
184
+	 */
185
+	public static function get_format_for_google_charts($CNT_ISO = '')
186
+	{
187
+		$currency_config            = EEH_Money::get_currency_config($CNT_ISO);
188
+		$decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0');
189
+		// first get the decimal place and number of places
190
+		$format = '#,##0.' . $decimal_places_placeholder;
191
+		// currency symbol on right side.
192
+		$format          = $currency_config->sign_b4
193
+			? $currency_config->sign . $format
194
+			: $format
195
+			  . $currency_config->sign;
196
+		$formatterObject = array(
197
+			'decimalSymbol'  => $currency_config->dec_mrk,
198
+			'groupingSymbol' => $currency_config->thsnds,
199
+			'fractionDigits' => $currency_config->dec_plc,
200
+		);
201
+		if ($currency_config->sign_b4) {
202
+			$formatterObject['prefix'] = $currency_config->sign;
203
+		} else {
204
+			$formatterObject['suffix'] = $currency_config->sign;
205
+		}
206
+		return array(
207
+			'format'          => $format,
208
+			'formatterObject' => $formatterObject,
209
+		);
210
+	}
211 211
 
212 212
 
213
-    /**
214
-     * @param string $CNT_ISO
215
-     * @return EE_Currency_Config|null
216
-     * @throws EE_Error
217
-     */
218
-    public static function get_currency_config($CNT_ISO = '')
219
-    {
220
-        // if CNT_ISO passed lets try to get currency settings for it.
221
-        $currency_config = $CNT_ISO !== ''
222
-            ? new EE_Currency_Config($CNT_ISO)
223
-            : null;
224
-        // default currency settings for site if not set
225
-        if (! $currency_config instanceof EE_Currency_Config) {
226
-            $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
227
-                ? EE_Registry::instance()->CFG->currency
228
-                : new EE_Currency_Config();
229
-        }
230
-        return $currency_config;
231
-    }
213
+	/**
214
+	 * @param string $CNT_ISO
215
+	 * @return EE_Currency_Config|null
216
+	 * @throws EE_Error
217
+	 */
218
+	public static function get_currency_config($CNT_ISO = '')
219
+	{
220
+		// if CNT_ISO passed lets try to get currency settings for it.
221
+		$currency_config = $CNT_ISO !== ''
222
+			? new EE_Currency_Config($CNT_ISO)
223
+			: null;
224
+		// default currency settings for site if not set
225
+		if (! $currency_config instanceof EE_Currency_Config) {
226
+			$currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
227
+				? EE_Registry::instance()->CFG->currency
228
+				: new EE_Currency_Config();
229
+		}
230
+		return $currency_config;
231
+	}
232 232
 
233
-    /** 
234
-     * Rounds the number to a whole penny amount 
235
-     * @param float $amount 
236
-     * @param string $currency_code 
237
-     * @return float 
238
-     */ 
239
-    public static function round_for_currency($amount, $currency_code)
240
-    { 
241
-        $dec_places = EEM_Currency::instance()->get_var(
242
-            array(array('CUR_code' => $currency_code), 'limit' => 1),
243
-            'CUR_dec_plc'
244
-        ); 
245
-        if($dec_places === false || $dec_places === null) { 
246
-            $dec_places = EE_Config::instance()->currency->dec_plc; 
247
-        } 
248
-        return round($amount, $dec_places); 
249
-    } 
233
+	/** 
234
+	 * Rounds the number to a whole penny amount 
235
+	 * @param float $amount 
236
+	 * @param string $currency_code 
237
+	 * @return float 
238
+	 */ 
239
+	public static function round_for_currency($amount, $currency_code)
240
+	{ 
241
+		$dec_places = EEM_Currency::instance()->get_var(
242
+			array(array('CUR_code' => $currency_code), 'limit' => 1),
243
+			'CUR_dec_plc'
244
+		); 
245
+		if($dec_places === false || $dec_places === null) { 
246
+			$dec_places = EE_Config::instance()->currency->dec_plc; 
247
+		} 
248
+		return round($amount, $dec_places); 
249
+	} 
250 250
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
             ),
38 38
             $money_value
39 39
         );
40
-        $money_value     = filter_var(
40
+        $money_value = filter_var(
41 41
             $money_value,
42 42
             FILTER_SANITIZE_NUMBER_FLOAT,
43 43
             FILTER_FLAG_ALLOW_FRACTION
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
         $format          = 'f';
166 166
         $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
167 167
         // first get the decimal place and number of places
168
-        $format = "%'." . $currency_config->dec_plc . $format;
168
+        $format = "%'.".$currency_config->dec_plc.$format;
169 169
         // currency symbol on right side.
170
-        $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
170
+        $format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign;
171 171
         return $format;
172 172
     }
173 173
 
@@ -187,10 +187,10 @@  discard block
 block discarded – undo
187 187
         $currency_config            = EEH_Money::get_currency_config($CNT_ISO);
188 188
         $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0');
189 189
         // first get the decimal place and number of places
190
-        $format = '#,##0.' . $decimal_places_placeholder;
190
+        $format = '#,##0.'.$decimal_places_placeholder;
191 191
         // currency symbol on right side.
192
-        $format          = $currency_config->sign_b4
193
-            ? $currency_config->sign . $format
192
+        $format = $currency_config->sign_b4
193
+            ? $currency_config->sign.$format
194 194
             : $format
195 195
               . $currency_config->sign;
196 196
         $formatterObject = array(
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
             ? new EE_Currency_Config($CNT_ISO)
223 223
             : null;
224 224
         // default currency settings for site if not set
225
-        if (! $currency_config instanceof EE_Currency_Config) {
225
+        if ( ! $currency_config instanceof EE_Currency_Config) {
226 226
             $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
227 227
                 ? EE_Registry::instance()->CFG->currency
228 228
                 : new EE_Currency_Config();
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
             array(array('CUR_code' => $currency_code), 'limit' => 1),
243 243
             'CUR_dec_plc'
244 244
         ); 
245
-        if($dec_places === false || $dec_places === null) { 
245
+        if ($dec_places === false || $dec_places === null) { 
246 246
             $dec_places = EE_Config::instance()->currency->dec_plc; 
247 247
         } 
248 248
         return round($amount, $dec_places); 
Please login to merge, or discard this patch.
core/db_models/EEM_Price.model.php 1 patch
Indentation   +275 added lines, -275 removed lines patch added patch discarded remove patch
@@ -10,279 +10,279 @@
 block discarded – undo
10 10
 class EEM_Price extends EEM_Soft_Delete_Base
11 11
 {
12 12
 
13
-    // private instance of the EEM_Price object
14
-    protected static $_instance = null;
15
-
16
-
17
-
18
-    /**
19
-     *      private constructor to prevent direct creation
20
-     *      @Constructor
21
-     *      @access protected
22
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
23
-     *      @return EEM_Price
24
-     */
25
-    protected function __construct($timezone)
26
-    {
27
-        require_once(EE_MODELS . 'EEM_Price_Type.model.php');
28
-        $this->singular_item = __('Price', 'event_espresso');
29
-        $this->plural_item = __('Prices', 'event_espresso');
30
-
31
-        $this->_tables = array(
32
-            'Price'=>new EE_Primary_Table('esp_price', 'PRC_ID')
33
-        );
34
-        $this->_fields = array(
35
-            'Price'=> array(
36
-                'PRC_ID'=>new EE_Primary_Key_Int_Field('PRC_ID', 'Price ID'),
37
-                'PRT_ID'=>new EE_Foreign_Key_Int_Field('PRT_ID', 'Price type Id', false, null, 'Price_Type'),
38
-                'PRC_amount'=>new EE_Money_Field('PRC_amount', 'Price Amount', false, 0, false),
39
-                'PRC_name'=>new EE_Plain_Text_Field('PRC_name', 'Name of Price', false, ''),
40
-                'PRC_desc'=>new EE_Post_Content_Field('PRC_desc', 'Price Description', false, ''),
41
-                'PRC_is_default'=>new EE_Boolean_Field('PRC_is_default', 'Flag indicating whether price is a default price', false, false),
42
-                'PRC_overrides'=>new EE_Integer_Field('PRC_overrides', 'Price ID for a global Price that will be overridden by this Price  ( for replacing default prices )', true, 0),
43
-                'PRC_order'=>new EE_Integer_Field('PRC_order', 'Order of Application of Price (lower numbers apply first?)', false, 1),
44
-                'PRC_deleted'=>new EE_Trashed_Flag_Field('PRC_deleted', 'Flag Indicating if this has been deleted or not', false, false),
45
-                'PRC_parent' => new EE_Integer_Field('PRC_parent', __('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), true, 0),
46
-                'PRC_wp_user' => new EE_WP_User_Field('PRC_wp_user', __('Price Creator ID', 'event_espresso'), false),
47
-            )
48
-        );
49
-        $this->_model_relations = array(
50
-            'Ticket'=>new EE_HABTM_Relation('Ticket_Price'),
51
-            'Price_Type'=>new EE_Belongs_To_Relation(),
52
-            'WP_User' => new EE_Belongs_To_Relation(),
53
-        );
54
-        // this model is generally available for reading
55
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event');
56
-        // account for default tickets in the caps
57
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
58
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
59
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
60
-        parent::__construct($timezone);
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     *      instantiate a new price object with blank/empty properties
67
-     *
68
-     *      @access     public
69
-     *      @return     mixed       array on success, FALSE on fail
70
-     */
71
-    public function get_new_price()
72
-    {
73
-        return $this->create_default_object();
74
-    }
75
-
76
-
77
-
78
-
79
-
80
-    /**
81
-     *      retrieve  ALL prices from db
82
-     *
83
-     *      @access     public
84
-     *      @return     EE_PRice[]
85
-     */
86
-    public function get_all_prices()
87
-    {
88
-        // retrieve all prices
89
-        return $this->get_all(array('order_by'=>array('PRC_amount'=>'ASC')));
90
-    }
91
-
92
-
93
-
94
-    /**
95
-     *        retrieve all active prices for a particular event
96
-     *
97
-     * @access        public
98
-     * @param int $EVT_ID
99
-     * @return array on success
100
-     */
101
-    public function get_all_event_prices($EVT_ID = 0)
102
-    {
103
-        return $this->get_all(array(
104
-            array(
105
-                'EVT_ID'=>$EVT_ID,
106
-                'Price_Type.PBT_ID'=>array('!=',  EEM_Price_Type::base_type_tax)
107
-            ),
108
-            'order_by'=>$this->_order_by_array_for_get_all_method()
109
-        ));
110
-    }
111
-
112
-
113
-    /**
114
-     *      retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event
115
-     *
116
-     *      @access     public
117
-     *      @param      boolean         $count  return count
118
-     *      @return         array           on success
119
-     *      @return         boolean     false on fail
120
-     */
121
-    public function get_all_default_prices($count = false)
122
-    {
123
-        $_where = array(
124
-            'Price_Type.PBT_ID'=>array('!=',4),
125
-            'PRC_deleted' => 0,
126
-            'PRC_is_default' => 1
127
-        );
128
-        $_query_params = array(
129
-            $_where,
130
-            'order_by'=>$this->_order_by_array_for_get_all_method()
131
-        );
132
-        return $count ? $this->count(array($_where)) : $this->get_all($_query_params);
133
-    }
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-    /**
145
-     *      retrieve all prices that are taxes
146
-     *
147
-     *      @access     public
148
-     *      @return         array               on success
149
-     *      @return         array top-level keys are the price's order and their values are an array,
150
-     *                      next-level keys are the price's ID, and their values are EE_Price objects
151
-     */
152
-    public function get_all_prices_that_are_taxes()
153
-    {
154
-        $taxes = array();
155
-        $all_taxes = $this->get_all(array(
156
-            array( 'Price_Type.PBT_ID'=>  EEM_Price_Type::base_type_tax ),
157
-            'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' )
158
-        ));
159
-        foreach ($all_taxes as $tax) {
160
-            if ($tax instanceof EE_Price) {
161
-                $taxes[ $tax->order() ][ $tax->ID() ] = $tax;
162
-            }
163
-        }
164
-        return $taxes;
165
-    }
166
-
167
-
168
-
169
-
170
-
171
-    /**
172
-     *      retrieve all prices for an ticket plus default global prices, but not taxes
173
-     *
174
-     *      @access     public
175
-     *      @param int $TKT_ID          the id of the event.  If not included then we assume that this is a new ticket.
176
-     *      @return         boolean         false on fail
177
-     */
178
-    public function get_all_ticket_prices_for_admin($TKT_ID = 0)
179
-    {
180
-        $array_of_price_objects = array();
181
-        if (empty($TKT_ID)) {
182
-            // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active
183
-            // return that list
184
-            $default_prices = $this->get_all_default_prices();
185
-
186
-            if ($default_prices) {
187
-                foreach ($default_prices as $price) {
188
-                    if ($price instanceof EE_Price) {
189
-                        $array_of_price_objects[ $price->type() ][] = $price;
190
-                    }
191
-                }
192
-                return $array_of_price_objects;
193
-            } else {
194
-                return array();
195
-            }
196
-        } else {
197
-            $ticket_prices = $this->get_all(array(
198
-                array(
199
-                    'TKT_ID'=>$TKT_ID,
200
-                    'PRC_deleted' => 0
201
-                    ),
202
-                'order_by'=> array('PRC_order' => 'ASC')
203
-            ));
204
-        }
205
-
206
-        if (!empty($ticket_prices)) {
207
-            foreach ($ticket_prices as $price) {
208
-                if ($price instanceof EE_Price) {
209
-                    $array_of_price_objects[ $price->type() ][] = $price;
210
-                }
211
-            }
212
-            return $array_of_price_objects;
213
-        } else {
214
-            return false;
215
-        }
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     *        _sort_event_prices_by_type
222
-     *
223
-     * @access public
224
-     * @param \EE_Price $price_a
225
-     * @param \EE_Price $price_b
226
-     * @return bool false on fail
227
-     */
228
-    public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b)
229
-    {
230
-        if ($price_a->type_obj()->order() == $price_b->type_obj()->order()) {
231
-            return $this->_sort_event_prices_by_order($price_a, $price_b);
232
-        }
233
-        return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1;
234
-    }
235
-
236
-
237
-
238
-    /**
239
-     *        _sort_event_prices_by_order
240
-     *
241
-     * @access public
242
-     * @param \EE_Price $price_a
243
-     * @param \EE_Price $price_b
244
-     * @return bool false on fail
245
-     */
246
-    public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b)
247
-    {
248
-        if ($price_a->order() == $price_b->order()) {
249
-            return 0;
250
-        }
251
-        return $price_a->order() < $price_b->order() ? -1 : 1;
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     *      get all prices of a specific type
258
-     *
259
-     *      @access     public
260
-     *      @param      int                 $type - PRT_ID
261
-     *      @return         boolean     false on fail
262
-     */
263
-    public function get_all_prices_that_are_type($type = 0)
264
-    {
265
-        return $this->get_all(array(
266
-            array(
267
-                'PRT_ID'=>$type
268
-            ),
269
-            'order_by'=>$this->_order_by_array_for_get_all_method()
270
-        ));
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     * Returns an array of the normal 'order_by' query parameter provided to the get_all query.
277
-     * Of course you don't have to use it, but this is the order we usually want to sort prices by
278
-     * @return array which can be used like so: $this->get_all(array(array(...where stuff...),'order_by'=>$this->_order_by_array_for_get_all_method()));
279
-     */
280
-    public function _order_by_array_for_get_all_method()
281
-    {
282
-        return array(
283
-                'PRC_order'=>'ASC',
284
-                'Price_Type.PRT_order'=>'ASC',
285
-                'PRC_ID'=>'ASC'
286
-        );
287
-    }
13
+	// private instance of the EEM_Price object
14
+	protected static $_instance = null;
15
+
16
+
17
+
18
+	/**
19
+	 *      private constructor to prevent direct creation
20
+	 *      @Constructor
21
+	 *      @access protected
22
+	 *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
23
+	 *      @return EEM_Price
24
+	 */
25
+	protected function __construct($timezone)
26
+	{
27
+		require_once(EE_MODELS . 'EEM_Price_Type.model.php');
28
+		$this->singular_item = __('Price', 'event_espresso');
29
+		$this->plural_item = __('Prices', 'event_espresso');
30
+
31
+		$this->_tables = array(
32
+			'Price'=>new EE_Primary_Table('esp_price', 'PRC_ID')
33
+		);
34
+		$this->_fields = array(
35
+			'Price'=> array(
36
+				'PRC_ID'=>new EE_Primary_Key_Int_Field('PRC_ID', 'Price ID'),
37
+				'PRT_ID'=>new EE_Foreign_Key_Int_Field('PRT_ID', 'Price type Id', false, null, 'Price_Type'),
38
+				'PRC_amount'=>new EE_Money_Field('PRC_amount', 'Price Amount', false, 0, false),
39
+				'PRC_name'=>new EE_Plain_Text_Field('PRC_name', 'Name of Price', false, ''),
40
+				'PRC_desc'=>new EE_Post_Content_Field('PRC_desc', 'Price Description', false, ''),
41
+				'PRC_is_default'=>new EE_Boolean_Field('PRC_is_default', 'Flag indicating whether price is a default price', false, false),
42
+				'PRC_overrides'=>new EE_Integer_Field('PRC_overrides', 'Price ID for a global Price that will be overridden by this Price  ( for replacing default prices )', true, 0),
43
+				'PRC_order'=>new EE_Integer_Field('PRC_order', 'Order of Application of Price (lower numbers apply first?)', false, 1),
44
+				'PRC_deleted'=>new EE_Trashed_Flag_Field('PRC_deleted', 'Flag Indicating if this has been deleted or not', false, false),
45
+				'PRC_parent' => new EE_Integer_Field('PRC_parent', __('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), true, 0),
46
+				'PRC_wp_user' => new EE_WP_User_Field('PRC_wp_user', __('Price Creator ID', 'event_espresso'), false),
47
+			)
48
+		);
49
+		$this->_model_relations = array(
50
+			'Ticket'=>new EE_HABTM_Relation('Ticket_Price'),
51
+			'Price_Type'=>new EE_Belongs_To_Relation(),
52
+			'WP_User' => new EE_Belongs_To_Relation(),
53
+		);
54
+		// this model is generally available for reading
55
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event');
56
+		// account for default tickets in the caps
57
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
58
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
59
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
60
+		parent::__construct($timezone);
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 *      instantiate a new price object with blank/empty properties
67
+	 *
68
+	 *      @access     public
69
+	 *      @return     mixed       array on success, FALSE on fail
70
+	 */
71
+	public function get_new_price()
72
+	{
73
+		return $this->create_default_object();
74
+	}
75
+
76
+
77
+
78
+
79
+
80
+	/**
81
+	 *      retrieve  ALL prices from db
82
+	 *
83
+	 *      @access     public
84
+	 *      @return     EE_PRice[]
85
+	 */
86
+	public function get_all_prices()
87
+	{
88
+		// retrieve all prices
89
+		return $this->get_all(array('order_by'=>array('PRC_amount'=>'ASC')));
90
+	}
91
+
92
+
93
+
94
+	/**
95
+	 *        retrieve all active prices for a particular event
96
+	 *
97
+	 * @access        public
98
+	 * @param int $EVT_ID
99
+	 * @return array on success
100
+	 */
101
+	public function get_all_event_prices($EVT_ID = 0)
102
+	{
103
+		return $this->get_all(array(
104
+			array(
105
+				'EVT_ID'=>$EVT_ID,
106
+				'Price_Type.PBT_ID'=>array('!=',  EEM_Price_Type::base_type_tax)
107
+			),
108
+			'order_by'=>$this->_order_by_array_for_get_all_method()
109
+		));
110
+	}
111
+
112
+
113
+	/**
114
+	 *      retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event
115
+	 *
116
+	 *      @access     public
117
+	 *      @param      boolean         $count  return count
118
+	 *      @return         array           on success
119
+	 *      @return         boolean     false on fail
120
+	 */
121
+	public function get_all_default_prices($count = false)
122
+	{
123
+		$_where = array(
124
+			'Price_Type.PBT_ID'=>array('!=',4),
125
+			'PRC_deleted' => 0,
126
+			'PRC_is_default' => 1
127
+		);
128
+		$_query_params = array(
129
+			$_where,
130
+			'order_by'=>$this->_order_by_array_for_get_all_method()
131
+		);
132
+		return $count ? $this->count(array($_where)) : $this->get_all($_query_params);
133
+	}
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+	/**
145
+	 *      retrieve all prices that are taxes
146
+	 *
147
+	 *      @access     public
148
+	 *      @return         array               on success
149
+	 *      @return         array top-level keys are the price's order and their values are an array,
150
+	 *                      next-level keys are the price's ID, and their values are EE_Price objects
151
+	 */
152
+	public function get_all_prices_that_are_taxes()
153
+	{
154
+		$taxes = array();
155
+		$all_taxes = $this->get_all(array(
156
+			array( 'Price_Type.PBT_ID'=>  EEM_Price_Type::base_type_tax ),
157
+			'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' )
158
+		));
159
+		foreach ($all_taxes as $tax) {
160
+			if ($tax instanceof EE_Price) {
161
+				$taxes[ $tax->order() ][ $tax->ID() ] = $tax;
162
+			}
163
+		}
164
+		return $taxes;
165
+	}
166
+
167
+
168
+
169
+
170
+
171
+	/**
172
+	 *      retrieve all prices for an ticket plus default global prices, but not taxes
173
+	 *
174
+	 *      @access     public
175
+	 *      @param int $TKT_ID          the id of the event.  If not included then we assume that this is a new ticket.
176
+	 *      @return         boolean         false on fail
177
+	 */
178
+	public function get_all_ticket_prices_for_admin($TKT_ID = 0)
179
+	{
180
+		$array_of_price_objects = array();
181
+		if (empty($TKT_ID)) {
182
+			// if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active
183
+			// return that list
184
+			$default_prices = $this->get_all_default_prices();
185
+
186
+			if ($default_prices) {
187
+				foreach ($default_prices as $price) {
188
+					if ($price instanceof EE_Price) {
189
+						$array_of_price_objects[ $price->type() ][] = $price;
190
+					}
191
+				}
192
+				return $array_of_price_objects;
193
+			} else {
194
+				return array();
195
+			}
196
+		} else {
197
+			$ticket_prices = $this->get_all(array(
198
+				array(
199
+					'TKT_ID'=>$TKT_ID,
200
+					'PRC_deleted' => 0
201
+					),
202
+				'order_by'=> array('PRC_order' => 'ASC')
203
+			));
204
+		}
205
+
206
+		if (!empty($ticket_prices)) {
207
+			foreach ($ticket_prices as $price) {
208
+				if ($price instanceof EE_Price) {
209
+					$array_of_price_objects[ $price->type() ][] = $price;
210
+				}
211
+			}
212
+			return $array_of_price_objects;
213
+		} else {
214
+			return false;
215
+		}
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 *        _sort_event_prices_by_type
222
+	 *
223
+	 * @access public
224
+	 * @param \EE_Price $price_a
225
+	 * @param \EE_Price $price_b
226
+	 * @return bool false on fail
227
+	 */
228
+	public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b)
229
+	{
230
+		if ($price_a->type_obj()->order() == $price_b->type_obj()->order()) {
231
+			return $this->_sort_event_prices_by_order($price_a, $price_b);
232
+		}
233
+		return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1;
234
+	}
235
+
236
+
237
+
238
+	/**
239
+	 *        _sort_event_prices_by_order
240
+	 *
241
+	 * @access public
242
+	 * @param \EE_Price $price_a
243
+	 * @param \EE_Price $price_b
244
+	 * @return bool false on fail
245
+	 */
246
+	public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b)
247
+	{
248
+		if ($price_a->order() == $price_b->order()) {
249
+			return 0;
250
+		}
251
+		return $price_a->order() < $price_b->order() ? -1 : 1;
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 *      get all prices of a specific type
258
+	 *
259
+	 *      @access     public
260
+	 *      @param      int                 $type - PRT_ID
261
+	 *      @return         boolean     false on fail
262
+	 */
263
+	public function get_all_prices_that_are_type($type = 0)
264
+	{
265
+		return $this->get_all(array(
266
+			array(
267
+				'PRT_ID'=>$type
268
+			),
269
+			'order_by'=>$this->_order_by_array_for_get_all_method()
270
+		));
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * Returns an array of the normal 'order_by' query parameter provided to the get_all query.
277
+	 * Of course you don't have to use it, but this is the order we usually want to sort prices by
278
+	 * @return array which can be used like so: $this->get_all(array(array(...where stuff...),'order_by'=>$this->_order_by_array_for_get_all_method()));
279
+	 */
280
+	public function _order_by_array_for_get_all_method()
281
+	{
282
+		return array(
283
+				'PRC_order'=>'ASC',
284
+				'Price_Type.PRT_order'=>'ASC',
285
+				'PRC_ID'=>'ASC'
286
+		);
287
+	}
288 288
 }
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/Prices_List_Table.class.php 2 patches
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -16,220 +16,220 @@
 block discarded – undo
16 16
 class Prices_List_Table extends EE_Admin_List_Table
17 17
 {
18 18
 
19
-    private $_PRT;
20
-
21
-    /**
22
-     * Array of price types.
23
-     *
24
-     * @var EE_Price_Type[]
25
-     */
26
-    protected $_price_types = array();
27
-
28
-    public function __construct($admin_page)
29
-    {
30
-        parent::__construct($admin_page);
31
-        require_once(EE_MODELS . 'EEM_Price_Type.model.php');
32
-        $this->_PRT = EEM_Price_Type::instance();
33
-        $this->_price_types = $this->_PRT->get_all_deleted_and_undeleted();
34
-    }
35
-
36
-
37
-    protected function _setup_data()
38
-    {
39
-        $trashed = $this->_admin_page->get_view() == 'trashed' ? true : false;
40
-        $this->_data = $this->_admin_page->get_prices_overview_data($this->_per_page, false, $trashed);
41
-        $this->_all_data_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, false);
42
-        $this->_trashed_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, true);
43
-    }
44
-
45
-
46
-    protected function _set_properties()
47
-    {
48
-        $this->_wp_list_args = array(
49
-            'singular' => __('price', 'event_espresso'),
50
-            'plural'   => __('prices', 'event_espresso'),
51
-            'ajax'     => true,
52
-            'screen'   => $this->_admin_page->get_current_screen()->id,
53
-        );
54
-
55
-        $this->_columns = array(
56
-            'cb'          => '<input type="checkbox" />', // Render a checkbox instead of text
57
-            'name'        => __('Name', 'event_espresso'),
58
-            'type'        => __('Price Type', 'event_espresso'),
59
-            'description' => __('Description', 'event_espresso'),
60
-            'amount'      => __('Amount', 'event_espresso'),
61
-        );
62
-
63
-        $this->_sortable_columns = array(
64
-            // true means its already sorted
65
-            'name'   => array('name' => false),
66
-            'type'   => array('type' => false),
67
-            'amount' => array('amount' => false),
68
-        );
69
-
70
-        $this->_hidden_columns = array();
71
-
72
-        $this->_ajax_sorting_callback = 'update_prices_order';
73
-    }
74
-
75
-
76
-    protected function _get_table_filters()
77
-    {
78
-    }
79
-
80
-
81
-    protected function _add_view_counts()
82
-    {
83
-        $this->_views['all']['count'] = $this->_all_data_count;
84
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) {
85
-            $this->_views['trashed']['count'] = $this->_trashed_count;
86
-        }
87
-    }
88
-
89
-
90
-    /**
91
-     * overriding parent method so that we can make sure the row isn't sortable for certain items
92
-     *
93
-     * @param  object $item the current item
94
-     * @return string
95
-     */
96
-    protected function _get_row_class($item)
97
-    {
98
-        static $row_class = '';
99
-        $row_class = ($row_class == '' ? 'alternate' : '');
100
-
101
-        $new_row = $row_class;
102
-
103
-        if ($item->type_obj()->base_type() !== 1 && $item->type_obj()->base_type() !== 4) {
104
-            $new_row .= ' rowsortable';
105
-        }
106
-
107
-        return ' class="' . $new_row . '"';
108
-    }
109
-
110
-
111
-    public function column_cb($item)
112
-    {
113
-        if ($item->type_obj()->base_type() !== 1) {
114
-            return sprintf(
115
-                '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />',
116
-                $item->ID()
117
-            );
118
-        }
119
-        return '';
120
-    }
121
-
122
-
123
-    public function column_name($item)
124
-    {
125
-
126
-        // Build row actions
127
-        $actions = array();
128
-        // edit price link
129
-        if (EE_Registry::instance()->CAP->current_user_can(
130
-            'ee_edit_default_price',
131
-            'pricing_edit_price',
132
-            $item->ID()
133
-        )) {
134
-            $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
135
-                'action' => 'edit_price',
136
-                'id'     => $item->ID(),
137
-            ), PRICING_ADMIN_URL);
138
-            $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="'
139
-                               . esc_attr__('Edit Price', 'event_espresso') . '">'
140
-                               . __('Edit', 'event_espresso') . '</a>';
141
-        }
142
-
143
-        $name_link = EE_Registry::instance()->CAP->current_user_can(
144
-            'ee_edit_default_price',
145
-            'edit_price',
146
-            $item->ID()
147
-        )
148
-            ? '<a href="' . $edit_lnk_url . '" title="'
149
-              . esc_attr__('Edit Price', 'event_espresso') . '">'
150
-              . stripslashes($item->name()) . '</a>'
151
-            : $item->name();
152
-
153
-        if ($item->type_obj()->base_type() !== 1) {
154
-            if ($this->_view == 'all') {
155
-                // trash price link
156
-                if (EE_Registry::instance()->CAP->current_user_can(
157
-                    'ee_delete_default_price',
158
-                    'pricing_trash_price',
159
-                    $item->ID()
160
-                )) {
161
-                    $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
162
-                        'action'   => 'trash_price',
163
-                        'id'       => $item->ID(),
164
-                        'noheader' => true,
165
-                    ), PRICING_ADMIN_URL);
166
-                    $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="'
167
-                                        . esc_attr__('Move Price to Trash', 'event_espresso') . '">'
168
-                                        . __('Move to Trash', 'event_espresso') . '</a>';
169
-                }
170
-            } else {
171
-                if (EE_Registry::instance()->CAP->current_user_can(
172
-                    'ee_delete_default_price',
173
-                    'pricing_restore_price',
174
-                    $item->ID()
175
-                )) {
176
-                    // restore price link
177
-                    $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
178
-                        'action'   => 'restore_price',
179
-                        'id'       => $item->ID(),
180
-                        'noheader' => true,
181
-                    ), PRICING_ADMIN_URL);
182
-                    $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="'
183
-                                          . esc_attr__('Restore Price', 'event_espresso') . '">'
184
-                                          . __('Restore', 'event_espresso') . '</a>';
185
-                }
186
-
187
-                // delete price link
188
-                if (EE_Registry::instance()->CAP->current_user_can(
189
-                    'ee_delete_default_price',
190
-                    'pricing_delete_price',
191
-                    $item->ID()
192
-                )) {
193
-                    $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
194
-                        'action'   => 'delete_price',
195
-                        'id'       => $item->ID(),
196
-                        'noheader' => true,
197
-                    ), PRICING_ADMIN_URL);
198
-                    $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="'
199
-                                         . esc_attr__('Delete Price Permanently', 'event_espresso') . '">'
200
-                                         . __('Delete Permanently', 'event_espresso') . '</a>';
201
-                }
202
-            }
203
-        }
204
-
205
-        // Return the name contents
206
-        return sprintf(
207
-            '%1$s <span style="color:silver">(id:%2$s)</span>%3$s',
208
-            $name_link,
209
-            $item->ID(),
210
-            $this->row_actions($actions)
211
-        );
212
-    }
213
-
214
-
215
-    public function column_type($item)
216
-    {
217
-        return $this->_price_types[ $item->type() ]->name();
218
-    }
219
-
220
-
221
-    public function column_description($item)
222
-    {
223
-        return stripslashes($item->desc());
224
-    }
225
-
226
-
227
-    public function column_amount($item)
228
-    {
229
-        if ($this->_price_types[ $item->type() ]->is_percent()) {
230
-            return '<div class="pad-amnt-rght">' . $item->amount() . '%</div>';
231
-        } else {
232
-            return '<div class="pad-amnt-rght">' . EEH_Template::format_currency($item->amount()) . '</div>';
233
-        }
234
-    }
19
+	private $_PRT;
20
+
21
+	/**
22
+	 * Array of price types.
23
+	 *
24
+	 * @var EE_Price_Type[]
25
+	 */
26
+	protected $_price_types = array();
27
+
28
+	public function __construct($admin_page)
29
+	{
30
+		parent::__construct($admin_page);
31
+		require_once(EE_MODELS . 'EEM_Price_Type.model.php');
32
+		$this->_PRT = EEM_Price_Type::instance();
33
+		$this->_price_types = $this->_PRT->get_all_deleted_and_undeleted();
34
+	}
35
+
36
+
37
+	protected function _setup_data()
38
+	{
39
+		$trashed = $this->_admin_page->get_view() == 'trashed' ? true : false;
40
+		$this->_data = $this->_admin_page->get_prices_overview_data($this->_per_page, false, $trashed);
41
+		$this->_all_data_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, false);
42
+		$this->_trashed_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, true);
43
+	}
44
+
45
+
46
+	protected function _set_properties()
47
+	{
48
+		$this->_wp_list_args = array(
49
+			'singular' => __('price', 'event_espresso'),
50
+			'plural'   => __('prices', 'event_espresso'),
51
+			'ajax'     => true,
52
+			'screen'   => $this->_admin_page->get_current_screen()->id,
53
+		);
54
+
55
+		$this->_columns = array(
56
+			'cb'          => '<input type="checkbox" />', // Render a checkbox instead of text
57
+			'name'        => __('Name', 'event_espresso'),
58
+			'type'        => __('Price Type', 'event_espresso'),
59
+			'description' => __('Description', 'event_espresso'),
60
+			'amount'      => __('Amount', 'event_espresso'),
61
+		);
62
+
63
+		$this->_sortable_columns = array(
64
+			// true means its already sorted
65
+			'name'   => array('name' => false),
66
+			'type'   => array('type' => false),
67
+			'amount' => array('amount' => false),
68
+		);
69
+
70
+		$this->_hidden_columns = array();
71
+
72
+		$this->_ajax_sorting_callback = 'update_prices_order';
73
+	}
74
+
75
+
76
+	protected function _get_table_filters()
77
+	{
78
+	}
79
+
80
+
81
+	protected function _add_view_counts()
82
+	{
83
+		$this->_views['all']['count'] = $this->_all_data_count;
84
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) {
85
+			$this->_views['trashed']['count'] = $this->_trashed_count;
86
+		}
87
+	}
88
+
89
+
90
+	/**
91
+	 * overriding parent method so that we can make sure the row isn't sortable for certain items
92
+	 *
93
+	 * @param  object $item the current item
94
+	 * @return string
95
+	 */
96
+	protected function _get_row_class($item)
97
+	{
98
+		static $row_class = '';
99
+		$row_class = ($row_class == '' ? 'alternate' : '');
100
+
101
+		$new_row = $row_class;
102
+
103
+		if ($item->type_obj()->base_type() !== 1 && $item->type_obj()->base_type() !== 4) {
104
+			$new_row .= ' rowsortable';
105
+		}
106
+
107
+		return ' class="' . $new_row . '"';
108
+	}
109
+
110
+
111
+	public function column_cb($item)
112
+	{
113
+		if ($item->type_obj()->base_type() !== 1) {
114
+			return sprintf(
115
+				'<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />',
116
+				$item->ID()
117
+			);
118
+		}
119
+		return '';
120
+	}
121
+
122
+
123
+	public function column_name($item)
124
+	{
125
+
126
+		// Build row actions
127
+		$actions = array();
128
+		// edit price link
129
+		if (EE_Registry::instance()->CAP->current_user_can(
130
+			'ee_edit_default_price',
131
+			'pricing_edit_price',
132
+			$item->ID()
133
+		)) {
134
+			$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
135
+				'action' => 'edit_price',
136
+				'id'     => $item->ID(),
137
+			), PRICING_ADMIN_URL);
138
+			$actions['edit'] = '<a href="' . $edit_lnk_url . '" title="'
139
+							   . esc_attr__('Edit Price', 'event_espresso') . '">'
140
+							   . __('Edit', 'event_espresso') . '</a>';
141
+		}
142
+
143
+		$name_link = EE_Registry::instance()->CAP->current_user_can(
144
+			'ee_edit_default_price',
145
+			'edit_price',
146
+			$item->ID()
147
+		)
148
+			? '<a href="' . $edit_lnk_url . '" title="'
149
+			  . esc_attr__('Edit Price', 'event_espresso') . '">'
150
+			  . stripslashes($item->name()) . '</a>'
151
+			: $item->name();
152
+
153
+		if ($item->type_obj()->base_type() !== 1) {
154
+			if ($this->_view == 'all') {
155
+				// trash price link
156
+				if (EE_Registry::instance()->CAP->current_user_can(
157
+					'ee_delete_default_price',
158
+					'pricing_trash_price',
159
+					$item->ID()
160
+				)) {
161
+					$trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
162
+						'action'   => 'trash_price',
163
+						'id'       => $item->ID(),
164
+						'noheader' => true,
165
+					), PRICING_ADMIN_URL);
166
+					$actions['trash'] = '<a href="' . $trash_lnk_url . '" title="'
167
+										. esc_attr__('Move Price to Trash', 'event_espresso') . '">'
168
+										. __('Move to Trash', 'event_espresso') . '</a>';
169
+				}
170
+			} else {
171
+				if (EE_Registry::instance()->CAP->current_user_can(
172
+					'ee_delete_default_price',
173
+					'pricing_restore_price',
174
+					$item->ID()
175
+				)) {
176
+					// restore price link
177
+					$restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
178
+						'action'   => 'restore_price',
179
+						'id'       => $item->ID(),
180
+						'noheader' => true,
181
+					), PRICING_ADMIN_URL);
182
+					$actions['restore'] = '<a href="' . $restore_lnk_url . '" title="'
183
+										  . esc_attr__('Restore Price', 'event_espresso') . '">'
184
+										  . __('Restore', 'event_espresso') . '</a>';
185
+				}
186
+
187
+				// delete price link
188
+				if (EE_Registry::instance()->CAP->current_user_can(
189
+					'ee_delete_default_price',
190
+					'pricing_delete_price',
191
+					$item->ID()
192
+				)) {
193
+					$delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
194
+						'action'   => 'delete_price',
195
+						'id'       => $item->ID(),
196
+						'noheader' => true,
197
+					), PRICING_ADMIN_URL);
198
+					$actions['delete'] = '<a href="' . $delete_lnk_url . '" title="'
199
+										 . esc_attr__('Delete Price Permanently', 'event_espresso') . '">'
200
+										 . __('Delete Permanently', 'event_espresso') . '</a>';
201
+				}
202
+			}
203
+		}
204
+
205
+		// Return the name contents
206
+		return sprintf(
207
+			'%1$s <span style="color:silver">(id:%2$s)</span>%3$s',
208
+			$name_link,
209
+			$item->ID(),
210
+			$this->row_actions($actions)
211
+		);
212
+	}
213
+
214
+
215
+	public function column_type($item)
216
+	{
217
+		return $this->_price_types[ $item->type() ]->name();
218
+	}
219
+
220
+
221
+	public function column_description($item)
222
+	{
223
+		return stripslashes($item->desc());
224
+	}
225
+
226
+
227
+	public function column_amount($item)
228
+	{
229
+		if ($this->_price_types[ $item->type() ]->is_percent()) {
230
+			return '<div class="pad-amnt-rght">' . $item->amount() . '%</div>';
231
+		} else {
232
+			return '<div class="pad-amnt-rght">' . EEH_Template::format_currency($item->amount()) . '</div>';
233
+		}
234
+	}
235 235
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
     public function __construct($admin_page)
29 29
     {
30 30
         parent::__construct($admin_page);
31
-        require_once(EE_MODELS . 'EEM_Price_Type.model.php');
31
+        require_once(EE_MODELS.'EEM_Price_Type.model.php');
32 32
         $this->_PRT = EEM_Price_Type::instance();
33 33
         $this->_price_types = $this->_PRT->get_all_deleted_and_undeleted();
34 34
     }
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
             $new_row .= ' rowsortable';
105 105
         }
106 106
 
107
-        return ' class="' . $new_row . '"';
107
+        return ' class="'.$new_row.'"';
108 108
     }
109 109
 
110 110
 
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
                 'action' => 'edit_price',
136 136
                 'id'     => $item->ID(),
137 137
             ), PRICING_ADMIN_URL);
138
-            $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="'
139
-                               . esc_attr__('Edit Price', 'event_espresso') . '">'
140
-                               . __('Edit', 'event_espresso') . '</a>';
138
+            $actions['edit'] = '<a href="'.$edit_lnk_url.'" title="'
139
+                               . esc_attr__('Edit Price', 'event_espresso').'">'
140
+                               . __('Edit', 'event_espresso').'</a>';
141 141
         }
142 142
 
143 143
         $name_link = EE_Registry::instance()->CAP->current_user_can(
@@ -145,9 +145,9 @@  discard block
 block discarded – undo
145 145
             'edit_price',
146 146
             $item->ID()
147 147
         )
148
-            ? '<a href="' . $edit_lnk_url . '" title="'
149
-              . esc_attr__('Edit Price', 'event_espresso') . '">'
150
-              . stripslashes($item->name()) . '</a>'
148
+            ? '<a href="'.$edit_lnk_url.'" title="'
149
+              . esc_attr__('Edit Price', 'event_espresso').'">'
150
+              . stripslashes($item->name()).'</a>'
151 151
             : $item->name();
152 152
 
153 153
         if ($item->type_obj()->base_type() !== 1) {
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
                         'id'       => $item->ID(),
164 164
                         'noheader' => true,
165 165
                     ), PRICING_ADMIN_URL);
166
-                    $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="'
167
-                                        . esc_attr__('Move Price to Trash', 'event_espresso') . '">'
168
-                                        . __('Move to Trash', 'event_espresso') . '</a>';
166
+                    $actions['trash'] = '<a href="'.$trash_lnk_url.'" title="'
167
+                                        . esc_attr__('Move Price to Trash', 'event_espresso').'">'
168
+                                        . __('Move to Trash', 'event_espresso').'</a>';
169 169
                 }
170 170
             } else {
171 171
                 if (EE_Registry::instance()->CAP->current_user_can(
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
                         'id'       => $item->ID(),
180 180
                         'noheader' => true,
181 181
                     ), PRICING_ADMIN_URL);
182
-                    $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="'
183
-                                          . esc_attr__('Restore Price', 'event_espresso') . '">'
184
-                                          . __('Restore', 'event_espresso') . '</a>';
182
+                    $actions['restore'] = '<a href="'.$restore_lnk_url.'" title="'
183
+                                          . esc_attr__('Restore Price', 'event_espresso').'">'
184
+                                          . __('Restore', 'event_espresso').'</a>';
185 185
                 }
186 186
 
187 187
                 // delete price link
@@ -195,9 +195,9 @@  discard block
 block discarded – undo
195 195
                         'id'       => $item->ID(),
196 196
                         'noheader' => true,
197 197
                     ), PRICING_ADMIN_URL);
198
-                    $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="'
199
-                                         . esc_attr__('Delete Price Permanently', 'event_espresso') . '">'
200
-                                         . __('Delete Permanently', 'event_espresso') . '</a>';
198
+                    $actions['delete'] = '<a href="'.$delete_lnk_url.'" title="'
199
+                                         . esc_attr__('Delete Price Permanently', 'event_espresso').'">'
200
+                                         . __('Delete Permanently', 'event_espresso').'</a>';
201 201
                 }
202 202
             }
203 203
         }
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 
215 215
     public function column_type($item)
216 216
     {
217
-        return $this->_price_types[ $item->type() ]->name();
217
+        return $this->_price_types[$item->type()]->name();
218 218
     }
219 219
 
220 220
 
@@ -226,10 +226,10 @@  discard block
 block discarded – undo
226 226
 
227 227
     public function column_amount($item)
228 228
     {
229
-        if ($this->_price_types[ $item->type() ]->is_percent()) {
230
-            return '<div class="pad-amnt-rght">' . $item->amount() . '%</div>';
229
+        if ($this->_price_types[$item->type()]->is_percent()) {
230
+            return '<div class="pad-amnt-rght">'.$item->amount().'%</div>';
231 231
         } else {
232
-            return '<div class="pad-amnt-rght">' . EEH_Template::format_currency($item->amount()) . '</div>';
232
+            return '<div class="pad-amnt-rght">'.EEH_Template::format_currency($item->amount()).'</div>';
233 233
         }
234 234
     }
235 235
 }
Please login to merge, or discard this patch.
libraries/line_item_display/EE_SPCO_Line_Item_Display_Strategy.strategy.php 1 patch
Indentation   +622 added lines, -622 removed lines patch added patch discarded remove patch
@@ -12,626 +12,626 @@
 block discarded – undo
12 12
 class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display
13 13
 {
14 14
 
15
-    /**
16
-     * array of events
17
-     *
18
-     * @type EE_Line_Item[] $_events
19
-     */
20
-    private $_events = array();
21
-
22
-    /**
23
-     * whether to display the taxes row or not
24
-     *
25
-     * @type bool $_show_taxes
26
-     */
27
-    private $_show_taxes = false;
28
-
29
-    /**
30
-     * html for any tax rows
31
-     *
32
-     * @type string $_show_taxes
33
-     */
34
-    private $_taxes_html = '';
35
-
36
-    /**
37
-     * total amount including tax we can bill for at this time
38
-     *
39
-     * @type float $_grand_total
40
-     */
41
-    private $_grand_total = 0.00;
42
-
43
-    /**
44
-     * total number of items being billed for
45
-     *
46
-     * @type int $_total_items
47
-     */
48
-    private $_total_items = 0;
49
-
50
-
51
-
52
-    /**
53
-     * @return float
54
-     */
55
-    public function grand_total()
56
-    {
57
-        return $this->_grand_total;
58
-    }
59
-
60
-
61
-
62
-    /**
63
-     * @return int
64
-     */
65
-    public function total_items()
66
-    {
67
-        return $this->_total_items;
68
-    }
69
-
70
-
71
-
72
-    /**
73
-     * @param EE_Line_Item $line_item
74
-     * @param array        $options
75
-     * @param EE_Line_Item $parent_line_item
76
-     * @return mixed
77
-     * @throws EE_Error
78
-     */
79
-    public function display_line_item(
80
-        EE_Line_Item $line_item,
81
-        $options = array(),
82
-        EE_Line_Item $parent_line_item = null
83
-    ) {
84
-        $html = '';
85
-        // set some default options and merge with incoming
86
-        $default_options = array(
87
-            'show_desc' => true,  //    true        false
88
-            'odd'       => false,
89
-        );
90
-        $options = array_merge($default_options, (array) $options);
91
-        switch ($line_item->type()) {
92
-            case EEM_Line_Item::type_line_item:
93
-                $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
94
-                if ($line_item->OBJ_type() === 'Ticket') {
95
-                    // item row
96
-                    $html .= $this->_ticket_row($line_item, $options);
97
-                } else {
98
-                    // item row
99
-                    $html .= $this->_item_row($line_item, $options);
100
-                }
101
-                if (apply_filters(
102
-                    'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
103
-                    true
104
-                )
105
-                ) {
106
-                    // got any kids?
107
-                    foreach ($line_item->children() as $child_line_item) {
108
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
109
-                    }
110
-                }
111
-                break;
112
-            case EEM_Line_Item::type_sub_line_item:
113
-                $html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
114
-                break;
115
-            case EEM_Line_Item::type_sub_total:
116
-                static $sub_total = 0;
117
-                $event_sub_total = 0;
118
-                $text = esc_html__('Sub-Total', 'event_espresso');
119
-                if ($line_item->OBJ_type() === 'Event') {
120
-                    $options['event_id'] = $event_id = $line_item->OBJ_ID();
121
-                    if (! isset($this->_events[ $options['event_id'] ])) {
122
-                        $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
123
-                        // if event has default reg status of Not Approved, then don't display info on it
124
-                        if ($event instanceof EE_Event
125
-                            && $event->default_registration_status() === EEM_Registration::status_id_not_approved
126
-                        ) {
127
-                            $display_event = false;
128
-                            // unless there are registrations for it that are returning to pay
129
-                            if (isset($options['registrations']) && is_array($options['registrations'])) {
130
-                                foreach ($options['registrations'] as $registration) {
131
-                                    if (! $registration instanceof EE_Registration) {
132
-                                        continue;
133
-                                    }
134
-                                    $display_event = $registration->event_ID() === $options['event_id']
135
-                                                     && $registration->status_ID() !== EEM_Registration::status_id_not_approved
136
-                                        ? true
137
-                                        : $display_event;
138
-                                }
139
-                            }
140
-                            if (! $display_event) {
141
-                                return '';
142
-                            }
143
-                        }
144
-                        $this->_events[ $options['event_id'] ] = 0;
145
-                        $html .= $this->_event_row($line_item);
146
-                        $text = esc_html__('Event Sub-Total', 'event_espresso');
147
-                    }
148
-                }
149
-                $child_line_items = $line_item->children();
150
-                // loop thru children
151
-                foreach ($child_line_items as $child_line_item) {
152
-                    // recursively feed children back into this method
153
-                    $html .= $this->display_line_item($child_line_item, $options, $line_item);
154
-                }
155
-                $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0;
156
-                $sub_total += $event_sub_total;
157
-                if ((
158
-                        // event subtotals
159
-                        $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
160
-                    )
161
-                    || (
162
-                        // pre-tax subtotals
163
-                        $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
164
-                    )
165
-                ) {
166
-                    $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
167
-                    $html .= $this->_sub_total_row($line_item, $text, $options);
168
-                }
169
-                break;
170
-            case EEM_Line_Item::type_tax:
171
-                if ($this->_show_taxes) {
172
-                    $this->_taxes_html .= $this->_tax_row($line_item, $options);
173
-                }
174
-                break;
175
-            case EEM_Line_Item::type_tax_sub_total:
176
-                if ($this->_show_taxes) {
177
-                    $child_line_items = $line_item->children();
178
-                    // loop thru children
179
-                    foreach ($child_line_items as $child_line_item) {
180
-                        // recursively feed children back into this method
181
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
182
-                    }
183
-                    if (count($child_line_items) > 1) {
184
-                        $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
185
-                    }
186
-                }
187
-                break;
188
-            case EEM_Line_Item::type_total:
189
-                // get all child line items
190
-                $children = $line_item->children();
191
-                // loop thru all non-tax child line items
192
-                foreach ($children as $child_line_item) {
193
-                    if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
194
-                        // recursively feed children back into this method
195
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
196
-                    }
197
-                }
198
-                // now loop thru  tax child line items
199
-                foreach ($children as $child_line_item) {
200
-                    if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
201
-                        // recursively feed children back into this method
202
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
203
-                    }
204
-                }
205
-                $html .= $this->_taxes_html;
206
-                $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
207
-                $html .= $this->_payments_and_amount_owing_rows($line_item, $options);
208
-                break;
209
-        }
210
-        return $html;
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * _event_row - basically a Heading row displayed once above each event's ticket rows
217
-     *
218
-     * @param EE_Line_Item $line_item
219
-     * @return mixed
220
-     */
221
-    private function _event_row(EE_Line_Item $line_item)
222
-    {
223
-        // start of row
224
-        $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
225
-        // event name td
226
-        $html .= EEH_HTML::td(
227
-            EEH_HTML::strong($line_item->name()),
228
-            '',
229
-            'event-header',
230
-            '',
231
-            ' colspan="4"'
232
-        );
233
-        // end of row
234
-        $html .= EEH_HTML::trx();
235
-        return $html;
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     * _ticket_row
242
-     *
243
-     * @param EE_Line_Item $line_item
244
-     * @param array        $options
245
-     * @return mixed
246
-     * @throws EE_Error
247
-     */
248
-    private function _ticket_row(EE_Line_Item $line_item, $options = array())
249
-    {
250
-        // start of row
251
-        $row_class = $options['odd'] ? 'item odd' : 'item';
252
-        $html = EEH_HTML::tr('', '', $row_class);
253
-        // name && desc
254
-        $name_and_desc = apply_filters(
255
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
256
-            $line_item->name(),
257
-            $line_item
258
-        );
259
-        $name_and_desc .= apply_filters(
260
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
261
-            (
262
-                $options['show_desc']
263
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
264
-                    : ''
265
-            ),
266
-            $line_item,
267
-            $options
268
-        );
269
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
270
-        // name td
271
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
272
-            $name_and_desc,
273
-            '',
274
-            'item_l'
275
-        );
276
-        // price td
277
-        $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
278
-        // quantity td
279
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
280
-        $this->_total_items += $line_item->quantity();
281
-        // determine total for line item
282
-        $total = $line_item->total();
283
-        $this->_events[ $options['event_id'] ] += $total;
284
-        // total td
285
-        $html .= EEH_HTML::td(
286
-            EEH_Template::format_currency($total, false, false),
287
-            '',
288
-            'item_r jst-rght'
289
-        );
290
-        // end of row
291
-        $html .= EEH_HTML::trx();
292
-        return $html;
293
-    }
294
-
295
-
296
-
297
-    /**
298
-     * _item_row
299
-     *
300
-     * @param EE_Line_Item $line_item
301
-     * @param array        $options
302
-     * @return mixed
303
-     * @throws EE_Error
304
-     */
305
-    private function _item_row(EE_Line_Item $line_item, $options = array())
306
-    {
307
-        // start of row
308
-        $row_class = $options['odd'] ? 'item odd' : 'item';
309
-        $html = EEH_HTML::tr('', '', $row_class);
310
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
311
-        // name && desc
312
-        $name_and_desc = apply_filters(
313
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
314
-            $obj_name . $line_item->name(),
315
-            $line_item
316
-        );
317
-        $name_and_desc .= apply_filters(
318
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
319
-            (
320
-                $options['show_desc']
321
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
322
-                : ''
323
-            ),
324
-            $line_item,
325
-            $options
326
-        );
327
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
328
-        // name td
329
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
330
-        // price td
331
-        if ($line_item->is_percent()) {
332
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
333
-        } else {
334
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
335
-        }
336
-        // quantity td
337
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
338
-        // $total = $line_item->total() * $line_item->quantity();
339
-        $total = $line_item->total();
340
-        if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) {
341
-            $this->_events[ $options['event_id'] ] += $total;
342
-        }
343
-        // total td
344
-        $html .= EEH_HTML::td(
345
-            EEH_Template::format_currency($total, false, false),
346
-            '',
347
-            'item_r jst-rght'
348
-        );
349
-        // end of row
350
-        $html .= EEH_HTML::trx();
351
-        return $html;
352
-    }
353
-
354
-
355
-
356
-    /**
357
-     * _sub_item_row
358
-     *
359
-     * @param EE_Line_Item $line_item
360
-     * @param array        $options
361
-     * @param EE_Line_Item $parent_line_item
362
-     * @return mixed
363
-     * @throws EE_Error
364
-     */
365
-    private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
366
-    {
367
-        if ($parent_line_item instanceof  EE_Line_Item
368
-            && $line_item->children() === array()
369
-            && $line_item->name() === $parent_line_item->name()
370
-            && apply_filters(
371
-                'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item',
372
-                true
373
-            )
374
-        ) {
375
-            return '';
376
-        }
377
-        // start of row
378
-        $html = EEH_HTML::tr('', '', 'item sub-item-row');
379
-        // name && desc
380
-        $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
381
-                         . $line_item->name();
382
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
383
-                                                  . $line_item->desc()
384
-                                                  . '</span>' : '';
385
-        // name td
386
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item');
387
-        $html .= EEH_HTML::td(
388
-                $line_item->prettyUnitPrice(),
389
-            '',
390
-            'item_c jst-rght'
391
-        );
392
-        // no quantity td
393
-        $html .= EEH_HTML::td();
394
-        // no total td
395
-        $html .= EEH_HTML::td();
396
-        // end of row
397
-        $html .= EEH_HTML::trx();
398
-        $html = apply_filters(
399
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html',
400
-            $html,
401
-            $line_item,
402
-            $options,
403
-            $parent_line_item
404
-        );
405
-        return $html;
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * _tax_row
412
-     *
413
-     * @param EE_Line_Item $line_item
414
-     * @param array        $options
415
-     * @return mixed
416
-     * @throws EE_Error
417
-     */
418
-    private function _tax_row(EE_Line_Item $line_item, $options = array())
419
-    {
420
-        // start of row
421
-        $html = EEH_HTML::tr('', 'item sub-item tax-total');
422
-        // name && desc
423
-        $name_and_desc = $line_item->name();
424
-        $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
425
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
426
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
427
-        // name td
428
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
429
-            $name_and_desc,
430
-            '',
431
-            'item_l sub-item'
432
-        );
433
-        // percent td
434
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
435
-        // empty td (price)
436
-        $html .= EEH_HTML::td(EEH_HTML::nbsp());
437
-        // total td
438
-        $html .= EEH_HTML::td(
439
-            EEH_Template::format_currency(
440
-                $line_item->total(),
441
-                false,
442
-                false
443
-            ),
444
-            '',
445
-            'item_r jst-rght'
446
-        );
447
-        // end of row
448
-        $html .= EEH_HTML::trx();
449
-        return $html;
450
-    }
451
-
452
-
453
-
454
-    /**
455
-     * _total_row
456
-     *
457
-     * @param EE_Line_Item $line_item
458
-     * @param string       $text
459
-     * @return mixed
460
-     * @throws EE_Error
461
-     */
462
-    private function _total_tax_row(EE_Line_Item $line_item, $text = '')
463
-    {
464
-        $html = '';
465
-        if ($line_item->total()) {
466
-            // start of row
467
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
468
-            // total td
469
-            $html .= EEH_HTML::td(
470
-                $text,
471
-                '',
472
-                'total_currency total jst-rght',
473
-                '',
474
-                ' colspan="2"'
475
-            );
476
-            // empty td (price)
477
-            $html .= EEH_HTML::td(EEH_HTML::nbsp());
478
-            // total td
479
-            $html .= EEH_HTML::td(
480
-                EEH_Template::format_currency($line_item->total(), false, false),
481
-                '',
482
-                'total jst-rght'
483
-            );
484
-            // end of row
485
-            $html .= EEH_HTML::trx();
486
-        }
487
-        return $html;
488
-    }
489
-
490
-
491
-
492
-    /**
493
-     * _total_row
494
-     *
495
-     * @param EE_Line_Item $line_item
496
-     * @param string       $text
497
-     * @param array        $options
498
-     * @return mixed
499
-     * @throws EE_Error
500
-     */
501
-    private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
502
-    {
503
-        $html = '';
504
-        if ($line_item->total()) {
505
-            // start of row
506
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
507
-            // total td
508
-            $html .= EEH_HTML::td(
509
-                $text,
510
-                '',
511
-                'total_currency total jst-rght',
512
-                '',
513
-                ' colspan="3"'
514
-            );
515
-            // total td
516
-            $html .= EEH_HTML::td(
517
-                EEH_Template::format_currency($options['sub_total'], false, false),
518
-                '',
519
-                'total jst-rght'
520
-            );
521
-            // end of row
522
-            $html .= EEH_HTML::trx();
523
-        }
524
-        return $html;
525
-    }
526
-
527
-
528
-
529
-    /**
530
-     * _total_row
531
-     *
532
-     * @param EE_Line_Item $line_item
533
-     * @param string       $text
534
-     * @return mixed
535
-     * @throws EE_Error
536
-     */
537
-    private function _total_row(EE_Line_Item $line_item, $text = '')
538
-    {
539
-        // start of row
540
-        $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
541
-        // total td
542
-        $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
543
-        // total td
544
-        $html .= EEH_HTML::td(
545
-            EEH_Template::format_currency($line_item->total(), false, false),
546
-            '',
547
-            'total jst-rght'
548
-        );
549
-        // end of row
550
-        $html .= EEH_HTML::trx();
551
-        return $html;
552
-    }
553
-
554
-
555
-
556
-    /**
557
-     * _payments_and_amount_owing_rows
558
-     *
559
-     * @param EE_Line_Item $line_item
560
-     * @param array        $options
561
-     * @return mixed
562
-     * @throws EE_Error
563
-     */
564
-    private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
565
-    {
566
-        $html = '';
567
-        $owing = $line_item->total();
568
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
569
-        if ($transaction instanceof EE_Transaction) {
570
-            $registration_payments = array();
571
-            $registrations = ! empty($options['registrations'])
572
-                ? $options['registrations']
573
-                : $transaction->registrations();
574
-            foreach ($registrations as $registration) {
575
-                if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
576
-                    $registration_payments += $registration->registration_payments();
577
-                }
578
-            }
579
-            if (! empty($registration_payments)) {
580
-                foreach ($registration_payments as $registration_payment) {
581
-                    if ($registration_payment instanceof EE_Registration_Payment) {
582
-                        $owing -= $registration_payment->amount();
583
-                        $payment = $registration_payment->payment();
584
-                        $payment_desc = '';
585
-                        if ($payment instanceof EE_Payment) {
586
-                            $payment_desc = sprintf(
587
-                                esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
588
-                                $payment->txn_id_chq_nmbr() !== ''
589
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
590
-                                    : '',
591
-                                $payment->timestamp()
592
-                            );
593
-                        }
594
-                        // start of row
595
-                        $html .= EEH_HTML::tr('', '', 'total_tr odd');
596
-                        // payment desc
597
-                        $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
598
-                        // total td
599
-                        $html .= EEH_HTML::td(
600
-                            EEH_Template::format_currency(
601
-                                $registration_payment->amount(),
602
-                                false,
603
-                                false
604
-                            ),
605
-                            '',
606
-                            'total jst-rght'
607
-                        );
608
-                        // end of row
609
-                        $html .= EEH_HTML::trx();
610
-                    }
611
-                }
612
-                if ($line_item->total()) {
613
-                    // start of row
614
-                    $html .= EEH_HTML::tr('', '', 'total_tr odd');
615
-                    // total td
616
-                    $html .= EEH_HTML::td(
617
-                        esc_html__('Amount Owing', 'event_espresso'),
618
-                        '',
619
-                        'total_currency total jst-rght',
620
-                        '',
621
-                        ' colspan="3"'
622
-                    );
623
-                    // total td
624
-                    $html .= EEH_HTML::td(
625
-                        EEH_Template::format_currency($owing, false, false),
626
-                        '',
627
-                        'total jst-rght'
628
-                    );
629
-                    // end of row
630
-                    $html .= EEH_HTML::trx();
631
-                }
632
-            }
633
-        }
634
-        $this->_grand_total = $owing;
635
-        return $html;
636
-    }
15
+	/**
16
+	 * array of events
17
+	 *
18
+	 * @type EE_Line_Item[] $_events
19
+	 */
20
+	private $_events = array();
21
+
22
+	/**
23
+	 * whether to display the taxes row or not
24
+	 *
25
+	 * @type bool $_show_taxes
26
+	 */
27
+	private $_show_taxes = false;
28
+
29
+	/**
30
+	 * html for any tax rows
31
+	 *
32
+	 * @type string $_show_taxes
33
+	 */
34
+	private $_taxes_html = '';
35
+
36
+	/**
37
+	 * total amount including tax we can bill for at this time
38
+	 *
39
+	 * @type float $_grand_total
40
+	 */
41
+	private $_grand_total = 0.00;
42
+
43
+	/**
44
+	 * total number of items being billed for
45
+	 *
46
+	 * @type int $_total_items
47
+	 */
48
+	private $_total_items = 0;
49
+
50
+
51
+
52
+	/**
53
+	 * @return float
54
+	 */
55
+	public function grand_total()
56
+	{
57
+		return $this->_grand_total;
58
+	}
59
+
60
+
61
+
62
+	/**
63
+	 * @return int
64
+	 */
65
+	public function total_items()
66
+	{
67
+		return $this->_total_items;
68
+	}
69
+
70
+
71
+
72
+	/**
73
+	 * @param EE_Line_Item $line_item
74
+	 * @param array        $options
75
+	 * @param EE_Line_Item $parent_line_item
76
+	 * @return mixed
77
+	 * @throws EE_Error
78
+	 */
79
+	public function display_line_item(
80
+		EE_Line_Item $line_item,
81
+		$options = array(),
82
+		EE_Line_Item $parent_line_item = null
83
+	) {
84
+		$html = '';
85
+		// set some default options and merge with incoming
86
+		$default_options = array(
87
+			'show_desc' => true,  //    true        false
88
+			'odd'       => false,
89
+		);
90
+		$options = array_merge($default_options, (array) $options);
91
+		switch ($line_item->type()) {
92
+			case EEM_Line_Item::type_line_item:
93
+				$this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
94
+				if ($line_item->OBJ_type() === 'Ticket') {
95
+					// item row
96
+					$html .= $this->_ticket_row($line_item, $options);
97
+				} else {
98
+					// item row
99
+					$html .= $this->_item_row($line_item, $options);
100
+				}
101
+				if (apply_filters(
102
+					'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
103
+					true
104
+				)
105
+				) {
106
+					// got any kids?
107
+					foreach ($line_item->children() as $child_line_item) {
108
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
109
+					}
110
+				}
111
+				break;
112
+			case EEM_Line_Item::type_sub_line_item:
113
+				$html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
114
+				break;
115
+			case EEM_Line_Item::type_sub_total:
116
+				static $sub_total = 0;
117
+				$event_sub_total = 0;
118
+				$text = esc_html__('Sub-Total', 'event_espresso');
119
+				if ($line_item->OBJ_type() === 'Event') {
120
+					$options['event_id'] = $event_id = $line_item->OBJ_ID();
121
+					if (! isset($this->_events[ $options['event_id'] ])) {
122
+						$event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
123
+						// if event has default reg status of Not Approved, then don't display info on it
124
+						if ($event instanceof EE_Event
125
+							&& $event->default_registration_status() === EEM_Registration::status_id_not_approved
126
+						) {
127
+							$display_event = false;
128
+							// unless there are registrations for it that are returning to pay
129
+							if (isset($options['registrations']) && is_array($options['registrations'])) {
130
+								foreach ($options['registrations'] as $registration) {
131
+									if (! $registration instanceof EE_Registration) {
132
+										continue;
133
+									}
134
+									$display_event = $registration->event_ID() === $options['event_id']
135
+													 && $registration->status_ID() !== EEM_Registration::status_id_not_approved
136
+										? true
137
+										: $display_event;
138
+								}
139
+							}
140
+							if (! $display_event) {
141
+								return '';
142
+							}
143
+						}
144
+						$this->_events[ $options['event_id'] ] = 0;
145
+						$html .= $this->_event_row($line_item);
146
+						$text = esc_html__('Event Sub-Total', 'event_espresso');
147
+					}
148
+				}
149
+				$child_line_items = $line_item->children();
150
+				// loop thru children
151
+				foreach ($child_line_items as $child_line_item) {
152
+					// recursively feed children back into this method
153
+					$html .= $this->display_line_item($child_line_item, $options, $line_item);
154
+				}
155
+				$event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0;
156
+				$sub_total += $event_sub_total;
157
+				if ((
158
+						// event subtotals
159
+						$line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
160
+					)
161
+					|| (
162
+						// pre-tax subtotals
163
+						$line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
164
+					)
165
+				) {
166
+					$options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
167
+					$html .= $this->_sub_total_row($line_item, $text, $options);
168
+				}
169
+				break;
170
+			case EEM_Line_Item::type_tax:
171
+				if ($this->_show_taxes) {
172
+					$this->_taxes_html .= $this->_tax_row($line_item, $options);
173
+				}
174
+				break;
175
+			case EEM_Line_Item::type_tax_sub_total:
176
+				if ($this->_show_taxes) {
177
+					$child_line_items = $line_item->children();
178
+					// loop thru children
179
+					foreach ($child_line_items as $child_line_item) {
180
+						// recursively feed children back into this method
181
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
182
+					}
183
+					if (count($child_line_items) > 1) {
184
+						$this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
185
+					}
186
+				}
187
+				break;
188
+			case EEM_Line_Item::type_total:
189
+				// get all child line items
190
+				$children = $line_item->children();
191
+				// loop thru all non-tax child line items
192
+				foreach ($children as $child_line_item) {
193
+					if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
194
+						// recursively feed children back into this method
195
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
196
+					}
197
+				}
198
+				// now loop thru  tax child line items
199
+				foreach ($children as $child_line_item) {
200
+					if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
201
+						// recursively feed children back into this method
202
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
203
+					}
204
+				}
205
+				$html .= $this->_taxes_html;
206
+				$html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
207
+				$html .= $this->_payments_and_amount_owing_rows($line_item, $options);
208
+				break;
209
+		}
210
+		return $html;
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * _event_row - basically a Heading row displayed once above each event's ticket rows
217
+	 *
218
+	 * @param EE_Line_Item $line_item
219
+	 * @return mixed
220
+	 */
221
+	private function _event_row(EE_Line_Item $line_item)
222
+	{
223
+		// start of row
224
+		$html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
225
+		// event name td
226
+		$html .= EEH_HTML::td(
227
+			EEH_HTML::strong($line_item->name()),
228
+			'',
229
+			'event-header',
230
+			'',
231
+			' colspan="4"'
232
+		);
233
+		// end of row
234
+		$html .= EEH_HTML::trx();
235
+		return $html;
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 * _ticket_row
242
+	 *
243
+	 * @param EE_Line_Item $line_item
244
+	 * @param array        $options
245
+	 * @return mixed
246
+	 * @throws EE_Error
247
+	 */
248
+	private function _ticket_row(EE_Line_Item $line_item, $options = array())
249
+	{
250
+		// start of row
251
+		$row_class = $options['odd'] ? 'item odd' : 'item';
252
+		$html = EEH_HTML::tr('', '', $row_class);
253
+		// name && desc
254
+		$name_and_desc = apply_filters(
255
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
256
+			$line_item->name(),
257
+			$line_item
258
+		);
259
+		$name_and_desc .= apply_filters(
260
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
261
+			(
262
+				$options['show_desc']
263
+					? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
264
+					: ''
265
+			),
266
+			$line_item,
267
+			$options
268
+		);
269
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
270
+		// name td
271
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
272
+			$name_and_desc,
273
+			'',
274
+			'item_l'
275
+		);
276
+		// price td
277
+		$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
278
+		// quantity td
279
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
280
+		$this->_total_items += $line_item->quantity();
281
+		// determine total for line item
282
+		$total = $line_item->total();
283
+		$this->_events[ $options['event_id'] ] += $total;
284
+		// total td
285
+		$html .= EEH_HTML::td(
286
+			EEH_Template::format_currency($total, false, false),
287
+			'',
288
+			'item_r jst-rght'
289
+		);
290
+		// end of row
291
+		$html .= EEH_HTML::trx();
292
+		return $html;
293
+	}
294
+
295
+
296
+
297
+	/**
298
+	 * _item_row
299
+	 *
300
+	 * @param EE_Line_Item $line_item
301
+	 * @param array        $options
302
+	 * @return mixed
303
+	 * @throws EE_Error
304
+	 */
305
+	private function _item_row(EE_Line_Item $line_item, $options = array())
306
+	{
307
+		// start of row
308
+		$row_class = $options['odd'] ? 'item odd' : 'item';
309
+		$html = EEH_HTML::tr('', '', $row_class);
310
+		$obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
311
+		// name && desc
312
+		$name_and_desc = apply_filters(
313
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
314
+			$obj_name . $line_item->name(),
315
+			$line_item
316
+		);
317
+		$name_and_desc .= apply_filters(
318
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
319
+			(
320
+				$options['show_desc']
321
+				? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
322
+				: ''
323
+			),
324
+			$line_item,
325
+			$options
326
+		);
327
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
328
+		// name td
329
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l');
330
+		// price td
331
+		if ($line_item->is_percent()) {
332
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
333
+		} else {
334
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
335
+		}
336
+		// quantity td
337
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
338
+		// $total = $line_item->total() * $line_item->quantity();
339
+		$total = $line_item->total();
340
+		if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) {
341
+			$this->_events[ $options['event_id'] ] += $total;
342
+		}
343
+		// total td
344
+		$html .= EEH_HTML::td(
345
+			EEH_Template::format_currency($total, false, false),
346
+			'',
347
+			'item_r jst-rght'
348
+		);
349
+		// end of row
350
+		$html .= EEH_HTML::trx();
351
+		return $html;
352
+	}
353
+
354
+
355
+
356
+	/**
357
+	 * _sub_item_row
358
+	 *
359
+	 * @param EE_Line_Item $line_item
360
+	 * @param array        $options
361
+	 * @param EE_Line_Item $parent_line_item
362
+	 * @return mixed
363
+	 * @throws EE_Error
364
+	 */
365
+	private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
366
+	{
367
+		if ($parent_line_item instanceof  EE_Line_Item
368
+			&& $line_item->children() === array()
369
+			&& $line_item->name() === $parent_line_item->name()
370
+			&& apply_filters(
371
+				'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item',
372
+				true
373
+			)
374
+		) {
375
+			return '';
376
+		}
377
+		// start of row
378
+		$html = EEH_HTML::tr('', '', 'item sub-item-row');
379
+		// name && desc
380
+		$name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
381
+						 . $line_item->name();
382
+		$name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
383
+												  . $line_item->desc()
384
+												  . '</span>' : '';
385
+		// name td
386
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item');
387
+		$html .= EEH_HTML::td(
388
+				$line_item->prettyUnitPrice(),
389
+			'',
390
+			'item_c jst-rght'
391
+		);
392
+		// no quantity td
393
+		$html .= EEH_HTML::td();
394
+		// no total td
395
+		$html .= EEH_HTML::td();
396
+		// end of row
397
+		$html .= EEH_HTML::trx();
398
+		$html = apply_filters(
399
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html',
400
+			$html,
401
+			$line_item,
402
+			$options,
403
+			$parent_line_item
404
+		);
405
+		return $html;
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * _tax_row
412
+	 *
413
+	 * @param EE_Line_Item $line_item
414
+	 * @param array        $options
415
+	 * @return mixed
416
+	 * @throws EE_Error
417
+	 */
418
+	private function _tax_row(EE_Line_Item $line_item, $options = array())
419
+	{
420
+		// start of row
421
+		$html = EEH_HTML::tr('', 'item sub-item tax-total');
422
+		// name && desc
423
+		$name_and_desc = $line_item->name();
424
+		$name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
425
+						  . esc_html__(' * taxable items', 'event_espresso') . '</span>';
426
+		$name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
427
+		// name td
428
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
429
+			$name_and_desc,
430
+			'',
431
+			'item_l sub-item'
432
+		);
433
+		// percent td
434
+		$html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
435
+		// empty td (price)
436
+		$html .= EEH_HTML::td(EEH_HTML::nbsp());
437
+		// total td
438
+		$html .= EEH_HTML::td(
439
+			EEH_Template::format_currency(
440
+				$line_item->total(),
441
+				false,
442
+				false
443
+			),
444
+			'',
445
+			'item_r jst-rght'
446
+		);
447
+		// end of row
448
+		$html .= EEH_HTML::trx();
449
+		return $html;
450
+	}
451
+
452
+
453
+
454
+	/**
455
+	 * _total_row
456
+	 *
457
+	 * @param EE_Line_Item $line_item
458
+	 * @param string       $text
459
+	 * @return mixed
460
+	 * @throws EE_Error
461
+	 */
462
+	private function _total_tax_row(EE_Line_Item $line_item, $text = '')
463
+	{
464
+		$html = '';
465
+		if ($line_item->total()) {
466
+			// start of row
467
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
468
+			// total td
469
+			$html .= EEH_HTML::td(
470
+				$text,
471
+				'',
472
+				'total_currency total jst-rght',
473
+				'',
474
+				' colspan="2"'
475
+			);
476
+			// empty td (price)
477
+			$html .= EEH_HTML::td(EEH_HTML::nbsp());
478
+			// total td
479
+			$html .= EEH_HTML::td(
480
+				EEH_Template::format_currency($line_item->total(), false, false),
481
+				'',
482
+				'total jst-rght'
483
+			);
484
+			// end of row
485
+			$html .= EEH_HTML::trx();
486
+		}
487
+		return $html;
488
+	}
489
+
490
+
491
+
492
+	/**
493
+	 * _total_row
494
+	 *
495
+	 * @param EE_Line_Item $line_item
496
+	 * @param string       $text
497
+	 * @param array        $options
498
+	 * @return mixed
499
+	 * @throws EE_Error
500
+	 */
501
+	private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
502
+	{
503
+		$html = '';
504
+		if ($line_item->total()) {
505
+			// start of row
506
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
507
+			// total td
508
+			$html .= EEH_HTML::td(
509
+				$text,
510
+				'',
511
+				'total_currency total jst-rght',
512
+				'',
513
+				' colspan="3"'
514
+			);
515
+			// total td
516
+			$html .= EEH_HTML::td(
517
+				EEH_Template::format_currency($options['sub_total'], false, false),
518
+				'',
519
+				'total jst-rght'
520
+			);
521
+			// end of row
522
+			$html .= EEH_HTML::trx();
523
+		}
524
+		return $html;
525
+	}
526
+
527
+
528
+
529
+	/**
530
+	 * _total_row
531
+	 *
532
+	 * @param EE_Line_Item $line_item
533
+	 * @param string       $text
534
+	 * @return mixed
535
+	 * @throws EE_Error
536
+	 */
537
+	private function _total_row(EE_Line_Item $line_item, $text = '')
538
+	{
539
+		// start of row
540
+		$html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
541
+		// total td
542
+		$html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
543
+		// total td
544
+		$html .= EEH_HTML::td(
545
+			EEH_Template::format_currency($line_item->total(), false, false),
546
+			'',
547
+			'total jst-rght'
548
+		);
549
+		// end of row
550
+		$html .= EEH_HTML::trx();
551
+		return $html;
552
+	}
553
+
554
+
555
+
556
+	/**
557
+	 * _payments_and_amount_owing_rows
558
+	 *
559
+	 * @param EE_Line_Item $line_item
560
+	 * @param array        $options
561
+	 * @return mixed
562
+	 * @throws EE_Error
563
+	 */
564
+	private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
565
+	{
566
+		$html = '';
567
+		$owing = $line_item->total();
568
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
569
+		if ($transaction instanceof EE_Transaction) {
570
+			$registration_payments = array();
571
+			$registrations = ! empty($options['registrations'])
572
+				? $options['registrations']
573
+				: $transaction->registrations();
574
+			foreach ($registrations as $registration) {
575
+				if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
576
+					$registration_payments += $registration->registration_payments();
577
+				}
578
+			}
579
+			if (! empty($registration_payments)) {
580
+				foreach ($registration_payments as $registration_payment) {
581
+					if ($registration_payment instanceof EE_Registration_Payment) {
582
+						$owing -= $registration_payment->amount();
583
+						$payment = $registration_payment->payment();
584
+						$payment_desc = '';
585
+						if ($payment instanceof EE_Payment) {
586
+							$payment_desc = sprintf(
587
+								esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
588
+								$payment->txn_id_chq_nmbr() !== ''
589
+									? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
590
+									: '',
591
+								$payment->timestamp()
592
+							);
593
+						}
594
+						// start of row
595
+						$html .= EEH_HTML::tr('', '', 'total_tr odd');
596
+						// payment desc
597
+						$html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
598
+						// total td
599
+						$html .= EEH_HTML::td(
600
+							EEH_Template::format_currency(
601
+								$registration_payment->amount(),
602
+								false,
603
+								false
604
+							),
605
+							'',
606
+							'total jst-rght'
607
+						);
608
+						// end of row
609
+						$html .= EEH_HTML::trx();
610
+					}
611
+				}
612
+				if ($line_item->total()) {
613
+					// start of row
614
+					$html .= EEH_HTML::tr('', '', 'total_tr odd');
615
+					// total td
616
+					$html .= EEH_HTML::td(
617
+						esc_html__('Amount Owing', 'event_espresso'),
618
+						'',
619
+						'total_currency total jst-rght',
620
+						'',
621
+						' colspan="3"'
622
+					);
623
+					// total td
624
+					$html .= EEH_HTML::td(
625
+						EEH_Template::format_currency($owing, false, false),
626
+						'',
627
+						'total jst-rght'
628
+					);
629
+					// end of row
630
+					$html .= EEH_HTML::trx();
631
+				}
632
+			}
633
+		}
634
+		$this->_grand_total = $owing;
635
+		return $html;
636
+	}
637 637
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Template.helper.php 2 patches
Indentation   +981 added lines, -981 removed lines patch added patch discarded remove patch
@@ -5,35 +5,35 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\services\loaders\LoaderFactory;
6 6
 
7 7
 if (! function_exists('espresso_get_template_part')) {
8
-    /**
9
-     * espresso_get_template_part
10
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
11
-     * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
12
-     *
13
-     * @param string $slug The slug name for the generic template.
14
-     * @param string $name The name of the specialised template.
15
-     * @return string        the html output for the formatted money value
16
-     */
17
-    function espresso_get_template_part($slug = null, $name = null)
18
-    {
19
-        EEH_Template::get_template_part($slug, $name);
20
-    }
8
+	/**
9
+	 * espresso_get_template_part
10
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
11
+	 * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
12
+	 *
13
+	 * @param string $slug The slug name for the generic template.
14
+	 * @param string $name The name of the specialised template.
15
+	 * @return string        the html output for the formatted money value
16
+	 */
17
+	function espresso_get_template_part($slug = null, $name = null)
18
+	{
19
+		EEH_Template::get_template_part($slug, $name);
20
+	}
21 21
 }
22 22
 
23 23
 
24 24
 if (! function_exists('espresso_get_object_css_class')) {
25
-    /**
26
-     * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27
-     *
28
-     * @param EE_Base_Class $object the EE object the css class is being generated for
29
-     * @param  string       $prefix added to the beginning of the generated class
30
-     * @param  string       $suffix added to the end of the generated class
31
-     * @return string
32
-     */
33
-    function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
34
-    {
35
-        return EEH_Template::get_object_css_class($object, $prefix, $suffix);
36
-    }
25
+	/**
26
+	 * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27
+	 *
28
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
29
+	 * @param  string       $prefix added to the beginning of the generated class
30
+	 * @param  string       $suffix added to the end of the generated class
31
+	 * @return string
32
+	 */
33
+	function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
34
+	{
35
+		return EEH_Template::get_object_css_class($object, $prefix, $suffix);
36
+	}
37 37
 }
38 38
 
39 39
 
@@ -48,691 +48,691 @@  discard block
 block discarded – undo
48 48
 class EEH_Template
49 49
 {
50 50
 
51
-    private static $_espresso_themes = array();
52
-
53
-
54
-    /**
55
-     *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
56
-     *
57
-     * @return boolean
58
-     */
59
-    public static function is_espresso_theme()
60
-    {
61
-        return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false;
62
-    }
63
-
64
-    /**
65
-     *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
66
-     *    load it's functions.php file ( if not already loaded )
67
-     *
68
-     * @return void
69
-     */
70
-    public static function load_espresso_theme_functions()
71
-    {
72
-        if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) {
74
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php');
75
-            }
76
-        }
77
-    }
78
-
79
-
80
-    /**
81
-     *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
82
-     *
83
-     * @return array
84
-     */
85
-    public static function get_espresso_themes()
86
-    {
87
-        if (empty(EEH_Template::$_espresso_themes)) {
88
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
89
-            if (empty($espresso_themes)) {
90
-                return array();
91
-            }
92
-            if (($key = array_search('global_assets', $espresso_themes)) !== false) {
93
-                unset($espresso_themes[ $key ]);
94
-            }
95
-            EEH_Template::$_espresso_themes = array();
96
-            foreach ($espresso_themes as $espresso_theme) {
97
-                EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
98
-            }
99
-        }
100
-        return EEH_Template::$_espresso_themes;
101
-    }
102
-
103
-
104
-    /**
105
-     * EEH_Template::get_template_part
106
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
107
-     * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
108
-     * filtering based off of the entire template part name
109
-     *
110
-     * @param string $slug The slug name for the generic template.
111
-     * @param string $name The name of the specialised template.
112
-     * @param array  $template_args
113
-     * @param bool   $return_string
114
-     * @return string        the html output for the formatted money value
115
-     */
116
-    public static function get_template_part(
117
-        $slug = null,
118
-        $name = null,
119
-        $template_args = array(),
120
-        $return_string = false
121
-    ) {
122
-        do_action("get_template_part_{$slug}-{$name}", $slug, $name);
123
-        $templates = array();
124
-        $name      = (string) $name;
125
-        if ($name != '') {
126
-            $templates[] = "{$slug}-{$name}.php";
127
-        }
128
-        // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
129
-        if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
130
-            EEH_Template::locate_template($templates, $template_args, true, $return_string);
131
-        }
132
-    }
133
-
134
-
135
-    /**
136
-     *    locate_template
137
-     *    locate a template file by looking in the following places, in the following order:
138
-     *        <server path up to>/wp-content/themes/<current active WordPress theme>/
139
-     *        <assumed full absolute server path>
140
-     *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
141
-     *        <server path up to>/wp-content/uploads/espresso/templates/
142
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
143
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
144
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/
145
-     *    as soon as the template is found in one of these locations, it will be returned or loaded
146
-     *        Example:
147
-     *          You are using the WordPress Twenty Sixteen theme,
148
-     *        and you want to customize the "some-event.template.php" template,
149
-     *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
150
-     *          Assuming WP is installed on your server in the "/home/public_html/" folder,
151
-     *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
152
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
153
-     *        /relative/path/to/some-event.template.php
154
-     *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
155
-     *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
156
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
157
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
158
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
159
-     *          Had you passed an absolute path to your template that was in some other location,
160
-     *        ie: "/absolute/path/to/some-event.template.php"
161
-     *          then the search would have been :
162
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
163
-     *        /absolute/path/to/some-event.template.php
164
-     *          and stopped there upon finding it in the second location
165
-     *
166
-     * @param array|string $templates       array of template file names including extension (or just a single string)
167
-     * @param  array       $template_args   an array of arguments to be extracted for use in the template
168
-     * @param  boolean     $load            whether to pass the located template path on to the
169
-     *                                      EEH_Template::display_template() method or simply return it
170
-     * @param  boolean     $return_string   whether to send output immediately to screen, or capture and return as a
171
-     *                                      string
172
-     * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
173
-     *                                      generate a custom template or not. Used in places where you don't actually
174
-     *                                      load the template, you just want to know if there's a custom version of it.
175
-     * @return mixed
176
-     * @throws DomainException
177
-     * @throws InvalidArgumentException
178
-     * @throws InvalidDataTypeException
179
-     * @throws InvalidInterfaceException
180
-     */
181
-    public static function locate_template(
182
-        $templates = array(),
183
-        $template_args = array(),
184
-        $load = true,
185
-        $return_string = true,
186
-        $check_if_custom = false
187
-    ) {
188
-        // first use WP locate_template to check for template in the current theme folder
189
-        $template_path = locate_template($templates);
190
-
191
-        if ($check_if_custom && ! empty($template_path)) {
192
-            return true;
193
-        }
194
-
195
-        // not in the theme
196
-        if (empty($template_path)) {
197
-            // not even a template to look for ?
198
-            if (empty($templates)) {
199
-                // get post_type
200
-                $post_type = EE_Registry::instance()->REQ->get('post_type');
201
-                /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
202
-                $custom_post_types = LoaderFactory::getLoader()->getShared(
203
-                    'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
204
-                );
205
-                // get array of EE Custom Post Types
206
-                $EE_CPTs = $custom_post_types->getDefinitions();
207
-                // build template name based on request
208
-                if (isset($EE_CPTs[ $post_type ])) {
209
-                    $archive_or_single = is_archive() ? 'archive' : '';
210
-                    $archive_or_single = is_single() ? 'single' : $archive_or_single;
211
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
212
-                }
213
-            }
214
-            // currently active EE template theme
215
-            $current_theme = EE_Config::get_current_theme();
216
-
217
-            // array of paths to folders that may contain templates
218
-            $template_folder_paths = array(
219
-                // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
220
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
221
-                // then in the root of the /wp-content/uploads/espresso/templates/ folder
222
-                EVENT_ESPRESSO_TEMPLATE_DIR,
223
-            );
224
-
225
-            // add core plugin folders for checking only if we're not $check_if_custom
226
-            if (! $check_if_custom) {
227
-                $core_paths            = array(
228
-                    // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
229
-                    EE_PUBLIC . $current_theme,
230
-                    // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
231
-                    EE_TEMPLATES . $current_theme,
232
-                    // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
233
-                    EE_PLUGIN_DIR_PATH,
234
-                );
235
-                $template_folder_paths = array_merge($template_folder_paths, $core_paths);
236
-            }
237
-
238
-            // now filter that array
239
-            $template_folder_paths = apply_filters(
240
-                'FHEE__EEH_Template__locate_template__template_folder_paths',
241
-                $template_folder_paths
242
-            );
243
-            $templates             = is_array($templates) ? $templates : array($templates);
244
-            $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
245
-            // array to hold all possible template paths
246
-            $full_template_paths = array();
247
-
248
-            // loop through $templates
249
-            foreach ($templates as $template) {
250
-                // normalize directory separators
251
-                $template                      = EEH_File::standardise_directory_separators($template);
252
-                $file_name                     = basename($template);
253
-                $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
254
-                // while looping through all template folder paths
255
-                foreach ($template_folder_paths as $template_folder_path) {
256
-                    // normalize directory separators
257
-                    $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
258
-                    // determine if any common base path exists between the two paths
259
-                    $common_base_path = EEH_Template::_find_common_base_path(
260
-                        array($template_folder_path, $template_path_minus_file_name)
261
-                    );
262
-                    if ($common_base_path !== '') {
263
-                        // both paths have a common base, so just tack the filename onto our search path
264
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
265
-                    } else {
266
-                        // no common base path, so let's just concatenate
267
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
268
-                    }
269
-                    // build up our template locations array by adding our resolved paths
270
-                    $full_template_paths[] = $resolved_path;
271
-                }
272
-                // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
273
-                array_unshift($full_template_paths, $template);
274
-                // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
275
-                array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name);
276
-            }
277
-            // filter final array of full template paths
278
-            $full_template_paths = apply_filters(
279
-                'FHEE__EEH_Template__locate_template__full_template_paths',
280
-                $full_template_paths,
281
-                $file_name
282
-            );
283
-            // now loop through our final array of template location paths and check each location
284
-            foreach ((array) $full_template_paths as $full_template_path) {
285
-                if (is_readable($full_template_path)) {
286
-                    $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
287
-                    break;
288
-                }
289
-            }
290
-        }
291
-
292
-        // hook that can be used to display the full template path that will be used
293
-        do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
294
-
295
-        // if we got it and you want to see it...
296
-        if ($template_path && $load && ! $check_if_custom) {
297
-            if ($return_string) {
298
-                return EEH_Template::display_template($template_path, $template_args, true);
299
-            } else {
300
-                EEH_Template::display_template($template_path, $template_args, false);
301
-            }
302
-        }
303
-        return $check_if_custom && ! empty($template_path) ? true : $template_path;
304
-    }
305
-
306
-
307
-    /**
308
-     * _find_common_base_path
309
-     * given two paths, this determines if there is a common base path between the two
310
-     *
311
-     * @param array $paths
312
-     * @return string
313
-     */
314
-    protected static function _find_common_base_path($paths)
315
-    {
316
-        $last_offset      = 0;
317
-        $common_base_path = '';
318
-        while (($index = strpos($paths[0], DS, $last_offset)) !== false) {
319
-            $dir_length = $index - $last_offset + 1;
320
-            $directory  = substr($paths[0], $last_offset, $dir_length);
321
-            foreach ($paths as $path) {
322
-                if (substr($path, $last_offset, $dir_length) != $directory) {
323
-                    return $common_base_path;
324
-                }
325
-            }
326
-            $common_base_path .= $directory;
327
-            $last_offset = $index + 1;
328
-        }
329
-        return substr($common_base_path, 0, -1);
330
-    }
331
-
332
-
333
-    /**
334
-     * load and display a template
335
-     *
336
-     * @param bool|string $template_path server path to the file to be loaded, including file name and extension
337
-     * @param  array      $template_args an array of arguments to be extracted for use in the template
338
-     * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
339
-     * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
340
-     *                                      not found or is not readable
341
-     * @return mixed string
342
-     * @throws \DomainException
343
-     */
344
-    public static function display_template(
345
-        $template_path = false,
346
-        $template_args = array(),
347
-        $return_string = false,
348
-        $throw_exceptions = false
349
-    ) {
350
-
351
-        /**
352
-         * These two filters are intended for last minute changes to templates being loaded and/or template arg
353
-         * modifications.  NOTE... modifying these things can cause breakage as most templates running through
354
-         * the display_template method are templates we DON'T want modified (usually because of js
355
-         * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
356
-         * using this.
357
-         *
358
-         * @since 4.6.0
359
-         */
360
-        $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
361
-        $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
362
-
363
-        // you gimme nuttin - YOU GET NUTTIN !!
364
-        if (! $template_path || ! is_readable($template_path)) {
365
-            return '';
366
-        }
367
-        // if $template_args are not in an array, then make it so
368
-        if (! is_array($template_args) && ! is_object($template_args)) {
369
-            $template_args = array($template_args);
370
-        }
371
-        extract($template_args, EXTR_SKIP);
372
-        // ignore whether template is accessible ?
373
-        if ($throw_exceptions && ! is_readable($template_path)) {
374
-            throw new \DomainException(
375
-                esc_html__(
376
-                    'Invalid, unreadable, or missing file.',
377
-                    'event_espresso'
378
-                )
379
-            );
380
-        }
381
-
382
-
383
-        if ($return_string) {
384
-            // because we want to return a string, we are going to capture the output
385
-            ob_start();
386
-            include($template_path);
387
-            return ob_get_clean();
388
-        } else {
389
-            include($template_path);
390
-        }
391
-        return '';
392
-    }
393
-
394
-
395
-    /**
396
-     * get_object_css_class - attempts to generate a css class based on the type of EE object passed
397
-     *
398
-     * @param EE_Base_Class $object the EE object the css class is being generated for
399
-     * @param  string       $prefix added to the beginning of the generated class
400
-     * @param  string       $suffix added to the end of the generated class
401
-     * @return string
402
-     */
403
-    public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
404
-    {
405
-        // in the beginning...
406
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
407
-        // da muddle
408
-        $class = '';
409
-        // the end
410
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
411
-        // is the passed object an EE object ?
412
-        if ($object instanceof EE_Base_Class) {
413
-            // grab the exact type of object
414
-            $obj_class = get_class($object);
415
-            // depending on the type of object...
416
-            switch ($obj_class) {
417
-                // no specifics just yet...
418
-                default:
419
-                    $class = strtolower(str_replace('_', '-', $obj_class));
420
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
421
-            }
422
-        }
423
-        return $prefix . $class . $suffix;
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * EEH_Template::format_currency
430
-     * This helper takes a raw float value and formats it according to the default config country currency settings, or
431
-     * the country currency settings from the supplied country ISO code
432
-     *
433
-     * @param  float   $amount       raw money value
434
-     * @param  boolean $return_raw   whether to return the formatted float value only with no currency sign or code
435
-     * @param  boolean $display_code whether to display the country code (USD). Default = TRUE
436
-     * @param string   $CNT_ISO      2 letter ISO code for a country
437
-     * @param string   $cur_code_span_class
438
-     * @param boolean $allow_partial_pennies whether to allow displaying partial penny amounts
439
-     * @return string        the html output for the formatted money value
440
-     * @throws \EE_Error
441
-     */
442
-    public static function format_currency(
443
-        $amount = null,
444
-        $return_raw = false,
445
-        $display_code = true,
446
-        $CNT_ISO = '',
447
-        $cur_code_span_class = 'currency-code',
448
-        $allow_partial_pennies = false
449
-    ) {
450
-        // ensure amount was received
451
-        if ($amount === null) {
452
-            $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso');
453
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
454
-            return '';
455
-        }
456
-        // ensure amount is float
457
-        $amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
458
-        $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
459
-        // filter raw amount (allows 0.00 to be changed to "free" for example)
460
-        $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
461
-        // still a number or was amount converted to a string like "free" ?
462
-        if (is_float($amount_formatted)) {
463
-            // was a country ISO code passed ? if so generate currency config object for that country
464
-            $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
465
-            // verify results
466
-            if (! $mny instanceof EE_Currency_Config) {
467
-                // set default config country currency settings
468
-                $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
469
-                    ? EE_Registry::instance()->CFG->currency
470
-                    : new EE_Currency_Config();
471
-            }
472
-            // format float
473
-
474
-            $decimal_places_to_use = $mny->dec_plc;
475
-            // If we're allowing showing partial penny amounts, determine how many decimal places to use.
476
-            if($allow_partial_pennies){
477
-                $pos_of_period = strrpos($amount, '.');
478
-                if($pos_of_period !== false) {
479
-                    // Use a max of two extra decimal places (more than that and it starts
480
-                    // to look silly), but at least the normal number of decimal places.
481
-                    $decimal_places_to_use = min(
482
-                            max(
483
-                            strlen($amount) - 1 - strpos($amount, '.'),
484
-                            $decimal_places_to_use
485
-                        ),
486
-                        $decimal_places_to_use + 2
487
-                    );
488
-                }
489
-            }
490
-            $amount_formatted = number_format($amount, $decimal_places_to_use, $mny->dec_mrk, $mny->thsnds);
491
-            // add formatting ?
492
-            if (! $return_raw) {
493
-                // add currency sign
494
-                if ($mny->sign_b4) {
495
-                    if ($amount >= 0) {
496
-                        $amount_formatted = $mny->sign . $amount_formatted;
497
-                    } else {
498
-                        $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
499
-                    }
500
-                } else {
501
-                    $amount_formatted = $amount_formatted . $mny->sign;
502
-                }
503
-
504
-                // filter to allow global setting of display_code
505
-                $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
506
-
507
-                // add currency code ?
508
-                $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
509
-            }
510
-            // filter results
511
-            $amount_formatted = apply_filters(
512
-                'FHEE__EEH_Template__format_currency__amount_formatted',
513
-                $amount_formatted,
514
-                $mny,
515
-                $return_raw
516
-            );
517
-        }
518
-        // clean up vars
519
-        unset($mny);
520
-        // return formatted currency amount
521
-        return $amount_formatted;
522
-    }
523
-
524
-
525
-    /**
526
-     * This function is used for outputting the localized label for a given status id in the schema requested (and
527
-     * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
528
-     * related status model or model object (i.e. in documentation etc.)
529
-     *
530
-     * @param  string  $status_id Status ID matching a registered status in the esp_status table.  If there is no
531
-     *                            match, then 'Unknown' will be returned.
532
-     * @param  boolean $plural    Whether to return plural or not
533
-     * @param  string  $schema    'UPPER', 'lower', or 'Sentence'
534
-     * @return string             The localized label for the status id.
535
-     */
536
-    public static function pretty_status($status_id, $plural = false, $schema = 'upper')
537
-    {
538
-        /** @type EEM_Status $EEM_Status */
539
-        $EEM_Status = EE_Registry::instance()->load_model('Status');
540
-        $status     = $EEM_Status->localized_status(
541
-            array($status_id => __('unknown', 'event_espresso')),
542
-            $plural,
543
-            $schema
544
-        );
545
-        return $status[ $status_id ];
546
-    }
547
-
548
-
549
-    /**
550
-     * This helper just returns a button or link for the given parameters
551
-     *
552
-     * @param  string $url   the url for the link, note that `esc_url` will be called on it
553
-     * @param  string $label What is the label you want displayed for the button
554
-     * @param  string $class what class is used for the button (defaults to 'button-primary')
555
-     * @param string  $icon
556
-     * @param string  $title
557
-     * @return string the html output for the button
558
-     */
559
-    public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
560
-    {
561
-        $icon_html = '';
562
-        if (! empty($icon)) {
563
-            $dashicons = preg_split("(ee-icon |dashicons )", $icon);
564
-            $dashicons = array_filter($dashicons);
565
-            $count     = count($dashicons);
566
-            $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
567
-            foreach ($dashicons as $dashicon) {
568
-                $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
569
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
570
-            }
571
-            $icon_html .= $count > 1 ? '</span>' : '';
572
-        }
573
-        $label  = ! empty($icon) ? $icon_html . $label : $label;
574
-        $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
575
-        return $button;
576
-    }
577
-
578
-
579
-    /**
580
-     * This returns a generated link that will load the related help tab on admin pages.
581
-     *
582
-     * @param  string     $help_tab_id the id for the connected help tab
583
-     * @param bool|string $page        The page identifier for the page the help tab is on
584
-     * @param bool|string $action      The action (route) for the admin page the help tab is on.
585
-     * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
586
-     * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
587
-     * @return string              generated link
588
-     */
589
-    public static function get_help_tab_link(
590
-        $help_tab_id,
591
-        $page = false,
592
-        $action = false,
593
-        $icon_style = false,
594
-        $help_text = false
595
-    ) {
596
-
597
-        if (! $page) {
598
-            $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
599
-        }
600
-
601
-        if (! $action) {
602
-            $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
603
-        }
604
-
605
-        $action = empty($action) ? 'default' : $action;
606
-
607
-
608
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
609
-        $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
610
-        $help_text    = ! $help_text ? '' : $help_text;
611
-        return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__(
612
-            'Click to open the \'Help\' tab for more information about this feature.',
613
-            'event_espresso'
614
-        ) . '" > ' . $help_text . ' </a>';
615
-    }
616
-
617
-
618
-    /**
619
-     * This helper generates the html structure for the jquery joyride plugin with the given params.
620
-     *
621
-     * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
622
-     * @see  EE_Admin_Page->_stop_callback() for the construct expected for the $stops param.
623
-     * @param EE_Help_Tour
624
-     * @return string         html
625
-     */
626
-    public static function help_tour_stops_generator(EE_Help_Tour $tour)
627
-    {
628
-        $id    = $tour->get_slug();
629
-        $stops = $tour->get_stops();
630
-
631
-        $content = '<ol style="display:none" id="' . $id . '">';
632
-
633
-        foreach ($stops as $stop) {
634
-            $data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
635
-            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
636
-
637
-            // if container is set to modal then let's make sure we set the options accordingly
638
-            if (empty($data_id) && empty($data_class)) {
639
-                $stop['options']['modal']  = true;
640
-                $stop['options']['expose'] = true;
641
-            }
642
-
643
-            $custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
644
-            $button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
645
-            $inner_content = isset($stop['content']) ? $stop['content'] : '';
646
-
647
-            // options
648
-            if (isset($stop['options']) && is_array($stop['options'])) {
649
-                $options = ' data-options="';
650
-                foreach ($stop['options'] as $option => $value) {
651
-                    $options .= $option . ':' . $value . ';';
652
-                }
653
-                $options .= '"';
654
-            } else {
655
-                $options = '';
656
-            }
657
-
658
-            // let's put all together
659
-            $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
660
-        }
661
-
662
-        $content .= '</ol>';
663
-        return $content;
664
-    }
665
-
666
-
667
-    /**
668
-     * This is a helper method to generate a status legend for a given status array.
669
-     * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
670
-     * status_array.
671
-     *
672
-     * @param  array  $status_array  array of statuses that will make up the legend. In format:
673
-     *                               array(
674
-     *                               'status_item' => 'status_name'
675
-     *                               )
676
-     * @param  string $active_status This is used to indicate what the active status is IF that is to be highlighted in
677
-     *                               the legend.
678
-     * @throws EE_Error
679
-     * @return string               html structure for status.
680
-     */
681
-    public static function status_legend($status_array, $active_status = '')
682
-    {
683
-        if (! is_array($status_array)) {
684
-            throw new EE_Error(esc_html__(
685
-                'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
686
-                'event_espresso'
687
-            ));
688
-        }
689
-
690
-        $setup_array = array();
691
-        foreach ($status_array as $item => $status) {
692
-            $setup_array[ $item ] = array(
693
-                'class'  => 'ee-status-legend ee-status-legend-' . $status,
694
-                'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
695
-                'status' => $status,
696
-            );
697
-        }
698
-
699
-        $content = '<div class="ee-list-table-legend-container">' . "\n";
700
-        $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
701
-        $content .= '<dl class="ee-list-table-legend">' . "\n\t";
702
-        foreach ($setup_array as $item => $details) {
703
-            $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
704
-            $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
705
-            $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
706
-            $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
707
-            $content .= '</dt>' . "\n";
708
-        }
709
-        $content .= '</dl>' . "\n";
710
-        $content .= '</div>' . "\n";
711
-        return $content;
712
-    }
713
-
714
-
715
-    /**
716
-     * Gets HTML for laying out a deeply-nested array (and objects) in a format
717
-     * that's nice for presenting in the wp admin
718
-     *
719
-     * @param mixed $data
720
-     * @return string
721
-     */
722
-    public static function layout_array_as_table($data)
723
-    {
724
-        if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
725
-            $data = (array) $data;
726
-        }
727
-        ob_start();
728
-        if (is_array($data)) {
729
-            if (EEH_Array::is_associative_array($data)) {
730
-                ?>
51
+	private static $_espresso_themes = array();
52
+
53
+
54
+	/**
55
+	 *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
56
+	 *
57
+	 * @return boolean
58
+	 */
59
+	public static function is_espresso_theme()
60
+	{
61
+		return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false;
62
+	}
63
+
64
+	/**
65
+	 *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
66
+	 *    load it's functions.php file ( if not already loaded )
67
+	 *
68
+	 * @return void
69
+	 */
70
+	public static function load_espresso_theme_functions()
71
+	{
72
+		if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
+			if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) {
74
+				require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php');
75
+			}
76
+		}
77
+	}
78
+
79
+
80
+	/**
81
+	 *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
82
+	 *
83
+	 * @return array
84
+	 */
85
+	public static function get_espresso_themes()
86
+	{
87
+		if (empty(EEH_Template::$_espresso_themes)) {
88
+			$espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
89
+			if (empty($espresso_themes)) {
90
+				return array();
91
+			}
92
+			if (($key = array_search('global_assets', $espresso_themes)) !== false) {
93
+				unset($espresso_themes[ $key ]);
94
+			}
95
+			EEH_Template::$_espresso_themes = array();
96
+			foreach ($espresso_themes as $espresso_theme) {
97
+				EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
98
+			}
99
+		}
100
+		return EEH_Template::$_espresso_themes;
101
+	}
102
+
103
+
104
+	/**
105
+	 * EEH_Template::get_template_part
106
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
107
+	 * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
108
+	 * filtering based off of the entire template part name
109
+	 *
110
+	 * @param string $slug The slug name for the generic template.
111
+	 * @param string $name The name of the specialised template.
112
+	 * @param array  $template_args
113
+	 * @param bool   $return_string
114
+	 * @return string        the html output for the formatted money value
115
+	 */
116
+	public static function get_template_part(
117
+		$slug = null,
118
+		$name = null,
119
+		$template_args = array(),
120
+		$return_string = false
121
+	) {
122
+		do_action("get_template_part_{$slug}-{$name}", $slug, $name);
123
+		$templates = array();
124
+		$name      = (string) $name;
125
+		if ($name != '') {
126
+			$templates[] = "{$slug}-{$name}.php";
127
+		}
128
+		// allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
129
+		if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
130
+			EEH_Template::locate_template($templates, $template_args, true, $return_string);
131
+		}
132
+	}
133
+
134
+
135
+	/**
136
+	 *    locate_template
137
+	 *    locate a template file by looking in the following places, in the following order:
138
+	 *        <server path up to>/wp-content/themes/<current active WordPress theme>/
139
+	 *        <assumed full absolute server path>
140
+	 *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
141
+	 *        <server path up to>/wp-content/uploads/espresso/templates/
142
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
143
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
144
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/
145
+	 *    as soon as the template is found in one of these locations, it will be returned or loaded
146
+	 *        Example:
147
+	 *          You are using the WordPress Twenty Sixteen theme,
148
+	 *        and you want to customize the "some-event.template.php" template,
149
+	 *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
150
+	 *          Assuming WP is installed on your server in the "/home/public_html/" folder,
151
+	 *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
152
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
153
+	 *        /relative/path/to/some-event.template.php
154
+	 *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
155
+	 *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
156
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
157
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
158
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
159
+	 *          Had you passed an absolute path to your template that was in some other location,
160
+	 *        ie: "/absolute/path/to/some-event.template.php"
161
+	 *          then the search would have been :
162
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
163
+	 *        /absolute/path/to/some-event.template.php
164
+	 *          and stopped there upon finding it in the second location
165
+	 *
166
+	 * @param array|string $templates       array of template file names including extension (or just a single string)
167
+	 * @param  array       $template_args   an array of arguments to be extracted for use in the template
168
+	 * @param  boolean     $load            whether to pass the located template path on to the
169
+	 *                                      EEH_Template::display_template() method or simply return it
170
+	 * @param  boolean     $return_string   whether to send output immediately to screen, or capture and return as a
171
+	 *                                      string
172
+	 * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
173
+	 *                                      generate a custom template or not. Used in places where you don't actually
174
+	 *                                      load the template, you just want to know if there's a custom version of it.
175
+	 * @return mixed
176
+	 * @throws DomainException
177
+	 * @throws InvalidArgumentException
178
+	 * @throws InvalidDataTypeException
179
+	 * @throws InvalidInterfaceException
180
+	 */
181
+	public static function locate_template(
182
+		$templates = array(),
183
+		$template_args = array(),
184
+		$load = true,
185
+		$return_string = true,
186
+		$check_if_custom = false
187
+	) {
188
+		// first use WP locate_template to check for template in the current theme folder
189
+		$template_path = locate_template($templates);
190
+
191
+		if ($check_if_custom && ! empty($template_path)) {
192
+			return true;
193
+		}
194
+
195
+		// not in the theme
196
+		if (empty($template_path)) {
197
+			// not even a template to look for ?
198
+			if (empty($templates)) {
199
+				// get post_type
200
+				$post_type = EE_Registry::instance()->REQ->get('post_type');
201
+				/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
202
+				$custom_post_types = LoaderFactory::getLoader()->getShared(
203
+					'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
204
+				);
205
+				// get array of EE Custom Post Types
206
+				$EE_CPTs = $custom_post_types->getDefinitions();
207
+				// build template name based on request
208
+				if (isset($EE_CPTs[ $post_type ])) {
209
+					$archive_or_single = is_archive() ? 'archive' : '';
210
+					$archive_or_single = is_single() ? 'single' : $archive_or_single;
211
+					$templates         = $archive_or_single . '-' . $post_type . '.php';
212
+				}
213
+			}
214
+			// currently active EE template theme
215
+			$current_theme = EE_Config::get_current_theme();
216
+
217
+			// array of paths to folders that may contain templates
218
+			$template_folder_paths = array(
219
+				// first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
220
+				EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
221
+				// then in the root of the /wp-content/uploads/espresso/templates/ folder
222
+				EVENT_ESPRESSO_TEMPLATE_DIR,
223
+			);
224
+
225
+			// add core plugin folders for checking only if we're not $check_if_custom
226
+			if (! $check_if_custom) {
227
+				$core_paths            = array(
228
+					// in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
229
+					EE_PUBLIC . $current_theme,
230
+					// in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
231
+					EE_TEMPLATES . $current_theme,
232
+					// or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
233
+					EE_PLUGIN_DIR_PATH,
234
+				);
235
+				$template_folder_paths = array_merge($template_folder_paths, $core_paths);
236
+			}
237
+
238
+			// now filter that array
239
+			$template_folder_paths = apply_filters(
240
+				'FHEE__EEH_Template__locate_template__template_folder_paths',
241
+				$template_folder_paths
242
+			);
243
+			$templates             = is_array($templates) ? $templates : array($templates);
244
+			$template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
245
+			// array to hold all possible template paths
246
+			$full_template_paths = array();
247
+
248
+			// loop through $templates
249
+			foreach ($templates as $template) {
250
+				// normalize directory separators
251
+				$template                      = EEH_File::standardise_directory_separators($template);
252
+				$file_name                     = basename($template);
253
+				$template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
254
+				// while looping through all template folder paths
255
+				foreach ($template_folder_paths as $template_folder_path) {
256
+					// normalize directory separators
257
+					$template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
258
+					// determine if any common base path exists between the two paths
259
+					$common_base_path = EEH_Template::_find_common_base_path(
260
+						array($template_folder_path, $template_path_minus_file_name)
261
+					);
262
+					if ($common_base_path !== '') {
263
+						// both paths have a common base, so just tack the filename onto our search path
264
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
265
+					} else {
266
+						// no common base path, so let's just concatenate
267
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
268
+					}
269
+					// build up our template locations array by adding our resolved paths
270
+					$full_template_paths[] = $resolved_path;
271
+				}
272
+				// if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
273
+				array_unshift($full_template_paths, $template);
274
+				// path to the directory of the current theme: /wp-content/themes/(current WP theme)/
275
+				array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name);
276
+			}
277
+			// filter final array of full template paths
278
+			$full_template_paths = apply_filters(
279
+				'FHEE__EEH_Template__locate_template__full_template_paths',
280
+				$full_template_paths,
281
+				$file_name
282
+			);
283
+			// now loop through our final array of template location paths and check each location
284
+			foreach ((array) $full_template_paths as $full_template_path) {
285
+				if (is_readable($full_template_path)) {
286
+					$template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
287
+					break;
288
+				}
289
+			}
290
+		}
291
+
292
+		// hook that can be used to display the full template path that will be used
293
+		do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
294
+
295
+		// if we got it and you want to see it...
296
+		if ($template_path && $load && ! $check_if_custom) {
297
+			if ($return_string) {
298
+				return EEH_Template::display_template($template_path, $template_args, true);
299
+			} else {
300
+				EEH_Template::display_template($template_path, $template_args, false);
301
+			}
302
+		}
303
+		return $check_if_custom && ! empty($template_path) ? true : $template_path;
304
+	}
305
+
306
+
307
+	/**
308
+	 * _find_common_base_path
309
+	 * given two paths, this determines if there is a common base path between the two
310
+	 *
311
+	 * @param array $paths
312
+	 * @return string
313
+	 */
314
+	protected static function _find_common_base_path($paths)
315
+	{
316
+		$last_offset      = 0;
317
+		$common_base_path = '';
318
+		while (($index = strpos($paths[0], DS, $last_offset)) !== false) {
319
+			$dir_length = $index - $last_offset + 1;
320
+			$directory  = substr($paths[0], $last_offset, $dir_length);
321
+			foreach ($paths as $path) {
322
+				if (substr($path, $last_offset, $dir_length) != $directory) {
323
+					return $common_base_path;
324
+				}
325
+			}
326
+			$common_base_path .= $directory;
327
+			$last_offset = $index + 1;
328
+		}
329
+		return substr($common_base_path, 0, -1);
330
+	}
331
+
332
+
333
+	/**
334
+	 * load and display a template
335
+	 *
336
+	 * @param bool|string $template_path server path to the file to be loaded, including file name and extension
337
+	 * @param  array      $template_args an array of arguments to be extracted for use in the template
338
+	 * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
339
+	 * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
340
+	 *                                      not found or is not readable
341
+	 * @return mixed string
342
+	 * @throws \DomainException
343
+	 */
344
+	public static function display_template(
345
+		$template_path = false,
346
+		$template_args = array(),
347
+		$return_string = false,
348
+		$throw_exceptions = false
349
+	) {
350
+
351
+		/**
352
+		 * These two filters are intended for last minute changes to templates being loaded and/or template arg
353
+		 * modifications.  NOTE... modifying these things can cause breakage as most templates running through
354
+		 * the display_template method are templates we DON'T want modified (usually because of js
355
+		 * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
356
+		 * using this.
357
+		 *
358
+		 * @since 4.6.0
359
+		 */
360
+		$template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
361
+		$template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
362
+
363
+		// you gimme nuttin - YOU GET NUTTIN !!
364
+		if (! $template_path || ! is_readable($template_path)) {
365
+			return '';
366
+		}
367
+		// if $template_args are not in an array, then make it so
368
+		if (! is_array($template_args) && ! is_object($template_args)) {
369
+			$template_args = array($template_args);
370
+		}
371
+		extract($template_args, EXTR_SKIP);
372
+		// ignore whether template is accessible ?
373
+		if ($throw_exceptions && ! is_readable($template_path)) {
374
+			throw new \DomainException(
375
+				esc_html__(
376
+					'Invalid, unreadable, or missing file.',
377
+					'event_espresso'
378
+				)
379
+			);
380
+		}
381
+
382
+
383
+		if ($return_string) {
384
+			// because we want to return a string, we are going to capture the output
385
+			ob_start();
386
+			include($template_path);
387
+			return ob_get_clean();
388
+		} else {
389
+			include($template_path);
390
+		}
391
+		return '';
392
+	}
393
+
394
+
395
+	/**
396
+	 * get_object_css_class - attempts to generate a css class based on the type of EE object passed
397
+	 *
398
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
399
+	 * @param  string       $prefix added to the beginning of the generated class
400
+	 * @param  string       $suffix added to the end of the generated class
401
+	 * @return string
402
+	 */
403
+	public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
404
+	{
405
+		// in the beginning...
406
+		$prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
407
+		// da muddle
408
+		$class = '';
409
+		// the end
410
+		$suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
411
+		// is the passed object an EE object ?
412
+		if ($object instanceof EE_Base_Class) {
413
+			// grab the exact type of object
414
+			$obj_class = get_class($object);
415
+			// depending on the type of object...
416
+			switch ($obj_class) {
417
+				// no specifics just yet...
418
+				default:
419
+					$class = strtolower(str_replace('_', '-', $obj_class));
420
+					$class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
421
+			}
422
+		}
423
+		return $prefix . $class . $suffix;
424
+	}
425
+
426
+
427
+
428
+	/**
429
+	 * EEH_Template::format_currency
430
+	 * This helper takes a raw float value and formats it according to the default config country currency settings, or
431
+	 * the country currency settings from the supplied country ISO code
432
+	 *
433
+	 * @param  float   $amount       raw money value
434
+	 * @param  boolean $return_raw   whether to return the formatted float value only with no currency sign or code
435
+	 * @param  boolean $display_code whether to display the country code (USD). Default = TRUE
436
+	 * @param string   $CNT_ISO      2 letter ISO code for a country
437
+	 * @param string   $cur_code_span_class
438
+	 * @param boolean $allow_partial_pennies whether to allow displaying partial penny amounts
439
+	 * @return string        the html output for the formatted money value
440
+	 * @throws \EE_Error
441
+	 */
442
+	public static function format_currency(
443
+		$amount = null,
444
+		$return_raw = false,
445
+		$display_code = true,
446
+		$CNT_ISO = '',
447
+		$cur_code_span_class = 'currency-code',
448
+		$allow_partial_pennies = false
449
+	) {
450
+		// ensure amount was received
451
+		if ($amount === null) {
452
+			$msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso');
453
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
454
+			return '';
455
+		}
456
+		// ensure amount is float
457
+		$amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
458
+		$CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
459
+		// filter raw amount (allows 0.00 to be changed to "free" for example)
460
+		$amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
461
+		// still a number or was amount converted to a string like "free" ?
462
+		if (is_float($amount_formatted)) {
463
+			// was a country ISO code passed ? if so generate currency config object for that country
464
+			$mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
465
+			// verify results
466
+			if (! $mny instanceof EE_Currency_Config) {
467
+				// set default config country currency settings
468
+				$mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
469
+					? EE_Registry::instance()->CFG->currency
470
+					: new EE_Currency_Config();
471
+			}
472
+			// format float
473
+
474
+			$decimal_places_to_use = $mny->dec_plc;
475
+			// If we're allowing showing partial penny amounts, determine how many decimal places to use.
476
+			if($allow_partial_pennies){
477
+				$pos_of_period = strrpos($amount, '.');
478
+				if($pos_of_period !== false) {
479
+					// Use a max of two extra decimal places (more than that and it starts
480
+					// to look silly), but at least the normal number of decimal places.
481
+					$decimal_places_to_use = min(
482
+							max(
483
+							strlen($amount) - 1 - strpos($amount, '.'),
484
+							$decimal_places_to_use
485
+						),
486
+						$decimal_places_to_use + 2
487
+					);
488
+				}
489
+			}
490
+			$amount_formatted = number_format($amount, $decimal_places_to_use, $mny->dec_mrk, $mny->thsnds);
491
+			// add formatting ?
492
+			if (! $return_raw) {
493
+				// add currency sign
494
+				if ($mny->sign_b4) {
495
+					if ($amount >= 0) {
496
+						$amount_formatted = $mny->sign . $amount_formatted;
497
+					} else {
498
+						$amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
499
+					}
500
+				} else {
501
+					$amount_formatted = $amount_formatted . $mny->sign;
502
+				}
503
+
504
+				// filter to allow global setting of display_code
505
+				$display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
506
+
507
+				// add currency code ?
508
+				$amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
509
+			}
510
+			// filter results
511
+			$amount_formatted = apply_filters(
512
+				'FHEE__EEH_Template__format_currency__amount_formatted',
513
+				$amount_formatted,
514
+				$mny,
515
+				$return_raw
516
+			);
517
+		}
518
+		// clean up vars
519
+		unset($mny);
520
+		// return formatted currency amount
521
+		return $amount_formatted;
522
+	}
523
+
524
+
525
+	/**
526
+	 * This function is used for outputting the localized label for a given status id in the schema requested (and
527
+	 * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
528
+	 * related status model or model object (i.e. in documentation etc.)
529
+	 *
530
+	 * @param  string  $status_id Status ID matching a registered status in the esp_status table.  If there is no
531
+	 *                            match, then 'Unknown' will be returned.
532
+	 * @param  boolean $plural    Whether to return plural or not
533
+	 * @param  string  $schema    'UPPER', 'lower', or 'Sentence'
534
+	 * @return string             The localized label for the status id.
535
+	 */
536
+	public static function pretty_status($status_id, $plural = false, $schema = 'upper')
537
+	{
538
+		/** @type EEM_Status $EEM_Status */
539
+		$EEM_Status = EE_Registry::instance()->load_model('Status');
540
+		$status     = $EEM_Status->localized_status(
541
+			array($status_id => __('unknown', 'event_espresso')),
542
+			$plural,
543
+			$schema
544
+		);
545
+		return $status[ $status_id ];
546
+	}
547
+
548
+
549
+	/**
550
+	 * This helper just returns a button or link for the given parameters
551
+	 *
552
+	 * @param  string $url   the url for the link, note that `esc_url` will be called on it
553
+	 * @param  string $label What is the label you want displayed for the button
554
+	 * @param  string $class what class is used for the button (defaults to 'button-primary')
555
+	 * @param string  $icon
556
+	 * @param string  $title
557
+	 * @return string the html output for the button
558
+	 */
559
+	public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
560
+	{
561
+		$icon_html = '';
562
+		if (! empty($icon)) {
563
+			$dashicons = preg_split("(ee-icon |dashicons )", $icon);
564
+			$dashicons = array_filter($dashicons);
565
+			$count     = count($dashicons);
566
+			$icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
567
+			foreach ($dashicons as $dashicon) {
568
+				$type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
569
+				$icon_html .= '<span class="' . $type . $dashicon . '"></span>';
570
+			}
571
+			$icon_html .= $count > 1 ? '</span>' : '';
572
+		}
573
+		$label  = ! empty($icon) ? $icon_html . $label : $label;
574
+		$button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
575
+		return $button;
576
+	}
577
+
578
+
579
+	/**
580
+	 * This returns a generated link that will load the related help tab on admin pages.
581
+	 *
582
+	 * @param  string     $help_tab_id the id for the connected help tab
583
+	 * @param bool|string $page        The page identifier for the page the help tab is on
584
+	 * @param bool|string $action      The action (route) for the admin page the help tab is on.
585
+	 * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
586
+	 * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
587
+	 * @return string              generated link
588
+	 */
589
+	public static function get_help_tab_link(
590
+		$help_tab_id,
591
+		$page = false,
592
+		$action = false,
593
+		$icon_style = false,
594
+		$help_text = false
595
+	) {
596
+
597
+		if (! $page) {
598
+			$page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
599
+		}
600
+
601
+		if (! $action) {
602
+			$action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
603
+		}
604
+
605
+		$action = empty($action) ? 'default' : $action;
606
+
607
+
608
+		$help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
609
+		$icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
610
+		$help_text    = ! $help_text ? '' : $help_text;
611
+		return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__(
612
+			'Click to open the \'Help\' tab for more information about this feature.',
613
+			'event_espresso'
614
+		) . '" > ' . $help_text . ' </a>';
615
+	}
616
+
617
+
618
+	/**
619
+	 * This helper generates the html structure for the jquery joyride plugin with the given params.
620
+	 *
621
+	 * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
622
+	 * @see  EE_Admin_Page->_stop_callback() for the construct expected for the $stops param.
623
+	 * @param EE_Help_Tour
624
+	 * @return string         html
625
+	 */
626
+	public static function help_tour_stops_generator(EE_Help_Tour $tour)
627
+	{
628
+		$id    = $tour->get_slug();
629
+		$stops = $tour->get_stops();
630
+
631
+		$content = '<ol style="display:none" id="' . $id . '">';
632
+
633
+		foreach ($stops as $stop) {
634
+			$data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
635
+			$data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
636
+
637
+			// if container is set to modal then let's make sure we set the options accordingly
638
+			if (empty($data_id) && empty($data_class)) {
639
+				$stop['options']['modal']  = true;
640
+				$stop['options']['expose'] = true;
641
+			}
642
+
643
+			$custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
644
+			$button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
645
+			$inner_content = isset($stop['content']) ? $stop['content'] : '';
646
+
647
+			// options
648
+			if (isset($stop['options']) && is_array($stop['options'])) {
649
+				$options = ' data-options="';
650
+				foreach ($stop['options'] as $option => $value) {
651
+					$options .= $option . ':' . $value . ';';
652
+				}
653
+				$options .= '"';
654
+			} else {
655
+				$options = '';
656
+			}
657
+
658
+			// let's put all together
659
+			$content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
660
+		}
661
+
662
+		$content .= '</ol>';
663
+		return $content;
664
+	}
665
+
666
+
667
+	/**
668
+	 * This is a helper method to generate a status legend for a given status array.
669
+	 * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
670
+	 * status_array.
671
+	 *
672
+	 * @param  array  $status_array  array of statuses that will make up the legend. In format:
673
+	 *                               array(
674
+	 *                               'status_item' => 'status_name'
675
+	 *                               )
676
+	 * @param  string $active_status This is used to indicate what the active status is IF that is to be highlighted in
677
+	 *                               the legend.
678
+	 * @throws EE_Error
679
+	 * @return string               html structure for status.
680
+	 */
681
+	public static function status_legend($status_array, $active_status = '')
682
+	{
683
+		if (! is_array($status_array)) {
684
+			throw new EE_Error(esc_html__(
685
+				'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
686
+				'event_espresso'
687
+			));
688
+		}
689
+
690
+		$setup_array = array();
691
+		foreach ($status_array as $item => $status) {
692
+			$setup_array[ $item ] = array(
693
+				'class'  => 'ee-status-legend ee-status-legend-' . $status,
694
+				'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
695
+				'status' => $status,
696
+			);
697
+		}
698
+
699
+		$content = '<div class="ee-list-table-legend-container">' . "\n";
700
+		$content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
701
+		$content .= '<dl class="ee-list-table-legend">' . "\n\t";
702
+		foreach ($setup_array as $item => $details) {
703
+			$active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
704
+			$content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
705
+			$content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
706
+			$content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
707
+			$content .= '</dt>' . "\n";
708
+		}
709
+		$content .= '</dl>' . "\n";
710
+		$content .= '</div>' . "\n";
711
+		return $content;
712
+	}
713
+
714
+
715
+	/**
716
+	 * Gets HTML for laying out a deeply-nested array (and objects) in a format
717
+	 * that's nice for presenting in the wp admin
718
+	 *
719
+	 * @param mixed $data
720
+	 * @return string
721
+	 */
722
+	public static function layout_array_as_table($data)
723
+	{
724
+		if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
725
+			$data = (array) $data;
726
+		}
727
+		ob_start();
728
+		if (is_array($data)) {
729
+			if (EEH_Array::is_associative_array($data)) {
730
+				?>
731 731
                 <table class="widefat">
732 732
                     <tbody>
733 733
                     <?php
734
-                    foreach ($data as $data_key => $data_values) {
735
-                        ?>
734
+					foreach ($data as $data_key => $data_values) {
735
+						?>
736 736
                         <tr>
737 737
                             <td>
738 738
                                 <?php echo $data_key; ?>
@@ -742,291 +742,291 @@  discard block
 block discarded – undo
742 742
                             </td>
743 743
                         </tr>
744 744
                         <?php
745
-                    } ?>
745
+					} ?>
746 746
                     </tbody>
747 747
                 </table>
748 748
                 <?php
749
-            } else {
750
-                ?>
749
+			} else {
750
+				?>
751 751
                 <ul>
752 752
                     <?php
753
-                    foreach ($data as $datum) {
754
-                        echo "<li>";
755
-                        echo self::layout_array_as_table($datum);
756
-                        echo "</li>";
757
-                    } ?>
753
+					foreach ($data as $datum) {
754
+						echo "<li>";
755
+						echo self::layout_array_as_table($datum);
756
+						echo "</li>";
757
+					} ?>
758 758
                 </ul>
759 759
                 <?php
760
-            }
761
-        } else {
762
-            // simple value
763
-            echo esc_html($data);
764
-        }
765
-        return ob_get_clean();
766
-    }
767
-
768
-
769
-    /**
770
-     * wrapper for self::get_paging_html() that simply echos the generated paging html
771
-     *
772
-     * @since 4.4.0
773
-     * @see   self:get_paging_html() for argument docs.
774
-     * @param        $total_items
775
-     * @param        $current
776
-     * @param        $per_page
777
-     * @param        $url
778
-     * @param bool   $show_num_field
779
-     * @param string $paged_arg_name
780
-     * @param array  $items_label
781
-     * @return string
782
-     */
783
-    public static function paging_html(
784
-        $total_items,
785
-        $current,
786
-        $per_page,
787
-        $url,
788
-        $show_num_field = true,
789
-        $paged_arg_name = 'paged',
790
-        $items_label = array()
791
-    ) {
792
-        echo self::get_paging_html(
793
-            $total_items,
794
-            $current,
795
-            $per_page,
796
-            $url,
797
-            $show_num_field,
798
-            $paged_arg_name,
799
-            $items_label
800
-        );
801
-    }
802
-
803
-
804
-    /**
805
-     * A method for generating paging similar to WP_List_Table
806
-     *
807
-     * @since    4.4.0
808
-     * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
809
-     * @param  integer $total_items     How many total items there are to page.
810
-     * @param  integer $current         What the current page is.
811
-     * @param  integer $per_page        How many items per page.
812
-     * @param  string  $url             What the base url for page links is.
813
-     * @param  boolean $show_num_field  Whether to show the input for changing page number.
814
-     * @param  string  $paged_arg_name  The name of the key for the paged query argument.
815
-     * @param  array   $items_label     An array of singular/plural values for the items label:
816
-     *                                  array(
817
-     *                                  'single' => 'item',
818
-     *                                  'plural' => 'items'
819
-     *                                  )
820
-     * @return  string
821
-     */
822
-    public static function get_paging_html(
823
-        $total_items,
824
-        $current,
825
-        $per_page,
826
-        $url,
827
-        $show_num_field = true,
828
-        $paged_arg_name = 'paged',
829
-        $items_label = array()
830
-    ) {
831
-        $page_links     = array();
832
-        $disable_first  = $disable_last = '';
833
-        $total_items    = (int) $total_items;
834
-        $per_page       = (int) $per_page;
835
-        $current        = (int) $current;
836
-        $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
837
-
838
-        // filter items_label
839
-        $items_label = apply_filters(
840
-            'FHEE__EEH_Template__get_paging_html__items_label',
841
-            $items_label
842
-        );
843
-
844
-        if (empty($items_label)
845
-            || ! is_array($items_label)
846
-            || ! isset($items_label['single'])
847
-            || ! isset($items_label['plural'])
848
-        ) {
849
-            $items_label = array(
850
-                'single' => __('1 item', 'event_espresso'),
851
-                'plural' => __('%s items', 'event_espresso'),
852
-            );
853
-        } else {
854
-            $items_label = array(
855
-                'single' => '1 ' . esc_html($items_label['single']),
856
-                'plural' => '%s ' . esc_html($items_label['plural']),
857
-            );
858
-        }
859
-
860
-        $total_pages = ceil($total_items / $per_page);
861
-
862
-        if ($total_pages <= 1) {
863
-            return '';
864
-        }
865
-
866
-        $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
867
-
868
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
869
-
870
-        if ($current === 1) {
871
-            $disable_first = ' disabled';
872
-        }
873
-        if ($current == $total_pages) {
874
-            $disable_last = ' disabled';
875
-        }
876
-
877
-        $page_links[] = sprintf(
878
-            "<a class='%s' title='%s' href='%s'>%s</a>",
879
-            'first-page' . $disable_first,
880
-            esc_attr__('Go to the first page', 'event_espresso'),
881
-            esc_url(remove_query_arg($paged_arg_name, $url)),
882
-            '&laquo;'
883
-        );
884
-
885
-        $page_links[] = sprintf(
886
-            '<a class="%s" title="%s" href="%s">%s</a>',
887
-            'prev-page' . $disable_first,
888
-            esc_attr__('Go to the previous page', 'event_espresso'),
889
-            esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
890
-            '&lsaquo;'
891
-        );
892
-
893
-        if (! $show_num_field) {
894
-            $html_current_page = $current;
895
-        } else {
896
-            $html_current_page = sprintf(
897
-                "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
898
-                esc_attr__('Current page', 'event_espresso'),
899
-                $current,
900
-                strlen($total_pages)
901
-            );
902
-        }
903
-
904
-        $html_total_pages = sprintf(
905
-            '<span class="total-pages">%s</span>',
906
-            number_format_i18n($total_pages)
907
-        );
908
-        $page_links[]     = sprintf(
909
-            _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
910
-            $html_current_page,
911
-            $html_total_pages,
912
-            '<span class="paging-input">',
913
-            '</span>'
914
-        );
915
-
916
-        $page_links[] = sprintf(
917
-            '<a class="%s" title="%s" href="%s">%s</a>',
918
-            'next-page' . $disable_last,
919
-            esc_attr__('Go to the next page', 'event_espresso'),
920
-            esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
921
-            '&rsaquo;'
922
-        );
923
-
924
-        $page_links[] = sprintf(
925
-            '<a class="%s" title="%s" href="%s">%s</a>',
926
-            'last-page' . $disable_last,
927
-            esc_attr__('Go to the last page', 'event_espresso'),
928
-            esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
929
-            '&raquo;'
930
-        );
931
-
932
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
933
-        // set page class
934
-        if ($total_pages) {
935
-            $page_class = $total_pages < 2 ? ' one-page' : '';
936
-        } else {
937
-            $page_class = ' no-pages';
938
-        }
939
-
940
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
941
-    }
942
-
943
-
944
-    /**
945
-     * @param string $wrap_class
946
-     * @param string $wrap_id
947
-     * @return string
948
-     */
949
-    public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
950
-    {
951
-        $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
952
-        if (! $admin &&
953
-            ! apply_filters(
954
-                'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
955
-                EE_Registry::instance()->CFG->admin->show_reg_footer
956
-            )
957
-        ) {
958
-            return '';
959
-        }
960
-        $tag        = $admin ? 'span' : 'div';
961
-        $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
962
-        $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
963
-        $attributes .= ! empty($wrap_class)
964
-            ? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
965
-            : ' class="powered-by-event-espresso-credit"';
966
-        $query_args = array_merge(
967
-            array(
968
-                'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
969
-                'utm_source'   => 'powered_by_event_espresso',
970
-                'utm_medium'   => 'link',
971
-                'utm_campaign' => 'powered_by',
972
-            ),
973
-            $query_args
974
-        );
975
-        $powered_by = apply_filters(
976
-            'FHEE__EEH_Template__powered_by_event_espresso_text',
977
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
978
-        );
979
-        $url        = add_query_arg($query_args, 'https://eventespresso.com/');
980
-        $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
981
-        return (string) apply_filters(
982
-            'FHEE__EEH_Template__powered_by_event_espresso__html',
983
-            sprintf(
984
-                esc_html_x(
985
-                    '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
986
-                    'Online event registration and ticketing powered by [link to eventespresso.com]',
987
-                    'event_espresso'
988
-                ),
989
-                "<{$tag}{$attributes}>",
990
-                "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
991
-                $admin ? '' : '<br />'
992
-            ),
993
-            $wrap_class,
994
-            $wrap_id
995
-        );
996
-    }
760
+			}
761
+		} else {
762
+			// simple value
763
+			echo esc_html($data);
764
+		}
765
+		return ob_get_clean();
766
+	}
767
+
768
+
769
+	/**
770
+	 * wrapper for self::get_paging_html() that simply echos the generated paging html
771
+	 *
772
+	 * @since 4.4.0
773
+	 * @see   self:get_paging_html() for argument docs.
774
+	 * @param        $total_items
775
+	 * @param        $current
776
+	 * @param        $per_page
777
+	 * @param        $url
778
+	 * @param bool   $show_num_field
779
+	 * @param string $paged_arg_name
780
+	 * @param array  $items_label
781
+	 * @return string
782
+	 */
783
+	public static function paging_html(
784
+		$total_items,
785
+		$current,
786
+		$per_page,
787
+		$url,
788
+		$show_num_field = true,
789
+		$paged_arg_name = 'paged',
790
+		$items_label = array()
791
+	) {
792
+		echo self::get_paging_html(
793
+			$total_items,
794
+			$current,
795
+			$per_page,
796
+			$url,
797
+			$show_num_field,
798
+			$paged_arg_name,
799
+			$items_label
800
+		);
801
+	}
802
+
803
+
804
+	/**
805
+	 * A method for generating paging similar to WP_List_Table
806
+	 *
807
+	 * @since    4.4.0
808
+	 * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
809
+	 * @param  integer $total_items     How many total items there are to page.
810
+	 * @param  integer $current         What the current page is.
811
+	 * @param  integer $per_page        How many items per page.
812
+	 * @param  string  $url             What the base url for page links is.
813
+	 * @param  boolean $show_num_field  Whether to show the input for changing page number.
814
+	 * @param  string  $paged_arg_name  The name of the key for the paged query argument.
815
+	 * @param  array   $items_label     An array of singular/plural values for the items label:
816
+	 *                                  array(
817
+	 *                                  'single' => 'item',
818
+	 *                                  'plural' => 'items'
819
+	 *                                  )
820
+	 * @return  string
821
+	 */
822
+	public static function get_paging_html(
823
+		$total_items,
824
+		$current,
825
+		$per_page,
826
+		$url,
827
+		$show_num_field = true,
828
+		$paged_arg_name = 'paged',
829
+		$items_label = array()
830
+	) {
831
+		$page_links     = array();
832
+		$disable_first  = $disable_last = '';
833
+		$total_items    = (int) $total_items;
834
+		$per_page       = (int) $per_page;
835
+		$current        = (int) $current;
836
+		$paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
837
+
838
+		// filter items_label
839
+		$items_label = apply_filters(
840
+			'FHEE__EEH_Template__get_paging_html__items_label',
841
+			$items_label
842
+		);
843
+
844
+		if (empty($items_label)
845
+			|| ! is_array($items_label)
846
+			|| ! isset($items_label['single'])
847
+			|| ! isset($items_label['plural'])
848
+		) {
849
+			$items_label = array(
850
+				'single' => __('1 item', 'event_espresso'),
851
+				'plural' => __('%s items', 'event_espresso'),
852
+			);
853
+		} else {
854
+			$items_label = array(
855
+				'single' => '1 ' . esc_html($items_label['single']),
856
+				'plural' => '%s ' . esc_html($items_label['plural']),
857
+			);
858
+		}
859
+
860
+		$total_pages = ceil($total_items / $per_page);
861
+
862
+		if ($total_pages <= 1) {
863
+			return '';
864
+		}
865
+
866
+		$item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
867
+
868
+		$output = '<span class="displaying-num">' . $item_label . '</span>';
869
+
870
+		if ($current === 1) {
871
+			$disable_first = ' disabled';
872
+		}
873
+		if ($current == $total_pages) {
874
+			$disable_last = ' disabled';
875
+		}
876
+
877
+		$page_links[] = sprintf(
878
+			"<a class='%s' title='%s' href='%s'>%s</a>",
879
+			'first-page' . $disable_first,
880
+			esc_attr__('Go to the first page', 'event_espresso'),
881
+			esc_url(remove_query_arg($paged_arg_name, $url)),
882
+			'&laquo;'
883
+		);
884
+
885
+		$page_links[] = sprintf(
886
+			'<a class="%s" title="%s" href="%s">%s</a>',
887
+			'prev-page' . $disable_first,
888
+			esc_attr__('Go to the previous page', 'event_espresso'),
889
+			esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
890
+			'&lsaquo;'
891
+		);
892
+
893
+		if (! $show_num_field) {
894
+			$html_current_page = $current;
895
+		} else {
896
+			$html_current_page = sprintf(
897
+				"<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
898
+				esc_attr__('Current page', 'event_espresso'),
899
+				$current,
900
+				strlen($total_pages)
901
+			);
902
+		}
903
+
904
+		$html_total_pages = sprintf(
905
+			'<span class="total-pages">%s</span>',
906
+			number_format_i18n($total_pages)
907
+		);
908
+		$page_links[]     = sprintf(
909
+			_x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
910
+			$html_current_page,
911
+			$html_total_pages,
912
+			'<span class="paging-input">',
913
+			'</span>'
914
+		);
915
+
916
+		$page_links[] = sprintf(
917
+			'<a class="%s" title="%s" href="%s">%s</a>',
918
+			'next-page' . $disable_last,
919
+			esc_attr__('Go to the next page', 'event_espresso'),
920
+			esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
921
+			'&rsaquo;'
922
+		);
923
+
924
+		$page_links[] = sprintf(
925
+			'<a class="%s" title="%s" href="%s">%s</a>',
926
+			'last-page' . $disable_last,
927
+			esc_attr__('Go to the last page', 'event_espresso'),
928
+			esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
929
+			'&raquo;'
930
+		);
931
+
932
+		$output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
933
+		// set page class
934
+		if ($total_pages) {
935
+			$page_class = $total_pages < 2 ? ' one-page' : '';
936
+		} else {
937
+			$page_class = ' no-pages';
938
+		}
939
+
940
+		return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
941
+	}
942
+
943
+
944
+	/**
945
+	 * @param string $wrap_class
946
+	 * @param string $wrap_id
947
+	 * @return string
948
+	 */
949
+	public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
950
+	{
951
+		$admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
952
+		if (! $admin &&
953
+			! apply_filters(
954
+				'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
955
+				EE_Registry::instance()->CFG->admin->show_reg_footer
956
+			)
957
+		) {
958
+			return '';
959
+		}
960
+		$tag        = $admin ? 'span' : 'div';
961
+		$attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
962
+		$wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
963
+		$attributes .= ! empty($wrap_class)
964
+			? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
965
+			: ' class="powered-by-event-espresso-credit"';
966
+		$query_args = array_merge(
967
+			array(
968
+				'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
969
+				'utm_source'   => 'powered_by_event_espresso',
970
+				'utm_medium'   => 'link',
971
+				'utm_campaign' => 'powered_by',
972
+			),
973
+			$query_args
974
+		);
975
+		$powered_by = apply_filters(
976
+			'FHEE__EEH_Template__powered_by_event_espresso_text',
977
+			$admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
978
+		);
979
+		$url        = add_query_arg($query_args, 'https://eventespresso.com/');
980
+		$url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
981
+		return (string) apply_filters(
982
+			'FHEE__EEH_Template__powered_by_event_espresso__html',
983
+			sprintf(
984
+				esc_html_x(
985
+					'%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
986
+					'Online event registration and ticketing powered by [link to eventespresso.com]',
987
+					'event_espresso'
988
+				),
989
+				"<{$tag}{$attributes}>",
990
+				"<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
991
+				$admin ? '' : '<br />'
992
+			),
993
+			$wrap_class,
994
+			$wrap_id
995
+		);
996
+	}
997 997
 }
998 998
 
999 999
 
1000 1000
 
1001 1001
 
1002 1002
 if (! function_exists('espresso_pagination')) {
1003
-    /**
1004
-     *    espresso_pagination
1005
-     *
1006
-     * @access    public
1007
-     * @return    void
1008
-     */
1009
-    function espresso_pagination()
1010
-    {
1011
-        global $wp_query;
1012
-        $big        = 999999999; // need an unlikely integer
1013
-        $pagination = paginate_links(
1014
-            array(
1015
-                'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
1016
-                'format'       => '?paged=%#%',
1017
-                'current'      => max(1, get_query_var('paged')),
1018
-                'total'        => $wp_query->max_num_pages,
1019
-                'show_all'     => true,
1020
-                'end_size'     => 10,
1021
-                'mid_size'     => 6,
1022
-                'prev_next'    => true,
1023
-                'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
1024
-                'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
1025
-                'type'         => 'plain',
1026
-                'add_args'     => false,
1027
-                'add_fragment' => '',
1028
-            )
1029
-        );
1030
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
1031
-    }
1003
+	/**
1004
+	 *    espresso_pagination
1005
+	 *
1006
+	 * @access    public
1007
+	 * @return    void
1008
+	 */
1009
+	function espresso_pagination()
1010
+	{
1011
+		global $wp_query;
1012
+		$big        = 999999999; // need an unlikely integer
1013
+		$pagination = paginate_links(
1014
+			array(
1015
+				'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
1016
+				'format'       => '?paged=%#%',
1017
+				'current'      => max(1, get_query_var('paged')),
1018
+				'total'        => $wp_query->max_num_pages,
1019
+				'show_all'     => true,
1020
+				'end_size'     => 10,
1021
+				'mid_size'     => 6,
1022
+				'prev_next'    => true,
1023
+				'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
1024
+				'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
1025
+				'type'         => 'plain',
1026
+				'add_args'     => false,
1027
+				'add_fragment' => '',
1028
+			)
1029
+		);
1030
+		echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
1031
+	}
1032 1032
 }
1033 1033
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\exceptions\InvalidInterfaceException;
5 5
 use EventEspresso\core\services\loaders\LoaderFactory;
6 6
 
7
-if (! function_exists('espresso_get_template_part')) {
7
+if ( ! function_exists('espresso_get_template_part')) {
8 8
     /**
9 9
      * espresso_get_template_part
10 10
      * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 }
22 22
 
23 23
 
24
-if (! function_exists('espresso_get_object_css_class')) {
24
+if ( ! function_exists('espresso_get_object_css_class')) {
25 25
     /**
26 26
      * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27 27
      *
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public static function load_espresso_theme_functions()
71 71
     {
72
-        if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) {
74
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php');
72
+        if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
+            if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php')) {
74
+                require_once(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php');
75 75
             }
76 76
         }
77 77
     }
@@ -85,16 +85,16 @@  discard block
 block discarded – undo
85 85
     public static function get_espresso_themes()
86 86
     {
87 87
         if (empty(EEH_Template::$_espresso_themes)) {
88
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
88
+            $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR);
89 89
             if (empty($espresso_themes)) {
90 90
                 return array();
91 91
             }
92 92
             if (($key = array_search('global_assets', $espresso_themes)) !== false) {
93
-                unset($espresso_themes[ $key ]);
93
+                unset($espresso_themes[$key]);
94 94
             }
95 95
             EEH_Template::$_espresso_themes = array();
96 96
             foreach ($espresso_themes as $espresso_theme) {
97
-                EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
97
+                EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme;
98 98
             }
99 99
         }
100 100
         return EEH_Template::$_espresso_themes;
@@ -205,10 +205,10 @@  discard block
 block discarded – undo
205 205
                 // get array of EE Custom Post Types
206 206
                 $EE_CPTs = $custom_post_types->getDefinitions();
207 207
                 // build template name based on request
208
-                if (isset($EE_CPTs[ $post_type ])) {
208
+                if (isset($EE_CPTs[$post_type])) {
209 209
                     $archive_or_single = is_archive() ? 'archive' : '';
210 210
                     $archive_or_single = is_single() ? 'single' : $archive_or_single;
211
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
211
+                    $templates         = $archive_or_single.'-'.$post_type.'.php';
212 212
                 }
213 213
             }
214 214
             // currently active EE template theme
@@ -217,18 +217,18 @@  discard block
 block discarded – undo
217 217
             // array of paths to folders that may contain templates
218 218
             $template_folder_paths = array(
219 219
                 // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
220
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
220
+                EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme,
221 221
                 // then in the root of the /wp-content/uploads/espresso/templates/ folder
222 222
                 EVENT_ESPRESSO_TEMPLATE_DIR,
223 223
             );
224 224
 
225 225
             // add core plugin folders for checking only if we're not $check_if_custom
226
-            if (! $check_if_custom) {
227
-                $core_paths            = array(
226
+            if ( ! $check_if_custom) {
227
+                $core_paths = array(
228 228
                     // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
229
-                    EE_PUBLIC . $current_theme,
229
+                    EE_PUBLIC.$current_theme,
230 230
                     // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
231
-                    EE_TEMPLATES . $current_theme,
231
+                    EE_TEMPLATES.$current_theme,
232 232
                     // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
233 233
                     EE_PLUGIN_DIR_PATH,
234 234
                 );
@@ -261,10 +261,10 @@  discard block
 block discarded – undo
261 261
                     );
262 262
                     if ($common_base_path !== '') {
263 263
                         // both paths have a common base, so just tack the filename onto our search path
264
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
264
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name;
265 265
                     } else {
266 266
                         // no common base path, so let's just concatenate
267
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
267
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template;
268 268
                     }
269 269
                     // build up our template locations array by adding our resolved paths
270 270
                     $full_template_paths[] = $resolved_path;
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
                 // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
273 273
                 array_unshift($full_template_paths, $template);
274 274
                 // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
275
-                array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name);
275
+                array_unshift($full_template_paths, get_stylesheet_directory().DS.$file_name);
276 276
             }
277 277
             // filter final array of full template paths
278 278
             $full_template_paths = apply_filters(
@@ -361,11 +361,11 @@  discard block
 block discarded – undo
361 361
         $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
362 362
 
363 363
         // you gimme nuttin - YOU GET NUTTIN !!
364
-        if (! $template_path || ! is_readable($template_path)) {
364
+        if ( ! $template_path || ! is_readable($template_path)) {
365 365
             return '';
366 366
         }
367 367
         // if $template_args are not in an array, then make it so
368
-        if (! is_array($template_args) && ! is_object($template_args)) {
368
+        if ( ! is_array($template_args) && ! is_object($template_args)) {
369 369
             $template_args = array($template_args);
370 370
         }
371 371
         extract($template_args, EXTR_SKIP);
@@ -403,11 +403,11 @@  discard block
 block discarded – undo
403 403
     public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
404 404
     {
405 405
         // in the beginning...
406
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
406
+        $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : '';
407 407
         // da muddle
408 408
         $class = '';
409 409
         // the end
410
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
410
+        $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : '';
411 411
         // is the passed object an EE object ?
412 412
         if ($object instanceof EE_Base_Class) {
413 413
             // grab the exact type of object
@@ -417,10 +417,10 @@  discard block
 block discarded – undo
417 417
                 // no specifics just yet...
418 418
                 default:
419 419
                     $class = strtolower(str_replace('_', '-', $obj_class));
420
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
420
+                    $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : '';
421 421
             }
422 422
         }
423
-        return $prefix . $class . $suffix;
423
+        return $prefix.$class.$suffix;
424 424
     }
425 425
 
426 426
 
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
             // was a country ISO code passed ? if so generate currency config object for that country
464 464
             $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
465 465
             // verify results
466
-            if (! $mny instanceof EE_Currency_Config) {
466
+            if ( ! $mny instanceof EE_Currency_Config) {
467 467
                 // set default config country currency settings
468 468
                 $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
469 469
                     ? EE_Registry::instance()->CFG->currency
@@ -473,9 +473,9 @@  discard block
 block discarded – undo
473 473
 
474 474
             $decimal_places_to_use = $mny->dec_plc;
475 475
             // If we're allowing showing partial penny amounts, determine how many decimal places to use.
476
-            if($allow_partial_pennies){
476
+            if ($allow_partial_pennies) {
477 477
                 $pos_of_period = strrpos($amount, '.');
478
-                if($pos_of_period !== false) {
478
+                if ($pos_of_period !== false) {
479 479
                     // Use a max of two extra decimal places (more than that and it starts
480 480
                     // to look silly), but at least the normal number of decimal places.
481 481
                     $decimal_places_to_use = min(
@@ -489,23 +489,23 @@  discard block
 block discarded – undo
489 489
             }
490 490
             $amount_formatted = number_format($amount, $decimal_places_to_use, $mny->dec_mrk, $mny->thsnds);
491 491
             // add formatting ?
492
-            if (! $return_raw) {
492
+            if ( ! $return_raw) {
493 493
                 // add currency sign
494 494
                 if ($mny->sign_b4) {
495 495
                     if ($amount >= 0) {
496
-                        $amount_formatted = $mny->sign . $amount_formatted;
496
+                        $amount_formatted = $mny->sign.$amount_formatted;
497 497
                     } else {
498
-                        $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
498
+                        $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted);
499 499
                     }
500 500
                 } else {
501
-                    $amount_formatted = $amount_formatted . $mny->sign;
501
+                    $amount_formatted = $amount_formatted.$mny->sign;
502 502
                 }
503 503
 
504 504
                 // filter to allow global setting of display_code
505 505
                 $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
506 506
 
507 507
                 // add currency code ?
508
-                $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
508
+                $amount_formatted = $display_code ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' : $amount_formatted;
509 509
             }
510 510
             // filter results
511 511
             $amount_formatted = apply_filters(
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
             $plural,
543 543
             $schema
544 544
         );
545
-        return $status[ $status_id ];
545
+        return $status[$status_id];
546 546
     }
547 547
 
548 548
 
@@ -559,19 +559,19 @@  discard block
 block discarded – undo
559 559
     public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
560 560
     {
561 561
         $icon_html = '';
562
-        if (! empty($icon)) {
562
+        if ( ! empty($icon)) {
563 563
             $dashicons = preg_split("(ee-icon |dashicons )", $icon);
564 564
             $dashicons = array_filter($dashicons);
565 565
             $count     = count($dashicons);
566 566
             $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
567 567
             foreach ($dashicons as $dashicon) {
568 568
                 $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
569
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
569
+                $icon_html .= '<span class="'.$type.$dashicon.'"></span>';
570 570
             }
571 571
             $icon_html .= $count > 1 ? '</span>' : '';
572 572
         }
573
-        $label  = ! empty($icon) ? $icon_html . $label : $label;
574
-        $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
573
+        $label  = ! empty($icon) ? $icon_html.$label : $label;
574
+        $button = '<a id="'.sanitize_title_with_dashes($label).'" href="'.esc_url($url).'" class="'.$class.'" title="'.$title.'">'.$label.'</a>';
575 575
         return $button;
576 576
     }
577 577
 
@@ -594,24 +594,24 @@  discard block
 block discarded – undo
594 594
         $help_text = false
595 595
     ) {
596 596
 
597
-        if (! $page) {
597
+        if ( ! $page) {
598 598
             $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
599 599
         }
600 600
 
601
-        if (! $action) {
601
+        if ( ! $action) {
602 602
             $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
603 603
         }
604 604
 
605 605
         $action = empty($action) ? 'default' : $action;
606 606
 
607 607
 
608
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
608
+        $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id;
609 609
         $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
610 610
         $help_text    = ! $help_text ? '' : $help_text;
611
-        return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__(
611
+        return '<a id="'.$help_tab_lnk.'" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'.$icon.'" title="'.esc_attr__(
612 612
             'Click to open the \'Help\' tab for more information about this feature.',
613 613
             'event_espresso'
614
-        ) . '" > ' . $help_text . ' </a>';
614
+        ).'" > '.$help_text.' </a>';
615 615
     }
616 616
 
617 617
 
@@ -628,11 +628,11 @@  discard block
 block discarded – undo
628 628
         $id    = $tour->get_slug();
629 629
         $stops = $tour->get_stops();
630 630
 
631
-        $content = '<ol style="display:none" id="' . $id . '">';
631
+        $content = '<ol style="display:none" id="'.$id.'">';
632 632
 
633 633
         foreach ($stops as $stop) {
634
-            $data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
635
-            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
634
+            $data_id    = ! empty($stop['id']) ? ' data-id="'.$stop['id'].'"' : '';
635
+            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="'.$stop['class'].'"' : '';
636 636
 
637 637
             // if container is set to modal then let's make sure we set the options accordingly
638 638
             if (empty($data_id) && empty($data_class)) {
@@ -640,15 +640,15 @@  discard block
 block discarded – undo
640 640
                 $stop['options']['expose'] = true;
641 641
             }
642 642
 
643
-            $custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
644
-            $button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
643
+            $custom_class  = ! empty($stop['custom_class']) ? ' class="'.$stop['custom_class'].'"' : '';
644
+            $button_text   = ! empty($stop['button_text']) ? ' data-button="'.$stop['button_text'].'"' : '';
645 645
             $inner_content = isset($stop['content']) ? $stop['content'] : '';
646 646
 
647 647
             // options
648 648
             if (isset($stop['options']) && is_array($stop['options'])) {
649 649
                 $options = ' data-options="';
650 650
                 foreach ($stop['options'] as $option => $value) {
651
-                    $options .= $option . ':' . $value . ';';
651
+                    $options .= $option.':'.$value.';';
652 652
                 }
653 653
                 $options .= '"';
654 654
             } else {
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
             }
657 657
 
658 658
             // let's put all together
659
-            $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
659
+            $content .= '<li'.$data_id.$data_class.$custom_class.$button_text.$options.'>'.$inner_content.'</li>';
660 660
         }
661 661
 
662 662
         $content .= '</ol>';
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
      */
681 681
     public static function status_legend($status_array, $active_status = '')
682 682
     {
683
-        if (! is_array($status_array)) {
683
+        if ( ! is_array($status_array)) {
684 684
             throw new EE_Error(esc_html__(
685 685
                 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
686 686
                 'event_espresso'
@@ -689,25 +689,25 @@  discard block
 block discarded – undo
689 689
 
690 690
         $setup_array = array();
691 691
         foreach ($status_array as $item => $status) {
692
-            $setup_array[ $item ] = array(
693
-                'class'  => 'ee-status-legend ee-status-legend-' . $status,
692
+            $setup_array[$item] = array(
693
+                'class'  => 'ee-status-legend ee-status-legend-'.$status,
694 694
                 'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
695 695
                 'status' => $status,
696 696
             );
697 697
         }
698 698
 
699
-        $content = '<div class="ee-list-table-legend-container">' . "\n";
700
-        $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
701
-        $content .= '<dl class="ee-list-table-legend">' . "\n\t";
699
+        $content = '<div class="ee-list-table-legend-container">'."\n";
700
+        $content .= '<h4 class="status-legend-title">'.esc_html__('Status Legend', 'event_espresso').'</h4>'."\n";
701
+        $content .= '<dl class="ee-list-table-legend">'."\n\t";
702 702
         foreach ($setup_array as $item => $details) {
703 703
             $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
704
-            $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
705
-            $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
706
-            $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
707
-            $content .= '</dt>' . "\n";
704
+            $content .= '<dt id="ee-legend-item-tooltip-'.$item.'"'.$active_class.'>'."\n\t\t";
705
+            $content .= '<span class="'.$details['class'].'"></span>'."\n\t\t";
706
+            $content .= '<span class="ee-legend-description">'.$details['desc'].'</span>'."\n\t";
707
+            $content .= '</dt>'."\n";
708 708
         }
709
-        $content .= '</dl>' . "\n";
710
-        $content .= '</div>' . "\n";
709
+        $content .= '</dl>'."\n";
710
+        $content .= '</div>'."\n";
711 711
         return $content;
712 712
     }
713 713
 
@@ -852,8 +852,8 @@  discard block
 block discarded – undo
852 852
             );
853 853
         } else {
854 854
             $items_label = array(
855
-                'single' => '1 ' . esc_html($items_label['single']),
856
-                'plural' => '%s ' . esc_html($items_label['plural']),
855
+                'single' => '1 '.esc_html($items_label['single']),
856
+                'plural' => '%s '.esc_html($items_label['plural']),
857 857
             );
858 858
         }
859 859
 
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
 
866 866
         $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
867 867
 
868
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
868
+        $output = '<span class="displaying-num">'.$item_label.'</span>';
869 869
 
870 870
         if ($current === 1) {
871 871
             $disable_first = ' disabled';
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
 
877 877
         $page_links[] = sprintf(
878 878
             "<a class='%s' title='%s' href='%s'>%s</a>",
879
-            'first-page' . $disable_first,
879
+            'first-page'.$disable_first,
880 880
             esc_attr__('Go to the first page', 'event_espresso'),
881 881
             esc_url(remove_query_arg($paged_arg_name, $url)),
882 882
             '&laquo;'
@@ -884,13 +884,13 @@  discard block
 block discarded – undo
884 884
 
885 885
         $page_links[] = sprintf(
886 886
             '<a class="%s" title="%s" href="%s">%s</a>',
887
-            'prev-page' . $disable_first,
887
+            'prev-page'.$disable_first,
888 888
             esc_attr__('Go to the previous page', 'event_espresso'),
889 889
             esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
890 890
             '&lsaquo;'
891 891
         );
892 892
 
893
-        if (! $show_num_field) {
893
+        if ( ! $show_num_field) {
894 894
             $html_current_page = $current;
895 895
         } else {
896 896
             $html_current_page = sprintf(
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
             '<span class="total-pages">%s</span>',
906 906
             number_format_i18n($total_pages)
907 907
         );
908
-        $page_links[]     = sprintf(
908
+        $page_links[] = sprintf(
909 909
             _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
910 910
             $html_current_page,
911 911
             $html_total_pages,
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
 
916 916
         $page_links[] = sprintf(
917 917
             '<a class="%s" title="%s" href="%s">%s</a>',
918
-            'next-page' . $disable_last,
918
+            'next-page'.$disable_last,
919 919
             esc_attr__('Go to the next page', 'event_espresso'),
920 920
             esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
921 921
             '&rsaquo;'
@@ -923,13 +923,13 @@  discard block
 block discarded – undo
923 923
 
924 924
         $page_links[] = sprintf(
925 925
             '<a class="%s" title="%s" href="%s">%s</a>',
926
-            'last-page' . $disable_last,
926
+            'last-page'.$disable_last,
927 927
             esc_attr__('Go to the last page', 'event_espresso'),
928 928
             esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
929 929
             '&raquo;'
930 930
         );
931 931
 
932
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
932
+        $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>';
933 933
         // set page class
934 934
         if ($total_pages) {
935 935
             $page_class = $total_pages < 2 ? ' one-page' : '';
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
             $page_class = ' no-pages';
938 938
         }
939 939
 
940
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
940
+        return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>';
941 941
     }
942 942
 
943 943
 
@@ -949,7 +949,7 @@  discard block
 block discarded – undo
949 949
     public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
950 950
     {
951 951
         $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
952
-        if (! $admin &&
952
+        if ( ! $admin &&
953 953
             ! apply_filters(
954 954
                 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
955 955
                 EE_Registry::instance()->CFG->admin->show_reg_footer
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
         );
975 975
         $powered_by = apply_filters(
976 976
             'FHEE__EEH_Template__powered_by_event_espresso_text',
977
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
977
+            $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso'
978 978
         );
979 979
         $url        = add_query_arg($query_args, 'https://eventespresso.com/');
980 980
         $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
@@ -999,7 +999,7 @@  discard block
 block discarded – undo
999 999
 
1000 1000
 
1001 1001
 
1002
-if (! function_exists('espresso_pagination')) {
1002
+if ( ! function_exists('espresso_pagination')) {
1003 1003
     /**
1004 1004
      *    espresso_pagination
1005 1005
      *
@@ -1027,6 +1027,6 @@  discard block
 block discarded – undo
1027 1027
                 'add_fragment' => '',
1028 1028
             )
1029 1029
         );
1030
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
1030
+        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : '';
1031 1031
     }
1032 1032
 }
1033 1033
\ No newline at end of file
Please login to merge, or discard this patch.
ticket_selector_caff/templates/ticket_selector_price_details.template.php 2 patches
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -7,39 +7,39 @@  discard block
 block discarded – undo
7 7
 if ($display_ticket_price) { ?>
8 8
     <section class="tckt-slctr-tkt-price-sctn">
9 9
         <h5><?php
10
-            echo apply_filters(
11
-                'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading',
12
-                esc_html__('Price', 'event_espresso')
13
-            ); ?></h5>
10
+			echo apply_filters(
11
+				'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading',
12
+				esc_html__('Price', 'event_espresso')
13
+			); ?></h5>
14 14
         <div class="tckt-slctr-tkt-details-tbl-wrap-dv">
15 15
             <table class="tckt-slctr-tkt-details-tbl">
16 16
                 <thead>
17 17
                 <tr>
18 18
                     <th class="ee-third-width"><span class="small-text">
19 19
                             <?php
20
-                            esc_html_e(
21
-                                'Name',
22
-                                'event_espresso'
23
-                            ); ?></span>
20
+							esc_html_e(
21
+								'Name',
22
+								'event_espresso'
23
+							); ?></span>
24 24
                     </th>
25 25
                     <th class="jst-cntr"><span class="small-text">
26 26
                             <?php
27
-                            esc_html_e(
28
-                                'Description',
29
-                                'event_espresso'
30
-                            ); ?></span>
27
+							esc_html_e(
28
+								'Description',
29
+								'event_espresso'
30
+							); ?></span>
31 31
                     </th>
32 32
                     <th class="ee-fourth-width jst-rght"><span class="small-text">
33 33
                             <?php
34
-                            esc_html_e(
35
-                                'Amount',
36
-                                'event_espresso'
37
-                            ); ?></span></th>
34
+							esc_html_e(
35
+								'Amount',
36
+								'event_espresso'
37
+							); ?></span></th>
38 38
                 </tr>
39 39
                 </thead>
40 40
                 <tbody>
41 41
                 <?php
42
-                if ($ticket->base_price() instanceof EE_Price) { ?>
42
+				if ($ticket->base_price() instanceof EE_Price) { ?>
43 43
                     <tr>
44 44
                         <td data-th="<?php esc_html_e('Name', 'event_espresso'); ?>" class="small-text">
45 45
                             <b><?php echo $ticket->base_price()->name(); ?></b></td>
@@ -49,12 +49,12 @@  discard block
 block discarded – undo
49 49
                             class="jst-rght small-text"><?php echo $ticket->base_price()->pretty_price(); ?></td>
50 50
                     </tr>
51 51
                     <?php
52
-                    $running_total = $ticket->base_price()->amount();
53
-                } else {
54
-                    $running_total = 0;
55
-                }
56
-                // now add price modifiers
57
-                foreach ($ticket->price_modifiers() as $price_mod) { ?>
52
+					$running_total = $ticket->base_price()->amount();
53
+				} else {
54
+					$running_total = 0;
55
+				}
56
+				// now add price modifiers
57
+				foreach ($ticket->price_modifiers() as $price_mod) { ?>
58 58
                     <tr>
59 59
                         <td data-th="<?php esc_html_e('Name', 'event_espresso'); ?>"
60 60
                             class="jst-rght small-text"><?php echo $price_mod->name(); ?></td>
@@ -64,29 +64,29 @@  discard block
 block discarded – undo
64 64
                                 %
65 65
                             </td>
66 66
                             <?php
67
-                            $new_sub_total = $running_total * ($price_mod->amount() / 100);
68
-                            $new_sub_total = $price_mod->is_discount() ? $new_sub_total * -1 : $new_sub_total;
69
-                            ?>
67
+							$new_sub_total = $running_total * ($price_mod->amount() / 100);
68
+							$new_sub_total = $price_mod->is_discount() ? $new_sub_total * -1 : $new_sub_total;
69
+							?>
70 70
                         <?php } else { ?>
71 71
                             <?php $new_sub_total = $price_mod->is_discount() ? $price_mod->amount() * -1
72
-                                : $price_mod->amount(); ?>
72
+								: $price_mod->amount(); ?>
73 73
                             <td data-th="<?php esc_html_e('Description', 'event_espresso'); ?>"
74 74
                                 class="small-text"><?php echo $price_mod->desc(); ?></td>
75 75
                             <?php $new_sub_total = $price_mod->is_discount() ? $price_mod->amount() * -1
76
-                                : $price_mod->amount(); ?>
76
+								: $price_mod->amount(); ?>
77 77
                         <?php } ?>
78 78
                         <td data-th="<?php esc_html_e('Amount', 'event_espresso'); ?>"
79 79
                             class="jst-rght small-text">
80 80
                             <?php
81
-                                echo EEH_Template::format_currency(
82
-                                    $new_sub_total,
83
-                                    false,
84
-                                    true,
85
-                                    '',
86
-                                    'currency-code',
87
-                                    true
88
-                                );
89
-                             ?></td>
81
+								echo EEH_Template::format_currency(
82
+									$new_sub_total,
83
+									false,
84
+									true,
85
+									'',
86
+									'currency-code',
87
+									true
88
+								);
89
+							 ?></td>
90 90
                         <?php $running_total += $new_sub_total; ?>
91 91
                     </tr>
92 92
                 <?php } ?>
@@ -95,10 +95,10 @@  discard block
 block discarded – undo
95 95
                     <tr>
96 96
                         <td colspan="2" class="jst-rght small-text sbttl"><b>
97 97
                                 <?php
98
-                                esc_html_e(
99
-                                    'subtotal',
100
-                                    'event_espresso'
101
-                                ); ?></b></td>
98
+								esc_html_e(
99
+									'subtotal',
100
+									'event_espresso'
101
+								); ?></b></td>
102 102
                         <td data-th="<?php esc_html_e('subtotal', 'event_espresso'); ?>" class="jst-rght small-text">
103 103
                             <b><?php echo EEH_Template::format_currency($running_total); ?></b></td>
104 104
                     </tr>
@@ -114,13 +114,13 @@  discard block
 block discarded – undo
114 114
                             <td data-th="<?php esc_html_e('Amount', 'event_espresso'); ?>"
115 115
                                 class="jst-rght small-text">
116 116
                                 <?php
117
-                                if($price_mod->is_percent()) {
118
-                                    echo $new_sub_total;
119
-                                } else {
120
-                                    echo EEH_Template::format_currency(
121
-                                        $new_sub_total
122
-                                    );
123
-                                } ?></td>
117
+								if($price_mod->is_percent()) {
118
+									echo $new_sub_total;
119
+								} else {
120
+									echo EEH_Template::format_currency(
121
+										$new_sub_total
122
+									);
123
+								} ?></td>
124 124
                             <?php $running_total += $tax_amount; ?>
125 125
                         </tr>
126 126
                     <?php } ?>
@@ -128,15 +128,15 @@  discard block
 block discarded – undo
128 128
                 <tr>
129 129
                     <td colspan="2" class="jst-rght small-text ttl-lbl-td">
130 130
                         <b><?php
131
-                            echo apply_filters(
132
-                                'FHEE__ticket_selector_chart_template__ticket_details_total_price',
133
-                                esc_html__('Total', 'event_espresso')
134
-                            ); ?></b></td>
131
+							echo apply_filters(
132
+								'FHEE__ticket_selector_chart_template__ticket_details_total_price',
133
+								esc_html__('Total', 'event_espresso')
134
+							); ?></b></td>
135 135
                     <td data-th="<?php
136
-                                    echo apply_filters(
137
-                                        'FHEE__ticket_selector_chart_template__ticket_details_total_price',
138
-                                        esc_html__('Total', 'event_espresso')
139
-                                    ); ?>" class="jst-rght small-text">
136
+									echo apply_filters(
137
+										'FHEE__ticket_selector_chart_template__ticket_details_total_price',
138
+										esc_html__('Total', 'event_espresso')
139
+									); ?>" class="jst-rght small-text">
140 140
                         <b><?php echo EEH_Template::format_currency($running_total); ?></b></td>
141 141
                 </tr>
142 142
                 </tbody>
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@
 block discarded – undo
114 114
                             <td data-th="<?php esc_html_e('Amount', 'event_espresso'); ?>"
115 115
                                 class="jst-rght small-text">
116 116
                                 <?php
117
-                                if($price_mod->is_percent()) {
117
+                                if ($price_mod->is_percent()) {
118 118
                                     echo $new_sub_total;
119 119
                                 } else {
120 120
                                     echo EEH_Template::format_currency(
Please login to merge, or discard this patch.
core/db_classes/EE_Line_Item.class.php 3 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -356,6 +356,9 @@  discard block
 block discarded – undo
356 356
         return $this->get('LIN_unit_price');
357 357
     }
358 358
 
359
+    /**
360
+     * @return string
361
+     */
359 362
     public function prettyUnitPrice()
360 363
     {
361 364
         if($this->parent_ID() !== 0
@@ -807,7 +810,7 @@  discard block
 block discarded – undo
807 810
     /**
808 811
      * Gets the event that's related to the ticket, if this line item represents a ticket.
809 812
      *
810
-     * @return EE_Event|null
813
+     * @return EE_Base_Class|null
811 814
      * @throws EE_Error
812 815
      * @throws InvalidArgumentException
813 816
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
Indentation   +1757 added lines, -1757 removed lines patch added patch discarded remove patch
@@ -14,1761 +14,1761 @@
 block discarded – undo
14 14
 class EE_Line_Item extends EE_Base_Class implements EEI_Line_Item
15 15
 {
16 16
 
17
-    /**
18
-     * for children line items (currently not a normal relation)
19
-     *
20
-     * @type EE_Line_Item[]
21
-     */
22
-    protected $_children = array();
23
-
24
-    /**
25
-     * for the parent line item
26
-     *
27
-     * @var EE_Line_Item
28
-     */
29
-    protected $_parent;
30
-
31
-
32
-    /**
33
-     * @param array  $props_n_values          incoming values
34
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
35
-     *                                        used.)
36
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
37
-     *                                        date_format and the second value is the time format
38
-     * @return EE_Line_Item
39
-     * @throws EE_Error
40
-     * @throws InvalidArgumentException
41
-     * @throws InvalidDataTypeException
42
-     * @throws InvalidInterfaceException
43
-     * @throws ReflectionException
44
-     */
45
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
46
-    {
47
-        $has_object = parent::_check_for_object(
48
-            $props_n_values,
49
-            __CLASS__,
50
-            $timezone,
51
-            $date_formats
52
-        );
53
-        return $has_object
54
-            ? $has_object
55
-            : new self($props_n_values, false, $timezone);
56
-    }
57
-
58
-
59
-    /**
60
-     * @param array  $props_n_values  incoming values from the database
61
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
62
-     *                                the website will be used.
63
-     * @return EE_Line_Item
64
-     * @throws EE_Error
65
-     * @throws InvalidArgumentException
66
-     * @throws InvalidDataTypeException
67
-     * @throws InvalidInterfaceException
68
-     * @throws ReflectionException
69
-     */
70
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
71
-    {
72
-        return new self($props_n_values, true, $timezone);
73
-    }
74
-
75
-
76
-    /**
77
-     * Adds some defaults if they're not specified
78
-     *
79
-     * @param array  $fieldValues
80
-     * @param bool   $bydb
81
-     * @param string $timezone
82
-     * @throws EE_Error
83
-     * @throws InvalidArgumentException
84
-     * @throws InvalidDataTypeException
85
-     * @throws InvalidInterfaceException
86
-     * @throws ReflectionException
87
-     */
88
-    protected function __construct($fieldValues = array(), $bydb = false, $timezone = '')
89
-    {
90
-        parent::__construct($fieldValues, $bydb, $timezone);
91
-        if (! $this->get('LIN_code')) {
92
-            $this->set_code($this->generate_code());
93
-        }
94
-    }
95
-
96
-
97
-    /**
98
-     * Gets ID
99
-     *
100
-     * @return int
101
-     * @throws EE_Error
102
-     * @throws InvalidArgumentException
103
-     * @throws InvalidDataTypeException
104
-     * @throws InvalidInterfaceException
105
-     * @throws ReflectionException
106
-     */
107
-    public function ID()
108
-    {
109
-        return $this->get('LIN_ID');
110
-    }
111
-
112
-
113
-    /**
114
-     * Gets TXN_ID
115
-     *
116
-     * @return int
117
-     * @throws EE_Error
118
-     * @throws InvalidArgumentException
119
-     * @throws InvalidDataTypeException
120
-     * @throws InvalidInterfaceException
121
-     * @throws ReflectionException
122
-     */
123
-    public function TXN_ID()
124
-    {
125
-        return $this->get('TXN_ID');
126
-    }
127
-
128
-
129
-    /**
130
-     * Sets TXN_ID
131
-     *
132
-     * @param int $TXN_ID
133
-     * @throws EE_Error
134
-     * @throws InvalidArgumentException
135
-     * @throws InvalidDataTypeException
136
-     * @throws InvalidInterfaceException
137
-     * @throws ReflectionException
138
-     */
139
-    public function set_TXN_ID($TXN_ID)
140
-    {
141
-        $this->set('TXN_ID', $TXN_ID);
142
-    }
143
-
144
-
145
-    /**
146
-     * Gets name
147
-     *
148
-     * @return string
149
-     * @throws EE_Error
150
-     * @throws InvalidArgumentException
151
-     * @throws InvalidDataTypeException
152
-     * @throws InvalidInterfaceException
153
-     * @throws ReflectionException
154
-     */
155
-    public function name()
156
-    {
157
-        $name = $this->get('LIN_name');
158
-        if (! $name) {
159
-            $name = ucwords(str_replace('-', ' ', $this->type()));
160
-        }
161
-        return $name;
162
-    }
163
-
164
-
165
-    /**
166
-     * Sets name
167
-     *
168
-     * @param string $name
169
-     * @throws EE_Error
170
-     * @throws InvalidArgumentException
171
-     * @throws InvalidDataTypeException
172
-     * @throws InvalidInterfaceException
173
-     * @throws ReflectionException
174
-     */
175
-    public function set_name($name)
176
-    {
177
-        $this->set('LIN_name', $name);
178
-    }
179
-
180
-
181
-    /**
182
-     * Gets desc
183
-     *
184
-     * @return string
185
-     * @throws EE_Error
186
-     * @throws InvalidArgumentException
187
-     * @throws InvalidDataTypeException
188
-     * @throws InvalidInterfaceException
189
-     * @throws ReflectionException
190
-     */
191
-    public function desc()
192
-    {
193
-        return $this->get('LIN_desc');
194
-    }
195
-
196
-
197
-    /**
198
-     * Sets desc
199
-     *
200
-     * @param string $desc
201
-     * @throws EE_Error
202
-     * @throws InvalidArgumentException
203
-     * @throws InvalidDataTypeException
204
-     * @throws InvalidInterfaceException
205
-     * @throws ReflectionException
206
-     */
207
-    public function set_desc($desc)
208
-    {
209
-        $this->set('LIN_desc', $desc);
210
-    }
211
-
212
-
213
-    /**
214
-     * Gets quantity
215
-     *
216
-     * @return int
217
-     * @throws EE_Error
218
-     * @throws InvalidArgumentException
219
-     * @throws InvalidDataTypeException
220
-     * @throws InvalidInterfaceException
221
-     * @throws ReflectionException
222
-     */
223
-    public function quantity()
224
-    {
225
-        return $this->get('LIN_quantity');
226
-    }
227
-
228
-
229
-    /**
230
-     * Sets quantity
231
-     *
232
-     * @param int $quantity
233
-     * @throws EE_Error
234
-     * @throws InvalidArgumentException
235
-     * @throws InvalidDataTypeException
236
-     * @throws InvalidInterfaceException
237
-     * @throws ReflectionException
238
-     */
239
-    public function set_quantity($quantity)
240
-    {
241
-        $this->set('LIN_quantity', max($quantity, 0));
242
-    }
243
-
244
-
245
-    /**
246
-     * Gets item_id
247
-     *
248
-     * @return string
249
-     * @throws EE_Error
250
-     * @throws InvalidArgumentException
251
-     * @throws InvalidDataTypeException
252
-     * @throws InvalidInterfaceException
253
-     * @throws ReflectionException
254
-     */
255
-    public function OBJ_ID()
256
-    {
257
-        return $this->get('OBJ_ID');
258
-    }
259
-
260
-
261
-    /**
262
-     * Sets item_id
263
-     *
264
-     * @param string $item_id
265
-     * @throws EE_Error
266
-     * @throws InvalidArgumentException
267
-     * @throws InvalidDataTypeException
268
-     * @throws InvalidInterfaceException
269
-     * @throws ReflectionException
270
-     */
271
-    public function set_OBJ_ID($item_id)
272
-    {
273
-        $this->set('OBJ_ID', $item_id);
274
-    }
275
-
276
-
277
-    /**
278
-     * Gets item_type
279
-     *
280
-     * @return string
281
-     * @throws EE_Error
282
-     * @throws InvalidArgumentException
283
-     * @throws InvalidDataTypeException
284
-     * @throws InvalidInterfaceException
285
-     * @throws ReflectionException
286
-     */
287
-    public function OBJ_type()
288
-    {
289
-        return $this->get('OBJ_type');
290
-    }
291
-
292
-
293
-    /**
294
-     * Gets item_type
295
-     *
296
-     * @return string
297
-     * @throws EE_Error
298
-     * @throws InvalidArgumentException
299
-     * @throws InvalidDataTypeException
300
-     * @throws InvalidInterfaceException
301
-     * @throws ReflectionException
302
-     */
303
-    public function OBJ_type_i18n()
304
-    {
305
-        $obj_type = $this->OBJ_type();
306
-        switch ($obj_type) {
307
-            case EEM_Line_Item::OBJ_TYPE_EVENT:
308
-                $obj_type = esc_html__('Event', 'event_espresso');
309
-                break;
310
-            case EEM_Line_Item::OBJ_TYPE_PRICE:
311
-                $obj_type = esc_html__('Price', 'event_espresso');
312
-                break;
313
-            case EEM_Line_Item::OBJ_TYPE_PROMOTION:
314
-                $obj_type = esc_html__('Promotion', 'event_espresso');
315
-                break;
316
-            case EEM_Line_Item::OBJ_TYPE_TICKET:
317
-                $obj_type = esc_html__('Ticket', 'event_espresso');
318
-                break;
319
-            case EEM_Line_Item::OBJ_TYPE_TRANSACTION:
320
-                $obj_type = esc_html__('Transaction', 'event_espresso');
321
-                break;
322
-        }
323
-        return apply_filters('FHEE__EE_Line_Item__OBJ_type_i18n', $obj_type, $this);
324
-    }
325
-
326
-
327
-    /**
328
-     * Sets item_type
329
-     *
330
-     * @param string $OBJ_type
331
-     * @throws EE_Error
332
-     * @throws InvalidArgumentException
333
-     * @throws InvalidDataTypeException
334
-     * @throws InvalidInterfaceException
335
-     * @throws ReflectionException
336
-     */
337
-    public function set_OBJ_type($OBJ_type)
338
-    {
339
-        $this->set('OBJ_type', $OBJ_type);
340
-    }
341
-
342
-
343
-    /**
344
-     * Gets unit_price for flat rate items. Percent items should set this to 0.
345
-     * You may alternatively want to use prettyUnitPrice(), which works for flat and percent items.
346
-     *
347
-     * @return float
348
-     * @throws EE_Error
349
-     * @throws InvalidArgumentException
350
-     * @throws InvalidDataTypeException
351
-     * @throws InvalidInterfaceException
352
-     * @throws ReflectionException
353
-     */
354
-    public function unit_price()
355
-    {
356
-        return $this->get('LIN_unit_price');
357
-    }
358
-
359
-    public function prettyUnitPrice()
360
-    {
361
-        if($this->parent_ID() !== 0
362
-            && $this->parent() instanceof EE_Line_Item
363
-            && $this->parent()->type() === EEM_Line_Item::type_line_item
364
-        ) {
365
-            $quantity = $this->parent()->quantity();
366
-        } else {
367
-            $quantity = $this->quantity();
368
-        }
369
-        if($this->is_percent()) {
370
-            return $this->get_model()->field_settings_for('LIN_unit_price')->prepare_for_pretty_echoing(
371
-                $this->total() / $quantity,
372
-                'no_currency_code'
373
-            );
374
-        } else {
375
-            return $this->unit_price_no_code();
376
-        }
377
-    }
378
-
379
-    /**
380
-     * Sets unit_price
381
-     *
382
-     * @param float $unit_price
383
-     * @throws EE_Error
384
-     * @throws InvalidArgumentException
385
-     * @throws InvalidDataTypeException
386
-     * @throws InvalidInterfaceException
387
-     * @throws ReflectionException
388
-     */
389
-    public function set_unit_price($unit_price)
390
-    {
391
-        if($this->type() !== EEM_Line_Item::type_sub_line_item) { 
392
-            $unit_price = EEH_Money::round_for_currency($unit_price, EE_Config::instance()->currency->code);
393
-        } 
394
-        $this->set('LIN_unit_price', $unit_price);
395
-    }
396
-
397
-
398
-    /**
399
-     * Checks if this item is a percentage modifier or not
400
-     *
401
-     * @return boolean
402
-     * @throws EE_Error
403
-     * @throws InvalidArgumentException
404
-     * @throws InvalidDataTypeException
405
-     * @throws InvalidInterfaceException
406
-     * @throws ReflectionException
407
-     */
408
-    public function is_percent()
409
-    {
410
-        if ($this->is_tax_sub_total()) {
411
-            // tax subtotals HAVE a percent on them, that percentage only applies
412
-            // to taxable items, so its' an exception. Treat it like a flat line item
413
-            return false;
414
-        }
415
-        $unit_price = abs($this->get('LIN_unit_price'));
416
-        $percent = abs($this->get('LIN_percent'));
417
-        if ($unit_price < .001 && $percent) {
418
-            return true;
419
-        }
420
-        if ($unit_price >= .001 && ! $percent) {
421
-            return false;
422
-        }
423
-        if ($unit_price >= .001 && $percent) {
424
-            throw new EE_Error(
425
-                sprintf(
426
-                    esc_html__(
427
-                        'A Line Item can not have a unit price of (%s) AND a percent (%s)!',
428
-                        'event_espresso'
429
-                    ),
430
-                    $unit_price,
431
-                    $percent
432
-                )
433
-            );
434
-        }
435
-        // if they're both 0, assume its not a percent item
436
-        return false;
437
-    }
438
-
439
-
440
-    /**
441
-     * Gets percent (between 100-.001)
442
-     *
443
-     * @return float
444
-     * @throws EE_Error
445
-     * @throws InvalidArgumentException
446
-     * @throws InvalidDataTypeException
447
-     * @throws InvalidInterfaceException
448
-     * @throws ReflectionException
449
-     */
450
-    public function percent()
451
-    {
452
-        return $this->get('LIN_percent');
453
-    }
454
-
455
-
456
-    /**
457
-     * Sets percent (between 100-0.01)
458
-     *
459
-     * @param float $percent
460
-     * @throws EE_Error
461
-     * @throws InvalidArgumentException
462
-     * @throws InvalidDataTypeException
463
-     * @throws InvalidInterfaceException
464
-     * @throws ReflectionException
465
-     */
466
-    public function set_percent($percent)
467
-    {
468
-        $this->set('LIN_percent', $percent);
469
-    }
470
-
471
-
472
-    /**
473
-     * Gets total
474
-     *
475
-     * @return float
476
-     * @throws EE_Error
477
-     * @throws InvalidArgumentException
478
-     * @throws InvalidDataTypeException
479
-     * @throws InvalidInterfaceException
480
-     * @throws ReflectionException
481
-     */
482
-    public function total()
483
-    {
484
-        return $this->get('LIN_total');
485
-    }
486
-
487
-
488
-    /**
489
-     * Sets total
490
-     *
491
-     * @param float $total
492
-     * @throws EE_Error
493
-     * @throws InvalidArgumentException
494
-     * @throws InvalidDataTypeException
495
-     * @throws InvalidInterfaceException
496
-     * @throws ReflectionException
497
-     */
498
-    public function set_total($total)
499
-    {
500
-        if($this->type() !== EEM_Line_Item::type_sub_line_item) { 
501
-            $total = EEH_Money::round_for_currency($total, EE_Config::instance()->currency->code); 
502
-        } 
503
-        $this->set('LIN_total', $total);
504
-    }
505
-
506
-
507
-    /**
508
-     * Gets order
509
-     *
510
-     * @return int
511
-     * @throws EE_Error
512
-     * @throws InvalidArgumentException
513
-     * @throws InvalidDataTypeException
514
-     * @throws InvalidInterfaceException
515
-     * @throws ReflectionException
516
-     */
517
-    public function order()
518
-    {
519
-        return $this->get('LIN_order');
520
-    }
521
-
522
-
523
-    /**
524
-     * Sets order
525
-     *
526
-     * @param int $order
527
-     * @throws EE_Error
528
-     * @throws InvalidArgumentException
529
-     * @throws InvalidDataTypeException
530
-     * @throws InvalidInterfaceException
531
-     * @throws ReflectionException
532
-     */
533
-    public function set_order($order)
534
-    {
535
-        $this->set('LIN_order', $order);
536
-    }
537
-
538
-
539
-    /**
540
-     * Gets parent
541
-     *
542
-     * @return int
543
-     * @throws EE_Error
544
-     * @throws InvalidArgumentException
545
-     * @throws InvalidDataTypeException
546
-     * @throws InvalidInterfaceException
547
-     * @throws ReflectionException
548
-     */
549
-    public function parent_ID()
550
-    {
551
-        return $this->get('LIN_parent');
552
-    }
553
-
554
-
555
-    /**
556
-     * Sets parent
557
-     *
558
-     * @param int $parent
559
-     * @throws EE_Error
560
-     * @throws InvalidArgumentException
561
-     * @throws InvalidDataTypeException
562
-     * @throws InvalidInterfaceException
563
-     * @throws ReflectionException
564
-     */
565
-    public function set_parent_ID($parent)
566
-    {
567
-        $this->set('LIN_parent', $parent);
568
-    }
569
-
570
-
571
-    /**
572
-     * Gets type
573
-     *
574
-     * @return string
575
-     * @throws EE_Error
576
-     * @throws InvalidArgumentException
577
-     * @throws InvalidDataTypeException
578
-     * @throws InvalidInterfaceException
579
-     * @throws ReflectionException
580
-     */
581
-    public function type()
582
-    {
583
-        return $this->get('LIN_type');
584
-    }
585
-
586
-
587
-    /**
588
-     * Sets type
589
-     *
590
-     * @param string $type
591
-     * @throws EE_Error
592
-     * @throws InvalidArgumentException
593
-     * @throws InvalidDataTypeException
594
-     * @throws InvalidInterfaceException
595
-     * @throws ReflectionException
596
-     */
597
-    public function set_type($type)
598
-    {
599
-        $this->set('LIN_type', $type);
600
-    }
601
-
602
-
603
-    /**
604
-     * Gets the line item of which this item is a composite. Eg, if this is a subtotal, the parent might be a total\
605
-     * If this line item is saved to the DB, fetches the parent from the DB. However, if this line item isn't in the DB
606
-     * it uses its cached reference to its parent line item (which would have been set by `EE_Line_Item::set_parent()`
607
-     * or indirectly by `EE_Line_item::add_child_line_item()`)
608
-     *
609
-     * @return EE_Base_Class|EE_Line_Item
610
-     * @throws EE_Error
611
-     * @throws InvalidArgumentException
612
-     * @throws InvalidDataTypeException
613
-     * @throws InvalidInterfaceException
614
-     * @throws ReflectionException
615
-     */
616
-    public function parent()
617
-    {
618
-        return $this->ID()
619
-            ? $this->get_model()->get_one_by_ID($this->parent_ID())
620
-            : $this->_parent;
621
-    }
622
-
623
-
624
-    /**
625
-     * Gets ALL the children of this line item (ie, all the parts that contribute towards this total).
626
-     *
627
-     * @return EE_Base_Class[]|EE_Line_Item[]
628
-     * @throws EE_Error
629
-     * @throws InvalidArgumentException
630
-     * @throws InvalidDataTypeException
631
-     * @throws InvalidInterfaceException
632
-     * @throws ReflectionException
633
-     */
634
-    public function children()
635
-    {
636
-        if ($this->ID()) {
637
-            return $this->get_model()->get_all(
638
-                array(
639
-                    array('LIN_parent' => $this->ID()),
640
-                    'order_by' => array('LIN_order' => 'ASC'),
641
-                )
642
-            );
643
-        }
644
-        if (! is_array($this->_children)) {
645
-            $this->_children = array();
646
-        }
647
-        return $this->_children;
648
-    }
649
-
650
-
651
-    /**
652
-     * Gets code
653
-     *
654
-     * @return string
655
-     * @throws EE_Error
656
-     * @throws InvalidArgumentException
657
-     * @throws InvalidDataTypeException
658
-     * @throws InvalidInterfaceException
659
-     * @throws ReflectionException
660
-     */
661
-    public function code()
662
-    {
663
-        return $this->get('LIN_code');
664
-    }
665
-
666
-
667
-    /**
668
-     * Sets code
669
-     *
670
-     * @param string $code
671
-     * @throws EE_Error
672
-     * @throws InvalidArgumentException
673
-     * @throws InvalidDataTypeException
674
-     * @throws InvalidInterfaceException
675
-     * @throws ReflectionException
676
-     */
677
-    public function set_code($code)
678
-    {
679
-        $this->set('LIN_code', $code);
680
-    }
681
-
682
-
683
-    /**
684
-     * Gets is_taxable
685
-     *
686
-     * @return boolean
687
-     * @throws EE_Error
688
-     * @throws InvalidArgumentException
689
-     * @throws InvalidDataTypeException
690
-     * @throws InvalidInterfaceException
691
-     * @throws ReflectionException
692
-     */
693
-    public function is_taxable()
694
-    {
695
-        return $this->get('LIN_is_taxable');
696
-    }
697
-
698
-
699
-    /**
700
-     * Sets is_taxable
701
-     *
702
-     * @param boolean $is_taxable
703
-     * @throws EE_Error
704
-     * @throws InvalidArgumentException
705
-     * @throws InvalidDataTypeException
706
-     * @throws InvalidInterfaceException
707
-     * @throws ReflectionException
708
-     */
709
-    public function set_is_taxable($is_taxable)
710
-    {
711
-        $this->set('LIN_is_taxable', $is_taxable);
712
-    }
713
-
714
-
715
-    /**
716
-     * Gets the object that this model-joins-to.
717
-     * returns one of the model objects that the field OBJ_ID can point to... see the 'OBJ_ID' field on
718
-     * EEM_Promotion_Object
719
-     *        Eg, if this line item join model object is for a ticket, this will return the EE_Ticket object
720
-     *
721
-     * @return EE_Base_Class | NULL
722
-     * @throws EE_Error
723
-     * @throws InvalidArgumentException
724
-     * @throws InvalidDataTypeException
725
-     * @throws InvalidInterfaceException
726
-     * @throws ReflectionException
727
-     */
728
-    public function get_object()
729
-    {
730
-        $model_name_of_related_obj = $this->OBJ_type();
731
-        return $this->get_model()->has_relation($model_name_of_related_obj)
732
-            ? $this->get_first_related($model_name_of_related_obj)
733
-            : null;
734
-    }
735
-
736
-
737
-    /**
738
-     * Like EE_Line_Item::get_object(), but can only ever actually return an EE_Ticket.
739
-     * (IE, if this line item is for a price or something else, will return NULL)
740
-     *
741
-     * @param array $query_params
742
-     * @return EE_Base_Class|EE_Ticket
743
-     * @throws EE_Error
744
-     * @throws InvalidArgumentException
745
-     * @throws InvalidDataTypeException
746
-     * @throws InvalidInterfaceException
747
-     * @throws ReflectionException
748
-     */
749
-    public function ticket($query_params = array())
750
-    {
751
-        // we're going to assume that when this method is called
752
-        // we always want to receive the attached ticket EVEN if that ticket is archived.
753
-        // This can be overridden via the incoming $query_params argument
754
-        $remove_defaults = array('default_where_conditions' => 'none');
755
-        $query_params = array_merge($remove_defaults, $query_params);
756
-        return $this->get_first_related(EEM_Line_Item::OBJ_TYPE_TICKET, $query_params);
757
-    }
758
-
759
-
760
-    /**
761
-     * Gets the EE_Datetime that's related to the ticket, IF this is for a ticket
762
-     *
763
-     * @return EE_Datetime | NULL
764
-     * @throws EE_Error
765
-     * @throws InvalidArgumentException
766
-     * @throws InvalidDataTypeException
767
-     * @throws InvalidInterfaceException
768
-     * @throws ReflectionException
769
-     */
770
-    public function get_ticket_datetime()
771
-    {
772
-        if ($this->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET) {
773
-            $ticket = $this->ticket();
774
-            if ($ticket instanceof EE_Ticket) {
775
-                $datetime = $ticket->first_datetime();
776
-                if ($datetime instanceof EE_Datetime) {
777
-                    return $datetime;
778
-                }
779
-            }
780
-        }
781
-        return null;
782
-    }
783
-
784
-
785
-    /**
786
-     * Gets the event's name that's related to the ticket, if this is for
787
-     * a ticket
788
-     *
789
-     * @return string
790
-     * @throws EE_Error
791
-     * @throws InvalidArgumentException
792
-     * @throws InvalidDataTypeException
793
-     * @throws InvalidInterfaceException
794
-     * @throws ReflectionException
795
-     */
796
-    public function ticket_event_name()
797
-    {
798
-        $event_name = esc_html__('Unknown', 'event_espresso');
799
-        $event = $this->ticket_event();
800
-        if ($event instanceof EE_Event) {
801
-            $event_name = $event->name();
802
-        }
803
-        return $event_name;
804
-    }
805
-
806
-
807
-    /**
808
-     * Gets the event that's related to the ticket, if this line item represents a ticket.
809
-     *
810
-     * @return EE_Event|null
811
-     * @throws EE_Error
812
-     * @throws InvalidArgumentException
813
-     * @throws InvalidDataTypeException
814
-     * @throws InvalidInterfaceException
815
-     * @throws ReflectionException
816
-     */
817
-    public function ticket_event()
818
-    {
819
-        $event = null;
820
-        $ticket = $this->ticket();
821
-        if ($ticket instanceof EE_Ticket) {
822
-            $datetime = $ticket->first_datetime();
823
-            if ($datetime instanceof EE_Datetime) {
824
-                $event = $datetime->event();
825
-            }
826
-        }
827
-        return $event;
828
-    }
829
-
830
-
831
-    /**
832
-     * Gets the first datetime for this lien item, assuming it's for a ticket
833
-     *
834
-     * @param string $date_format
835
-     * @param string $time_format
836
-     * @return string
837
-     * @throws EE_Error
838
-     * @throws InvalidArgumentException
839
-     * @throws InvalidDataTypeException
840
-     * @throws InvalidInterfaceException
841
-     * @throws ReflectionException
842
-     */
843
-    public function ticket_datetime_start($date_format = '', $time_format = '')
844
-    {
845
-        $first_datetime_string = esc_html__('Unknown', 'event_espresso');
846
-        $datetime = $this->get_ticket_datetime();
847
-        if ($datetime) {
848
-            $first_datetime_string = $datetime->start_date_and_time($date_format, $time_format);
849
-        }
850
-        return $first_datetime_string;
851
-    }
852
-
853
-
854
-    /**
855
-     * Adds the line item as a child to this line item. If there is another child line
856
-     * item with the same LIN_code, it is overwritten by this new one
857
-     *
858
-     * @param EEI_Line_Item $line_item
859
-     * @param bool          $set_order
860
-     * @return bool success
861
-     * @throws EE_Error
862
-     * @throws InvalidArgumentException
863
-     * @throws InvalidDataTypeException
864
-     * @throws InvalidInterfaceException
865
-     * @throws ReflectionException
866
-     */
867
-    public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true)
868
-    {
869
-        // should we calculate the LIN_order for this line item ?
870
-        if ($set_order || $line_item->order() === null) {
871
-            $line_item->set_order(count($this->children()));
872
-        }
873
-        if ($this->ID()) {
874
-            // check for any duplicate line items (with the same code), if so, this replaces it
875
-            $line_item_with_same_code = $this->get_child_line_item($line_item->code());
876
-            if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) {
877
-                $this->delete_child_line_item($line_item_with_same_code->code());
878
-            }
879
-            $line_item->set_parent_ID($this->ID());
880
-            if ($this->TXN_ID()) {
881
-                $line_item->set_TXN_ID($this->TXN_ID());
882
-            }
883
-            return $line_item->save();
884
-        }
885
-        $this->_children[ $line_item->code() ] = $line_item;
886
-        if ($line_item->parent() !== $this) {
887
-            $line_item->set_parent($this);
888
-        }
889
-        return true;
890
-    }
891
-
892
-
893
-    /**
894
-     * Similar to EE_Base_Class::_add_relation_to, except this isn't a normal relation.
895
-     * If this line item is saved to the DB, this is just a wrapper for set_parent_ID() and save()
896
-     * However, if this line item is NOT saved to the DB, this just caches the parent on
897
-     * the EE_Line_Item::_parent property.
898
-     *
899
-     * @param EE_Line_Item $line_item
900
-     * @throws EE_Error
901
-     * @throws InvalidArgumentException
902
-     * @throws InvalidDataTypeException
903
-     * @throws InvalidInterfaceException
904
-     * @throws ReflectionException
905
-     */
906
-    public function set_parent($line_item)
907
-    {
908
-        if ($this->ID()) {
909
-            if (! $line_item->ID()) {
910
-                $line_item->save();
911
-            }
912
-            $this->set_parent_ID($line_item->ID());
913
-            $this->save();
914
-        } else {
915
-            $this->_parent = $line_item;
916
-            $this->set_parent_ID($line_item->ID());
917
-        }
918
-    }
919
-
920
-
921
-    /**
922
-     * Gets the child line item as specified by its code. Because this returns an object (by reference)
923
-     * you can modify this child line item and the parent (this object) can know about them
924
-     * because it also has a reference to that line item
925
-     *
926
-     * @param string $code
927
-     * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
928
-     * @throws EE_Error
929
-     * @throws InvalidArgumentException
930
-     * @throws InvalidDataTypeException
931
-     * @throws InvalidInterfaceException
932
-     * @throws ReflectionException
933
-     */
934
-    public function get_child_line_item($code)
935
-    {
936
-        if ($this->ID()) {
937
-            return $this->get_model()->get_one(
938
-                array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code))
939
-            );
940
-        }
941
-        return isset($this->_children[ $code ])
942
-            ? $this->_children[ $code ]
943
-            : null;
944
-    }
945
-
946
-
947
-    /**
948
-     * Returns how many items are deleted (or, if this item has not been saved ot the DB yet, just how many it HAD
949
-     * cached on it)
950
-     *
951
-     * @return int
952
-     * @throws EE_Error
953
-     * @throws InvalidArgumentException
954
-     * @throws InvalidDataTypeException
955
-     * @throws InvalidInterfaceException
956
-     * @throws ReflectionException
957
-     */
958
-    public function delete_children_line_items()
959
-    {
960
-        if ($this->ID()) {
961
-            return $this->get_model()->delete(array(array('LIN_parent' => $this->ID())));
962
-        }
963
-        $count = count($this->_children);
964
-        $this->_children = array();
965
-        return $count;
966
-    }
967
-
968
-
969
-    /**
970
-     * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line
971
-     * HAS NOT been saved to the DB, removes the child line item with index $code.
972
-     * Also searches through the child's children for a matching line item. However, once a line item has been found
973
-     * and deleted, stops searching (so if there are line items with duplicate codes, only the first one found will be
974
-     * deleted)
975
-     *
976
-     * @param string $code
977
-     * @param bool   $stop_search_once_found
978
-     * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to
979
-     *             the DB yet)
980
-     * @throws EE_Error
981
-     * @throws InvalidArgumentException
982
-     * @throws InvalidDataTypeException
983
-     * @throws InvalidInterfaceException
984
-     * @throws ReflectionException
985
-     */
986
-    public function delete_child_line_item($code, $stop_search_once_found = true)
987
-    {
988
-        if ($this->ID()) {
989
-            $items_deleted = 0;
990
-            if ($this->code() === $code) {
991
-                $items_deleted += EEH_Line_Item::delete_all_child_items($this);
992
-                $items_deleted += (int) $this->delete();
993
-                if ($stop_search_once_found) {
994
-                    return $items_deleted;
995
-                }
996
-            }
997
-            foreach ($this->children() as $child_line_item) {
998
-                $items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found);
999
-            }
1000
-            return $items_deleted;
1001
-        }
1002
-        if (isset($this->_children[ $code ])) {
1003
-            unset($this->_children[ $code ]);
1004
-            return 1;
1005
-        }
1006
-        return 0;
1007
-    }
1008
-
1009
-
1010
-    /**
1011
-     * If this line item is in the database, is of the type subtotal, and
1012
-     * has no children, why do we have it? It should be deleted so this function
1013
-     * does that
1014
-     *
1015
-     * @return boolean
1016
-     * @throws EE_Error
1017
-     * @throws InvalidArgumentException
1018
-     * @throws InvalidDataTypeException
1019
-     * @throws InvalidInterfaceException
1020
-     * @throws ReflectionException
1021
-     */
1022
-    public function delete_if_childless_subtotal()
1023
-    {
1024
-        if ($this->ID() && $this->type() === EEM_Line_Item::type_sub_total && ! $this->children()) {
1025
-            return $this->delete();
1026
-        }
1027
-        return false;
1028
-    }
1029
-
1030
-
1031
-    /**
1032
-     * Creates a code and returns a string. doesn't assign the code to this model object
1033
-     *
1034
-     * @return string
1035
-     * @throws EE_Error
1036
-     * @throws InvalidArgumentException
1037
-     * @throws InvalidDataTypeException
1038
-     * @throws InvalidInterfaceException
1039
-     * @throws ReflectionException
1040
-     */
1041
-    public function generate_code()
1042
-    {
1043
-        // each line item in the cart requires a unique identifier
1044
-        return md5($this->get('OBJ_type') . $this->get('OBJ_ID') . microtime());
1045
-    }
1046
-
1047
-
1048
-    /**
1049
-     * @return bool
1050
-     * @throws EE_Error
1051
-     * @throws InvalidArgumentException
1052
-     * @throws InvalidDataTypeException
1053
-     * @throws InvalidInterfaceException
1054
-     * @throws ReflectionException
1055
-     */
1056
-    public function is_tax()
1057
-    {
1058
-        return $this->type() === EEM_Line_Item::type_tax;
1059
-    }
1060
-
1061
-
1062
-    /**
1063
-     * @return bool
1064
-     * @throws EE_Error
1065
-     * @throws InvalidArgumentException
1066
-     * @throws InvalidDataTypeException
1067
-     * @throws InvalidInterfaceException
1068
-     * @throws ReflectionException
1069
-     */
1070
-    public function is_tax_sub_total()
1071
-    {
1072
-        return $this->type() === EEM_Line_Item::type_tax_sub_total;
1073
-    }
1074
-
1075
-
1076
-    /**
1077
-     * @return bool
1078
-     * @throws EE_Error
1079
-     * @throws InvalidArgumentException
1080
-     * @throws InvalidDataTypeException
1081
-     * @throws InvalidInterfaceException
1082
-     * @throws ReflectionException
1083
-     */
1084
-    public function is_line_item()
1085
-    {
1086
-        return $this->type() === EEM_Line_Item::type_line_item;
1087
-    }
1088
-
1089
-
1090
-    /**
1091
-     * @return bool
1092
-     * @throws EE_Error
1093
-     * @throws InvalidArgumentException
1094
-     * @throws InvalidDataTypeException
1095
-     * @throws InvalidInterfaceException
1096
-     * @throws ReflectionException
1097
-     */
1098
-    public function is_sub_line_item()
1099
-    {
1100
-        return $this->type() === EEM_Line_Item::type_sub_line_item;
1101
-    }
1102
-
1103
-
1104
-    /**
1105
-     * @return bool
1106
-     * @throws EE_Error
1107
-     * @throws InvalidArgumentException
1108
-     * @throws InvalidDataTypeException
1109
-     * @throws InvalidInterfaceException
1110
-     * @throws ReflectionException
1111
-     */
1112
-    public function is_sub_total()
1113
-    {
1114
-        return $this->type() === EEM_Line_Item::type_sub_total;
1115
-    }
1116
-
1117
-
1118
-    /**
1119
-     * Whether or not this line item is a cancellation line item
1120
-     *
1121
-     * @return boolean
1122
-     * @throws EE_Error
1123
-     * @throws InvalidArgumentException
1124
-     * @throws InvalidDataTypeException
1125
-     * @throws InvalidInterfaceException
1126
-     * @throws ReflectionException
1127
-     */
1128
-    public function is_cancellation()
1129
-    {
1130
-        return EEM_Line_Item::type_cancellation === $this->type();
1131
-    }
1132
-
1133
-
1134
-    /**
1135
-     * @return bool
1136
-     * @throws EE_Error
1137
-     * @throws InvalidArgumentException
1138
-     * @throws InvalidDataTypeException
1139
-     * @throws InvalidInterfaceException
1140
-     * @throws ReflectionException
1141
-     */
1142
-    public function is_total()
1143
-    {
1144
-        return $this->type() === EEM_Line_Item::type_total;
1145
-    }
1146
-
1147
-
1148
-    /**
1149
-     * @return bool
1150
-     * @throws EE_Error
1151
-     * @throws InvalidArgumentException
1152
-     * @throws InvalidDataTypeException
1153
-     * @throws InvalidInterfaceException
1154
-     * @throws ReflectionException
1155
-     */
1156
-    public function is_cancelled()
1157
-    {
1158
-        return $this->type() === EEM_Line_Item::type_cancellation;
1159
-    }
1160
-
1161
-
1162
-    /**
1163
-     * @return string like '2, 004.00', formatted according to the localized currency
1164
-     * @throws EE_Error
1165
-     * @throws InvalidArgumentException
1166
-     * @throws InvalidDataTypeException
1167
-     * @throws InvalidInterfaceException
1168
-     * @throws ReflectionException
1169
-     */
1170
-    public function unit_price_no_code()
1171
-    {
1172
-        return $this->get_pretty('LIN_unit_price', 'no_currency_code');
1173
-    }
1174
-
1175
-
1176
-    /**
1177
-     * @return string like '2, 004.00', formatted according to the localized currency
1178
-     * @throws EE_Error
1179
-     * @throws InvalidArgumentException
1180
-     * @throws InvalidDataTypeException
1181
-     * @throws InvalidInterfaceException
1182
-     * @throws ReflectionException
1183
-     */
1184
-    public function total_no_code()
1185
-    {
1186
-        return $this->get_pretty('LIN_total', 'no_currency_code');
1187
-    }
1188
-
1189
-
1190
-    /**
1191
-     * Gets the final total on this item, taking taxes into account.
1192
-     * Has the side-effect of setting the sub-total as it was just calculated.
1193
-     * If this is used on a grand-total line item, also updates the transaction's
1194
-     * TXN_total (provided this line item is allowed to persist, otherwise we don't
1195
-     * want to change a persistable transaction with info from a non-persistent line item)
1196
-     *
1197
-     * @param bool $update_txn_status
1198
-     * @return float
1199
-     * @throws EE_Error
1200
-     * @throws InvalidArgumentException
1201
-     * @throws InvalidDataTypeException
1202
-     * @throws InvalidInterfaceException
1203
-     * @throws ReflectionException
1204
-     * @throws RuntimeException
1205
-     */
1206
-    public function recalculate_total_including_taxes($update_txn_status = false)
1207
-    {
1208
-        $pre_tax_total = $this->recalculate_pre_tax_total();
1209
-        $tax_total = $this->recalculate_taxes_and_tax_total();
1210
-        $total = $pre_tax_total + $tax_total;
1211
-        // no negative totals plz
1212
-        $total = max($total, 0);
1213
-        $this->set_total($total);
1214
-        // only update the related transaction's total
1215
-        // if we intend to save this line item and its a grand total
1216
-        if ($this->allow_persist() && $this->type() === EEM_Line_Item::type_total
1217
-            && $this->transaction()
1218
-               instanceof
1219
-               EE_Transaction
1220
-        ) {
1221
-            $this->transaction()->set_total($total);
1222
-            if ($update_txn_status) {
1223
-                // don't save the TXN because that will be done below
1224
-                // and the following method only saves if the status changes
1225
-                $this->transaction()->update_status_based_on_total_paid(false);
1226
-            }
1227
-            if ($this->transaction()->ID()) {
1228
-                $this->transaction()->save();
1229
-            }
1230
-        }
1231
-        $this->maybe_save();
1232
-        return $total;
1233
-    }
1234
-
1235
-
1236
-    /**
1237
-     * Recursively goes through all the children and recalculates sub-totals EXCEPT for
1238
-     * tax-sub-totals (they're a an odd beast). Updates the 'total' on each line item according to either its
1239
-     * unit price * quantity or the total of all its children EXCEPT when we're only calculating the taxable total and
1240
-     * when this is called on the grand total
1241
-     *
1242
-     * @return float
1243
-     * @throws EE_Error
1244
-     * @throws InvalidArgumentException
1245
-     * @throws InvalidDataTypeException
1246
-     * @throws InvalidInterfaceException
1247
-     * @throws ReflectionException
1248
-     */
1249
-    public function recalculate_pre_tax_total()
1250
-    {
1251
-        $total = 0;
1252
-        $my_children = $this->children();
1253
-        $has_children = ! empty($my_children);
1254
-        if ($has_children && $this->is_line_item()) {
1255
-            $total = $this->_recalculate_pretax_total_for_line_item($total, $my_children);
1256
-        } elseif (! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) {
1257
-            $total = $this->unit_price() * $this->quantity();
1258
-        } elseif ($this->is_sub_total() || $this->is_total()) {
1259
-            $total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children);
1260
-        } elseif ($this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled()) {
1261
-            // completely ignore tax totals, tax sub-totals, and cancelled line items, when calculating the pre-tax-total
1262
-            return 0;
1263
-        }
1264
-        // ensure all non-line items and non-sub-line-items have a quantity of 1 (except for Events)
1265
-        if (! $this->is_line_item() && ! $this->is_sub_line_item() && ! $this->is_cancellation()
1266
-        ) {
1267
-            if ($this->OBJ_type() !== EEM_Line_Item::OBJ_TYPE_EVENT) {
1268
-                $this->set_quantity(1);
1269
-            }
1270
-            if (! $this->is_percent()) {
1271
-                $this->set_unit_price($total);
1272
-            }
1273
-        }
1274
-        // we don't want to bother saving grand totals, because that needs to factor in taxes anyways
1275
-        // so it ought to be
1276
-        if (! $this->is_total()) {
1277
-            $this->set_total($total);
1278
-            // if not a percent line item, make sure we keep the unit price in sync
1279
-            if ($has_children
1280
-                && $this->is_line_item()
1281
-                && ! $this->is_percent()
1282
-            ) {
1283
-                if ($this->quantity() === 0) {
1284
-                    $new_unit_price = 0;
1285
-                } else {
1286
-                    $new_unit_price = $this->total() / $this->quantity();
1287
-                }
1288
-                $this->set_unit_price($new_unit_price);
1289
-            }
1290
-            $this->maybe_save();
1291
-        }
1292
-        return $total;
1293
-    }
1294
-
1295
-
1296
-    /**
1297
-     * Calculates the pretax total when this line item is a subtotal or total line item.
1298
-     * Basically does a sum-then-round approach (ie, any percent line item that are children
1299
-     * will calculate their total based on the un-rounded total we're working with so far, and
1300
-     * THEN round the result; instead of rounding as we go like with sub-line-items)
1301
-     *
1302
-     * @param float          $calculated_total_so_far
1303
-     * @param EE_Line_Item[] $my_children
1304
-     * @return float
1305
-     * @throws EE_Error
1306
-     * @throws InvalidArgumentException
1307
-     * @throws InvalidDataTypeException
1308
-     * @throws InvalidInterfaceException
1309
-     * @throws ReflectionException
1310
-     */
1311
-    protected function _recalculate_pretax_total_for_subtotal($calculated_total_so_far, $my_children = null)
1312
-    {
1313
-        if ($my_children === null) {
1314
-            $my_children = $this->children();
1315
-        }
1316
-        $subtotal_quantity = 0;
1317
-        // get the total of all its children
1318
-        foreach ($my_children as $child_line_item) {
1319
-            if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) {
1320
-                // percentage line items are based on total so far
1321
-                if ($child_line_item->is_percent()) {
1322
-                    $percent_total = $calculated_total_so_far * $child_line_item->percent() / 100;
1323
-                    $child_line_item->set_total($calculated_total_so_far * $child_line_item->percent() / 100);
1324
-                    // so far all percent line items should have a quantity of 1
1325
-                    // (ie, no double percent discounts. Although that might be requested someday)
1326
-                    $child_line_item->set_quantity(1);
1327
-                    $child_line_item->maybe_save();
1328
-                    $calculated_total_so_far += $percent_total;
1329
-                } else {
1330
-                    // verify flat sub-line-item quantities match their parent
1331
-                    if ($child_line_item->is_sub_line_item()) {
1332
-                        $child_line_item->set_quantity($this->quantity());
1333
-                    }
1334
-                    $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total();
1335
-                    $subtotal_quantity += $child_line_item->quantity();
1336
-                }
1337
-            }
1338
-        }
1339
-        if ($this->is_sub_total()) {
1340
-            // no negative totals plz
1341
-            $calculated_total_so_far = max($calculated_total_so_far, 0);
1342
-            $subtotal_quantity = $subtotal_quantity > 0 ? 1 : 0;
1343
-            $this->set_quantity($subtotal_quantity);
1344
-            $this->maybe_save();
1345
-        }
1346
-        return $calculated_total_so_far;
1347
-    }
1348
-
1349
-
1350
-    /**
1351
-     * Calculates the pretax total for a normal line item, in a round-then-sum approach
1352
-     * (where each sub-line-item is applied to the base price for the line item
1353
-     * and the result is immediately rounded, rather than summing all the sub-line-items
1354
-     * then rounding, like we do when recalculating pretax totals on totals and subtotals).
1355
-     *
1356
-     * @param float          $calculated_total_so_far
1357
-     * @param EE_Line_Item[] $my_children
1358
-     * @return float
1359
-     * @throws EE_Error
1360
-     * @throws InvalidArgumentException
1361
-     * @throws InvalidDataTypeException
1362
-     * @throws InvalidInterfaceException
1363
-     * @throws ReflectionException
1364
-     */
1365
-    protected function _recalculate_pretax_total_for_line_item($calculated_total_so_far, $my_children = null)
1366
-    {
1367
-        if ($my_children === null) {
1368
-            $my_children = $this->children();
1369
-        }
1370
-        // we need to keep track of the running total for a single item,
1371
-        // because we need to round as we go
1372
-        $unit_price_for_total = 0;
1373
-        $quantity_for_total = 1;
1374
-        // get the total of all its children
1375
-        foreach ($my_children as $child_line_item) {
1376
-            if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) {
1377
-                if ($child_line_item->is_percent()) {
1378
-                    // it should be the unit-price-so-far multiplied by teh percent multiplied by the quantity
1379
-                    // not total multiplied by percent, because that ignores rounding along-the-way
1380
-                    $percent_unit_price = $unit_price_for_total * $child_line_item->percent() / 100;
1381
-                    $percent_total = $percent_unit_price * $quantity_for_total;
1382
-                    $child_line_item->set_total($percent_total);
1383
-                    // so far all percent line items should have a quantity of 1
1384
-                    // (ie, no double percent discounts. Although that might be requested someday)
1385
-                    $child_line_item->set_quantity(1);
1386
-                    $child_line_item->maybe_save();
1387
-                    $calculated_total_so_far += $percent_total;
1388
-                    $unit_price_for_total += $percent_unit_price;
1389
-                } else {
1390
-                    // verify flat sub-line-item quantities match their parent
1391
-                    if ($child_line_item->is_sub_line_item()) {
1392
-                        $child_line_item->set_quantity($this->quantity());
1393
-                    }
1394
-                    $quantity_for_total = $child_line_item->quantity();
1395
-                    $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total();
1396
-                    $unit_price_for_total += $child_line_item->unit_price();
1397
-                }
1398
-            }
1399
-        }
1400
-        return round(
1401
-            $unit_price_for_total,
1402
-            EE_Registry::instance()->CFG->currency->dec_plc
1403
-        ) * $quantity_for_total;
1404
-    }
1405
-
1406
-
1407
-    /**
1408
-     * Recalculates the total on each individual tax (based on a recalculation of the pre-tax total), sets
1409
-     * the totals on each tax calculated, and returns the final tax total. Re-saves tax line items
1410
-     * and tax sub-total if already in the DB
1411
-     *
1412
-     * @return float
1413
-     * @throws EE_Error
1414
-     * @throws InvalidArgumentException
1415
-     * @throws InvalidDataTypeException
1416
-     * @throws InvalidInterfaceException
1417
-     * @throws ReflectionException
1418
-     */
1419
-    public function recalculate_taxes_and_tax_total()
1420
-    {
1421
-        // get all taxes
1422
-        $taxes = $this->tax_descendants();
1423
-        // calculate the pretax total
1424
-        $taxable_total = $this->taxable_total();
1425
-        $tax_total = 0;
1426
-        foreach ($taxes as $tax) {
1427
-            $total_on_this_tax = $taxable_total * $tax->percent() / 100;
1428
-            // remember the total on this line item
1429
-            $tax->set_total($total_on_this_tax);
1430
-            $tax->maybe_save();
1431
-            $tax_total += $tax->total();
1432
-        }
1433
-        $this->_recalculate_tax_sub_total();
1434
-        return $tax_total;
1435
-    }
1436
-
1437
-
1438
-    /**
1439
-     * Simply forces all the tax-sub-totals to recalculate. Assumes the taxes have been calculated
1440
-     *
1441
-     * @return void
1442
-     * @throws EE_Error
1443
-     * @throws InvalidArgumentException
1444
-     * @throws InvalidDataTypeException
1445
-     * @throws InvalidInterfaceException
1446
-     * @throws ReflectionException
1447
-     */
1448
-    private function _recalculate_tax_sub_total()
1449
-    {
1450
-        if ($this->is_tax_sub_total()) {
1451
-            $total = 0;
1452
-            $total_percent = 0;
1453
-            // simply loop through all its children (which should be taxes) and sum their total
1454
-            foreach ($this->children() as $child_tax) {
1455
-                if ($child_tax instanceof EE_Line_Item) {
1456
-                    $total += $child_tax->total();
1457
-                    $total_percent += $child_tax->percent();
1458
-                }
1459
-            }
1460
-            $this->set_total($total);
1461
-            $this->set_percent($total_percent);
1462
-            $this->maybe_save();
1463
-        } elseif ($this->is_total()) {
1464
-            foreach ($this->children() as $maybe_tax_subtotal) {
1465
-                if ($maybe_tax_subtotal instanceof EE_Line_Item) {
1466
-                    $maybe_tax_subtotal->_recalculate_tax_sub_total();
1467
-                }
1468
-            }
1469
-        }
1470
-    }
1471
-
1472
-
1473
-    /**
1474
-     * Gets the total tax on this line item. Assumes taxes have already been calculated using
1475
-     * recalculate_taxes_and_total
1476
-     *
1477
-     * @return float
1478
-     * @throws EE_Error
1479
-     * @throws InvalidArgumentException
1480
-     * @throws InvalidDataTypeException
1481
-     * @throws InvalidInterfaceException
1482
-     * @throws ReflectionException
1483
-     */
1484
-    public function get_total_tax()
1485
-    {
1486
-        $this->_recalculate_tax_sub_total();
1487
-        $total = 0;
1488
-        foreach ($this->tax_descendants() as $tax_line_item) {
1489
-            if ($tax_line_item instanceof EE_Line_Item) {
1490
-                $total += $tax_line_item->total();
1491
-            }
1492
-        }
1493
-        return $total;
1494
-    }
1495
-
1496
-
1497
-    /**
1498
-     * Gets the total for all the items purchased only
1499
-     *
1500
-     * @return float
1501
-     * @throws EE_Error
1502
-     * @throws InvalidArgumentException
1503
-     * @throws InvalidDataTypeException
1504
-     * @throws InvalidInterfaceException
1505
-     * @throws ReflectionException
1506
-     */
1507
-    public function get_items_total()
1508
-    {
1509
-        // by default, let's make sure we're consistent with the existing line item
1510
-        if ($this->is_total()) {
1511
-            $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal($this);
1512
-            if ($pretax_subtotal_li instanceof EE_Line_Item) {
1513
-                return $pretax_subtotal_li->total();
1514
-            }
1515
-        }
1516
-        $total = 0;
1517
-        foreach ($this->get_items() as $item) {
1518
-            if ($item instanceof EE_Line_Item) {
1519
-                $total += $item->total();
1520
-            }
1521
-        }
1522
-        return $total;
1523
-    }
1524
-
1525
-
1526
-    /**
1527
-     * Gets all the descendants (ie, children or children of children etc) that
1528
-     * are of the type 'tax'
1529
-     *
1530
-     * @return EE_Line_Item[]
1531
-     * @throws EE_Error
1532
-     */
1533
-    public function tax_descendants()
1534
-    {
1535
-        return EEH_Line_Item::get_tax_descendants($this);
1536
-    }
1537
-
1538
-
1539
-    /**
1540
-     * Gets all the real items purchased which are children of this item
1541
-     *
1542
-     * @return EE_Line_Item[]
1543
-     * @throws EE_Error
1544
-     */
1545
-    public function get_items()
1546
-    {
1547
-        return EEH_Line_Item::get_line_item_descendants($this);
1548
-    }
1549
-
1550
-
1551
-    /**
1552
-     * Returns the amount taxable among this line item's children (or if it has no children,
1553
-     * how much of it is taxable). Does not recalculate totals or subtotals.
1554
-     * If the taxable total is negative, (eg, if none of the tickets were taxable,
1555
-     * but there is a "Taxable" discount), returns 0.
1556
-     *
1557
-     * @return float
1558
-     * @throws EE_Error
1559
-     * @throws InvalidArgumentException
1560
-     * @throws InvalidDataTypeException
1561
-     * @throws InvalidInterfaceException
1562
-     * @throws ReflectionException
1563
-     */
1564
-    public function taxable_total()
1565
-    {
1566
-        $total = 0;
1567
-        if ($this->children()) {
1568
-            foreach ($this->children() as $child_line_item) {
1569
-                if ($child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) {
1570
-                    // if it's a percent item, only take into account the percent
1571
-                    // that's taxable too (the taxable total so far)
1572
-                    if ($child_line_item->is_percent()) {
1573
-                        $total += ($total * $child_line_item->percent() / 100);
1574
-                    } else {
1575
-                        $total += $child_line_item->total();
1576
-                    }
1577
-                } elseif ($child_line_item->type() === EEM_Line_Item::type_sub_total) {
1578
-                    $total += $child_line_item->taxable_total();
1579
-                }
1580
-            }
1581
-        }
1582
-        return max($total, 0);
1583
-    }
1584
-
1585
-
1586
-    /**
1587
-     * Gets the transaction for this line item
1588
-     *
1589
-     * @return EE_Base_Class|EE_Transaction
1590
-     * @throws EE_Error
1591
-     * @throws InvalidArgumentException
1592
-     * @throws InvalidDataTypeException
1593
-     * @throws InvalidInterfaceException
1594
-     * @throws ReflectionException
1595
-     */
1596
-    public function transaction()
1597
-    {
1598
-        return $this->get_first_related(EEM_Line_Item::OBJ_TYPE_TRANSACTION);
1599
-    }
1600
-
1601
-
1602
-    /**
1603
-     * Saves this line item to the DB, and recursively saves its descendants.
1604
-     * Because there currently is no proper parent-child relation on the model,
1605
-     * save_this_and_cached() will NOT save the descendants.
1606
-     * Also sets the transaction on this line item and all its descendants before saving
1607
-     *
1608
-     * @param int $txn_id if none is provided, assumes $this->TXN_ID()
1609
-     * @return int count of items saved
1610
-     * @throws EE_Error
1611
-     * @throws InvalidArgumentException
1612
-     * @throws InvalidDataTypeException
1613
-     * @throws InvalidInterfaceException
1614
-     * @throws ReflectionException
1615
-     */
1616
-    public function save_this_and_descendants_to_txn($txn_id = null)
1617
-    {
1618
-        $count = 0;
1619
-        if (! $txn_id) {
1620
-            $txn_id = $this->TXN_ID();
1621
-        }
1622
-        $this->set_TXN_ID($txn_id);
1623
-        $children = $this->children();
1624
-        $count += $this->save()
1625
-            ? 1
1626
-            : 0;
1627
-        foreach ($children as $child_line_item) {
1628
-            if ($child_line_item instanceof EE_Line_Item) {
1629
-                $child_line_item->set_parent_ID($this->ID());
1630
-                $count += $child_line_item->save_this_and_descendants_to_txn($txn_id);
1631
-            }
1632
-        }
1633
-        return $count;
1634
-    }
1635
-
1636
-
1637
-    /**
1638
-     * Saves this line item to the DB, and recursively saves its descendants.
1639
-     *
1640
-     * @return int count of items saved
1641
-     * @throws EE_Error
1642
-     * @throws InvalidArgumentException
1643
-     * @throws InvalidDataTypeException
1644
-     * @throws InvalidInterfaceException
1645
-     * @throws ReflectionException
1646
-     */
1647
-    public function save_this_and_descendants()
1648
-    {
1649
-        $count = 0;
1650
-        $children = $this->children();
1651
-        $count += $this->save()
1652
-            ? 1
1653
-            : 0;
1654
-        foreach ($children as $child_line_item) {
1655
-            if ($child_line_item instanceof EE_Line_Item) {
1656
-                $child_line_item->set_parent_ID($this->ID());
1657
-                $count += $child_line_item->save_this_and_descendants();
1658
-            }
1659
-        }
1660
-        return $count;
1661
-    }
1662
-
1663
-
1664
-    /**
1665
-     * returns the cancellation line item if this item was cancelled
1666
-     *
1667
-     * @return EE_Line_Item[]
1668
-     * @throws InvalidArgumentException
1669
-     * @throws InvalidInterfaceException
1670
-     * @throws InvalidDataTypeException
1671
-     * @throws ReflectionException
1672
-     * @throws EE_Error
1673
-     */
1674
-    public function get_cancellations()
1675
-    {
1676
-        EE_Registry::instance()->load_helper('Line_Item');
1677
-        return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation);
1678
-    }
1679
-
1680
-
1681
-    /**
1682
-     * If this item has an ID, then this saves it again to update the db
1683
-     *
1684
-     * @return int count of items saved
1685
-     * @throws EE_Error
1686
-     * @throws InvalidArgumentException
1687
-     * @throws InvalidDataTypeException
1688
-     * @throws InvalidInterfaceException
1689
-     * @throws ReflectionException
1690
-     */
1691
-    public function maybe_save()
1692
-    {
1693
-        if ($this->ID()) {
1694
-            return $this->save();
1695
-        }
1696
-        return false;
1697
-    }
1698
-
1699
-
1700
-    /**
1701
-     * clears the cached children and parent from the line item
1702
-     *
1703
-     * @return void
1704
-     */
1705
-    public function clear_related_line_item_cache()
1706
-    {
1707
-        $this->_children = array();
1708
-        $this->_parent = null;
1709
-    }
1710
-
1711
-
1712
-    /**
1713
-     * @param bool $raw
1714
-     * @return int
1715
-     * @throws EE_Error
1716
-     * @throws InvalidArgumentException
1717
-     * @throws InvalidDataTypeException
1718
-     * @throws InvalidInterfaceException
1719
-     * @throws ReflectionException
1720
-     */
1721
-    public function timestamp($raw = false)
1722
-    {
1723
-        return $raw
1724
-            ? $this->get_raw('LIN_timestamp')
1725
-            : $this->get('LIN_timestamp');
1726
-    }
1727
-
1728
-
1729
-
1730
-
1731
-    /************************* DEPRECATED *************************/
1732
-    /**
1733
-     * @deprecated 4.6.0
1734
-     * @param string $type one of the constants on EEM_Line_Item
1735
-     * @return EE_Line_Item[]
1736
-     * @throws EE_Error
1737
-     */
1738
-    protected function _get_descendants_of_type($type)
1739
-    {
1740
-        EE_Error::doing_it_wrong(
1741
-            'EE_Line_Item::_get_descendants_of_type()',
1742
-            sprintf(
1743
-                esc_html__('Method replaced with %1$s', 'event_espresso'),
1744
-                'EEH_Line_Item::get_descendants_of_type()'
1745
-            ),
1746
-            '4.6.0'
1747
-        );
1748
-        return EEH_Line_Item::get_descendants_of_type($this, $type);
1749
-    }
1750
-
1751
-
1752
-    /**
1753
-     * @deprecated 4.6.0
1754
-     * @param string $type like one of the EEM_Line_Item::type_*
1755
-     * @return EE_Line_Item
1756
-     * @throws EE_Error
1757
-     * @throws InvalidArgumentException
1758
-     * @throws InvalidDataTypeException
1759
-     * @throws InvalidInterfaceException
1760
-     * @throws ReflectionException
1761
-     */
1762
-    public function get_nearest_descendant_of_type($type)
1763
-    {
1764
-        EE_Error::doing_it_wrong(
1765
-            'EE_Line_Item::get_nearest_descendant_of_type()',
1766
-            sprintf(
1767
-                esc_html__('Method replaced with %1$s', 'event_espresso'),
1768
-                'EEH_Line_Item::get_nearest_descendant_of_type()'
1769
-            ),
1770
-            '4.6.0'
1771
-        );
1772
-        return EEH_Line_Item::get_nearest_descendant_of_type($this, $type);
1773
-    }
17
+	/**
18
+	 * for children line items (currently not a normal relation)
19
+	 *
20
+	 * @type EE_Line_Item[]
21
+	 */
22
+	protected $_children = array();
23
+
24
+	/**
25
+	 * for the parent line item
26
+	 *
27
+	 * @var EE_Line_Item
28
+	 */
29
+	protected $_parent;
30
+
31
+
32
+	/**
33
+	 * @param array  $props_n_values          incoming values
34
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
35
+	 *                                        used.)
36
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
37
+	 *                                        date_format and the second value is the time format
38
+	 * @return EE_Line_Item
39
+	 * @throws EE_Error
40
+	 * @throws InvalidArgumentException
41
+	 * @throws InvalidDataTypeException
42
+	 * @throws InvalidInterfaceException
43
+	 * @throws ReflectionException
44
+	 */
45
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
46
+	{
47
+		$has_object = parent::_check_for_object(
48
+			$props_n_values,
49
+			__CLASS__,
50
+			$timezone,
51
+			$date_formats
52
+		);
53
+		return $has_object
54
+			? $has_object
55
+			: new self($props_n_values, false, $timezone);
56
+	}
57
+
58
+
59
+	/**
60
+	 * @param array  $props_n_values  incoming values from the database
61
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
62
+	 *                                the website will be used.
63
+	 * @return EE_Line_Item
64
+	 * @throws EE_Error
65
+	 * @throws InvalidArgumentException
66
+	 * @throws InvalidDataTypeException
67
+	 * @throws InvalidInterfaceException
68
+	 * @throws ReflectionException
69
+	 */
70
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
71
+	{
72
+		return new self($props_n_values, true, $timezone);
73
+	}
74
+
75
+
76
+	/**
77
+	 * Adds some defaults if they're not specified
78
+	 *
79
+	 * @param array  $fieldValues
80
+	 * @param bool   $bydb
81
+	 * @param string $timezone
82
+	 * @throws EE_Error
83
+	 * @throws InvalidArgumentException
84
+	 * @throws InvalidDataTypeException
85
+	 * @throws InvalidInterfaceException
86
+	 * @throws ReflectionException
87
+	 */
88
+	protected function __construct($fieldValues = array(), $bydb = false, $timezone = '')
89
+	{
90
+		parent::__construct($fieldValues, $bydb, $timezone);
91
+		if (! $this->get('LIN_code')) {
92
+			$this->set_code($this->generate_code());
93
+		}
94
+	}
95
+
96
+
97
+	/**
98
+	 * Gets ID
99
+	 *
100
+	 * @return int
101
+	 * @throws EE_Error
102
+	 * @throws InvalidArgumentException
103
+	 * @throws InvalidDataTypeException
104
+	 * @throws InvalidInterfaceException
105
+	 * @throws ReflectionException
106
+	 */
107
+	public function ID()
108
+	{
109
+		return $this->get('LIN_ID');
110
+	}
111
+
112
+
113
+	/**
114
+	 * Gets TXN_ID
115
+	 *
116
+	 * @return int
117
+	 * @throws EE_Error
118
+	 * @throws InvalidArgumentException
119
+	 * @throws InvalidDataTypeException
120
+	 * @throws InvalidInterfaceException
121
+	 * @throws ReflectionException
122
+	 */
123
+	public function TXN_ID()
124
+	{
125
+		return $this->get('TXN_ID');
126
+	}
127
+
128
+
129
+	/**
130
+	 * Sets TXN_ID
131
+	 *
132
+	 * @param int $TXN_ID
133
+	 * @throws EE_Error
134
+	 * @throws InvalidArgumentException
135
+	 * @throws InvalidDataTypeException
136
+	 * @throws InvalidInterfaceException
137
+	 * @throws ReflectionException
138
+	 */
139
+	public function set_TXN_ID($TXN_ID)
140
+	{
141
+		$this->set('TXN_ID', $TXN_ID);
142
+	}
143
+
144
+
145
+	/**
146
+	 * Gets name
147
+	 *
148
+	 * @return string
149
+	 * @throws EE_Error
150
+	 * @throws InvalidArgumentException
151
+	 * @throws InvalidDataTypeException
152
+	 * @throws InvalidInterfaceException
153
+	 * @throws ReflectionException
154
+	 */
155
+	public function name()
156
+	{
157
+		$name = $this->get('LIN_name');
158
+		if (! $name) {
159
+			$name = ucwords(str_replace('-', ' ', $this->type()));
160
+		}
161
+		return $name;
162
+	}
163
+
164
+
165
+	/**
166
+	 * Sets name
167
+	 *
168
+	 * @param string $name
169
+	 * @throws EE_Error
170
+	 * @throws InvalidArgumentException
171
+	 * @throws InvalidDataTypeException
172
+	 * @throws InvalidInterfaceException
173
+	 * @throws ReflectionException
174
+	 */
175
+	public function set_name($name)
176
+	{
177
+		$this->set('LIN_name', $name);
178
+	}
179
+
180
+
181
+	/**
182
+	 * Gets desc
183
+	 *
184
+	 * @return string
185
+	 * @throws EE_Error
186
+	 * @throws InvalidArgumentException
187
+	 * @throws InvalidDataTypeException
188
+	 * @throws InvalidInterfaceException
189
+	 * @throws ReflectionException
190
+	 */
191
+	public function desc()
192
+	{
193
+		return $this->get('LIN_desc');
194
+	}
195
+
196
+
197
+	/**
198
+	 * Sets desc
199
+	 *
200
+	 * @param string $desc
201
+	 * @throws EE_Error
202
+	 * @throws InvalidArgumentException
203
+	 * @throws InvalidDataTypeException
204
+	 * @throws InvalidInterfaceException
205
+	 * @throws ReflectionException
206
+	 */
207
+	public function set_desc($desc)
208
+	{
209
+		$this->set('LIN_desc', $desc);
210
+	}
211
+
212
+
213
+	/**
214
+	 * Gets quantity
215
+	 *
216
+	 * @return int
217
+	 * @throws EE_Error
218
+	 * @throws InvalidArgumentException
219
+	 * @throws InvalidDataTypeException
220
+	 * @throws InvalidInterfaceException
221
+	 * @throws ReflectionException
222
+	 */
223
+	public function quantity()
224
+	{
225
+		return $this->get('LIN_quantity');
226
+	}
227
+
228
+
229
+	/**
230
+	 * Sets quantity
231
+	 *
232
+	 * @param int $quantity
233
+	 * @throws EE_Error
234
+	 * @throws InvalidArgumentException
235
+	 * @throws InvalidDataTypeException
236
+	 * @throws InvalidInterfaceException
237
+	 * @throws ReflectionException
238
+	 */
239
+	public function set_quantity($quantity)
240
+	{
241
+		$this->set('LIN_quantity', max($quantity, 0));
242
+	}
243
+
244
+
245
+	/**
246
+	 * Gets item_id
247
+	 *
248
+	 * @return string
249
+	 * @throws EE_Error
250
+	 * @throws InvalidArgumentException
251
+	 * @throws InvalidDataTypeException
252
+	 * @throws InvalidInterfaceException
253
+	 * @throws ReflectionException
254
+	 */
255
+	public function OBJ_ID()
256
+	{
257
+		return $this->get('OBJ_ID');
258
+	}
259
+
260
+
261
+	/**
262
+	 * Sets item_id
263
+	 *
264
+	 * @param string $item_id
265
+	 * @throws EE_Error
266
+	 * @throws InvalidArgumentException
267
+	 * @throws InvalidDataTypeException
268
+	 * @throws InvalidInterfaceException
269
+	 * @throws ReflectionException
270
+	 */
271
+	public function set_OBJ_ID($item_id)
272
+	{
273
+		$this->set('OBJ_ID', $item_id);
274
+	}
275
+
276
+
277
+	/**
278
+	 * Gets item_type
279
+	 *
280
+	 * @return string
281
+	 * @throws EE_Error
282
+	 * @throws InvalidArgumentException
283
+	 * @throws InvalidDataTypeException
284
+	 * @throws InvalidInterfaceException
285
+	 * @throws ReflectionException
286
+	 */
287
+	public function OBJ_type()
288
+	{
289
+		return $this->get('OBJ_type');
290
+	}
291
+
292
+
293
+	/**
294
+	 * Gets item_type
295
+	 *
296
+	 * @return string
297
+	 * @throws EE_Error
298
+	 * @throws InvalidArgumentException
299
+	 * @throws InvalidDataTypeException
300
+	 * @throws InvalidInterfaceException
301
+	 * @throws ReflectionException
302
+	 */
303
+	public function OBJ_type_i18n()
304
+	{
305
+		$obj_type = $this->OBJ_type();
306
+		switch ($obj_type) {
307
+			case EEM_Line_Item::OBJ_TYPE_EVENT:
308
+				$obj_type = esc_html__('Event', 'event_espresso');
309
+				break;
310
+			case EEM_Line_Item::OBJ_TYPE_PRICE:
311
+				$obj_type = esc_html__('Price', 'event_espresso');
312
+				break;
313
+			case EEM_Line_Item::OBJ_TYPE_PROMOTION:
314
+				$obj_type = esc_html__('Promotion', 'event_espresso');
315
+				break;
316
+			case EEM_Line_Item::OBJ_TYPE_TICKET:
317
+				$obj_type = esc_html__('Ticket', 'event_espresso');
318
+				break;
319
+			case EEM_Line_Item::OBJ_TYPE_TRANSACTION:
320
+				$obj_type = esc_html__('Transaction', 'event_espresso');
321
+				break;
322
+		}
323
+		return apply_filters('FHEE__EE_Line_Item__OBJ_type_i18n', $obj_type, $this);
324
+	}
325
+
326
+
327
+	/**
328
+	 * Sets item_type
329
+	 *
330
+	 * @param string $OBJ_type
331
+	 * @throws EE_Error
332
+	 * @throws InvalidArgumentException
333
+	 * @throws InvalidDataTypeException
334
+	 * @throws InvalidInterfaceException
335
+	 * @throws ReflectionException
336
+	 */
337
+	public function set_OBJ_type($OBJ_type)
338
+	{
339
+		$this->set('OBJ_type', $OBJ_type);
340
+	}
341
+
342
+
343
+	/**
344
+	 * Gets unit_price for flat rate items. Percent items should set this to 0.
345
+	 * You may alternatively want to use prettyUnitPrice(), which works for flat and percent items.
346
+	 *
347
+	 * @return float
348
+	 * @throws EE_Error
349
+	 * @throws InvalidArgumentException
350
+	 * @throws InvalidDataTypeException
351
+	 * @throws InvalidInterfaceException
352
+	 * @throws ReflectionException
353
+	 */
354
+	public function unit_price()
355
+	{
356
+		return $this->get('LIN_unit_price');
357
+	}
358
+
359
+	public function prettyUnitPrice()
360
+	{
361
+		if($this->parent_ID() !== 0
362
+			&& $this->parent() instanceof EE_Line_Item
363
+			&& $this->parent()->type() === EEM_Line_Item::type_line_item
364
+		) {
365
+			$quantity = $this->parent()->quantity();
366
+		} else {
367
+			$quantity = $this->quantity();
368
+		}
369
+		if($this->is_percent()) {
370
+			return $this->get_model()->field_settings_for('LIN_unit_price')->prepare_for_pretty_echoing(
371
+				$this->total() / $quantity,
372
+				'no_currency_code'
373
+			);
374
+		} else {
375
+			return $this->unit_price_no_code();
376
+		}
377
+	}
378
+
379
+	/**
380
+	 * Sets unit_price
381
+	 *
382
+	 * @param float $unit_price
383
+	 * @throws EE_Error
384
+	 * @throws InvalidArgumentException
385
+	 * @throws InvalidDataTypeException
386
+	 * @throws InvalidInterfaceException
387
+	 * @throws ReflectionException
388
+	 */
389
+	public function set_unit_price($unit_price)
390
+	{
391
+		if($this->type() !== EEM_Line_Item::type_sub_line_item) { 
392
+			$unit_price = EEH_Money::round_for_currency($unit_price, EE_Config::instance()->currency->code);
393
+		} 
394
+		$this->set('LIN_unit_price', $unit_price);
395
+	}
396
+
397
+
398
+	/**
399
+	 * Checks if this item is a percentage modifier or not
400
+	 *
401
+	 * @return boolean
402
+	 * @throws EE_Error
403
+	 * @throws InvalidArgumentException
404
+	 * @throws InvalidDataTypeException
405
+	 * @throws InvalidInterfaceException
406
+	 * @throws ReflectionException
407
+	 */
408
+	public function is_percent()
409
+	{
410
+		if ($this->is_tax_sub_total()) {
411
+			// tax subtotals HAVE a percent on them, that percentage only applies
412
+			// to taxable items, so its' an exception. Treat it like a flat line item
413
+			return false;
414
+		}
415
+		$unit_price = abs($this->get('LIN_unit_price'));
416
+		$percent = abs($this->get('LIN_percent'));
417
+		if ($unit_price < .001 && $percent) {
418
+			return true;
419
+		}
420
+		if ($unit_price >= .001 && ! $percent) {
421
+			return false;
422
+		}
423
+		if ($unit_price >= .001 && $percent) {
424
+			throw new EE_Error(
425
+				sprintf(
426
+					esc_html__(
427
+						'A Line Item can not have a unit price of (%s) AND a percent (%s)!',
428
+						'event_espresso'
429
+					),
430
+					$unit_price,
431
+					$percent
432
+				)
433
+			);
434
+		}
435
+		// if they're both 0, assume its not a percent item
436
+		return false;
437
+	}
438
+
439
+
440
+	/**
441
+	 * Gets percent (between 100-.001)
442
+	 *
443
+	 * @return float
444
+	 * @throws EE_Error
445
+	 * @throws InvalidArgumentException
446
+	 * @throws InvalidDataTypeException
447
+	 * @throws InvalidInterfaceException
448
+	 * @throws ReflectionException
449
+	 */
450
+	public function percent()
451
+	{
452
+		return $this->get('LIN_percent');
453
+	}
454
+
455
+
456
+	/**
457
+	 * Sets percent (between 100-0.01)
458
+	 *
459
+	 * @param float $percent
460
+	 * @throws EE_Error
461
+	 * @throws InvalidArgumentException
462
+	 * @throws InvalidDataTypeException
463
+	 * @throws InvalidInterfaceException
464
+	 * @throws ReflectionException
465
+	 */
466
+	public function set_percent($percent)
467
+	{
468
+		$this->set('LIN_percent', $percent);
469
+	}
470
+
471
+
472
+	/**
473
+	 * Gets total
474
+	 *
475
+	 * @return float
476
+	 * @throws EE_Error
477
+	 * @throws InvalidArgumentException
478
+	 * @throws InvalidDataTypeException
479
+	 * @throws InvalidInterfaceException
480
+	 * @throws ReflectionException
481
+	 */
482
+	public function total()
483
+	{
484
+		return $this->get('LIN_total');
485
+	}
486
+
487
+
488
+	/**
489
+	 * Sets total
490
+	 *
491
+	 * @param float $total
492
+	 * @throws EE_Error
493
+	 * @throws InvalidArgumentException
494
+	 * @throws InvalidDataTypeException
495
+	 * @throws InvalidInterfaceException
496
+	 * @throws ReflectionException
497
+	 */
498
+	public function set_total($total)
499
+	{
500
+		if($this->type() !== EEM_Line_Item::type_sub_line_item) { 
501
+			$total = EEH_Money::round_for_currency($total, EE_Config::instance()->currency->code); 
502
+		} 
503
+		$this->set('LIN_total', $total);
504
+	}
505
+
506
+
507
+	/**
508
+	 * Gets order
509
+	 *
510
+	 * @return int
511
+	 * @throws EE_Error
512
+	 * @throws InvalidArgumentException
513
+	 * @throws InvalidDataTypeException
514
+	 * @throws InvalidInterfaceException
515
+	 * @throws ReflectionException
516
+	 */
517
+	public function order()
518
+	{
519
+		return $this->get('LIN_order');
520
+	}
521
+
522
+
523
+	/**
524
+	 * Sets order
525
+	 *
526
+	 * @param int $order
527
+	 * @throws EE_Error
528
+	 * @throws InvalidArgumentException
529
+	 * @throws InvalidDataTypeException
530
+	 * @throws InvalidInterfaceException
531
+	 * @throws ReflectionException
532
+	 */
533
+	public function set_order($order)
534
+	{
535
+		$this->set('LIN_order', $order);
536
+	}
537
+
538
+
539
+	/**
540
+	 * Gets parent
541
+	 *
542
+	 * @return int
543
+	 * @throws EE_Error
544
+	 * @throws InvalidArgumentException
545
+	 * @throws InvalidDataTypeException
546
+	 * @throws InvalidInterfaceException
547
+	 * @throws ReflectionException
548
+	 */
549
+	public function parent_ID()
550
+	{
551
+		return $this->get('LIN_parent');
552
+	}
553
+
554
+
555
+	/**
556
+	 * Sets parent
557
+	 *
558
+	 * @param int $parent
559
+	 * @throws EE_Error
560
+	 * @throws InvalidArgumentException
561
+	 * @throws InvalidDataTypeException
562
+	 * @throws InvalidInterfaceException
563
+	 * @throws ReflectionException
564
+	 */
565
+	public function set_parent_ID($parent)
566
+	{
567
+		$this->set('LIN_parent', $parent);
568
+	}
569
+
570
+
571
+	/**
572
+	 * Gets type
573
+	 *
574
+	 * @return string
575
+	 * @throws EE_Error
576
+	 * @throws InvalidArgumentException
577
+	 * @throws InvalidDataTypeException
578
+	 * @throws InvalidInterfaceException
579
+	 * @throws ReflectionException
580
+	 */
581
+	public function type()
582
+	{
583
+		return $this->get('LIN_type');
584
+	}
585
+
586
+
587
+	/**
588
+	 * Sets type
589
+	 *
590
+	 * @param string $type
591
+	 * @throws EE_Error
592
+	 * @throws InvalidArgumentException
593
+	 * @throws InvalidDataTypeException
594
+	 * @throws InvalidInterfaceException
595
+	 * @throws ReflectionException
596
+	 */
597
+	public function set_type($type)
598
+	{
599
+		$this->set('LIN_type', $type);
600
+	}
601
+
602
+
603
+	/**
604
+	 * Gets the line item of which this item is a composite. Eg, if this is a subtotal, the parent might be a total\
605
+	 * If this line item is saved to the DB, fetches the parent from the DB. However, if this line item isn't in the DB
606
+	 * it uses its cached reference to its parent line item (which would have been set by `EE_Line_Item::set_parent()`
607
+	 * or indirectly by `EE_Line_item::add_child_line_item()`)
608
+	 *
609
+	 * @return EE_Base_Class|EE_Line_Item
610
+	 * @throws EE_Error
611
+	 * @throws InvalidArgumentException
612
+	 * @throws InvalidDataTypeException
613
+	 * @throws InvalidInterfaceException
614
+	 * @throws ReflectionException
615
+	 */
616
+	public function parent()
617
+	{
618
+		return $this->ID()
619
+			? $this->get_model()->get_one_by_ID($this->parent_ID())
620
+			: $this->_parent;
621
+	}
622
+
623
+
624
+	/**
625
+	 * Gets ALL the children of this line item (ie, all the parts that contribute towards this total).
626
+	 *
627
+	 * @return EE_Base_Class[]|EE_Line_Item[]
628
+	 * @throws EE_Error
629
+	 * @throws InvalidArgumentException
630
+	 * @throws InvalidDataTypeException
631
+	 * @throws InvalidInterfaceException
632
+	 * @throws ReflectionException
633
+	 */
634
+	public function children()
635
+	{
636
+		if ($this->ID()) {
637
+			return $this->get_model()->get_all(
638
+				array(
639
+					array('LIN_parent' => $this->ID()),
640
+					'order_by' => array('LIN_order' => 'ASC'),
641
+				)
642
+			);
643
+		}
644
+		if (! is_array($this->_children)) {
645
+			$this->_children = array();
646
+		}
647
+		return $this->_children;
648
+	}
649
+
650
+
651
+	/**
652
+	 * Gets code
653
+	 *
654
+	 * @return string
655
+	 * @throws EE_Error
656
+	 * @throws InvalidArgumentException
657
+	 * @throws InvalidDataTypeException
658
+	 * @throws InvalidInterfaceException
659
+	 * @throws ReflectionException
660
+	 */
661
+	public function code()
662
+	{
663
+		return $this->get('LIN_code');
664
+	}
665
+
666
+
667
+	/**
668
+	 * Sets code
669
+	 *
670
+	 * @param string $code
671
+	 * @throws EE_Error
672
+	 * @throws InvalidArgumentException
673
+	 * @throws InvalidDataTypeException
674
+	 * @throws InvalidInterfaceException
675
+	 * @throws ReflectionException
676
+	 */
677
+	public function set_code($code)
678
+	{
679
+		$this->set('LIN_code', $code);
680
+	}
681
+
682
+
683
+	/**
684
+	 * Gets is_taxable
685
+	 *
686
+	 * @return boolean
687
+	 * @throws EE_Error
688
+	 * @throws InvalidArgumentException
689
+	 * @throws InvalidDataTypeException
690
+	 * @throws InvalidInterfaceException
691
+	 * @throws ReflectionException
692
+	 */
693
+	public function is_taxable()
694
+	{
695
+		return $this->get('LIN_is_taxable');
696
+	}
697
+
698
+
699
+	/**
700
+	 * Sets is_taxable
701
+	 *
702
+	 * @param boolean $is_taxable
703
+	 * @throws EE_Error
704
+	 * @throws InvalidArgumentException
705
+	 * @throws InvalidDataTypeException
706
+	 * @throws InvalidInterfaceException
707
+	 * @throws ReflectionException
708
+	 */
709
+	public function set_is_taxable($is_taxable)
710
+	{
711
+		$this->set('LIN_is_taxable', $is_taxable);
712
+	}
713
+
714
+
715
+	/**
716
+	 * Gets the object that this model-joins-to.
717
+	 * returns one of the model objects that the field OBJ_ID can point to... see the 'OBJ_ID' field on
718
+	 * EEM_Promotion_Object
719
+	 *        Eg, if this line item join model object is for a ticket, this will return the EE_Ticket object
720
+	 *
721
+	 * @return EE_Base_Class | NULL
722
+	 * @throws EE_Error
723
+	 * @throws InvalidArgumentException
724
+	 * @throws InvalidDataTypeException
725
+	 * @throws InvalidInterfaceException
726
+	 * @throws ReflectionException
727
+	 */
728
+	public function get_object()
729
+	{
730
+		$model_name_of_related_obj = $this->OBJ_type();
731
+		return $this->get_model()->has_relation($model_name_of_related_obj)
732
+			? $this->get_first_related($model_name_of_related_obj)
733
+			: null;
734
+	}
735
+
736
+
737
+	/**
738
+	 * Like EE_Line_Item::get_object(), but can only ever actually return an EE_Ticket.
739
+	 * (IE, if this line item is for a price or something else, will return NULL)
740
+	 *
741
+	 * @param array $query_params
742
+	 * @return EE_Base_Class|EE_Ticket
743
+	 * @throws EE_Error
744
+	 * @throws InvalidArgumentException
745
+	 * @throws InvalidDataTypeException
746
+	 * @throws InvalidInterfaceException
747
+	 * @throws ReflectionException
748
+	 */
749
+	public function ticket($query_params = array())
750
+	{
751
+		// we're going to assume that when this method is called
752
+		// we always want to receive the attached ticket EVEN if that ticket is archived.
753
+		// This can be overridden via the incoming $query_params argument
754
+		$remove_defaults = array('default_where_conditions' => 'none');
755
+		$query_params = array_merge($remove_defaults, $query_params);
756
+		return $this->get_first_related(EEM_Line_Item::OBJ_TYPE_TICKET, $query_params);
757
+	}
758
+
759
+
760
+	/**
761
+	 * Gets the EE_Datetime that's related to the ticket, IF this is for a ticket
762
+	 *
763
+	 * @return EE_Datetime | NULL
764
+	 * @throws EE_Error
765
+	 * @throws InvalidArgumentException
766
+	 * @throws InvalidDataTypeException
767
+	 * @throws InvalidInterfaceException
768
+	 * @throws ReflectionException
769
+	 */
770
+	public function get_ticket_datetime()
771
+	{
772
+		if ($this->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET) {
773
+			$ticket = $this->ticket();
774
+			if ($ticket instanceof EE_Ticket) {
775
+				$datetime = $ticket->first_datetime();
776
+				if ($datetime instanceof EE_Datetime) {
777
+					return $datetime;
778
+				}
779
+			}
780
+		}
781
+		return null;
782
+	}
783
+
784
+
785
+	/**
786
+	 * Gets the event's name that's related to the ticket, if this is for
787
+	 * a ticket
788
+	 *
789
+	 * @return string
790
+	 * @throws EE_Error
791
+	 * @throws InvalidArgumentException
792
+	 * @throws InvalidDataTypeException
793
+	 * @throws InvalidInterfaceException
794
+	 * @throws ReflectionException
795
+	 */
796
+	public function ticket_event_name()
797
+	{
798
+		$event_name = esc_html__('Unknown', 'event_espresso');
799
+		$event = $this->ticket_event();
800
+		if ($event instanceof EE_Event) {
801
+			$event_name = $event->name();
802
+		}
803
+		return $event_name;
804
+	}
805
+
806
+
807
+	/**
808
+	 * Gets the event that's related to the ticket, if this line item represents a ticket.
809
+	 *
810
+	 * @return EE_Event|null
811
+	 * @throws EE_Error
812
+	 * @throws InvalidArgumentException
813
+	 * @throws InvalidDataTypeException
814
+	 * @throws InvalidInterfaceException
815
+	 * @throws ReflectionException
816
+	 */
817
+	public function ticket_event()
818
+	{
819
+		$event = null;
820
+		$ticket = $this->ticket();
821
+		if ($ticket instanceof EE_Ticket) {
822
+			$datetime = $ticket->first_datetime();
823
+			if ($datetime instanceof EE_Datetime) {
824
+				$event = $datetime->event();
825
+			}
826
+		}
827
+		return $event;
828
+	}
829
+
830
+
831
+	/**
832
+	 * Gets the first datetime for this lien item, assuming it's for a ticket
833
+	 *
834
+	 * @param string $date_format
835
+	 * @param string $time_format
836
+	 * @return string
837
+	 * @throws EE_Error
838
+	 * @throws InvalidArgumentException
839
+	 * @throws InvalidDataTypeException
840
+	 * @throws InvalidInterfaceException
841
+	 * @throws ReflectionException
842
+	 */
843
+	public function ticket_datetime_start($date_format = '', $time_format = '')
844
+	{
845
+		$first_datetime_string = esc_html__('Unknown', 'event_espresso');
846
+		$datetime = $this->get_ticket_datetime();
847
+		if ($datetime) {
848
+			$first_datetime_string = $datetime->start_date_and_time($date_format, $time_format);
849
+		}
850
+		return $first_datetime_string;
851
+	}
852
+
853
+
854
+	/**
855
+	 * Adds the line item as a child to this line item. If there is another child line
856
+	 * item with the same LIN_code, it is overwritten by this new one
857
+	 *
858
+	 * @param EEI_Line_Item $line_item
859
+	 * @param bool          $set_order
860
+	 * @return bool success
861
+	 * @throws EE_Error
862
+	 * @throws InvalidArgumentException
863
+	 * @throws InvalidDataTypeException
864
+	 * @throws InvalidInterfaceException
865
+	 * @throws ReflectionException
866
+	 */
867
+	public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true)
868
+	{
869
+		// should we calculate the LIN_order for this line item ?
870
+		if ($set_order || $line_item->order() === null) {
871
+			$line_item->set_order(count($this->children()));
872
+		}
873
+		if ($this->ID()) {
874
+			// check for any duplicate line items (with the same code), if so, this replaces it
875
+			$line_item_with_same_code = $this->get_child_line_item($line_item->code());
876
+			if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) {
877
+				$this->delete_child_line_item($line_item_with_same_code->code());
878
+			}
879
+			$line_item->set_parent_ID($this->ID());
880
+			if ($this->TXN_ID()) {
881
+				$line_item->set_TXN_ID($this->TXN_ID());
882
+			}
883
+			return $line_item->save();
884
+		}
885
+		$this->_children[ $line_item->code() ] = $line_item;
886
+		if ($line_item->parent() !== $this) {
887
+			$line_item->set_parent($this);
888
+		}
889
+		return true;
890
+	}
891
+
892
+
893
+	/**
894
+	 * Similar to EE_Base_Class::_add_relation_to, except this isn't a normal relation.
895
+	 * If this line item is saved to the DB, this is just a wrapper for set_parent_ID() and save()
896
+	 * However, if this line item is NOT saved to the DB, this just caches the parent on
897
+	 * the EE_Line_Item::_parent property.
898
+	 *
899
+	 * @param EE_Line_Item $line_item
900
+	 * @throws EE_Error
901
+	 * @throws InvalidArgumentException
902
+	 * @throws InvalidDataTypeException
903
+	 * @throws InvalidInterfaceException
904
+	 * @throws ReflectionException
905
+	 */
906
+	public function set_parent($line_item)
907
+	{
908
+		if ($this->ID()) {
909
+			if (! $line_item->ID()) {
910
+				$line_item->save();
911
+			}
912
+			$this->set_parent_ID($line_item->ID());
913
+			$this->save();
914
+		} else {
915
+			$this->_parent = $line_item;
916
+			$this->set_parent_ID($line_item->ID());
917
+		}
918
+	}
919
+
920
+
921
+	/**
922
+	 * Gets the child line item as specified by its code. Because this returns an object (by reference)
923
+	 * you can modify this child line item and the parent (this object) can know about them
924
+	 * because it also has a reference to that line item
925
+	 *
926
+	 * @param string $code
927
+	 * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
928
+	 * @throws EE_Error
929
+	 * @throws InvalidArgumentException
930
+	 * @throws InvalidDataTypeException
931
+	 * @throws InvalidInterfaceException
932
+	 * @throws ReflectionException
933
+	 */
934
+	public function get_child_line_item($code)
935
+	{
936
+		if ($this->ID()) {
937
+			return $this->get_model()->get_one(
938
+				array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code))
939
+			);
940
+		}
941
+		return isset($this->_children[ $code ])
942
+			? $this->_children[ $code ]
943
+			: null;
944
+	}
945
+
946
+
947
+	/**
948
+	 * Returns how many items are deleted (or, if this item has not been saved ot the DB yet, just how many it HAD
949
+	 * cached on it)
950
+	 *
951
+	 * @return int
952
+	 * @throws EE_Error
953
+	 * @throws InvalidArgumentException
954
+	 * @throws InvalidDataTypeException
955
+	 * @throws InvalidInterfaceException
956
+	 * @throws ReflectionException
957
+	 */
958
+	public function delete_children_line_items()
959
+	{
960
+		if ($this->ID()) {
961
+			return $this->get_model()->delete(array(array('LIN_parent' => $this->ID())));
962
+		}
963
+		$count = count($this->_children);
964
+		$this->_children = array();
965
+		return $count;
966
+	}
967
+
968
+
969
+	/**
970
+	 * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line
971
+	 * HAS NOT been saved to the DB, removes the child line item with index $code.
972
+	 * Also searches through the child's children for a matching line item. However, once a line item has been found
973
+	 * and deleted, stops searching (so if there are line items with duplicate codes, only the first one found will be
974
+	 * deleted)
975
+	 *
976
+	 * @param string $code
977
+	 * @param bool   $stop_search_once_found
978
+	 * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to
979
+	 *             the DB yet)
980
+	 * @throws EE_Error
981
+	 * @throws InvalidArgumentException
982
+	 * @throws InvalidDataTypeException
983
+	 * @throws InvalidInterfaceException
984
+	 * @throws ReflectionException
985
+	 */
986
+	public function delete_child_line_item($code, $stop_search_once_found = true)
987
+	{
988
+		if ($this->ID()) {
989
+			$items_deleted = 0;
990
+			if ($this->code() === $code) {
991
+				$items_deleted += EEH_Line_Item::delete_all_child_items($this);
992
+				$items_deleted += (int) $this->delete();
993
+				if ($stop_search_once_found) {
994
+					return $items_deleted;
995
+				}
996
+			}
997
+			foreach ($this->children() as $child_line_item) {
998
+				$items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found);
999
+			}
1000
+			return $items_deleted;
1001
+		}
1002
+		if (isset($this->_children[ $code ])) {
1003
+			unset($this->_children[ $code ]);
1004
+			return 1;
1005
+		}
1006
+		return 0;
1007
+	}
1008
+
1009
+
1010
+	/**
1011
+	 * If this line item is in the database, is of the type subtotal, and
1012
+	 * has no children, why do we have it? It should be deleted so this function
1013
+	 * does that
1014
+	 *
1015
+	 * @return boolean
1016
+	 * @throws EE_Error
1017
+	 * @throws InvalidArgumentException
1018
+	 * @throws InvalidDataTypeException
1019
+	 * @throws InvalidInterfaceException
1020
+	 * @throws ReflectionException
1021
+	 */
1022
+	public function delete_if_childless_subtotal()
1023
+	{
1024
+		if ($this->ID() && $this->type() === EEM_Line_Item::type_sub_total && ! $this->children()) {
1025
+			return $this->delete();
1026
+		}
1027
+		return false;
1028
+	}
1029
+
1030
+
1031
+	/**
1032
+	 * Creates a code and returns a string. doesn't assign the code to this model object
1033
+	 *
1034
+	 * @return string
1035
+	 * @throws EE_Error
1036
+	 * @throws InvalidArgumentException
1037
+	 * @throws InvalidDataTypeException
1038
+	 * @throws InvalidInterfaceException
1039
+	 * @throws ReflectionException
1040
+	 */
1041
+	public function generate_code()
1042
+	{
1043
+		// each line item in the cart requires a unique identifier
1044
+		return md5($this->get('OBJ_type') . $this->get('OBJ_ID') . microtime());
1045
+	}
1046
+
1047
+
1048
+	/**
1049
+	 * @return bool
1050
+	 * @throws EE_Error
1051
+	 * @throws InvalidArgumentException
1052
+	 * @throws InvalidDataTypeException
1053
+	 * @throws InvalidInterfaceException
1054
+	 * @throws ReflectionException
1055
+	 */
1056
+	public function is_tax()
1057
+	{
1058
+		return $this->type() === EEM_Line_Item::type_tax;
1059
+	}
1060
+
1061
+
1062
+	/**
1063
+	 * @return bool
1064
+	 * @throws EE_Error
1065
+	 * @throws InvalidArgumentException
1066
+	 * @throws InvalidDataTypeException
1067
+	 * @throws InvalidInterfaceException
1068
+	 * @throws ReflectionException
1069
+	 */
1070
+	public function is_tax_sub_total()
1071
+	{
1072
+		return $this->type() === EEM_Line_Item::type_tax_sub_total;
1073
+	}
1074
+
1075
+
1076
+	/**
1077
+	 * @return bool
1078
+	 * @throws EE_Error
1079
+	 * @throws InvalidArgumentException
1080
+	 * @throws InvalidDataTypeException
1081
+	 * @throws InvalidInterfaceException
1082
+	 * @throws ReflectionException
1083
+	 */
1084
+	public function is_line_item()
1085
+	{
1086
+		return $this->type() === EEM_Line_Item::type_line_item;
1087
+	}
1088
+
1089
+
1090
+	/**
1091
+	 * @return bool
1092
+	 * @throws EE_Error
1093
+	 * @throws InvalidArgumentException
1094
+	 * @throws InvalidDataTypeException
1095
+	 * @throws InvalidInterfaceException
1096
+	 * @throws ReflectionException
1097
+	 */
1098
+	public function is_sub_line_item()
1099
+	{
1100
+		return $this->type() === EEM_Line_Item::type_sub_line_item;
1101
+	}
1102
+
1103
+
1104
+	/**
1105
+	 * @return bool
1106
+	 * @throws EE_Error
1107
+	 * @throws InvalidArgumentException
1108
+	 * @throws InvalidDataTypeException
1109
+	 * @throws InvalidInterfaceException
1110
+	 * @throws ReflectionException
1111
+	 */
1112
+	public function is_sub_total()
1113
+	{
1114
+		return $this->type() === EEM_Line_Item::type_sub_total;
1115
+	}
1116
+
1117
+
1118
+	/**
1119
+	 * Whether or not this line item is a cancellation line item
1120
+	 *
1121
+	 * @return boolean
1122
+	 * @throws EE_Error
1123
+	 * @throws InvalidArgumentException
1124
+	 * @throws InvalidDataTypeException
1125
+	 * @throws InvalidInterfaceException
1126
+	 * @throws ReflectionException
1127
+	 */
1128
+	public function is_cancellation()
1129
+	{
1130
+		return EEM_Line_Item::type_cancellation === $this->type();
1131
+	}
1132
+
1133
+
1134
+	/**
1135
+	 * @return bool
1136
+	 * @throws EE_Error
1137
+	 * @throws InvalidArgumentException
1138
+	 * @throws InvalidDataTypeException
1139
+	 * @throws InvalidInterfaceException
1140
+	 * @throws ReflectionException
1141
+	 */
1142
+	public function is_total()
1143
+	{
1144
+		return $this->type() === EEM_Line_Item::type_total;
1145
+	}
1146
+
1147
+
1148
+	/**
1149
+	 * @return bool
1150
+	 * @throws EE_Error
1151
+	 * @throws InvalidArgumentException
1152
+	 * @throws InvalidDataTypeException
1153
+	 * @throws InvalidInterfaceException
1154
+	 * @throws ReflectionException
1155
+	 */
1156
+	public function is_cancelled()
1157
+	{
1158
+		return $this->type() === EEM_Line_Item::type_cancellation;
1159
+	}
1160
+
1161
+
1162
+	/**
1163
+	 * @return string like '2, 004.00', formatted according to the localized currency
1164
+	 * @throws EE_Error
1165
+	 * @throws InvalidArgumentException
1166
+	 * @throws InvalidDataTypeException
1167
+	 * @throws InvalidInterfaceException
1168
+	 * @throws ReflectionException
1169
+	 */
1170
+	public function unit_price_no_code()
1171
+	{
1172
+		return $this->get_pretty('LIN_unit_price', 'no_currency_code');
1173
+	}
1174
+
1175
+
1176
+	/**
1177
+	 * @return string like '2, 004.00', formatted according to the localized currency
1178
+	 * @throws EE_Error
1179
+	 * @throws InvalidArgumentException
1180
+	 * @throws InvalidDataTypeException
1181
+	 * @throws InvalidInterfaceException
1182
+	 * @throws ReflectionException
1183
+	 */
1184
+	public function total_no_code()
1185
+	{
1186
+		return $this->get_pretty('LIN_total', 'no_currency_code');
1187
+	}
1188
+
1189
+
1190
+	/**
1191
+	 * Gets the final total on this item, taking taxes into account.
1192
+	 * Has the side-effect of setting the sub-total as it was just calculated.
1193
+	 * If this is used on a grand-total line item, also updates the transaction's
1194
+	 * TXN_total (provided this line item is allowed to persist, otherwise we don't
1195
+	 * want to change a persistable transaction with info from a non-persistent line item)
1196
+	 *
1197
+	 * @param bool $update_txn_status
1198
+	 * @return float
1199
+	 * @throws EE_Error
1200
+	 * @throws InvalidArgumentException
1201
+	 * @throws InvalidDataTypeException
1202
+	 * @throws InvalidInterfaceException
1203
+	 * @throws ReflectionException
1204
+	 * @throws RuntimeException
1205
+	 */
1206
+	public function recalculate_total_including_taxes($update_txn_status = false)
1207
+	{
1208
+		$pre_tax_total = $this->recalculate_pre_tax_total();
1209
+		$tax_total = $this->recalculate_taxes_and_tax_total();
1210
+		$total = $pre_tax_total + $tax_total;
1211
+		// no negative totals plz
1212
+		$total = max($total, 0);
1213
+		$this->set_total($total);
1214
+		// only update the related transaction's total
1215
+		// if we intend to save this line item and its a grand total
1216
+		if ($this->allow_persist() && $this->type() === EEM_Line_Item::type_total
1217
+			&& $this->transaction()
1218
+			   instanceof
1219
+			   EE_Transaction
1220
+		) {
1221
+			$this->transaction()->set_total($total);
1222
+			if ($update_txn_status) {
1223
+				// don't save the TXN because that will be done below
1224
+				// and the following method only saves if the status changes
1225
+				$this->transaction()->update_status_based_on_total_paid(false);
1226
+			}
1227
+			if ($this->transaction()->ID()) {
1228
+				$this->transaction()->save();
1229
+			}
1230
+		}
1231
+		$this->maybe_save();
1232
+		return $total;
1233
+	}
1234
+
1235
+
1236
+	/**
1237
+	 * Recursively goes through all the children and recalculates sub-totals EXCEPT for
1238
+	 * tax-sub-totals (they're a an odd beast). Updates the 'total' on each line item according to either its
1239
+	 * unit price * quantity or the total of all its children EXCEPT when we're only calculating the taxable total and
1240
+	 * when this is called on the grand total
1241
+	 *
1242
+	 * @return float
1243
+	 * @throws EE_Error
1244
+	 * @throws InvalidArgumentException
1245
+	 * @throws InvalidDataTypeException
1246
+	 * @throws InvalidInterfaceException
1247
+	 * @throws ReflectionException
1248
+	 */
1249
+	public function recalculate_pre_tax_total()
1250
+	{
1251
+		$total = 0;
1252
+		$my_children = $this->children();
1253
+		$has_children = ! empty($my_children);
1254
+		if ($has_children && $this->is_line_item()) {
1255
+			$total = $this->_recalculate_pretax_total_for_line_item($total, $my_children);
1256
+		} elseif (! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) {
1257
+			$total = $this->unit_price() * $this->quantity();
1258
+		} elseif ($this->is_sub_total() || $this->is_total()) {
1259
+			$total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children);
1260
+		} elseif ($this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled()) {
1261
+			// completely ignore tax totals, tax sub-totals, and cancelled line items, when calculating the pre-tax-total
1262
+			return 0;
1263
+		}
1264
+		// ensure all non-line items and non-sub-line-items have a quantity of 1 (except for Events)
1265
+		if (! $this->is_line_item() && ! $this->is_sub_line_item() && ! $this->is_cancellation()
1266
+		) {
1267
+			if ($this->OBJ_type() !== EEM_Line_Item::OBJ_TYPE_EVENT) {
1268
+				$this->set_quantity(1);
1269
+			}
1270
+			if (! $this->is_percent()) {
1271
+				$this->set_unit_price($total);
1272
+			}
1273
+		}
1274
+		// we don't want to bother saving grand totals, because that needs to factor in taxes anyways
1275
+		// so it ought to be
1276
+		if (! $this->is_total()) {
1277
+			$this->set_total($total);
1278
+			// if not a percent line item, make sure we keep the unit price in sync
1279
+			if ($has_children
1280
+				&& $this->is_line_item()
1281
+				&& ! $this->is_percent()
1282
+			) {
1283
+				if ($this->quantity() === 0) {
1284
+					$new_unit_price = 0;
1285
+				} else {
1286
+					$new_unit_price = $this->total() / $this->quantity();
1287
+				}
1288
+				$this->set_unit_price($new_unit_price);
1289
+			}
1290
+			$this->maybe_save();
1291
+		}
1292
+		return $total;
1293
+	}
1294
+
1295
+
1296
+	/**
1297
+	 * Calculates the pretax total when this line item is a subtotal or total line item.
1298
+	 * Basically does a sum-then-round approach (ie, any percent line item that are children
1299
+	 * will calculate their total based on the un-rounded total we're working with so far, and
1300
+	 * THEN round the result; instead of rounding as we go like with sub-line-items)
1301
+	 *
1302
+	 * @param float          $calculated_total_so_far
1303
+	 * @param EE_Line_Item[] $my_children
1304
+	 * @return float
1305
+	 * @throws EE_Error
1306
+	 * @throws InvalidArgumentException
1307
+	 * @throws InvalidDataTypeException
1308
+	 * @throws InvalidInterfaceException
1309
+	 * @throws ReflectionException
1310
+	 */
1311
+	protected function _recalculate_pretax_total_for_subtotal($calculated_total_so_far, $my_children = null)
1312
+	{
1313
+		if ($my_children === null) {
1314
+			$my_children = $this->children();
1315
+		}
1316
+		$subtotal_quantity = 0;
1317
+		// get the total of all its children
1318
+		foreach ($my_children as $child_line_item) {
1319
+			if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) {
1320
+				// percentage line items are based on total so far
1321
+				if ($child_line_item->is_percent()) {
1322
+					$percent_total = $calculated_total_so_far * $child_line_item->percent() / 100;
1323
+					$child_line_item->set_total($calculated_total_so_far * $child_line_item->percent() / 100);
1324
+					// so far all percent line items should have a quantity of 1
1325
+					// (ie, no double percent discounts. Although that might be requested someday)
1326
+					$child_line_item->set_quantity(1);
1327
+					$child_line_item->maybe_save();
1328
+					$calculated_total_so_far += $percent_total;
1329
+				} else {
1330
+					// verify flat sub-line-item quantities match their parent
1331
+					if ($child_line_item->is_sub_line_item()) {
1332
+						$child_line_item->set_quantity($this->quantity());
1333
+					}
1334
+					$calculated_total_so_far += $child_line_item->recalculate_pre_tax_total();
1335
+					$subtotal_quantity += $child_line_item->quantity();
1336
+				}
1337
+			}
1338
+		}
1339
+		if ($this->is_sub_total()) {
1340
+			// no negative totals plz
1341
+			$calculated_total_so_far = max($calculated_total_so_far, 0);
1342
+			$subtotal_quantity = $subtotal_quantity > 0 ? 1 : 0;
1343
+			$this->set_quantity($subtotal_quantity);
1344
+			$this->maybe_save();
1345
+		}
1346
+		return $calculated_total_so_far;
1347
+	}
1348
+
1349
+
1350
+	/**
1351
+	 * Calculates the pretax total for a normal line item, in a round-then-sum approach
1352
+	 * (where each sub-line-item is applied to the base price for the line item
1353
+	 * and the result is immediately rounded, rather than summing all the sub-line-items
1354
+	 * then rounding, like we do when recalculating pretax totals on totals and subtotals).
1355
+	 *
1356
+	 * @param float          $calculated_total_so_far
1357
+	 * @param EE_Line_Item[] $my_children
1358
+	 * @return float
1359
+	 * @throws EE_Error
1360
+	 * @throws InvalidArgumentException
1361
+	 * @throws InvalidDataTypeException
1362
+	 * @throws InvalidInterfaceException
1363
+	 * @throws ReflectionException
1364
+	 */
1365
+	protected function _recalculate_pretax_total_for_line_item($calculated_total_so_far, $my_children = null)
1366
+	{
1367
+		if ($my_children === null) {
1368
+			$my_children = $this->children();
1369
+		}
1370
+		// we need to keep track of the running total for a single item,
1371
+		// because we need to round as we go
1372
+		$unit_price_for_total = 0;
1373
+		$quantity_for_total = 1;
1374
+		// get the total of all its children
1375
+		foreach ($my_children as $child_line_item) {
1376
+			if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) {
1377
+				if ($child_line_item->is_percent()) {
1378
+					// it should be the unit-price-so-far multiplied by teh percent multiplied by the quantity
1379
+					// not total multiplied by percent, because that ignores rounding along-the-way
1380
+					$percent_unit_price = $unit_price_for_total * $child_line_item->percent() / 100;
1381
+					$percent_total = $percent_unit_price * $quantity_for_total;
1382
+					$child_line_item->set_total($percent_total);
1383
+					// so far all percent line items should have a quantity of 1
1384
+					// (ie, no double percent discounts. Although that might be requested someday)
1385
+					$child_line_item->set_quantity(1);
1386
+					$child_line_item->maybe_save();
1387
+					$calculated_total_so_far += $percent_total;
1388
+					$unit_price_for_total += $percent_unit_price;
1389
+				} else {
1390
+					// verify flat sub-line-item quantities match their parent
1391
+					if ($child_line_item->is_sub_line_item()) {
1392
+						$child_line_item->set_quantity($this->quantity());
1393
+					}
1394
+					$quantity_for_total = $child_line_item->quantity();
1395
+					$calculated_total_so_far += $child_line_item->recalculate_pre_tax_total();
1396
+					$unit_price_for_total += $child_line_item->unit_price();
1397
+				}
1398
+			}
1399
+		}
1400
+		return round(
1401
+			$unit_price_for_total,
1402
+			EE_Registry::instance()->CFG->currency->dec_plc
1403
+		) * $quantity_for_total;
1404
+	}
1405
+
1406
+
1407
+	/**
1408
+	 * Recalculates the total on each individual tax (based on a recalculation of the pre-tax total), sets
1409
+	 * the totals on each tax calculated, and returns the final tax total. Re-saves tax line items
1410
+	 * and tax sub-total if already in the DB
1411
+	 *
1412
+	 * @return float
1413
+	 * @throws EE_Error
1414
+	 * @throws InvalidArgumentException
1415
+	 * @throws InvalidDataTypeException
1416
+	 * @throws InvalidInterfaceException
1417
+	 * @throws ReflectionException
1418
+	 */
1419
+	public function recalculate_taxes_and_tax_total()
1420
+	{
1421
+		// get all taxes
1422
+		$taxes = $this->tax_descendants();
1423
+		// calculate the pretax total
1424
+		$taxable_total = $this->taxable_total();
1425
+		$tax_total = 0;
1426
+		foreach ($taxes as $tax) {
1427
+			$total_on_this_tax = $taxable_total * $tax->percent() / 100;
1428
+			// remember the total on this line item
1429
+			$tax->set_total($total_on_this_tax);
1430
+			$tax->maybe_save();
1431
+			$tax_total += $tax->total();
1432
+		}
1433
+		$this->_recalculate_tax_sub_total();
1434
+		return $tax_total;
1435
+	}
1436
+
1437
+
1438
+	/**
1439
+	 * Simply forces all the tax-sub-totals to recalculate. Assumes the taxes have been calculated
1440
+	 *
1441
+	 * @return void
1442
+	 * @throws EE_Error
1443
+	 * @throws InvalidArgumentException
1444
+	 * @throws InvalidDataTypeException
1445
+	 * @throws InvalidInterfaceException
1446
+	 * @throws ReflectionException
1447
+	 */
1448
+	private function _recalculate_tax_sub_total()
1449
+	{
1450
+		if ($this->is_tax_sub_total()) {
1451
+			$total = 0;
1452
+			$total_percent = 0;
1453
+			// simply loop through all its children (which should be taxes) and sum their total
1454
+			foreach ($this->children() as $child_tax) {
1455
+				if ($child_tax instanceof EE_Line_Item) {
1456
+					$total += $child_tax->total();
1457
+					$total_percent += $child_tax->percent();
1458
+				}
1459
+			}
1460
+			$this->set_total($total);
1461
+			$this->set_percent($total_percent);
1462
+			$this->maybe_save();
1463
+		} elseif ($this->is_total()) {
1464
+			foreach ($this->children() as $maybe_tax_subtotal) {
1465
+				if ($maybe_tax_subtotal instanceof EE_Line_Item) {
1466
+					$maybe_tax_subtotal->_recalculate_tax_sub_total();
1467
+				}
1468
+			}
1469
+		}
1470
+	}
1471
+
1472
+
1473
+	/**
1474
+	 * Gets the total tax on this line item. Assumes taxes have already been calculated using
1475
+	 * recalculate_taxes_and_total
1476
+	 *
1477
+	 * @return float
1478
+	 * @throws EE_Error
1479
+	 * @throws InvalidArgumentException
1480
+	 * @throws InvalidDataTypeException
1481
+	 * @throws InvalidInterfaceException
1482
+	 * @throws ReflectionException
1483
+	 */
1484
+	public function get_total_tax()
1485
+	{
1486
+		$this->_recalculate_tax_sub_total();
1487
+		$total = 0;
1488
+		foreach ($this->tax_descendants() as $tax_line_item) {
1489
+			if ($tax_line_item instanceof EE_Line_Item) {
1490
+				$total += $tax_line_item->total();
1491
+			}
1492
+		}
1493
+		return $total;
1494
+	}
1495
+
1496
+
1497
+	/**
1498
+	 * Gets the total for all the items purchased only
1499
+	 *
1500
+	 * @return float
1501
+	 * @throws EE_Error
1502
+	 * @throws InvalidArgumentException
1503
+	 * @throws InvalidDataTypeException
1504
+	 * @throws InvalidInterfaceException
1505
+	 * @throws ReflectionException
1506
+	 */
1507
+	public function get_items_total()
1508
+	{
1509
+		// by default, let's make sure we're consistent with the existing line item
1510
+		if ($this->is_total()) {
1511
+			$pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal($this);
1512
+			if ($pretax_subtotal_li instanceof EE_Line_Item) {
1513
+				return $pretax_subtotal_li->total();
1514
+			}
1515
+		}
1516
+		$total = 0;
1517
+		foreach ($this->get_items() as $item) {
1518
+			if ($item instanceof EE_Line_Item) {
1519
+				$total += $item->total();
1520
+			}
1521
+		}
1522
+		return $total;
1523
+	}
1524
+
1525
+
1526
+	/**
1527
+	 * Gets all the descendants (ie, children or children of children etc) that
1528
+	 * are of the type 'tax'
1529
+	 *
1530
+	 * @return EE_Line_Item[]
1531
+	 * @throws EE_Error
1532
+	 */
1533
+	public function tax_descendants()
1534
+	{
1535
+		return EEH_Line_Item::get_tax_descendants($this);
1536
+	}
1537
+
1538
+
1539
+	/**
1540
+	 * Gets all the real items purchased which are children of this item
1541
+	 *
1542
+	 * @return EE_Line_Item[]
1543
+	 * @throws EE_Error
1544
+	 */
1545
+	public function get_items()
1546
+	{
1547
+		return EEH_Line_Item::get_line_item_descendants($this);
1548
+	}
1549
+
1550
+
1551
+	/**
1552
+	 * Returns the amount taxable among this line item's children (or if it has no children,
1553
+	 * how much of it is taxable). Does not recalculate totals or subtotals.
1554
+	 * If the taxable total is negative, (eg, if none of the tickets were taxable,
1555
+	 * but there is a "Taxable" discount), returns 0.
1556
+	 *
1557
+	 * @return float
1558
+	 * @throws EE_Error
1559
+	 * @throws InvalidArgumentException
1560
+	 * @throws InvalidDataTypeException
1561
+	 * @throws InvalidInterfaceException
1562
+	 * @throws ReflectionException
1563
+	 */
1564
+	public function taxable_total()
1565
+	{
1566
+		$total = 0;
1567
+		if ($this->children()) {
1568
+			foreach ($this->children() as $child_line_item) {
1569
+				if ($child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) {
1570
+					// if it's a percent item, only take into account the percent
1571
+					// that's taxable too (the taxable total so far)
1572
+					if ($child_line_item->is_percent()) {
1573
+						$total += ($total * $child_line_item->percent() / 100);
1574
+					} else {
1575
+						$total += $child_line_item->total();
1576
+					}
1577
+				} elseif ($child_line_item->type() === EEM_Line_Item::type_sub_total) {
1578
+					$total += $child_line_item->taxable_total();
1579
+				}
1580
+			}
1581
+		}
1582
+		return max($total, 0);
1583
+	}
1584
+
1585
+
1586
+	/**
1587
+	 * Gets the transaction for this line item
1588
+	 *
1589
+	 * @return EE_Base_Class|EE_Transaction
1590
+	 * @throws EE_Error
1591
+	 * @throws InvalidArgumentException
1592
+	 * @throws InvalidDataTypeException
1593
+	 * @throws InvalidInterfaceException
1594
+	 * @throws ReflectionException
1595
+	 */
1596
+	public function transaction()
1597
+	{
1598
+		return $this->get_first_related(EEM_Line_Item::OBJ_TYPE_TRANSACTION);
1599
+	}
1600
+
1601
+
1602
+	/**
1603
+	 * Saves this line item to the DB, and recursively saves its descendants.
1604
+	 * Because there currently is no proper parent-child relation on the model,
1605
+	 * save_this_and_cached() will NOT save the descendants.
1606
+	 * Also sets the transaction on this line item and all its descendants before saving
1607
+	 *
1608
+	 * @param int $txn_id if none is provided, assumes $this->TXN_ID()
1609
+	 * @return int count of items saved
1610
+	 * @throws EE_Error
1611
+	 * @throws InvalidArgumentException
1612
+	 * @throws InvalidDataTypeException
1613
+	 * @throws InvalidInterfaceException
1614
+	 * @throws ReflectionException
1615
+	 */
1616
+	public function save_this_and_descendants_to_txn($txn_id = null)
1617
+	{
1618
+		$count = 0;
1619
+		if (! $txn_id) {
1620
+			$txn_id = $this->TXN_ID();
1621
+		}
1622
+		$this->set_TXN_ID($txn_id);
1623
+		$children = $this->children();
1624
+		$count += $this->save()
1625
+			? 1
1626
+			: 0;
1627
+		foreach ($children as $child_line_item) {
1628
+			if ($child_line_item instanceof EE_Line_Item) {
1629
+				$child_line_item->set_parent_ID($this->ID());
1630
+				$count += $child_line_item->save_this_and_descendants_to_txn($txn_id);
1631
+			}
1632
+		}
1633
+		return $count;
1634
+	}
1635
+
1636
+
1637
+	/**
1638
+	 * Saves this line item to the DB, and recursively saves its descendants.
1639
+	 *
1640
+	 * @return int count of items saved
1641
+	 * @throws EE_Error
1642
+	 * @throws InvalidArgumentException
1643
+	 * @throws InvalidDataTypeException
1644
+	 * @throws InvalidInterfaceException
1645
+	 * @throws ReflectionException
1646
+	 */
1647
+	public function save_this_and_descendants()
1648
+	{
1649
+		$count = 0;
1650
+		$children = $this->children();
1651
+		$count += $this->save()
1652
+			? 1
1653
+			: 0;
1654
+		foreach ($children as $child_line_item) {
1655
+			if ($child_line_item instanceof EE_Line_Item) {
1656
+				$child_line_item->set_parent_ID($this->ID());
1657
+				$count += $child_line_item->save_this_and_descendants();
1658
+			}
1659
+		}
1660
+		return $count;
1661
+	}
1662
+
1663
+
1664
+	/**
1665
+	 * returns the cancellation line item if this item was cancelled
1666
+	 *
1667
+	 * @return EE_Line_Item[]
1668
+	 * @throws InvalidArgumentException
1669
+	 * @throws InvalidInterfaceException
1670
+	 * @throws InvalidDataTypeException
1671
+	 * @throws ReflectionException
1672
+	 * @throws EE_Error
1673
+	 */
1674
+	public function get_cancellations()
1675
+	{
1676
+		EE_Registry::instance()->load_helper('Line_Item');
1677
+		return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation);
1678
+	}
1679
+
1680
+
1681
+	/**
1682
+	 * If this item has an ID, then this saves it again to update the db
1683
+	 *
1684
+	 * @return int count of items saved
1685
+	 * @throws EE_Error
1686
+	 * @throws InvalidArgumentException
1687
+	 * @throws InvalidDataTypeException
1688
+	 * @throws InvalidInterfaceException
1689
+	 * @throws ReflectionException
1690
+	 */
1691
+	public function maybe_save()
1692
+	{
1693
+		if ($this->ID()) {
1694
+			return $this->save();
1695
+		}
1696
+		return false;
1697
+	}
1698
+
1699
+
1700
+	/**
1701
+	 * clears the cached children and parent from the line item
1702
+	 *
1703
+	 * @return void
1704
+	 */
1705
+	public function clear_related_line_item_cache()
1706
+	{
1707
+		$this->_children = array();
1708
+		$this->_parent = null;
1709
+	}
1710
+
1711
+
1712
+	/**
1713
+	 * @param bool $raw
1714
+	 * @return int
1715
+	 * @throws EE_Error
1716
+	 * @throws InvalidArgumentException
1717
+	 * @throws InvalidDataTypeException
1718
+	 * @throws InvalidInterfaceException
1719
+	 * @throws ReflectionException
1720
+	 */
1721
+	public function timestamp($raw = false)
1722
+	{
1723
+		return $raw
1724
+			? $this->get_raw('LIN_timestamp')
1725
+			: $this->get('LIN_timestamp');
1726
+	}
1727
+
1728
+
1729
+
1730
+
1731
+	/************************* DEPRECATED *************************/
1732
+	/**
1733
+	 * @deprecated 4.6.0
1734
+	 * @param string $type one of the constants on EEM_Line_Item
1735
+	 * @return EE_Line_Item[]
1736
+	 * @throws EE_Error
1737
+	 */
1738
+	protected function _get_descendants_of_type($type)
1739
+	{
1740
+		EE_Error::doing_it_wrong(
1741
+			'EE_Line_Item::_get_descendants_of_type()',
1742
+			sprintf(
1743
+				esc_html__('Method replaced with %1$s', 'event_espresso'),
1744
+				'EEH_Line_Item::get_descendants_of_type()'
1745
+			),
1746
+			'4.6.0'
1747
+		);
1748
+		return EEH_Line_Item::get_descendants_of_type($this, $type);
1749
+	}
1750
+
1751
+
1752
+	/**
1753
+	 * @deprecated 4.6.0
1754
+	 * @param string $type like one of the EEM_Line_Item::type_*
1755
+	 * @return EE_Line_Item
1756
+	 * @throws EE_Error
1757
+	 * @throws InvalidArgumentException
1758
+	 * @throws InvalidDataTypeException
1759
+	 * @throws InvalidInterfaceException
1760
+	 * @throws ReflectionException
1761
+	 */
1762
+	public function get_nearest_descendant_of_type($type)
1763
+	{
1764
+		EE_Error::doing_it_wrong(
1765
+			'EE_Line_Item::get_nearest_descendant_of_type()',
1766
+			sprintf(
1767
+				esc_html__('Method replaced with %1$s', 'event_espresso'),
1768
+				'EEH_Line_Item::get_nearest_descendant_of_type()'
1769
+			),
1770
+			'4.6.0'
1771
+		);
1772
+		return EEH_Line_Item::get_nearest_descendant_of_type($this, $type);
1773
+	}
1774 1774
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
     protected function __construct($fieldValues = array(), $bydb = false, $timezone = '')
89 89
     {
90 90
         parent::__construct($fieldValues, $bydb, $timezone);
91
-        if (! $this->get('LIN_code')) {
91
+        if ( ! $this->get('LIN_code')) {
92 92
             $this->set_code($this->generate_code());
93 93
         }
94 94
     }
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
     public function name()
156 156
     {
157 157
         $name = $this->get('LIN_name');
158
-        if (! $name) {
158
+        if ( ! $name) {
159 159
             $name = ucwords(str_replace('-', ' ', $this->type()));
160 160
         }
161 161
         return $name;
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 
359 359
     public function prettyUnitPrice()
360 360
     {
361
-        if($this->parent_ID() !== 0
361
+        if ($this->parent_ID() !== 0
362 362
             && $this->parent() instanceof EE_Line_Item
363 363
             && $this->parent()->type() === EEM_Line_Item::type_line_item
364 364
         ) {
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
         } else {
367 367
             $quantity = $this->quantity();
368 368
         }
369
-        if($this->is_percent()) {
369
+        if ($this->is_percent()) {
370 370
             return $this->get_model()->field_settings_for('LIN_unit_price')->prepare_for_pretty_echoing(
371 371
                 $this->total() / $quantity,
372 372
                 'no_currency_code'
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
      */
389 389
     public function set_unit_price($unit_price)
390 390
     {
391
-        if($this->type() !== EEM_Line_Item::type_sub_line_item) { 
391
+        if ($this->type() !== EEM_Line_Item::type_sub_line_item) { 
392 392
             $unit_price = EEH_Money::round_for_currency($unit_price, EE_Config::instance()->currency->code);
393 393
         } 
394 394
         $this->set('LIN_unit_price', $unit_price);
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
      */
498 498
     public function set_total($total)
499 499
     {
500
-        if($this->type() !== EEM_Line_Item::type_sub_line_item) { 
500
+        if ($this->type() !== EEM_Line_Item::type_sub_line_item) { 
501 501
             $total = EEH_Money::round_for_currency($total, EE_Config::instance()->currency->code); 
502 502
         } 
503 503
         $this->set('LIN_total', $total);
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
                 )
642 642
             );
643 643
         }
644
-        if (! is_array($this->_children)) {
644
+        if ( ! is_array($this->_children)) {
645 645
             $this->_children = array();
646 646
         }
647 647
         return $this->_children;
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
             }
883 883
             return $line_item->save();
884 884
         }
885
-        $this->_children[ $line_item->code() ] = $line_item;
885
+        $this->_children[$line_item->code()] = $line_item;
886 886
         if ($line_item->parent() !== $this) {
887 887
             $line_item->set_parent($this);
888 888
         }
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
     public function set_parent($line_item)
907 907
     {
908 908
         if ($this->ID()) {
909
-            if (! $line_item->ID()) {
909
+            if ( ! $line_item->ID()) {
910 910
                 $line_item->save();
911 911
             }
912 912
             $this->set_parent_ID($line_item->ID());
@@ -938,8 +938,8 @@  discard block
 block discarded – undo
938 938
                 array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code))
939 939
             );
940 940
         }
941
-        return isset($this->_children[ $code ])
942
-            ? $this->_children[ $code ]
941
+        return isset($this->_children[$code])
942
+            ? $this->_children[$code]
943 943
             : null;
944 944
     }
945 945
 
@@ -999,8 +999,8 @@  discard block
 block discarded – undo
999 999
             }
1000 1000
             return $items_deleted;
1001 1001
         }
1002
-        if (isset($this->_children[ $code ])) {
1003
-            unset($this->_children[ $code ]);
1002
+        if (isset($this->_children[$code])) {
1003
+            unset($this->_children[$code]);
1004 1004
             return 1;
1005 1005
         }
1006 1006
         return 0;
@@ -1041,7 +1041,7 @@  discard block
 block discarded – undo
1041 1041
     public function generate_code()
1042 1042
     {
1043 1043
         // each line item in the cart requires a unique identifier
1044
-        return md5($this->get('OBJ_type') . $this->get('OBJ_ID') . microtime());
1044
+        return md5($this->get('OBJ_type').$this->get('OBJ_ID').microtime());
1045 1045
     }
1046 1046
 
1047 1047
 
@@ -1253,7 +1253,7 @@  discard block
 block discarded – undo
1253 1253
         $has_children = ! empty($my_children);
1254 1254
         if ($has_children && $this->is_line_item()) {
1255 1255
             $total = $this->_recalculate_pretax_total_for_line_item($total, $my_children);
1256
-        } elseif (! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) {
1256
+        } elseif ( ! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) {
1257 1257
             $total = $this->unit_price() * $this->quantity();
1258 1258
         } elseif ($this->is_sub_total() || $this->is_total()) {
1259 1259
             $total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children);
@@ -1262,18 +1262,18 @@  discard block
 block discarded – undo
1262 1262
             return 0;
1263 1263
         }
1264 1264
         // ensure all non-line items and non-sub-line-items have a quantity of 1 (except for Events)
1265
-        if (! $this->is_line_item() && ! $this->is_sub_line_item() && ! $this->is_cancellation()
1265
+        if ( ! $this->is_line_item() && ! $this->is_sub_line_item() && ! $this->is_cancellation()
1266 1266
         ) {
1267 1267
             if ($this->OBJ_type() !== EEM_Line_Item::OBJ_TYPE_EVENT) {
1268 1268
                 $this->set_quantity(1);
1269 1269
             }
1270
-            if (! $this->is_percent()) {
1270
+            if ( ! $this->is_percent()) {
1271 1271
                 $this->set_unit_price($total);
1272 1272
             }
1273 1273
         }
1274 1274
         // we don't want to bother saving grand totals, because that needs to factor in taxes anyways
1275 1275
         // so it ought to be
1276
-        if (! $this->is_total()) {
1276
+        if ( ! $this->is_total()) {
1277 1277
             $this->set_total($total);
1278 1278
             // if not a percent line item, make sure we keep the unit price in sync
1279 1279
             if ($has_children
@@ -1616,7 +1616,7 @@  discard block
 block discarded – undo
1616 1616
     public function save_this_and_descendants_to_txn($txn_id = null)
1617 1617
     {
1618 1618
         $count = 0;
1619
-        if (! $txn_id) {
1619
+        if ( ! $txn_id) {
1620 1620
             $txn_id = $this->TXN_ID();
1621 1621
         }
1622 1622
         $this->set_TXN_ID($txn_id);
Please login to merge, or discard this patch.