@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );/** |
3 | 5 | * |
4 | 6 | * Event Espresso |
@@ -64,7 +66,7 @@ discard block |
||
64 | 66 | // check if class object is instantiated |
65 | 67 | if( ! empty( $grand_total ) ){ |
66 | 68 | self::$_instance = new self( $grand_total ); |
67 | - }elseif ( ! self::$_instance instanceof EE_Cart) { |
|
69 | + } elseif ( ! self::$_instance instanceof EE_Cart) { |
|
68 | 70 | //try getting the cart out of the session |
69 | 71 | $saved_cart = EE_Registry::instance()->SSN->cart(); |
70 | 72 | self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self( $grand_total ); |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | * @access public |
195 | 195 | * @param EE_Ticket $ticket |
196 | 196 | * @param int $qty |
197 | - * @return TRUE on success, FALSE on fail |
|
197 | + * @return boolean on success, FALSE on fail |
|
198 | 198 | */ |
199 | 199 | public function add_ticket_to_cart( EE_Ticket $ticket, $qty = 1 ) { |
200 | 200 | EEH_Line_Item::add_ticket_purchase( $this->_grand_total, $ticket, $qty ); |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | /** |
218 | 218 | * gets the total amount of tax paid for items in this cart |
219 | 219 | * @access public |
220 | - * @return float |
|
220 | + * @return boolean |
|
221 | 221 | */ |
222 | 222 | public function get_applied_taxes() { |
223 | 223 | return EEH_Line_Item::ensure_taxes_applied( $this->_grand_total ); |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | /** |
229 | 229 | * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
230 | 230 | * @access public |
231 | - * @return float |
|
231 | + * @return boolean |
|
232 | 232 | */ |
233 | 233 | public function get_cart_grand_total() { |
234 | 234 | EEH_Line_Item::ensure_taxes_applied( $this->_grand_total ); |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | /** |
295 | 295 | * @save cart to session |
296 | 296 | * @access public |
297 | - * @return TRUE on success, FALSE on fail |
|
297 | + * @return boolean on success, FALSE on fail |
|
298 | 298 | */ |
299 | 299 | public function save_cart() { |
300 | 300 | EEH_Line_Item::ensure_taxes_applied( $this->_grand_total ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | -do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );/** |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | +do_action('AHEE_log', __FILE__, __FUNCTION__, ''); /** |
|
3 | 3 | * |
4 | 4 | * Event Espresso |
5 | 5 | * |
@@ -59,20 +59,20 @@ discard block |
||
59 | 59 | * @param EE_Line_Item $grand_total |
60 | 60 | * @return \EE_Cart |
61 | 61 | */ |
62 | - public static function instance( EE_Line_Item $grand_total = NULL ) { |
|
62 | + public static function instance(EE_Line_Item $grand_total = NULL) { |
|
63 | 63 | EE_Registry::instance()->load_helper('Line_Item'); |
64 | 64 | // check if class object is instantiated |
65 | - if( ! empty( $grand_total ) ){ |
|
66 | - self::$_instance = new self( $grand_total ); |
|
65 | + if ( ! empty($grand_total)) { |
|
66 | + self::$_instance = new self($grand_total); |
|
67 | 67 | }elseif ( ! self::$_instance instanceof EE_Cart) { |
68 | 68 | //try getting the cart out of the session |
69 | 69 | $saved_cart = EE_Registry::instance()->SSN->cart(); |
70 | - self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self( $grand_total ); |
|
71 | - unset( $saved_cart ); |
|
70 | + self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total); |
|
71 | + unset($saved_cart); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | // once everything is all said and done, save the cart to the EE_Session |
75 | - add_action( 'shutdown', array( self::$_instance, 'save_cart' ), 90 ); |
|
75 | + add_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
76 | 76 | return self::$_instance; |
77 | 77 | } |
78 | 78 | |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | * @param EE_Line_Item $grand_total |
86 | 86 | * @return \EE_Cart |
87 | 87 | */ |
88 | - private function __construct( EE_Line_Item $grand_total = NULL ) { |
|
89 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
90 | - if ( ! defined( 'ESPRESSO_CART' )) { |
|
91 | - define( 'ESPRESSO_CART', TRUE ); |
|
88 | + private function __construct(EE_Line_Item $grand_total = NULL) { |
|
89 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
90 | + if ( ! defined('ESPRESSO_CART')) { |
|
91 | + define('ESPRESSO_CART', TRUE); |
|
92 | 92 | } |
93 | - if ( $grand_total instanceof EE_Line_Item ) { |
|
94 | - $this->set_grand_total_line_item( $grand_total ); |
|
93 | + if ($grand_total instanceof EE_Line_Item) { |
|
94 | + $this->set_grand_total_line_item($grand_total); |
|
95 | 95 | } |
96 | 96 | $this->get_grand_total(); |
97 | 97 | } |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | * @param EE_Line_Item $grand_total |
104 | 104 | * @return EE_Cart |
105 | 105 | */ |
106 | - public static function reset( EE_Line_Item $grand_total = NULL ){ |
|
107 | - remove_action( 'shutdown', array( self::$_instance, 'save_cart'), 90 ); |
|
106 | + public static function reset(EE_Line_Item $grand_total = NULL) { |
|
107 | + remove_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
108 | 108 | EE_Registry::instance()->SSN->reset_cart(); |
109 | 109 | self::$_instance = NULL; |
110 | - return self::instance( $grand_total ); |
|
110 | + return self::instance($grand_total); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | |
@@ -118,11 +118,11 @@ discard block |
||
118 | 118 | * @param EE_Transaction $transaction |
119 | 119 | * @return \EE_Cart |
120 | 120 | */ |
121 | - public static function get_cart_from_txn( EE_Transaction $transaction ) { |
|
121 | + public static function get_cart_from_txn(EE_Transaction $transaction) { |
|
122 | 122 | $grand_total = $transaction->total_line_item(); |
123 | 123 | $grand_total->get_items(); |
124 | 124 | $grand_total->tax_descendants(); |
125 | - return EE_Cart::instance( $grand_total ); |
|
125 | + return EE_Cart::instance($grand_total); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
132 | 132 | * @return EE_Line_Item |
133 | 133 | */ |
134 | - private function _create_grand_total(){ |
|
134 | + private function _create_grand_total() { |
|
135 | 135 | $this->_grand_total = EEH_Line_Item::create_default_total_line_item(); |
136 | 136 | return $this->_grand_total; |
137 | 137 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return \EE_Line_Item[] |
145 | 145 | */ |
146 | 146 | public function get_tickets() { |
147 | - return EEH_Line_Item::get_items_subtotal( $this->_grand_total )->children(); |
|
147 | + return EEH_Line_Item::get_items_subtotal($this->_grand_total)->children(); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | |
@@ -157,11 +157,11 @@ discard block |
||
157 | 157 | */ |
158 | 158 | public function all_ticket_quantity_count() { |
159 | 159 | $tickets = $this->get_tickets(); |
160 | - if ( empty( $tickets )) { |
|
160 | + if (empty($tickets)) { |
|
161 | 161 | return 0; |
162 | 162 | } |
163 | 163 | $count = 0; |
164 | - foreach ( $tickets as $ticket ) { |
|
164 | + foreach ($tickets as $ticket) { |
|
165 | 165 | $count = $count + $ticket->get('LIN_quantity'); |
166 | 166 | } |
167 | 167 | return $count; |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | * Gets all tha tax line items |
174 | 174 | * @return \EE_Line_Item[] |
175 | 175 | */ |
176 | - public function get_taxes(){ |
|
177 | - return EEH_Line_Item::get_taxes_subtotal( $this->_grand_total )->children(); |
|
176 | + public function get_taxes() { |
|
177 | + return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children(); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * Gets the total line item (which is a parent of all other line items) on this cart |
184 | 184 | * @return EE_Line_Item |
185 | 185 | */ |
186 | - public function get_grand_total(){ |
|
186 | + public function get_grand_total() { |
|
187 | 187 | return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total(); |
188 | 188 | } |
189 | 189 | |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * @param int $qty |
197 | 197 | * @return TRUE on success, FALSE on fail |
198 | 198 | */ |
199 | - public function add_ticket_to_cart( EE_Ticket $ticket, $qty = 1 ) { |
|
200 | - EEH_Line_Item::add_ticket_purchase( $this->_grand_total, $ticket, $qty ); |
|
199 | + public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) { |
|
200 | + EEH_Line_Item::add_ticket_purchase($this->_grand_total, $ticket, $qty); |
|
201 | 201 | return $this->save_cart() ? TRUE : FALSE; |
202 | 202 | } |
203 | 203 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @return float |
221 | 221 | */ |
222 | 222 | public function get_applied_taxes() { |
223 | - return EEH_Line_Item::ensure_taxes_applied( $this->_grand_total ); |
|
223 | + return EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @return float |
232 | 232 | */ |
233 | 233 | public function get_cart_grand_total() { |
234 | - EEH_Line_Item::ensure_taxes_applied( $this->_grand_total ); |
|
234 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
235 | 235 | return $this->get_grand_total()->total(); |
236 | 236 | } |
237 | 237 | |
@@ -243,10 +243,10 @@ discard block |
||
243 | 243 | * @param mixed - string or array - line_item_ids |
244 | 244 | * @return int on success, FALSE on fail |
245 | 245 | */ |
246 | - public function delete_items( $line_item_codes = FALSE ) { |
|
246 | + public function delete_items($line_item_codes = FALSE) { |
|
247 | 247 | |
248 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
249 | - return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes ); |
|
248 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
249 | + return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes); |
|
250 | 250 | |
251 | 251 | } |
252 | 252 | |
@@ -258,9 +258,9 @@ discard block |
||
258 | 258 | * @return void |
259 | 259 | */ |
260 | 260 | public function empty_cart() { |
261 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
261 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
262 | 262 | $this->_grand_total = $this->_create_grand_total(); |
263 | - $this->save_cart( TRUE ); |
|
263 | + $this->save_cart(TRUE); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * know the grand total line item on it |
271 | 271 | * @param EE_Line_Item $line_item |
272 | 272 | */ |
273 | - public function set_grand_total_line_item( EE_Line_Item $line_item ) { |
|
273 | + public function set_grand_total_line_item(EE_Line_Item $line_item) { |
|
274 | 274 | $this->_grand_total = $line_item; |
275 | 275 | } |
276 | 276 | |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | * @return TRUE on success, FALSE on fail |
283 | 283 | */ |
284 | 284 | public function save_cart() { |
285 | - EEH_Line_Item::ensure_taxes_applied( $this->_grand_total ); |
|
286 | - return EE_Registry::instance()->SSN->set_cart( $this ); |
|
285 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
286 | + return EE_Registry::instance()->SSN->set_cart($this); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | /** |
3 | 5 | * Event Espresso |
4 | 6 | * |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | |
60 | 60 | |
61 | 61 | /** |
62 | - * @return mixed |
|
62 | + * @return string |
|
63 | 63 | */ |
64 | 64 | public function config_section() { |
65 | 65 | return $this->_config_section; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | |
79 | 79 | /** |
80 | - * @return mixed |
|
80 | + * @return string |
|
81 | 81 | */ |
82 | 82 | public function config_class() { |
83 | 83 | return $this->_config_class; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | |
87 | 87 | |
88 | 88 | /** |
89 | - * @param mixed $config_name |
|
89 | + * @param string $config_name |
|
90 | 90 | */ |
91 | 91 | public function set_config_name( $config_name ) { |
92 | 92 | $this->_config_name = ! empty( $config_name ) ? $config_name : get_called_class(); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | |
97 | 97 | /** |
98 | - * @return mixed |
|
98 | + * @return string |
|
99 | 99 | */ |
100 | 100 | public function config_name() { |
101 | 101 | return $this->_config_name; |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * @param string $config_section |
54 | 54 | */ |
55 | - public function set_config_section( $config_section = '' ) { |
|
56 | - $this->_config_section = ! empty( $config_section ) ? $config_section : 'modules'; |
|
55 | + public function set_config_section($config_section = '') { |
|
56 | + $this->_config_section = ! empty($config_section) ? $config_section : 'modules'; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * @param string $config_class |
72 | 72 | */ |
73 | - public function set_config_class( $config_class = '' ) { |
|
73 | + public function set_config_class($config_class = '') { |
|
74 | 74 | $this->_config_class = $config_class; |
75 | 75 | } |
76 | 76 | |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | /** |
89 | 89 | * @param mixed $config_name |
90 | 90 | */ |
91 | - public function set_config_name( $config_name ) { |
|
92 | - $this->_config_name = ! empty( $config_name ) ? $config_name : get_called_class(); |
|
91 | + public function set_config_name($config_name) { |
|
92 | + $this->_config_name = ! empty($config_name) ? $config_name : get_called_class(); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * @param EE_Config_Base $config_obj |
113 | 113 | * @return mixed EE_Config_Base | NULL |
114 | 114 | */ |
115 | - protected function _set_config( EE_Config_Base $config_obj = NULL ) { |
|
116 | - return EE_Config::instance()->set_config( $this->config_section(), $this->config_name(), $this->config_class(), $config_obj ); |
|
115 | + protected function _set_config(EE_Config_Base $config_obj = NULL) { |
|
116 | + return EE_Config::instance()->set_config($this->config_section(), $this->config_name(), $this->config_class(), $config_obj); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | * @param EE_Config_Base $config_obj |
127 | 127 | * @return mixed EE_Config_Base | NULL |
128 | 128 | */ |
129 | - protected function _update_config( EE_Config_Base $config_obj = NULL ) { |
|
130 | - $this->_config = EE_Config::instance()->update_config( $this->config_section(), $this->config_name(), $config_obj ); |
|
129 | + protected function _update_config(EE_Config_Base $config_obj = NULL) { |
|
130 | + $this->_config = EE_Config::instance()->update_config($this->config_section(), $this->config_name(), $config_obj); |
|
131 | 131 | return $this->_config; |
132 | 132 | } |
133 | 133 | |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @return EE_Config_Base |
140 | 140 | */ |
141 | 141 | public function config() { |
142 | - if ( empty( $this->_config )) { |
|
143 | - $this->_config = EE_Config::instance()->get_config( $this->config_section(), $this->config_name(), $this->config_class() ); |
|
142 | + if (empty($this->_config)) { |
|
143 | + $this->_config = EE_Config::instance()->get_config($this->config_section(), $this->config_name(), $this->config_class()); |
|
144 | 144 | } |
145 | 145 | return $this->_config; |
146 | 146 | } |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | /** |
3 | 5 | * Event Espresso |
4 | 6 | * |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public static function instance() { |
63 | 63 | // check if class object is instantiated, and instantiated properly |
64 | - if ( self::$_instance === NULL or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EE_Front_Controller )) { |
|
64 | + if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Front_Controller)) { |
|
65 | 65 | self::$_instance = new self(); |
66 | 66 | } |
67 | 67 | return self::$_instance; |
@@ -79,35 +79,35 @@ discard block |
||
79 | 79 | */ |
80 | 80 | private function __construct() { |
81 | 81 | // make sure template tags are loaded immediately so that themes don't break |
82 | - add_action( 'AHEE__EE_System__core_loaded_and_ready', array( $this, 'load_espresso_template_tags' ), 10 ); |
|
82 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'load_espresso_template_tags'), 10); |
|
83 | 83 | // determine how to integrate WP_Query with the EE models |
84 | - add_action( 'AHEE__EE_System__initialize', array( $this, 'employ_CPT_Strategy' )); |
|
84 | + add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
85 | 85 | // load other resources and begin to actually run shortcodes and modules |
86 | - add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 5 ); |
|
86 | + add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
87 | 87 | // analyse the incoming WP request |
88 | - add_action( 'parse_request', array( $this, 'get_request' ), 1, 1 ); |
|
88 | + add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
89 | 89 | // process any content shortcodes |
90 | - add_action( 'parse_request', array( $this, '_initialize_shortcodes' ), 5 ); |
|
90 | + add_action('parse_request', array($this, '_initialize_shortcodes'), 5); |
|
91 | 91 | // process request with module factory |
92 | - add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ), 10, 1 ); |
|
92 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
93 | 93 | // before headers sent |
94 | - add_action( 'wp', array( $this, 'wp' ), 5 ); |
|
94 | + add_action('wp', array($this, 'wp'), 5); |
|
95 | 95 | // load css and js |
96 | - add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 5 ); |
|
96 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 5); |
|
97 | 97 | // header |
98 | - add_action('wp_head', array( $this, 'header_meta_tag' ), 5 ); |
|
99 | - add_filter( 'template_include', array( $this, 'template_include' ), 1 ); |
|
98 | + add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
99 | + add_filter('template_include', array($this, 'template_include'), 1); |
|
100 | 100 | // display errors |
101 | - add_action('loop_start', array( $this, 'display_errors' ), 2 ); |
|
101 | + add_action('loop_start', array($this, 'display_errors'), 2); |
|
102 | 102 | // the content |
103 | - add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
103 | + add_filter('the_content', array($this, 'the_content'), 5, 1); |
|
104 | 104 | |
105 | 105 | //exclude our private cpt comments |
106 | - add_filter( 'comments_clauses', array( $this, 'filter_wp_comments'), 10, 1 ); |
|
106 | + add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
107 | 107 | //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
108 | - add_filter( 'admin_url', array( $this, 'maybe_force_admin_ajax_ssl' ), 200, 1 ); |
|
108 | + add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
109 | 109 | // action hook EE |
110 | - do_action( 'AHEE__EE_Front_Controller__construct__done',$this ); |
|
110 | + do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | * @return void |
127 | 127 | */ |
128 | 128 | public function load_espresso_template_tags() { |
129 | - if ( is_readable( EE_PUBLIC . 'template_tags.php' )) { |
|
130 | - require_once( EE_PUBLIC . 'template_tags.php' ); |
|
129 | + if (is_readable(EE_PUBLIC.'template_tags.php')) { |
|
130 | + require_once(EE_PUBLIC.'template_tags.php'); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | |
@@ -142,12 +142,12 @@ discard block |
||
142 | 142 | * @param array $clauses array of comment clauses setup by WP_Comment_Query |
143 | 143 | * @return array array of comment clauses with modifications. |
144 | 144 | */ |
145 | - public function filter_wp_comments( $clauses ) { |
|
145 | + public function filter_wp_comments($clauses) { |
|
146 | 146 | global $wpdb; |
147 | - if ( strpos( $clauses['join'], $wpdb->posts ) !== FALSE ) { |
|
147 | + if (strpos($clauses['join'], $wpdb->posts) !== FALSE) { |
|
148 | 148 | $cpts = EE_Register_CPTs::get_private_CPTs(); |
149 | - foreach ( $cpts as $cpt => $details ) { |
|
150 | - $clauses['where'] .= $wpdb->prepare( " AND $wpdb->posts.post_type != %s", $cpt ); |
|
149 | + foreach ($cpts as $cpt => $details) { |
|
150 | + $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | return $clauses; |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | * @return void |
165 | 165 | */ |
166 | 166 | public function employ_CPT_Strategy() { |
167 | - if ( apply_filters( 'FHEE__EE_Front_Controller__employ_CPT_Strategy',true) ){ |
|
168 | - EE_Registry::instance()->load_core( 'CPT_Strategy' ); |
|
167 | + if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
168 | + EE_Registry::instance()->load_core('CPT_Strategy'); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | * @param string $url incoming url |
178 | 178 | * @return string final assembled url |
179 | 179 | */ |
180 | - public function maybe_force_admin_ajax_ssl( $url ) { |
|
181 | - if ( is_ssl() && preg_match( '/admin-ajax.php/', $url )) { |
|
182 | - $url = str_replace( 'http://', 'https://', $url ); |
|
180 | + public function maybe_force_admin_ajax_ssl($url) { |
|
181 | + if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
182 | + $url = str_replace('http://', 'https://', $url); |
|
183 | 183 | } |
184 | 184 | return $url; |
185 | 185 | } |
@@ -216,10 +216,10 @@ discard block |
||
216 | 216 | * @param WP $WP |
217 | 217 | * @return void |
218 | 218 | */ |
219 | - public function get_request( WP $WP ) { |
|
220 | - do_action( 'AHEE__EE_Front_Controller__get_request__start' ); |
|
221 | - EE_Registry::instance()->load_core( 'Request_Handler', $WP ); |
|
222 | - do_action( 'AHEE__EE_Front_Controller__get_request__complete' ); |
|
219 | + public function get_request(WP $WP) { |
|
220 | + do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
221 | + EE_Registry::instance()->load_core('Request_Handler', $WP); |
|
222 | + do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | |
@@ -231,22 +231,22 @@ discard block |
||
231 | 231 | * @param WP $WP |
232 | 232 | * @return void |
233 | 233 | */ |
234 | - public function _initialize_shortcodes( WP $WP ) { |
|
235 | - do_action( 'AHEE__EE_Front_Controller__initialize_shortcodes__begin', $WP, $this ); |
|
234 | + public function _initialize_shortcodes(WP $WP) { |
|
235 | + do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $WP, $this); |
|
236 | 236 | // grab post_name from request |
237 | - $current_post = apply_filters( 'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name', EE_Registry::instance()->REQ->get( 'post_name' )); |
|
237 | + $current_post = apply_filters('FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name', EE_Registry::instance()->REQ->get('post_name')); |
|
238 | 238 | // if it's not set, then check if frontpage is blog |
239 | - if ( empty( $current_post ) && get_option( 'show_on_front' ) == 'posts' ) { |
|
239 | + if (empty($current_post) && get_option('show_on_front') == 'posts') { |
|
240 | 240 | // yup.. this is the posts page, prepare to load all shortcode modules |
241 | 241 | $current_post = 'posts'; |
242 | - } else if ( empty( $current_post ) && get_option( 'show_on_front' ) == 'page' ) { |
|
242 | + } else if (empty($current_post) && get_option('show_on_front') == 'page') { |
|
243 | 243 | // some other page is set as the homepage |
244 | - $page_on_front = get_option( 'page_on_front' ); |
|
245 | - if ( $page_on_front ) { |
|
244 | + $page_on_front = get_option('page_on_front'); |
|
245 | + if ($page_on_front) { |
|
246 | 246 | // k now we need to find the post_name for this page |
247 | 247 | global $wpdb; |
248 | 248 | $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='page' AND post_status='publish' AND ID=%d"; |
249 | - $page_on_front = $wpdb->get_var( $wpdb->prepare( $SQL, $page_on_front )); |
|
249 | + $page_on_front = $wpdb->get_var($wpdb->prepare($SQL, $page_on_front)); |
|
250 | 250 | // set the current post slug to what it actually is |
251 | 251 | $current_post = $page_on_front ? $page_on_front : $current_post; |
252 | 252 | } |
@@ -254,58 +254,58 @@ discard block |
||
254 | 254 | // where are posts being displayed ? |
255 | 255 | $page_for_posts = EE_Config::get_page_for_posts(); |
256 | 256 | // in case $current_post is hierarchical like: /parent-page/current-page |
257 | - $current_post = basename( $current_post ); |
|
257 | + $current_post = basename($current_post); |
|
258 | 258 | // are we on a category page? |
259 | - $term_exists = is_array( term_exists( $current_post, 'category' )) || array_key_exists( 'category_name', $WP->query_vars ); |
|
259 | + $term_exists = is_array(term_exists($current_post, 'category')) || array_key_exists('category_name', $WP->query_vars); |
|
260 | 260 | // make sure shortcodes are set |
261 | - if ( isset( EE_Registry::instance()->CFG->core->post_shortcodes )) { |
|
261 | + if (isset(EE_Registry::instance()->CFG->core->post_shortcodes)) { |
|
262 | 262 | // d( EE_Registry::instance()->CFG->core->post_shortcodes ); |
263 | 263 | // cycle thru all posts with shortcodes set |
264 | - foreach ( EE_Registry::instance()->CFG->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
264 | + foreach (EE_Registry::instance()->CFG->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
265 | 265 | // filter shortcodes so |
266 | - $post_shortcodes = apply_filters( 'FHEE__Front_Controller__initialize_shortcodes__post_shortcodes', $post_shortcodes ); |
|
266 | + $post_shortcodes = apply_filters('FHEE__Front_Controller__initialize_shortcodes__post_shortcodes', $post_shortcodes); |
|
267 | 267 | // now cycle thru shortcodes |
268 | - foreach ( $post_shortcodes as $shortcode_class => $post_id ) { |
|
268 | + foreach ($post_shortcodes as $shortcode_class => $post_id) { |
|
269 | 269 | // are we on this page, or on the blog page, or an EE CPT category page ? |
270 | - if ( $current_post == $post_name || $term_exists ) { |
|
270 | + if ($current_post == $post_name || $term_exists) { |
|
271 | 271 | // verify shortcode is in list of registered shortcodes |
272 | - if ( ! isset( EE_Registry::instance()->shortcodes->$shortcode_class )) { |
|
273 | - if ( $current_post != $page_for_posts && current_user_can( 'edit_post', $post_id )) { |
|
274 | - $msg = sprintf( __( 'The [%s] shortcode has not been properly registered or the corresponding addon/module is not active for some reason. Either fix/remove the shortcode from the post, or activate the addon/module the shortcode is associated with.', 'event_espresso' ), $shortcode_class ); |
|
275 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
276 | - add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
272 | + if ( ! isset(EE_Registry::instance()->shortcodes->$shortcode_class)) { |
|
273 | + if ($current_post != $page_for_posts && current_user_can('edit_post', $post_id)) { |
|
274 | + $msg = sprintf(__('The [%s] shortcode has not been properly registered or the corresponding addon/module is not active for some reason. Either fix/remove the shortcode from the post, or activate the addon/module the shortcode is associated with.', 'event_espresso'), $shortcode_class); |
|
275 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
276 | + add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
277 | 277 | } |
278 | - add_shortcode( $shortcode_class, array( 'EES_Shortcode', 'invalid_shortcode_processor' )); |
|
278 | + add_shortcode($shortcode_class, array('EES_Shortcode', 'invalid_shortcode_processor')); |
|
279 | 279 | break; |
280 | 280 | } |
281 | 281 | // is this : a shortcodes set exclusively for this post, or for the home page, or a category, or a taxonomy ? |
282 | - if ( isset( EE_Registry::instance()->CFG->core->post_shortcodes[ $current_post ] ) || $term_exists || $current_post == $page_for_posts ) { |
|
282 | + if (isset(EE_Registry::instance()->CFG->core->post_shortcodes[$current_post]) || $term_exists || $current_post == $page_for_posts) { |
|
283 | 283 | // let's pause to reflect on this... |
284 | - $sc_reflector = new ReflectionClass( 'EES_' . $shortcode_class ); |
|
284 | + $sc_reflector = new ReflectionClass('EES_'.$shortcode_class); |
|
285 | 285 | // ensure that class is actually a shortcode |
286 | - if ( ! $sc_reflector->isSubclassOf( 'EES_Shortcode' ) && defined( 'WP_DEBUG' ) && WP_DEBUG === TRUE ) { |
|
287 | - $msg = sprintf( __( 'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.', 'event_espresso' ), $shortcode_class ); |
|
288 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
289 | - add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
286 | + if ( ! $sc_reflector->isSubclassOf('EES_Shortcode') && defined('WP_DEBUG') && WP_DEBUG === TRUE) { |
|
287 | + $msg = sprintf(__('The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.', 'event_espresso'), $shortcode_class); |
|
288 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
289 | + add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
290 | 290 | break; |
291 | 291 | } |
292 | 292 | // and pass the request object to the run method |
293 | 293 | EE_Registry::instance()->shortcodes->$shortcode_class = $sc_reflector->newInstance(); |
294 | 294 | // fire the shortcode class's run method, so that it can activate resources |
295 | - EE_Registry::instance()->shortcodes->$shortcode_class->run( $WP ); |
|
295 | + EE_Registry::instance()->shortcodes->$shortcode_class->run($WP); |
|
296 | 296 | } |
297 | 297 | // if this is NOT the "Posts page" and we have a valid entry for the "Posts page" in our tracked post_shortcodes array |
298 | - } else if ( $post_name != $page_for_posts && isset( EE_Registry::instance()->CFG->core->post_shortcodes[ $page_for_posts ] )) { |
|
298 | + } else if ($post_name != $page_for_posts && isset(EE_Registry::instance()->CFG->core->post_shortcodes[$page_for_posts])) { |
|
299 | 299 | // and the shortcode is not being tracked for this page |
300 | - if ( ! isset( EE_Registry::instance()->CFG->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] )) { |
|
300 | + if ( ! isset(EE_Registry::instance()->CFG->core->post_shortcodes[$page_for_posts][$shortcode_class])) { |
|
301 | 301 | // then remove the "fallback" shortcode processor |
302 | - remove_shortcode( $shortcode_class ); |
|
302 | + remove_shortcode($shortcode_class); |
|
303 | 303 | } |
304 | 304 | } |
305 | 305 | } |
306 | 306 | } |
307 | 307 | } |
308 | - do_action( 'AHEE__EE_Front_Controller__initialize_shortcodes__end', $this ); |
|
308 | + do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $this); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | |
@@ -317,20 +317,20 @@ discard block |
||
317 | 317 | * @param WP_Query $WP_Query |
318 | 318 | * @return void |
319 | 319 | */ |
320 | - public function pre_get_posts( $WP_Query ) { |
|
320 | + public function pre_get_posts($WP_Query) { |
|
321 | 321 | // only load Module_Request_Router if this is the main query |
322 | - if ( $WP_Query->is_main_query() ) { |
|
322 | + if ($WP_Query->is_main_query()) { |
|
323 | 323 | // load module request router |
324 | - $Module_Request_Router = EE_Registry::instance()->load_core( 'Module_Request_Router' ); |
|
324 | + $Module_Request_Router = EE_Registry::instance()->load_core('Module_Request_Router'); |
|
325 | 325 | // verify object |
326 | - if ( $Module_Request_Router instanceof EE_Module_Request_Router ) { |
|
326 | + if ($Module_Request_Router instanceof EE_Module_Request_Router) { |
|
327 | 327 | // cycle thru module routes |
328 | - while ( $route = $Module_Request_Router->get_route( $WP_Query )) { |
|
328 | + while ($route = $Module_Request_Router->get_route($WP_Query)) { |
|
329 | 329 | // determine module and method for route |
330 | - $module = $Module_Request_Router->resolve_route( $route[0], $route[1] ); |
|
331 | - if( $module instanceof EED_Module ) { |
|
330 | + $module = $Module_Request_Router->resolve_route($route[0], $route[1]); |
|
331 | + if ($module instanceof EED_Module) { |
|
332 | 332 | // get registered view for route |
333 | - $this->_template_path = $Module_Request_Router->get_view( $route ); |
|
333 | + $this->_template_path = $Module_Request_Router->get_view($route); |
|
334 | 334 | // grab module name |
335 | 335 | $module_name = $module->module_name(); |
336 | 336 | // map the module to the module objects |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | * @return void |
358 | 358 | */ |
359 | 359 | public function wp() { |
360 | - EE_Registry::instance()->load_helper( 'Template' ); |
|
360 | + EE_Registry::instance()->load_helper('Template'); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | |
@@ -375,30 +375,30 @@ discard block |
||
375 | 375 | public function wp_enqueue_scripts() { |
376 | 376 | |
377 | 377 | // css is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF via: add_filter( 'FHEE_load_css', '__return_false' ); |
378 | - if ( apply_filters( 'FHEE_load_css', TRUE ) ) { |
|
378 | + if (apply_filters('FHEE_load_css', TRUE)) { |
|
379 | 379 | |
380 | 380 | EE_Registry::instance()->CFG->template_settings->enable_default_style = TRUE; |
381 | 381 | //Load the ThemeRoller styles if enabled |
382 | - if ( isset( EE_Registry::instance()->CFG->template_settings->enable_default_style ) && EE_Registry::instance()->CFG->template_settings->enable_default_style ) { |
|
382 | + if (isset(EE_Registry::instance()->CFG->template_settings->enable_default_style) && EE_Registry::instance()->CFG->template_settings->enable_default_style) { |
|
383 | 383 | |
384 | 384 | //Load custom style sheet if available |
385 | - if ( isset( EE_Registry::instance()->CFG->template_settings->custom_style_sheet )) { |
|
386 | - wp_register_style('espresso_custom_css', EVENT_ESPRESSO_UPLOAD_URL . 'css/' . EE_Registry::instance()->CFG->template_settings->custom_style_sheet, EVENT_ESPRESSO_VERSION ); |
|
385 | + if (isset(EE_Registry::instance()->CFG->template_settings->custom_style_sheet)) { |
|
386 | + wp_register_style('espresso_custom_css', EVENT_ESPRESSO_UPLOAD_URL.'css/'.EE_Registry::instance()->CFG->template_settings->custom_style_sheet, EVENT_ESPRESSO_VERSION); |
|
387 | 387 | wp_enqueue_style('espresso_custom_css'); |
388 | 388 | } |
389 | 389 | |
390 | - EE_Registry::instance()->load_helper( 'File' ); |
|
391 | - if ( is_readable( EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css' )) { |
|
392 | - wp_register_style( 'espresso_default', EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css', array( 'dashicons' ), EVENT_ESPRESSO_VERSION ); |
|
390 | + EE_Registry::instance()->load_helper('File'); |
|
391 | + if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')) { |
|
392 | + wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR.'css/espresso_default.css', array('dashicons'), EVENT_ESPRESSO_VERSION); |
|
393 | 393 | } else { |
394 | - wp_register_style( 'espresso_default', EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', array( 'dashicons' ), EVENT_ESPRESSO_VERSION ); |
|
394 | + wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', array('dashicons'), EVENT_ESPRESSO_VERSION); |
|
395 | 395 | } |
396 | 396 | wp_enqueue_style('espresso_default'); |
397 | 397 | |
398 | - if ( is_readable( get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'style.css' )) { |
|
399 | - wp_register_style( 'espresso_style', get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'style.css', array( 'dashicons', 'espresso_default' ) ); |
|
398 | + if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'style.css')) { |
|
399 | + wp_register_style('espresso_style', get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'style.css', array('dashicons', 'espresso_default')); |
|
400 | 400 | } else { |
401 | - wp_register_style( 'espresso_style', EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'style.css', array( 'dashicons', 'espresso_default' ) ); |
|
401 | + wp_register_style('espresso_style', EE_TEMPLATES_URL.EE_Config::get_current_theme().DS.'style.css', array('dashicons', 'espresso_default')); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | } |
@@ -406,28 +406,28 @@ discard block |
||
406 | 406 | } |
407 | 407 | |
408 | 408 | // js is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF via: add_filter( 'FHEE_load_js', '__return_false' ); |
409 | - if ( apply_filters( 'FHEE_load_js', TRUE ) ) { |
|
409 | + if (apply_filters('FHEE_load_js', TRUE)) { |
|
410 | 410 | |
411 | - wp_enqueue_script( 'jquery' ); |
|
411 | + wp_enqueue_script('jquery'); |
|
412 | 412 | //let's make sure that all required scripts have been setup |
413 | - if ( function_exists( 'wp_script_is' )) { |
|
414 | - if ( ! wp_script_is( 'jquery' )) { |
|
413 | + if (function_exists('wp_script_is')) { |
|
414 | + if ( ! wp_script_is('jquery')) { |
|
415 | 415 | $msg = sprintf( |
416 | - __( '%sJquery is not loaded!%sEvent Espresso is unable to load Jquery due to a conflict with your theme or another plugin.', 'event_espresso' ), |
|
416 | + __('%sJquery is not loaded!%sEvent Espresso is unable to load Jquery due to a conflict with your theme or another plugin.', 'event_espresso'), |
|
417 | 417 | '<em><br />', |
418 | 418 | '</em>' |
419 | 419 | ); |
420 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
420 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
421 | 421 | } |
422 | 422 | } |
423 | 423 | // load core js |
424 | - wp_register_script( 'espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
425 | - wp_enqueue_script( 'espresso_core' ); |
|
424 | + wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE); |
|
425 | + wp_enqueue_script('espresso_core'); |
|
426 | 426 | |
427 | 427 | } |
428 | 428 | |
429 | 429 | //qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
430 | - if ( apply_filters( 'FHEE_load_qtip', FALSE ) ) { |
|
430 | + if (apply_filters('FHEE_load_qtip', FALSE)) { |
|
431 | 431 | EE_Registry::instance()->load_helper('Qtip_Loader'); |
432 | 432 | EEH_Qtip_Loader::instance()->register_and_enqueue(); |
433 | 433 | } |
@@ -435,11 +435,11 @@ discard block |
||
435 | 435 | |
436 | 436 | //accounting.js library |
437 | 437 | // @link http://josscrowcroft.github.io/accounting.js/ |
438 | - if ( apply_filters( 'FHEE_load_accounting_js', FALSE ) ) { |
|
439 | - $acct_js = EE_THIRD_PARTY_URL . 'accounting/accounting.js'; |
|
440 | - wp_register_script( 'ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
441 | - wp_register_script( 'ee-accounting-core', $acct_js, array('underscore'), '0.3.2', TRUE ); |
|
442 | - wp_enqueue_script( 'ee-accounting' ); |
|
438 | + if (apply_filters('FHEE_load_accounting_js', FALSE)) { |
|
439 | + $acct_js = EE_THIRD_PARTY_URL.'accounting/accounting.js'; |
|
440 | + wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, TRUE); |
|
441 | + wp_register_script('ee-accounting-core', $acct_js, array('underscore'), '0.3.2', TRUE); |
|
442 | + wp_enqueue_script('ee-accounting'); |
|
443 | 443 | |
444 | 444 | $currency_config = array( |
445 | 445 | 'currency' => array( |
@@ -462,21 +462,21 @@ discard block |
||
462 | 462 | wp_localize_script('ee-accounting', 'EE_ACCOUNTING_CFG', $currency_config); |
463 | 463 | } |
464 | 464 | |
465 | - if ( ! function_exists( 'wp_head' )) { |
|
465 | + if ( ! function_exists('wp_head')) { |
|
466 | 466 | $msg = sprintf( |
467 | - __( '%sMissing wp_head() function.%sThe WordPress function wp_head() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.', 'event_espresso' ), |
|
467 | + __('%sMissing wp_head() function.%sThe WordPress function wp_head() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.', 'event_espresso'), |
|
468 | 468 | '<em><br />', |
469 | 469 | '</em>' |
470 | 470 | ); |
471 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
471 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
472 | 472 | } |
473 | - if ( ! function_exists( 'wp_footer' )) { |
|
473 | + if ( ! function_exists('wp_footer')) { |
|
474 | 474 | $msg = sprintf( |
475 | - __( '%sMissing wp_footer() function.%sThe WordPress function wp_footer() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.', 'event_espresso' ), |
|
475 | + __('%sMissing wp_footer() function.%sThe WordPress function wp_footer() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.', 'event_espresso'), |
|
476 | 476 | '<em><br />', |
477 | 477 | '</em>' |
478 | 478 | ); |
479 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
479 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | } |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | * @return void |
491 | 491 | */ |
492 | 492 | public function header_meta_tag() { |
493 | - print( apply_filters("FHEE__EE_Front_Controller__header_meta_tag","<meta name='generator' content='Event Espresso Version " . EVENT_ESPRESSO_VERSION . "' />")); |
|
493 | + print(apply_filters("FHEE__EE_Front_Controller__header_meta_tag", "<meta name='generator' content='Event Espresso Version ".EVENT_ESPRESSO_VERSION."' />")); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | |
@@ -504,9 +504,9 @@ discard block |
||
504 | 504 | * @param $the_content |
505 | 505 | * @return string |
506 | 506 | */ |
507 | - public function the_content( $the_content ) { |
|
507 | + public function the_content($the_content) { |
|
508 | 508 | // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
509 | - if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
509 | + if (apply_filters('FHEE_run_EE_the_content', FALSE)) { |
|
510 | 510 | } |
511 | 511 | return $the_content; |
512 | 512 | } |
@@ -531,14 +531,14 @@ discard block |
||
531 | 531 | */ |
532 | 532 | public function display_errors() { |
533 | 533 | static $shown_already = FALSE; |
534 | - do_action( 'AHEE__EE_Front_Controller__display_errors__begin' ); |
|
535 | - if ( apply_filters( 'FHEE__EE_Front_Controller__display_errors', TRUE ) && ! $shown_already && is_main_query() && ! is_feed() && in_the_loop() ) { |
|
534 | + do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
535 | + if (apply_filters('FHEE__EE_Front_Controller__display_errors', TRUE) && ! $shown_already && is_main_query() && ! is_feed() && in_the_loop()) { |
|
536 | 536 | echo EE_Error::get_notices(); |
537 | 537 | $shown_already = TRUE; |
538 | - EE_Registry::instance()->load_helper( 'Template' ); |
|
539 | - EEH_Template::display_template( EE_TEMPLATES . 'espresso-ajax-notices.template.php' ); |
|
538 | + EE_Registry::instance()->load_helper('Template'); |
|
539 | + EEH_Template::display_template(EE_TEMPLATES.'espresso-ajax-notices.template.php'); |
|
540 | 540 | } |
541 | - do_action( 'AHEE__EE_Front_Controller__display_errors__end' ); |
|
541 | + do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | |
@@ -553,12 +553,12 @@ discard block |
||
553 | 553 | * @param string $template_include_path |
554 | 554 | * @return string |
555 | 555 | */ |
556 | - public function template_include( $template_include_path = NULL ) { |
|
557 | - if ( EE_Registry::instance()->REQ->is_espresso_page() ) { |
|
558 | - $this->_template_path = ! empty( $this->_template_path ) ? basename( $this->_template_path ) : basename( $template_include_path ); |
|
559 | - $template_path = EEH_Template::locate_template( $this->_template_path, array(), false ); |
|
560 | - $this->_template_path = ! empty( $template_path ) ? $template_path : $template_include_path; |
|
561 | - $this->_template = basename( $this->_template_path ); |
|
556 | + public function template_include($template_include_path = NULL) { |
|
557 | + if (EE_Registry::instance()->REQ->is_espresso_page()) { |
|
558 | + $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
559 | + $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
560 | + $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
561 | + $this->_template = basename($this->_template_path); |
|
562 | 562 | return $this->_template_path; |
563 | 563 | } |
564 | 564 | return $template_include_path; |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | * @param bool $with_path |
574 | 574 | * @return string |
575 | 575 | */ |
576 | - public function get_selected_template( $with_path = FALSE ) { |
|
576 | + public function get_selected_template($with_path = FALSE) { |
|
577 | 577 | return $with_path ? $this->_template_path : $this->_template; |
578 | 578 | } |
579 | 579 |
@@ -8,16 +8,16 @@ |
||
8 | 8 | <div class="ee-list-table-legend-container"> |
9 | 9 | <h4><?php _e('Legend', 'event_espresso'); ?></h4> |
10 | 10 | <dl class="alignleft ee-list-table-legend"> |
11 | - <?php foreach ( $items as $item => $details ) : ?> |
|
12 | - <?php if ( $per_col < $count ) : ?> |
|
11 | + <?php foreach ($items as $item => $details) : ?> |
|
12 | + <?php if ($per_col < $count) : ?> |
|
13 | 13 | </dl> |
14 | 14 | <dl class="alignleft ee-list-table-legend"> |
15 | 15 | <?php $count = 1; endif; ?> |
16 | 16 | <dt id="ee-legend-item-<?php echo $item; ?>"> |
17 | - <?php $class = !empty($details['class']) ? $details['class'] : 'ee-legend-img-container'; ?> |
|
17 | + <?php $class = ! empty($details['class']) ? $details['class'] : 'ee-legend-img-container'; ?> |
|
18 | 18 | <span class="<?php echo $class; ?>"> |
19 | - <?php if ( !empty($details['icon']) ) : ?> |
|
20 | - <img src="<?php echo $details['icon']; ?>" class="ee-legend-icon" alt="<?php echo esc_attr( $details['desc'] ); ?>" /> |
|
19 | + <?php if ( ! empty($details['icon'])) : ?> |
|
20 | + <img src="<?php echo $details['icon']; ?>" class="ee-legend-icon" alt="<?php echo esc_attr($details['desc']); ?>" /> |
|
21 | 21 | <?php endif; ?> |
22 | 22 | </span> |
23 | 23 | <span class="ee-legend-description"><?php echo $details['desc']; ?></span> |
@@ -47,25 +47,25 @@ |
||
47 | 47 | |
48 | 48 | |
49 | 49 | /** |
50 | - * date format |
|
51 | - * |
|
52 | - * pattern or format for displaying dates |
|
53 | - * |
|
54 | - * @access protected |
|
55 | - * @var string |
|
56 | - */ |
|
50 | + * date format |
|
51 | + * |
|
52 | + * pattern or format for displaying dates |
|
53 | + * |
|
54 | + * @access protected |
|
55 | + * @var string |
|
56 | + */ |
|
57 | 57 | protected $_dt_frmt; |
58 | 58 | |
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * time format |
|
63 | - * |
|
64 | - * pattern or format for displaying time |
|
65 | - * |
|
66 | - * @access protected |
|
67 | - * @var string |
|
68 | - */ |
|
61 | + /** |
|
62 | + * time format |
|
63 | + * |
|
64 | + * pattern or format for displaying time |
|
65 | + * |
|
66 | + * @access protected |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | protected $_tm_frmt; |
70 | 70 | |
71 | 71 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | -do_action( 'AHEE_log', __FILE__, ' FILE LOADED', '' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | +do_action('AHEE_log', __FILE__, ' FILE LOADED', ''); |
|
3 | 3 | /** |
4 | 4 | * |
5 | 5 | * Event Espresso |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * ------------------------------------------------------------------------ |
25 | 25 | */ |
26 | 26 | |
27 | -abstract class EE_Base_Class{ |
|
27 | +abstract class EE_Base_Class { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * This is an array of the original properties and values provided during construction |
@@ -105,39 +105,39 @@ discard block |
||
105 | 105 | * @throws EE_Error |
106 | 106 | * @return \EE_Base_Class |
107 | 107 | */ |
108 | - protected function __construct( $fieldValues = array(), $bydb = FALSE, $timezone = '' ){ |
|
108 | + protected function __construct($fieldValues = array(), $bydb = FALSE, $timezone = '') { |
|
109 | 109 | |
110 | - $className=get_class($this); |
|
110 | + $className = get_class($this); |
|
111 | 111 | //set default formats for date and time |
112 | - $this->_dt_frmt = EE_Base_Class::fix_date_format_for_use_with_strtotime( get_option( 'date_format' )); |
|
113 | - $this->_tm_frmt = get_option( 'time_format' ); |
|
112 | + $this->_dt_frmt = EE_Base_Class::fix_date_format_for_use_with_strtotime(get_option('date_format')); |
|
113 | + $this->_tm_frmt = get_option('time_format'); |
|
114 | 114 | |
115 | 115 | |
116 | - do_action("AHEE__{$className}__construct",$this,$fieldValues); |
|
117 | - $model=$this->get_model(); |
|
118 | - $model_fields = $model->field_settings( FALSE ); |
|
116 | + do_action("AHEE__{$className}__construct", $this, $fieldValues); |
|
117 | + $model = $this->get_model(); |
|
118 | + $model_fields = $model->field_settings(FALSE); |
|
119 | 119 | // ensure $fieldValues is an array |
120 | - $fieldValues = is_array( $fieldValues ) ? $fieldValues : array( $fieldValues ); |
|
120 | + $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues); |
|
121 | 121 | // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
122 | 122 | // verify client code has not passed any invalid field names |
123 | - foreach($fieldValues as $field_name=> $field_value){ |
|
124 | - if( ! isset( $model_fields[ $field_name] ) ){ |
|
125 | - throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"),$field_name,get_class($this),implode(", ",array_keys($model_fields)))); |
|
123 | + foreach ($fieldValues as $field_name=> $field_value) { |
|
124 | + if ( ! isset($model_fields[$field_name])) { |
|
125 | + throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields)))); |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | // EEH_Debug_Tools::printr( $model_fields, '$model_fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
129 | 129 | |
130 | 130 | //if db model is instantiating |
131 | - if( $bydb ){ |
|
131 | + if ($bydb) { |
|
132 | 132 | //client code has indicated these field values are from the database |
133 | - foreach($fieldValues as $field_name => $field_value_from_db){ |
|
134 | - $this->set_from_db($field_name,$field_value_from_db); |
|
133 | + foreach ($fieldValues as $field_name => $field_value_from_db) { |
|
134 | + $this->set_from_db($field_name, $field_value_from_db); |
|
135 | 135 | } |
136 | - }else{ |
|
136 | + } else { |
|
137 | 137 | //we're constructing a brand |
138 | 138 | //new instance of the model object. Generally, this means we'll need to do more field validation |
139 | - foreach($model_fields as $fieldName => $field_obj){ |
|
140 | - $this->set($fieldName,isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null ,true); |
|
139 | + foreach ($model_fields as $fieldName => $field_obj) { |
|
140 | + $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
@@ -146,14 +146,14 @@ discard block |
||
146 | 146 | //remember what values were passed to this constructor |
147 | 147 | $this->_props_n_values_provided_in_constructor = $fieldValues; |
148 | 148 | //remember in entity mapper |
149 | - if($model->has_primary_key_field() && $this->ID() && ! $bydb ){ |
|
149 | + if ($model->has_primary_key_field() && $this->ID() && ! $bydb) { |
|
150 | 150 | $model->add_to_entity_map($this); |
151 | 151 | } |
152 | 152 | //setup all the relations |
153 | - foreach($this->get_model()->relation_settings() as $relation_name=>$relation_obj){ |
|
154 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
153 | + foreach ($this->get_model()->relation_settings() as $relation_name=>$relation_obj) { |
|
154 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
155 | 155 | $this->_model_relations[$relation_name] = NULL; |
156 | - }else{ |
|
156 | + } else { |
|
157 | 157 | $this->_model_relations[$relation_name] = array(); |
158 | 158 | } |
159 | 159 | } |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * Action done at the end of each model object construction |
162 | 162 | * @param EE_Base_Class $this the model object just created |
163 | 163 | */ |
164 | - do_action( 'AHEE__EE_Base_Class__construct__finished', $this ); |
|
164 | + do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | |
@@ -173,11 +173,11 @@ discard block |
||
173 | 173 | * @param string $field_name |
174 | 174 | * @return mixed|null |
175 | 175 | */ |
176 | - public function get_original( $field_name ){ |
|
177 | - if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
|
178 | - $field_settings = $this->get_Model()->field_settings_for( $field_name )){ |
|
179 | - return $field_settings->prepare_for_get( $this->_props_n_values_provided_in_constructor[ $field_name ] ); |
|
180 | - }else{ |
|
176 | + public function get_original($field_name) { |
|
177 | + if (isset($this->_props_n_values_provided_in_constructor[$field_name]) && |
|
178 | + $field_settings = $this->get_Model()->field_settings_for($field_name)) { |
|
179 | + return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]); |
|
180 | + } else { |
|
181 | 181 | return NULL; |
182 | 182 | } |
183 | 183 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @param EE_Base_Class $obj |
188 | 188 | * @return string |
189 | 189 | */ |
190 | - public function get_class($obj){ |
|
190 | + public function get_class($obj) { |
|
191 | 191 | return get_class($obj); |
192 | 192 | } |
193 | 193 | |
@@ -200,24 +200,24 @@ discard block |
||
200 | 200 | * @param mixed $field_value |
201 | 201 | * @param bool $use_default |
202 | 202 | */ |
203 | - public function set( $field_name, $field_value, $use_default = FALSE ){ |
|
204 | - $field_obj = $this->get_model()->field_settings_for( $field_name ); |
|
205 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
206 | - if ( method_exists( $field_obj, 'set_timezone' )) { |
|
207 | - $field_obj->set_timezone( $this->_timezone ); |
|
203 | + public function set($field_name, $field_value, $use_default = FALSE) { |
|
204 | + $field_obj = $this->get_model()->field_settings_for($field_name); |
|
205 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
206 | + if (method_exists($field_obj, 'set_timezone')) { |
|
207 | + $field_obj->set_timezone($this->_timezone); |
|
208 | 208 | } |
209 | 209 | $holder_of_value = $field_obj->prepare_for_set($field_value); |
210 | - if( ($field_value === NULL || $holder_of_value === NULL || $holder_of_value ==='') && $use_default){ |
|
210 | + if (($field_value === NULL || $holder_of_value === NULL || $holder_of_value === '') && $use_default) { |
|
211 | 211 | $this->_fields[$field_name] = $field_obj->get_default_value(); |
212 | - }else{ |
|
212 | + } else { |
|
213 | 213 | $this->_fields[$field_name] = $holder_of_value; |
214 | 214 | } |
215 | 215 | |
216 | 216 | //if we're not in the constructor... |
217 | 217 | //now check if what we set was a primary key |
218 | - if($this->_props_n_values_provided_in_constructor && //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
218 | + if ($this->_props_n_values_provided_in_constructor && //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
219 | 219 | $field_name == $this->_get_primary_key_name(get_class($this)) && |
220 | - $field_value){ |
|
220 | + $field_value) { |
|
221 | 221 | //if so, we want all this object's fields to be filled either with |
222 | 222 | //what we've explicitly set on this model |
223 | 223 | //or what we have in the db |
@@ -225,19 +225,19 @@ discard block |
||
225 | 225 | $fields_on_model = $this->_get_model(get_class($this))->field_settings(); |
226 | 226 | |
227 | 227 | $obj_in_db = $this->_get_model(get_class($this))->get_one_by_ID($field_value); |
228 | - foreach($fields_on_model as $field_obj){ |
|
229 | - if( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
230 | - && $field_obj->get_name() != $field_name ){ |
|
228 | + foreach ($fields_on_model as $field_obj) { |
|
229 | + if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
230 | + && $field_obj->get_name() != $field_name) { |
|
231 | 231 | |
232 | - $this->set($field_obj->get_name(),$obj_in_db->get($field_obj->get_name())); |
|
232 | + $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
233 | 233 | } |
234 | 234 | } |
235 | 235 | //oh this model object has an ID? well make sure its in the entity mapper |
236 | 236 | $this->get_model()->add_to_entity_map($this); |
237 | 237 | } |
238 | 238 | //let's unset any cache for this field_name from the $_cached_properties property. |
239 | - $this->_clear_cached_property( $field_name ); |
|
240 | - }else{ |
|
239 | + $this->_clear_cached_property($field_name); |
|
240 | + } else { |
|
241 | 241 | echo "\r\n\r\nSAAAY WHAT?? $field_name doesnt have a field???"; |
242 | 242 | } |
243 | 243 | |
@@ -253,17 +253,17 @@ discard block |
||
253 | 253 | * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php |
254 | 254 | * @return void |
255 | 255 | */ |
256 | - public function set_timezone( $timezone = '' ) { |
|
257 | - $timezone = empty( $timezone ) ? get_option( 'timezone_string' ) : $timezone; |
|
256 | + public function set_timezone($timezone = '') { |
|
257 | + $timezone = empty($timezone) ? get_option('timezone_string') : $timezone; |
|
258 | 258 | |
259 | 259 | //if timezone is STILL empty then let's get the GMT offset and then set the timezone_string using our converter |
260 | - if ( empty( $timezone ) ) { |
|
260 | + if (empty($timezone)) { |
|
261 | 261 | //let's get a the WordPress UTC offset |
262 | 262 | $offset = get_option('gmt_offset'); |
263 | - $timezone = EE_Datetime_Field::timezone_convert_to_string_from_offset( $offset ); |
|
263 | + $timezone = EE_Datetime_Field::timezone_convert_to_string_from_offset($offset); |
|
264 | 264 | } |
265 | 265 | |
266 | - EE_Datetime_Field::validate_timezone( $timezone ); //just running validation on the timezone. |
|
266 | + EE_Datetime_Field::validate_timezone($timezone); //just running validation on the timezone. |
|
267 | 267 | $this->_timezone = $timezone; |
268 | 268 | //make sure we clear all cached properties because they won't be relevant now |
269 | 269 | $this->_clear_cached_properties(); |
@@ -294,11 +294,11 @@ discard block |
||
294 | 294 | * @param string $dt_frmt |
295 | 295 | * @return string |
296 | 296 | */ |
297 | - public static function fix_date_format_for_use_with_strtotime( $dt_frmt ) { |
|
297 | + public static function fix_date_format_for_use_with_strtotime($dt_frmt) { |
|
298 | 298 | // if the date format is d/m/y |
299 | - if ( strpos( $dt_frmt, 'd/' )=== 0 ) { |
|
299 | + if (strpos($dt_frmt, 'd/') === 0) { |
|
300 | 300 | // change it to d-m-y, or else strtotime() will think it is m/d/y |
301 | - $dt_frmt = str_replace( '/', '-', $dt_frmt ); |
|
301 | + $dt_frmt = str_replace('/', '-', $dt_frmt); |
|
302 | 302 | } |
303 | 303 | return $dt_frmt; |
304 | 304 | } |
@@ -316,17 +316,17 @@ discard block |
||
316 | 316 | * @throws EE_Error |
317 | 317 | * @return mixed index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one related thing, no array) |
318 | 318 | */ |
319 | - public function cache( $relationName = '', $object_to_cache = NULL, $cache_id = NULL ){ |
|
319 | + public function cache($relationName = '', $object_to_cache = NULL, $cache_id = NULL) { |
|
320 | 320 | // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
321 | - if ( ! $object_to_cache instanceof EE_Base_Class ) { |
|
321 | + if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
322 | 322 | return FALSE; |
323 | 323 | } |
324 | 324 | // also get "how" the object is related, or throw an error |
325 | - if( ! $relationship_to_model = $this->get_model()->related_settings_for( $relationName )) { |
|
326 | - throw new EE_Error( sprintf( __( 'There is no relationship to %s on a %s. Cannot cache it', 'event_espresso' ), $relationName, get_class( $this ))); |
|
325 | + if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
326 | + throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), $relationName, get_class($this))); |
|
327 | 327 | } |
328 | 328 | // how many things are related ? |
329 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ){ |
|
329 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
330 | 330 | // if it's a "belongs to" relationship, then there's only one related model object eg, if this is a registration, there's only 1 attendee for it |
331 | 331 | // so for these model objects just set it to be cached |
332 | 332 | $this->_model_relations[$relationName] = $object_to_cache; |
@@ -334,26 +334,26 @@ discard block |
||
334 | 334 | } else { |
335 | 335 | // otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type. |
336 | 336 | // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
337 | - if( ! is_array( $this->_model_relations[$relationName] )) { |
|
337 | + if ( ! is_array($this->_model_relations[$relationName])) { |
|
338 | 338 | // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
339 | - $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array( $this->_model_relations[$relationName] ) : array(); |
|
339 | + $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array($this->_model_relations[$relationName]) : array(); |
|
340 | 340 | } |
341 | 341 | // first check for a cache_id which is normally empty |
342 | - if ( ! empty( $cache_id )) { |
|
342 | + if ( ! empty($cache_id)) { |
|
343 | 343 | // if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on |
344 | - $this->_model_relations[$relationName][ $cache_id ] = $object_to_cache; |
|
344 | + $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
345 | 345 | $return = $cache_id; |
346 | - } elseif ( $object_to_cache->ID() ) { |
|
346 | + } elseif ($object_to_cache->ID()) { |
|
347 | 347 | // OR the cached object originally came from the db, so let's just use it's PK for an ID |
348 | - $this->_model_relations[$relationName][ $object_to_cache->ID() ] = $object_to_cache; |
|
348 | + $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
349 | 349 | $return = $object_to_cache->ID(); |
350 | 350 | } else { |
351 | 351 | // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
352 | 352 | $this->_model_relations[$relationName][] = $object_to_cache; |
353 | 353 | // move the internal pointer to the end of the array |
354 | - end( $this->_model_relations[$relationName] ); |
|
354 | + end($this->_model_relations[$relationName]); |
|
355 | 355 | // and grab the key so that we can return it |
356 | - $return = key( $this->_model_relations[$relationName] ); |
|
356 | + $return = key($this->_model_relations[$relationName]); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | } |
@@ -371,11 +371,11 @@ discard block |
||
371 | 371 | * @param null $cache_type |
372 | 372 | * @return void |
373 | 373 | */ |
374 | - protected function _set_cached_property( $fieldname, $value, $cache_type = NULL ) { |
|
374 | + protected function _set_cached_property($fieldname, $value, $cache_type = NULL) { |
|
375 | 375 | //first make sure this property exists |
376 | 376 | $this->get_model()->field_settings_for($fieldname); |
377 | 377 | |
378 | - $cache_type = empty( $cache_type ) ? 'standard' : $cache_type; |
|
378 | + $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
379 | 379 | $this->_cached_properties[$fieldname][$cache_type] = $value; |
380 | 380 | } |
381 | 381 | |
@@ -390,24 +390,24 @@ discard block |
||
390 | 390 | * It can also accept certain pre-defined "schema" strings to define how to output the property. see the field's prepare_for_pretty_echoing for what strings can be used |
391 | 391 | * @return mixed whatever the value for the property is we're retrieving |
392 | 392 | */ |
393 | - protected function _get_cached_property( $fieldname, $pretty = FALSE, $extra_cache_ref = NULL ) { |
|
393 | + protected function _get_cached_property($fieldname, $pretty = FALSE, $extra_cache_ref = NULL) { |
|
394 | 394 | //verify the field exists |
395 | 395 | $this->get_model()->field_settings_for($fieldname); |
396 | 396 | |
397 | 397 | $cache_type = $pretty ? 'pretty' : 'standard'; |
398 | - $cache_type .= !empty( $extra_cache_ref ) ? '_' . $extra_cache_ref : ''; |
|
398 | + $cache_type .= ! empty($extra_cache_ref) ? '_'.$extra_cache_ref : ''; |
|
399 | 399 | |
400 | - if ( isset( $this->_cached_properties[$fieldname][$cache_type] ) ) { |
|
400 | + if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
401 | 401 | return $this->_cached_properties[$fieldname][$cache_type]; |
402 | 402 | } |
403 | 403 | |
404 | 404 | $field_obj = $this->get_model()->field_settings_for($fieldname); |
405 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
406 | - if( ! isset($this->_fields[$fieldname])){ |
|
405 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
406 | + if ( ! isset($this->_fields[$fieldname])) { |
|
407 | 407 | $this->_fields[$fieldname] = NULL; |
408 | 408 | } |
409 | - $value = $pretty ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) : $field_obj->prepare_for_get($this->_fields[$fieldname] ); |
|
410 | - $this->_set_cached_property( $fieldname, $value, $cache_type ); |
|
409 | + $value = $pretty ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
410 | + $this->_set_cached_property($fieldname, $value, $cache_type); |
|
411 | 411 | return $value; |
412 | 412 | } |
413 | 413 | return FALSE; |
@@ -433,9 +433,9 @@ discard block |
||
433 | 433 | * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
434 | 434 | * @return void |
435 | 435 | */ |
436 | - protected function _clear_cached_property( $property_name ) { |
|
437 | - if ( isset( $this->_cached_properties[ $property_name ] ) ) |
|
438 | - unset( $this->_cached_properties[ $property_name ] ); |
|
436 | + protected function _clear_cached_property($property_name) { |
|
437 | + if (isset($this->_cached_properties[$property_name])) |
|
438 | + unset($this->_cached_properties[$property_name]); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | * @param string $model_name name of the related thing, eg 'Attendee', |
447 | 447 | * @return EE_Base_Class |
448 | 448 | */ |
449 | - protected function ensure_related_thing_is_model_obj($object_or_id,$model_name){ |
|
449 | + protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) { |
|
450 | 450 | $other_model_instance = self::_get_model_instance_with_name(self::_get_model_classname($model_name), $this->_timezone); |
451 | 451 | $model_obj = $other_model_instance->ensure_is_obj($object_or_id); |
452 | 452 | return $model_obj; |
@@ -466,55 +466,55 @@ discard block |
||
466 | 466 | * @throws EE_Error |
467 | 467 | * @return EE_Base_Class from which was cleared from the cache, or true if we requested to remove a relation from all |
468 | 468 | */ |
469 | - public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE){ |
|
469 | + public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE) { |
|
470 | 470 | $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
471 | 471 | $index_in_cache = ''; |
472 | - if( ! $relationship_to_model){ |
|
473 | - throw new EE_Error(sprintf(__("There is no relationship to %s on a %s. Cannot clear that cache",'event_espresso'),$relationName,get_class($this))); |
|
472 | + if ( ! $relationship_to_model) { |
|
473 | + throw new EE_Error(sprintf(__("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), $relationName, get_class($this))); |
|
474 | 474 | } |
475 | - if($clear_all){ |
|
475 | + if ($clear_all) { |
|
476 | 476 | $obj_removed = true; |
477 | 477 | $this->_model_relations[$relationName] = null; |
478 | - }elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
478 | + }elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
479 | 479 | $obj_removed = $this->_model_relations[$relationName]; |
480 | 480 | $this->_model_relations[$relationName] = null; |
481 | - }else{ |
|
482 | - if($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()){ |
|
481 | + } else { |
|
482 | + if ($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()) { |
|
483 | 483 | $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
484 | - if( is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])){ |
|
484 | + if (is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])) { |
|
485 | 485 | $index_found_at = NULL; |
486 | 486 | //find this object in the array even though it has a different key |
487 | - foreach($this->_model_relations[$relationName] as $index=>$obj){ |
|
488 | - if( $obj instanceof EE_Base_Class && ( $obj == $object_to_remove_or_index_into_array || $obj->ID() == $object_to_remove_or_index_into_array->ID() )) { |
|
487 | + foreach ($this->_model_relations[$relationName] as $index=>$obj) { |
|
488 | + if ($obj instanceof EE_Base_Class && ($obj == $object_to_remove_or_index_into_array || $obj->ID() == $object_to_remove_or_index_into_array->ID())) { |
|
489 | 489 | $index_found_at = $index; |
490 | 490 | break; |
491 | 491 | } |
492 | 492 | } |
493 | - if($index_found_at){ |
|
493 | + if ($index_found_at) { |
|
494 | 494 | $index_in_cache = $index_found_at; |
495 | - }else{ |
|
495 | + } else { |
|
496 | 496 | //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
497 | 497 | //if it wasn't in it to begin with. So we're done |
498 | 498 | return $object_to_remove_or_index_into_array; |
499 | 499 | } |
500 | 500 | } |
501 | - }elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
501 | + }elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
502 | 502 | //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
503 | - foreach($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want){ |
|
504 | - if($potentially_obj_we_want == $object_to_remove_or_index_into_array){ |
|
503 | + foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
504 | + if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
505 | 505 | $index_in_cache = $index; |
506 | 506 | } |
507 | 507 | } |
508 | - }else{ |
|
508 | + } else { |
|
509 | 509 | $index_in_cache = $object_to_remove_or_index_into_array; |
510 | 510 | } |
511 | 511 | //supposedly we've found it. But it could just be that the client code |
512 | 512 | //provided a bad index/object |
513 | - if(isset( $this->_model_relations[$relationName]) && |
|
514 | - isset( $this->_model_relations[$relationName][$index_in_cache])){ |
|
513 | + if (isset($this->_model_relations[$relationName]) && |
|
514 | + isset($this->_model_relations[$relationName][$index_in_cache])) { |
|
515 | 515 | $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
516 | 516 | unset($this->_model_relations[$relationName][$index_in_cache]); |
517 | - }else{ |
|
517 | + } else { |
|
518 | 518 | //that thing was never cached anyways. |
519 | 519 | $obj_removed = NULL; |
520 | 520 | } |
@@ -533,24 +533,24 @@ discard block |
||
533 | 533 | * @param string $current_cache_id - the ID that was used when originally caching the object |
534 | 534 | * @return boolean TRUE on success, FALSE on fail |
535 | 535 | */ |
536 | - public function update_cache_after_object_save( $relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
536 | + public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
537 | 537 | // verify that incoming object is of the correct type |
538 | - $obj_class = 'EE_' . $relationName; |
|
539 | - if ( $newly_saved_object instanceof $obj_class ) { |
|
538 | + $obj_class = 'EE_'.$relationName; |
|
539 | + if ($newly_saved_object instanceof $obj_class) { |
|
540 | 540 | /* @type EE_Base_Class $newly_saved_object*/ |
541 | 541 | // now get the type of relation |
542 | - $relationship_to_model = $this->get_model()->related_settings_for( $relationName ); |
|
542 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
543 | 543 | // if this is a 1:1 relationship |
544 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ) { |
|
544 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
545 | 545 | // then just replace the cached object with the newly saved object |
546 | 546 | $this->_model_relations[$relationName] = $newly_saved_object; |
547 | 547 | return TRUE; |
548 | 548 | // or if it's some kind of sordid feral polyamorous relationship... |
549 | - } elseif ( is_array( $this->_model_relations[$relationName] ) && isset( $this->_model_relations[$relationName][ $current_cache_id ] )) { |
|
549 | + } elseif (is_array($this->_model_relations[$relationName]) && isset($this->_model_relations[$relationName][$current_cache_id])) { |
|
550 | 550 | // then remove the current cached item |
551 | - unset( $this->_model_relations[$relationName][ $current_cache_id ] ); |
|
551 | + unset($this->_model_relations[$relationName][$current_cache_id]); |
|
552 | 552 | // and cache the newly saved object using it's new ID |
553 | - $this->_model_relations[$relationName][ $newly_saved_object->ID() ] = $newly_saved_object; |
|
553 | + $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
554 | 554 | return TRUE; |
555 | 555 | } |
556 | 556 | } |
@@ -566,11 +566,11 @@ discard block |
||
566 | 566 | * @param string $relationName |
567 | 567 | * @return EE_Base_Class |
568 | 568 | */ |
569 | - public function get_one_from_cache($relationName){ |
|
570 | - $cached_array_or_object = $this->_model_relations[$relationName]; |
|
571 | - if(is_array($cached_array_or_object)){ |
|
569 | + public function get_one_from_cache($relationName) { |
|
570 | + $cached_array_or_object = $this->_model_relations[$relationName]; |
|
571 | + if (is_array($cached_array_or_object)) { |
|
572 | 572 | return array_shift($cached_array_or_object); |
573 | - }else{ |
|
573 | + } else { |
|
574 | 574 | return $cached_array_or_object; |
575 | 575 | } |
576 | 576 | } |
@@ -585,14 +585,14 @@ discard block |
||
585 | 585 | * @throws \EE_Error |
586 | 586 | * @return EE_Base_Class[] |
587 | 587 | */ |
588 | - public function get_all_from_cache($relationName){ |
|
589 | - $cached_array_or_object = $this->_model_relations[$relationName]; |
|
590 | - if(is_array($cached_array_or_object)){ |
|
588 | + public function get_all_from_cache($relationName) { |
|
589 | + $cached_array_or_object = $this->_model_relations[$relationName]; |
|
590 | + if (is_array($cached_array_or_object)) { |
|
591 | 591 | $objects = $cached_array_or_object; |
592 | - }elseif($cached_array_or_object){ |
|
592 | + }elseif ($cached_array_or_object) { |
|
593 | 593 | //if the result is not an array, but exists, make it an array |
594 | 594 | $objects = array($cached_array_or_object); |
595 | - }else{ |
|
595 | + } else { |
|
596 | 596 | //if nothing was found, return an empty array |
597 | 597 | $objects = array(); |
598 | 598 | } |
@@ -600,15 +600,15 @@ discard block |
||
600 | 600 | //basically, if this model object was stored in the session, and these cached model objects |
601 | 601 | //already have IDs, let's make sure they're in their model's entity mapper |
602 | 602 | //otherwise we will have duplicates next time we call EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
603 | - foreach( $objects as $model_object ){ |
|
604 | - $model = EE_Registry::instance()->load_model( $relationName ); |
|
605 | - if( $model instanceof EEM_Base && $model_object instanceof EE_Base_Class ){ |
|
603 | + foreach ($objects as $model_object) { |
|
604 | + $model = EE_Registry::instance()->load_model($relationName); |
|
605 | + if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
606 | 606 | //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
607 | - if( $model_object->ID() ){ |
|
608 | - $model->add_to_entity_map( $model_object ); |
|
607 | + if ($model_object->ID()) { |
|
608 | + $model->add_to_entity_map($model_object); |
|
609 | 609 | } |
610 | - }else{ |
|
611 | - throw new EE_Error( sprintf( __( 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', 'event_espresso' ), $relationName, gettype( $model_object ))); |
|
610 | + } else { |
|
611 | + throw new EE_Error(sprintf(__('Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', 'event_espresso'), $relationName, gettype($model_object))); |
|
612 | 612 | } |
613 | 613 | } |
614 | 614 | return $objects; |
@@ -627,13 +627,13 @@ discard block |
||
627 | 627 | * |
628 | 628 | * @return array|EE_Base_Class[] |
629 | 629 | */ |
630 | - public function next_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
631 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
632 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
633 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
630 | + public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
631 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
632 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
633 | + if (empty($field) || empty($current_value)) { |
|
634 | 634 | return array(); |
635 | 635 | } |
636 | - return $this->get_model()->next_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
636 | + return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | |
@@ -652,13 +652,13 @@ discard block |
||
652 | 652 | * |
653 | 653 | * @return array|EE_Base_Class[] |
654 | 654 | */ |
655 | - public function previous_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
656 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
657 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
658 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
655 | + public function previous_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
656 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
657 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
658 | + if (empty($field) || empty($current_value)) { |
|
659 | 659 | return array(); |
660 | 660 | } |
661 | - return $this->get_model()->previous_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
661 | + return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
662 | 662 | } |
663 | 663 | |
664 | 664 | |
@@ -676,13 +676,13 @@ discard block |
||
676 | 676 | * |
677 | 677 | * @return array|EE_Base_Class |
678 | 678 | */ |
679 | - public function next( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
680 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
681 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
682 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
679 | + public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
680 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
681 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
682 | + if (empty($field) || empty($current_value)) { |
|
683 | 683 | return array(); |
684 | 684 | } |
685 | - return $this->get_model()->next( $current_value, $field, $query_params, $columns_to_select ); |
|
685 | + return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select); |
|
686 | 686 | } |
687 | 687 | |
688 | 688 | |
@@ -701,13 +701,13 @@ discard block |
||
701 | 701 | * |
702 | 702 | * @return array|EE_Base_Class |
703 | 703 | */ |
704 | - public function previous( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
705 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
706 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
707 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
704 | + public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
705 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
706 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
707 | + if (empty($field) || empty($current_value)) { |
|
708 | 708 | return array(); |
709 | 709 | } |
710 | - return $this->get_model()->previous( $current_value, $field, $query_params, $columns_to_select ); |
|
710 | + return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select); |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | |
@@ -721,20 +721,20 @@ discard block |
||
721 | 721 | * @param string $field_name |
722 | 722 | * @param mixed $field_value_from_db |
723 | 723 | */ |
724 | - public function set_from_db($field_name,$field_value_from_db){ |
|
724 | + public function set_from_db($field_name, $field_value_from_db) { |
|
725 | 725 | $field_obj = $this->get_model()->field_settings_for($field_name); |
726 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
726 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
727 | 727 | //you would think the DB has no NULLs for non-null label fields right? wrong! |
728 | 728 | //eg, a CPT model object could have an entry in the posts table, but no |
729 | 729 | //entry in the meta table. Meaning that all its columns in the meta table |
730 | 730 | //are null! yikes! so when we find one like that, use defaults for its meta columns |
731 | - if($field_value_from_db === NULL && ! $field_obj->is_nullable()){ |
|
731 | + if ($field_value_from_db === NULL && ! $field_obj->is_nullable()) { |
|
732 | 732 | $field_value = $field_obj->get_default_value(); |
733 | - }else{ |
|
733 | + } else { |
|
734 | 734 | $field_value = $field_value_from_db; |
735 | 735 | } |
736 | 736 | $this->_fields[$field_name] = $field_obj->prepare_for_set_from_db($field_value); |
737 | - $this->_clear_cached_property( $field_name ); |
|
737 | + $this->_clear_cached_property($field_name); |
|
738 | 738 | } |
739 | 739 | } |
740 | 740 | |
@@ -746,8 +746,8 @@ discard block |
||
746 | 746 | * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property (in cases where the same property may be used for different outputs - i.e. datetime, money etc.) |
747 | 747 | * @return boolean |
748 | 748 | */ |
749 | - public function get($field_name, $extra_cache_ref = NULL ){ |
|
750 | - return $this->_get_cached_property( $field_name, FALSE, $extra_cache_ref ); |
|
749 | + public function get($field_name, $extra_cache_ref = NULL) { |
|
750 | + return $this->_get_cached_property($field_name, FALSE, $extra_cache_ref); |
|
751 | 751 | } |
752 | 752 | |
753 | 753 | |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property (in cases where the same property may be used for different outputs - i.e. datetime, money etc.) |
773 | 773 | * @return void |
774 | 774 | */ |
775 | - public function e($field_name, $extra_cache_ref = NULL){ |
|
775 | + public function e($field_name, $extra_cache_ref = NULL) { |
|
776 | 776 | echo $this->get_pretty($field_name, $extra_cache_ref); |
777 | 777 | } |
778 | 778 | /** |
@@ -781,8 +781,8 @@ discard block |
||
781 | 781 | * @param string $field_name |
782 | 782 | * @return void |
783 | 783 | */ |
784 | - public function f($field_name){ |
|
785 | - $this->e($field_name,'form_input'); |
|
784 | + public function f($field_name) { |
|
785 | + $this->e($field_name, 'form_input'); |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | /** |
@@ -791,8 +791,8 @@ discard block |
||
791 | 791 | * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property (in cases where the same property may be used for different outputs - i.e. datetime, money etc.) |
792 | 792 | * @return mixed |
793 | 793 | */ |
794 | - public function get_pretty($field_name, $extra_cache_ref = NULL){ |
|
795 | - return $this->_get_cached_property( $field_name, TRUE, $extra_cache_ref ); |
|
794 | + public function get_pretty($field_name, $extra_cache_ref = NULL) { |
|
795 | + return $this->_get_cached_property($field_name, TRUE, $extra_cache_ref); |
|
796 | 796 | } |
797 | 797 | |
798 | 798 | |
@@ -809,36 +809,36 @@ discard block |
||
809 | 809 | * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
810 | 810 | * @return void | string | bool | EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown if field is not a valid dtt field, or void if echoing |
811 | 811 | */ |
812 | - protected function _get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE ) { |
|
812 | + protected function _get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE) { |
|
813 | 813 | |
814 | - $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : EE_Base_Class::fix_date_format_for_use_with_strtotime( $dt_frmt ); |
|
814 | + $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : EE_Base_Class::fix_date_format_for_use_with_strtotime($dt_frmt); |
|
815 | 815 | $in_tm_frmt = empty($tm_frmt) ? $this->_tm_frmt : $tm_frmt; |
816 | 816 | |
817 | 817 | |
818 | 818 | //validate field for datetime and returns field settings if valid. |
819 | - $field = $this->_get_dtt_field_settings( $field_name ); |
|
819 | + $field = $this->_get_dtt_field_settings($field_name); |
|
820 | 820 | |
821 | - if ( $dt_frmt !== NULL ) { |
|
822 | - $this->_clear_cached_property( $field_name, $date_or_time ); |
|
821 | + if ($dt_frmt !== NULL) { |
|
822 | + $this->_clear_cached_property($field_name, $date_or_time); |
|
823 | 823 | } |
824 | - if ( $echo ) |
|
825 | - $field->set_pretty_date_format( $in_dt_frmt ); |
|
824 | + if ($echo) |
|
825 | + $field->set_pretty_date_format($in_dt_frmt); |
|
826 | 826 | else |
827 | - $field->set_date_format( $in_dt_frmt ); |
|
827 | + $field->set_date_format($in_dt_frmt); |
|
828 | 828 | |
829 | - if ( $tm_frmt !== NULL ) { |
|
830 | - $this->_clear_cached_property( $field_name, $date_or_time ); |
|
829 | + if ($tm_frmt !== NULL) { |
|
830 | + $this->_clear_cached_property($field_name, $date_or_time); |
|
831 | 831 | } |
832 | - if ( $echo ) |
|
833 | - $field->set_pretty_time_format( $in_tm_frmt ); |
|
832 | + if ($echo) |
|
833 | + $field->set_pretty_time_format($in_tm_frmt); |
|
834 | 834 | else |
835 | - $field->set_time_format( $in_tm_frmt ); |
|
835 | + $field->set_time_format($in_tm_frmt); |
|
836 | 836 | |
837 | 837 | //set timezone in field object |
838 | - $field->set_timezone( $this->_timezone ); |
|
838 | + $field->set_timezone($this->_timezone); |
|
839 | 839 | |
840 | 840 | //set the output returned |
841 | - switch ( $date_or_time ) { |
|
841 | + switch ($date_or_time) { |
|
842 | 842 | |
843 | 843 | case 'D' : |
844 | 844 | $field->set_date_time_output('date'); |
@@ -853,11 +853,11 @@ discard block |
||
853 | 853 | } |
854 | 854 | |
855 | 855 | |
856 | - if ( $echo ) { |
|
857 | - $this->e( $field_name, $date_or_time ); |
|
856 | + if ($echo) { |
|
857 | + $this->e($field_name, $date_or_time); |
|
858 | 858 | return ''; |
859 | 859 | } |
860 | - return $this->get( $field_name, $date_or_time ); |
|
860 | + return $this->get($field_name, $date_or_time); |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | |
@@ -867,8 +867,8 @@ discard block |
||
867 | 867 | * @param string $format format for the date returned (if NULL we use default in dt_frmt property) |
868 | 868 | * @return string datetime value formatted |
869 | 869 | */ |
870 | - public function get_date( $field_name, $format = NULL ) { |
|
871 | - return $this->_get_datetime( $field_name, $format, NULL, 'D' ); |
|
870 | + public function get_date($field_name, $format = NULL) { |
|
871 | + return $this->_get_datetime($field_name, $format, NULL, 'D'); |
|
872 | 872 | } |
873 | 873 | |
874 | 874 | |
@@ -877,8 +877,8 @@ discard block |
||
877 | 877 | * @param $field_name |
878 | 878 | * @param null $format |
879 | 879 | */ |
880 | - public function e_date( $field_name, $format = NULL ) { |
|
881 | - $this->_get_datetime( $field_name, $format, NULL, 'D', TRUE ); |
|
880 | + public function e_date($field_name, $format = NULL) { |
|
881 | + $this->_get_datetime($field_name, $format, NULL, 'D', TRUE); |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | |
@@ -888,8 +888,8 @@ discard block |
||
888 | 888 | * @param string $format format for the time returned ( if NULL we use default in tm_frmt property) |
889 | 889 | * @return string datetime value formatted |
890 | 890 | */ |
891 | - public function get_time( $field_name, $format = NULL ) { |
|
892 | - return $this->_get_datetime( $field_name, NULL, $format, 'T' ); |
|
891 | + public function get_time($field_name, $format = NULL) { |
|
892 | + return $this->_get_datetime($field_name, NULL, $format, 'T'); |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | |
@@ -898,8 +898,8 @@ discard block |
||
898 | 898 | * @param $field_name |
899 | 899 | * @param null $format |
900 | 900 | */ |
901 | - public function e_time( $field_name, $format = NULL ) { |
|
902 | - $this->_get_datetime( $field_name, NULL, $format, 'T', TRUE ); |
|
901 | + public function e_time($field_name, $format = NULL) { |
|
902 | + $this->_get_datetime($field_name, NULL, $format, 'T', TRUE); |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | |
@@ -912,8 +912,8 @@ discard block |
||
912 | 912 | * @param string $tm_frmt format for the time returned (if NULL we use default in tm_frmt property) |
913 | 913 | * @return string datetime value formatted |
914 | 914 | */ |
915 | - public function get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
916 | - return $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt ); |
|
915 | + public function get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
916 | + return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
917 | 917 | } |
918 | 918 | |
919 | 919 | |
@@ -923,8 +923,8 @@ discard block |
||
923 | 923 | * @param null $dt_frmt |
924 | 924 | * @param null $tm_frmt |
925 | 925 | */ |
926 | - public function e_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
927 | - $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
926 | + public function e_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
927 | + $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
928 | 928 | } |
929 | 929 | |
930 | 930 | |
@@ -938,9 +938,9 @@ discard block |
||
938 | 938 | * |
939 | 939 | * @return string Date and time string in set locale. |
940 | 940 | */ |
941 | - public function get_i18n_datetime( $field_name, $format = NULL ) { |
|
942 | - $format = empty( $format ) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
943 | - return date_i18n( $format, strtotime( $this->_get_datetime( $field_name, NULL, NULL, NULL, false ) ) ); |
|
941 | + public function get_i18n_datetime($field_name, $format = NULL) { |
|
942 | + $format = empty($format) ? $this->_dt_frmt.' '.$this->_tm_frmt : $format; |
|
943 | + return date_i18n($format, strtotime($this->_get_datetime($field_name, NULL, NULL, NULL, false))); |
|
944 | 944 | } |
945 | 945 | |
946 | 946 | |
@@ -951,14 +951,14 @@ discard block |
||
951 | 951 | * @throws EE_Error |
952 | 952 | * @return EE_Datetime_Field |
953 | 953 | */ |
954 | - protected function _get_dtt_field_settings( $field_name ) { |
|
954 | + protected function _get_dtt_field_settings($field_name) { |
|
955 | 955 | $field = $this->get_model()->field_settings_for($field_name); |
956 | 956 | |
957 | 957 | //check if field is dtt |
958 | - if ( $field instanceof EE_Datetime_Field ) { |
|
958 | + if ($field instanceof EE_Datetime_Field) { |
|
959 | 959 | return $field; |
960 | 960 | } else { |
961 | - throw new EE_Error( sprintf( __('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', 'event_espresso'), $field_name, self::_get_model_classname( get_class($this) ) ) ); |
|
961 | + throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', 'event_espresso'), $field_name, self::_get_model_classname(get_class($this)))); |
|
962 | 962 | } |
963 | 963 | } |
964 | 964 | |
@@ -979,8 +979,8 @@ discard block |
||
979 | 979 | * @param string $time a valid time string for php datetime functions |
980 | 980 | * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
981 | 981 | */ |
982 | - protected function _set_time_for( $time, $fieldname ) { |
|
983 | - $this->_set_date_time( 'T', $time, $fieldname ); |
|
982 | + protected function _set_time_for($time, $fieldname) { |
|
983 | + $this->_set_date_time('T', $time, $fieldname); |
|
984 | 984 | } |
985 | 985 | |
986 | 986 | |
@@ -994,8 +994,8 @@ discard block |
||
994 | 994 | * @param string $date a valid date string for php datetime functions |
995 | 995 | * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
996 | 996 | */ |
997 | - protected function _set_date_for( $date, $fieldname ) { |
|
998 | - $this->_set_date_time( 'D', $date, $fieldname ); |
|
997 | + protected function _set_date_for($date, $fieldname) { |
|
998 | + $this->_set_date_time('D', $date, $fieldname); |
|
999 | 999 | } |
1000 | 1000 | |
1001 | 1001 | |
@@ -1011,19 +1011,19 @@ discard block |
||
1011 | 1011 | * @param string $datetime_value A valid Date or Time string |
1012 | 1012 | * @param string $fieldname the name of the field the date OR time is being set on (must match a EE_Datetime_Field property) |
1013 | 1013 | */ |
1014 | - protected function _set_date_time( $what = 'T', $datetime_value, $fieldname ) { |
|
1015 | - $field = $this->_get_dtt_field_settings( $fieldname ); |
|
1016 | - $field->set_timezone( $this->_timezone ); |
|
1014 | + protected function _set_date_time($what = 'T', $datetime_value, $fieldname) { |
|
1015 | + $field = $this->_get_dtt_field_settings($fieldname); |
|
1016 | + $field->set_timezone($this->_timezone); |
|
1017 | 1017 | |
1018 | - switch ( $what ) { |
|
1018 | + switch ($what) { |
|
1019 | 1019 | case 'T' : |
1020 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( $datetime_value, $this->_fields[$fieldname] ); |
|
1020 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time($datetime_value, $this->_fields[$fieldname]); |
|
1021 | 1021 | break; |
1022 | 1022 | case 'D' : |
1023 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( $datetime_value, $this->_fields[$fieldname] ); |
|
1023 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date($datetime_value, $this->_fields[$fieldname]); |
|
1024 | 1024 | break; |
1025 | 1025 | case 'B' : |
1026 | - $this->_fields[$fieldname] = $field->prepare_for_set( $datetime_value ); |
|
1026 | + $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
1027 | 1027 | break; |
1028 | 1028 | } |
1029 | 1029 | |
@@ -1046,25 +1046,25 @@ discard block |
||
1046 | 1046 | * @throws EE_Error |
1047 | 1047 | * @return string timestamp |
1048 | 1048 | */ |
1049 | - public function display_in_my_timezone( $field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '' ) { |
|
1049 | + public function display_in_my_timezone($field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '') { |
|
1050 | 1050 | EE_Registry::instance()->load_helper('DTT_Helper'); |
1051 | 1051 | $timezone = EEH_DTT_Helper::get_timezone(); |
1052 | 1052 | |
1053 | - if ( $timezone == $this->_timezone ) |
|
1053 | + if ($timezone == $this->_timezone) |
|
1054 | 1054 | return ''; |
1055 | 1055 | |
1056 | 1056 | $original_timezone = $this->_timezone; |
1057 | - $this->set_timezone( $timezone ); |
|
1057 | + $this->set_timezone($timezone); |
|
1058 | 1058 | |
1059 | 1059 | $fn = (array) $field_name; |
1060 | - $args = array_merge( $fn, (array) $args ); |
|
1060 | + $args = array_merge($fn, (array) $args); |
|
1061 | 1061 | |
1062 | - if ( !method_exists( $this, $callback ) ) |
|
1063 | - throw new EE_Error(sprintf( __('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback ) ); |
|
1062 | + if ( ! method_exists($this, $callback)) |
|
1063 | + throw new EE_Error(sprintf(__('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback)); |
|
1064 | 1064 | $args = (array) $args; |
1065 | - $return = $prepend . call_user_func_array( array( $this, $callback ), $args ) . $append; |
|
1065 | + $return = $prepend.call_user_func_array(array($this, $callback), $args).$append; |
|
1066 | 1066 | |
1067 | - $this->set_timezone( $original_timezone ); |
|
1067 | + $this->set_timezone($original_timezone); |
|
1068 | 1068 | return $return; |
1069 | 1069 | } |
1070 | 1070 | |
@@ -1075,20 +1075,20 @@ discard block |
||
1075 | 1075 | * Deletes this model object. That may mean just 'soft deleting' it though. |
1076 | 1076 | * @return boolean | int |
1077 | 1077 | */ |
1078 | - public function delete(){ |
|
1078 | + public function delete() { |
|
1079 | 1079 | /** |
1080 | 1080 | * Called just before deleting a model object |
1081 | 1081 | * |
1082 | 1082 | * @param EE_Base_Class $model_object about to be 'deleted' |
1083 | 1083 | */ |
1084 | - do_action( 'AHEE__EE_Base_Class__delete__before', $this ); |
|
1085 | - $result = $this->get_model()->delete_by_ID( $this->ID() ); |
|
1084 | + do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
1085 | + $result = $this->get_model()->delete_by_ID($this->ID()); |
|
1086 | 1086 | /** |
1087 | 1087 | * Called just after deleting a model object |
1088 | 1088 | * @param EE_Base_Class $model_object that was just 'deleted' |
1089 | 1089 | * @param boolean $result |
1090 | 1090 | */ |
1091 | - do_action( 'AHEE__EE_Base_Class__delete__end', $this, $result ); |
|
1091 | + do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
1092 | 1092 | return $result; |
1093 | 1093 | } |
1094 | 1094 | |
@@ -1098,11 +1098,11 @@ discard block |
||
1098 | 1098 | * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an error) |
1099 | 1099 | * @return bool |
1100 | 1100 | */ |
1101 | - public function delete_permanently(){ |
|
1102 | - $model=$this->get_model(); |
|
1103 | - if($model instanceof EEM_Soft_Delete_Base){ |
|
1104 | - $result=$model->delete_permanently_by_ID($this->ID()); |
|
1105 | - }else{ |
|
1101 | + public function delete_permanently() { |
|
1102 | + $model = $this->get_model(); |
|
1103 | + if ($model instanceof EEM_Soft_Delete_Base) { |
|
1104 | + $result = $model->delete_permanently_by_ID($this->ID()); |
|
1105 | + } else { |
|
1106 | 1106 | $result = $this->delete(); |
1107 | 1107 | } |
1108 | 1108 | return $result ? true : false; |
@@ -1120,17 +1120,17 @@ discard block |
||
1120 | 1120 | * @throws \EE_Error |
1121 | 1121 | * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure |
1122 | 1122 | */ |
1123 | - public function save($set_cols_n_values=array()) { |
|
1123 | + public function save($set_cols_n_values = array()) { |
|
1124 | 1124 | /** |
1125 | 1125 | * Filters the fields we're about to save on the model object |
1126 | 1126 | * |
1127 | 1127 | * @param array $set_cols_n_values |
1128 | 1128 | * @param EE_Base_Class $model_object |
1129 | 1129 | */ |
1130 | - $set_cols_n_values = apply_filters( 'FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this ); |
|
1130 | + $set_cols_n_values = apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this); |
|
1131 | 1131 | //set attributes as provided in $set_cols_n_values |
1132 | - foreach($set_cols_n_values as $column=>$value){ |
|
1133 | - $this->set($column,$value); |
|
1132 | + foreach ($set_cols_n_values as $column=>$value) { |
|
1133 | + $this->set($column, $value); |
|
1134 | 1134 | } |
1135 | 1135 | /** |
1136 | 1136 | * Saving a model object. |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | * Before we perform a save, this action is fired. |
1139 | 1139 | * @param EE_Base_Class $model_object the model object about to be saved. |
1140 | 1140 | */ |
1141 | - do_action( 'AHEE__EE_Base_Class__save__begin', $this ); |
|
1141 | + do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
1142 | 1142 | //now get current attribute values |
1143 | 1143 | $save_cols_n_values = $this->_fields; |
1144 | 1144 | //if the object already has an ID, update it. Otherwise, insert it |
@@ -1146,61 +1146,61 @@ discard block |
||
1146 | 1146 | $old_assumption_concerning_value_preparation = $this->get_model()->get_assumption_concerning_values_already_prepared_by_model_object(); |
1147 | 1147 | $this->get_model()->assume_values_already_prepared_by_model_object(true); |
1148 | 1148 | //does this model have an autoincrement PK? |
1149 | - if($this->get_model()->has_primary_key_field()){ |
|
1150 | - if($this->get_model()->get_primary_key_field()->is_auto_increment()){ |
|
1149 | + if ($this->get_model()->has_primary_key_field()) { |
|
1150 | + if ($this->get_model()->get_primary_key_field()->is_auto_increment()) { |
|
1151 | 1151 | //ok check if it's set, if so: update; if not, insert |
1152 | - if ( ! empty( $save_cols_n_values[self::_get_primary_key_name( get_class($this) )] ) ){ |
|
1153 | - $results = $this->get_model()->update_by_ID ( $save_cols_n_values, $this->ID() ); |
|
1152 | + if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) { |
|
1153 | + $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
1154 | 1154 | } else { |
1155 | - unset($save_cols_n_values[self::_get_primary_key_name( get_class( $this) )]); |
|
1156 | - $results = $this->get_model()->insert( $save_cols_n_values, true); |
|
1157 | - if($results){ |
|
1155 | + unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]); |
|
1156 | + $results = $this->get_model()->insert($save_cols_n_values, true); |
|
1157 | + if ($results) { |
|
1158 | 1158 | //if successful, set the primary key |
1159 | 1159 | //but don't use the normal SET method, because it will check if |
1160 | 1160 | //an item with the same ID exists in the mapper & db, then |
1161 | 1161 | //will find it in the db (because we just added it) and THAT object |
1162 | 1162 | //will get added to the mapper before we can add this one! |
1163 | 1163 | //but if we just avoid using the SET method, all that headache can be avoided |
1164 | - $pk_field_name =self::_get_primary_key_name( get_class($this)); |
|
1164 | + $pk_field_name = self::_get_primary_key_name(get_class($this)); |
|
1165 | 1165 | $this->_fields[$pk_field_name] = $results; |
1166 | 1166 | $this->_clear_cached_property($pk_field_name); |
1167 | - $this->get_model()->add_to_entity_map( $this ); |
|
1167 | + $this->get_model()->add_to_entity_map($this); |
|
1168 | 1168 | $this->_update_cached_related_model_objs_fks(); |
1169 | 1169 | } |
1170 | 1170 | } |
1171 | - }else{//PK is NOT auto-increment |
|
1171 | + } else {//PK is NOT auto-increment |
|
1172 | 1172 | //so check if one like it already exists in the db |
1173 | - if( $this->get_model()->exists_by_ID( $this->ID() ) ){ |
|
1174 | - if( ! $this->in_entity_map() && WP_DEBUG ){ |
|
1173 | + if ($this->get_model()->exists_by_ID($this->ID())) { |
|
1174 | + if ( ! $this->in_entity_map() && WP_DEBUG) { |
|
1175 | 1175 | throw new EE_Error( |
1176 | 1176 | sprintf( |
1177 | - __( 'Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', 'event_espresso' ), |
|
1177 | + __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', 'event_espresso'), |
|
1178 | 1178 | get_class($this), |
1179 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
1180 | - get_class( $this->get_model() ) . '::instance()->get_one_by_ID()', |
|
1179 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
1180 | + get_class($this->get_model()).'::instance()->get_one_by_ID()', |
|
1181 | 1181 | '<br />' |
1182 | 1182 | ) |
1183 | 1183 | ); |
1184 | 1184 | } |
1185 | 1185 | $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
1186 | - }else{ |
|
1186 | + } else { |
|
1187 | 1187 | $results = $this->get_model()->insert($save_cols_n_values); |
1188 | 1188 | $this->_update_cached_related_model_objs_fks(); |
1189 | 1189 | } |
1190 | 1190 | } |
1191 | - }else{//there is NO primary key |
|
1191 | + } else {//there is NO primary key |
|
1192 | 1192 | $already_in_db = false; |
1193 | - foreach($this->get_model()->unique_indexes() as $index){ |
|
1193 | + foreach ($this->get_model()->unique_indexes() as $index) { |
|
1194 | 1194 | $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
1195 | - if($this->get_model()->exists(array($uniqueness_where_params))){ |
|
1195 | + if ($this->get_model()->exists(array($uniqueness_where_params))) { |
|
1196 | 1196 | $already_in_db = true; |
1197 | 1197 | } |
1198 | 1198 | } |
1199 | - if( $already_in_db ){ |
|
1200 | - $combined_pk_fields_n_values = array_intersect_key( $save_cols_n_values, $this->get_model()->get_combined_primary_key_fields() ); |
|
1201 | - $results = $this->get_model()->update( $save_cols_n_values,$combined_pk_fields_n_values ); |
|
1202 | - }else{ |
|
1203 | - $results = $this->get_model()->insert( $save_cols_n_values ); |
|
1199 | + if ($already_in_db) { |
|
1200 | + $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, $this->get_model()->get_combined_primary_key_fields()); |
|
1201 | + $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values); |
|
1202 | + } else { |
|
1203 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
1204 | 1204 | } |
1205 | 1205 | } |
1206 | 1206 | //restore the old assumption about values being prepared by the model object |
@@ -1213,7 +1213,7 @@ discard block |
||
1213 | 1213 | * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
1214 | 1214 | * the new ID (or 0 if an error occurred and it wasn't updated) |
1215 | 1215 | */ |
1216 | - do_action( 'AHEE__EE_Base_Class__save__end', $this, $results ); |
|
1216 | + do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
1217 | 1217 | return $results; |
1218 | 1218 | } |
1219 | 1219 | |
@@ -1225,13 +1225,13 @@ discard block |
||
1225 | 1225 | * and we want to let its cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on the transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether or not they exist in the DB (if they do, their DB records will be automatically updated) |
1226 | 1226 | * @return void |
1227 | 1227 | */ |
1228 | - protected function _update_cached_related_model_objs_fks(){ |
|
1229 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ){ |
|
1230 | - if( $relation_obj instanceof EE_Has_Many_Relation ){ |
|
1231 | - foreach( $this->get_all_from_cache( $relation_name ) as $related_model_obj_in_cache) { |
|
1232 | - $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( $this->get_model()->get_this_model_name() ); |
|
1233 | - $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID() ); |
|
1234 | - if( $related_model_obj_in_cache->ID() ){ |
|
1228 | + protected function _update_cached_related_model_objs_fks() { |
|
1229 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
1230 | + if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
1231 | + foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
1232 | + $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to($this->get_model()->get_this_model_name()); |
|
1233 | + $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
1234 | + if ($related_model_obj_in_cache->ID()) { |
|
1235 | 1235 | $related_model_obj_in_cache->save(); |
1236 | 1236 | } |
1237 | 1237 | } |
@@ -1247,21 +1247,21 @@ discard block |
||
1247 | 1247 | * and this object and properly setup |
1248 | 1248 | * @return int ID of new model object on save; 0 on failure+ |
1249 | 1249 | */ |
1250 | - public function save_new_cached_related_model_objs(){ |
|
1250 | + public function save_new_cached_related_model_objs() { |
|
1251 | 1251 | //make sure this has been saved |
1252 | - if( ! $this->ID()){ |
|
1252 | + if ( ! $this->ID()) { |
|
1253 | 1253 | $id = $this->save(); |
1254 | - }else{ |
|
1254 | + } else { |
|
1255 | 1255 | $id = $this->ID(); |
1256 | 1256 | } |
1257 | 1257 | //now save all the NEW cached model objects (ie they don't exist in the DB) |
1258 | - foreach($this->get_model()->relation_settings() as $relationName => $relationObj){ |
|
1258 | + foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
1259 | 1259 | |
1260 | 1260 | |
1261 | - if($this->_model_relations[$relationName]){ |
|
1261 | + if ($this->_model_relations[$relationName]) { |
|
1262 | 1262 | //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
1263 | 1263 | //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
1264 | - if($relationObj instanceof EE_Belongs_To_Relation){ |
|
1264 | + if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
1265 | 1265 | //add a relation to that relation type (which saves the appropriate thing in the process) |
1266 | 1266 | //but ONLY if it DOES NOT exist in the DB |
1267 | 1267 | /* @var $related_model_obj EE_Base_Class */ |
@@ -1270,8 +1270,8 @@ discard block |
||
1270 | 1270 | $this->_add_relation_to($related_model_obj, $relationName); |
1271 | 1271 | $related_model_obj->save_new_cached_related_model_objs(); |
1272 | 1272 | // } |
1273 | - }else{ |
|
1274 | - foreach($this->_model_relations[$relationName] as $related_model_obj){ |
|
1273 | + } else { |
|
1274 | + foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
1275 | 1275 | //add a relation to that relation type (which saves the appropriate thing in the process) |
1276 | 1276 | //but ONLY if it DOES NOT exist in the DB |
1277 | 1277 | // if( ! $related_model_obj->ID()){ |
@@ -1292,8 +1292,8 @@ discard block |
||
1292 | 1292 | * @return \EEM_Base | \EEM_CPT_Base |
1293 | 1293 | */ |
1294 | 1294 | public function get_model() { |
1295 | - $modelName = self::_get_model_classname( get_class($this) ); |
|
1296 | - return self::_get_model_instance_with_name($modelName, $this->_timezone ); |
|
1295 | + $modelName = self::_get_model_classname(get_class($this)); |
|
1296 | + return self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | 1299 | |
@@ -1303,10 +1303,10 @@ discard block |
||
1303 | 1303 | * @param $classname |
1304 | 1304 | * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
1305 | 1305 | */ |
1306 | - protected static function _get_object_from_entity_mapper($props_n_values, $classname){ |
|
1306 | + protected static function _get_object_from_entity_mapper($props_n_values, $classname) { |
|
1307 | 1307 | //TODO: will not work for Term_Relationships because they have no PK! |
1308 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
1309 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
|
1308 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
1309 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
1310 | 1310 | $id = $props_n_values[$primary_id_ref]; |
1311 | 1311 | return self::_get_model($classname)->get_from_entity_map($id); |
1312 | 1312 | } |
@@ -1323,24 +1323,24 @@ discard block |
||
1323 | 1323 | * @param null $timezone |
1324 | 1324 | * @return mixed (EE_Base_Class|bool) |
1325 | 1325 | */ |
1326 | - protected static function _check_for_object( $props_n_values, $classname, $timezone = NULL ) { |
|
1327 | - if( self::_get_model( $classname )->has_primary_key_field()){ |
|
1328 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
1326 | + protected static function _check_for_object($props_n_values, $classname, $timezone = NULL) { |
|
1327 | + if (self::_get_model($classname)->has_primary_key_field()) { |
|
1328 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
1329 | 1329 | |
1330 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
|
1331 | - $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( $props_n_values[$primary_id_ref] ); |
|
1332 | - }else{ |
|
1330 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
1331 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID($props_n_values[$primary_id_ref]); |
|
1332 | + } else { |
|
1333 | 1333 | $existing = null; |
1334 | 1334 | } |
1335 | - }elseif( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ){ |
|
1335 | + }elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) { |
|
1336 | 1336 | //no primary key on this model, but there's still a matching item in the DB |
1337 | - $existing = self::_get_model($classname, $timezone)->get_one_by_ID( self::_get_model($classname, $timezone)->get_index_primary_key_string( $props_n_values ) ); |
|
1338 | - }else{ |
|
1337 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID(self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)); |
|
1338 | + } else { |
|
1339 | 1339 | $existing = null; |
1340 | 1340 | } |
1341 | - if ( $existing ) { |
|
1342 | - foreach ( $props_n_values as $property => $field_value ) { |
|
1343 | - $existing->set( $property, $field_value ); |
|
1341 | + if ($existing) { |
|
1342 | + foreach ($props_n_values as $property => $field_value) { |
|
1343 | + $existing->set($property, $field_value); |
|
1344 | 1344 | } |
1345 | 1345 | return $existing; |
1346 | 1346 | } else { |
@@ -1358,13 +1358,13 @@ discard block |
||
1358 | 1358 | * @throws EE_Error |
1359 | 1359 | * @return EEM_Base |
1360 | 1360 | */ |
1361 | - protected static function _get_model( $classname, $timezone = NULL ){ |
|
1361 | + protected static function _get_model($classname, $timezone = NULL) { |
|
1362 | 1362 | //find model for this class |
1363 | - if( ! $classname ){ |
|
1364 | - throw new EE_Error(sprintf(__("What were you thinking calling _get_model(%s)?? You need to specify the class name", "event_espresso"),$classname)); |
|
1363 | + if ( ! $classname) { |
|
1364 | + throw new EE_Error(sprintf(__("What were you thinking calling _get_model(%s)?? You need to specify the class name", "event_espresso"), $classname)); |
|
1365 | 1365 | } |
1366 | - $modelName=self::_get_model_classname($classname); |
|
1367 | - return self::_get_model_instance_with_name($modelName, $timezone ); |
|
1366 | + $modelName = self::_get_model_classname($classname); |
|
1367 | + return self::_get_model_instance_with_name($modelName, $timezone); |
|
1368 | 1368 | } |
1369 | 1369 | |
1370 | 1370 | |
@@ -1375,10 +1375,10 @@ discard block |
||
1375 | 1375 | * @param null $timezone |
1376 | 1376 | * @return EEM_Base |
1377 | 1377 | */ |
1378 | - protected static function _get_model_instance_with_name($model_classname, $timezone = NULL){ |
|
1379 | - $model_classname = str_replace( 'EEM_', '', $model_classname ); |
|
1380 | - $model = EE_Registry::instance()->load_model( $model_classname ); |
|
1381 | - $model->set_timezone( $timezone ); |
|
1378 | + protected static function _get_model_instance_with_name($model_classname, $timezone = NULL) { |
|
1379 | + $model_classname = str_replace('EEM_', '', $model_classname); |
|
1380 | + $model = EE_Registry::instance()->load_model($model_classname); |
|
1381 | + $model->set_timezone($timezone); |
|
1382 | 1382 | return $model; |
1383 | 1383 | } |
1384 | 1384 | |
@@ -1390,10 +1390,10 @@ discard block |
||
1390 | 1390 | * @param null $model_name |
1391 | 1391 | * @return string like EEM_Attendee |
1392 | 1392 | */ |
1393 | - private static function _get_model_classname( $model_name = null){ |
|
1394 | - if(strpos($model_name,"EE_")===0){ |
|
1395 | - $model_classname=str_replace("EE_","EEM_",$model_name); |
|
1396 | - }else{ |
|
1393 | + private static function _get_model_classname($model_name = null) { |
|
1394 | + if (strpos($model_name, "EE_") === 0) { |
|
1395 | + $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
1396 | + } else { |
|
1397 | 1397 | $model_classname = "EEM_".$model_name; |
1398 | 1398 | } |
1399 | 1399 | return $model_classname; |
@@ -1407,11 +1407,11 @@ discard block |
||
1407 | 1407 | * @throws EE_Error |
1408 | 1408 | * @return string |
1409 | 1409 | */ |
1410 | - protected static function _get_primary_key_name( $classname = NULL ){ |
|
1411 | - if( ! $classname){ |
|
1412 | - throw new EE_Error(sprintf(__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),$classname)); |
|
1410 | + protected static function _get_primary_key_name($classname = NULL) { |
|
1411 | + if ( ! $classname) { |
|
1412 | + throw new EE_Error(sprintf(__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), $classname)); |
|
1413 | 1413 | } |
1414 | - return self::_get_model( $classname )->get_primary_key_field()->get_name(); |
|
1414 | + return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
1415 | 1415 | } |
1416 | 1416 | |
1417 | 1417 | |
@@ -1423,12 +1423,12 @@ discard block |
||
1423 | 1423 | * Usually defaults for integer primary keys are 0; string primary keys are usually NULL). |
1424 | 1424 | * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
1425 | 1425 | */ |
1426 | - public function ID(){ |
|
1426 | + public function ID() { |
|
1427 | 1427 | //now that we know the name of the variable, use a variable variable to get its value and return its |
1428 | - if( $this->get_model()->has_primary_key_field() ) { |
|
1429 | - return $this->_fields[self::_get_primary_key_name( get_class($this) )]; |
|
1430 | - }else{ |
|
1431 | - return $this->get_model()->get_index_primary_key_string( $this->_fields ); |
|
1428 | + if ($this->get_model()->has_primary_key_field()) { |
|
1429 | + return $this->_fields[self::_get_primary_key_name(get_class($this))]; |
|
1430 | + } else { |
|
1431 | + return $this->get_model()->get_index_primary_key_string($this->_fields); |
|
1432 | 1432 | } |
1433 | 1433 | } |
1434 | 1434 | |
@@ -1446,24 +1446,24 @@ discard block |
||
1446 | 1446 | * @throws EE_Error |
1447 | 1447 | * @return EE_Base_Class the object the relation was added to |
1448 | 1448 | */ |
1449 | - public function _add_relation_to( $otherObjectModelObjectOrID,$relationName, $where_query = array(), $cache_id = NULL ){ |
|
1449 | + public function _add_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array(), $cache_id = NULL) { |
|
1450 | 1450 | //if this thing exists in the DB, save the relation to the DB |
1451 | - if( $this->ID() ){ |
|
1452 | - $otherObject = $this->get_model()->add_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $where_query ); |
|
1451 | + if ($this->ID()) { |
|
1452 | + $otherObject = $this->get_model()->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query); |
|
1453 | 1453 | //clear cache so future get_many_related and get_first_related() return new results. |
1454 | - $this->clear_cache( $relationName, $otherObject, TRUE ); |
|
1454 | + $this->clear_cache($relationName, $otherObject, TRUE); |
|
1455 | 1455 | } else { |
1456 | 1456 | //this thing doesn't exist in the DB, so just cache it |
1457 | - if( ! $otherObjectModelObjectOrID instanceof EE_Base_Class){ |
|
1458 | - throw new EE_Error( sprintf( |
|
1459 | - __( 'Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso' ), |
|
1457 | + if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
1458 | + throw new EE_Error(sprintf( |
|
1459 | + __('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso'), |
|
1460 | 1460 | $otherObjectModelObjectOrID, |
1461 | - get_class( $this ) |
|
1461 | + get_class($this) |
|
1462 | 1462 | )); |
1463 | 1463 | } else { |
1464 | 1464 | $otherObject = $otherObjectModelObjectOrID; |
1465 | 1465 | } |
1466 | - $this->cache( $relationName, $otherObjectModelObjectOrID, $cache_id ); |
|
1466 | + $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
1467 | 1467 | } |
1468 | 1468 | |
1469 | 1469 | |
@@ -1481,12 +1481,12 @@ discard block |
||
1481 | 1481 | * @param array $where_query You can optionally include an array of key=>value pairs that allow you to further constrict the relation to being added. However, keep in mind that the columns (keys) given must match a column on the JOIN table and currently only the HABTM models accept these additional conditions. Also remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is created in the join table. |
1482 | 1482 | * @return EE_Base_Class the relation was removed from |
1483 | 1483 | */ |
1484 | - public function _remove_relation_to($otherObjectModelObjectOrID,$relationName, $where_query = array() ){ |
|
1485 | - if($this->ID()){//if this exists in the DB, save the relation change to the DB too |
|
1486 | - $otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query ); |
|
1484 | + public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) { |
|
1485 | + if ($this->ID()) {//if this exists in the DB, save the relation change to the DB too |
|
1486 | + $otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query); |
|
1487 | 1487 | $this->clear_cache($relationName, $otherObject); |
1488 | - }else{//this doesn't exist in the DB, just remove it from the cache |
|
1489 | - $otherObject = $this->clear_cache($relationName,$otherObjectModelObjectOrID); |
|
1488 | + } else {//this doesn't exist in the DB, just remove it from the cache |
|
1489 | + $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
1490 | 1490 | } |
1491 | 1491 | return $otherObject; |
1492 | 1492 | } |
@@ -1497,12 +1497,12 @@ discard block |
||
1497 | 1497 | * @param array $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions) |
1498 | 1498 | * @return EE_Base_Class |
1499 | 1499 | */ |
1500 | - public function _remove_relations($relationName,$where_query_params = array()){ |
|
1501 | - if($this->ID()){//if this exists in the DB, save the relation change to the DB too |
|
1502 | - $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params ); |
|
1503 | - $this->clear_cache($relationName,null,true); |
|
1504 | - }else{//this doesn't exist in the DB, just remove it from the cache |
|
1505 | - $otherObjects = $this->clear_cache($relationName,null,true); |
|
1500 | + public function _remove_relations($relationName, $where_query_params = array()) { |
|
1501 | + if ($this->ID()) {//if this exists in the DB, save the relation change to the DB too |
|
1502 | + $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
1503 | + $this->clear_cache($relationName, null, true); |
|
1504 | + } else {//this doesn't exist in the DB, just remove it from the cache |
|
1505 | + $otherObjects = $this->clear_cache($relationName, null, true); |
|
1506 | 1506 | } |
1507 | 1507 | return $otherObjects; |
1508 | 1508 | } |
@@ -1518,26 +1518,26 @@ discard block |
||
1518 | 1518 | * @param array $query_params like EEM_Base::get_all |
1519 | 1519 | * @return EE_Base_Class[] |
1520 | 1520 | */ |
1521 | - public function get_many_related($relationName,$query_params = array()){ |
|
1522 | - if($this->ID()){//this exists in the DB, so get the related things from either the cache or the DB |
|
1521 | + public function get_many_related($relationName, $query_params = array()) { |
|
1522 | + if ($this->ID()) {//this exists in the DB, so get the related things from either the cache or the DB |
|
1523 | 1523 | //if there are query parameters, forget about caching the related model objects. |
1524 | - if( $query_params ){ |
|
1524 | + if ($query_params) { |
|
1525 | 1525 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
1526 | - }else{ |
|
1526 | + } else { |
|
1527 | 1527 | //did we already cache the result of this query? |
1528 | 1528 | $cached_results = $this->get_all_from_cache($relationName); |
1529 | - if ( ! $cached_results ){ |
|
1529 | + if ( ! $cached_results) { |
|
1530 | 1530 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
1531 | 1531 | //if no query parameters were passed, then we got all the related model objects |
1532 | 1532 | //for that relation. We can cache them then. |
1533 | - foreach($related_model_objects as $related_model_object){ |
|
1533 | + foreach ($related_model_objects as $related_model_object) { |
|
1534 | 1534 | $this->cache($relationName, $related_model_object); |
1535 | 1535 | } |
1536 | - }else{ |
|
1536 | + } else { |
|
1537 | 1537 | $related_model_objects = $cached_results; |
1538 | 1538 | } |
1539 | 1539 | } |
1540 | - }else{//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1540 | + } else {//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1541 | 1541 | $related_model_objects = $this->get_all_from_cache($relationName); |
1542 | 1542 | } |
1543 | 1543 | return $related_model_objects; |
@@ -1554,8 +1554,8 @@ discard block |
||
1554 | 1554 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
1555 | 1555 | * @return int |
1556 | 1556 | */ |
1557 | - public function count_related($relation_name, $query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
1558 | - return $this->get_model()->count_related($this,$relation_name,$query_params,$field_to_count,$distinct); |
|
1557 | + public function count_related($relation_name, $query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
1558 | + return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
1559 | 1559 | } |
1560 | 1560 | |
1561 | 1561 | |
@@ -1569,7 +1569,7 @@ discard block |
||
1569 | 1569 | * By default, uses primary key (which doesn't make much sense, so you should probably change it) |
1570 | 1570 | * @return int |
1571 | 1571 | */ |
1572 | - public function sum_related($relation_name, $query_params = array(), $field_to_sum = null){ |
|
1572 | + public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) { |
|
1573 | 1573 | return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
1574 | 1574 | } |
1575 | 1575 | |
@@ -1581,34 +1581,34 @@ discard block |
||
1581 | 1581 | * @param array $query_params like EEM_Base::get_all |
1582 | 1582 | * @return EE_Base_Class (not an array, a single object) |
1583 | 1583 | */ |
1584 | - public function get_first_related($relationName,$query_params = array()){ |
|
1585 | - if($this->ID()){//this exists in the DB, get from the cache OR the DB |
|
1584 | + public function get_first_related($relationName, $query_params = array()) { |
|
1585 | + if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
1586 | 1586 | |
1587 | 1587 | //if they've provided some query parameters, don't bother trying to cache the result |
1588 | 1588 | //also make sure we're not caching the result of get_first_related |
1589 | 1589 | //on a relation which should have an array of objects (because the cache might have an array of objects) |
1590 | - if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
1591 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1592 | - }else{ |
|
1590 | + if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
1591 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1592 | + } else { |
|
1593 | 1593 | //first, check if we've already cached the result of this query |
1594 | 1594 | $cached_result = $this->get_one_from_cache($relationName); |
1595 | - if ( ! $cached_result ){ |
|
1595 | + if ( ! $cached_result) { |
|
1596 | 1596 | |
1597 | 1597 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1598 | - $this->cache($relationName,$related_model_object); |
|
1599 | - }else{ |
|
1598 | + $this->cache($relationName, $related_model_object); |
|
1599 | + } else { |
|
1600 | 1600 | $related_model_object = $cached_result; |
1601 | 1601 | } |
1602 | 1602 | } |
1603 | - }else{ |
|
1603 | + } else { |
|
1604 | 1604 | //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
1605 | - if( $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
1606 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1607 | - }else{ |
|
1605 | + if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
1606 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1607 | + } else { |
|
1608 | 1608 | $related_model_object = null; |
1609 | 1609 | } |
1610 | 1610 | //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object |
1611 | - if( ! $related_model_object){ |
|
1611 | + if ( ! $related_model_object) { |
|
1612 | 1612 | $related_model_object = $this->get_one_from_cache($relationName); |
1613 | 1613 | } |
1614 | 1614 | |
@@ -1627,12 +1627,12 @@ discard block |
||
1627 | 1627 | * @param array $query_params like EEM_Base::get_all's |
1628 | 1628 | * @return int how many deleted |
1629 | 1629 | */ |
1630 | - public function delete_related($relationName,$query_params = array()){ |
|
1631 | - if($this->ID()){ |
|
1632 | - $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
1633 | - }else{ |
|
1630 | + public function delete_related($relationName, $query_params = array()) { |
|
1631 | + if ($this->ID()) { |
|
1632 | + $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
1633 | + } else { |
|
1634 | 1634 | $count = count($this->get_all_from_cache($relationName)); |
1635 | - $this->clear_cache($relationName,NULL,TRUE); |
|
1635 | + $this->clear_cache($relationName, NULL, TRUE); |
|
1636 | 1636 | } |
1637 | 1637 | return $count; |
1638 | 1638 | } |
@@ -1647,13 +1647,13 @@ discard block |
||
1647 | 1647 | * @param array $query_params like EEM_Base::get_all's |
1648 | 1648 | * @return int how many deleted (including those soft deleted) |
1649 | 1649 | */ |
1650 | - public function delete_related_permanently($relationName,$query_params = array()){ |
|
1651 | - if($this->ID()){ |
|
1652 | - $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
1653 | - }else{ |
|
1650 | + public function delete_related_permanently($relationName, $query_params = array()) { |
|
1651 | + if ($this->ID()) { |
|
1652 | + $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
1653 | + } else { |
|
1654 | 1654 | $count = count($this->get_all_from_cache($relationName)); |
1655 | 1655 | } |
1656 | - $this->clear_cache($relationName,NULL,TRUE); |
|
1656 | + $this->clear_cache($relationName, NULL, TRUE); |
|
1657 | 1657 | return $count; |
1658 | 1658 | } |
1659 | 1659 | |
@@ -1669,7 +1669,7 @@ discard block |
||
1669 | 1669 | * @param string $field_name property to check |
1670 | 1670 | * @return bool TRUE if existing,FALSE if not. |
1671 | 1671 | */ |
1672 | - public function is_set( $field_name ) { |
|
1672 | + public function is_set($field_name) { |
|
1673 | 1673 | return isset($this->_fields[$field_name]); |
1674 | 1674 | } |
1675 | 1675 | |
@@ -1681,12 +1681,12 @@ discard block |
||
1681 | 1681 | * @throws EE_Error |
1682 | 1682 | * @return bool TRUE if existing, throw EE_Error if not. |
1683 | 1683 | */ |
1684 | - protected function _property_exists( $properties ) { |
|
1684 | + protected function _property_exists($properties) { |
|
1685 | 1685 | |
1686 | - foreach ( (array) $properties as $property_name ) { |
|
1686 | + foreach ((array) $properties as $property_name) { |
|
1687 | 1687 | //first make sure this property exists |
1688 | - if ( ! $this->_fields[ $property_name ] ) |
|
1689 | - throw new EE_Error( sprintf( __('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name ) ); |
|
1688 | + if ( ! $this->_fields[$property_name]) |
|
1689 | + throw new EE_Error(sprintf(__('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name)); |
|
1690 | 1690 | } |
1691 | 1691 | |
1692 | 1692 | return TRUE; |
@@ -1703,7 +1703,7 @@ discard block |
||
1703 | 1703 | $fields = $this->get_model()->field_settings(FALSE); |
1704 | 1704 | $properties = array(); |
1705 | 1705 | //remove prepended underscore |
1706 | - foreach ( $fields as $field_name => $settings ) { |
|
1706 | + foreach ($fields as $field_name => $settings) { |
|
1707 | 1707 | $properties[$field_name] = $this->get($field_name); |
1708 | 1708 | } |
1709 | 1709 | return $properties; |
@@ -1733,14 +1733,14 @@ discard block |
||
1733 | 1733 | * @throws EE_Error |
1734 | 1734 | * @return mixed whatever the plugin which calls add_filter decides |
1735 | 1735 | */ |
1736 | - public function __call($methodName,$args){ |
|
1737 | - $className=get_class($this); |
|
1738 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
1739 | - if(!has_filter($tagName)){ |
|
1740 | - throw new EE_Error(sprintf(__("Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}","event_espresso"), |
|
1741 | - $methodName,$className,$tagName)); |
|
1736 | + public function __call($methodName, $args) { |
|
1737 | + $className = get_class($this); |
|
1738 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
1739 | + if ( ! has_filter($tagName)) { |
|
1740 | + throw new EE_Error(sprintf(__("Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}", "event_espresso"), |
|
1741 | + $methodName, $className, $tagName)); |
|
1742 | 1742 | } |
1743 | - return apply_filters($tagName,null,$this,$args); |
|
1743 | + return apply_filters($tagName, null, $this, $args); |
|
1744 | 1744 | } |
1745 | 1745 | |
1746 | 1746 | |
@@ -1755,22 +1755,22 @@ discard block |
||
1755 | 1755 | * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
1756 | 1756 | * NOTE: if the values haven't changed, returns 0 |
1757 | 1757 | */ |
1758 | - public function update_extra_meta($meta_key,$meta_value,$previous_value = NULL){ |
|
1759 | - $query_params = array(array( |
|
1758 | + public function update_extra_meta($meta_key, $meta_value, $previous_value = NULL) { |
|
1759 | + $query_params = array(array( |
|
1760 | 1760 | 'EXM_key'=>$meta_key, |
1761 | 1761 | 'OBJ_ID'=>$this->ID(), |
1762 | 1762 | 'EXM_type'=>$this->get_model()->get_this_model_name())); |
1763 | - if($previous_value !== NULL){ |
|
1763 | + if ($previous_value !== NULL) { |
|
1764 | 1764 | $query_params[0]['EXM_value'] = $meta_value; |
1765 | 1765 | } |
1766 | 1766 | $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
1767 | - if( ! $existing_rows_like_that){ |
|
1767 | + if ( ! $existing_rows_like_that) { |
|
1768 | 1768 | return $this->add_extra_meta($meta_key, $meta_value); |
1769 | - }else{ |
|
1770 | - foreach( $existing_rows_like_that as $existing_row){ |
|
1771 | - $existing_row->save( array( 'EXM_value' => $meta_value ) ); |
|
1769 | + } else { |
|
1770 | + foreach ($existing_rows_like_that as $existing_row) { |
|
1771 | + $existing_row->save(array('EXM_value' => $meta_value)); |
|
1772 | 1772 | } |
1773 | - return count( $existing_rows_like_that ); |
|
1773 | + return count($existing_rows_like_that); |
|
1774 | 1774 | } |
1775 | 1775 | } |
1776 | 1776 | |
@@ -1783,10 +1783,10 @@ discard block |
||
1783 | 1783 | * @param boolean $unique |
1784 | 1784 | * @return boolean |
1785 | 1785 | */ |
1786 | - public function add_extra_meta($meta_key,$meta_value,$unique = false){ |
|
1787 | - if($unique){ |
|
1788 | - $existing_extra_meta = EEM_Extra_Meta::instance()->get_one(array(array('EXM_key'=>$meta_key,'OBJ_ID'=>$this->ID(),'EXM_type'=>$this->_get_model_classname(get_class($this))))); |
|
1789 | - if($existing_extra_meta){ |
|
1786 | + public function add_extra_meta($meta_key, $meta_value, $unique = false) { |
|
1787 | + if ($unique) { |
|
1788 | + $existing_extra_meta = EEM_Extra_Meta::instance()->get_one(array(array('EXM_key'=>$meta_key, 'OBJ_ID'=>$this->ID(), 'EXM_type'=>$this->_get_model_classname(get_class($this))))); |
|
1789 | + if ($existing_extra_meta) { |
|
1790 | 1790 | return false; |
1791 | 1791 | } |
1792 | 1792 | } |
@@ -1806,12 +1806,12 @@ discard block |
||
1806 | 1806 | * @param string $meta_value |
1807 | 1807 | * @return int number of extra meta rows deleted |
1808 | 1808 | */ |
1809 | - public function delete_extra_meta($meta_key,$meta_value = NULL){ |
|
1810 | - $query_params = array(array( |
|
1809 | + public function delete_extra_meta($meta_key, $meta_value = NULL) { |
|
1810 | + $query_params = array(array( |
|
1811 | 1811 | 'EXM_key'=>$meta_key, |
1812 | 1812 | 'OBJ_ID'=>$this->ID(), |
1813 | 1813 | 'EXM_type'=>$this->get_model()->get_this_model_name())); |
1814 | - if($meta_value !== NULL){ |
|
1814 | + if ($meta_value !== NULL) { |
|
1815 | 1815 | $query_params[0]['EXM_value'] = $meta_value; |
1816 | 1816 | } |
1817 | 1817 | $count_deleted = EEM_Extra_Meta::instance()->delete($query_params); |
@@ -1827,25 +1827,25 @@ discard block |
||
1827 | 1827 | * @param mixed $default if we don't find anything, what should we return? |
1828 | 1828 | * @return mixed single value if $single; array if ! $single |
1829 | 1829 | */ |
1830 | - public function get_extra_meta($meta_key,$single = FALSE,$default = NULL){ |
|
1831 | - if($single){ |
|
1832 | - $result = $this->get_first_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
1833 | - if ( $result instanceof EE_Extra_Meta ){ |
|
1830 | + public function get_extra_meta($meta_key, $single = FALSE, $default = NULL) { |
|
1831 | + if ($single) { |
|
1832 | + $result = $this->get_first_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
1833 | + if ($result instanceof EE_Extra_Meta) { |
|
1834 | 1834 | return $result->value(); |
1835 | - }else{ |
|
1835 | + } else { |
|
1836 | 1836 | return $default; |
1837 | 1837 | } |
1838 | - }else{ |
|
1839 | - $results = $this->get_many_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
1840 | - if($results){ |
|
1838 | + } else { |
|
1839 | + $results = $this->get_many_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
1840 | + if ($results) { |
|
1841 | 1841 | $values = array(); |
1842 | - foreach($results as $result){ |
|
1843 | - if ( $result instanceof EE_Extra_Meta ){ |
|
1842 | + foreach ($results as $result) { |
|
1843 | + if ($result instanceof EE_Extra_Meta) { |
|
1844 | 1844 | $values[$result->ID()] = $result->value(); |
1845 | 1845 | } |
1846 | 1846 | } |
1847 | 1847 | return $values; |
1848 | - }else{ |
|
1848 | + } else { |
|
1849 | 1849 | return $default; |
1850 | 1850 | } |
1851 | 1851 | } |
@@ -1862,17 +1862,17 @@ discard block |
||
1862 | 1862 | * @param boolean $one_of_each_key |
1863 | 1863 | * @return array |
1864 | 1864 | */ |
1865 | - public function all_extra_meta_array($one_of_each_key = true){ |
|
1865 | + public function all_extra_meta_array($one_of_each_key = true) { |
|
1866 | 1866 | $return_array = array(); |
1867 | - if($one_of_each_key){ |
|
1867 | + if ($one_of_each_key) { |
|
1868 | 1868 | $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by'=>'EXM_key')); |
1869 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
1869 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
1870 | 1870 | $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
1871 | 1871 | } |
1872 | - }else{ |
|
1872 | + } else { |
|
1873 | 1873 | $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
1874 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
1875 | - if( ! isset($return_array[$extra_meta_obj->key()])){ |
|
1874 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
1875 | + if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
1876 | 1876 | $return_array[$extra_meta_obj->key()] = array(); |
1877 | 1877 | } |
1878 | 1878 | $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
@@ -1884,19 +1884,19 @@ discard block |
||
1884 | 1884 | * Gets a pretty nice displayable nice for this model object. Often overriden |
1885 | 1885 | * @return string |
1886 | 1886 | */ |
1887 | - public function name(){ |
|
1887 | + public function name() { |
|
1888 | 1888 | //find a field that's not a text field |
1889 | 1889 | $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
1890 | - if($field_we_can_use){ |
|
1890 | + if ($field_we_can_use) { |
|
1891 | 1891 | return $this->get($field_we_can_use->get_name()); |
1892 | - }else{ |
|
1892 | + } else { |
|
1893 | 1893 | $first_few_properties = $this->model_field_array(); |
1894 | - $first_few_properties = array_slice($first_few_properties,0,3); |
|
1894 | + $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
1895 | 1895 | $name_parts = array(); |
1896 | - foreach( $first_few_properties as $name=> $value ){ |
|
1896 | + foreach ($first_few_properties as $name=> $value) { |
|
1897 | 1897 | $name_parts[] = "$name:$value"; |
1898 | 1898 | } |
1899 | - return implode(",",$name_parts); |
|
1899 | + return implode(",", $name_parts); |
|
1900 | 1900 | } |
1901 | 1901 | } |
1902 | 1902 | |
@@ -1905,11 +1905,11 @@ discard block |
||
1905 | 1905 | * Checks if this model object has been proven to already be in the entity map |
1906 | 1906 | * @return boolean |
1907 | 1907 | */ |
1908 | - public function in_entity_map(){ |
|
1909 | - if( $this->ID() && $this->get_model()->get_from_entity_map( $this->ID() ) === $this ) { |
|
1908 | + public function in_entity_map() { |
|
1909 | + if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
1910 | 1910 | //well, if we looked, did we find it in the entity map? |
1911 | 1911 | return TRUE; |
1912 | - }else{ |
|
1912 | + } else { |
|
1913 | 1913 | return FALSE; |
1914 | 1914 | } |
1915 | 1915 | } |
@@ -1920,21 +1920,21 @@ discard block |
||
1920 | 1920 | * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
1921 | 1921 | * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
1922 | 1922 | */ |
1923 | - public function refresh_from_db(){ |
|
1924 | - if( $this->ID() && $this->in_entity_map() ){ |
|
1925 | - $this->get_model()->refresh_entity_map_from_db( $this->ID() ); |
|
1926 | - }else{ |
|
1923 | + public function refresh_from_db() { |
|
1924 | + if ($this->ID() && $this->in_entity_map()) { |
|
1925 | + $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
1926 | + } else { |
|
1927 | 1927 | //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
1928 | 1928 | //if it has an ID but it's not in the map, and you're asking me to refresh it |
1929 | 1929 | //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
1930 | 1930 | //absolutely nothing in it for this ID |
1931 | - if( WP_DEBUG ) { |
|
1931 | + if (WP_DEBUG) { |
|
1932 | 1932 | throw new EE_Error( |
1933 | 1933 | sprintf( |
1934 | - __( 'Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', 'event_espresso' ), |
|
1934 | + __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', 'event_espresso'), |
|
1935 | 1935 | $this->ID(), |
1936 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
1937 | - get_class( $this->get_model() ) . '::instance()->refresh_entity_map()' |
|
1936 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
1937 | + get_class($this->get_model()).'::instance()->refresh_entity_map()' |
|
1938 | 1938 | ) |
1939 | 1939 | ); |
1940 | 1940 | } |
@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | do_action( 'AHEE_log', __FILE__, ' FILE LOADED', '' ); |
3 | 5 | /** |
4 | 6 | * |
@@ -133,7 +135,7 @@ discard block |
||
133 | 135 | foreach($fieldValues as $field_name => $field_value_from_db){ |
134 | 136 | $this->set_from_db($field_name,$field_value_from_db); |
135 | 137 | } |
136 | - }else{ |
|
138 | + } else{ |
|
137 | 139 | //we're constructing a brand |
138 | 140 | //new instance of the model object. Generally, this means we'll need to do more field validation |
139 | 141 | foreach($model_fields as $fieldName => $field_obj){ |
@@ -153,7 +155,7 @@ discard block |
||
153 | 155 | foreach($this->get_model()->relation_settings() as $relation_name=>$relation_obj){ |
154 | 156 | if($relation_obj instanceof EE_Belongs_To_Relation){ |
155 | 157 | $this->_model_relations[$relation_name] = NULL; |
156 | - }else{ |
|
158 | + } else{ |
|
157 | 159 | $this->_model_relations[$relation_name] = array(); |
158 | 160 | } |
159 | 161 | } |
@@ -177,7 +179,7 @@ discard block |
||
177 | 179 | if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
178 | 180 | $field_settings = $this->get_Model()->field_settings_for( $field_name )){ |
179 | 181 | return $field_settings->prepare_for_get( $this->_props_n_values_provided_in_constructor[ $field_name ] ); |
180 | - }else{ |
|
182 | + } else{ |
|
181 | 183 | return NULL; |
182 | 184 | } |
183 | 185 | } |
@@ -209,7 +211,7 @@ discard block |
||
209 | 211 | $holder_of_value = $field_obj->prepare_for_set($field_value); |
210 | 212 | if( ($field_value === NULL || $holder_of_value === NULL || $holder_of_value ==='') && $use_default){ |
211 | 213 | $this->_fields[$field_name] = $field_obj->get_default_value(); |
212 | - }else{ |
|
214 | + } else{ |
|
213 | 215 | $this->_fields[$field_name] = $holder_of_value; |
214 | 216 | } |
215 | 217 | |
@@ -237,7 +239,7 @@ discard block |
||
237 | 239 | } |
238 | 240 | //let's unset any cache for this field_name from the $_cached_properties property. |
239 | 241 | $this->_clear_cached_property( $field_name ); |
240 | - }else{ |
|
242 | + } else{ |
|
241 | 243 | echo "\r\n\r\nSAAAY WHAT?? $field_name doesnt have a field???"; |
242 | 244 | } |
243 | 245 | |
@@ -434,8 +436,9 @@ discard block |
||
434 | 436 | * @return void |
435 | 437 | */ |
436 | 438 | protected function _clear_cached_property( $property_name ) { |
437 | - if ( isset( $this->_cached_properties[ $property_name ] ) ) |
|
438 | - unset( $this->_cached_properties[ $property_name ] ); |
|
439 | + if ( isset( $this->_cached_properties[ $property_name ] ) ) { |
|
440 | + unset( $this->_cached_properties[ $property_name ] ); |
|
441 | + } |
|
439 | 442 | } |
440 | 443 | |
441 | 444 | |
@@ -475,10 +478,10 @@ discard block |
||
475 | 478 | if($clear_all){ |
476 | 479 | $obj_removed = true; |
477 | 480 | $this->_model_relations[$relationName] = null; |
478 | - }elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
481 | + } elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
479 | 482 | $obj_removed = $this->_model_relations[$relationName]; |
480 | 483 | $this->_model_relations[$relationName] = null; |
481 | - }else{ |
|
484 | + } else{ |
|
482 | 485 | if($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()){ |
483 | 486 | $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
484 | 487 | if( is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])){ |
@@ -492,20 +495,20 @@ discard block |
||
492 | 495 | } |
493 | 496 | if($index_found_at){ |
494 | 497 | $index_in_cache = $index_found_at; |
495 | - }else{ |
|
498 | + } else{ |
|
496 | 499 | //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
497 | 500 | //if it wasn't in it to begin with. So we're done |
498 | 501 | return $object_to_remove_or_index_into_array; |
499 | 502 | } |
500 | 503 | } |
501 | - }elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
504 | + } elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
502 | 505 | //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
503 | 506 | foreach($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want){ |
504 | 507 | if($potentially_obj_we_want == $object_to_remove_or_index_into_array){ |
505 | 508 | $index_in_cache = $index; |
506 | 509 | } |
507 | 510 | } |
508 | - }else{ |
|
511 | + } else{ |
|
509 | 512 | $index_in_cache = $object_to_remove_or_index_into_array; |
510 | 513 | } |
511 | 514 | //supposedly we've found it. But it could just be that the client code |
@@ -514,7 +517,7 @@ discard block |
||
514 | 517 | isset( $this->_model_relations[$relationName][$index_in_cache])){ |
515 | 518 | $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
516 | 519 | unset($this->_model_relations[$relationName][$index_in_cache]); |
517 | - }else{ |
|
520 | + } else{ |
|
518 | 521 | //that thing was never cached anyways. |
519 | 522 | $obj_removed = NULL; |
520 | 523 | } |
@@ -570,7 +573,7 @@ discard block |
||
570 | 573 | $cached_array_or_object = $this->_model_relations[$relationName]; |
571 | 574 | if(is_array($cached_array_or_object)){ |
572 | 575 | return array_shift($cached_array_or_object); |
573 | - }else{ |
|
576 | + } else{ |
|
574 | 577 | return $cached_array_or_object; |
575 | 578 | } |
576 | 579 | } |
@@ -589,10 +592,10 @@ discard block |
||
589 | 592 | $cached_array_or_object = $this->_model_relations[$relationName]; |
590 | 593 | if(is_array($cached_array_or_object)){ |
591 | 594 | $objects = $cached_array_or_object; |
592 | - }elseif($cached_array_or_object){ |
|
595 | + } elseif($cached_array_or_object){ |
|
593 | 596 | //if the result is not an array, but exists, make it an array |
594 | 597 | $objects = array($cached_array_or_object); |
595 | - }else{ |
|
598 | + } else{ |
|
596 | 599 | //if nothing was found, return an empty array |
597 | 600 | $objects = array(); |
598 | 601 | } |
@@ -607,7 +610,7 @@ discard block |
||
607 | 610 | if( $model_object->ID() ){ |
608 | 611 | $model->add_to_entity_map( $model_object ); |
609 | 612 | } |
610 | - }else{ |
|
613 | + } else{ |
|
611 | 614 | throw new EE_Error( sprintf( __( 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', 'event_espresso' ), $relationName, gettype( $model_object ))); |
612 | 615 | } |
613 | 616 | } |
@@ -730,7 +733,7 @@ discard block |
||
730 | 733 | //are null! yikes! so when we find one like that, use defaults for its meta columns |
731 | 734 | if($field_value_from_db === NULL && ! $field_obj->is_nullable()){ |
732 | 735 | $field_value = $field_obj->get_default_value(); |
733 | - }else{ |
|
736 | + } else{ |
|
734 | 737 | $field_value = $field_value_from_db; |
735 | 738 | } |
736 | 739 | $this->_fields[$field_name] = $field_obj->prepare_for_set_from_db($field_value); |
@@ -821,18 +824,20 @@ discard block |
||
821 | 824 | if ( $dt_frmt !== NULL ) { |
822 | 825 | $this->_clear_cached_property( $field_name, $date_or_time ); |
823 | 826 | } |
824 | - if ( $echo ) |
|
825 | - $field->set_pretty_date_format( $in_dt_frmt ); |
|
826 | - else |
|
827 | - $field->set_date_format( $in_dt_frmt ); |
|
827 | + if ( $echo ) { |
|
828 | + $field->set_pretty_date_format( $in_dt_frmt ); |
|
829 | + } else { |
|
830 | + $field->set_date_format( $in_dt_frmt ); |
|
831 | + } |
|
828 | 832 | |
829 | 833 | if ( $tm_frmt !== NULL ) { |
830 | 834 | $this->_clear_cached_property( $field_name, $date_or_time ); |
831 | 835 | } |
832 | - if ( $echo ) |
|
833 | - $field->set_pretty_time_format( $in_tm_frmt ); |
|
834 | - else |
|
835 | - $field->set_time_format( $in_tm_frmt ); |
|
836 | + if ( $echo ) { |
|
837 | + $field->set_pretty_time_format( $in_tm_frmt ); |
|
838 | + } else { |
|
839 | + $field->set_time_format( $in_tm_frmt ); |
|
840 | + } |
|
836 | 841 | |
837 | 842 | //set timezone in field object |
838 | 843 | $field->set_timezone( $this->_timezone ); |
@@ -1050,8 +1055,9 @@ discard block |
||
1050 | 1055 | EE_Registry::instance()->load_helper('DTT_Helper'); |
1051 | 1056 | $timezone = EEH_DTT_Helper::get_timezone(); |
1052 | 1057 | |
1053 | - if ( $timezone == $this->_timezone ) |
|
1054 | - return ''; |
|
1058 | + if ( $timezone == $this->_timezone ) { |
|
1059 | + return ''; |
|
1060 | + } |
|
1055 | 1061 | |
1056 | 1062 | $original_timezone = $this->_timezone; |
1057 | 1063 | $this->set_timezone( $timezone ); |
@@ -1059,8 +1065,9 @@ discard block |
||
1059 | 1065 | $fn = (array) $field_name; |
1060 | 1066 | $args = array_merge( $fn, (array) $args ); |
1061 | 1067 | |
1062 | - if ( !method_exists( $this, $callback ) ) |
|
1063 | - throw new EE_Error(sprintf( __('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback ) ); |
|
1068 | + if ( !method_exists( $this, $callback ) ) { |
|
1069 | + throw new EE_Error(sprintf( __('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback ) ); |
|
1070 | + } |
|
1064 | 1071 | $args = (array) $args; |
1065 | 1072 | $return = $prepend . call_user_func_array( array( $this, $callback ), $args ) . $append; |
1066 | 1073 | |
@@ -1102,7 +1109,7 @@ discard block |
||
1102 | 1109 | $model=$this->get_model(); |
1103 | 1110 | if($model instanceof EEM_Soft_Delete_Base){ |
1104 | 1111 | $result=$model->delete_permanently_by_ID($this->ID()); |
1105 | - }else{ |
|
1112 | + } else{ |
|
1106 | 1113 | $result = $this->delete(); |
1107 | 1114 | } |
1108 | 1115 | return $result ? true : false; |
@@ -1168,7 +1175,7 @@ discard block |
||
1168 | 1175 | $this->_update_cached_related_model_objs_fks(); |
1169 | 1176 | } |
1170 | 1177 | } |
1171 | - }else{//PK is NOT auto-increment |
|
1178 | + } else{//PK is NOT auto-increment |
|
1172 | 1179 | //so check if one like it already exists in the db |
1173 | 1180 | if( $this->get_model()->exists_by_ID( $this->ID() ) ){ |
1174 | 1181 | if( ! $this->in_entity_map() && WP_DEBUG ){ |
@@ -1183,12 +1190,12 @@ discard block |
||
1183 | 1190 | ); |
1184 | 1191 | } |
1185 | 1192 | $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
1186 | - }else{ |
|
1193 | + } else{ |
|
1187 | 1194 | $results = $this->get_model()->insert($save_cols_n_values); |
1188 | 1195 | $this->_update_cached_related_model_objs_fks(); |
1189 | 1196 | } |
1190 | 1197 | } |
1191 | - }else{//there is NO primary key |
|
1198 | + } else{//there is NO primary key |
|
1192 | 1199 | $already_in_db = false; |
1193 | 1200 | foreach($this->get_model()->unique_indexes() as $index){ |
1194 | 1201 | $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
@@ -1199,7 +1206,7 @@ discard block |
||
1199 | 1206 | if( $already_in_db ){ |
1200 | 1207 | $combined_pk_fields_n_values = array_intersect_key( $save_cols_n_values, $this->get_model()->get_combined_primary_key_fields() ); |
1201 | 1208 | $results = $this->get_model()->update( $save_cols_n_values,$combined_pk_fields_n_values ); |
1202 | - }else{ |
|
1209 | + } else{ |
|
1203 | 1210 | $results = $this->get_model()->insert( $save_cols_n_values ); |
1204 | 1211 | } |
1205 | 1212 | } |
@@ -1251,7 +1258,7 @@ discard block |
||
1251 | 1258 | //make sure this has been saved |
1252 | 1259 | if( ! $this->ID()){ |
1253 | 1260 | $id = $this->save(); |
1254 | - }else{ |
|
1261 | + } else{ |
|
1255 | 1262 | $id = $this->ID(); |
1256 | 1263 | } |
1257 | 1264 | //now save all the NEW cached model objects (ie they don't exist in the DB) |
@@ -1270,7 +1277,7 @@ discard block |
||
1270 | 1277 | $this->_add_relation_to($related_model_obj, $relationName); |
1271 | 1278 | $related_model_obj->save_new_cached_related_model_objs(); |
1272 | 1279 | // } |
1273 | - }else{ |
|
1280 | + } else{ |
|
1274 | 1281 | foreach($this->_model_relations[$relationName] as $related_model_obj){ |
1275 | 1282 | //add a relation to that relation type (which saves the appropriate thing in the process) |
1276 | 1283 | //but ONLY if it DOES NOT exist in the DB |
@@ -1329,13 +1336,13 @@ discard block |
||
1329 | 1336 | |
1330 | 1337 | if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
1331 | 1338 | $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( $props_n_values[$primary_id_ref] ); |
1332 | - }else{ |
|
1339 | + } else{ |
|
1333 | 1340 | $existing = null; |
1334 | 1341 | } |
1335 | - }elseif( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ){ |
|
1342 | + } elseif( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ){ |
|
1336 | 1343 | //no primary key on this model, but there's still a matching item in the DB |
1337 | 1344 | $existing = self::_get_model($classname, $timezone)->get_one_by_ID( self::_get_model($classname, $timezone)->get_index_primary_key_string( $props_n_values ) ); |
1338 | - }else{ |
|
1345 | + } else{ |
|
1339 | 1346 | $existing = null; |
1340 | 1347 | } |
1341 | 1348 | if ( $existing ) { |
@@ -1393,7 +1400,7 @@ discard block |
||
1393 | 1400 | private static function _get_model_classname( $model_name = null){ |
1394 | 1401 | if(strpos($model_name,"EE_")===0){ |
1395 | 1402 | $model_classname=str_replace("EE_","EEM_",$model_name); |
1396 | - }else{ |
|
1403 | + } else{ |
|
1397 | 1404 | $model_classname = "EEM_".$model_name; |
1398 | 1405 | } |
1399 | 1406 | return $model_classname; |
@@ -1427,7 +1434,7 @@ discard block |
||
1427 | 1434 | //now that we know the name of the variable, use a variable variable to get its value and return its |
1428 | 1435 | if( $this->get_model()->has_primary_key_field() ) { |
1429 | 1436 | return $this->_fields[self::_get_primary_key_name( get_class($this) )]; |
1430 | - }else{ |
|
1437 | + } else{ |
|
1431 | 1438 | return $this->get_model()->get_index_primary_key_string( $this->_fields ); |
1432 | 1439 | } |
1433 | 1440 | } |
@@ -1485,7 +1492,7 @@ discard block |
||
1485 | 1492 | if($this->ID()){//if this exists in the DB, save the relation change to the DB too |
1486 | 1493 | $otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query ); |
1487 | 1494 | $this->clear_cache($relationName, $otherObject); |
1488 | - }else{//this doesn't exist in the DB, just remove it from the cache |
|
1495 | + } else{//this doesn't exist in the DB, just remove it from the cache |
|
1489 | 1496 | $otherObject = $this->clear_cache($relationName,$otherObjectModelObjectOrID); |
1490 | 1497 | } |
1491 | 1498 | return $otherObject; |
@@ -1501,7 +1508,7 @@ discard block |
||
1501 | 1508 | if($this->ID()){//if this exists in the DB, save the relation change to the DB too |
1502 | 1509 | $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params ); |
1503 | 1510 | $this->clear_cache($relationName,null,true); |
1504 | - }else{//this doesn't exist in the DB, just remove it from the cache |
|
1511 | + } else{//this doesn't exist in the DB, just remove it from the cache |
|
1505 | 1512 | $otherObjects = $this->clear_cache($relationName,null,true); |
1506 | 1513 | } |
1507 | 1514 | return $otherObjects; |
@@ -1523,7 +1530,7 @@ discard block |
||
1523 | 1530 | //if there are query parameters, forget about caching the related model objects. |
1524 | 1531 | if( $query_params ){ |
1525 | 1532 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
1526 | - }else{ |
|
1533 | + } else{ |
|
1527 | 1534 | //did we already cache the result of this query? |
1528 | 1535 | $cached_results = $this->get_all_from_cache($relationName); |
1529 | 1536 | if ( ! $cached_results ){ |
@@ -1533,11 +1540,11 @@ discard block |
||
1533 | 1540 | foreach($related_model_objects as $related_model_object){ |
1534 | 1541 | $this->cache($relationName, $related_model_object); |
1535 | 1542 | } |
1536 | - }else{ |
|
1543 | + } else{ |
|
1537 | 1544 | $related_model_objects = $cached_results; |
1538 | 1545 | } |
1539 | 1546 | } |
1540 | - }else{//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1547 | + } else{//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1541 | 1548 | $related_model_objects = $this->get_all_from_cache($relationName); |
1542 | 1549 | } |
1543 | 1550 | return $related_model_objects; |
@@ -1589,22 +1596,22 @@ discard block |
||
1589 | 1596 | //on a relation which should have an array of objects (because the cache might have an array of objects) |
1590 | 1597 | if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
1591 | 1598 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1592 | - }else{ |
|
1599 | + } else{ |
|
1593 | 1600 | //first, check if we've already cached the result of this query |
1594 | 1601 | $cached_result = $this->get_one_from_cache($relationName); |
1595 | 1602 | if ( ! $cached_result ){ |
1596 | 1603 | |
1597 | 1604 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1598 | 1605 | $this->cache($relationName,$related_model_object); |
1599 | - }else{ |
|
1606 | + } else{ |
|
1600 | 1607 | $related_model_object = $cached_result; |
1601 | 1608 | } |
1602 | 1609 | } |
1603 | - }else{ |
|
1610 | + } else{ |
|
1604 | 1611 | //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
1605 | 1612 | if( $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
1606 | 1613 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1607 | - }else{ |
|
1614 | + } else{ |
|
1608 | 1615 | $related_model_object = null; |
1609 | 1616 | } |
1610 | 1617 | //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object |
@@ -1630,7 +1637,7 @@ discard block |
||
1630 | 1637 | public function delete_related($relationName,$query_params = array()){ |
1631 | 1638 | if($this->ID()){ |
1632 | 1639 | $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
1633 | - }else{ |
|
1640 | + } else{ |
|
1634 | 1641 | $count = count($this->get_all_from_cache($relationName)); |
1635 | 1642 | $this->clear_cache($relationName,NULL,TRUE); |
1636 | 1643 | } |
@@ -1650,7 +1657,7 @@ discard block |
||
1650 | 1657 | public function delete_related_permanently($relationName,$query_params = array()){ |
1651 | 1658 | if($this->ID()){ |
1652 | 1659 | $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
1653 | - }else{ |
|
1660 | + } else{ |
|
1654 | 1661 | $count = count($this->get_all_from_cache($relationName)); |
1655 | 1662 | } |
1656 | 1663 | $this->clear_cache($relationName,NULL,TRUE); |
@@ -1685,8 +1692,9 @@ discard block |
||
1685 | 1692 | |
1686 | 1693 | foreach ( (array) $properties as $property_name ) { |
1687 | 1694 | //first make sure this property exists |
1688 | - if ( ! $this->_fields[ $property_name ] ) |
|
1689 | - throw new EE_Error( sprintf( __('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name ) ); |
|
1695 | + if ( ! $this->_fields[ $property_name ] ) { |
|
1696 | + throw new EE_Error( sprintf( __('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name ) ); |
|
1697 | + } |
|
1690 | 1698 | } |
1691 | 1699 | |
1692 | 1700 | return TRUE; |
@@ -1766,7 +1774,7 @@ discard block |
||
1766 | 1774 | $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
1767 | 1775 | if( ! $existing_rows_like_that){ |
1768 | 1776 | return $this->add_extra_meta($meta_key, $meta_value); |
1769 | - }else{ |
|
1777 | + } else{ |
|
1770 | 1778 | foreach( $existing_rows_like_that as $existing_row){ |
1771 | 1779 | $existing_row->save( array( 'EXM_value' => $meta_value ) ); |
1772 | 1780 | } |
@@ -1832,10 +1840,10 @@ discard block |
||
1832 | 1840 | $result = $this->get_first_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
1833 | 1841 | if ( $result instanceof EE_Extra_Meta ){ |
1834 | 1842 | return $result->value(); |
1835 | - }else{ |
|
1843 | + } else{ |
|
1836 | 1844 | return $default; |
1837 | 1845 | } |
1838 | - }else{ |
|
1846 | + } else{ |
|
1839 | 1847 | $results = $this->get_many_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
1840 | 1848 | if($results){ |
1841 | 1849 | $values = array(); |
@@ -1845,7 +1853,7 @@ discard block |
||
1845 | 1853 | } |
1846 | 1854 | } |
1847 | 1855 | return $values; |
1848 | - }else{ |
|
1856 | + } else{ |
|
1849 | 1857 | return $default; |
1850 | 1858 | } |
1851 | 1859 | } |
@@ -1869,7 +1877,7 @@ discard block |
||
1869 | 1877 | foreach($extra_meta_objs as $extra_meta_obj){ |
1870 | 1878 | $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
1871 | 1879 | } |
1872 | - }else{ |
|
1880 | + } else{ |
|
1873 | 1881 | $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
1874 | 1882 | foreach($extra_meta_objs as $extra_meta_obj){ |
1875 | 1883 | if( ! isset($return_array[$extra_meta_obj->key()])){ |
@@ -1889,7 +1897,7 @@ discard block |
||
1889 | 1897 | $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
1890 | 1898 | if($field_we_can_use){ |
1891 | 1899 | return $this->get($field_we_can_use->get_name()); |
1892 | - }else{ |
|
1900 | + } else{ |
|
1893 | 1901 | $first_few_properties = $this->model_field_array(); |
1894 | 1902 | $first_few_properties = array_slice($first_few_properties,0,3); |
1895 | 1903 | $name_parts = array(); |
@@ -1909,7 +1917,7 @@ discard block |
||
1909 | 1917 | if( $this->ID() && $this->get_model()->get_from_entity_map( $this->ID() ) === $this ) { |
1910 | 1918 | //well, if we looked, did we find it in the entity map? |
1911 | 1919 | return TRUE; |
1912 | - }else{ |
|
1920 | + } else{ |
|
1913 | 1921 | return FALSE; |
1914 | 1922 | } |
1915 | 1923 | } |
@@ -1923,7 +1931,7 @@ discard block |
||
1923 | 1931 | public function refresh_from_db(){ |
1924 | 1932 | if( $this->ID() && $this->in_entity_map() ){ |
1925 | 1933 | $this->get_model()->refresh_entity_map_from_db( $this->ID() ); |
1926 | - }else{ |
|
1934 | + } else{ |
|
1927 | 1935 | //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
1928 | 1936 | //if it has an ID but it's not in the map, and you're asking me to refresh it |
1929 | 1937 | //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | * @access protected |
369 | 369 | * @param string $fieldname the property item the corresponding value is for. |
370 | 370 | * @param mixed $value The value we are caching. |
371 | - * @param null $cache_type |
|
371 | + * @param string $cache_type |
|
372 | 372 | * @return void |
373 | 373 | */ |
374 | 374 | protected function _set_cached_property( $fieldname, $value, $cache_type = NULL ) { |
@@ -803,11 +803,11 @@ discard block |
||
803 | 803 | * |
804 | 804 | * @access protected |
805 | 805 | * @param string $field_name Field on the instantiated EE_Base_Class child object |
806 | - * @param null $dt_frmt valid datetime format used for date (if '' then we just use the default on the field, if NULL we use the last-used format) |
|
807 | - * @param null $tm_frmt Same as above except this is for time format |
|
806 | + * @param string|null $dt_frmt valid datetime format used for date (if '' then we just use the default on the field, if NULL we use the last-used format) |
|
807 | + * @param null|string $tm_frmt Same as above except this is for time format |
|
808 | 808 | * @param string $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time. |
809 | 809 | * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
810 | - * @return void | string | bool | EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown if field is not a valid dtt field, or void if echoing |
|
810 | + * @return string|boolean | string | bool | EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown if field is not a valid dtt field, or void if echoing |
|
811 | 811 | */ |
812 | 812 | protected function _get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE ) { |
813 | 813 | |
@@ -1289,7 +1289,7 @@ discard block |
||
1289 | 1289 | |
1290 | 1290 | /** |
1291 | 1291 | * for getting a model while instantiated. |
1292 | - * @return \EEM_Base | \EEM_CPT_Base |
|
1292 | + * @return boolean | \EEM_CPT_Base |
|
1293 | 1293 | */ |
1294 | 1294 | public function get_model() { |
1295 | 1295 | $modelName = self::_get_model_classname( get_class($this) ); |
@@ -1320,7 +1320,7 @@ discard block |
||
1320 | 1320 | * If there is a key in the incoming array that matches the primary key for the model AND it is not null, then we check the db. If there's a an object we return it. If not we return false. |
1321 | 1321 | * @param array $props_n_values incoming array of properties and their values |
1322 | 1322 | * @param string $classname the classname of the child class |
1323 | - * @param null $timezone |
|
1323 | + * @param null|string $timezone |
|
1324 | 1324 | * @return mixed (EE_Base_Class|bool) |
1325 | 1325 | */ |
1326 | 1326 | protected static function _check_for_object( $props_n_values, $classname, $timezone = NULL ) { |
@@ -1356,7 +1356,7 @@ discard block |
||
1356 | 1356 | * @param $classname |
1357 | 1357 | * @param null $timezone |
1358 | 1358 | * @throws EE_Error |
1359 | - * @return EEM_Base |
|
1359 | + * @return boolean |
|
1360 | 1360 | */ |
1361 | 1361 | protected static function _get_model( $classname, $timezone = NULL ){ |
1362 | 1362 | //find model for this class |
@@ -1372,8 +1372,8 @@ discard block |
||
1372 | 1372 | /** |
1373 | 1373 | * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee) |
1374 | 1374 | * @param string $model_classname |
1375 | - * @param null $timezone |
|
1376 | - * @return EEM_Base |
|
1375 | + * @param string|null $timezone |
|
1376 | + * @return boolean |
|
1377 | 1377 | */ |
1378 | 1378 | protected static function _get_model_instance_with_name($model_classname, $timezone = NULL){ |
1379 | 1379 | $model_classname = str_replace( 'EEM_', '', $model_classname ); |
@@ -1548,7 +1548,7 @@ discard block |
||
1548 | 1548 | /** |
1549 | 1549 | * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default, |
1550 | 1550 | * unless otherwise specified in the $query_params |
1551 | - * @param $relation_name model_name like 'Event', or 'Registration' |
|
1551 | + * @param string $relation_name model_name like 'Event', or 'Registration' |
|
1552 | 1552 | * @param array $query_params like EEM_Base::get_all's |
1553 | 1553 | * @param string $field_to_count name of field to count by. By default, uses primary key |
1554 | 1554 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
@@ -1563,7 +1563,7 @@ discard block |
||
1563 | 1563 | /** |
1564 | 1564 | * Instead of getting the related model objects, simply sums up the values of the specified field. |
1565 | 1565 | * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params |
1566 | - * @param $relation_name model_name like 'Event', or 'Registration' |
|
1566 | + * @param string $relation_name model_name like 'Event', or 'Registration' |
|
1567 | 1567 | * @param array $query_params like EEM_Base::get_all's |
1568 | 1568 | * @param string $field_to_sum name of field to count by. |
1569 | 1569 | * By default, uses primary key (which doesn't make much sense, so you should probably change it) |
@@ -1824,7 +1824,7 @@ discard block |
||
1824 | 1824 | * You can specify $default is case you haven't found the extra meta |
1825 | 1825 | * @param string $meta_key |
1826 | 1826 | * @param boolean $single |
1827 | - * @param mixed $default if we don't find anything, what should we return? |
|
1827 | + * @param string|false $default if we don't find anything, what should we return? |
|
1828 | 1828 | * @return mixed single value if $single; array if ! $single |
1829 | 1829 | */ |
1830 | 1830 | public function get_extra_meta($meta_key,$single = FALSE,$default = NULL){ |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
3 | 5 | /** |
4 | 6 | * Event Espresso |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | -do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | +do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3 | 3 | /** |
4 | 4 | * Event Espresso |
5 | 5 | * |
@@ -23,16 +23,16 @@ discard block |
||
23 | 23 | * @subpackage includes/classes/EE_Checkin.class.php |
24 | 24 | * @author Darren Ethier |
25 | 25 | */ |
26 | -class EE_Checkin extends EE_Base_Class{ |
|
26 | +class EE_Checkin extends EE_Base_Class { |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @param array $props_n_values |
30 | 30 | * @param null $timezone |
31 | 31 | * @return EE_Checkin|mixed |
32 | 32 | */ |
33 | - public static function new_instance( $props_n_values = array(), $timezone = NULL ) { |
|
34 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone ); |
|
35 | - return $has_object ? $has_object : new self( $props_n_values, FALSE, $timezone ); |
|
33 | + public static function new_instance($props_n_values = array(), $timezone = NULL) { |
|
34 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
35 | + return $has_object ? $has_object : new self($props_n_values, FALSE, $timezone); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | * @param null $timezone |
43 | 43 | * @return EE_Checkin |
44 | 44 | */ |
45 | - public static function new_instance_from_db ( $props_n_values = array(), $timezone = NULL ) { |
|
46 | - return new self( $props_n_values, TRUE, $timezone ); |
|
45 | + public static function new_instance_from_db($props_n_values = array(), $timezone = NULL) { |
|
46 | + return new self($props_n_values, TRUE, $timezone); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 |
@@ -1,7 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
3 | +if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | +} |
|
5 | 6 | /** |
6 | 7 | * Event Espresso |
7 | 8 | * |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | /** |
50 | 50 | * |
51 | 51 | * @param type $props_n_values |
52 | - * @return EE_Answer |
|
52 | + * @return EE_Currency |
|
53 | 53 | */ |
54 | 54 | public static function new_instance_from_db ( $props_n_values = array() ) { |
55 | 55 | $classname = __CLASS__; |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | } |
61 | 61 | /** |
62 | 62 | * Gets code |
63 | - * @return string |
|
63 | + * @return boolean |
|
64 | 64 | */ |
65 | 65 | function code() { |
66 | 66 | return $this->get('CUR_code'); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | /** |
70 | 70 | * Sets code |
71 | 71 | * @param string $code |
72 | - * @return boolean |
|
72 | + * @return boolean|null |
|
73 | 73 | */ |
74 | 74 | function set_code($code) { |
75 | 75 | return $this->set('CUR_code', $code); |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | /** |
86 | 86 | * Sets active |
87 | 87 | * @param boolean $active |
88 | - * @return boolean |
|
88 | + * @return boolean|null |
|
89 | 89 | */ |
90 | 90 | function set_active($active) { |
91 | 91 | return $this->set('CUR_active', $active); |
92 | 92 | } |
93 | 93 | /** |
94 | 94 | * Gets dec_plc |
95 | - * @return int |
|
95 | + * @return boolean |
|
96 | 96 | */ |
97 | 97 | function dec_plc() { |
98 | 98 | return $this->get('CUR_dec_plc'); |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | /** |
102 | 102 | * Sets dec_plc |
103 | 103 | * @param int $dec_plc |
104 | - * @return boolean |
|
104 | + * @return boolean|null |
|
105 | 105 | */ |
106 | 106 | function set_dec_plc($dec_plc) { |
107 | 107 | return $this->set('CUR_dec_plc', $dec_plc); |
108 | 108 | } |
109 | 109 | /** |
110 | 110 | * Gets plural |
111 | - * @return string |
|
111 | + * @return boolean |
|
112 | 112 | */ |
113 | 113 | function plural_name() { |
114 | 114 | return $this->get('CUR_plural'); |
@@ -117,14 +117,14 @@ discard block |
||
117 | 117 | /** |
118 | 118 | * Sets plural |
119 | 119 | * @param string $plural |
120 | - * @return boolean |
|
120 | + * @return boolean|null |
|
121 | 121 | */ |
122 | 122 | function set_plural_name($plural) { |
123 | 123 | return $this->set('CUR_plural', $plural); |
124 | 124 | } |
125 | 125 | /** |
126 | 126 | * Gets sign |
127 | - * @return string |
|
127 | + * @return boolean |
|
128 | 128 | */ |
129 | 129 | function sign() { |
130 | 130 | return $this->get('CUR_sign'); |
@@ -133,14 +133,14 @@ discard block |
||
133 | 133 | /** |
134 | 134 | * Sets sign |
135 | 135 | * @param string $sign |
136 | - * @return boolean |
|
136 | + * @return boolean|null |
|
137 | 137 | */ |
138 | 138 | function set_sign($sign) { |
139 | 139 | return $this->set('CUR_sign', $sign); |
140 | 140 | } |
141 | 141 | /** |
142 | 142 | * Gets single |
143 | - * @return string |
|
143 | + * @return boolean |
|
144 | 144 | */ |
145 | 145 | function singular_name() { |
146 | 146 | return $this->get('CUR_single'); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | /** |
150 | 150 | * Sets single |
151 | 151 | * @param string $single |
152 | - * @return boolean |
|
152 | + * @return boolean|null |
|
153 | 153 | */ |
154 | 154 | function set_singular_name($single) { |
155 | 155 | return $this->set('CUR_single', $single); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | |
6 | 6 | /** |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * |
26 | 26 | * ------------------------------------------------------------------------ |
27 | 27 | */ |
28 | -class EE_Currency extends EE_Base_Class{ |
|
28 | +class EE_Currency extends EE_Base_Class { |
|
29 | 29 | |
30 | 30 | /** Currency COde @var CUR_code*/ protected $_CUR_code = NULL; |
31 | 31 | /** Currency Name Singular @var CUR_single*/ protected $_CUR_single = NULL; |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | * @param type $props_n_values |
40 | 40 | * @return EE_Answer |
41 | 41 | */ |
42 | - public static function new_instance( $props_n_values = array() ) { |
|
42 | + public static function new_instance($props_n_values = array()) { |
|
43 | 43 | $classname = __CLASS__; |
44 | - $has_object = parent::_check_for_object( $props_n_values, $classname ); |
|
44 | + $has_object = parent::_check_for_object($props_n_values, $classname); |
|
45 | 45 | // d( $has_object ); |
46 | - return $has_object ? $has_object : new self( $props_n_values); |
|
46 | + return $has_object ? $has_object : new self($props_n_values); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | * @param type $props_n_values |
52 | 52 | * @return EE_Answer |
53 | 53 | */ |
54 | - public static function new_instance_from_db ( $props_n_values = array() ) { |
|
54 | + public static function new_instance_from_db($props_n_values = array()) { |
|
55 | 55 | $classname = __CLASS__; |
56 | 56 | // $mapped_object = parent::_get_object_from_entity_mapper($props_n_values, $classname); |
57 | 57 | // d( $mapped_object ); |
58 | 58 | // return $mapped_object ? $mapped_object : new self( $props_n_values, TRUE ); |
59 | - return new self( $props_n_values, TRUE ); |
|
59 | + return new self($props_n_values, TRUE); |
|
60 | 60 | } |
61 | 61 | /** |
62 | 62 | * Gets code |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * Gets a prettier name |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - function name(){ |
|
162 | - return sprintf(__("%s (%s)", "event_espresso"),$this->code(),$this->plural_name()); |
|
161 | + function name() { |
|
162 | + return sprintf(__("%s (%s)", "event_espresso"), $this->code(), $this->plural_name()); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | } |
@@ -1,7 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
3 | +if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | +} |
|
5 | 6 | /** |
6 | 7 | * Event Espresso |
7 | 8 | * |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | |
6 | 6 | /** |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * |
27 | 27 | * ------------------------------------------------------------------------ |
28 | 28 | */ |
29 | -class EE_Currency_Payment_Method extends EE_Base_Class{ |
|
29 | +class EE_Currency_Payment_Method extends EE_Base_Class { |
|
30 | 30 | |
31 | 31 | /** Currency to Payment Method Link ID @var CPM_ID*/ |
32 | 32 | protected $_CPM_ID = NULL; |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | * @param array $props_n_values |
45 | 45 | * @return EE_Currency_Payment_Method |
46 | 46 | */ |
47 | - public static function new_instance( $props_n_values = array() ) { |
|
48 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__ ); |
|
49 | - return $has_object ? $has_object : new self( $props_n_values); |
|
47 | + public static function new_instance($props_n_values = array()) { |
|
48 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
49 | + return $has_object ? $has_object : new self($props_n_values); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * @param array $props_n_values |
55 | 55 | * @return EE_Currency_Payment_Method |
56 | 56 | */ |
57 | - public static function new_instance_from_db ( $props_n_values = array() ) { |
|
58 | - return new self( $props_n_values, TRUE ); |
|
57 | + public static function new_instance_from_db($props_n_values = array()) { |
|
58 | + return new self($props_n_values, TRUE); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -35,9 +35,9 @@ discard block |
||
35 | 35 | * @param string $timezone |
36 | 36 | * @return EE_Ticket_Template|mixed |
37 | 37 | */ |
38 | - public static function new_instance( $props_n_values = array(), $timezone = '' ) { |
|
39 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone ); |
|
40 | - return $has_object ? $has_object : new self( $props_n_values, FALSE, $timezone ); |
|
38 | + public static function new_instance($props_n_values = array(), $timezone = '') { |
|
39 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
40 | + return $has_object ? $has_object : new self($props_n_values, FALSE, $timezone); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | * @param string $timezone |
48 | 48 | * @return EE_Ticket_Template |
49 | 49 | */ |
50 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = '' ) { |
|
51 | - return new self( $props_n_values, TRUE, $timezone ); |
|
50 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') { |
|
51 | + return new self($props_n_values, TRUE, $timezone); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 |