Completed
Pull Request — master (#952)
by
unknown
09:09
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.
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -6,112 +6,112 @@
 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($value_on_field_to_be_outputted, false, $display_code);
49
-    }
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($value_on_field_to_be_outputted, false, $display_code);
49
+	}
50 50
 
51
-    /**
52
-     * If provided with a string, strips out money-related formatting to turn it into a proper float.
53
-     * Rounds the float to the correct number of decimal places for this country's currency.
54
-     * Also, interprets periods and commas according to the country's currency settings.
55
-     * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
56
-     *
57
-     * @param string $value_inputted_for_field_on_model_object
58
-     * @return float
59
-     */
60
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
61
-    {
62
-        // now it's a float-style string or number
63
-        $float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object);
64
-        // round to the correctly number of decimal places for this  currency
65
-        return $this->_round_if_no_partial_pennies( $float_val );
66
-    }
51
+	/**
52
+	 * If provided with a string, strips out money-related formatting to turn it into a proper float.
53
+	 * Rounds the float to the correct number of decimal places for this country's currency.
54
+	 * Also, interprets periods and commas according to the country's currency settings.
55
+	 * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
56
+	 *
57
+	 * @param string $value_inputted_for_field_on_model_object
58
+	 * @return float
59
+	 */
60
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
61
+	{
62
+		// now it's a float-style string or number
63
+		$float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object);
64
+		// round to the correctly number of decimal places for this  currency
65
+		return $this->_round_if_no_partial_pennies( $float_val );
66
+	}
67 67
 
68
-    public function prepare_for_get($value_of_field_on_model_object)
69
-    {
70
-        return $this->_round_if_no_partial_pennies(parent::prepare_for_get($value_of_field_on_model_object));
71
-    }
68
+	public function prepare_for_get($value_of_field_on_model_object)
69
+	{
70
+		return $this->_round_if_no_partial_pennies(parent::prepare_for_get($value_of_field_on_model_object));
71
+	}
72 72
 
73
-    public function getSchemaProperties()
74
-    {
75
-        return array(
76
-            'raw' => array(
77
-                'description' =>  sprintf(
78
-                    __('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'),
79
-                    $this->get_nicename()
80
-                ),
81
-                'type' => 'number',
82
-            ),
83
-            'pretty' => array(
84
-                'description' =>  sprintf(
85
-                    __('%s - formatted for display in the set currency and decimal places.', 'event_espresso'),
86
-                    $this->get_nicename()
87
-                ),
88
-                'type' => 'string',
89
-                'format' => 'money'
90
-            )
91
-        );
92
-    }
73
+	public function getSchemaProperties()
74
+	{
75
+		return array(
76
+			'raw' => array(
77
+				'description' =>  sprintf(
78
+					__('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'),
79
+					$this->get_nicename()
80
+				),
81
+				'type' => 'number',
82
+			),
83
+			'pretty' => array(
84
+				'description' =>  sprintf(
85
+					__('%s - formatted for display in the set currency and decimal places.', 'event_espresso'),
86
+					$this->get_nicename()
87
+				),
88
+				'type' => 'string',
89
+				'format' => 'money'
90
+			)
91
+		);
92
+	}
93 93
 
94
-    /** 
95
-     * Returns whether or not this money field allows partial penny amounts 
96
-     * @return boolean 
97
-     */ 
98
-    public function whole_pennies_only()
99
-    {
100
-        return $this->_whole_pennies_only;
101
-    }
94
+	/** 
95
+	 * Returns whether or not this money field allows partial penny amounts 
96
+	 * @return boolean 
97
+	 */ 
98
+	public function whole_pennies_only()
99
+	{
100
+		return $this->_whole_pennies_only;
101
+	}
102 102
 
103
-    /** 
104
-     * If partial pennies allowed, leaves the amount as-is; if not, rounds it according 
105
-     * to the site's currency 
106
-     * @param type $amount 
107
-     * @return float 
108
-     */ 
109
-    protected function _round_if_no_partial_pennies( $amount )
110
-    { 
111
-        if($this->whole_pennies_only()) { 
112
-            return EEH_Money::round_for_currency($amount, EE_Registry::instance()->CFG->currency->code); 
113
-        } else { 
114
-            return $amount; 
115
-        } 
116
-    }
103
+	/** 
104
+	 * If partial pennies allowed, leaves the amount as-is; if not, rounds it according 
105
+	 * to the site's currency 
106
+	 * @param type $amount 
107
+	 * @return float 
108
+	 */ 
109
+	protected function _round_if_no_partial_pennies( $amount )
110
+	{ 
111
+		if($this->whole_pennies_only()) { 
112
+			return EEH_Money::round_for_currency($amount, EE_Registry::instance()->CFG->currency->code); 
113
+		} else { 
114
+			return $amount; 
115
+		} 
116
+	}
117 117
 }
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.
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_classes/EE_Line_Item.class.php 2 patches
Indentation   +1432 added lines, -1432 removed lines patch added patch discarded remove patch
@@ -14,1436 +14,1436 @@
 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
