@@ -42,11 +42,11 @@ |
||
42 | 42 | 'Price' => new EE_Belongs_To_Relation() |
43 | 43 | ); |
44 | 44 | $this->_model_chain_to_wp_user = 'Ticket'; |
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
45 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
46 | 46 | // account for default tickets in the caps |
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
50 | 50 | // follow the caps of the ticket |
51 | 51 | $this->_caps_slug = 'tickets'; |
52 | 52 | parent::__construct($timezone); |
@@ -11,43 +11,43 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_Ticket_Price extends EEM_Base |
13 | 13 | { |
14 | - // private instance of the EEM_Ticket_Price object |
|
15 | - protected static $_instance = null; |
|
14 | + // private instance of the EEM_Ticket_Price object |
|
15 | + protected static $_instance = null; |
|
16 | 16 | |
17 | - /** |
|
18 | - * private constructor to prevent direct creation |
|
19 | - * @Constructor |
|
20 | - * @access protected |
|
21 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - protected function __construct($timezone) |
|
25 | - { |
|
26 | - $this->singular_item = esc_html__('Ticket Price', 'event_espresso'); |
|
27 | - $this->plural_item = esc_html__('Ticket Prices', 'event_espresso'); |
|
17 | + /** |
|
18 | + * private constructor to prevent direct creation |
|
19 | + * @Constructor |
|
20 | + * @access protected |
|
21 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + protected function __construct($timezone) |
|
25 | + { |
|
26 | + $this->singular_item = esc_html__('Ticket Price', 'event_espresso'); |
|
27 | + $this->plural_item = esc_html__('Ticket Prices', 'event_espresso'); |
|
28 | 28 | |
29 | - $this->_tables = array( |
|
30 | - 'Ticket_Price' => new EE_Primary_Table('esp_ticket_price', 'TKP_ID') |
|
31 | - ); |
|
32 | - $this->_fields = array( |
|
33 | - 'Ticket_Price' => array( |
|
34 | - 'TKP_ID' => new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'), |
|
35 | - 'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'), |
|
36 | - 'PRC_ID' => new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'), |
|
37 | - ) |
|
38 | - ); |
|
39 | - $this->_model_relations = array( |
|
40 | - 'Ticket' => new EE_Belongs_To_Relation(), |
|
41 | - 'Price' => new EE_Belongs_To_Relation() |
|
42 | - ); |
|
43 | - $this->_model_chain_to_wp_user = 'Ticket'; |
|
44 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
45 | - // account for default tickets in the caps |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | - // follow the caps of the ticket |
|
50 | - $this->_caps_slug = 'tickets'; |
|
51 | - parent::__construct($timezone); |
|
52 | - } |
|
29 | + $this->_tables = array( |
|
30 | + 'Ticket_Price' => new EE_Primary_Table('esp_ticket_price', 'TKP_ID') |
|
31 | + ); |
|
32 | + $this->_fields = array( |
|
33 | + 'Ticket_Price' => array( |
|
34 | + 'TKP_ID' => new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'), |
|
35 | + 'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'), |
|
36 | + 'PRC_ID' => new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'), |
|
37 | + ) |
|
38 | + ); |
|
39 | + $this->_model_relations = array( |
|
40 | + 'Ticket' => new EE_Belongs_To_Relation(), |
|
41 | + 'Price' => new EE_Belongs_To_Relation() |
|
42 | + ); |
|
43 | + $this->_model_chain_to_wp_user = 'Ticket'; |
|
44 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
45 | + // account for default tickets in the caps |
|
46 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | + // follow the caps of the ticket |
|
50 | + $this->_caps_slug = 'tickets'; |
|
51 | + parent::__construct($timezone); |
|
52 | + } |
|
53 | 53 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | 'Payment_Method' => new EE_Belongs_To_Relation() |
35 | 35 | ); |
36 | 36 | // this model is generally available for reading |
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
37 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
38 | 38 | $this->_caps_slug = 'payment_methods'; |
39 | 39 | parent::__construct($timezone); |
40 | 40 | } |
@@ -11,31 +11,31 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_Currency_Payment_Method extends EEM_Base |
13 | 13 | { |
14 | - // private instance of the Attendee object |
|
15 | - protected static $_instance = null; |
|
14 | + // private instance of the Attendee object |
|
15 | + protected static $_instance = null; |
|
16 | 16 | |
17 | 17 | |
18 | - protected function __construct($timezone = null) |
|
19 | - { |
|
20 | - $this->singular_item = esc_html__('Currency Usable by Payment Method', 'event_espresso'); |
|
21 | - $this->plural_item = esc_html__('Currencies Usable by Payment Methods', 'event_espresso'); |
|
22 | - $this->_tables = array( |
|
23 | - 'Currency_Payment_Method' => new EE_Primary_Table('esp_currency_payment_method', 'CPM_ID') |
|
24 | - ); |
|
25 | - $this->_fields = array( |
|
26 | - 'Currency_Payment_Method' => array( |
|
27 | - 'CPM_ID' => new EE_Primary_Key_Int_Field('CPM_ID', esc_html__('Currency to Payment Method LInk ID', 'event_espresso')), |
|
28 | - 'CUR_code' => new EE_Foreign_Key_String_Field('CUR_code', esc_html__('Currency Code', 'event_espresso'), false, '', 'Currency'), |
|
29 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', esc_html__('Paymetn Method ID', 'event_espresso'), false, 0, 'Payment_Method') |
|
30 | - ) |
|
31 | - ); |
|
32 | - $this->_model_relations = array( |
|
33 | - 'Currency' => new EE_Belongs_To_Relation(), |
|
34 | - 'Payment_Method' => new EE_Belongs_To_Relation() |
|
35 | - ); |
|
36 | - // this model is generally available for reading |
|
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
38 | - $this->_caps_slug = 'payment_methods'; |
|
39 | - parent::__construct($timezone); |
|
40 | - } |
|
18 | + protected function __construct($timezone = null) |
|
19 | + { |
|
20 | + $this->singular_item = esc_html__('Currency Usable by Payment Method', 'event_espresso'); |
|
21 | + $this->plural_item = esc_html__('Currencies Usable by Payment Methods', 'event_espresso'); |
|
22 | + $this->_tables = array( |
|
23 | + 'Currency_Payment_Method' => new EE_Primary_Table('esp_currency_payment_method', 'CPM_ID') |
|
24 | + ); |
|
25 | + $this->_fields = array( |
|
26 | + 'Currency_Payment_Method' => array( |
|
27 | + 'CPM_ID' => new EE_Primary_Key_Int_Field('CPM_ID', esc_html__('Currency to Payment Method LInk ID', 'event_espresso')), |
|
28 | + 'CUR_code' => new EE_Foreign_Key_String_Field('CUR_code', esc_html__('Currency Code', 'event_espresso'), false, '', 'Currency'), |
|
29 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', esc_html__('Paymetn Method ID', 'event_espresso'), false, 0, 'Payment_Method') |
|
30 | + ) |
|
31 | + ); |
|
32 | + $this->_model_relations = array( |
|
33 | + 'Currency' => new EE_Belongs_To_Relation(), |
|
34 | + 'Payment_Method' => new EE_Belongs_To_Relation() |
|
35 | + ); |
|
36 | + // this model is generally available for reading |
|
37 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
38 | + $this->_caps_slug = 'payment_methods'; |
|
39 | + parent::__construct($timezone); |
|
40 | + } |
|
41 | 41 | } |
@@ -9,153 +9,153 @@ |
||
9 | 9 | */ |
10 | 10 | class EE_Model_Parser |
11 | 11 | { |
12 | - const table_alias_model_relation_chain_separator = '__'; |
|
13 | - const table_alias_model_relation_chain_prefix_end = '___'; |
|
14 | - /** |
|
15 | - * Adds a period onto the front and end of the string. This often helps in searching. |
|
16 | - * For example, if we want to find the model name "Event", it can be tricky when the following are possible |
|
17 | - * "","Event.EVT_ID","Event","Event_Venue.Venue.VNU_ID",etc. It's easier to look for ".Event." in |
|
18 | - * "..",".Event.EVT_ID.", ".Event.", and ".Event_Venue.Venue.VNU_ID", especially when the last example should NOT |
|
19 | - * be found because the "Event" model isn't mentioned- it's just a string that has a model name that coincidentally |
|
20 | - * has it as a substring |
|
21 | - * @param string $string_to_pad |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public static function pad_with_periods($string_to_pad) |
|
25 | - { |
|
26 | - return "." . $string_to_pad . "."; |
|
27 | - } |
|
28 | - /** |
|
29 | - * Basically undoes _pad_with_periods |
|
30 | - * @param string $string_to_trim |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - public static function trim_periods($string_to_trim) |
|
34 | - { |
|
35 | - return trim($string_to_trim, '.'); |
|
36 | - } |
|
12 | + const table_alias_model_relation_chain_separator = '__'; |
|
13 | + const table_alias_model_relation_chain_prefix_end = '___'; |
|
14 | + /** |
|
15 | + * Adds a period onto the front and end of the string. This often helps in searching. |
|
16 | + * For example, if we want to find the model name "Event", it can be tricky when the following are possible |
|
17 | + * "","Event.EVT_ID","Event","Event_Venue.Venue.VNU_ID",etc. It's easier to look for ".Event." in |
|
18 | + * "..",".Event.EVT_ID.", ".Event.", and ".Event_Venue.Venue.VNU_ID", especially when the last example should NOT |
|
19 | + * be found because the "Event" model isn't mentioned- it's just a string that has a model name that coincidentally |
|
20 | + * has it as a substring |
|
21 | + * @param string $string_to_pad |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public static function pad_with_periods($string_to_pad) |
|
25 | + { |
|
26 | + return "." . $string_to_pad . "."; |
|
27 | + } |
|
28 | + /** |
|
29 | + * Basically undoes _pad_with_periods |
|
30 | + * @param string $string_to_trim |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + public static function trim_periods($string_to_trim) |
|
34 | + { |
|
35 | + return trim($string_to_trim, '.'); |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Gets the calculated table's alias |
|
42 | - * @param string $model_relation_chain or query param |
|
43 | - * @param $this_model_name |
|
44 | - * @return string which can be added onto table aliases to make them unique |
|
45 | - */ |
|
46 | - public static function extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this_model_name) |
|
47 | - { |
|
48 | - // eg $model_relation_chain = 'Venue.Event_Venue.Event.Registration", and $this_model_name = 'Event' |
|
49 | - $model_relation_chain = self::pad_with_periods($model_relation_chain); |
|
50 | - $this_model_name = self::pad_with_periods($this_model_name); |
|
51 | - // eg '.Venue.Event_Venue.Event.Registration." and '.Event.' |
|
52 | - // remove this model name and everything afterwards |
|
53 | - $pos_of_model_name = strpos($model_relation_chain, $this_model_name); |
|
54 | - $model_relation_chain = substr($model_relation_chain, 0, $pos_of_model_name); |
|
55 | - // eg '.Venue.Event_Venue.' |
|
56 | - // trim periods |
|
57 | - $model_relation_chain = self::trim_periods($model_relation_chain); |
|
58 | - // eg 'Venue.Event_Venue' |
|
59 | - // replace periods with double-underscores |
|
60 | - $model_relation_chain = str_replace(".", self::table_alias_model_relation_chain_separator, $model_relation_chain); |
|
61 | - // eg 'Venue__Event_Venue' |
|
62 | - if ($model_relation_chain != '') { |
|
63 | - $model_relation_chain = $model_relation_chain . self::table_alias_model_relation_chain_prefix_end; |
|
64 | - } |
|
65 | - // eg 'Venue_Event_Venue___' |
|
66 | - return $model_relation_chain; |
|
67 | - } |
|
68 | - /** |
|
69 | - * Gets the table's alias (without prefix or anything) |
|
70 | - * @param string $table_alias_with_model_relation_chain_prefix which CAN have a table alias model relation chain prefix (or not) |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public static function remove_table_alias_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix) |
|
74 | - { |
|
75 | - // does this actually have a table alias model relation chain prefix? |
|
76 | - $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end); |
|
77 | - if ($pos !== false) { |
|
78 | - // yes |
|
79 | - // find that triple underscore and remove it and everything before it |
|
80 | - $table_alias = substr($table_alias_with_model_relation_chain_prefix, $pos + strlen(self::table_alias_model_relation_chain_prefix_end)); |
|
81 | - } else { |
|
82 | - $table_alias = $table_alias_with_model_relation_chain_prefix; |
|
83 | - } |
|
84 | - return $table_alias; |
|
85 | - } |
|
86 | - /** |
|
87 | - * Gets the table alias model relation chain prefix from the table alias already containing it |
|
88 | - * @param string $table_alias_with_model_relation_chain_prefix |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public static function get_prefix_from_table_alias_with_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix) |
|
92 | - { |
|
93 | - // does this actually have a table alias model relation chain prefix? |
|
94 | - $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end); |
|
95 | - if ($pos !== false) { |
|
96 | - // yes |
|
97 | - // find that triple underscore and remove it and everything before it |
|
98 | - $prefix = substr($table_alias_with_model_relation_chain_prefix, 0, $pos + strlen(self::table_alias_model_relation_chain_prefix_end)); |
|
99 | - } else { |
|
100 | - $prefix = ''; |
|
101 | - } |
|
102 | - return $prefix; |
|
103 | - } |
|
40 | + /** |
|
41 | + * Gets the calculated table's alias |
|
42 | + * @param string $model_relation_chain or query param |
|
43 | + * @param $this_model_name |
|
44 | + * @return string which can be added onto table aliases to make them unique |
|
45 | + */ |
|
46 | + public static function extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this_model_name) |
|
47 | + { |
|
48 | + // eg $model_relation_chain = 'Venue.Event_Venue.Event.Registration", and $this_model_name = 'Event' |
|
49 | + $model_relation_chain = self::pad_with_periods($model_relation_chain); |
|
50 | + $this_model_name = self::pad_with_periods($this_model_name); |
|
51 | + // eg '.Venue.Event_Venue.Event.Registration." and '.Event.' |
|
52 | + // remove this model name and everything afterwards |
|
53 | + $pos_of_model_name = strpos($model_relation_chain, $this_model_name); |
|
54 | + $model_relation_chain = substr($model_relation_chain, 0, $pos_of_model_name); |
|
55 | + // eg '.Venue.Event_Venue.' |
|
56 | + // trim periods |
|
57 | + $model_relation_chain = self::trim_periods($model_relation_chain); |
|
58 | + // eg 'Venue.Event_Venue' |
|
59 | + // replace periods with double-underscores |
|
60 | + $model_relation_chain = str_replace(".", self::table_alias_model_relation_chain_separator, $model_relation_chain); |
|
61 | + // eg 'Venue__Event_Venue' |
|
62 | + if ($model_relation_chain != '') { |
|
63 | + $model_relation_chain = $model_relation_chain . self::table_alias_model_relation_chain_prefix_end; |
|
64 | + } |
|
65 | + // eg 'Venue_Event_Venue___' |
|
66 | + return $model_relation_chain; |
|
67 | + } |
|
68 | + /** |
|
69 | + * Gets the table's alias (without prefix or anything) |
|
70 | + * @param string $table_alias_with_model_relation_chain_prefix which CAN have a table alias model relation chain prefix (or not) |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public static function remove_table_alias_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix) |
|
74 | + { |
|
75 | + // does this actually have a table alias model relation chain prefix? |
|
76 | + $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end); |
|
77 | + if ($pos !== false) { |
|
78 | + // yes |
|
79 | + // find that triple underscore and remove it and everything before it |
|
80 | + $table_alias = substr($table_alias_with_model_relation_chain_prefix, $pos + strlen(self::table_alias_model_relation_chain_prefix_end)); |
|
81 | + } else { |
|
82 | + $table_alias = $table_alias_with_model_relation_chain_prefix; |
|
83 | + } |
|
84 | + return $table_alias; |
|
85 | + } |
|
86 | + /** |
|
87 | + * Gets the table alias model relation chain prefix from the table alias already containing it |
|
88 | + * @param string $table_alias_with_model_relation_chain_prefix |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public static function get_prefix_from_table_alias_with_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix) |
|
92 | + { |
|
93 | + // does this actually have a table alias model relation chain prefix? |
|
94 | + $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end); |
|
95 | + if ($pos !== false) { |
|
96 | + // yes |
|
97 | + // find that triple underscore and remove it and everything before it |
|
98 | + $prefix = substr($table_alias_with_model_relation_chain_prefix, 0, $pos + strlen(self::table_alias_model_relation_chain_prefix_end)); |
|
99 | + } else { |
|
100 | + $prefix = ''; |
|
101 | + } |
|
102 | + return $prefix; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Gets the table alias model relation chain prefix (ie, what can be prepended onto |
|
107 | - * EE_Model_Field::get_qualified_column() to get the proper column name for that field |
|
108 | - * in a specific query) from teh query param (eg 'Registration.Event.EVT_ID'). |
|
109 | - * |
|
110 | - * @param string $model_name of the model on which the related query param was found to be belong |
|
111 | - * @param string $original_query_param |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public static function extract_table_alias_model_relation_chain_from_query_param($model_name, $original_query_param) |
|
115 | - { |
|
116 | - $relation_chain = self::extract_model_relation_chain($model_name, $original_query_param); |
|
117 | - $table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($relation_chain, $model_name); |
|
118 | - return $table_alias_with_model_relation_chain_prefix; |
|
119 | - } |
|
120 | - /** |
|
121 | - * Gets the model relation chain to $model_name from the $original_query_param. |
|
122 | - * Eg, if $model_name were 'Payment', and $original_query_param were 'Registration.Transaction.Payment.PAY_ID', |
|
123 | - * this would return 'Registration.Transaction.Payment'. Also if the query param were 'Registration.Transaction.Payment' |
|
124 | - * and $model_name were 'Payment', it should return 'Registration.Transaction.Payment' |
|
125 | - * @param string $model_name |
|
126 | - * @param string $original_query_param |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public static function extract_model_relation_chain($model_name, $original_query_param) |
|
130 | - { |
|
131 | - // prefix and postfix both with a period, as this facilitates searching |
|
132 | - $model_name = EE_Model_Parser::pad_with_periods($model_name); |
|
133 | - $original_query_param = EE_Model_Parser::pad_with_periods($original_query_param); |
|
134 | - $pos_of_model_string = strpos($original_query_param, $model_name); |
|
135 | - // eg, if we're looking for the model relation chain from Event to Payment, the original query param is probably something like |
|
136 | - // "Registration.Transaction.Payment.PAY_ID", $pos_of_model_string points to the 'P' or Payment. We want the string |
|
137 | - // "Registration.Transaction.Payment" |
|
138 | - $model_relation_chain = substr($original_query_param, 0, $pos_of_model_string + strlen($model_name)); |
|
139 | - return EE_Model_Parser::trim_periods($model_relation_chain); |
|
140 | - } |
|
105 | + /** |
|
106 | + * Gets the table alias model relation chain prefix (ie, what can be prepended onto |
|
107 | + * EE_Model_Field::get_qualified_column() to get the proper column name for that field |
|
108 | + * in a specific query) from teh query param (eg 'Registration.Event.EVT_ID'). |
|
109 | + * |
|
110 | + * @param string $model_name of the model on which the related query param was found to be belong |
|
111 | + * @param string $original_query_param |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public static function extract_table_alias_model_relation_chain_from_query_param($model_name, $original_query_param) |
|
115 | + { |
|
116 | + $relation_chain = self::extract_model_relation_chain($model_name, $original_query_param); |
|
117 | + $table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($relation_chain, $model_name); |
|
118 | + return $table_alias_with_model_relation_chain_prefix; |
|
119 | + } |
|
120 | + /** |
|
121 | + * Gets the model relation chain to $model_name from the $original_query_param. |
|
122 | + * Eg, if $model_name were 'Payment', and $original_query_param were 'Registration.Transaction.Payment.PAY_ID', |
|
123 | + * this would return 'Registration.Transaction.Payment'. Also if the query param were 'Registration.Transaction.Payment' |
|
124 | + * and $model_name were 'Payment', it should return 'Registration.Transaction.Payment' |
|
125 | + * @param string $model_name |
|
126 | + * @param string $original_query_param |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public static function extract_model_relation_chain($model_name, $original_query_param) |
|
130 | + { |
|
131 | + // prefix and postfix both with a period, as this facilitates searching |
|
132 | + $model_name = EE_Model_Parser::pad_with_periods($model_name); |
|
133 | + $original_query_param = EE_Model_Parser::pad_with_periods($original_query_param); |
|
134 | + $pos_of_model_string = strpos($original_query_param, $model_name); |
|
135 | + // eg, if we're looking for the model relation chain from Event to Payment, the original query param is probably something like |
|
136 | + // "Registration.Transaction.Payment.PAY_ID", $pos_of_model_string points to the 'P' or Payment. We want the string |
|
137 | + // "Registration.Transaction.Payment" |
|
138 | + $model_relation_chain = substr($original_query_param, 0, $pos_of_model_string + strlen($model_name)); |
|
139 | + return EE_Model_Parser::trim_periods($model_relation_chain); |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Replaces the specified model in teh model relation chain with teh join model. |
|
144 | - * Eg EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain( |
|
145 | - * "Ticket", "Datetime_Ticket", "Datetime.Ticket" ) will return |
|
146 | - * "Datetime.Datetime_Ticket" which can be used to find the table alias model relation chain prefix |
|
147 | - * using EE_Model_Parser::extract_table_alias_model_relation_chain_prefix |
|
148 | - * @param string $model_name |
|
149 | - * @param string $join_model_name |
|
150 | - * @param string $model_relation_chain |
|
151 | - * @return string |
|
152 | - */ |
|
153 | - public static function replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_name, $model_relation_chain) |
|
154 | - { |
|
155 | - $model_name = EE_Model_Parser::pad_with_periods($model_name); |
|
156 | - $join_model_name = EE_Model_Parser::pad_with_periods($join_model_name); |
|
157 | - $model_relation_chain = EE_Model_Parser::pad_with_periods($model_relation_chain); |
|
158 | - $replaced_with_periods = str_replace($model_name, $join_model_name, $model_relation_chain); |
|
159 | - return EE_Model_Parser::trim_periods($replaced_with_periods); |
|
160 | - } |
|
142 | + /** |
|
143 | + * Replaces the specified model in teh model relation chain with teh join model. |
|
144 | + * Eg EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain( |
|
145 | + * "Ticket", "Datetime_Ticket", "Datetime.Ticket" ) will return |
|
146 | + * "Datetime.Datetime_Ticket" which can be used to find the table alias model relation chain prefix |
|
147 | + * using EE_Model_Parser::extract_table_alias_model_relation_chain_prefix |
|
148 | + * @param string $model_name |
|
149 | + * @param string $join_model_name |
|
150 | + * @param string $model_relation_chain |
|
151 | + * @return string |
|
152 | + */ |
|
153 | + public static function replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_name, $model_relation_chain) |
|
154 | + { |
|
155 | + $model_name = EE_Model_Parser::pad_with_periods($model_name); |
|
156 | + $join_model_name = EE_Model_Parser::pad_with_periods($join_model_name); |
|
157 | + $model_relation_chain = EE_Model_Parser::pad_with_periods($model_relation_chain); |
|
158 | + $replaced_with_periods = str_replace($model_name, $join_model_name, $model_relation_chain); |
|
159 | + return EE_Model_Parser::trim_periods($replaced_with_periods); |
|
160 | + } |
|
161 | 161 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public static function pad_with_periods($string_to_pad) |
25 | 25 | { |
26 | - return "." . $string_to_pad . "."; |
|
26 | + return ".".$string_to_pad."."; |
|
27 | 27 | } |
28 | 28 | /** |
29 | 29 | * Basically undoes _pad_with_periods |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $model_relation_chain = str_replace(".", self::table_alias_model_relation_chain_separator, $model_relation_chain); |
61 | 61 | // eg 'Venue__Event_Venue' |
62 | 62 | if ($model_relation_chain != '') { |
63 | - $model_relation_chain = $model_relation_chain . self::table_alias_model_relation_chain_prefix_end; |
|
63 | + $model_relation_chain = $model_relation_chain.self::table_alias_model_relation_chain_prefix_end; |
|
64 | 64 | } |
65 | 65 | // eg 'Venue_Event_Venue___' |
66 | 66 | return $model_relation_chain; |
@@ -8,118 +8,118 @@ |
||
8 | 8 | */ |
9 | 9 | class EE_Secondary_Table extends EE_Table_Base |
10 | 10 | { |
11 | - protected $_extra_join_conditions; |
|
11 | + protected $_extra_join_conditions; |
|
12 | 12 | |
13 | - /** |
|
14 | - * |
|
15 | - * @global type $wpdb |
|
16 | - * @param string $table_name with or without wpdb prefix |
|
17 | - * @param string $pk_column name of primary key column on THIS table |
|
18 | - * @param string $fk_column the name of the COLUMN that is a foreign key to the primary table's primary key |
|
19 | - * @param string $extra_join_conditions string for additional SQL to add onto the join statement's ON condition |
|
20 | - * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install, |
|
21 | - * or whether each site on a multisite install has a copy of this table |
|
22 | - */ |
|
23 | - public function __construct($table_name, $pk_column, $fk_column = null, $extra_join_conditions = null, $global = false) |
|
24 | - { |
|
25 | - $this->_fk_on_table = $fk_column; |
|
26 | - $this->_extra_join_conditions = $extra_join_conditions; |
|
27 | - parent::__construct($table_name, $pk_column, $global); |
|
28 | - } |
|
29 | - public function get_fk_on_table() |
|
30 | - { |
|
31 | - return $this->_fk_on_table; |
|
32 | - } |
|
33 | - public function _construct_finalize_set_table_to_join_with(EE_Table_Base $table) |
|
34 | - { |
|
35 | - $this->_table_to_join_with = $table; |
|
36 | - } |
|
37 | - /** |
|
38 | - * |
|
39 | - * @return string of sql like "Event.post_type = 'event'", which gets added to |
|
40 | - * the end of the join statement with the primary table |
|
41 | - */ |
|
42 | - public function get_extra_join_conditions() |
|
43 | - { |
|
44 | - return $this->_extra_join_conditions; |
|
45 | - } |
|
46 | - /** |
|
47 | - * |
|
48 | - * @return EE_Primary_Table |
|
49 | - */ |
|
50 | - public function get_table_to_join_with() |
|
51 | - { |
|
52 | - return $this->_table_to_join_with; |
|
53 | - } |
|
54 | - /** |
|
55 | - * creates join statement FROM primary table |
|
56 | - * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk |
|
57 | - * |
|
58 | - * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery) |
|
59 | - * @return string of SQL |
|
60 | - */ |
|
61 | - public function get_join_sql($primary_table_alias_with_model_chain_prefix) |
|
62 | - { |
|
13 | + /** |
|
14 | + * |
|
15 | + * @global type $wpdb |
|
16 | + * @param string $table_name with or without wpdb prefix |
|
17 | + * @param string $pk_column name of primary key column on THIS table |
|
18 | + * @param string $fk_column the name of the COLUMN that is a foreign key to the primary table's primary key |
|
19 | + * @param string $extra_join_conditions string for additional SQL to add onto the join statement's ON condition |
|
20 | + * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install, |
|
21 | + * or whether each site on a multisite install has a copy of this table |
|
22 | + */ |
|
23 | + public function __construct($table_name, $pk_column, $fk_column = null, $extra_join_conditions = null, $global = false) |
|
24 | + { |
|
25 | + $this->_fk_on_table = $fk_column; |
|
26 | + $this->_extra_join_conditions = $extra_join_conditions; |
|
27 | + parent::__construct($table_name, $pk_column, $global); |
|
28 | + } |
|
29 | + public function get_fk_on_table() |
|
30 | + { |
|
31 | + return $this->_fk_on_table; |
|
32 | + } |
|
33 | + public function _construct_finalize_set_table_to_join_with(EE_Table_Base $table) |
|
34 | + { |
|
35 | + $this->_table_to_join_with = $table; |
|
36 | + } |
|
37 | + /** |
|
38 | + * |
|
39 | + * @return string of sql like "Event.post_type = 'event'", which gets added to |
|
40 | + * the end of the join statement with the primary table |
|
41 | + */ |
|
42 | + public function get_extra_join_conditions() |
|
43 | + { |
|
44 | + return $this->_extra_join_conditions; |
|
45 | + } |
|
46 | + /** |
|
47 | + * |
|
48 | + * @return EE_Primary_Table |
|
49 | + */ |
|
50 | + public function get_table_to_join_with() |
|
51 | + { |
|
52 | + return $this->_table_to_join_with; |
|
53 | + } |
|
54 | + /** |
|
55 | + * creates join statement FROM primary table |
|
56 | + * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk |
|
57 | + * |
|
58 | + * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery) |
|
59 | + * @return string of SQL |
|
60 | + */ |
|
61 | + public function get_join_sql($primary_table_alias_with_model_chain_prefix) |
|
62 | + { |
|
63 | 63 | |
64 | - $table_name = $this->get_table_name(); |
|
65 | - $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias(); |
|
66 | - $other_table_pk = $this->get_table_to_join_with()->get_pk_column(); |
|
67 | - $fk = $this->get_fk_on_table(); |
|
68 | - $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk "; |
|
69 | - if ($this->get_extra_join_conditions()) { |
|
70 | - $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
71 | - } |
|
72 | - return $join_sql; |
|
73 | - } |
|
64 | + $table_name = $this->get_table_name(); |
|
65 | + $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias(); |
|
66 | + $other_table_pk = $this->get_table_to_join_with()->get_pk_column(); |
|
67 | + $fk = $this->get_fk_on_table(); |
|
68 | + $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk "; |
|
69 | + if ($this->get_extra_join_conditions()) { |
|
70 | + $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
71 | + } |
|
72 | + return $join_sql; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * Produces join SQL like get_join_sql, except instead of joining the primary table to the |
|
78 | - * secondary table, does the inverse: joins the secondary table to the primary one. (Eg, isntead of |
|
79 | - * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns |
|
80 | - * " LEFT JOIN primary_table AS Primary ON ...". |
|
81 | - * This is useful if the secondary table is already included in the SQL, but the primary table is not yet. |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix) |
|
85 | - { |
|
86 | - $primary_table_name = $this->get_table_to_join_with()->get_table_name(); |
|
87 | - $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias(); |
|
88 | - $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column(); |
|
89 | - $fk = $this->get_fk_on_table(); |
|
90 | - $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk "; |
|
91 | - if ($this->get_extra_join_conditions()) { |
|
92 | - $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
93 | - } |
|
94 | - return $join_sql; |
|
95 | - } |
|
76 | + /** |
|
77 | + * Produces join SQL like get_join_sql, except instead of joining the primary table to the |
|
78 | + * secondary table, does the inverse: joins the secondary table to the primary one. (Eg, isntead of |
|
79 | + * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns |
|
80 | + * " LEFT JOIN primary_table AS Primary ON ...". |
|
81 | + * This is useful if the secondary table is already included in the SQL, but the primary table is not yet. |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix) |
|
85 | + { |
|
86 | + $primary_table_name = $this->get_table_to_join_with()->get_table_name(); |
|
87 | + $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias(); |
|
88 | + $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column(); |
|
89 | + $fk = $this->get_fk_on_table(); |
|
90 | + $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk "; |
|
91 | + if ($this->get_extra_join_conditions()) { |
|
92 | + $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
93 | + } |
|
94 | + return $join_sql; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * This prepares the join on the other table using a select with a internal limit. |
|
99 | - * @param mixed (array|string) $limit limit |
|
100 | - * @return string SQL to return |
|
101 | - */ |
|
102 | - public function get_select_join_limit_join($limit) |
|
103 | - { |
|
104 | - // first get the select |
|
105 | - $select = $this->get_select_join_limit($limit); |
|
106 | - $join_sql = $this->get_join_sql($select); |
|
107 | - return $join_sql; |
|
108 | - } |
|
97 | + /** |
|
98 | + * This prepares the join on the other table using a select with a internal limit. |
|
99 | + * @param mixed (array|string) $limit limit |
|
100 | + * @return string SQL to return |
|
101 | + */ |
|
102 | + public function get_select_join_limit_join($limit) |
|
103 | + { |
|
104 | + // first get the select |
|
105 | + $select = $this->get_select_join_limit($limit); |
|
106 | + $join_sql = $this->get_join_sql($select); |
|
107 | + return $join_sql; |
|
108 | + } |
|
109 | 109 | |
110 | 110 | |
111 | 111 | |
112 | - public function get_fully_qualified_fk_column() |
|
113 | - { |
|
114 | - $table_alias = $this->get_table_alias(); |
|
115 | - $fk = $this->get_fk_on_table(); |
|
116 | - return $table_alias . '.' . $fk; |
|
117 | - } |
|
112 | + public function get_fully_qualified_fk_column() |
|
113 | + { |
|
114 | + $table_alias = $this->get_table_alias(); |
|
115 | + $fk = $this->get_fk_on_table(); |
|
116 | + return $table_alias . '.' . $fk; |
|
117 | + } |
|
118 | 118 | |
119 | - public function get_fully_qualified_pk_on_fk_table() |
|
120 | - { |
|
121 | - $table_alias = $this->get_table_to_join_with()->get_table_alias(); |
|
122 | - $pk = $this->get_table_to_join_with()->get_pk_column(); |
|
123 | - return $table_alias . '.' . $pk; |
|
124 | - } |
|
119 | + public function get_fully_qualified_pk_on_fk_table() |
|
120 | + { |
|
121 | + $table_alias = $this->get_table_to_join_with()->get_table_alias(); |
|
122 | + $pk = $this->get_table_to_join_with()->get_pk_column(); |
|
123 | + return $table_alias . '.' . $pk; |
|
124 | + } |
|
125 | 125 | } |
@@ -62,12 +62,12 @@ discard block |
||
62 | 62 | { |
63 | 63 | |
64 | 64 | $table_name = $this->get_table_name(); |
65 | - $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias(); |
|
65 | + $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix).$this->get_table_alias(); |
|
66 | 66 | $other_table_pk = $this->get_table_to_join_with()->get_pk_column(); |
67 | 67 | $fk = $this->get_fk_on_table(); |
68 | 68 | $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk "; |
69 | 69 | if ($this->get_extra_join_conditions()) { |
70 | - $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
70 | + $join_sql .= "AND ".$this->get_extra_join_conditions(); |
|
71 | 71 | } |
72 | 72 | return $join_sql; |
73 | 73 | } |
@@ -84,12 +84,12 @@ discard block |
||
84 | 84 | public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix) |
85 | 85 | { |
86 | 86 | $primary_table_name = $this->get_table_to_join_with()->get_table_name(); |
87 | - $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias(); |
|
88 | - $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column(); |
|
87 | + $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix).$this->get_table_to_join_with()->get_table_alias(); |
|
88 | + $primary_table_pk = $this->get_table_to_join_with()->get_pk_column(); // $this->get_pk_column(); |
|
89 | 89 | $fk = $this->get_fk_on_table(); |
90 | 90 | $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk "; |
91 | 91 | if ($this->get_extra_join_conditions()) { |
92 | - $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
92 | + $join_sql .= "AND ".$this->get_extra_join_conditions(); |
|
93 | 93 | } |
94 | 94 | return $join_sql; |
95 | 95 | } |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | { |
114 | 114 | $table_alias = $this->get_table_alias(); |
115 | 115 | $fk = $this->get_fk_on_table(); |
116 | - return $table_alias . '.' . $fk; |
|
116 | + return $table_alias.'.'.$fk; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | public function get_fully_qualified_pk_on_fk_table() |
120 | 120 | { |
121 | 121 | $table_alias = $this->get_table_to_join_with()->get_table_alias(); |
122 | 122 | $pk = $this->get_table_to_join_with()->get_pk_column(); |
123 | - return $table_alias . '.' . $pk; |
|
123 | + return $table_alias.'.'.$pk; |
|
124 | 124 | } |
125 | 125 | } |
@@ -6,45 +6,45 @@ |
||
6 | 6 | */ |
7 | 7 | class EE_Index |
8 | 8 | { |
9 | - protected $_name; |
|
10 | - protected $_field_names; |
|
11 | - protected $_model_name; |
|
12 | - public function __construct($fields) |
|
13 | - { |
|
14 | - $this->_field_names = $fields; |
|
15 | - } |
|
16 | - public function _construct_finalize($name, $model_name) |
|
17 | - { |
|
18 | - $this->_name = $name; |
|
19 | - $this->_model_name = $model_name; |
|
20 | - } |
|
21 | - public function field_names() |
|
22 | - { |
|
23 | - return $this->_field_names; |
|
24 | - } |
|
25 | - /** |
|
26 | - * Internally used by get_this_model() and get_other_model() |
|
27 | - * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
|
28 | - * @return EEM_Base |
|
29 | - */ |
|
30 | - protected function _get_model($model_name) |
|
31 | - { |
|
32 | - $modelInstance = call_user_func("EEM_" . $model_name . "::instance"); |
|
33 | - return $modelInstance; |
|
34 | - } |
|
35 | - /** |
|
36 | - * Gets all the fields for this index |
|
37 | - * @return EE_Model_Field_Base[] |
|
38 | - */ |
|
39 | - public function fields() |
|
40 | - { |
|
41 | - $fields = array(); |
|
42 | - $model = $this->_get_model($this->_model_name); |
|
43 | - foreach ($model->field_settings() as $field_name => $field_obj) { |
|
44 | - if (in_array($field_name, $this->field_names())) { |
|
45 | - $fields[ $field_name ] = $field_obj; |
|
46 | - } |
|
47 | - } |
|
48 | - return $fields; |
|
49 | - } |
|
9 | + protected $_name; |
|
10 | + protected $_field_names; |
|
11 | + protected $_model_name; |
|
12 | + public function __construct($fields) |
|
13 | + { |
|
14 | + $this->_field_names = $fields; |
|
15 | + } |
|
16 | + public function _construct_finalize($name, $model_name) |
|
17 | + { |
|
18 | + $this->_name = $name; |
|
19 | + $this->_model_name = $model_name; |
|
20 | + } |
|
21 | + public function field_names() |
|
22 | + { |
|
23 | + return $this->_field_names; |
|
24 | + } |
|
25 | + /** |
|
26 | + * Internally used by get_this_model() and get_other_model() |
|
27 | + * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
|
28 | + * @return EEM_Base |
|
29 | + */ |
|
30 | + protected function _get_model($model_name) |
|
31 | + { |
|
32 | + $modelInstance = call_user_func("EEM_" . $model_name . "::instance"); |
|
33 | + return $modelInstance; |
|
34 | + } |
|
35 | + /** |
|
36 | + * Gets all the fields for this index |
|
37 | + * @return EE_Model_Field_Base[] |
|
38 | + */ |
|
39 | + public function fields() |
|
40 | + { |
|
41 | + $fields = array(); |
|
42 | + $model = $this->_get_model($this->_model_name); |
|
43 | + foreach ($model->field_settings() as $field_name => $field_obj) { |
|
44 | + if (in_array($field_name, $this->field_names())) { |
|
45 | + $fields[ $field_name ] = $field_obj; |
|
46 | + } |
|
47 | + } |
|
48 | + return $fields; |
|
49 | + } |
|
50 | 50 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | protected function _get_model($model_name) |
31 | 31 | { |
32 | - $modelInstance = call_user_func("EEM_" . $model_name . "::instance"); |
|
32 | + $modelInstance = call_user_func("EEM_".$model_name."::instance"); |
|
33 | 33 | return $modelInstance; |
34 | 34 | } |
35 | 35 | /** |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $model = $this->_get_model($this->_model_name); |
43 | 43 | foreach ($model->field_settings() as $field_name => $field_obj) { |
44 | 44 | if (in_array($field_name, $this->field_names())) { |
45 | - $fields[ $field_name ] = $field_obj; |
|
45 | + $fields[$field_name] = $field_obj; |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | return $fields; |
@@ -25,6 +25,6 @@ |
||
25 | 25 | */ |
26 | 26 | public function get_table_sql() |
27 | 27 | { |
28 | - return " " . $this->get_table_name() . " AS " . $this->get_table_alias() . " "; |
|
28 | + return " ".$this->get_table_name()." AS ".$this->get_table_alias()." "; |
|
29 | 29 | } |
30 | 30 | } |
@@ -6,24 +6,24 @@ |
||
6 | 6 | */ |
7 | 7 | class EE_Primary_Table extends EE_Table_Base |
8 | 8 | { |
9 | - /** |
|
10 | - * |
|
11 | - * @global type $wpdb |
|
12 | - * @param string $table_name with or without wpdb prefix |
|
13 | - * @param string $pk_column name of primary key column |
|
14 | - * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install, |
|
15 | - * or whether each site on a multisite install has a copy of this table |
|
16 | - */ |
|
17 | - public function __construct($table_name, $pk_column = null, $global = false) |
|
18 | - { |
|
19 | - parent::__construct($table_name, $pk_column, $global); |
|
20 | - } |
|
21 | - /** |
|
22 | - * Gets SQL for this table and assigning it an alias. Eg " wp_esp_attendee AS Attendee " |
|
23 | - * @return string |
|
24 | - */ |
|
25 | - public function get_table_sql() |
|
26 | - { |
|
27 | - return " " . $this->get_table_name() . " AS " . $this->get_table_alias() . " "; |
|
28 | - } |
|
9 | + /** |
|
10 | + * |
|
11 | + * @global type $wpdb |
|
12 | + * @param string $table_name with or without wpdb prefix |
|
13 | + * @param string $pk_column name of primary key column |
|
14 | + * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install, |
|
15 | + * or whether each site on a multisite install has a copy of this table |
|
16 | + */ |
|
17 | + public function __construct($table_name, $pk_column = null, $global = false) |
|
18 | + { |
|
19 | + parent::__construct($table_name, $pk_column, $global); |
|
20 | + } |
|
21 | + /** |
|
22 | + * Gets SQL for this table and assigning it an alias. Eg " wp_esp_attendee AS Attendee " |
|
23 | + * @return string |
|
24 | + */ |
|
25 | + public function get_table_sql() |
|
26 | + { |
|
27 | + return " " . $this->get_table_name() . " AS " . $this->get_table_alias() . " "; |
|
28 | + } |
|
29 | 29 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | 'Venue' => new EE_Has_Many_Relation(), |
43 | 43 | ); |
44 | 44 | // this model is generally available for reading |
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
45 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
46 | 46 | // @todo: only show STA_active |
47 | 47 | parent::__construct($timezone); |
48 | 48 | } |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function get_all_states() |
75 | 75 | { |
76 | - if (! self::$_all_states) { |
|
77 | - self::$_all_states = $this->get_all(array( 'order_by' => array( 'STA_name' => 'ASC' ), 'limit' => array( 0, 99999 ))); |
|
76 | + if ( ! self::$_all_states) { |
|
77 | + self::$_all_states = $this->get_all(array('order_by' => array('STA_name' => 'ASC'), 'limit' => array(0, 99999))); |
|
78 | 78 | } |
79 | 79 | return self::$_all_states; |
80 | 80 | } |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function get_all_active_states($countries = array(), $flush_cache = false) |
93 | 93 | { |
94 | - if (! self::$_active_states || $flush_cache) { |
|
94 | + if ( ! self::$_active_states || $flush_cache) { |
|
95 | 95 | $countries = is_array($countries) && ! empty($countries) ? $countries : EEM_Country::instance()->get_all_active_countries(); |
96 | - self::$_active_states = $this->get_all(array( |
|
97 | - array( 'STA_active' => true, 'CNT_ISO' => array( 'IN', array_keys($countries))), |
|
98 | - 'order_by' => array( 'STA_name' => 'ASC' ), |
|
99 | - 'limit' => array( 0, 99999 ), |
|
100 | - 'force_join' => array( 'Country' ) |
|
96 | + self::$_active_states = $this->get_all(array( |
|
97 | + array('STA_active' => true, 'CNT_ISO' => array('IN', array_keys($countries))), |
|
98 | + 'order_by' => array('STA_name' => 'ASC'), |
|
99 | + 'limit' => array(0, 99999), |
|
100 | + 'force_join' => array('Country') |
|
101 | 101 | )); |
102 | 102 | } |
103 | 103 | return self::$_active_states; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function get_all_states_of_active_countries() |
113 | 113 | { |
114 | - if ($states = $this->get_all(array( array( 'Country.CNT_active' => true, 'STA_active' => true ), 'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) { |
|
114 | + if ($states = $this->get_all(array(array('Country.CNT_active' => true, 'STA_active' => true), 'order_by' => array('Country.CNT_name' => 'ASC', 'STA_name' => 'ASC')))) { |
|
115 | 115 | return $states; |
116 | 116 | } |
117 | 117 | return false; |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function get_all_active_states_for_these_countries($countries) |
127 | 127 | { |
128 | - if (! $countries) { |
|
128 | + if ( ! $countries) { |
|
129 | 129 | return false; |
130 | 130 | } |
131 | - if ($states = $this->get_all(array( array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries)), 'STA_active' => true ), 'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) { |
|
131 | + if ($states = $this->get_all(array(array('Country.CNT_ISO' => array('IN', array_keys($countries)), 'STA_active' => true), 'order_by' => array('Country.CNT_name' => 'ASC', 'STA_name' => 'ASC')))) { |
|
132 | 132 | return $states; |
133 | 133 | } |
134 | 134 | return false; |
@@ -142,10 +142,10 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function get_all_states_for_these_countries($countries) |
144 | 144 | { |
145 | - if (! $countries) { |
|
145 | + if ( ! $countries) { |
|
146 | 146 | return false; |
147 | 147 | } |
148 | - if ($states = $this->get_all(array( array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries))), 'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) { |
|
148 | + if ($states = $this->get_all(array(array('Country.CNT_ISO' => array('IN', array_keys($countries))), 'order_by' => array('Country.CNT_name' => 'ASC', 'STA_name' => 'ASC')))) { |
|
149 | 149 | return $states; |
150 | 150 | } |
151 | 151 | return false; |
@@ -159,12 +159,12 @@ discard block |
||
159 | 159 | public function get_state_name_by_ID($state_ID) |
160 | 160 | { |
161 | 161 | if ( |
162 | - isset(self::$_all_states[ $state_ID ]) && |
|
163 | - self::$_all_states[ $state_ID ] instanceof EE_State |
|
162 | + isset(self::$_all_states[$state_ID]) && |
|
163 | + self::$_all_states[$state_ID] instanceof EE_State |
|
164 | 164 | ) { |
165 | - return self::$_all_states[ $state_ID ]->name(); |
|
165 | + return self::$_all_states[$state_ID]->name(); |
|
166 | 166 | } |
167 | - $names = $this->get_col(array( array( 'STA_ID' => $state_ID ), 'limit' => 1), 'STA_name'); |
|
167 | + $names = $this->get_col(array(array('STA_ID' => $state_ID), 'limit' => 1), 'STA_name'); |
|
168 | 168 | if (is_array($names) && ! empty($names)) { |
169 | 169 | return reset($names); |
170 | 170 | } else { |
@@ -11,163 +11,163 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_State extends EEM_Base |
13 | 13 | { |
14 | - // private instance of the Attendee object |
|
15 | - protected static $_instance = null; |
|
16 | - // array of all states |
|
17 | - private static $_all_states = false; |
|
18 | - // array of all active states |
|
19 | - private static $_active_states = false; |
|
20 | - |
|
21 | - protected function __construct($timezone = null) |
|
22 | - { |
|
23 | - $this->singular_item = esc_html__('State/Province', 'event_espresso'); |
|
24 | - $this->plural_item = esc_html__('States/Provinces', 'event_espresso'); |
|
25 | - |
|
26 | - $this->_tables = array( |
|
27 | - 'State' => new EE_Primary_Table('esp_state', 'STA_ID') |
|
28 | - ); |
|
29 | - |
|
30 | - $this->_fields = array( |
|
31 | - 'State' => array( |
|
32 | - 'STA_ID' => new EE_Primary_Key_Int_Field('STA_ID', esc_html__('State ID', 'event_espresso')), |
|
33 | - 'CNT_ISO' => new EE_Foreign_Key_String_Field('CNT_ISO', esc_html__('Country ISO Code', 'event_espresso'), false, null, 'Country'), |
|
34 | - 'STA_abbrev' => new EE_Plain_Text_Field('STA_abbrev', esc_html__('State Abbreviation', 'event_espresso'), false, ''), |
|
35 | - 'STA_name' => new EE_Plain_Text_Field('STA_name', esc_html__('State Name', 'event_espresso'), false, ''), |
|
36 | - 'STA_active' => new EE_Boolean_Field('STA_active', esc_html__('State Active Flag', 'event_espresso'), false, false) |
|
37 | - )); |
|
38 | - $this->_model_relations = array( |
|
39 | - 'Attendee' => new EE_Has_Many_Relation(), |
|
40 | - 'Country' => new EE_Belongs_To_Relation(), |
|
41 | - 'Venue' => new EE_Has_Many_Relation(), |
|
42 | - ); |
|
43 | - // this model is generally available for reading |
|
44 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
45 | - // @todo: only show STA_active |
|
46 | - parent::__construct($timezone); |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * reset_cached_states |
|
54 | - * |
|
55 | - * @access private |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function reset_cached_states() |
|
59 | - { |
|
60 | - EEM_State::$_active_states = array(); |
|
61 | - EEM_State::$_all_states = array(); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * _get_states |
|
69 | - * |
|
70 | - * @access private |
|
71 | - * @return array |
|
72 | - */ |
|
73 | - public function get_all_states() |
|
74 | - { |
|
75 | - if (! self::$_all_states) { |
|
76 | - self::$_all_states = $this->get_all(array( 'order_by' => array( 'STA_name' => 'ASC' ), 'limit' => array( 0, 99999 ))); |
|
77 | - } |
|
78 | - return self::$_all_states; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * _get_states |
|
85 | - * |
|
86 | - * @access public |
|
87 | - * @param array $countries |
|
88 | - * @param bool $flush_cache |
|
89 | - * @return array |
|
90 | - */ |
|
91 | - public function get_all_active_states($countries = array(), $flush_cache = false) |
|
92 | - { |
|
93 | - if (! self::$_active_states || $flush_cache) { |
|
94 | - $countries = is_array($countries) && ! empty($countries) ? $countries : EEM_Country::instance()->get_all_active_countries(); |
|
95 | - self::$_active_states = $this->get_all(array( |
|
96 | - array( 'STA_active' => true, 'CNT_ISO' => array( 'IN', array_keys($countries))), |
|
97 | - 'order_by' => array( 'STA_name' => 'ASC' ), |
|
98 | - 'limit' => array( 0, 99999 ), |
|
99 | - 'force_join' => array( 'Country' ) |
|
100 | - )); |
|
101 | - } |
|
102 | - return self::$_active_states; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * get_all_states_of_active_countries |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - public function get_all_states_of_active_countries() |
|
112 | - { |
|
113 | - if ($states = $this->get_all(array( array( 'Country.CNT_active' => true, 'STA_active' => true ), 'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) { |
|
114 | - return $states; |
|
115 | - } |
|
116 | - return false; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * get_all_states_of_active_countries |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public function get_all_active_states_for_these_countries($countries) |
|
126 | - { |
|
127 | - if (! $countries) { |
|
128 | - return false; |
|
129 | - } |
|
130 | - if ($states = $this->get_all(array( array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries)), 'STA_active' => true ), 'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) { |
|
131 | - return $states; |
|
132 | - } |
|
133 | - return false; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * get_all_states_of_active_countries |
|
140 | - * @return array |
|
141 | - */ |
|
142 | - public function get_all_states_for_these_countries($countries) |
|
143 | - { |
|
144 | - if (! $countries) { |
|
145 | - return false; |
|
146 | - } |
|
147 | - if ($states = $this->get_all(array( array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries))), 'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) { |
|
148 | - return $states; |
|
149 | - } |
|
150 | - return false; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Gets the state's name by its ID |
|
155 | - * @param string $state_ID |
|
156 | - * @return string |
|
157 | - */ |
|
158 | - public function get_state_name_by_ID($state_ID) |
|
159 | - { |
|
160 | - if ( |
|
161 | - isset(self::$_all_states[ $state_ID ]) && |
|
162 | - self::$_all_states[ $state_ID ] instanceof EE_State |
|
163 | - ) { |
|
164 | - return self::$_all_states[ $state_ID ]->name(); |
|
165 | - } |
|
166 | - $names = $this->get_col(array( array( 'STA_ID' => $state_ID ), 'limit' => 1), 'STA_name'); |
|
167 | - if (is_array($names) && ! empty($names)) { |
|
168 | - return reset($names); |
|
169 | - } else { |
|
170 | - return ''; |
|
171 | - } |
|
172 | - } |
|
14 | + // private instance of the Attendee object |
|
15 | + protected static $_instance = null; |
|
16 | + // array of all states |
|
17 | + private static $_all_states = false; |
|
18 | + // array of all active states |
|
19 | + private static $_active_states = false; |
|
20 | + |
|
21 | + protected function __construct($timezone = null) |
|
22 | + { |
|
23 | + $this->singular_item = esc_html__('State/Province', 'event_espresso'); |
|
24 | + $this->plural_item = esc_html__('States/Provinces', 'event_espresso'); |
|
25 | + |
|
26 | + $this->_tables = array( |
|
27 | + 'State' => new EE_Primary_Table('esp_state', 'STA_ID') |
|
28 | + ); |
|
29 | + |
|
30 | + $this->_fields = array( |
|
31 | + 'State' => array( |
|
32 | + 'STA_ID' => new EE_Primary_Key_Int_Field('STA_ID', esc_html__('State ID', 'event_espresso')), |
|
33 | + 'CNT_ISO' => new EE_Foreign_Key_String_Field('CNT_ISO', esc_html__('Country ISO Code', 'event_espresso'), false, null, 'Country'), |
|
34 | + 'STA_abbrev' => new EE_Plain_Text_Field('STA_abbrev', esc_html__('State Abbreviation', 'event_espresso'), false, ''), |
|
35 | + 'STA_name' => new EE_Plain_Text_Field('STA_name', esc_html__('State Name', 'event_espresso'), false, ''), |
|
36 | + 'STA_active' => new EE_Boolean_Field('STA_active', esc_html__('State Active Flag', 'event_espresso'), false, false) |
|
37 | + )); |
|
38 | + $this->_model_relations = array( |
|
39 | + 'Attendee' => new EE_Has_Many_Relation(), |
|
40 | + 'Country' => new EE_Belongs_To_Relation(), |
|
41 | + 'Venue' => new EE_Has_Many_Relation(), |
|
42 | + ); |
|
43 | + // this model is generally available for reading |
|
44 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
45 | + // @todo: only show STA_active |
|
46 | + parent::__construct($timezone); |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * reset_cached_states |
|
54 | + * |
|
55 | + * @access private |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function reset_cached_states() |
|
59 | + { |
|
60 | + EEM_State::$_active_states = array(); |
|
61 | + EEM_State::$_all_states = array(); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * _get_states |
|
69 | + * |
|
70 | + * @access private |
|
71 | + * @return array |
|
72 | + */ |
|
73 | + public function get_all_states() |
|
74 | + { |
|
75 | + if (! self::$_all_states) { |
|
76 | + self::$_all_states = $this->get_all(array( 'order_by' => array( 'STA_name' => 'ASC' ), 'limit' => array( 0, 99999 ))); |
|
77 | + } |
|
78 | + return self::$_all_states; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * _get_states |
|
85 | + * |
|
86 | + * @access public |
|
87 | + * @param array $countries |
|
88 | + * @param bool $flush_cache |
|
89 | + * @return array |
|
90 | + */ |
|
91 | + public function get_all_active_states($countries = array(), $flush_cache = false) |
|
92 | + { |
|
93 | + if (! self::$_active_states || $flush_cache) { |
|
94 | + $countries = is_array($countries) && ! empty($countries) ? $countries : EEM_Country::instance()->get_all_active_countries(); |
|
95 | + self::$_active_states = $this->get_all(array( |
|
96 | + array( 'STA_active' => true, 'CNT_ISO' => array( 'IN', array_keys($countries))), |
|
97 | + 'order_by' => array( 'STA_name' => 'ASC' ), |
|
98 | + 'limit' => array( 0, 99999 ), |
|
99 | + 'force_join' => array( 'Country' ) |
|
100 | + )); |
|
101 | + } |
|
102 | + return self::$_active_states; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * get_all_states_of_active_countries |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + public function get_all_states_of_active_countries() |
|
112 | + { |
|
113 | + if ($states = $this->get_all(array( array( 'Country.CNT_active' => true, 'STA_active' => true ), 'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) { |
|
114 | + return $states; |
|
115 | + } |
|
116 | + return false; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * get_all_states_of_active_countries |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public function get_all_active_states_for_these_countries($countries) |
|
126 | + { |
|
127 | + if (! $countries) { |
|
128 | + return false; |
|
129 | + } |
|
130 | + if ($states = $this->get_all(array( array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries)), 'STA_active' => true ), 'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) { |
|
131 | + return $states; |
|
132 | + } |
|
133 | + return false; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * get_all_states_of_active_countries |
|
140 | + * @return array |
|
141 | + */ |
|
142 | + public function get_all_states_for_these_countries($countries) |
|
143 | + { |
|
144 | + if (! $countries) { |
|
145 | + return false; |
|
146 | + } |
|
147 | + if ($states = $this->get_all(array( array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries))), 'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) { |
|
148 | + return $states; |
|
149 | + } |
|
150 | + return false; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Gets the state's name by its ID |
|
155 | + * @param string $state_ID |
|
156 | + * @return string |
|
157 | + */ |
|
158 | + public function get_state_name_by_ID($state_ID) |
|
159 | + { |
|
160 | + if ( |
|
161 | + isset(self::$_all_states[ $state_ID ]) && |
|
162 | + self::$_all_states[ $state_ID ] instanceof EE_State |
|
163 | + ) { |
|
164 | + return self::$_all_states[ $state_ID ]->name(); |
|
165 | + } |
|
166 | + $names = $this->get_col(array( array( 'STA_ID' => $state_ID ), 'limit' => 1), 'STA_name'); |
|
167 | + if (is_array($names) && ! empty($names)) { |
|
168 | + return reset($names); |
|
169 | + } else { |
|
170 | + return ''; |
|
171 | + } |
|
172 | + } |
|
173 | 173 | } |
@@ -43,11 +43,11 @@ |
||
43 | 43 | 'Ticket' => new EE_Has_Many_Relation() |
44 | 44 | ); |
45 | 45 | $this->_model_chain_to_wp_user = 'Ticket'; |
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
46 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | 47 | // account for default tickets in the caps |
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
50 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
50 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
51 | 51 | parent::__construct($timezone); |
52 | 52 | } |
53 | 53 | } |
@@ -11,40 +11,40 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_Ticket_Template extends EEM_Base |
13 | 13 | { |
14 | - // private instance of the EEM_Ticket_Template object |
|
15 | - protected static $_instance = null; |
|
14 | + // private instance of the EEM_Ticket_Template object |
|
15 | + protected static $_instance = null; |
|
16 | 16 | |
17 | - /** |
|
18 | - * private constructor to prevent direct creation |
|
19 | - * @Constructor |
|
20 | - * @access private |
|
21 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - protected function __construct($timezone) |
|
25 | - { |
|
26 | - $this->singular_item = esc_html__('Ticket Template', 'event_espresso'); |
|
27 | - $this->plural_item = esc_html__('Ticket Templates', 'event_espresso'); |
|
17 | + /** |
|
18 | + * private constructor to prevent direct creation |
|
19 | + * @Constructor |
|
20 | + * @access private |
|
21 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + protected function __construct($timezone) |
|
25 | + { |
|
26 | + $this->singular_item = esc_html__('Ticket Template', 'event_espresso'); |
|
27 | + $this->plural_item = esc_html__('Ticket Templates', 'event_espresso'); |
|
28 | 28 | |
29 | - $this->_tables = array( |
|
30 | - 'Ticket_Template' => new EE_Primary_Table('esp_ticket_template', 'TTM_ID') |
|
31 | - ); |
|
32 | - $this->_fields = array( |
|
33 | - 'Ticket_Template' => array( |
|
34 | - 'TTM_ID' => new EE_Primary_Key_Int_Field('TTM_ID', esc_html__('Ticket Template ID', 'event_espresso')), |
|
35 | - 'TTM_name' => new EE_Plain_Text_Field('TTM_name', esc_html__('The name of the ticket template', 'event_espresso'), false, ''), |
|
36 | - 'TTM_description' => new EE_Plain_Text_Field('TTM_description', esc_html__('The description for the ticket template', 'event_espresso'), true, ''), |
|
37 | - 'TTM_file' => new EE_Plain_Text_Field('TTM_file', esc_html__('The file name for the actual template file saved on disk', 'event_espresso'), true, ''), |
|
38 | - )); |
|
39 | - $this->_model_relations = array( |
|
40 | - 'Ticket' => new EE_Has_Many_Relation() |
|
41 | - ); |
|
42 | - $this->_model_chain_to_wp_user = 'Ticket'; |
|
43 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
44 | - // account for default tickets in the caps |
|
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | - parent::__construct($timezone); |
|
49 | - } |
|
29 | + $this->_tables = array( |
|
30 | + 'Ticket_Template' => new EE_Primary_Table('esp_ticket_template', 'TTM_ID') |
|
31 | + ); |
|
32 | + $this->_fields = array( |
|
33 | + 'Ticket_Template' => array( |
|
34 | + 'TTM_ID' => new EE_Primary_Key_Int_Field('TTM_ID', esc_html__('Ticket Template ID', 'event_espresso')), |
|
35 | + 'TTM_name' => new EE_Plain_Text_Field('TTM_name', esc_html__('The name of the ticket template', 'event_espresso'), false, ''), |
|
36 | + 'TTM_description' => new EE_Plain_Text_Field('TTM_description', esc_html__('The description for the ticket template', 'event_espresso'), true, ''), |
|
37 | + 'TTM_file' => new EE_Plain_Text_Field('TTM_file', esc_html__('The file name for the actual template file saved on disk', 'event_espresso'), true, ''), |
|
38 | + )); |
|
39 | + $this->_model_relations = array( |
|
40 | + 'Ticket' => new EE_Has_Many_Relation() |
|
41 | + ); |
|
42 | + $this->_model_chain_to_wp_user = 'Ticket'; |
|
43 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
44 | + // account for default tickets in the caps |
|
45 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
46 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | + parent::__construct($timezone); |
|
49 | + } |
|
50 | 50 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function get_registration_question_answer_object(EE_Registration $registration, $question_id = null) |
100 | 100 | { |
101 | - $answer_obj = $this->get_one(array( array( 'QST_ID' => $question_id, 'REG_ID' => $registration->ID() ))); |
|
101 | + $answer_obj = $this->get_one(array(array('QST_ID' => $question_id, 'REG_ID' => $registration->ID()))); |
|
102 | 102 | return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id); |
103 | 103 | } |
104 | 104 | |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | if (is_numeric($question_system_id)) { |
122 | 122 | // find this question's QST_system value |
123 | 123 | $question_id = $question_system_id; |
124 | - $question_system_id = EEM_Question::instance()->get_var(array( array( 'QST_ID' => $question_system_id ) ), 'QST_system'); |
|
124 | + $question_system_id = EEM_Question::instance()->get_var(array(array('QST_ID' => $question_system_id)), 'QST_system'); |
|
125 | 125 | } else { |
126 | - $question_id = (int) EEM_Question::instance()->get_var(array( array( 'QST_system' => $question_system_id ) ), 'QST_ID'); |
|
126 | + $question_id = (int) EEM_Question::instance()->get_var(array(array('QST_system' => $question_system_id)), 'QST_ID'); |
|
127 | 127 | } |
128 | 128 | // only bother checking if the registration has an attendee |
129 | 129 | if ($registration->attendee() instanceof EE_Attendee) { |
@@ -9,145 +9,145 @@ |
||
9 | 9 | */ |
10 | 10 | class EEM_Answer extends EEM_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * private instance of the EEM_Answer object |
|
14 | - * @type EEM_Answer |
|
15 | - */ |
|
16 | - protected static $_instance = null; |
|
12 | + /** |
|
13 | + * private instance of the EEM_Answer object |
|
14 | + * @type EEM_Answer |
|
15 | + */ |
|
16 | + protected static $_instance = null; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Mapping from system question ids to attendee field names |
|
20 | - * @type array |
|
21 | - * @deprecated since version 4.8.8 |
|
22 | - */ |
|
23 | - protected $_question_id_to_att_field_map = array( |
|
24 | - EEM_Attendee::fname_question_id => 'ATT_fname', |
|
25 | - EEM_Attendee::lname_question_id => 'ATT_lname', |
|
26 | - EEM_Attendee::email_question_id => 'ATT_email', |
|
27 | - EEM_Attendee::address_question_id => 'ATT_address', |
|
28 | - EEM_Attendee::address2_question_id => 'ATT_address2', |
|
29 | - EEM_Attendee::city_question_id => 'ATT_city', |
|
30 | - EEM_Attendee::state_question_id => 'STA_ID', |
|
31 | - EEM_Attendee::country_question_id => 'CNT_ISO', |
|
32 | - EEM_Attendee::zip_question_id => 'ATT_zip', |
|
33 | - EEM_Attendee::phone_question_id => 'ATT_phone' |
|
34 | - ); |
|
18 | + /** |
|
19 | + * Mapping from system question ids to attendee field names |
|
20 | + * @type array |
|
21 | + * @deprecated since version 4.8.8 |
|
22 | + */ |
|
23 | + protected $_question_id_to_att_field_map = array( |
|
24 | + EEM_Attendee::fname_question_id => 'ATT_fname', |
|
25 | + EEM_Attendee::lname_question_id => 'ATT_lname', |
|
26 | + EEM_Attendee::email_question_id => 'ATT_email', |
|
27 | + EEM_Attendee::address_question_id => 'ATT_address', |
|
28 | + EEM_Attendee::address2_question_id => 'ATT_address2', |
|
29 | + EEM_Attendee::city_question_id => 'ATT_city', |
|
30 | + EEM_Attendee::state_question_id => 'STA_ID', |
|
31 | + EEM_Attendee::country_question_id => 'CNT_ISO', |
|
32 | + EEM_Attendee::zip_question_id => 'ATT_zip', |
|
33 | + EEM_Attendee::phone_question_id => 'ATT_phone' |
|
34 | + ); |
|
35 | 35 | |
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * constructor |
|
40 | - */ |
|
41 | - protected function __construct($timezone = null) |
|
42 | - { |
|
43 | - $this->singular_item = esc_html__('Answer', 'event_espresso'); |
|
44 | - $this->plural_item = esc_html__('Answers', 'event_espresso'); |
|
45 | - $this->_tables = array( |
|
46 | - 'Answer' => new EE_Primary_Table('esp_answer', 'ANS_ID') |
|
47 | - ); |
|
48 | - $this->_fields = array( |
|
49 | - 'Answer' => array( |
|
50 | - 'ANS_ID' => new EE_Primary_Key_Int_Field('ANS_ID', esc_html__('Answer ID', 'event_espresso')), |
|
51 | - 'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', esc_html__('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
52 | - 'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', esc_html__('Question ID', 'event_espresso'), false, 0, 'Question'), |
|
53 | - 'ANS_value' => new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', esc_html__('Answer Value', 'event_espresso'), false, '') |
|
54 | - )); |
|
55 | - $this->_model_relations = array( |
|
56 | - 'Registration' => new EE_Belongs_To_Relation(), |
|
57 | - 'Question' => new EE_Belongs_To_Relation() |
|
58 | - ); |
|
59 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
60 | - $this->_caps_slug = 'registrations'; |
|
61 | - parent::__construct($timezone); |
|
62 | - } |
|
38 | + /** |
|
39 | + * constructor |
|
40 | + */ |
|
41 | + protected function __construct($timezone = null) |
|
42 | + { |
|
43 | + $this->singular_item = esc_html__('Answer', 'event_espresso'); |
|
44 | + $this->plural_item = esc_html__('Answers', 'event_espresso'); |
|
45 | + $this->_tables = array( |
|
46 | + 'Answer' => new EE_Primary_Table('esp_answer', 'ANS_ID') |
|
47 | + ); |
|
48 | + $this->_fields = array( |
|
49 | + 'Answer' => array( |
|
50 | + 'ANS_ID' => new EE_Primary_Key_Int_Field('ANS_ID', esc_html__('Answer ID', 'event_espresso')), |
|
51 | + 'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', esc_html__('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
52 | + 'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', esc_html__('Question ID', 'event_espresso'), false, 0, 'Question'), |
|
53 | + 'ANS_value' => new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', esc_html__('Answer Value', 'event_espresso'), false, '') |
|
54 | + )); |
|
55 | + $this->_model_relations = array( |
|
56 | + 'Registration' => new EE_Belongs_To_Relation(), |
|
57 | + 'Question' => new EE_Belongs_To_Relation() |
|
58 | + ); |
|
59 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
60 | + $this->_caps_slug = 'registrations'; |
|
61 | + parent::__construct($timezone); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * Gets the string answer to the question for this registration (it could either be stored |
|
68 | - * on the attendee or in the answer table. This function finds its value regardless) |
|
69 | - * @param EE_Registration $registration |
|
70 | - * @param int $question_id |
|
71 | - * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value' |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function get_answer_value_to_question(EE_Registration $registration, $question_id = null, $pretty_answer = false) |
|
75 | - { |
|
76 | - $value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer); |
|
77 | - if ($value === null) { |
|
78 | - $answer_obj = $this->get_registration_question_answer_object($registration, $question_id); |
|
79 | - if ($answer_obj instanceof EE_Answer) { |
|
80 | - if ($pretty_answer) { |
|
81 | - $value = $answer_obj->pretty_value(); |
|
82 | - } else { |
|
83 | - $value = $answer_obj->value(); |
|
84 | - } |
|
85 | - } |
|
86 | - } |
|
87 | - return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id); |
|
88 | - } |
|
66 | + /** |
|
67 | + * Gets the string answer to the question for this registration (it could either be stored |
|
68 | + * on the attendee or in the answer table. This function finds its value regardless) |
|
69 | + * @param EE_Registration $registration |
|
70 | + * @param int $question_id |
|
71 | + * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value' |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function get_answer_value_to_question(EE_Registration $registration, $question_id = null, $pretty_answer = false) |
|
75 | + { |
|
76 | + $value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer); |
|
77 | + if ($value === null) { |
|
78 | + $answer_obj = $this->get_registration_question_answer_object($registration, $question_id); |
|
79 | + if ($answer_obj instanceof EE_Answer) { |
|
80 | + if ($pretty_answer) { |
|
81 | + $value = $answer_obj->pretty_value(); |
|
82 | + } else { |
|
83 | + $value = $answer_obj->value(); |
|
84 | + } |
|
85 | + } |
|
86 | + } |
|
87 | + return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id); |
|
88 | + } |
|
89 | 89 | |
90 | 90 | |
91 | 91 | |
92 | - /** |
|
93 | - * Gets the EE_Answer object for the question for this registration (if it exists) |
|
94 | - * @param EE_Registration $registration |
|
95 | - * @param int $question_id |
|
96 | - * @return EE_Answer |
|
97 | - */ |
|
98 | - public function get_registration_question_answer_object(EE_Registration $registration, $question_id = null) |
|
99 | - { |
|
100 | - $answer_obj = $this->get_one(array( array( 'QST_ID' => $question_id, 'REG_ID' => $registration->ID() ))); |
|
101 | - return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id); |
|
102 | - } |
|
92 | + /** |
|
93 | + * Gets the EE_Answer object for the question for this registration (if it exists) |
|
94 | + * @param EE_Registration $registration |
|
95 | + * @param int $question_id |
|
96 | + * @return EE_Answer |
|
97 | + */ |
|
98 | + public function get_registration_question_answer_object(EE_Registration $registration, $question_id = null) |
|
99 | + { |
|
100 | + $answer_obj = $this->get_one(array( array( 'QST_ID' => $question_id, 'REG_ID' => $registration->ID() ))); |
|
101 | + return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | |
105 | - /** |
|
106 | - * Gets the string answer to the question for this registration's attendee |
|
107 | - * |
|
108 | - * @param EE_Registration $registration |
|
109 | - * @param int|string $question_system_id if an INT this is understood to be the question's ID; if a string |
|
110 | - * then it should be its QST_system value. Passing in the QST_system |
|
111 | - * value is more efficient |
|
112 | - * @param boolean $pretty_answer |
|
113 | - * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or |
|
114 | - * QST_system for a question corresponding to an attendee field, returns |
|
115 | - * null) |
|
116 | - * @throws EE_Error |
|
117 | - * @throws ReflectionException |
|
118 | - */ |
|
119 | - public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = null, $pretty_answer = false) |
|
120 | - { |
|
121 | - $value = null; |
|
122 | - // backward compat: we still want to find the question's ID |
|
123 | - if (is_numeric($question_system_id)) { |
|
124 | - // find this question's QST_system value |
|
125 | - $question_id = $question_system_id; |
|
126 | - $question_system_id = EEM_Question::instance()->get_var(array( array( 'QST_ID' => $question_system_id ) ), 'QST_system'); |
|
127 | - } else { |
|
128 | - $question_id = (int) EEM_Question::instance()->get_var(array( array( 'QST_system' => $question_system_id ) ), 'QST_ID'); |
|
129 | - } |
|
130 | - // only bother checking if the registration has an attendee |
|
131 | - if ($registration->attendee() instanceof EE_Attendee) { |
|
132 | - $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id); |
|
133 | - if ($field_name) { |
|
134 | - if ($pretty_answer) { |
|
135 | - if ($field_name === 'STA_ID') { |
|
136 | - $state = $registration->attendee()->state_obj(); |
|
137 | - $value = $state instanceof EE_State ? $state->name() : sprintf(esc_html__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID()); |
|
138 | - } elseif ($field_name === 'CNT_ISO') { |
|
139 | - $country = $registration->attendee()->country_obj(); |
|
140 | - $value = $country instanceof EE_Country ? $country->name() : sprintf(esc_html__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID()); |
|
141 | - } else { |
|
142 | - $value = $registration->attendee()->get_pretty($field_name); |
|
143 | - } |
|
144 | - // if field name is blank, leave the value as null too |
|
145 | - } else { |
|
146 | - $value = $registration->attendee()->get($field_name); |
|
147 | - } |
|
148 | - } |
|
149 | - // if no field was found, leave value blank |
|
150 | - } |
|
151 | - return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id); |
|
152 | - } |
|
105 | + /** |
|
106 | + * Gets the string answer to the question for this registration's attendee |
|
107 | + * |
|
108 | + * @param EE_Registration $registration |
|
109 | + * @param int|string $question_system_id if an INT this is understood to be the question's ID; if a string |
|
110 | + * then it should be its QST_system value. Passing in the QST_system |
|
111 | + * value is more efficient |
|
112 | + * @param boolean $pretty_answer |
|
113 | + * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or |
|
114 | + * QST_system for a question corresponding to an attendee field, returns |
|
115 | + * null) |
|
116 | + * @throws EE_Error |
|
117 | + * @throws ReflectionException |
|
118 | + */ |
|
119 | + public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = null, $pretty_answer = false) |
|
120 | + { |
|
121 | + $value = null; |
|
122 | + // backward compat: we still want to find the question's ID |
|
123 | + if (is_numeric($question_system_id)) { |
|
124 | + // find this question's QST_system value |
|
125 | + $question_id = $question_system_id; |
|
126 | + $question_system_id = EEM_Question::instance()->get_var(array( array( 'QST_ID' => $question_system_id ) ), 'QST_system'); |
|
127 | + } else { |
|
128 | + $question_id = (int) EEM_Question::instance()->get_var(array( array( 'QST_system' => $question_system_id ) ), 'QST_ID'); |
|
129 | + } |
|
130 | + // only bother checking if the registration has an attendee |
|
131 | + if ($registration->attendee() instanceof EE_Attendee) { |
|
132 | + $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id); |
|
133 | + if ($field_name) { |
|
134 | + if ($pretty_answer) { |
|
135 | + if ($field_name === 'STA_ID') { |
|
136 | + $state = $registration->attendee()->state_obj(); |
|
137 | + $value = $state instanceof EE_State ? $state->name() : sprintf(esc_html__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID()); |
|
138 | + } elseif ($field_name === 'CNT_ISO') { |
|
139 | + $country = $registration->attendee()->country_obj(); |
|
140 | + $value = $country instanceof EE_Country ? $country->name() : sprintf(esc_html__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID()); |
|
141 | + } else { |
|
142 | + $value = $registration->attendee()->get_pretty($field_name); |
|
143 | + } |
|
144 | + // if field name is blank, leave the value as null too |
|
145 | + } else { |
|
146 | + $value = $registration->attendee()->get($field_name); |
|
147 | + } |
|
148 | + } |
|
149 | + // if no field was found, leave value blank |
|
150 | + } |
|
151 | + return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id); |
|
152 | + } |
|
153 | 153 | } |