-     *
34
-     * @param array  $props_n_values          incoming values
35
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
36
-     *                                        used.)
37
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
38
-     *                                        date_format and the second value is the time format
39
-     * @return EE_Line_Item
40
-     * @throws EE_Error
41
-     */
42
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
43
-    {
44
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
45
-        return $has_object
46
-            ? $has_object
47
-            : new self($props_n_values, false, $timezone);
48
-    }
49
-
50
-
51
-    /**
52
-     * @param array  $props_n_values  incoming values from the database
53
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
54
-     *                                the website will be used.
55
-     * @return EE_Line_Item
56
-     * @throws EE_Error
57
-     */
58
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
59
-    {
60
-        return new self($props_n_values, true, $timezone);
61
-    }
62
-
63
-
64
-    /**
65
-     * Adds some defaults if they're not specified
66
-     *
67
-     * @param array  $fieldValues
68
-     * @param bool   $bydb
69
-     * @param string $timezone
70
-     * @throws EE_Error
71
-     */
72
-    protected function __construct($fieldValues = array(), $bydb = false, $timezone = '')
73
-    {
74
-        parent::__construct($fieldValues, $bydb, $timezone);
75
-        if (! $this->get('LIN_code')) {
76
-            $this->set_code($this->generate_code());
77
-        }
78
-    }
79
-
80
-
81
-    /**
82
-     * Gets ID
83
-     *
84
-     * @return int
85
-     * @throws EE_Error
86
-     */
87
-    public function ID()
88
-    {
89
-        return $this->get('LIN_ID');
90
-    }
91
-
92
-
93
-    /**
94
-     * Gets TXN_ID
95
-     *
96
-     * @return int
97
-     * @throws EE_Error
98
-     */
99
-    public function TXN_ID()
100
-    {
101
-        return $this->get('TXN_ID');
102
-    }
103
-
104
-
105
-    /**
106
-     * Sets TXN_ID
107
-     *
108
-     * @param int $TXN_ID
109
-     * @throws EE_Error
110
-     */
111
-    public function set_TXN_ID($TXN_ID)
112
-    {
113
-        $this->set('TXN_ID', $TXN_ID);
114
-    }
115
-
116
-
117
-    /**
118
-     * Gets name
119
-     *
120
-     * @return string
121
-     * @throws EE_Error
122
-     */
123
-    public function name()
124
-    {
125
-        $name = $this->get('LIN_name');
126
-        if (! $name) {
127
-            $name = ucwords(str_replace('-', ' ', $this->type()));
128
-        }
129
-        return $name;
130
-    }
131
-
132
-
133
-    /**
134
-     * Sets name
135
-     *
136
-     * @param string $name
137
-     * @throws EE_Error
138
-     */
139
-    public function set_name($name)
140
-    {
141
-        $this->set('LIN_name', $name);
142
-    }
143
-
144
-
145
-    /**
146
-     * Gets desc
147
-     *
148
-     * @return string
149
-     * @throws EE_Error
150
-     */
151
-    public function desc()
152
-    {
153
-        return $this->get('LIN_desc');
154
-    }
155
-
156
-
157
-    /**
158
-     * Sets desc
159
-     *
160
-     * @param string $desc
161
-     * @throws EE_Error
162
-     */
163
-    public function set_desc($desc)
164
-    {
165
-        $this->set('LIN_desc', $desc);
166
-    }
167
-
168
-
169
-    /**
170
-     * Gets quantity
171
-     *
172
-     * @return int
173
-     * @throws EE_Error
174
-     */
175
-    public function quantity()
176
-    {
177
-        return $this->get('LIN_quantity');
178
-    }
179
-
180
-
181
-    /**
182
-     * Sets quantity
183
-     *
184
-     * @param int $quantity
185
-     * @throws EE_Error
186
-     */
187
-    public function set_quantity($quantity)
188
-    {
189
-        $this->set('LIN_quantity', max($quantity, 0));
190
-    }
191
-
192
-
193
-    /**
194
-     * Gets item_id
195
-     *
196
-     * @return string
197
-     * @throws EE_Error
198
-     */
199
-    public function OBJ_ID()
200
-    {
201
-        return $this->get('OBJ_ID');
202
-    }
203
-
204
-
205
-    /**
206
-     * Sets item_id
207
-     *
208
-     * @param string $item_id
209
-     * @throws EE_Error
210
-     */
211
-    public function set_OBJ_ID($item_id)
212
-    {
213
-        $this->set('OBJ_ID', $item_id);
214
-    }
215
-
216
-
217
-    /**
218
-     * Gets item_type
219
-     *
220
-     * @return string
221
-     * @throws EE_Error
222
-     */
223
-    public function OBJ_type()
224
-    {
225
-        return $this->get('OBJ_type');
226
-    }
227
-
228
-
229
-    /**
230
-     * Gets item_type
231
-     *
232
-     * @return string
233
-     * @throws EE_Error
234
-     */
235
-    public function OBJ_type_i18n()
236
-    {
237
-        $obj_type = $this->OBJ_type();
238
-        switch ($obj_type) {
239
-            case 'Event':
240
-                $obj_type = __('Event', 'event_espresso');
241
-                break;
242
-            case 'Price':
243
-                $obj_type = __('Price', 'event_espresso');
244
-                break;
245
-            case 'Promotion':
246
-                $obj_type = __('Promotion', 'event_espresso');
247
-                break;
248
-            case 'Ticket':
249
-                $obj_type = __('Ticket', 'event_espresso');
250
-                break;
251
-            case 'Transaction':
252
-                $obj_type = __('Transaction', 'event_espresso');
253
-                break;
254
-        }
255
-        return apply_filters('FHEE__EE_Line_Item__OBJ_type_i18n', $obj_type, $this);
256
-    }
257
-
258
-
259
-    /**
260
-     * Sets item_type
261
-     *
262
-     * @param string $OBJ_type
263
-     * @throws EE_Error
264
-     */
265
-    public function set_OBJ_type($OBJ_type)
266
-    {
267
-        $this->set('OBJ_type', $OBJ_type);
268
-    }
269
-
270
-
271
-    /**
272
-     * Gets unit_price
273
-     *
274
-     * @return float
275
-     * @throws EE_Error
276
-     */
277
-    public function unit_price()
278
-    {
279
-        return $this->get('LIN_unit_price');
280
-    }
281
-
282
-
283
-    /**
284
-     * Sets unit_price
285
-     *
286
-     * @param float $unit_price
287
-     * @throws EE_Error
288
-     */
289
-    public function set_unit_price($unit_price)
290
-    {
291
-        if($this->type() !== EEM_Line_Item::type_sub_line_item) { 
292
-            $unit_price = EEH_Money::round_for_currency($unit_price, EE_Config::instance()->currency->code);
293
-        } 
294
-        $this->set('LIN_unit_price', $unit_price);
295
-    }
296
-
297
-
298
-    /**
299
-     * Checks if this item is a percentage modifier or not
300
-     *
301
-     * @return boolean
302
-     * @throws EE_Error
303
-     */
304
-    public function is_percent()
305
-    {
306
-        if ($this->is_tax_sub_total()) {
307
-            // tax subtotals HAVE a percent on them, that percentage only applies
308
-            // to taxable items, so its' an exception. Treat it like a flat line item
309
-            return false;
310
-        }
311
-        $unit_price = abs($this->get('LIN_unit_price'));
312
-        $percent = abs($this->get('LIN_percent'));
313
-        if ($unit_price < .001 && $percent) {
314
-            return true;
315
-        }
316
-        if ($unit_price >= .001 && ! $percent) {
317
-            return false;
318
-        }
319
-        if ($unit_price >= .001 && $percent) {
320
-            throw new EE_Error(
321
-                sprintf(
322
-                    esc_html__('A Line Item can not have a unit price of (%s) AND a percent (%s)!', 'event_espresso'),
323
-                    $unit_price,
324
-                    $percent
325
-                )
326
-            );
327
-        }
328
-        // if they're both 0, assume its not a percent item
329
-        return false;
330
-    }
331
-
332
-
333
-    /**
334
-     * Gets percent (between 100-.001)
335
-     *
336
-     * @return float
337
-     * @throws EE_Error
338
-     */
339
-    public function percent()
340
-    {
341
-        return $this->get('LIN_percent');
342
-    }
343
-
344
-
345
-    /**
346
-     * Sets percent (between 100-0.01)
347
-     *
348
-     * @param float $percent
349
-     * @throws EE_Error
350
-     */
351
-    public function set_percent($percent)
352
-    {
353
-        $this->set('LIN_percent', $percent);
354
-    }
355
-
356
-
357
-    /**
358
-     * Gets total
359
-     *
360
-     * @return float
361
-     * @throws EE_Error
362
-     */
363
-    public function total()
364
-    {
365
-        return $this->get('LIN_total');
366
-    }
367
-
368
-
369
-    /**
370
-     * Sets total
371
-     *
372
-     * @param float $total
373
-     * @throws EE_Error
374
-     */
375
-    public function set_total($total)
376
-    {
377
-        if($this->type() !== EEM_Line_Item::type_sub_line_item) { 
378
-            $total = EEH_Money::round_for_currency($total, EE_Config::instance()->currency->code); 
379
-        } 
380
-        $this->set('LIN_total', $total);
381
-    }
382
-
383
-
384
-    /**
385
-     * Gets order
386
-     *
387
-     * @return int
388
-     * @throws EE_Error
389
-     */
390
-    public function order()
391
-    {
392
-        return $this->get('LIN_order');
393
-    }
394
-
395
-
396
-    /**
397
-     * Sets order
398
-     *
399
-     * @param int $order
400
-     * @throws EE_Error
401
-     */
402
-    public function set_order($order)
403
-    {
404
-        $this->set('LIN_order', $order);
405
-    }
406
-
407
-
408
-    /**
409
-     * Gets parent
410
-     *
411
-     * @return int
412
-     * @throws EE_Error
413
-     */
414
-    public function parent_ID()
415
-    {
416
-        return $this->get('LIN_parent');
417
-    }
418
-
419
-
420
-    /**
421
-     * Sets parent
422
-     *
423
-     * @param int $parent
424
-     * @throws EE_Error
425
-     */
426
-    public function set_parent_ID($parent)
427
-    {
428
-        $this->set('LIN_parent', $parent);
429
-    }
430
-
431
-
432
-    /**
433
-     * Gets type
434
-     *
435
-     * @return string
436
-     * @throws EE_Error
437
-     */
438
-    public function type()
439
-    {
440
-        return $this->get('LIN_type');
441
-    }
442
-
443
-
444
-    /**
445
-     * Sets type
446
-     *
447
-     * @param string $type
448
-     * @throws EE_Error
449
-     */
450
-    public function set_type($type)
451
-    {
452
-        $this->set('LIN_type', $type);
453
-    }
454
-
455
-
456
-    /**
457
-     * Gets the line item of which this item is a composite. Eg, if this is a subtotal, the parent might be a total\
458
-     * 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
459
-     * it uses its cached reference to its parent line item (which would have been set by `EE_Line_Item::set_parent()`
460
-     * or indirectly by `EE_Line_item::add_child_line_item()`)
461
-     *
462
-     * @return EE_Base_Class|EE_Line_Item
463
-     * @throws EE_Error
464
-     */
465
-    public function parent()
466
-    {
467
-        return $this->ID()
468
-            ? $this->get_model()->get_one_by_ID($this->parent_ID())
469
-            : $this->_parent;
470
-    }
471
-
472
-
473
-    /**
474
-     * Gets ALL the children of this line item (ie, all the parts that contribute towards this total).
475
-     *
476
-     * @return EE_Base_Class[]|EE_Line_Item[]
477
-     * @throws EE_Error
478
-     */
479
-    public function children()
480
-    {
481
-        if ($this->ID()) {
482
-            return $this->get_model()->get_all(
483
-                array(
484
-                    array('LIN_parent' => $this->ID()),
485
-                    'order_by' => array('LIN_order' => 'ASC'),
486
-                )
487
-            );
488
-        }
489
-        if (! is_array($this->_children)) {
490
-            $this->_children = array();
491
-        }
492
-        return $this->_children;
493
-    }
494
-
495
-
496
-    /**
497
-     * Gets code
498
-     *
499
-     * @return string
500
-     * @throws EE_Error
501
-     */
502
-    public function code()
503
-    {
504
-        return $this->get('LIN_code');
505
-    }
506
-
507
-
508
-    /**
509
-     * Sets code
510
-     *
511
-     * @param string $code
512
-     * @throws EE_Error
513
-     */
514
-    public function set_code($code)
515
-    {
516
-        $this->set('LIN_code', $code);
517
-    }
518
-
519
-
520
-    /**
521
-     * Gets is_taxable
522
-     *
523
-     * @return boolean
524
-     * @throws EE_Error
525
-     */
526
-    public function is_taxable()
527
-    {
528
-        return $this->get('LIN_is_taxable');
529
-    }
530
-
531
-
532
-    /**
533
-     * Sets is_taxable
534
-     *
535
-     * @param boolean $is_taxable
536
-     * @throws EE_Error
537
-     */
538
-    public function set_is_taxable($is_taxable)
539
-    {
540
-        $this->set('LIN_is_taxable', $is_taxable);
541
-    }
542
-
543
-
544
-    /**
545
-     * Gets the object that this model-joins-to.
546
-     * returns one of the model objects that the field OBJ_ID can point to... see the 'OBJ_ID' field on
547
-     * EEM_Promotion_Object
548
-     *
549
-     *        Eg, if this line item join model object is for a ticket, this will return the EE_Ticket object
550
-     *
551
-     * @return EE_Base_Class | NULL
552
-     * @throws EE_Error
553
-     */
554
-    public function get_object()
555
-    {
556
-        $model_name_of_related_obj = $this->OBJ_type();
557
-        return $this->get_model()->has_relation($model_name_of_related_obj)
558
-            ? $this->get_first_related($model_name_of_related_obj)
559
-            : null;
560
-    }
561
-
562
-
563
-    /**
564
-     * Like EE_Line_Item::get_object(), but can only ever actually return an EE_Ticket.
565
-     * (IE, if this line item is for a price or something else, will return NULL)
566
-     *
567
-     * @param array $query_params
568
-     * @return EE_Base_Class|EE_Ticket
569
-     * @throws EE_Error
570
-     */
571
-    public function ticket($query_params = array())
572
-    {
573
-        // we're going to assume that when this method is called we always want to receive the attached ticket EVEN if that ticket is archived.  This can be overridden via the incoming $query_params argument
574
-        $remove_defaults = array('default_where_conditions' => 'none');
575
-        $query_params = array_merge($remove_defaults, $query_params);
576
-        return $this->get_first_related('Ticket', $query_params);
577
-    }
578
-
579
-
580
-    /**
581
-     * Gets the EE_Datetime that's related to the ticket, IF this is for a ticket
582
-     *
583
-     * @return EE_Datetime | NULL
584
-     * @throws EE_Error
585
-     */
586
-    public function get_ticket_datetime()
587
-    {
588
-        if ($this->OBJ_type() === 'Ticket') {
589
-            $ticket = $this->ticket();
590
-            if ($ticket instanceof EE_Ticket) {
591
-                $datetime = $ticket->first_datetime();
592
-                if ($datetime instanceof EE_Datetime) {
593
-                    return $datetime;
594
-                }
595
-            }
596
-        }
597
-        return null;
598
-    }
599
-
600
-
601
-    /**
602
-     * Gets the event's name that's related to the ticket, if this is for
603
-     * a ticket
604
-     *
605
-     * @return string
606
-     * @throws EE_Error
607
-     */
608
-    public function ticket_event_name()
609
-    {
610
-        $event_name = esc_html__('Unknown', 'event_espresso');
611
-        $event = $this->ticket_event();
612
-        if ($event instanceof EE_Event) {
613
-            $event_name = $event->name();
614
-        }
615
-        return $event_name;
616
-    }
617
-
618
-
619
-    /**
620
-     * Gets the event that's related to the ticket, if this line item represents a ticket.
621
-     *
622
-     * @return EE_Event|null
623
-     * @throws EE_Error
624
-     */
625
-    public function ticket_event()
626
-    {
627
-        $event = null;
628
-        $ticket = $this->ticket();
629
-        if ($ticket instanceof EE_Ticket) {
630
-            $datetime = $ticket->first_datetime();
631
-            if ($datetime instanceof EE_Datetime) {
632
-                $event = $datetime->event();
633
-            }
634
-        }
635
-        return $event;
636
-    }
637
-
638
-
639
-    /**
640
-     * Gets the first datetime for this lien item, assuming it's for a ticket
641
-     *
642
-     * @param string $date_format
643
-     * @param string $time_format
644
-     * @return string
645
-     * @throws EE_Error
646
-     */
647
-    public function ticket_datetime_start($date_format = '', $time_format = '')
648
-    {
649
-        $first_datetime_string = esc_html__('Unknown', 'event_espresso');
650
-        $datetime = $this->get_ticket_datetime();
651
-        if ($datetime) {
652
-            $first_datetime_string = $datetime->start_date_and_time($date_format, $time_format);
653
-        }
654
-        return $first_datetime_string;
655
-    }
656
-
657
-
658
-    /**
659
-     * Adds the line item as a child to this line item. If there is another child line
660
-     * item with the same LIN_code, it is overwritten by this new one
661
-     *
662
-     * @param EEI_Line_Item $line_item
663
-     * @param bool          $set_order
664
-     * @return bool success
665
-     * @throws EE_Error
666
-     */
667
-    public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true)
668
-    {
669
-        // should we calculate the LIN_order for this line item ?
670
-        if ($set_order || $line_item->order() === null) {
671
-            $line_item->set_order(count($this->children()));
672
-        }
673
-        if ($this->ID()) {
674
-            // check for any duplicate line items (with the same code), if so, this replaces it
675
-            $line_item_with_same_code = $this->get_child_line_item($line_item->code());
676
-            if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) {
677
-                $this->delete_child_line_item($line_item_with_same_code->code());
678
-            }
679
-            $line_item->set_parent_ID($this->ID());
680
-            if ($this->TXN_ID()) {
681
-                $line_item->set_TXN_ID($this->TXN_ID());
682
-            }
683
-            return $line_item->save();
684
-        }
685
-        $this->_children[ $line_item->code() ] = $line_item;
686
-        if ($line_item->parent() !== $this) {
687
-            $line_item->set_parent($this);
688
-        }
689
-        return true;
690
-    }
691
-
692
-
693
-    /**
694
-     * Similar to EE_Base_Class::_add_relation_to, except this isn't a normal relation.
695
-     * If this line item is saved to the DB, this is just a wrapper for set_parent_ID() and save()
696
-     * However, if this line item is NOT saved to the DB, this just caches the parent on
697
-     * the EE_Line_Item::_parent property.
698
-     *
699
-     * @param EE_Line_Item $line_item
700
-     * @throws EE_Error
701
-     */
702
-    public function set_parent($line_item)
703
-    {
704
-        if ($this->ID()) {
705
-            if (! $line_item->ID()) {
706
-                $line_item->save();
707
-            }
708
-            $this->set_parent_ID($line_item->ID());
709
-            $this->save();
710
-        } else {
711
-            $this->_parent = $line_item;
712
-            $this->set_parent_ID($line_item->ID());
713
-        }
714
-    }
715
-
716
-
717
-    /**
718
-     * Gets the child line item as specified by its code. Because this returns an object (by reference)
719
-     * you can modify this child line item and the parent (this object) can know about them
720
-     * because it also has a reference to that line item
721
-     *
722
-     * @param string $code
723
-     * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
724
-     * @throws EE_Error
725
-     */
726
-    public function get_child_line_item($code)
727
-    {
728
-        if ($this->ID()) {
729
-            return $this->get_model()->get_one(
730
-                array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code))
731
-            );
732
-        }
733
-        return isset($this->_children[ $code ])
734
-            ? $this->_children[ $code ]
735
-            : null;
736
-    }
737
-
738
-
739
-    /**
740
-     * Returns how many items are deleted (or, if this item has not been saved ot the DB yet, just how many it HAD
741
-     * cached on it)
742
-     *
743
-     * @return int
744
-     * @throws EE_Error
745
-     */
746
-    public function delete_children_line_items()
747
-    {
748
-        if ($this->ID()) {
749
-            return $this->get_model()->delete(array(array('LIN_parent' => $this->ID())));
750
-        }
751
-        $count = count($this->_children);
752
-        $this->_children = array();
753
-        return $count;
754
-    }
755
-
756
-
757
-    /**
758
-     * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line
759
-     * HAS NOT been saved to the DB, removes the child line item with index $code.
760
-     * Also searches through the child's children for a matching line item. However, once a line item has been found
761
-     * and deleted, stops searching (so if there are line items with duplicate codes, only the first one found will be
762
-     * deleted)
763
-     *
764
-     * @param string $code
765
-     * @param bool   $stop_search_once_found
766
-     * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to
767
-     *             the DB yet)
768
-     * @throws EE_Error
769
-     */
770
-    public function delete_child_line_item($code, $stop_search_once_found = true)
771
-    {
772
-        if ($this->ID()) {
773
-            $items_deleted = 0;
774
-            if ($this->code() === $code) {
775
-                $items_deleted += EEH_Line_Item::delete_all_child_items($this);
776
-                $items_deleted += (int) $this->delete();
777
-                if ($stop_search_once_found) {
778
-                    return $items_deleted;
779
-                }
780
-            }
781
-            foreach ($this->children() as $child_line_item) {
782
-                $items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found);
783
-            }
784
-            return $items_deleted;
785
-        }
786
-        if (isset($this->_children[ $code ])) {
787
-            unset($this->_children[ $code ]);
788
-            return 1;
789
-        }
790
-        return 0;
791
-    }
792
-
793
-
794
-    /**
795
-     * If this line item is in the database, is of the type subtotal, and
796
-     * has no children, why do we have it? It should be deleted so this function
797
-     * does that
798
-     *
799
-     * @return boolean
800
-     * @throws EE_Error
801
-     */
802
-    public function delete_if_childless_subtotal()
803
-    {
804
-        if ($this->ID() && $this->type() === EEM_Line_Item::type_sub_total && ! $this->children()) {
805
-            return $this->delete();
806
-        }
807
-        return false;
808
-    }
809
-
810
-
811
-    /**
812
-     * Creates a code and returns a string. doesn't assign the code to this model object
813
-     *
814
-     * @return string
815
-     * @throws EE_Error
816
-     */
817
-    public function generate_code()
818
-    {
819
-        // each line item in the cart requires a unique identifier
820
-        return md5($this->get('OBJ_type') . $this->get('OBJ_ID') . microtime());
821
-    }
822
-
823
-
824
-    /**
825
-     * @return bool
826
-     * @throws EE_Error
827
-     */
828
-    public function is_tax()
829
-    {
830
-        return $this->type() === EEM_Line_Item::type_tax;
831
-    }
832
-
833
-
834
-    /**
835
-     * @return bool
836
-     * @throws EE_Error
837
-     */
838
-    public function is_tax_sub_total()
839
-    {
840
-        return $this->type() === EEM_Line_Item::type_tax_sub_total;
841
-    }
842
-
843
-
844
-    /**
845
-     * @return bool
846
-     * @throws EE_Error
847
-     */
848
-    public function is_line_item()
849
-    {
850
-        return $this->type() === EEM_Line_Item::type_line_item;
851
-    }
852
-
853
-
854
-    /**
855
-     * @return bool
856
-     * @throws EE_Error
857
-     */
858
-    public function is_sub_line_item()
859
-    {
860
-        return $this->type() === EEM_Line_Item::type_sub_line_item;
861
-    }
862
-
863
-
864
-    /**
865
-     * @return bool
866
-     * @throws EE_Error
867
-     */
868
-    public function is_sub_total()
869
-    {
870
-        return $this->type() === EEM_Line_Item::type_sub_total;
871
-    }
872
-
873
-
874
-    /**
875
-     * Whether or not this line item is a cancellation line item
876
-     *
877
-     * @return boolean
878
-     * @throws EE_Error
879
-     */
880
-    public function is_cancellation()
881
-    {
882
-        return EEM_Line_Item::type_cancellation === $this->type();
883
-    }
884
-
885
-
886
-    /**
887
-     * @return bool
888
-     * @throws EE_Error
889
-     */
890
-    public function is_total()
891
-    {
892
-        return $this->type() === EEM_Line_Item::type_total;
893
-    }
894
-
895
-
896
-    /**
897
-     * @return bool
898
-     * @throws EE_Error
899
-     */
900
-    public function is_cancelled()
901
-    {
902
-        return $this->type() === EEM_Line_Item::type_cancellation;
903
-    }
904
-
905
-
906
-    /**
907
-     * @return string like '2, 004.00', formatted according to the localized currency
908
-     * @throws EE_Error
909
-     */
910
-    public function unit_price_no_code()
911
-    {
912
-        return $this->get_pretty('LIN_unit_price', 'no_currency_code');
913
-    }
914
-
915
-
916
-    /**
917
-     * @return string like '2, 004.00', formatted according to the localized currency
918
-     * @throws EE_Error
919
-     */
920
-    public function total_no_code()
921
-    {
922
-        return $this->get_pretty('LIN_total', 'no_currency_code');
923
-    }
924
-
925
-
926
-    /**
927
-     * Gets the final total on this item, taking taxes into account.
928
-     * Has the side-effect of setting the sub-total as it was just calculated.
929
-     * If this is used on a grand-total line item, also updates the transaction's
930
-     * TXN_total (provided this line item is allowed to persist, otherwise we don't
931
-     * want to change a persistable transaction with info from a non-persistent line item)
932
-     *
933
-     * @return float
934
-     * @throws EE_Error
935
-     * @throws InvalidArgumentException
936
-     * @throws InvalidInterfaceException
937
-     * @throws InvalidDataTypeException
938
-     */
939
-    public function recalculate_total_including_taxes()
940
-    {
941
-        $pre_tax_total = $this->recalculate_pre_tax_total();
942
-        $tax_total = $this->recalculate_taxes_and_tax_total();
943
-        $total = $pre_tax_total + $tax_total;
944
-        // no negative totals plz
945
-        $total = max($total, 0);
946
-        $this->set_total($total);
947
-        // only update the related transaction's total
948
-        // if we intend to save this line item and its a grand total
949
-        if ($this->allow_persist() && $this->type() === EEM_Line_Item::type_total
950
-            && $this->transaction()
951
-               instanceof
952
-               EE_Transaction
953
-        ) {
954
-            $this->transaction()->set_total($total);
955
-            if ($this->transaction()->ID()) {
956
-                $this->transaction()->save();
957
-            }
958
-        }
959
-        $this->maybe_save();
960
-        return $total;
961
-    }
962
-
963
-
964
-    /**
965
-     * Recursively goes through all the children and recalculates sub-totals EXCEPT for
966
-     * tax-sub-totals (they're a an odd beast). Updates the 'total' on each line item according to either its
967
-     * unit price * quantity or the total of all its children EXCEPT when we're only calculating the taxable total and
968
-     * when this is called on the grand total
969
-     *
970
-     * @return float
971
-     * @throws InvalidArgumentException
972
-     * @throws InvalidInterfaceException
973
-     * @throws InvalidDataTypeException
974
-     * @throws EE_Error
975
-     */
976
-    public function recalculate_pre_tax_total()
977
-    {
978
-        $total = 0;
979
-        $my_children = $this->children();
980
-        $has_children = ! empty($my_children);
981
-        if ($has_children && $this->is_line_item()) {
982
-            $total = $this->_recalculate_pretax_total_for_line_item($total, $my_children);
983
-        } elseif (! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) {
984
-            $total = $this->unit_price() * $this->quantity();
985
-        } elseif ($this->is_sub_total() || $this->is_total()) {
986
-            $total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children);
987
-        } elseif ($this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled()) {
988
-            // completely ignore tax totals, tax sub-totals, and cancelled line items, when calculating the pre-tax-total
989
-            return 0;
990
-        }
991
-        // ensure all non-line items and non-sub-line-items have a quantity of 1 (except for Events)
992
-        if (! $this->is_line_item() && ! $this->is_sub_line_item() && ! $this->is_cancellation()
993
-        ) {
994
-            if ($this->OBJ_type() !== 'Event') {
995
-                $this->set_quantity(1);
996
-            }
997
-            if (! $this->is_percent()) {
998
-                $this->set_unit_price($total);
999
-            }
1000
-        }
1001
-        // we don't want to bother saving grand totals, because that needs to factor in taxes anyways
1002
-        // so it ought to be
1003
-        if (! $this->is_total()) {
1004
-            $this->set_total($total);
1005
-            // if not a percent line item, make sure we keep the unit price in sync
1006
-            if ($has_children
1007
-                && $this->is_line_item()
1008
-                && ! $this->is_percent()
1009
-            ) {
1010
-                if ($this->quantity() === 0) {
1011
-                    $new_unit_price = 0;
1012
-                } else {
1013
-                    $new_unit_price = $this->total() / $this->quantity();
1014
-                }
1015
-                $this->set_unit_price($new_unit_price);
1016
-            }
1017
-            $this->maybe_save();
1018
-        }
1019
-        return $total;
1020
-    }
1021
-
1022
-
1023
-    /**
1024
-     * Calculates the pretax total when this line item is a subtotal or total line item.
1025
-     * Basically does a sum-then-round approach (ie, any percent line item that are children
1026
-     * will calculate their total based on the un-rounded total we're working with so far, and
1027
-     * THEN round the result; instead of rounding as we go like with sub-line-items)
1028
-     *
1029
-     * @param float          $calculated_total_so_far
1030
-     * @param EE_Line_Item[] $my_children
1031
-     * @return float
1032
-     * @throws InvalidArgumentException
1033
-     * @throws InvalidInterfaceException
1034
-     * @throws InvalidDataTypeException
1035
-     * @throws EE_Error
1036
-     */
1037
-    protected function _recalculate_pretax_total_for_subtotal($calculated_total_so_far, $my_children = null)
1038
-    {
1039
-        if ($my_children === null) {
1040
-            $my_children = $this->children();
1041
-        }
1042
-        $subtotal_quantity = 0;
1043
-        // get the total of all its children
1044
-        foreach ($my_children as $child_line_item) {
1045
-            if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) {
1046
-                // percentage line items are based on total so far
1047
-                if ($child_line_item->is_percent()) {
1048
-                    // round as we go so that the line items add up ok
1049
-                    $percent_total = round(
1050
-                        $calculated_total_so_far * $child_line_item->percent() / 100,
1051
-                        EE_Registry::instance()->CFG->currency->dec_plc
1052
-                    );
1053
-                    $child_line_item->set_total($percent_total);
1054
-                    // so far all percent line items should have a quantity of 1
1055
-                    // (ie, no double percent discounts. Although that might be requested someday)
1056
-                    $child_line_item->set_quantity(1);
1057
-                    $child_line_item->maybe_save();
1058
-                    $calculated_total_so_far += $percent_total;
1059
-                } else {
1060
-                    // verify flat sub-line-item quantities match their parent
1061
-                    if ($child_line_item->is_sub_line_item()) {
1062
-                        $child_line_item->set_quantity($this->quantity());
1063
-                    }
1064
-                    $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total();
1065
-                    $subtotal_quantity += $child_line_item->quantity();
1066
-                }
1067
-            }
1068
-        }
1069
-        if ($this->is_sub_total()) {
1070
-            // no negative totals plz
1071
-            $calculated_total_so_far = max($calculated_total_so_far, 0);
1072
-            $subtotal_quantity = $subtotal_quantity > 0 ? 1 : 0;
1073
-            $this->set_quantity($subtotal_quantity);
1074
-            $this->maybe_save();
1075
-        }
1076
-        return $calculated_total_so_far;
1077
-    }
1078
-
1079
-
1080
-    /**
1081
-     * Calculates the pretax total for a normal line item, in a round-then-sum approach
1082
-     * (where each sub-line-item is applied to the base price for the line item
1083
-     * and the result is immediately rounded, rather than summing all the sub-line-items
1084
-     * then rounding, like we do when recalculating pretax totals on totals and subtotals).
1085
-     *
1086
-     * @param float          $calculated_total_so_far
1087
-     * @param EE_Line_Item[] $my_children
1088
-     * @return float
1089
-     * @throws InvalidArgumentException
1090
-     * @throws InvalidInterfaceException
1091
-     * @throws InvalidDataTypeException
1092
-     * @throws EE_Error
1093
-     */
1094
-    protected function _recalculate_pretax_total_for_line_item($calculated_total_so_far, $my_children = null)
1095
-    {
1096
-        if ($my_children === null) {
1097
-            $my_children = $this->children();
1098
-        }
1099
-        // we need to keep track of the running total for a single item,
1100
-        // because we need to round as we go
1101
-        $unit_price_for_total = 0;
1102
-        $quantity_for_total = 1;
1103
-        // get the total of all its children
1104
-        foreach ($my_children as $child_line_item) {
1105
-            if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) {
1106
-                if ($child_line_item->is_percent()) {
1107
-                    // it should be the unit-price-so-far multiplied by teh percent multiplied by the quantity
1108
-                    // not total multiplied by percent, because that ignores rounding along-the-way
1109
-                    $percent_unit_price = round(
1110
-                        $unit_price_for_total * $child_line_item->percent() / 100,
1111
-                        EE_Registry::instance()->CFG->currency->dec_plc
1112
-                    );
1113
-                    $percent_total = $percent_unit_price * $quantity_for_total;
1114
-                    $child_line_item->set_total($percent_total);
1115
-                    // so far all percent line items should have a quantity of 1
1116
-                    // (ie, no double percent discounts. Although that might be requested someday)
1117
-                    $child_line_item->set_quantity(1);
1118
-                    $child_line_item->maybe_save();
1119
-                    $calculated_total_so_far += $percent_total;
1120
-                    $unit_price_for_total += $percent_unit_price;
1121
-                } else {
1122
-                    // verify flat sub-line-item quantities match their parent
1123
-                    if ($child_line_item->is_sub_line_item()) {
1124
-                        $child_line_item->set_quantity($this->quantity());
1125
-                    }
1126
-                    $quantity_for_total = $child_line_item->quantity();
1127
-                    $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total();
1128
-                    $unit_price_for_total += $child_line_item->unit_price();
1129
-                }
1130
-            }
1131
-        }
1132
-        return $calculated_total_so_far;
1133
-    }
1134
-
1135
-
1136
-    /**
1137
-     * Recalculates the total on each individual tax (based on a recalculation of the pre-tax total), sets
1138
-     * the totals on each tax calculated, and returns the final tax total. Re-saves tax line items
1139
-     * and tax sub-total if already in the DB
1140
-     *
1141
-     * @return float
1142
-     * @throws EE_Error
1143
-     */
1144
-    public function recalculate_taxes_and_tax_total()
1145
-    {
1146
-        // get all taxes
1147
-        $taxes = $this->tax_descendants();
1148
-        // calculate the pretax total
1149
-        $taxable_total = $this->taxable_total();
1150
-        $tax_total = 0;
1151
-        foreach ($taxes as $tax) {
1152
-            $total_on_this_tax = $taxable_total * $tax->percent() / 100;
1153
-            // remember the total on this line item
1154
-            $tax->set_total($total_on_this_tax);
1155
-            $tax->maybe_save();
1156
-            $tax_total += $tax->total();
1157
-        }
1158
-        $this->_recalculate_tax_sub_total();
1159
-        return $tax_total;
1160
-    }
1161
-
1162
-
1163
-    /**
1164
-     * Simply forces all the tax-sub-totals to recalculate. Assumes the taxes have been calculated
1165
-     *
1166
-     * @return void
1167
-     * @throws EE_Error
1168
-     */
1169
-    private function _recalculate_tax_sub_total()
1170
-    {
1171
-        if ($this->is_tax_sub_total()) {
1172
-            $total = 0;
1173
-            $total_percent = 0;
1174
-            // simply loop through all its children (which should be taxes) and sum their total
1175
-            foreach ($this->children() as $child_tax) {
1176
-                if ($child_tax instanceof EE_Line_Item) {
1177
-                    $total += $child_tax->total();
1178
-                    $total_percent += $child_tax->percent();
1179
-                }
1180
-            }
1181
-            $this->set_total($total);
1182
-            $this->set_percent($total_percent);
1183
-            $this->maybe_save();
1184
-        } elseif ($this->is_total()) {
1185
-            foreach ($this->children() as $maybe_tax_subtotal) {
1186
-                if ($maybe_tax_subtotal instanceof EE_Line_Item) {
1187
-                    $maybe_tax_subtotal->_recalculate_tax_sub_total();
1188
-                }
1189
-            }
1190
-        }
1191
-    }
1192
-
1193
-
1194
-    /**
1195
-     * Gets the total tax on this line item. Assumes taxes have already been calculated using
1196
-     * recalculate_taxes_and_total
1197
-     *
1198
-     * @return float
1199
-     * @throws EE_Error
1200
-     */
1201
-    public function get_total_tax()
1202
-    {
1203
-        $this->_recalculate_tax_sub_total();
1204
-        $total = 0;
1205
-        foreach ($this->tax_descendants() as $tax_line_item) {
1206
-            if ($tax_line_item instanceof EE_Line_Item) {
1207
-                $total += $tax_line_item->total();
1208
-            }
1209
-        }
1210
-        return $total;
1211
-    }
1212
-
1213
-
1214
-    /**
1215
-     * Gets the total for all the items purchased only
1216
-     *
1217
-     * @return float
1218
-     * @throws EE_Error
1219
-     */
1220
-    public function get_items_total()
1221
-    {
1222
-        // by default, let's make sure we're consistent with the existing line item
1223
-        if ($this->is_total()) {
1224
-            $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal($this);
1225
-            if ($pretax_subtotal_li instanceof EE_Line_Item) {
1226
-                return $pretax_subtotal_li->total();
1227
-            }
1228
-        }
1229
-        $total = 0;
1230
-        foreach ($this->get_items() as $item) {
1231
-            if ($item instanceof EE_Line_Item) {
1232
-                $total += $item->total();
1233
-            }
1234
-        }
1235
-        return $total;
1236
-    }
1237
-
1238
-
1239
-    /**
1240
-     * Gets all the descendants (ie, children or children of children etc) that
1241
-     * are of the type 'tax'
1242
-     *
1243
-     * @return EE_Line_Item[]
1244
-     */
1245
-    public function tax_descendants()
1246
-    {
1247
-        return EEH_Line_Item::get_tax_descendants($this);
1248
-    }
1249
-
1250
-
1251
-    /**
1252
-     * Gets all the real items purchased which are children of this item
1253
-     *
1254
-     * @return EE_Line_Item[]
1255
-     */
1256
-    public function get_items()
1257
-    {
1258
-        return EEH_Line_Item::get_line_item_descendants($this);
1259
-    }
1260
-
1261
-
1262
-    /**
1263
-     * Returns the amount taxable among this line item's children (or if it has no children,
1264
-     * how much of it is taxable). Does not recalculate totals or subtotals.
1265
-     * If the taxable total is negative, (eg, if none of the tickets were taxable,
1266
-     * but there is a "Taxable" discount), returns 0.
1267
-     *
1268
-     * @return float
1269
-     * @throws EE_Error
1270
-     */
1271
-    public function taxable_total()
1272
-    {
1273
-        $total = 0;
1274
-        if ($this->children()) {
1275
-            foreach ($this->children() as $child_line_item) {
1276
-                if ($child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) {
1277
-                    // if it's a percent item, only take into account the percent
1278
-                    // that's taxable too (the taxable total so far)
1279
-                    if ($child_line_item->is_percent()) {
1280
-                        $total += ($total * $child_line_item->percent() / 100);
1281
-                    } else {
1282
-                        $total += $child_line_item->total();
1283
-                    }
1284
-                } elseif ($child_line_item->type() === EEM_Line_Item::type_sub_total) {
1285
-                    $total += $child_line_item->taxable_total();
1286
-                }
1287
-            }
1288
-        }
1289
-        return max($total, 0);
1290
-    }
1291
-
1292
-
1293
-    /**
1294
-     * Gets the transaction for this line item
1295
-     *
1296
-     * @return EE_Base_Class|EE_Transaction
1297
-     * @throws EE_Error
1298
-     */
1299
-    public function transaction()
1300
-    {
1301
-        return $this->get_first_related('Transaction');
1302
-    }
1303
-
1304
-
1305
-    /**
1306
-     * Saves this line item to the DB, and recursively saves its descendants.
1307
-     * Because there currently is no proper parent-child relation on the model,
1308
-     * save_this_and_cached() will NOT save the descendants.
1309
-     * Also sets the transaction on this line item and all its descendants before saving
1310
-     *
1311
-     * @param int $txn_id if none is provided, assumes $this->TXN_ID()
1312
-     * @return int count of items saved
1313
-     * @throws EE_Error
1314
-     */
1315
-    public function save_this_and_descendants_to_txn($txn_id = null)
1316
-    {
1317
-        $count = 0;
1318
-        if (! $txn_id) {
1319
-            $txn_id = $this->TXN_ID();
1320
-        }
1321
-        $this->set_TXN_ID($txn_id);
1322
-        $children = $this->children();
1323
-        $count += $this->save()
1324
-            ? 1
1325
-            : 0;
1326
-        foreach ($children as $child_line_item) {
1327
-            if ($child_line_item instanceof EE_Line_Item) {
1328
-                $child_line_item->set_parent_ID($this->ID());
1329
-                $count += $child_line_item->save_this_and_descendants_to_txn($txn_id);
1330
-            }
1331
-        }
1332
-        return $count;
1333
-    }
1334
-
1335
-
1336
-    /**
1337
-     * Saves this line item to the DB, and recursively saves its descendants.
1338
-     *
1339
-     * @return int count of items saved
1340
-     * @throws EE_Error
1341
-     */
1342
-    public function save_this_and_descendants()
1343
-    {
1344
-        $count = 0;
1345
-        $children = $this->children();
1346
-        $count += $this->save()
1347
-            ? 1
1348
-            : 0;
1349
-        foreach ($children as $child_line_item) {
1350
-            if ($child_line_item instanceof EE_Line_Item) {
1351
-                $child_line_item->set_parent_ID($this->ID());
1352
-                $count += $child_line_item->save_this_and_descendants();
1353
-            }
1354
-        }
1355
-        return $count;
1356
-    }
1357
-
1358
-
1359
-    /**
1360
-     * returns the cancellation line item if this item was cancelled
1361
-     *
1362
-     * @return EE_Line_Item[]
1363
-     * @throws InvalidArgumentException
1364
-     * @throws InvalidInterfaceException
1365
-     * @throws InvalidDataTypeException
1366
-     * @throws ReflectionException
1367
-     * @throws EE_Error
1368
-     */
1369
-    public function get_cancellations()
1370
-    {
1371
-        EE_Registry::instance()->load_helper('Line_Item');
1372
-        return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation);
1373
-    }
1374
-
1375
-
1376
-    /**
1377
-     * If this item has an ID, then this saves it again to update the db
1378
-     *
1379
-     * @return int count of items saved
1380
-     * @throws EE_Error
1381
-     */
1382
-    public function maybe_save()
1383
-    {
1384
-        if ($this->ID()) {
1385
-            return $this->save();
1386
-        }
1387
-        return false;
1388
-    }
1389
-
1390
-
1391
-    /**
1392
-     * clears the cached children and parent from the line item
1393
-     *
1394
-     * @return void
1395
-     */
1396
-    public function clear_related_line_item_cache()
1397
-    {
1398
-        $this->_children = array();
1399
-        $this->_parent = null;
1400
-    }
1401
-
1402
-
1403
-    /**
1404
-     * @param bool $raw
1405
-     * @return int
1406
-     * @throws EE_Error
1407
-     */
1408
-    public function timestamp($raw = false)
1409
-    {
1410
-        return $raw
1411
-            ? $this->get_raw('LIN_timestamp')
1412
-            : $this->get('LIN_timestamp');
1413
-    }
1414
-
1415
-
1416
-
1417
-
1418
-    /************************* DEPRECATED *************************/
1419
-    /**
1420
-     * @deprecated 4.6.0
1421
-     * @param string $type one of the constants on EEM_Line_Item
1422
-     * @return EE_Line_Item[]
1423
-     */
1424
-    protected function _get_descendants_of_type($type)
1425
-    {
1426
-        EE_Error::doing_it_wrong(
1427
-            'EE_Line_Item::_get_descendants_of_type()',
1428
-            __('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'),
1429
-            '4.6.0'
1430
-        );
1431
-        return EEH_Line_Item::get_descendants_of_type($this, $type);
1432
-    }
1433
-
1434
-
1435
-    /**
1436
-     * @deprecated 4.6.0
1437
-     * @param string $type like one of the EEM_Line_Item::type_*
1438
-     * @return EE_Line_Item
1439
-     */
1440
-    public function get_nearest_descendant_of_type($type)
1441
-    {
1442
-        EE_Error::doing_it_wrong(
1443
-            'EE_Line_Item::get_nearest_descendant_of_type()',
1444
-            __('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'),
1445
-            '4.6.0'
1446
-        );
1447
-        return EEH_Line_Item::get_nearest_descendant_of_type($this, $type);
1448
-    }
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
+	 *
34
+	 * @param array  $props_n_values          incoming values
35
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
36
+	 *                                        used.)
37
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
38
+	 *                                        date_format and the second value is the time format
39
+	 * @return EE_Line_Item
40
+	 * @throws EE_Error
41
+	 */
42
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
43
+	{
44
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
45
+		return $has_object
46
+			? $has_object
47
+			: new self($props_n_values, false, $timezone);
48
+	}
49
+
50
+
51
+	/**
52
+	 * @param array  $props_n_values  incoming values from the database
53
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
54
+	 *                                the website will be used.
55
+	 * @return EE_Line_Item
56
+	 * @throws EE_Error
57
+	 */
58
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
59
+	{
60
+		return new self($props_n_values, true, $timezone);
61
+	}
62
+
63
+
64
+	/**
65
+	 * Adds some defaults if they're not specified
66
+	 *
67
+	 * @param array  $fieldValues
68
+	 * @param bool   $bydb
69
+	 * @param string $timezone
70
+	 * @throws EE_Error
71
+	 */
72
+	protected function __construct($fieldValues = array(), $bydb = false, $timezone = '')
73
+	{
74
+		parent::__construct($fieldValues, $bydb, $timezone);
75
+		if (! $this->get('LIN_code')) {
76
+			$this->set_code($this->generate_code());
77
+		}
78
+	}
79
+
80
+
81
+	/**
82
+	 * Gets ID
83
+	 *
84
+	 * @return int
85
+	 * @throws EE_Error
86
+	 */
87
+	public function ID()
88
+	{
89
+		return $this->get('LIN_ID');
90
+	}
91
+
92
+
93
+	/**
94
+	 * Gets TXN_ID
95
+	 *
96
+	 * @return int
97
+	 * @throws EE_Error
98
+	 */
99
+	public function TXN_ID()
100
+	{
101
+		return $this->get('TXN_ID');
102
+	}
103
+
104
+
105
+	/**
106
+	 * Sets TXN_ID
107
+	 *
108
+	 * @param int $TXN_ID
109
+	 * @throws EE_Error
110
+	 */
111
+	public function set_TXN_ID($TXN_ID)
112
+	{
113
+		$this->set('TXN_ID', $TXN_ID);
114
+	}
115
+
116
+
117
+	/**
118
+	 * Gets name
119
+	 *
120
+	 * @return string
121
+	 * @throws EE_Error
122
+	 */
123
+	public function name()
124
+	{
125
+		$name = $this->get('LIN_name');
126
+		if (! $name) {
127
+			$name = ucwords(str_replace('-', ' ', $this->type()));
128
+		}
129
+		return $name;
130
+	}
131
+
132
+
133
+	/**
134
+	 * Sets name
135
+	 *
136
+	 * @param string $name
137
+	 * @throws EE_Error
138
+	 */
139
+	public function set_name($name)
140
+	{
141
+		$this->set('LIN_name', $name);
142
+	}
143
+
144
+
145
+	/**
146
+	 * Gets desc
147
+	 *
148
+	 * @return string
149
+	 * @throws EE_Error
150
+	 */
151
+	public function desc()
152
+	{
153
+		return $this->get('LIN_desc');
154
+	}
155
+
156
+
157
+	/**
158
+	 * Sets desc
159
+	 *
160
+	 * @param string $desc
161
+	 * @throws EE_Error
162
+	 */
163
+	public function set_desc($desc)
164
+	{
165
+		$this->set('LIN_desc', $desc);
166
+	}
167
+
168
+
169
+	/**
170
+	 * Gets quantity
171
+	 *
172
+	 * @return int
173
+	 * @throws EE_Error
174
+	 */
175
+	public function quantity()
176
+	{
177
+		return $this->get('LIN_quantity');
178
+	}
179
+
180
+
181
+	/**
182
+	 * Sets quantity
183
+	 *
184
+	 * @param int $quantity
185
+	 * @throws EE_Error
186
+	 */
187
+	public function set_quantity($quantity)
188
+	{
189
+		$this->set('LIN_quantity', max($quantity, 0));
190
+	}
191
+
192
+
193
+	/**
194
+	 * Gets item_id
195
+	 *
196
+	 * @return string
197
+	 * @throws EE_Error
198
+	 */
199
+	public function OBJ_ID()
200
+	{
201
+		return $this->get('OBJ_ID');
202
+	}
203
+
204
+
205
+	/**
206
+	 * Sets item_id
207
+	 *
208
+	 * @param string $item_id
209
+	 * @throws EE_Error
210
+	 */
211
+	public function set_OBJ_ID($item_id)
212
+	{
213
+		$this->set('OBJ_ID', $item_id);
214
+	}
215
+
216
+
217
+	/**
218
+	 * Gets item_type
219
+	 *
220
+	 * @return string
221
+	 * @throws EE_Error
222
+	 */
223
+	public function OBJ_type()
224
+	{
225
+		return $this->get('OBJ_type');
226
+	}
227
+
228
+
229
+	/**
230
+	 * Gets item_type
231
+	 *
232
+	 * @return string
233
+	 * @throws EE_Error
234
+	 */
235
+	public function OBJ_type_i18n()
236
+	{
237
+		$obj_type = $this->OBJ_type();
238
+		switch ($obj_type) {
239
+			case 'Event':
240
+				$obj_type = __('Event', 'event_espresso');
241
+				break;
242
+			case 'Price':
243
+				$obj_type = __('Price', 'event_espresso');
244
+				break;
245
+			case 'Promotion':
246
+				$obj_type = __('Promotion', 'event_espresso');
247
+				break;
248
+			case 'Ticket':
249
+				$obj_type = __('Ticket', 'event_espresso');
250
+				break;
251
+			case 'Transaction':
252
+				$obj_type = __('Transaction', 'event_espresso');
253
+				break;
254
+		}
255
+		return apply_filters('FHEE__EE_Line_Item__OBJ_type_i18n', $obj_type, $this);
256
+	}
257
+
258
+
259
+	/**
260
+	 * Sets item_type
261
+	 *
262
+	 * @param string $OBJ_type
263
+	 * @throws EE_Error
264
+	 */
265
+	public function set_OBJ_type($OBJ_type)
266
+	{
267
+		$this->set('OBJ_type', $OBJ_type);
268
+	}
269
+
270
+
271
+	/**
272
+	 * Gets unit_price
273
+	 *
274
+	 * @return float
275
+	 * @throws EE_Error
276
+	 */
277
+	public function unit_price()
278
+	{
279
+		return $this->get('LIN_unit_price');
280
+	}
281
+
282
+
283
+	/**
284
+	 * Sets unit_price
285
+	 *
286
+	 * @param float $unit_price
287
+	 * @throws EE_Error
288
+	 */
289
+	public function set_unit_price($unit_price)
290
+	{
291
+		if($this->type() !== EEM_Line_Item::type_sub_line_item) { 
292
+			$unit_price = EEH_Money::round_for_currency($unit_price, EE_Config::instance()->currency->code);
293
+		} 
294
+		$this->set('LIN_unit_price', $unit_price);
295
+	}
296
+
297
+
298
+	/**
299
+	 * Checks if this item is a percentage modifier or not
300
+	 *
301
+	 * @return boolean
302
+	 * @throws EE_Error
303
+	 */
304
+	public function is_percent()
305
+	{
306
+		if ($this->is_tax_sub_total()) {
307
+			// tax subtotals HAVE a percent on them, that percentage only applies
308
+			// to taxable items, so its' an exception. Treat it like a flat line item
309
+			return false;
310
+		}
311
+		$unit_price = abs($this->get('LIN_unit_price'));
312
+		$percent = abs($this->get('LIN_percent'));
313
+		if ($unit_price < .001 && $percent) {
314
+			return true;
315
+		}
316
+		if ($unit_price >= .001 && ! $percent) {
317
+			return false;
318
+		}
319
+		if ($unit_price >= .001 && $percent) {
320
+			throw new EE_Error(
321
+				sprintf(
322
+					esc_html__('A Line Item can not have a unit price of (%s) AND a percent (%s)!', 'event_espresso'),
323
+					$unit_price,
324
+					$percent
325
+				)
326
+			);
327
+		}
328
+		// if they're both 0, assume its not a percent item
329
+		return false;
330
+	}
331
+
332
+
333
+	/**
334
+	 * Gets percent (between 100-.001)
335
+	 *
336
+	 * @return float
337
+	 * @throws EE_Error
338
+	 */
339
+	public function percent()
340
+	{
341
+		return $this->get('LIN_percent');
342
+	}
343
+
344
+
345
+	/**
346
+	 * Sets percent (between 100-0.01)
347
+	 *
348
+	 * @param float $percent
349
+	 * @throws EE_Error
350
+	 */
351
+	public function set_percent($percent)
352
+	{
353
+		$this->set('LIN_percent', $percent);
354
+	}
355
+
356
+
357
+	/**
358
+	 * Gets total
359
+	 *
360
+	 * @return float
361
+	 * @throws EE_Error
362
+	 */
363
+	public function total()
364
+	{
365
+		return $this->get('LIN_total');
366
+	}
367
+
368
+
369
+	/**
370
+	 * Sets total
371
+	 *
372
+	 * @param float $total
373
+	 * @throws EE_Error
374
+	 */
375
+	public function set_total($total)
376
+	{
377
+		if($this->type() !== EEM_Line_Item::type_sub_line_item) { 
378
+			$total = EEH_Money::round_for_currency($total, EE_Config::instance()->currency->code); 
379
+		} 
380
+		$this->set('LIN_total', $total);
381
+	}
382
+
383
+
384
+	/**
385
+	 * Gets order
386
+	 *
387
+	 * @return int
388
+	 * @throws EE_Error
389
+	 */
390
+	public function order()
391
+	{
392
+		return $this->get('LIN_order');
393
+	}
394
+
395
+
396
+	/**
397
+	 * Sets order
398
+	 *
399
+	 * @param int $order
400
+	 * @throws EE_Error
401
+	 */
402
+	public function set_order($order)
403
+	{
404
+		$this->set('LIN_order', $order);
405
+	}
406
+
407
+
408
+	/**
409
+	 * Gets parent
410
+	 *
411
+	 * @return int
412
+	 * @throws EE_Error
413
+	 */
414
+	public function parent_ID()
415
+	{
416
+		return $this->get('LIN_parent');
417
+	}
418
+
419
+
420
+	/**
421
+	 * Sets parent
422
+	 *
423
+	 * @param int $parent
424
+	 * @throws EE_Error
425
+	 */
426
+	public function set_parent_ID($parent)
427
+	{
428
+		$this->set('LIN_parent', $parent);
429
+	}
430
+
431
+
432
+	/**
433
+	 * Gets type
434
+	 *
435
+	 * @return string
436
+	 * @throws EE_Error
437
+	 */
438
+	public function type()
439
+	{
440
+		return $this->get('LIN_type');
441
+	}
442
+
443
+
444
+	/**
445
+	 * Sets type
446
+	 *
447
+	 * @param string $type
448
+	 * @throws EE_Error
449
+	 */
450
+	public function set_type($type)
451
+	{
452
+		$this->set('LIN_type', $type);
453
+	}
454
+
455
+
456
+	/**
457
+	 * Gets the line item of which this item is a composite. Eg, if this is a subtotal, the parent might be a total\
458
+	 * 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
459
+	 * it uses its cached reference to its parent line item (which would have been set by `EE_Line_Item::set_parent()`
460
+	 * or indirectly by `EE_Line_item::add_child_line_item()`)
461
+	 *
462
+	 * @return EE_Base_Class|EE_Line_Item
463
+	 * @throws EE_Error
464
+	 */
465
+	public function parent()
466
+	{
467
+		return $this->ID()
468
+			? $this->get_model()->get_one_by_ID($this->parent_ID())
469
+			: $this->_parent;
470
+	}
471
+
472
+
473
+	/**
474
+	 * Gets ALL the children of this line item (ie, all the parts that contribute towards this total).
475
+	 *
476
+	 * @return EE_Base_Class[]|EE_Line_Item[]
477
+	 * @throws EE_Error
478
+	 */
479
+	public function children()
480
+	{
481
+		if ($this->ID()) {
482
+			return $this->get_model()->get_all(
483
+				array(
484
+					array('LIN_parent' => $this->ID()),
485
+					'order_by' => array('LIN_order' => 'ASC'),
486
+				)
487
+			);
488
+		}
489
+		if (! is_array($this->_children)) {
490
+			$this->_children = array();
491
+		}
492
+		return $this->_children;
493
+	}
494
+
495
+
496
+	/**
497
+	 * Gets code
498
+	 *
499
+	 * @return string
500
+	 * @throws EE_Error
501
+	 */
502
+	public function code()
503
+	{
504
+		return $this->get('LIN_code');
505
+	}
506
+
507
+
508
+	/**
509
+	 * Sets code
510
+	 *
511
+	 * @param string $code
512
+	 * @throws EE_Error
513
+	 */
514
+	public function set_code($code)
515
+	{
516
+		$this->set('LIN_code', $code);
517
+	}
518
+
519
+
520
+	/**
521
+	 * Gets is_taxable
522
+	 *
523
+	 * @return boolean
524
+	 * @throws EE_Error
525
+	 */
526
+	public function is_taxable()
527
+	{
528
+		return $this->get('LIN_is_taxable');
529
+	}
530
+
531
+
532
+	/**
533
+	 * Sets is_taxable
534
+	 *
535
+	 * @param boolean $is_taxable
536
+	 * @throws EE_Error
537
+	 */
538
+	public function set_is_taxable($is_taxable)
539
+	{
540
+		$this->set('LIN_is_taxable', $is_taxable);
541
+	}
542
+
543
+
544
+	/**
545
+	 * Gets the object that this model-joins-to.
546
+	 * returns one of the model objects that the field OBJ_ID can point to... see the 'OBJ_ID' field on
547
+	 * EEM_Promotion_Object
548
+	 *
549
+	 *        Eg, if this line item join model object is for a ticket, this will return the EE_Ticket object
550
+	 *
551
+	 * @return EE_Base_Class | NULL
552
+	 * @throws EE_Error
553
+	 */
554
+	public function get_object()
555
+	{
556
+		$model_name_of_related_obj = $this->OBJ_type();
557
+		return $this->get_model()->has_relation($model_name_of_related_obj)
558
+			? $this->get_first_related($model_name_of_related_obj)
559
+			: null;
560
+	}
561
+
562
+
563
+	/**
564
+	 * Like EE_Line_Item::get_object(), but can only ever actually return an EE_Ticket.
565
+	 * (IE, if this line item is for a price or something else, will return NULL)
566
+	 *
567
+	 * @param array $query_params
568
+	 * @return EE_Base_Class|EE_Ticket
569
+	 * @throws EE_Error
570
+	 */
571
+	public function ticket($query_params = array())
572
+	{
573
+		// we're going to assume that when this method is called we always want to receive the attached ticket EVEN if that ticket is archived.  This can be overridden via the incoming $query_params argument
574
+		$remove_defaults = array('default_where_conditions' => 'none');
575
+		$query_params = array_merge($remove_defaults, $query_params);
576
+		return $this->get_first_related('Ticket', $query_params);
577
+	}
578
+
579
+
580
+	/**
581
+	 * Gets the EE_Datetime that's related to the ticket, IF this is for a ticket
582
+	 *
583
+	 * @return EE_Datetime | NULL
584
+	 * @throws EE_Error
585
+	 */
586
+	public function get_ticket_datetime()
587
+	{
588
+		if ($this->OBJ_type() === 'Ticket') {
589
+			$ticket = $this->ticket();
590
+			if ($ticket instanceof EE_Ticket) {
591
+				$datetime = $ticket->first_datetime();
592
+				if ($datetime instanceof EE_Datetime) {
593
+					return $datetime;
594
+				}
595
+			}
596
+		}
597
+		return null;
598
+	}
599
+
600
+
601
+	/**
602
+	 * Gets the event's name that's related to the ticket, if this is for
603
+	 * a ticket
604
+	 *
605
+	 * @return string
606
+	 * @throws EE_Error
607
+	 */
608
+	public function ticket_event_name()
609
+	{
610
+		$event_name = esc_html__('Unknown', 'event_espresso');
611
+		$event = $this->ticket_event();
612
+		if ($event instanceof EE_Event) {
613
+			$event_name = $event->name();
614
+		}
615
+		return $event_name;
616
+	}
617
+
618
+
619
+	/**
620
+	 * Gets the event that's related to the ticket, if this line item represents a ticket.
621
+	 *
622
+	 * @return EE_Event|null
623
+	 * @throws EE_Error
624
+	 */
625
+	public function ticket_event()
626
+	{
627
+		$event = null;
628
+		$ticket = $this->ticket();
629
+		if ($ticket instanceof EE_Ticket) {
630
+			$datetime = $ticket->first_datetime();
631
+			if ($datetime instanceof EE_Datetime) {
632
+				$event = $datetime->event();
633
+			}
634
+		}
635
+		return $event;
636
+	}
637
+
638
+
639
+	/**
640
+	 * Gets the first datetime for this lien item, assuming it's for a ticket
641
+	 *
642
+	 * @param string $date_format
643
+	 * @param string $time_format
644
+	 * @return string
645
+	 * @throws EE_Error
646
+	 */
647
+	public function ticket_datetime_start($date_format = '', $time_format = '')
648
+	{
649
+		$first_datetime_string = esc_html__('Unknown', 'event_espresso');
650
+		$datetime = $this->get_ticket_datetime();
651
+		if ($datetime) {
652
+			$first_datetime_string = $datetime->start_date_and_time($date_format, $time_format);
653
+		}
654
+		return $first_datetime_string;
655
+	}
656
+
657
+
658
+	/**
659
+	 * Adds the line item as a child to this line item. If there is another child line
660
+	 * item with the same LIN_code, it is overwritten by this new one
661
+	 *
662
+	 * @param EEI_Line_Item $line_item
663
+	 * @param bool          $set_order
664
+	 * @return bool success
665
+	 * @throws EE_Error
666
+	 */
667
+	public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true)
668
+	{
669
+		// should we calculate the LIN_order for this line item ?
670
+		if ($set_order || $line_item->order() === null) {
671
+			$line_item->set_order(count($this->children()));
672
+		}
673
+		if ($this->ID()) {
674
+			// check for any duplicate line items (with the same code), if so, this replaces it
675
+			$line_item_with_same_code = $this->get_child_line_item($line_item->code());
676
+			if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) {
677
+				$this->delete_child_line_item($line_item_with_same_code->code());
678
+			}
679
+			$line_item->set_parent_ID($this->ID());
680
+			if ($this->TXN_ID()) {
681
+				$line_item->set_TXN_ID($this->TXN_ID());
682
+			}
683
+			return $line_item->save();
684
+		}
685
+		$this->_children[ $line_item->code() ] = $line_item;
686
+		if ($line_item->parent() !== $this) {
687
+			$line_item->set_parent($this);
688
+		}
689
+		return true;
690
+	}
691
+
692
+
693
+	/**
694
+	 * Similar to EE_Base_Class::_add_relation_to, except this isn't a normal relation.
695
+	 * If this line item is saved to the DB, this is just a wrapper for set_parent_ID() and save()
696
+	 * However, if this line item is NOT saved to the DB, this just caches the parent on
697
+	 * the EE_Line_Item::_parent property.
698
+	 *
699
+	 * @param EE_Line_Item $line_item
700
+	 * @throws EE_Error
701
+	 */
702
+	public function set_parent($line_item)
703
+	{
704
+		if ($this->ID()) {
705
+			if (! $line_item->ID()) {
706
+				$line_item->save();
707
+			}
708
+			$this->set_parent_ID($line_item->ID());
709
+			$this->save();
710
+		} else {
711
+			$this->_parent = $line_item;
712
+			$this->set_parent_ID($line_item->ID());
713
+		}
714
+	}
715
+
716
+
717
+	/**
718
+	 * Gets the child line item as specified by its code. Because this returns an object (by reference)
719
+	 * you can modify this child line item and the parent (this object) can know about them
720
+	 * because it also has a reference to that line item
721
+	 *
722
+	 * @param string $code
723
+	 * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
724
+	 * @throws EE_Error
725
+	 */
726
+	public function get_child_line_item($code)
727
+	{
728
+		if ($this->ID()) {
729
+			return $this->get_model()->get_one(
730
+				array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code))
731
+			);
732
+		}
733
+		return isset($this->_children[ $code ])
734
+			? $this->_children[ $code ]
735
+			: null;
736
+	}
737
+
738
+
739
+	/**
740
+	 * Returns how many items are deleted (or, if this item has not been saved ot the DB yet, just how many it HAD
741
+	 * cached on it)
742
+	 *
743
+	 * @return int
744
+	 * @throws EE_Error
745
+	 */
746
+	public function delete_children_line_items()
747
+	{
748
+		if ($this->ID()) {
749
+			return $this->get_model()->delete(array(array('LIN_parent' => $this->ID())));
750
+		}
751
+		$count = count($this->_children);
752
+		$this->_children = array();
753
+		return $count;
754
+	}
755
+
756
+
757
+	/**
758
+	 * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line
759
+	 * HAS NOT been saved to the DB, removes the child line item with index $code.
760
+	 * Also searches through the child's children for a matching line item. However, once a line item has been found
761
+	 * and deleted, stops searching (so if there are line items with duplicate codes, only the first one found will be
762
+	 * deleted)
763
+	 *
764
+	 * @param string $code
765
+	 * @param bool   $stop_search_once_found
766
+	 * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to
767
+	 *             the DB yet)
768
+	 * @throws EE_Error
769
+	 */
770
+	public function delete_child_line_item($code, $stop_search_once_found = true)
771
+	{
772
+		if ($this->ID()) {
773
+			$items_deleted = 0;
774
+			if ($this->code() === $code) {
775
+				$items_deleted += EEH_Line_Item::delete_all_child_items($this);
776
+				$items_deleted += (int) $this->delete();
777
+				if ($stop_search_once_found) {
778
+					return $items_deleted;
779
+				}
780
+			}
781
+			foreach ($this->children() as $child_line_item) {
782
+				$items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found);
783
+			}
784
+			return $items_deleted;
785
+		}
786
+		if (isset($this->_children[ $code ])) {
787
+			unset($this->_children[ $code ]);
788
+			return 1;
789
+		}
790
+		return 0;
791
+	}
792
+
793
+
794
+	/**
795
+	 * If this line item is in the database, is of the type subtotal, and
796
+	 * has no children, why do we have it? It should be deleted so this function
797
+	 * does that
798
+	 *
799
+	 * @return boolean
800
+	 * @throws EE_Error
801
+	 */
802
+	public function delete_if_childless_subtotal()
803
+	{
804
+		if ($this->ID() && $this->type() === EEM_Line_Item::type_sub_total && ! $this->children()) {
805
+			return $this->delete();
806
+		}
807
+		return false;
808
+	}
809
+
810
+
811
+	/**
812
+	 * Creates a code and returns a string. doesn't assign the code to this model object
813
+	 *
814
+	 * @return string
815
+	 * @throws EE_Error
816
+	 */
817
+	public function generate_code()
818
+	{
819
+		// each line item in the cart requires a unique identifier
820
+		return md5($this->get('OBJ_type') . $this->get('OBJ_ID') . microtime());
821
+	}
822
+
823
+
824
+	/**
825
+	 * @return bool
826
+	 * @throws EE_Error
827
+	 */
828
+	public function is_tax()
829
+	{
830
+		return $this->type() === EEM_Line_Item::type_tax;
831
+	}
832
+
833
+
834
+	/**
835
+	 * @return bool
836
+	 * @throws EE_Error
837
+	 */
838
+	public function is_tax_sub_total()
839
+	{
840
+		return $this->type() === EEM_Line_Item::type_tax_sub_total;
841
+	}
842
+
843
+
844
+	/**
845
+	 * @return bool
846
+	 * @throws EE_Error
847
+	 */
848
+	public function is_line_item()
849
+	{
850
+		return $this->type() === EEM_Line_Item::type_line_item;
851
+	}
852
+
853
+
854
+	/**
855
+	 * @return bool
856
+	 * @throws EE_Error
857
+	 */
858
+	public function is_sub_line_item()
859
+	{
860
+		return $this->type() === EEM_Line_Item::type_sub_line_item;
861
+	}
862
+
863
+
864
+	/**
865
+	 * @return bool
866
+	 * @throws EE_Error
867
+	 */
868
+	public function is_sub_total()
869
+	{
870
+		return $this->type() === EEM_Line_Item::type_sub_total;
871
+	}
872
+
873
+
874
+	/**
875
+	 * Whether or not this line item is a cancellation line item
876
+	 *
877
+	 * @return boolean
878
+	 * @throws EE_Error
879
+	 */
880
+	public function is_cancellation()
881
+	{
882
+		return EEM_Line_Item::type_cancellation === $this->type();
883
+	}
884
+
885
+
886
+	/**
887
+	 * @return bool
888
+	 * @throws EE_Error
889
+	 */
890
+	public function is_total()
891
+	{
892
+		return $this->type() === EEM_Line_Item::type_total;
893
+	}
894
+
895
+
896
+	/**
897
+	 * @return bool
898
+	 * @throws EE_Error
899
+	 */
900
+	public function is_cancelled()
901
+	{
902
+		return $this->type() === EEM_Line_Item::type_cancellation;
903
+	}
904
+
905
+
906
+	/**
907
+	 * @return string like '2, 004.00', formatted according to the localized currency
908
+	 * @throws EE_Error
909
+	 */
910
+	public function unit_price_no_code()
911
+	{
912
+		return $this->get_pretty('LIN_unit_price', 'no_currency_code');
913
+	}
914
+
915
+
916
+	/**
917
+	 * @return string like '2, 004.00', formatted according to the localized currency
918
+	 * @throws EE_Error
919
+	 */
920
+	public function total_no_code()
921
+	{
922
+		return $this->get_pretty('LIN_total', 'no_currency_code');
923
+	}
924
+
925
+
926
+	/**
927
+	 * Gets the final total on this item, taking taxes into account.
928
+	 * Has the side-effect of setting the sub-total as it was just calculated.
929
+	 * If this is used on a grand-total line item, also updates the transaction's
930
+	 * TXN_total (provided this line item is allowed to persist, otherwise we don't
931
+	 * want to change a persistable transaction with info from a non-persistent line item)
932
+	 *
933
+	 * @return float
934
+	 * @throws EE_Error
935
+	 * @throws InvalidArgumentException
936
+	 * @throws InvalidInterfaceException
937
+	 * @throws InvalidDataTypeException
938
+	 */
939
+	public function recalculate_total_including_taxes()
940
+	{
941
+		$pre_tax_total = $this->recalculate_pre_tax_total();
942
+		$tax_total = $this->recalculate_taxes_and_tax_total();
943
+		$total = $pre_tax_total + $tax_total;
944
+		// no negative totals plz
945
+		$total = max($total, 0);
946
+		$this->set_total($total);
947
+		// only update the related transaction's total
948
+		// if we intend to save this line item and its a grand total
949
+		if ($this->allow_persist() && $this->type() === EEM_Line_Item::type_total
950
+			&& $this->transaction()
951
+			   instanceof
952
+			   EE_Transaction
953
+		) {
954
+			$this->transaction()->set_total($total);
955
+			if ($this->transaction()->ID()) {
956
+				$this->transaction()->save();
957
+			}
958
+		}
959
+		$this->maybe_save();
960
+		return $total;
961
+	}
962
+
963
+
964
+	/**
965
+	 * Recursively goes through all the children and recalculates sub-totals EXCEPT for
966
+	 * tax-sub-totals (they're a an odd beast). Updates the 'total' on each line item according to either its
967
+	 * unit price * quantity or the total of all its children EXCEPT when we're only calculating the taxable total and
968
+	 * when this is called on the grand total
969
+	 *
970
+	 * @return float
971
+	 * @throws InvalidArgumentException
972
+	 * @throws InvalidInterfaceException
973
+	 * @throws InvalidDataTypeException
974
+	 * @throws EE_Error
975
+	 */
976
+	public function recalculate_pre_tax_total()
977
+	{
978
+		$total = 0;
979
+		$my_children = $this->children();
980
+		$has_children = ! empty($my_children);
981
+		if ($has_children && $this->is_line_item()) {
982
+			$total = $this->_recalculate_pretax_total_for_line_item($total, $my_children);
983
+		} elseif (! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) {
984
+			$total = $this->unit_price() * $this->quantity();
985
+		} elseif ($this->is_sub_total() || $this->is_total()) {
986
+			$total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children);
987
+		} elseif ($this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled()) {
988
+			// completely ignore tax totals, tax sub-totals, and cancelled line items, when calculating the pre-tax-total
989
+			return 0;
990
+		}
991
+		// ensure all non-line items and non-sub-line-items have a quantity of 1 (except for Events)
992
+		if (! $this->is_line_item() && ! $this->is_sub_line_item() && ! $this->is_cancellation()
993
+		) {
994
+			if ($this->OBJ_type() !== 'Event') {
995
+				$this->set_quantity(1);
996
+			}
997
+			if (! $this->is_percent()) {
998
+				$this->set_unit_price($total);
999
+			}
1000
+		}
1001
+		// we don't want to bother saving grand totals, because that needs to factor in taxes anyways
1002
+		// so it ought to be
1003
+		if (! $this->is_total()) {
1004
+			$this->set_total($total);
1005
+			// if not a percent line item, make sure we keep the unit price in sync
1006
+			if ($has_children
1007
+				&& $this->is_line_item()
1008
+				&& ! $this->is_percent()
1009
+			) {
1010
+				if ($this->quantity() === 0) {
1011
+					$new_unit_price = 0;
1012
+				} else {
1013
+					$new_unit_price = $this->total() / $this->quantity();
1014
+				}
1015
+				$this->set_unit_price($new_unit_price);
1016
+			}
1017
+			$this->maybe_save();
1018
+		}
1019
+		return $total;
1020
+	}
1021
+
1022
+
1023
+	/**
1024
+	 * Calculates the pretax total when this line item is a subtotal or total line item.
1025
+	 * Basically does a sum-then-round approach (ie, any percent line item that are children
1026
+	 * will calculate their total based on the un-rounded total we're working with so far, and
1027
+	 * THEN round the result; instead of rounding as we go like with sub-line-items)
1028
+	 *
1029
+	 * @param float          $calculated_total_so_far
1030
+	 * @param EE_Line_Item[] $my_children
1031
+	 * @return float
1032
+	 * @throws InvalidArgumentException
1033
+	 * @throws InvalidInterfaceException
1034
+	 * @throws InvalidDataTypeException
1035
+	 * @throws EE_Error
1036
+	 */
1037
+	protected function _recalculate_pretax_total_for_subtotal($calculated_total_so_far, $my_children = null)
1038
+	{
1039
+		if ($my_children === null) {
1040
+			$my_children = $this->children();
1041
+		}
1042
+		$subtotal_quantity = 0;
1043
+		// get the total of all its children
1044
+		foreach ($my_children as $child_line_item) {
1045
+			if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) {
1046
+				// percentage line items are based on total so far
1047
+				if ($child_line_item->is_percent()) {
1048
+					// round as we go so that the line items add up ok
1049
+					$percent_total = round(
1050
+						$calculated_total_so_far * $child_line_item->percent() / 100,
1051
+						EE_Registry::instance()->CFG->currency->dec_plc
1052
+					);
1053
+					$child_line_item->set_total($percent_total);
1054
+					// so far all percent line items should have a quantity of 1
1055
+					// (ie, no double percent discounts. Although that might be requested someday)
1056
+					$child_line_item->set_quantity(1);
1057
+					$child_line_item->maybe_save();
1058
+					$calculated_total_so_far += $percent_total;
1059
+				} else {
1060
+					// verify flat sub-line-item quantities match their parent
1061
+					if ($child_line_item->is_sub_line_item()) {
1062
+						$child_line_item->set_quantity($this->quantity());
1063
+					}
1064
+					$calculated_total_so_far += $child_line_item->recalculate_pre_tax_total();
1065
+					$subtotal_quantity += $child_line_item->quantity();
1066
+				}
1067
+			}
1068
+		}
1069
+		if ($this->is_sub_total()) {
1070
+			// no negative totals plz
1071
+			$calculated_total_so_far = max($calculated_total_so_far, 0);
1072
+			$subtotal_quantity = $subtotal_quantity > 0 ? 1 : 0;
1073
+			$this->set_quantity($subtotal_quantity);
1074
+			$this->maybe_save();
1075
+		}
1076
+		return $calculated_total_so_far;
1077
+	}
1078
+
1079
+
1080
+	/**
1081
+	 * Calculates the pretax total for a normal line item, in a round-then-sum approach
1082
+	 * (where each sub-line-item is applied to the base price for the line item
1083
+	 * and the result is immediately rounded, rather than summing all the sub-line-items
1084
+	 * then rounding, like we do when recalculating pretax totals on totals and subtotals).
1085
+	 *
1086
+	 * @param float          $calculated_total_so_far
1087
+	 * @param EE_Line_Item[] $my_children
1088
+	 * @return float
1089
+	 * @throws InvalidArgumentException
1090
+	 * @throws InvalidInterfaceException
1091
+	 * @throws InvalidDataTypeException
1092
+	 * @throws EE_Error
1093
+	 */
1094
+	protected function _recalculate_pretax_total_for_line_item($calculated_total_so_far, $my_children = null)
1095
+	{
1096
+		if ($my_children === null) {
1097
+			$my_children = $this->children();
1098
+		}
1099
+		// we need to keep track of the running total for a single item,
1100
+		// because we need to round as we go
1101
+		$unit_price_for_total = 0;
1102
+		$quantity_for_total = 1;
1103
+		// get the total of all its children
1104
+		foreach ($my_children as $child_line_item) {
1105
+			if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) {
1106
+				if ($child_line_item->is_percent()) {
1107
+					// it should be the unit-price-so-far multiplied by teh percent multiplied by the quantity
1108
+					// not total multiplied by percent, because that ignores rounding along-the-way
1109
+					$percent_unit_price = round(
1110
+						$unit_price_for_total * $child_line_item->percent() / 100,
1111
+						EE_Registry::instance()->CFG->currency->dec_plc
1112
+					);
1113
+					$percent_total = $percent_unit_price * $quantity_for_total;
1114
+					$child_line_item->set_total($percent_total);
1115
+					// so far all percent line items should have a quantity of 1
1116
+					// (ie, no double percent discounts. Although that might be requested someday)
1117
+					$child_line_item->set_quantity(1);
1118
+					$child_line_item->maybe_save();
1119
+					$calculated_total_so_far += $percent_total;
1120
+					$unit_price_for_total += $percent_unit_price;
1121
+				} else {
1122
+					// verify flat sub-line-item quantities match their parent
1123
+					if ($child_line_item->is_sub_line_item()) {
1124
+						$child_line_item->set_quantity($this->quantity());
1125
+					}
1126
+					$quantity_for_total = $child_line_item->quantity();
1127
+					$calculated_total_so_far += $child_line_item->recalculate_pre_tax_total();
1128
+					$unit_price_for_total += $child_line_item->unit_price();
1129
+				}
1130
+			}
1131
+		}
1132
+		return $calculated_total_so_far;
1133
+	}
1134
+
1135
+
1136
+	/**
1137
+	 * Recalculates the total on each individual tax (based on a recalculation of the pre-tax total), sets
1138
+	 * the totals on each tax calculated, and returns the final tax total. Re-saves tax line items
1139
+	 * and tax sub-total if already in the DB
1140
+	 *
1141
+	 * @return float
1142
+	 * @throws EE_Error
1143
+	 */
1144
+	public function recalculate_taxes_and_tax_total()
1145
+	{
1146
+		// get all taxes
1147
+		$taxes = $this->tax_descendants();
1148
+		// calculate the pretax total
1149
+		$taxable_total = $this->taxable_total();
1150
+		$tax_total = 0;
1151
+		foreach ($taxes as $tax) {
1152
+			$total_on_this_tax = $taxable_total * $tax->percent() / 100;
1153
+			// remember the total on this line item
1154
+			$tax->set_total($total_on_this_tax);
1155
+			$tax->maybe_save();
1156
+			$tax_total += $tax->total();
1157
+		}
1158
+		$this->_recalculate_tax_sub_total();
1159
+		return $tax_total;
1160
+	}
1161
+
1162
+
1163
+	/**
1164
+	 * Simply forces all the tax-sub-totals to recalculate. Assumes the taxes have been calculated
1165
+	 *
1166
+	 * @return void
1167
+	 * @throws EE_Error
1168
+	 */
1169
+	private function _recalculate_tax_sub_total()
1170
+	{
1171
+		if ($this->is_tax_sub_total()) {
1172
+			$total = 0;
1173
+			$total_percent = 0;
1174
+			// simply loop through all its children (which should be taxes) and sum their total
1175
+			foreach ($this->children() as $child_tax) {
1176
+				if ($child_tax instanceof EE_Line_Item) {
1177
+					$total += $child_tax->total();
1178
+					$total_percent += $child_tax->percent();
1179
+				}
1180
+			}
1181
+			$this->set_total($total);
1182
+			$this->set_percent($total_percent);
1183
+			$this->maybe_save();
1184
+		} elseif ($this->is_total()) {
1185
+			foreach ($this->children() as $maybe_tax_subtotal) {
1186
+				if ($maybe_tax_subtotal instanceof EE_Line_Item) {
1187
+					$maybe_tax_subtotal->_recalculate_tax_sub_total();
1188
+				}
1189
+			}
1190
+		}
1191
+	}
1192
+
1193
+
1194
+	/**
1195
+	 * Gets the total tax on this line item. Assumes taxes have already been calculated using
1196
+	 * recalculate_taxes_and_total
1197
+	 *
1198
+	 * @return float
1199
+	 * @throws EE_Error
1200
+	 */
1201
+	public function get_total_tax()
1202
+	{
1203
+		$this->_recalculate_tax_sub_total();
1204
+		$total = 0;
1205
+		foreach ($this->tax_descendants() as $tax_line_item) {
1206
+			if ($tax_line_item instanceof EE_Line_Item) {
1207
+				$total += $tax_line_item->total();
1208
+			}
1209
+		}
1210
+		return $total;
1211
+	}
1212
+
1213
+
1214
+	/**
1215
+	 * Gets the total for all the items purchased only
1216
+	 *
1217
+	 * @return float
1218
+	 * @throws EE_Error
1219
+	 */
1220
+	public function get_items_total()
1221
+	{
1222
+		// by default, let's make sure we're consistent with the existing line item
1223
+		if ($this->is_total()) {
1224
+			$pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal($this);
1225
+			if ($pretax_subtotal_li instanceof EE_Line_Item) {
1226
+				return $pretax_subtotal_li->total();
1227
+			}
1228
+		}
1229
+		$total = 0;
1230
+		foreach ($this->get_items() as $item) {
1231
+			if ($item instanceof EE_Line_Item) {
1232
+				$total += $item->total();
1233
+			}
1234
+		}
1235
+		return $total;
1236
+	}
1237
+
1238
+
1239
+	/**
1240
+	 * Gets all the descendants (ie, children or children of children etc) that
1241
+	 * are of the type 'tax'
1242
+	 *
1243
+	 * @return EE_Line_Item[]
1244
+	 */
1245
+	public function tax_descendants()
1246
+	{
1247
+		return EEH_Line_Item::get_tax_descendants($this);
1248
+	}
1249
+
1250
+
1251
+	/**
1252
+	 * Gets all the real items purchased which are children of this item
1253
+	 *
1254
+	 * @return EE_Line_Item[]
1255
+	 */
1256
+	public function get_items()
1257
+	{
1258
+		return EEH_Line_Item::get_line_item_descendants($this);
1259
+	}
1260
+
1261
+
1262
+	/**
1263
+	 * Returns the amount taxable among this line item's children (or if it has no children,
1264
+	 * how much of it is taxable). Does not recalculate totals or subtotals.
1265
+	 * If the taxable total is negative, (eg, if none of the tickets were taxable,
1266
+	 * but there is a "Taxable" discount), returns 0.
1267
+	 *
1268
+	 * @return float
1269
+	 * @throws EE_Error
1270
+	 */
1271
+	public function taxable_total()
1272
+	{
1273
+		$total = 0;
1274
+		if ($this->children()) {
1275
+			foreach ($this->children() as $child_line_item) {
1276
+				if ($child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) {
1277
+					// if it's a percent item, only take into account the percent
1278
+					// that's taxable too (the taxable total so far)
1279
+					if ($child_line_item->is_percent()) {
1280
+						$total += ($total * $child_line_item->percent() / 100);
1281
+					} else {
1282
+						$total += $child_line_item->total();
1283
+					}
1284
+				} elseif ($child_line_item->type() === EEM_Line_Item::type_sub_total) {
1285
+					$total += $child_line_item->taxable_total();
1286
+				}
1287
+			}
1288
+		}
1289
+		return max($total, 0);
1290
+	}
1291
+
1292
+
1293
+	/**
1294
+	 * Gets the transaction for this line item
1295
+	 *
1296
+	 * @return EE_Base_Class|EE_Transaction
1297
+	 * @throws EE_Error
1298
+	 */
1299
+	public function transaction()
1300
+	{
1301
+		return $this->get_first_related('Transaction');
1302
+	}
1303
+
1304
+
1305
+	/**
1306
+	 * Saves this line item to the DB, and recursively saves its descendants.
1307
+	 * Because there currently is no proper parent-child relation on the model,
1308
+	 * save_this_and_cached() will NOT save the descendants.
1309
+	 * Also sets the transaction on this line item and all its descendants before saving
1310
+	 *
1311
+	 * @param int $txn_id if none is provided, assumes $this->TXN_ID()
1312
+	 * @return int count of items saved
1313
+	 * @throws EE_Error
1314
+	 */
1315
+	public function save_this_and_descendants_to_txn($txn_id = null)
1316
+	{
1317
+		$count = 0;
1318
+		if (! $txn_id) {
1319
+			$txn_id = $this->TXN_ID();
1320
+		}
1321
+		$this->set_TXN_ID($txn_id);
1322
+		$children = $this->children();
1323
+		$count += $this->save()
1324
+			? 1
1325
+			: 0;
1326
+		foreach ($children as $child_line_item) {
1327
+			if ($child_line_item instanceof EE_Line_Item) {
1328
+				$child_line_item->set_parent_ID($this->ID());
1329
+				$count += $child_line_item->save_this_and_descendants_to_txn($txn_id);
1330
+			}
1331
+		}
1332
+		return $count;
1333
+	}
1334
+
1335
+
1336
+	/**
1337
+	 * Saves this line item to the DB, and recursively saves its descendants.
1338
+	 *
1339
+	 * @return int count of items saved
1340
+	 * @throws EE_Error
1341
+	 */
1342
+	public function save_this_and_descendants()
1343
+	{
1344
+		$count = 0;
1345
+		$children = $this->children();
1346
+		$count += $this->save()
1347
+			? 1
1348
+			: 0;
1349
+		foreach ($children as $child_line_item) {
1350
+			if ($child_line_item instanceof EE_Line_Item) {
1351
+				$child_line_item->set_parent_ID($this->ID());
1352
+				$count += $child_line_item->save_this_and_descendants();
1353
+			}
1354
+		}
1355
+		return $count;
1356
+	}
1357
+
1358
+
1359
+	/**
1360
+	 * returns the cancellation line item if this item was cancelled
1361
+	 *
1362
+	 * @return EE_Line_Item[]
1363
+	 * @throws InvalidArgumentException
1364
+	 * @throws InvalidInterfaceException
1365
+	 * @throws InvalidDataTypeException
1366
+	 * @throws ReflectionException
1367
+	 * @throws EE_Error
1368
+	 */
1369
+	public function get_cancellations()
1370
+	{
1371
+		EE_Registry::instance()->load_helper('Line_Item');
1372
+		return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation);
1373
+	}
1374
+
1375
+
1376
+	/**
1377
+	 * If this item has an ID, then this saves it again to update the db
1378
+	 *
1379
+	 * @return int count of items saved
1380
+	 * @throws EE_Error
1381
+	 */
1382
+	public function maybe_save()
1383
+	{
1384
+		if ($this->ID()) {
1385
+			return $this->save();
1386
+		}
1387
+		return false;
1388
+	}
1389
+
1390
+
1391
+	/**
1392
+	 * clears the cached children and parent from the line item
1393
+	 *
1394
+	 * @return void
1395
+	 */
1396
+	public function clear_related_line_item_cache()
1397
+	{
1398
+		$this->_children = array();
1399
+		$this->_parent = null;
1400
+	}
1401
+
1402
+
1403
+	/**
1404
+	 * @param bool $raw
1405
+	 * @return int
1406
+	 * @throws EE_Error
1407
+	 */
1408
+	public function timestamp($raw = false)
1409
+	{
1410
+		return $raw
1411
+			? $this->get_raw('LIN_timestamp')
1412
+			: $this->get('LIN_timestamp');
1413
+	}
1414
+
1415
+
1416
+
1417
+
1418
+	/************************* DEPRECATED *************************/
1419
+	/**
1420
+	 * @deprecated 4.6.0
1421
+	 * @param string $type one of the constants on EEM_Line_Item
1422
+	 * @return EE_Line_Item[]
1423
+	 */
1424
+	protected function _get_descendants_of_type($type)
1425
+	{
1426
+		EE_Error::doing_it_wrong(
1427
+			'EE_Line_Item::_get_descendants_of_type()',
1428
+			__('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'),
1429
+			'4.6.0'
1430
+		);
1431
+		return EEH_Line_Item::get_descendants_of_type($this, $type);
1432
+	}
1433
+
1434
+
1435
+	/**
1436
+	 * @deprecated 4.6.0
1437
+	 * @param string $type like one of the EEM_Line_Item::type_*
1438
+	 * @return EE_Line_Item
1439
+	 */
1440
+	public function get_nearest_descendant_of_type($type)
1441
+	{
1442
+		EE_Error::doing_it_wrong(
1443
+			'EE_Line_Item::get_nearest_descendant_of_type()',
1444
+			__('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'),
1445
+			'4.6.0'
1446
+		);
1447
+		return EEH_Line_Item::get_nearest_descendant_of_type($this, $type);
1448
+	}
1449 1449
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
     protected function __construct($fieldValues = array(), $bydb = false, $timezone = '')
73 73
     {
74 74
         parent::__construct($fieldValues, $bydb, $timezone);
75
-        if (! $this->get('LIN_code')) {
75
+        if ( ! $this->get('LIN_code')) {
76 76
             $this->set_code($this->generate_code());
77 77
         }
78 78
     }
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
     public function name()
124 124
     {
125 125
         $name = $this->get('LIN_name');
126
-        if (! $name) {
126
+        if ( ! $name) {
127 127
             $name = ucwords(str_replace('-', ' ', $this->type()));
128 128
         }
129 129
         return $name;
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
      */
289 289
     public function set_unit_price($unit_price)
290 290
     {
291
-        if($this->type() !== EEM_Line_Item::type_sub_line_item) { 
291
+        if ($this->type() !== EEM_Line_Item::type_sub_line_item) { 
292 292
             $unit_price = EEH_Money::round_for_currency($unit_price, EE_Config::instance()->currency->code);
293 293
         } 
294 294
         $this->set('LIN_unit_price', $unit_price);
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
      */
375 375
     public function set_total($total)
376 376
     {
377
-        if($this->type() !== EEM_Line_Item::type_sub_line_item) { 
377
+        if ($this->type() !== EEM_Line_Item::type_sub_line_item) { 
378 378
             $total = EEH_Money::round_for_currency($total, EE_Config::instance()->currency->code); 
379 379
         } 
380 380
         $this->set('LIN_total', $total);
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
                 )
487 487
             );
488 488
         }
489
-        if (! is_array($this->_children)) {
489
+        if ( ! is_array($this->_children)) {
490 490
             $this->_children = array();
491 491
         }
492 492
         return $this->_children;
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
             }
683 683
             return $line_item->save();
684 684
         }
685
-        $this->_children[ $line_item->code() ] = $line_item;
685
+        $this->_children[$line_item->code()] = $line_item;
686 686
         if ($line_item->parent() !== $this) {
687 687
             $line_item->set_parent($this);
688 688
         }
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
     public function set_parent($line_item)
703 703
     {
704 704
         if ($this->ID()) {
705
-            if (! $line_item->ID()) {
705
+            if ( ! $line_item->ID()) {
706 706
                 $line_item->save();
707 707
             }
708 708
             $this->set_parent_ID($line_item->ID());
@@ -730,8 +730,8 @@  discard block
 block discarded – undo
730 730
                 array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code))
731 731
             );
732 732
         }
733
-        return isset($this->_children[ $code ])
734
-            ? $this->_children[ $code ]
733
+        return isset($this->_children[$code])
734
+            ? $this->_children[$code]
735 735
             : null;
736 736
     }
737 737
 
@@ -783,8 +783,8 @@  discard block
 block discarded – undo
783 783
             }
784 784
             return $items_deleted;
785 785
         }
786
-        if (isset($this->_children[ $code ])) {
787
-            unset($this->_children[ $code ]);
786
+        if (isset($this->_children[$code])) {
787
+            unset($this->_children[$code]);
788 788
             return 1;
789 789
         }
790 790
         return 0;
@@ -817,7 +817,7 @@  discard block
 block discarded – undo
817 817
     public function generate_code()
818 818
     {
819 819
         // each line item in the cart requires a unique identifier
820
-        return md5($this->get('OBJ_type') . $this->get('OBJ_ID') . microtime());
820
+        return md5($this->get('OBJ_type').$this->get('OBJ_ID').microtime());
821 821
     }
822 822
 
823 823
 
@@ -980,7 +980,7 @@  discard block
 block discarded – undo
980 980
         $has_children = ! empty($my_children);
981 981
         if ($has_children && $this->is_line_item()) {
982 982
             $total = $this->_recalculate_pretax_total_for_line_item($total, $my_children);
983
-        } elseif (! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) {
983
+        } elseif ( ! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) {
984 984
             $total = $this->unit_price() * $this->quantity();
985 985
         } elseif ($this->is_sub_total() || $this->is_total()) {
986 986
             $total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children);
@@ -989,18 +989,18 @@  discard block
 block discarded – undo
989 989
             return 0;
990 990
         }
991 991
         // ensure all non-line items and non-sub-line-items have a quantity of 1 (except for Events)
992
-        if (! $this->is_line_item() && ! $this->is_sub_line_item() && ! $this->is_cancellation()
992
+        if ( ! $this->is_line_item() && ! $this->is_sub_line_item() && ! $this->is_cancellation()
993 993
         ) {
994 994
             if ($this->OBJ_type() !== 'Event') {
995 995
                 $this->set_quantity(1);
996 996
             }
997
-            if (! $this->is_percent()) {
997
+            if ( ! $this->is_percent()) {
998 998
                 $this->set_unit_price($total);
999 999
             }
1000 1000
         }
1001 1001
         // we don't want to bother saving grand totals, because that needs to factor in taxes anyways
1002 1002
         // so it ought to be
1003
-        if (! $this->is_total()) {
1003
+        if ( ! $this->is_total()) {
1004 1004
             $this->set_total($total);
1005 1005
             // if not a percent line item, make sure we keep the unit price in sync
1006 1006
             if ($has_children
@@ -1315,7 +1315,7 @@  discard block
 block discarded – undo
1315 1315
     public function save_this_and_descendants_to_txn($txn_id = null)
1316 1316
     {
1317 1317
         $count = 0;
1318
-        if (! $txn_id) {
1318
+        if ( ! $txn_id) {
1319 1319
             $txn_id = $this->TXN_ID();
1320 1320
         }
1321 1321
         $this->set_TXN_ID($txn_id);
Please login to merge, or discard this patch.
core/db_models/EEM_Line_Item.model.php 1 patch
Indentation   +436 added lines, -436 removed lines patch added patch discarded remove patch
@@ -32,443 +32,443 @@
 block discarded – undo
32 32
 class EEM_Line_Item extends EEM_Base
33 33
 {
34 34
 
35
-    /**
36
-     * Tax sub-total is just the total of all the taxes, which should be children
37
-     * of this line item. There should only ever be one tax sub-total, and it should
38
-     * be a direct child of. Its quantity and LIN_unit_price = 1.
39
-     */
40
-    const type_tax_sub_total = 'tax-sub-total';
41
-
42
-    /**
43
-     * Tax line items indicate a tax applied to all the taxable line items.
44
-     * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
45
-     * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
46
-     */
47
-    const type_tax = 'tax';
48
-
49
-    /**
50
-     * Indicating individual items purchased, or discounts or surcharges.
51
-     * The sum of all the regular line items  plus the tax items should equal
52
-     * the grand total.
53
-     * Possible children are sub-line-items and cancellations.
54
-     * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children
55
-     * LIN_totals. Its LIN_percent = 0.
56
-     * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1).
57
-     * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1.
58
-     */
59
-    const type_line_item = 'line-item';
60
-
61
-    /**
62
-     * Line item indicating all the factors that make a single line item.
63
-     * Sub-line items should have NO children line items.
64
-     * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's
65
-     * contribution towards the price of ONE of their parent items, and its LIN_total should be
66
-     *  = LIN_quantity * LIN_unit_price. Its LIN_percent = 0.
67
-     * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should
68
-     * = LIN_percent / 100 * sum of lower-priority sibling line items..
69
-     */
70
-    const type_sub_line_item = 'sub-item';
71
-
72
-    /**
73
-     * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal).
74
-     * Direct children should be event subtotals.
75
-     * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals.
76
-     *
77
-     */
78
-    const type_sub_total = 'sub-total';
79
-
80
-    /**
81
-     * Line item for the grand total of an order. Its direct children
82
-     * should be tax subtotals and (pre-tax) subtotals, and possibly a regular line item
83
-     * indicating a transaction-wide discount/surcharge. Should have a quantity of 1, a LIN_total and LIN_unit_price of
84
-     * the entire order's mount.
85
-     */
86
-    const type_total = 'total';
87
-
88
-    /**
89
-     * When a line item is cancelled, a sub-line-item of type 'cancellation'
90
-     * should be created, indicating the quantity that were cancelled
91
-     * (because a line item could have a quantity of 1, and its cancellation item
92
-     * could be for 3, indicating that originally 4 were purchased, but 3 have been
93
-     * cancelled, and only one remains).
94
-     * When items are refunded, a cancellation line item should be made, which points
95
-     * to teh payment model object which actually refunded the payment.
96
-     * Cancellations should NOT have any children line items; the should NOT affect
97
-     * any calculations, and are only meant as a record that cancellations have occurred.
98
-     * Their LIN_percent should be 0.
99
-     */
100
-    const type_cancellation = 'cancellation';
101
-
102
-    // private instance of the EEM_Line_Item object
103
-    protected static $_instance = null;
104
-
105
-
106
-    /**
107
-     *        private constructor to prevent direct creation
108
-     * @Constructor
109
-     * @access protected
110
-     * @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)
111
-     * @return \EEM_Line_Item
112
-     */
113
-    protected function __construct($timezone)
114
-    {
115
-        $this->singular_item = __('Line Item', 'event_espresso');
116
-        $this->plural_item = __('Line Items', 'event_espresso');
117
-
118
-        $this->_tables = array(
119
-            'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID')
120
-        );
121
-        $line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event'));
122
-        $this->_fields = array(
123
-            'Line_Item' => array(
124
-                'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")),
125
-                'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), true),
126
-                'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), true, null, 'Transaction'),
127
-                'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), false, ''),
128
-                'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), true),
129
-                'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), false, 0, false),
130
-                'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), false, 0),
131
-                'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), false, false),
132
-                'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), false, 1),
133
-                'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), false, 0, false),
134
-                'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), true, 1),
135
-                'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), true, null),
136
-                'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), false, 'line-item', array(
137
-                        self::type_line_item => __("Line Item", "event_espresso"),
138
-                        self::type_sub_line_item => __("Sub-Item", "event_espresso"),
139
-                        self::type_sub_total => __("Subtotal", "event_espresso"),
140
-                        self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"),
141
-                        self::type_tax => __("Tax", "event_espresso"),
142
-                        self::type_total => __("Total", "event_espresso"),
143
-                        self::type_cancellation => __('Cancellation', 'event_espresso')
144
-                    )),
145
-                'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), true, null, $line_items_can_be_for),
146
-                'OBJ_type' => new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), true, null, $line_items_can_be_for),
147
-                'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
148
-            )
149
-        );
150
-        $this->_model_relations = array(
151
-            'Transaction' => new EE_Belongs_To_Relation(),
152
-            'Ticket' => new EE_Belongs_To_Any_Relation(),
153
-            'Price' => new EE_Belongs_To_Any_Relation(),
154
-            'Event' => new EE_Belongs_To_Any_Relation()
155
-        );
156
-        $this->_model_chain_to_wp_user = 'Transaction.Registration.Event';
157
-        $this->_caps_slug = 'transactions';
158
-        parent::__construct($timezone);
159
-    }
160
-
161
-
162
-    /**
163
-     * Gets all the line items for this transaction of the given type
164
-     * @param string $line_item_type like one of EEM_Line_Item::type_*
165
-     * @param EE_Transaction|int $transaction
166
-     * @return EE_Line_Item[]
167
-     */
168
-    public function get_all_of_type_for_transaction($line_item_type, $transaction)
169
-    {
170
-        $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
171
-        return $this->get_all(array(array(
172
-            'LIN_type' => $line_item_type,
173
-            'TXN_ID' => $transaction
174
-        )));
175
-    }
176
-
177
-
178
-    /**
179
-     * Gets all line items unrelated to tickets that are normal line items
180
-     * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category)
181
-     * @param EE_Transaction|int $transaction
182
-     * @return EE_Line_Item[]
183
-     */
184
-    public function get_all_non_ticket_line_items_for_transaction($transaction)
185
-    {
186
-        $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
187
-        return $this->get_all(array(array(
188
-            'LIN_type' => self::type_line_item,
189
-            'TXN_ID' => $transaction,
190
-            'OR' => array(
191
-                'OBJ_type*notticket' => array('!=', 'Ticket'),
192
-                'OBJ_type*null' => array('IS_NULL'))
193
-        )));
194
-    }
195
-
196
-    /**
197
-     * Deletes line items with no transaction who have passed the transaction cutoff time.
198
-     * This needs to be very efficient
199
-     * because if there are spam bots afoot there will be LOTS of line items
200
-     * @return int count of how many deleted
201
-     */
202
-    public function delete_line_items_with_no_transaction()
203
-    {
204
-        /** @type WPDB $wpdb */
205
-        global $wpdb;
206
-        $time_to_leave_alone = apply_filters(
207
-            'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone',
208
-            WEEK_IN_SECONDS
209
-        );
210
-        $query = $wpdb->prepare(
211
-            'DELETE li
35
+	/**
36
+	 * Tax sub-total is just the total of all the taxes, which should be children
37
+	 * of this line item. There should only ever be one tax sub-total, and it should
38
+	 * be a direct child of. Its quantity and LIN_unit_price = 1.
39
+	 */
40
+	const type_tax_sub_total = 'tax-sub-total';
41
+
42
+	/**
43
+	 * Tax line items indicate a tax applied to all the taxable line items.
44
+	 * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
45
+	 * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
46
+	 */
47
+	const type_tax = 'tax';
48
+
49
+	/**
50
+	 * Indicating individual items purchased, or discounts or surcharges.
51
+	 * The sum of all the regular line items  plus the tax items should equal
52
+	 * the grand total.
53
+	 * Possible children are sub-line-items and cancellations.
54
+	 * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children
55
+	 * LIN_totals. Its LIN_percent = 0.
56
+	 * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1).
57
+	 * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1.
58
+	 */
59
+	const type_line_item = 'line-item';
60
+
61
+	/**
62
+	 * Line item indicating all the factors that make a single line item.
63
+	 * Sub-line items should have NO children line items.
64
+	 * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's
65
+	 * contribution towards the price of ONE of their parent items, and its LIN_total should be
66
+	 *  = LIN_quantity * LIN_unit_price. Its LIN_percent = 0.
67
+	 * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should
68
+	 * = LIN_percent / 100 * sum of lower-priority sibling line items..
69
+	 */
70
+	const type_sub_line_item = 'sub-item';
71
+
72
+	/**
73
+	 * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal).
74
+	 * Direct children should be event subtotals.
75
+	 * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals.
76
+	 *
77
+	 */
78
+	const type_sub_total = 'sub-total';
79
+
80
+	/**
81
+	 * Line item for the grand total of an order. Its direct children
82
+	 * should be tax subtotals and (pre-tax) subtotals, and possibly a regular line item
83
+	 * indicating a transaction-wide discount/surcharge. Should have a quantity of 1, a LIN_total and LIN_unit_price of
84
+	 * the entire order's mount.
85
+	 */
86
+	const type_total = 'total';
87
+
88
+	/**
89
+	 * When a line item is cancelled, a sub-line-item of type 'cancellation'
90
+	 * should be created, indicating the quantity that were cancelled
91
+	 * (because a line item could have a quantity of 1, and its cancellation item
92
+	 * could be for 3, indicating that originally 4 were purchased, but 3 have been
93
+	 * cancelled, and only one remains).
94
+	 * When items are refunded, a cancellation line item should be made, which points
95
+	 * to teh payment model object which actually refunded the payment.
96
+	 * Cancellations should NOT have any children line items; the should NOT affect
97
+	 * any calculations, and are only meant as a record that cancellations have occurred.
98
+	 * Their LIN_percent should be 0.
99
+	 */
100
+	const type_cancellation = 'cancellation';
101
+
102
+	// private instance of the EEM_Line_Item object
103
+	protected static $_instance = null;
104
+
105
+
106
+	/**
107
+	 *        private constructor to prevent direct creation
108
+	 * @Constructor
109
+	 * @access protected
110
+	 * @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)
111
+	 * @return \EEM_Line_Item
112
+	 */
113
+	protected function __construct($timezone)
114
+	{
115
+		$this->singular_item = __('Line Item', 'event_espresso');
116
+		$this->plural_item = __('Line Items', 'event_espresso');
117
+
118
+		$this->_tables = array(
119
+			'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID')
120
+		);
121
+		$line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event'));
122
+		$this->_fields = array(
123
+			'Line_Item' => array(
124
+				'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")),
125
+				'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), true),
126
+				'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), true, null, 'Transaction'),
127
+				'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), false, ''),
128
+				'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), true),
129
+				'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), false, 0, false),
130
+				'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), false, 0),
131
+				'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), false, false),
132
+				'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), false, 1),
133
+				'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), false, 0, false),
134
+				'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), true, 1),
135
+				'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), true, null),
136
+				'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), false, 'line-item', array(
137
+						self::type_line_item => __("Line Item", "event_espresso"),
138
+						self::type_sub_line_item => __("Sub-Item", "event_espresso"),
139
+						self::type_sub_total => __("Subtotal", "event_espresso"),
140
+						self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"),
141
+						self::type_tax => __("Tax", "event_espresso"),
142
+						self::type_total => __("Total", "event_espresso"),
143
+						self::type_cancellation => __('Cancellation', 'event_espresso')
144
+					)),
145
+				'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), true, null, $line_items_can_be_for),
146
+				'OBJ_type' => new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), true, null, $line_items_can_be_for),
147
+				'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
148
+			)
149
+		);
150
+		$this->_model_relations = array(
151
+			'Transaction' => new EE_Belongs_To_Relation(),
152
+			'Ticket' => new EE_Belongs_To_Any_Relation(),
153
+			'Price' => new EE_Belongs_To_Any_Relation(),
154
+			'Event' => new EE_Belongs_To_Any_Relation()
155
+		);
156
+		$this->_model_chain_to_wp_user = 'Transaction.Registration.Event';
157
+		$this->_caps_slug = 'transactions';
158
+		parent::__construct($timezone);
159
+	}
160
+
161
+
162
+	/**
163
+	 * Gets all the line items for this transaction of the given type
164
+	 * @param string $line_item_type like one of EEM_Line_Item::type_*
165
+	 * @param EE_Transaction|int $transaction
166
+	 * @return EE_Line_Item[]
167
+	 */
168
+	public function get_all_of_type_for_transaction($line_item_type, $transaction)
169
+	{
170
+		$transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
171
+		return $this->get_all(array(array(
172
+			'LIN_type' => $line_item_type,
173
+			'TXN_ID' => $transaction
174
+		)));
175
+	}
176
+
177
+
178
+	/**
179
+	 * Gets all line items unrelated to tickets that are normal line items
180
+	 * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category)
181
+	 * @param EE_Transaction|int $transaction
182
+	 * @return EE_Line_Item[]
183
+	 */
184
+	public function get_all_non_ticket_line_items_for_transaction($transaction)
185
+	{
186
+		$transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
187
+		return $this->get_all(array(array(
188
+			'LIN_type' => self::type_line_item,
189
+			'TXN_ID' => $transaction,
190
+			'OR' => array(
191
+				'OBJ_type*notticket' => array('!=', 'Ticket'),
192
+				'OBJ_type*null' => array('IS_NULL'))
193
+		)));
194
+	}
195
+
196
+	/**
197
+	 * Deletes line items with no transaction who have passed the transaction cutoff time.
198
+	 * This needs to be very efficient
199
+	 * because if there are spam bots afoot there will be LOTS of line items
200
+	 * @return int count of how many deleted
201
+	 */
202
+	public function delete_line_items_with_no_transaction()
203
+	{
204
+		/** @type WPDB $wpdb */
205
+		global $wpdb;
206
+		$time_to_leave_alone = apply_filters(
207
+			'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone',
208
+			WEEK_IN_SECONDS
209
+		);
210
+		$query = $wpdb->prepare(
211
+			'DELETE li
212 212
 				FROM ' . $this->table() . ' li
213 213
 				LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID
214 214
 				WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s',
215
-            // use GMT time because that's what TXN_timestamps are in
216
-            date('Y-m-d H:i:s', time() - $time_to_leave_alone)
217
-        );
218
-        return $wpdb->query($query);
219
-    }
220
-
221
-
222
-    /**
223
-     * get_line_item_for_transaction_object
224
-     * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket
225
-     *
226
-     * @param int $TXN_ID
227
-     * @param \EE_Base_Class $object
228
-     * @return EE_Line_Item[]
229
-     */
230
-    public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object)
231
-    {
232
-        return $this->get_all(array(array(
233
-            'TXN_ID' => $TXN_ID,
234
-            'OBJ_type' => str_replace('EE_', '', get_class($object)),
235
-            'OBJ_ID' => $object->ID()
236
-        )));
237
-    }
238
-
239
-
240
-    /**
241
-     * get_object_line_items_for_transaction
242
-     * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs
243
-     *
244
-     * @param int $TXN_ID
245
-     * @param string $OBJ_type
246
-     * @param array $OBJ_IDs
247
-     * @return EE_Line_Item[]
248
-     */
249
-    public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array())
250
-    {
251
-        $query_params = array(
252
-            'OBJ_type' => $OBJ_type,
253
-            // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query
254
-            'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs
255
-        );
256
-        if ($TXN_ID) {
257
-            $query_params['TXN_ID'] = $TXN_ID;
258
-        }
259
-        return $this->get_all(array($query_params));
260
-    }
261
-
262
-
263
-    /**
264
-     * get_all_ticket_line_items_for_transaction
265
-     *
266
-     * @param EE_Transaction $transaction
267
-     * @return EE_Line_Item[]
268
-     */
269
-    public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction)
270
-    {
271
-        return $this->get_all(array(
272
-            array(
273
-                'TXN_ID' => $transaction->ID(),
274
-                'OBJ_type' => 'Ticket',
275
-            )
276
-        ));
277
-    }
278
-
279
-
280
-    /**
281
-     * get_ticket_line_item_for_transaction
282
-     *
283
-     * @param int $TXN_ID
284
-     * @param int $TKT_ID
285
-     * @return \EE_Line_Item
286
-     */
287
-    public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID)
288
-    {
289
-        return $this->get_one(array(
290
-            array(
291
-                'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID),
292
-                'OBJ_ID' => $TKT_ID,
293
-                'OBJ_type' => 'Ticket',
294
-            )
295
-        ));
296
-    }
297
-
298
-
299
-    /**
300
-     * get_existing_promotion_line_item
301
-     * searches the cart for existing line items for the specified promotion
302
-     *
303
-     * @since   1.0.0
304
-     *
305
-     * @param EE_Line_Item $parent_line_item
306
-     * @param EE_Promotion $promotion
307
-     * @return EE_Line_Item
308
-     */
309
-    public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion)
310
-    {
311
-        return $this->get_one(array(
312
-            array(
313
-                'TXN_ID' => $parent_line_item->TXN_ID(),
314
-                'LIN_parent' => $parent_line_item->ID(),
315
-                'OBJ_type' => 'Promotion',
316
-                'OBJ_ID' => $promotion->ID()
317
-            )
318
-        ));
319
-    }
320
-
321
-
322
-    /**
323
-     * get_all_promotion_line_items
324
-     * searches the cart for any and all existing promotion line items
325
-     *
326
-     * @since   1.0.0
327
-     *
328
-     * @param EE_Line_Item $parent_line_item
329
-     * @return EE_Line_Item[]
330
-     */
331
-    public function get_all_promotion_line_items(EE_Line_Item $parent_line_item)
332
-    {
333
-        return $this->get_all(array(
334
-            array(
335
-                'TXN_ID' => $parent_line_item->TXN_ID(),
336
-                'LIN_parent' => $parent_line_item->ID(),
337
-                'OBJ_type' => 'Promotion'
338
-            )
339
-        ));
340
-    }
341
-
342
-    /**
343
-     * Gets the registration's corresponding line item.
344
-     * Note: basically does NOT support having multiple line items for a single ticket,
345
-     * which would happen if some of the registrations had a price modifier while others didn't.
346
-     * In order to support that, we'd probably need a LIN_ID on registrations or something.
347
-     * @param EE_Registration $registration
348
-     * @return EE_Line_ITem
349
-     */
350
-    public function get_line_item_for_registration(EE_Registration $registration)
351
-    {
352
-        return $this->get_one($this->line_item_for_registration_query_params($registration));
353
-    }
354
-
355
-    /**
356
-     * Gets the query params used to retrieve a specific line item for the given registration
357
-     * @param EE_Registration $registration
358
-     * @param array $original_query_params any extra query params you'd like to be merged with
359
-     * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
360
-     */
361
-    public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array())
362
-    {
363
-        return array_replace_recursive($original_query_params, array(
364
-            array(
365
-                'OBJ_ID' => $registration->ticket_ID(),
366
-                'OBJ_type' => 'Ticket',
367
-                'TXN_ID' => $registration->transaction_ID()
368
-            )
369
-        ));
370
-    }
371
-
372
-
373
-    /**
374
-     * @return EE_Base_Class[]|EE_Line_Item[]
375
-     * @throws InvalidInterfaceException
376
-     * @throws InvalidDataTypeException
377
-     * @throws EE_Error
378
-     * @throws InvalidArgumentException
379
-     */
380
-    public function get_total_line_items_with_no_transaction()
381
-    {
382
-        return $this->get_total_line_items_for_carts();
383
-    }
384
-
385
-
386
-    /**
387
-     * @return EE_Base_Class[]|EE_Line_Item[]
388
-     * @throws InvalidInterfaceException
389
-     * @throws InvalidDataTypeException
390
-     * @throws EE_Error
391
-     * @throws InvalidArgumentException
392
-     */
393
-    public function get_total_line_items_for_active_carts()
394
-    {
395
-        return $this->get_total_line_items_for_carts(false);
396
-    }
397
-
398
-
399
-    /**
400
-     * @return EE_Base_Class[]|EE_Line_Item[]
401
-     * @throws InvalidInterfaceException
402
-     * @throws InvalidDataTypeException
403
-     * @throws EE_Error
404
-     * @throws InvalidArgumentException
405
-     */
406
-    public function get_total_line_items_for_expired_carts()
407
-    {
408
-        return $this->get_total_line_items_for_carts(true);
409
-    }
410
-
411
-
412
-    /**
413
-     * Returns an array of grand total line items where the TXN_ID is 0.
414
-     * If $expired is set to true, then only line items for expired sessions will be returned.
415
-     * If $expired is set to false, then only line items for active sessions will be returned.
416
-     *
417
-     * @param null $expired
418
-     * @return EE_Base_Class[]|EE_Line_Item[]
419
-     * @throws EE_Error
420
-     * @throws InvalidArgumentException
421
-     * @throws InvalidDataTypeException
422
-     * @throws InvalidInterfaceException
423
-     */
424
-    private function get_total_line_items_for_carts($expired = null)
425
-    {
426
-        $where_params = array(
427
-            'TXN_ID' => 0,
428
-            'LIN_type' => 'total',
429
-        );
430
-        if ($expired !== null) {
431
-            /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
432
-            $session_lifespan = LoaderFactory::getLoader()->getShared(
433
-                'EventEspresso\core\domain\values\session\SessionLifespan'
434
-            );
435
-            $where_params['LIN_timestamp'] = array(
436
-                $expired ? '<=' : '>',
437
-                $session_lifespan->expiration(),
438
-            );
439
-        }
440
-        return $this->get_all(array($where_params));
441
-    }
442
-
443
-
444
-    /**
445
-     * Returns an array of ticket total line items where the TXN_ID is 0
446
-     * AND the timestamp is older than the session lifespan.
447
-     *
448
-     * @param int $timestamp
449
-     * @return EE_Base_Class[]|EE_Line_Item[]
450
-     * @throws EE_Error
451
-     * @throws InvalidArgumentException
452
-     * @throws InvalidDataTypeException
453
-     * @throws InvalidInterfaceException
454
-     */
455
-    public function getTicketLineItemsForExpiredCarts($timestamp = 0)
456
-    {
457
-        if (! absint($timestamp)) {
458
-            /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
459
-            $session_lifespan = LoaderFactory::getLoader()->getShared(
460
-                'EventEspresso\core\domain\values\session\SessionLifespan'
461
-            );
462
-            $timestamp = $session_lifespan->expiration();
463
-        }
464
-        return $this->get_all(
465
-            array(
466
-                array(
467
-                    'TXN_ID'        => 0,
468
-                    'OBJ_type'      => 'Ticket',
469
-                    'LIN_timestamp' => array('<=', $timestamp),
470
-                )
471
-            )
472
-        );
473
-    }
215
+			// use GMT time because that's what TXN_timestamps are in
216
+			date('Y-m-d H:i:s', time() - $time_to_leave_alone)
217
+		);
218
+		return $wpdb->query($query);
219
+	}
220
+
221
+
222
+	/**
223
+	 * get_line_item_for_transaction_object
224
+	 * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket
225
+	 *
226
+	 * @param int $TXN_ID
227
+	 * @param \EE_Base_Class $object
228
+	 * @return EE_Line_Item[]
229
+	 */
230
+	public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object)
231
+	{
232
+		return $this->get_all(array(array(
233
+			'TXN_ID' => $TXN_ID,
234
+			'OBJ_type' => str_replace('EE_', '', get_class($object)),
235
+			'OBJ_ID' => $object->ID()
236
+		)));
237
+	}
238
+
239
+
240
+	/**
241
+	 * get_object_line_items_for_transaction
242
+	 * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs
243
+	 *
244
+	 * @param int $TXN_ID
245
+	 * @param string $OBJ_type
246
+	 * @param array $OBJ_IDs
247
+	 * @return EE_Line_Item[]
248
+	 */
249
+	public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array())
250
+	{
251
+		$query_params = array(
252
+			'OBJ_type' => $OBJ_type,
253
+			// if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query
254
+			'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs
255
+		);
256
+		if ($TXN_ID) {
257
+			$query_params['TXN_ID'] = $TXN_ID;
258
+		}
259
+		return $this->get_all(array($query_params));
260
+	}
261
+
262
+
263
+	/**
264
+	 * get_all_ticket_line_items_for_transaction
265
+	 *
266
+	 * @param EE_Transaction $transaction
267
+	 * @return EE_Line_Item[]
268
+	 */
269
+	public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction)
270
+	{
271
+		return $this->get_all(array(
272
+			array(
273
+				'TXN_ID' => $transaction->ID(),
274
+				'OBJ_type' => 'Ticket',
275
+			)
276
+		));
277
+	}
278
+
279
+
280
+	/**
281
+	 * get_ticket_line_item_for_transaction
282
+	 *
283
+	 * @param int $TXN_ID
284
+	 * @param int $TKT_ID
285
+	 * @return \EE_Line_Item
286
+	 */
287
+	public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID)
288
+	{
289
+		return $this->get_one(array(
290
+			array(
291
+				'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID),
292
+				'OBJ_ID' => $TKT_ID,
293
+				'OBJ_type' => 'Ticket',
294
+			)
295
+		));
296
+	}
297
+
298
+
299
+	/**
300
+	 * get_existing_promotion_line_item
301
+	 * searches the cart for existing line items for the specified promotion
302
+	 *
303
+	 * @since   1.0.0
304
+	 *
305
+	 * @param EE_Line_Item $parent_line_item
306
+	 * @param EE_Promotion $promotion
307
+	 * @return EE_Line_Item
308
+	 */
309
+	public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion)
310
+	{
311
+		return $this->get_one(array(
312
+			array(
313
+				'TXN_ID' => $parent_line_item->TXN_ID(),
314
+				'LIN_parent' => $parent_line_item->ID(),
315
+				'OBJ_type' => 'Promotion',
316
+				'OBJ_ID' => $promotion->ID()
317
+			)
318
+		));
319
+	}
320
+
321
+
322
+	/**
323
+	 * get_all_promotion_line_items
324
+	 * searches the cart for any and all existing promotion line items
325
+	 *
326
+	 * @since   1.0.0
327
+	 *
328
+	 * @param EE_Line_Item $parent_line_item
329
+	 * @return EE_Line_Item[]
330
+	 */
331
+	public function get_all_promotion_line_items(EE_Line_Item $parent_line_item)
332
+	{
333
+		return $this->get_all(array(
334
+			array(
335
+				'TXN_ID' => $parent_line_item->TXN_ID(),
336
+				'LIN_parent' => $parent_line_item->ID(),
337
+				'OBJ_type' => 'Promotion'
338
+			)
339
+		));
340
+	}
341
+
342
+	/**
343
+	 * Gets the registration's corresponding line item.
344
+	 * Note: basically does NOT support having multiple line items for a single ticket,
345
+	 * which would happen if some of the registrations had a price modifier while others didn't.
346
+	 * In order to support that, we'd probably need a LIN_ID on registrations or something.
347
+	 * @param EE_Registration $registration
348
+	 * @return EE_Line_ITem
349
+	 */
350
+	public function get_line_item_for_registration(EE_Registration $registration)
351
+	{
352
+		return $this->get_one($this->line_item_for_registration_query_params($registration));
353
+	}
354
+
355
+	/**
356
+	 * Gets the query params used to retrieve a specific line item for the given registration
357
+	 * @param EE_Registration $registration
358
+	 * @param array $original_query_params any extra query params you'd like to be merged with
359
+	 * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
360
+	 */
361
+	public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array())
362
+	{
363
+		return array_replace_recursive($original_query_params, array(
364
+			array(
365
+				'OBJ_ID' => $registration->ticket_ID(),
366
+				'OBJ_type' => 'Ticket',
367
+				'TXN_ID' => $registration->transaction_ID()
368
+			)
369
+		));
370
+	}
371
+
372
+
373
+	/**
374
+	 * @return EE_Base_Class[]|EE_Line_Item[]
375
+	 * @throws InvalidInterfaceException
376
+	 * @throws InvalidDataTypeException
377
+	 * @throws EE_Error
378
+	 * @throws InvalidArgumentException
379
+	 */
380
+	public function get_total_line_items_with_no_transaction()
381
+	{
382
+		return $this->get_total_line_items_for_carts();
383
+	}
384
+
385
+
386
+	/**
387
+	 * @return EE_Base_Class[]|EE_Line_Item[]
388
+	 * @throws InvalidInterfaceException
389
+	 * @throws InvalidDataTypeException
390
+	 * @throws EE_Error
391
+	 * @throws InvalidArgumentException
392
+	 */
393
+	public function get_total_line_items_for_active_carts()
394
+	{
395
+		return $this->get_total_line_items_for_carts(false);
396
+	}
397
+
398
+
399
+	/**
400
+	 * @return EE_Base_Class[]|EE_Line_Item[]
401
+	 * @throws InvalidInterfaceException
402
+	 * @throws InvalidDataTypeException
403
+	 * @throws EE_Error
404
+	 * @throws InvalidArgumentException
405
+	 */
406
+	public function get_total_line_items_for_expired_carts()
407
+	{
408
+		return $this->get_total_line_items_for_carts(true);
409
+	}
410
+
411
+
412
+	/**
413
+	 * Returns an array of grand total line items where the TXN_ID is 0.
414
+	 * If $expired is set to true, then only line items for expired sessions will be returned.
415
+	 * If $expired is set to false, then only line items for active sessions will be returned.
416
+	 *
417
+	 * @param null $expired
418
+	 * @return EE_Base_Class[]|EE_Line_Item[]
419
+	 * @throws EE_Error
420
+	 * @throws InvalidArgumentException
421
+	 * @throws InvalidDataTypeException
422
+	 * @throws InvalidInterfaceException
423
+	 */
424
+	private function get_total_line_items_for_carts($expired = null)
425
+	{
426
+		$where_params = array(
427
+			'TXN_ID' => 0,
428
+			'LIN_type' => 'total',
429
+		);
430
+		if ($expired !== null) {
431
+			/** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
432
+			$session_lifespan = LoaderFactory::getLoader()->getShared(
433
+				'EventEspresso\core\domain\values\session\SessionLifespan'
434
+			);
435
+			$where_params['LIN_timestamp'] = array(
436
+				$expired ? '<=' : '>',
437
+				$session_lifespan->expiration(),
438
+			);
439
+		}
440
+		return $this->get_all(array($where_params));
441
+	}
442
+
443
+
444
+	/**
445
+	 * Returns an array of ticket total line items where the TXN_ID is 0
446
+	 * AND the timestamp is older than the session lifespan.
447
+	 *
448
+	 * @param int $timestamp
449
+	 * @return EE_Base_Class[]|EE_Line_Item[]
450
+	 * @throws EE_Error
451
+	 * @throws InvalidArgumentException
452
+	 * @throws InvalidDataTypeException
453
+	 * @throws InvalidInterfaceException
454
+	 */
455
+	public function getTicketLineItemsForExpiredCarts($timestamp = 0)
456
+	{
457
+		if (! absint($timestamp)) {
458
+			/** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
459
+			$session_lifespan = LoaderFactory::getLoader()->getShared(
460
+				'EventEspresso\core\domain\values\session\SessionLifespan'
461
+			);
462
+			$timestamp = $session_lifespan->expiration();
463
+		}
464
+		return $this->get_all(
465
+			array(
466
+				array(
467
+					'TXN_ID'        => 0,
468
+					'OBJ_type'      => 'Ticket',
469
+					'LIN_timestamp' => array('<=', $timestamp),
470
+				)
471
+			)
472
+		);
473
+	}
474 474
 }
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.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.79.rc.010');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.79.rc.010');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
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.