@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * Note: this file should only be required right before calling the function the shim is for. This is to ensure that |
5 | 5 | * it does not override any existing definition of the function in WP. |
6 | 6 | */ |
7 | -if (! function_exists('get_preview_post_link')) { |
|
7 | +if ( ! function_exists('get_preview_post_link')) { |
|
8 | 8 | /** |
9 | 9 | * Function was added in WordPress 4.4.0 |
10 | 10 | * |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | function get_preview_post_link($post = null, $query_args = array(), $preview_link = '') |
17 | 17 | { |
18 | 18 | $post = get_post($post); |
19 | - if (! $post) { |
|
19 | + if ( ! $post) { |
|
20 | 20 | return ''; |
21 | 21 | } |
22 | 22 | |
23 | 23 | $post_type_object = get_post_type_object($post->post_type); |
24 | 24 | if (is_post_type_viewable($post_type_object)) { |
25 | - if (! $preview_link) { |
|
25 | + if ( ! $preview_link) { |
|
26 | 26 | $preview_link = set_url_scheme(get_permalink($post)); |
27 | 27 | } |
28 | 28 | |
@@ -42,12 +42,12 @@ discard block |
||
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | -if (! function_exists('is_post_type_viewable')) { |
|
45 | +if ( ! function_exists('is_post_type_viewable')) { |
|
46 | 46 | function is_post_type_viewable($post_type) |
47 | 47 | { |
48 | 48 | if (is_scalar($post_type)) { |
49 | 49 | $post_type = get_post_type_object($post_type); |
50 | - if (! $post_type) { |
|
50 | + if ( ! $post_type) { |
|
51 | 51 | return false; |
52 | 52 | } |
53 | 53 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
59 | -if (! function_exists('wp_scripts_get_suffix')) { |
|
59 | +if ( ! function_exists('wp_scripts_get_suffix')) { |
|
60 | 60 | /** |
61 | 61 | * Returns the suffix that can be used for the scripts. |
62 | 62 | * |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | static $suffixes; |
74 | 74 | |
75 | 75 | if ($suffixes === null) { |
76 | - include(ABSPATH . WPINC . '/version.php'); // include an unmodified $wp_version |
|
76 | + include(ABSPATH.WPINC.'/version.php'); // include an unmodified $wp_version |
|
77 | 77 | |
78 | 78 | $develop_src = false !== strpos($wp_version, '-src'); |
79 | 79 | |
80 | - if (! defined('SCRIPT_DEBUG')) { |
|
80 | + if ( ! defined('SCRIPT_DEBUG')) { |
|
81 | 81 | define('SCRIPT_DEBUG', $develop_src); |
82 | 82 | } |
83 | 83 | $suffix = SCRIPT_DEBUG ? '' : '.min'; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | -if (! function_exists('get_user_locale')) { |
|
97 | +if ( ! function_exists('get_user_locale')) { |
|
98 | 98 | /** |
99 | 99 | * Shim for get_user_locale that was added in WP 4.7.0 |
100 | 100 | * |
@@ -5,105 +5,105 @@ |
||
5 | 5 | * it does not override any existing definition of the function in WP. |
6 | 6 | */ |
7 | 7 | if (! function_exists('get_preview_post_link')) { |
8 | - /** |
|
9 | - * Function was added in WordPress 4.4.0 |
|
10 | - * |
|
11 | - * @param null $post |
|
12 | - * @param array $query_args |
|
13 | - * @param string $preview_link |
|
14 | - * @return mixed |
|
15 | - */ |
|
16 | - function get_preview_post_link($post = null, $query_args = array(), $preview_link = '') |
|
17 | - { |
|
18 | - $post = get_post($post); |
|
19 | - if (! $post) { |
|
20 | - return ''; |
|
21 | - } |
|
8 | + /** |
|
9 | + * Function was added in WordPress 4.4.0 |
|
10 | + * |
|
11 | + * @param null $post |
|
12 | + * @param array $query_args |
|
13 | + * @param string $preview_link |
|
14 | + * @return mixed |
|
15 | + */ |
|
16 | + function get_preview_post_link($post = null, $query_args = array(), $preview_link = '') |
|
17 | + { |
|
18 | + $post = get_post($post); |
|
19 | + if (! $post) { |
|
20 | + return ''; |
|
21 | + } |
|
22 | 22 | |
23 | - $post_type_object = get_post_type_object($post->post_type); |
|
24 | - if (is_post_type_viewable($post_type_object)) { |
|
25 | - if (! $preview_link) { |
|
26 | - $preview_link = set_url_scheme(get_permalink($post)); |
|
27 | - } |
|
23 | + $post_type_object = get_post_type_object($post->post_type); |
|
24 | + if (is_post_type_viewable($post_type_object)) { |
|
25 | + if (! $preview_link) { |
|
26 | + $preview_link = set_url_scheme(get_permalink($post)); |
|
27 | + } |
|
28 | 28 | |
29 | - $query_args['preview'] = 'true'; |
|
30 | - $preview_link = add_query_arg($query_args, $preview_link); |
|
31 | - } |
|
29 | + $query_args['preview'] = 'true'; |
|
30 | + $preview_link = add_query_arg($query_args, $preview_link); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Filters the URL used for a post preview. |
|
35 | - * |
|
36 | - * @since 2.0.5 |
|
37 | - * @since 4.0.0 Added the `$post` parameter. |
|
38 | - * @param string $preview_link URL used for the post preview. |
|
39 | - * @param WP_Post $post Post object. |
|
40 | - */ |
|
41 | - return apply_filters('preview_post_link', $preview_link, $post); |
|
42 | - } |
|
33 | + /** |
|
34 | + * Filters the URL used for a post preview. |
|
35 | + * |
|
36 | + * @since 2.0.5 |
|
37 | + * @since 4.0.0 Added the `$post` parameter. |
|
38 | + * @param string $preview_link URL used for the post preview. |
|
39 | + * @param WP_Post $post Post object. |
|
40 | + */ |
|
41 | + return apply_filters('preview_post_link', $preview_link, $post); |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | if (! function_exists('is_post_type_viewable')) { |
46 | - function is_post_type_viewable($post_type) |
|
47 | - { |
|
48 | - if (is_scalar($post_type)) { |
|
49 | - $post_type = get_post_type_object($post_type); |
|
50 | - if (! $post_type) { |
|
51 | - return false; |
|
52 | - } |
|
53 | - } |
|
46 | + function is_post_type_viewable($post_type) |
|
47 | + { |
|
48 | + if (is_scalar($post_type)) { |
|
49 | + $post_type = get_post_type_object($post_type); |
|
50 | + if (! $post_type) { |
|
51 | + return false; |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - return $post_type->publicly_queryable || ($post_type->_builtin && $post_type->public); |
|
56 | - } |
|
55 | + return $post_type->publicly_queryable || ($post_type->_builtin && $post_type->public); |
|
56 | + } |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | if (! function_exists('wp_scripts_get_suffix')) { |
60 | - /** |
|
61 | - * Returns the suffix that can be used for the scripts. |
|
62 | - * |
|
63 | - * There are two suffix types, the normal one and the dev suffix. |
|
64 | - * |
|
65 | - * @since 5.0.0 |
|
66 | - * |
|
67 | - * @param string $type The type of suffix to retrieve. |
|
68 | - * @return string The script suffix. |
|
69 | - */ |
|
70 | - function wp_scripts_get_suffix($type = '') |
|
71 | - { |
|
72 | - global $wp_version; |
|
73 | - static $suffixes; |
|
60 | + /** |
|
61 | + * Returns the suffix that can be used for the scripts. |
|
62 | + * |
|
63 | + * There are two suffix types, the normal one and the dev suffix. |
|
64 | + * |
|
65 | + * @since 5.0.0 |
|
66 | + * |
|
67 | + * @param string $type The type of suffix to retrieve. |
|
68 | + * @return string The script suffix. |
|
69 | + */ |
|
70 | + function wp_scripts_get_suffix($type = '') |
|
71 | + { |
|
72 | + global $wp_version; |
|
73 | + static $suffixes; |
|
74 | 74 | |
75 | - if ($suffixes === null) { |
|
76 | - include(ABSPATH . WPINC . '/version.php'); // include an unmodified $wp_version |
|
75 | + if ($suffixes === null) { |
|
76 | + include(ABSPATH . WPINC . '/version.php'); // include an unmodified $wp_version |
|
77 | 77 | |
78 | - $develop_src = false !== strpos($wp_version, '-src'); |
|
78 | + $develop_src = false !== strpos($wp_version, '-src'); |
|
79 | 79 | |
80 | - if (! defined('SCRIPT_DEBUG')) { |
|
81 | - define('SCRIPT_DEBUG', $develop_src); |
|
82 | - } |
|
83 | - $suffix = SCRIPT_DEBUG ? '' : '.min'; |
|
84 | - $dev_suffix = $develop_src ? '' : '.min'; |
|
80 | + if (! defined('SCRIPT_DEBUG')) { |
|
81 | + define('SCRIPT_DEBUG', $develop_src); |
|
82 | + } |
|
83 | + $suffix = SCRIPT_DEBUG ? '' : '.min'; |
|
84 | + $dev_suffix = $develop_src ? '' : '.min'; |
|
85 | 85 | |
86 | - $suffixes = array('suffix' => $suffix, 'dev_suffix' => $dev_suffix); |
|
87 | - } |
|
86 | + $suffixes = array('suffix' => $suffix, 'dev_suffix' => $dev_suffix); |
|
87 | + } |
|
88 | 88 | |
89 | - if ($type === 'dev') { |
|
90 | - return $suffixes['dev_suffix']; |
|
91 | - } |
|
89 | + if ($type === 'dev') { |
|
90 | + return $suffixes['dev_suffix']; |
|
91 | + } |
|
92 | 92 | |
93 | - return $suffixes['suffix']; |
|
94 | - } |
|
93 | + return $suffixes['suffix']; |
|
94 | + } |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | if (! function_exists('get_user_locale')) { |
98 | - /** |
|
99 | - * Shim for get_user_locale that was added in WP 4.7.0 |
|
100 | - * |
|
101 | - * @param int $user_id |
|
102 | - * @return string |
|
103 | - * @since 4.9.73.p |
|
104 | - */ |
|
105 | - function get_user_locale($user_id = 0) |
|
106 | - { |
|
107 | - return get_locale(); |
|
108 | - } |
|
98 | + /** |
|
99 | + * Shim for get_user_locale that was added in WP 4.7.0 |
|
100 | + * |
|
101 | + * @param int $user_id |
|
102 | + * @return string |
|
103 | + * @since 4.9.73.p |
|
104 | + */ |
|
105 | + function get_user_locale($user_id = 0) |
|
106 | + { |
|
107 | + return get_locale(); |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | \ No newline at end of file |
@@ -65,18 +65,18 @@ discard block |
||
65 | 65 | // remember the model relation chain to the JOIN model, because we'll |
66 | 66 | // need it for get_join_statement() |
67 | 67 | $this->_model_relation_chain_to_join_model = $model_relation_chain; |
68 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field();// get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
68 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); // get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
69 | 69 | $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
70 | 70 | $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
71 | 71 | $model_relation_chain, |
72 | 72 | $this->get_this_model()->get_this_model_name() |
73 | - ) . $this_table_pk_field->get_table_alias(); |
|
73 | + ).$this_table_pk_field->get_table_alias(); |
|
74 | 74 | |
75 | 75 | $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
76 | 76 | $model_relation_chain, |
77 | 77 | $this->get_join_model()->get_this_model_name() |
78 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | - $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
78 | + ).$join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | + $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
80 | 80 | // phew! ok, we have all the info we need, now we can create the SQL join string |
81 | 81 | $SQL = $this->_left_join( |
82 | 82 | $join_table, |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $join_table_fk_field_to_this_table->get_table_column(), |
85 | 85 | $this_table_alias, |
86 | 86 | $this_table_pk_field->get_table_column() |
87 | - ) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
87 | + ).$this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
88 | 88 | |
89 | 89 | return $SQL; |
90 | 90 | } |
@@ -113,14 +113,14 @@ discard block |
||
113 | 113 | $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
114 | 114 | $this->_model_relation_chain_to_join_model, |
115 | 115 | $this->get_join_model()->get_this_model_name() |
116 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
116 | + ).$join_table_fk_field_to_this_table->get_table_alias(); |
|
117 | 117 | $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
118 | 118 | $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
119 | 119 | $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
120 | 120 | $model_relation_chain, |
121 | 121 | $this->get_other_model()->get_this_model_name() |
122 | - ) . $other_table_pk_field->get_table_alias(); |
|
123 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
122 | + ).$other_table_pk_field->get_table_alias(); |
|
123 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
124 | 124 | |
125 | 125 | $SQL = $this->_left_join( |
126 | 126 | $other_table, |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $other_table_pk_field->get_table_column(), |
129 | 129 | $join_table_alias, |
130 | 130 | $join_table_fk_field_to_other_table->get_table_column() |
131 | - ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
131 | + ).$this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
132 | 132 | return $SQL; |
133 | 133 | } |
134 | 134 | |
@@ -161,17 +161,17 @@ discard block |
||
161 | 161 | ); |
162 | 162 | |
163 | 163 | // if $where_query exists lets add them to the query_params. |
164 | - if (! empty($extra_join_model_fields_n_values)) { |
|
164 | + if ( ! empty($extra_join_model_fields_n_values)) { |
|
165 | 165 | // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
166 | 166 | // make sure we strip THIS models name from the query param |
167 | 167 | $parsed_query = array(); |
168 | 168 | foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
169 | - $query_param = str_replace( |
|
170 | - $this->get_join_model()->get_this_model_name() . ".", |
|
169 | + $query_param = str_replace( |
|
170 | + $this->get_join_model()->get_this_model_name().".", |
|
171 | 171 | "", |
172 | 172 | $query_param |
173 | 173 | ); |
174 | - $parsed_query[ $query_param ] = $val; |
|
174 | + $parsed_query[$query_param] = $val; |
|
175 | 175 | } |
176 | 176 | $all_fields = array_merge($foreign_keys, $parsed_query); |
177 | 177 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | // new row. |
182 | 182 | // Again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
183 | 183 | // the other tables) use the joining model directly! |
184 | - if (! $existing_entry_in_join_table) { |
|
184 | + if ( ! $existing_entry_in_join_table) { |
|
185 | 185 | $this->get_join_model()->insert($all_fields); |
186 | 186 | } else { |
187 | 187 | $this->get_join_model()->update( |
@@ -217,17 +217,17 @@ discard block |
||
217 | 217 | ); |
218 | 218 | |
219 | 219 | // if $where_query exists lets add them to the query_params. |
220 | - if (! empty($where_query)) { |
|
220 | + if ( ! empty($where_query)) { |
|
221 | 221 | // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
222 | 222 | // make sure we strip THIS models name from the query param |
223 | 223 | $parsed_query = array(); |
224 | 224 | foreach ($where_query as $query_param => $val) { |
225 | - $query_param = str_replace( |
|
226 | - $this->get_join_model()->get_this_model_name() . ".", |
|
225 | + $query_param = str_replace( |
|
226 | + $this->get_join_model()->get_this_model_name().".", |
|
227 | 227 | "", |
228 | 228 | $query_param |
229 | 229 | ); |
230 | - $parsed_query[ $query_param ] = $val; |
|
230 | + $parsed_query[$query_param] = $val; |
|
231 | 231 | } |
232 | 232 | $cols_n_values = array_merge($cols_n_values, $parsed_query); |
233 | 233 | } |
@@ -9,266 +9,266 @@ |
||
9 | 9 | */ |
10 | 10 | class EE_HABTM_Relation extends EE_Model_Relation_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * Model which defines the relation between two other models. Eg, the EE_Event_Question_Group model, |
|
14 | - * which joins EE_Event and EE_Question_Group |
|
15 | - * |
|
16 | - * @var EEM_Base |
|
17 | - */ |
|
18 | - protected $_joining_model_name; |
|
12 | + /** |
|
13 | + * Model which defines the relation between two other models. Eg, the EE_Event_Question_Group model, |
|
14 | + * which joins EE_Event and EE_Question_Group |
|
15 | + * |
|
16 | + * @var EEM_Base |
|
17 | + */ |
|
18 | + protected $_joining_model_name; |
|
19 | 19 | |
20 | - protected $_model_relation_chain_to_join_model; |
|
20 | + protected $_model_relation_chain_to_join_model; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table |
|
25 | - * (and an ee joining-model.) This knows how to join the models, |
|
26 | - * get related models across the relation, and add-and-remove the relationships. |
|
27 | - * |
|
28 | - * @param bool $joining_model_name |
|
29 | - * @param boolean $block_deletes for this type of relation, we block by default for now. if there |
|
30 | - * are related models across this relation, block (prevent and add an |
|
31 | - * error) the deletion of this model |
|
32 | - * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
33 | - * default |
|
34 | - */ |
|
35 | - public function __construct($joining_model_name, $block_deletes = true, $blocking_delete_error_message = '') |
|
36 | - { |
|
37 | - $this->_joining_model_name = $joining_model_name; |
|
38 | - parent::__construct($block_deletes, $blocking_delete_error_message); |
|
39 | - } |
|
23 | + /** |
|
24 | + * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table |
|
25 | + * (and an ee joining-model.) This knows how to join the models, |
|
26 | + * get related models across the relation, and add-and-remove the relationships. |
|
27 | + * |
|
28 | + * @param bool $joining_model_name |
|
29 | + * @param boolean $block_deletes for this type of relation, we block by default for now. if there |
|
30 | + * are related models across this relation, block (prevent and add an |
|
31 | + * error) the deletion of this model |
|
32 | + * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
33 | + * default |
|
34 | + */ |
|
35 | + public function __construct($joining_model_name, $block_deletes = true, $blocking_delete_error_message = '') |
|
36 | + { |
|
37 | + $this->_joining_model_name = $joining_model_name; |
|
38 | + parent::__construct($block_deletes, $blocking_delete_error_message); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Gets the joining model's object |
|
43 | - * |
|
44 | - * @return EEM_Base |
|
45 | - */ |
|
46 | - public function get_join_model() |
|
47 | - { |
|
48 | - return $this->_get_model($this->_joining_model_name); |
|
49 | - } |
|
41 | + /** |
|
42 | + * Gets the joining model's object |
|
43 | + * |
|
44 | + * @return EEM_Base |
|
45 | + */ |
|
46 | + public function get_join_model() |
|
47 | + { |
|
48 | + return $this->_get_model($this->_joining_model_name); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN |
|
54 | - * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table" |
|
55 | - * |
|
56 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
57 | - * @return string of SQL |
|
58 | - * @throws \EE_Error |
|
59 | - */ |
|
60 | - public function get_join_to_intermediate_model_statement($model_relation_chain) |
|
61 | - { |
|
62 | - // create sql like |
|
63 | - // LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
|
64 | - // LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
|
65 | - // remember the model relation chain to the JOIN model, because we'll |
|
66 | - // need it for get_join_statement() |
|
67 | - $this->_model_relation_chain_to_join_model = $model_relation_chain; |
|
68 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field();// get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
69 | - $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
70 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
71 | - $model_relation_chain, |
|
72 | - $this->get_this_model()->get_this_model_name() |
|
73 | - ) . $this_table_pk_field->get_table_alias(); |
|
52 | + /** |
|
53 | + * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN |
|
54 | + * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table" |
|
55 | + * |
|
56 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
57 | + * @return string of SQL |
|
58 | + * @throws \EE_Error |
|
59 | + */ |
|
60 | + public function get_join_to_intermediate_model_statement($model_relation_chain) |
|
61 | + { |
|
62 | + // create sql like |
|
63 | + // LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
|
64 | + // LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
|
65 | + // remember the model relation chain to the JOIN model, because we'll |
|
66 | + // need it for get_join_statement() |
|
67 | + $this->_model_relation_chain_to_join_model = $model_relation_chain; |
|
68 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field();// get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
69 | + $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
70 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
71 | + $model_relation_chain, |
|
72 | + $this->get_this_model()->get_this_model_name() |
|
73 | + ) . $this_table_pk_field->get_table_alias(); |
|
74 | 74 | |
75 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
76 | - $model_relation_chain, |
|
77 | - $this->get_join_model()->get_this_model_name() |
|
78 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | - $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
80 | - // phew! ok, we have all the info we need, now we can create the SQL join string |
|
81 | - $SQL = $this->_left_join( |
|
82 | - $join_table, |
|
83 | - $join_table_alias, |
|
84 | - $join_table_fk_field_to_this_table->get_table_column(), |
|
85 | - $this_table_alias, |
|
86 | - $this_table_pk_field->get_table_column() |
|
87 | - ) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
75 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
76 | + $model_relation_chain, |
|
77 | + $this->get_join_model()->get_this_model_name() |
|
78 | + ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | + $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
80 | + // phew! ok, we have all the info we need, now we can create the SQL join string |
|
81 | + $SQL = $this->_left_join( |
|
82 | + $join_table, |
|
83 | + $join_table_alias, |
|
84 | + $join_table_fk_field_to_this_table->get_table_column(), |
|
85 | + $this_table_alias, |
|
86 | + $this_table_pk_field->get_table_column() |
|
87 | + ) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
88 | 88 | |
89 | - return $SQL; |
|
90 | - } |
|
89 | + return $SQL; |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table |
|
95 | - * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between |
|
96 | - * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the |
|
97 | - * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to |
|
98 | - * the intermediate join table, and then to the other model's pk's table |
|
99 | - * |
|
100 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
101 | - * @return string of SQL |
|
102 | - * @throws \EE_Error |
|
103 | - */ |
|
104 | - public function get_join_statement($model_relation_chain) |
|
105 | - { |
|
106 | - if ($this->_model_relation_chain_to_join_model === null) { |
|
107 | - throw new EE_Error(sprintf(esc_html__( |
|
108 | - 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', |
|
109 | - 'event_espresso' |
|
110 | - ))); |
|
111 | - } |
|
112 | - $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
113 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
114 | - $this->_model_relation_chain_to_join_model, |
|
115 | - $this->get_join_model()->get_this_model_name() |
|
116 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
117 | - $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
118 | - $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
119 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
120 | - $model_relation_chain, |
|
121 | - $this->get_other_model()->get_this_model_name() |
|
122 | - ) . $other_table_pk_field->get_table_alias(); |
|
123 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
93 | + /** |
|
94 | + * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table |
|
95 | + * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between |
|
96 | + * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the |
|
97 | + * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to |
|
98 | + * the intermediate join table, and then to the other model's pk's table |
|
99 | + * |
|
100 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
101 | + * @return string of SQL |
|
102 | + * @throws \EE_Error |
|
103 | + */ |
|
104 | + public function get_join_statement($model_relation_chain) |
|
105 | + { |
|
106 | + if ($this->_model_relation_chain_to_join_model === null) { |
|
107 | + throw new EE_Error(sprintf(esc_html__( |
|
108 | + 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', |
|
109 | + 'event_espresso' |
|
110 | + ))); |
|
111 | + } |
|
112 | + $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
113 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
114 | + $this->_model_relation_chain_to_join_model, |
|
115 | + $this->get_join_model()->get_this_model_name() |
|
116 | + ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
117 | + $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
118 | + $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
119 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
120 | + $model_relation_chain, |
|
121 | + $this->get_other_model()->get_this_model_name() |
|
122 | + ) . $other_table_pk_field->get_table_alias(); |
|
123 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
124 | 124 | |
125 | - $SQL = $this->_left_join( |
|
126 | - $other_table, |
|
127 | - $other_table_alias, |
|
128 | - $other_table_pk_field->get_table_column(), |
|
129 | - $join_table_alias, |
|
130 | - $join_table_fk_field_to_other_table->get_table_column() |
|
131 | - ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
132 | - return $SQL; |
|
133 | - } |
|
125 | + $SQL = $this->_left_join( |
|
126 | + $other_table, |
|
127 | + $other_table_alias, |
|
128 | + $other_table_pk_field->get_table_column(), |
|
129 | + $join_table_alias, |
|
130 | + $join_table_fk_field_to_other_table->get_table_column() |
|
131 | + ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
132 | + return $SQL; |
|
133 | + } |
|
134 | 134 | |
135 | 135 | |
136 | - /** |
|
137 | - * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like. |
|
138 | - * If the join table has additional columns (eg, the Event_Question_Group table has a is_primary column), then |
|
139 | - * you'll want to directly use the EEM_Event_Question_Group model to add the entry to the table and set those extra |
|
140 | - * columns' values |
|
141 | - * |
|
142 | - * @param EE_Base_Class|int $this_obj_or_id |
|
143 | - * @param EE_Base_Class|int $other_obj_or_id |
|
144 | - * @param array $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for |
|
145 | - * checking existing values and for setting new rows if |
|
146 | - * no exact matches. |
|
147 | - * @return EE_Base_Class |
|
148 | - * @throws \EE_Error |
|
149 | - */ |
|
150 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
151 | - { |
|
152 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
153 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
154 | - // check if such a relationship already exists |
|
155 | - $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
156 | - $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
136 | + /** |
|
137 | + * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like. |
|
138 | + * If the join table has additional columns (eg, the Event_Question_Group table has a is_primary column), then |
|
139 | + * you'll want to directly use the EEM_Event_Question_Group model to add the entry to the table and set those extra |
|
140 | + * columns' values |
|
141 | + * |
|
142 | + * @param EE_Base_Class|int $this_obj_or_id |
|
143 | + * @param EE_Base_Class|int $other_obj_or_id |
|
144 | + * @param array $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for |
|
145 | + * checking existing values and for setting new rows if |
|
146 | + * no exact matches. |
|
147 | + * @return EE_Base_Class |
|
148 | + * @throws \EE_Error |
|
149 | + */ |
|
150 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
151 | + { |
|
152 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
153 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
154 | + // check if such a relationship already exists |
|
155 | + $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
156 | + $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
157 | 157 | |
158 | - $foreign_keys = $all_fields = array( |
|
159 | - $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
160 | - $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
161 | - ); |
|
158 | + $foreign_keys = $all_fields = array( |
|
159 | + $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
160 | + $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
161 | + ); |
|
162 | 162 | |
163 | - // if $where_query exists lets add them to the query_params. |
|
164 | - if (! empty($extra_join_model_fields_n_values)) { |
|
165 | - // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
166 | - // make sure we strip THIS models name from the query param |
|
167 | - $parsed_query = array(); |
|
168 | - foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
169 | - $query_param = str_replace( |
|
170 | - $this->get_join_model()->get_this_model_name() . ".", |
|
171 | - "", |
|
172 | - $query_param |
|
173 | - ); |
|
174 | - $parsed_query[ $query_param ] = $val; |
|
175 | - } |
|
176 | - $all_fields = array_merge($foreign_keys, $parsed_query); |
|
177 | - } |
|
163 | + // if $where_query exists lets add them to the query_params. |
|
164 | + if (! empty($extra_join_model_fields_n_values)) { |
|
165 | + // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
166 | + // make sure we strip THIS models name from the query param |
|
167 | + $parsed_query = array(); |
|
168 | + foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
169 | + $query_param = str_replace( |
|
170 | + $this->get_join_model()->get_this_model_name() . ".", |
|
171 | + "", |
|
172 | + $query_param |
|
173 | + ); |
|
174 | + $parsed_query[ $query_param ] = $val; |
|
175 | + } |
|
176 | + $all_fields = array_merge($foreign_keys, $parsed_query); |
|
177 | + } |
|
178 | 178 | |
179 | - $existing_entry_in_join_table = $this->get_join_model()->get_one(array($foreign_keys)); |
|
180 | - // If there is already an entry in the join table, indicating a relationship, update it instead of adding a |
|
181 | - // new row. |
|
182 | - // Again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
|
183 | - // the other tables) use the joining model directly! |
|
184 | - if (! $existing_entry_in_join_table) { |
|
185 | - $this->get_join_model()->insert($all_fields); |
|
186 | - } else { |
|
187 | - $this->get_join_model()->update( |
|
188 | - $all_fields, |
|
189 | - [$foreign_keys] |
|
190 | - ); |
|
191 | - } |
|
192 | - return $other_model_obj; |
|
193 | - } |
|
179 | + $existing_entry_in_join_table = $this->get_join_model()->get_one(array($foreign_keys)); |
|
180 | + // If there is already an entry in the join table, indicating a relationship, update it instead of adding a |
|
181 | + // new row. |
|
182 | + // Again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
|
183 | + // the other tables) use the joining model directly! |
|
184 | + if (! $existing_entry_in_join_table) { |
|
185 | + $this->get_join_model()->insert($all_fields); |
|
186 | + } else { |
|
187 | + $this->get_join_model()->update( |
|
188 | + $all_fields, |
|
189 | + [$foreign_keys] |
|
190 | + ); |
|
191 | + } |
|
192 | + return $other_model_obj; |
|
193 | + } |
|
194 | 194 | |
195 | 195 | |
196 | - /** |
|
197 | - * Deletes any rows in the join table that have foreign keys matching the other model objects specified |
|
198 | - * |
|
199 | - * @param EE_Base_Class|int $this_obj_or_id |
|
200 | - * @param EE_Base_Class|int $other_obj_or_id |
|
201 | - * @param array $where_query col=>val pairs that are used as extra conditions for checking existing |
|
202 | - * values and for removing existing rows if exact matches exist. |
|
203 | - * @return EE_Base_Class |
|
204 | - * @throws \EE_Error |
|
205 | - */ |
|
206 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
207 | - { |
|
208 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
209 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
210 | - // check if such a relationship already exists |
|
211 | - $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
212 | - $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
196 | + /** |
|
197 | + * Deletes any rows in the join table that have foreign keys matching the other model objects specified |
|
198 | + * |
|
199 | + * @param EE_Base_Class|int $this_obj_or_id |
|
200 | + * @param EE_Base_Class|int $other_obj_or_id |
|
201 | + * @param array $where_query col=>val pairs that are used as extra conditions for checking existing |
|
202 | + * values and for removing existing rows if exact matches exist. |
|
203 | + * @return EE_Base_Class |
|
204 | + * @throws \EE_Error |
|
205 | + */ |
|
206 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
207 | + { |
|
208 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
209 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
210 | + // check if such a relationship already exists |
|
211 | + $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
212 | + $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
213 | 213 | |
214 | - $cols_n_values = array( |
|
215 | - $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
216 | - $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
217 | - ); |
|
214 | + $cols_n_values = array( |
|
215 | + $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
216 | + $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
217 | + ); |
|
218 | 218 | |
219 | - // if $where_query exists lets add them to the query_params. |
|
220 | - if (! empty($where_query)) { |
|
221 | - // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
222 | - // make sure we strip THIS models name from the query param |
|
223 | - $parsed_query = array(); |
|
224 | - foreach ($where_query as $query_param => $val) { |
|
225 | - $query_param = str_replace( |
|
226 | - $this->get_join_model()->get_this_model_name() . ".", |
|
227 | - "", |
|
228 | - $query_param |
|
229 | - ); |
|
230 | - $parsed_query[ $query_param ] = $val; |
|
231 | - } |
|
232 | - $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
233 | - } |
|
219 | + // if $where_query exists lets add them to the query_params. |
|
220 | + if (! empty($where_query)) { |
|
221 | + // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
222 | + // make sure we strip THIS models name from the query param |
|
223 | + $parsed_query = array(); |
|
224 | + foreach ($where_query as $query_param => $val) { |
|
225 | + $query_param = str_replace( |
|
226 | + $this->get_join_model()->get_this_model_name() . ".", |
|
227 | + "", |
|
228 | + $query_param |
|
229 | + ); |
|
230 | + $parsed_query[ $query_param ] = $val; |
|
231 | + } |
|
232 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
233 | + } |
|
234 | 234 | |
235 | - $this->get_join_model()->delete(array($cols_n_values)); |
|
236 | - return $other_model_obj; |
|
237 | - } |
|
235 | + $this->get_join_model()->delete(array($cols_n_values)); |
|
236 | + return $other_model_obj; |
|
237 | + } |
|
238 | 238 | |
239 | - /** |
|
240 | - * Gets all the non-key fields (ie, not the primary key and not foreign keys) on the join model. |
|
241 | - * @since 4.9.76.p |
|
242 | - * @return EE_Model_Field_Base[] |
|
243 | - * @throws EE_Error |
|
244 | - */ |
|
245 | - public function getNonKeyFields() |
|
246 | - { |
|
247 | - // all fields besides the primary key and two foreign keys should be parameters |
|
248 | - $join_model = $this->get_join_model(); |
|
249 | - $standard_fields = array(); |
|
250 | - if ($join_model->has_primary_key_field()) { |
|
251 | - $standard_fields[] = $join_model->primary_key_name(); |
|
252 | - } |
|
253 | - if ($this->get_this_model()->has_primary_key_field()) { |
|
254 | - $standard_fields[] = $this->get_this_model()->primary_key_name(); |
|
255 | - } |
|
256 | - if ($this->get_other_model()->has_primary_key_field()) { |
|
257 | - $standard_fields[] = $this->get_other_model()->primary_key_name(); |
|
258 | - } |
|
259 | - return array_diff_key( |
|
260 | - $join_model->field_settings(), |
|
261 | - array_flip($standard_fields) |
|
262 | - ); |
|
263 | - } |
|
239 | + /** |
|
240 | + * Gets all the non-key fields (ie, not the primary key and not foreign keys) on the join model. |
|
241 | + * @since 4.9.76.p |
|
242 | + * @return EE_Model_Field_Base[] |
|
243 | + * @throws EE_Error |
|
244 | + */ |
|
245 | + public function getNonKeyFields() |
|
246 | + { |
|
247 | + // all fields besides the primary key and two foreign keys should be parameters |
|
248 | + $join_model = $this->get_join_model(); |
|
249 | + $standard_fields = array(); |
|
250 | + if ($join_model->has_primary_key_field()) { |
|
251 | + $standard_fields[] = $join_model->primary_key_name(); |
|
252 | + } |
|
253 | + if ($this->get_this_model()->has_primary_key_field()) { |
|
254 | + $standard_fields[] = $this->get_this_model()->primary_key_name(); |
|
255 | + } |
|
256 | + if ($this->get_other_model()->has_primary_key_field()) { |
|
257 | + $standard_fields[] = $this->get_other_model()->primary_key_name(); |
|
258 | + } |
|
259 | + return array_diff_key( |
|
260 | + $join_model->field_settings(), |
|
261 | + array_flip($standard_fields) |
|
262 | + ); |
|
263 | + } |
|
264 | 264 | |
265 | - /** |
|
266 | - * Returns true if the join model has non-key fields (ie, fields that aren't the primary key or foreign keys.) |
|
267 | - * @since 4.9.76.p |
|
268 | - * @return boolean |
|
269 | - */ |
|
270 | - public function hasNonKeyFields() |
|
271 | - { |
|
272 | - return count($this->get_join_model()->field_settings()) > 3; |
|
273 | - } |
|
265 | + /** |
|
266 | + * Returns true if the join model has non-key fields (ie, fields that aren't the primary key or foreign keys.) |
|
267 | + * @since 4.9.76.p |
|
268 | + * @return boolean |
|
269 | + */ |
|
270 | + public function hasNonKeyFields() |
|
271 | + { |
|
272 | + return count($this->get_join_model()->field_settings()) > 3; |
|
273 | + } |
|
274 | 274 | } |
@@ -18,17 +18,17 @@ |
||
18 | 18 | */ |
19 | 19 | class RestPasswordRequiredException extends RestException |
20 | 20 | { |
21 | - public function __construct($previous = null) |
|
22 | - { |
|
23 | - parent::__construct( |
|
24 | - 'rest_post_password_required', |
|
25 | - esc_html__('A password is required to access this content.', 'event_espresso'), |
|
26 | - array( |
|
27 | - 'status' => 403, |
|
28 | - ), |
|
29 | - $previous |
|
30 | - ); |
|
31 | - } |
|
21 | + public function __construct($previous = null) |
|
22 | + { |
|
23 | + parent::__construct( |
|
24 | + 'rest_post_password_required', |
|
25 | + esc_html__('A password is required to access this content.', 'event_espresso'), |
|
26 | + array( |
|
27 | + 'status' => 403, |
|
28 | + ), |
|
29 | + $previous |
|
30 | + ); |
|
31 | + } |
|
32 | 32 | } |
33 | 33 | // End of file RestPasswordRequired.php |
34 | 34 | // Location: EventEspresso\core\exceptions/RestPasswordRequired.php |
@@ -18,27 +18,27 @@ |
||
18 | 18 | */ |
19 | 19 | class ModelConfigurationException extends DomainException |
20 | 20 | { |
21 | - /** |
|
22 | - * ModelConfigurationException constructor. |
|
23 | - * |
|
24 | - * @param EEM_Base $model |
|
25 | - * @param string $message Describe what's misconfigured about this model (don't bother mentioning which model, |
|
26 | - * that will be automatically added to the message based on the $model provided in the previous parameter). |
|
27 | - * @param int $code |
|
28 | - * @param Exception $previous |
|
29 | - */ |
|
30 | - public function __construct(EEM_Base $model, $message, $code = 0, Exception $previous = null) |
|
31 | - { |
|
32 | - $message_part_1 = sprintf( |
|
33 | - /* |
|
21 | + /** |
|
22 | + * ModelConfigurationException constructor. |
|
23 | + * |
|
24 | + * @param EEM_Base $model |
|
25 | + * @param string $message Describe what's misconfigured about this model (don't bother mentioning which model, |
|
26 | + * that will be automatically added to the message based on the $model provided in the previous parameter). |
|
27 | + * @param int $code |
|
28 | + * @param Exception $previous |
|
29 | + */ |
|
30 | + public function __construct(EEM_Base $model, $message, $code = 0, Exception $previous = null) |
|
31 | + { |
|
32 | + $message_part_1 = sprintf( |
|
33 | + /* |
|
34 | 34 | * translators: 1: the model name |
35 | 35 | */ |
36 | - esc_html__('The model "%1$s" appears to be misconfigured.', 'event_espresso'), |
|
37 | - $model->get_this_model_name() |
|
38 | - ); |
|
39 | - $message = $message_part_1 . ' ' . $message; |
|
40 | - parent::__construct($message, $code, $previous); |
|
41 | - } |
|
36 | + esc_html__('The model "%1$s" appears to be misconfigured.', 'event_espresso'), |
|
37 | + $model->get_this_model_name() |
|
38 | + ); |
|
39 | + $message = $message_part_1 . ' ' . $message; |
|
40 | + parent::__construct($message, $code, $previous); |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | // End of file ModelConfigurationException.php |
44 | 44 | // Location: EventEspresso\core\exceptions/ModelConfigurationException.php |
@@ -36,7 +36,7 @@ |
||
36 | 36 | esc_html__('The model "%1$s" appears to be misconfigured.', 'event_espresso'), |
37 | 37 | $model->get_this_model_name() |
38 | 38 | ); |
39 | - $message = $message_part_1 . ' ' . $message; |
|
39 | + $message = $message_part_1.' '.$message; |
|
40 | 40 | parent::__construct($message, $code, $previous); |
41 | 41 | } |
42 | 42 | } |
@@ -16,17 +16,17 @@ |
||
16 | 16 | */ |
17 | 17 | class RestPasswordIncorrectException extends RestException |
18 | 18 | { |
19 | - public function __construct($previous = null) |
|
20 | - { |
|
21 | - parent::__construct( |
|
22 | - 'rest_post_incorrect_password', |
|
23 | - esc_html__('Incorrect password.', 'event_espresso'), |
|
24 | - array( |
|
25 | - 'status' => 403, |
|
26 | - ), |
|
27 | - $previous |
|
28 | - ); |
|
29 | - } |
|
19 | + public function __construct($previous = null) |
|
20 | + { |
|
21 | + parent::__construct( |
|
22 | + 'rest_post_incorrect_password', |
|
23 | + esc_html__('Incorrect password.', 'event_espresso'), |
|
24 | + array( |
|
25 | + 'status' => 403, |
|
26 | + ), |
|
27 | + $previous |
|
28 | + ); |
|
29 | + } |
|
30 | 30 | } |
31 | 31 | // End of file RestPasswordIncorrectException.php |
32 | 32 | // Location: EventEspresso\core\exceptions/RestPasswordIncorrectException.php |
@@ -42,10 +42,10 @@ |
||
42 | 42 | ); |
43 | 43 | // this model is generally available for reading |
44 | 44 | $path_to_event = 'Datetime.Event'; |
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
45 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
49 | 49 | $this->model_chain_to_password = $path_to_event; |
50 | 50 | parent::__construct($timezone); |
51 | 51 | } |
@@ -11,41 +11,41 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_Datetime_Ticket extends EEM_Base |
13 | 13 | { |
14 | - // private instance of the EEM_Datetime_Ticket object |
|
15 | - protected static $_instance = null; |
|
14 | + // private instance of the EEM_Datetime_Ticket 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__('Datetime Ticket', 'event_espresso'); |
|
27 | - $this->plural_item = esc_html__('Datetime Tickets', '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__('Datetime Ticket', 'event_espresso'); |
|
27 | + $this->plural_item = esc_html__('Datetime Tickets', 'event_espresso'); |
|
28 | 28 | |
29 | - $this->_tables = array( |
|
30 | - 'Datetime_Ticket' => new EE_Primary_Table('esp_datetime_ticket', 'DTK_ID') |
|
31 | - ); |
|
32 | - $this->_fields = array( |
|
33 | - 'Datetime_Ticket' => array( |
|
34 | - 'DTK_ID' => new EE_Primary_Key_Int_Field('DTK_ID', esc_html__('Datetime Ticket ID', 'event_espresso')), |
|
35 | - 'DTT_ID' => new EE_Foreign_Key_Int_Field('DTT_ID', esc_html__('The ID to the Datetime', 'event_espresso'), false, 0, 'Datetime'), |
|
36 | - 'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', esc_html__('The ID to the Ticket', 'event_espresso'), false, 0, 'Ticket') |
|
37 | - )); |
|
38 | - $this->_model_relations = array( |
|
39 | - 'Ticket' => new EE_Belongs_To_Relation(), |
|
40 | - 'Datetime' => new EE_Belongs_To_Relation() |
|
41 | - ); |
|
42 | - // this model is generally available for reading |
|
43 | - $path_to_event = 'Datetime.Event'; |
|
44 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
48 | - $this->model_chain_to_password = $path_to_event; |
|
49 | - parent::__construct($timezone); |
|
50 | - } |
|
29 | + $this->_tables = array( |
|
30 | + 'Datetime_Ticket' => new EE_Primary_Table('esp_datetime_ticket', 'DTK_ID') |
|
31 | + ); |
|
32 | + $this->_fields = array( |
|
33 | + 'Datetime_Ticket' => array( |
|
34 | + 'DTK_ID' => new EE_Primary_Key_Int_Field('DTK_ID', esc_html__('Datetime Ticket ID', 'event_espresso')), |
|
35 | + 'DTT_ID' => new EE_Foreign_Key_Int_Field('DTT_ID', esc_html__('The ID to the Datetime', 'event_espresso'), false, 0, 'Datetime'), |
|
36 | + 'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', esc_html__('The ID to the Ticket', 'event_espresso'), false, 0, 'Ticket') |
|
37 | + )); |
|
38 | + $this->_model_relations = array( |
|
39 | + 'Ticket' => new EE_Belongs_To_Relation(), |
|
40 | + 'Datetime' => new EE_Belongs_To_Relation() |
|
41 | + ); |
|
42 | + // this model is generally available for reading |
|
43 | + $path_to_event = 'Datetime.Event'; |
|
44 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
45 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
46 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
48 | + $this->model_chain_to_password = $path_to_event; |
|
49 | + parent::__construct($timezone); |
|
50 | + } |
|
51 | 51 | } |
@@ -58,24 +58,24 @@ discard block |
||
58 | 58 | 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
59 | 59 | ); |
60 | 60 | foreach ($models_this_can_attach_to as $model_name) { |
61 | - $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation(); |
|
61 | + $this->_model_relations[$model_name] = new EE_Belongs_To_Relation(); |
|
62 | 62 | } |
63 | 63 | $this->_wp_core_model = true; |
64 | 64 | $this->_indexes = array( |
65 | 65 | 'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')), |
66 | 66 | ); |
67 | 67 | $path_to_event_model = 'Event'; |
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
68 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public( |
|
69 | 69 | $path_to_event_model |
70 | 70 | ); |
71 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
71 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = |
|
72 | 72 | new EE_Restriction_Generator_Event_Related_Protected( |
73 | 73 | $path_to_event_model |
74 | 74 | ); |
75 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
75 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected( |
|
76 | 76 | $path_to_event_model |
77 | 77 | ); |
78 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
78 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = |
|
79 | 79 | new EE_Restriction_Generator_Event_Related_Protected( |
80 | 80 | $path_to_event_model, |
81 | 81 | EEM_Base::caps_edit |
@@ -85,27 +85,27 @@ discard block |
||
85 | 85 | // and for deleting term relations too |
86 | 86 | $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete); |
87 | 87 | foreach ($cap_contexts_affected as $cap_context_affected) { |
88 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] = |
|
88 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_category'] = |
|
89 | 89 | new EE_Default_Where_Conditions( |
90 | 90 | array( |
91 | - $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array( |
|
91 | + $path_to_tax_model.'taxonomy*ee_assign_event_category' => array( |
|
92 | 92 | '!=', |
93 | 93 | 'espresso_event_categories', |
94 | 94 | ), |
95 | 95 | ) |
96 | 96 | ); |
97 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] = |
|
97 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_venue_category'] = |
|
98 | 98 | new EE_Default_Where_Conditions( |
99 | 99 | array( |
100 | - $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array( |
|
100 | + $path_to_tax_model.'taxonomy*ee_assign_venue_category' => array( |
|
101 | 101 | '!=', |
102 | 102 | 'espresso_venue_categories', |
103 | 103 | ), |
104 | 104 | ) |
105 | 105 | ); |
106 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
106 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
107 | 107 | array( |
108 | - $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
108 | + $path_to_tax_model.'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
109 | 109 | ) |
110 | 110 | ); |
111 | 111 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | { |
233 | 233 | if ($model === EEM_Term_Relationship::instance()) { |
234 | 234 | $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
235 | - if (! empty($taxonomies)) { |
|
235 | + if ( ! empty($taxonomies)) { |
|
236 | 236 | $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
237 | 237 | } |
238 | 238 | } |
@@ -9,233 +9,233 @@ |
||
9 | 9 | */ |
10 | 10 | class EEM_Term_Relationship extends EEM_Base |
11 | 11 | { |
12 | - // private instance of the Attendee object |
|
13 | - protected static $_instance = null; |
|
14 | - |
|
15 | - |
|
16 | - |
|
17 | - /** |
|
18 | - * EEM_Term_Relationship constructor. |
|
19 | - * |
|
20 | - * @param string $timezone |
|
21 | - */ |
|
22 | - protected function __construct($timezone = null) |
|
23 | - { |
|
24 | - $this->singular_item = esc_html__('Term Relationship', 'event_espresso'); |
|
25 | - $this->plural_item = esc_html__('Term Relationships', 'event_espresso'); |
|
26 | - $this->_tables = array( |
|
27 | - 'Term_Relationship' => new EE_Primary_Table('term_relationships'), |
|
28 | - ); |
|
29 | - $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
30 | - $this->_fields = array( |
|
31 | - 'Term_Relationship' => array( |
|
32 | - 'object_id' => new EE_Foreign_Key_Int_Field( |
|
33 | - 'object_id', |
|
34 | - esc_html__('Object(Post) ID', 'event_espresso'), |
|
35 | - false, |
|
36 | - 0, |
|
37 | - $models_this_can_attach_to |
|
38 | - ), |
|
39 | - 'term_taxonomy_id' => new EE_Foreign_Key_Int_Field( |
|
40 | - 'term_taxonomy_id', |
|
41 | - esc_html__( |
|
42 | - 'Term (in context of a taxonomy) ID', |
|
43 | - 'event_espresso' |
|
44 | - ), |
|
45 | - false, |
|
46 | - 0, |
|
47 | - 'Term_Taxonomy' |
|
48 | - ), |
|
49 | - 'term_order' => new EE_Integer_Field( |
|
50 | - 'term_order', |
|
51 | - esc_html__('Term Order', 'event_espresso'), |
|
52 | - false, |
|
53 | - 0 |
|
54 | - ), |
|
55 | - ), |
|
56 | - ); |
|
57 | - $this->_model_relations = array( |
|
58 | - 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
|
59 | - ); |
|
60 | - foreach ($models_this_can_attach_to as $model_name) { |
|
61 | - $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation(); |
|
62 | - } |
|
63 | - $this->_wp_core_model = true; |
|
64 | - $this->_indexes = array( |
|
65 | - 'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')), |
|
66 | - ); |
|
67 | - $path_to_event_model = 'Event'; |
|
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
69 | - $path_to_event_model |
|
70 | - ); |
|
71 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
72 | - new EE_Restriction_Generator_Event_Related_Protected( |
|
73 | - $path_to_event_model |
|
74 | - ); |
|
75 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
76 | - $path_to_event_model |
|
77 | - ); |
|
78 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
79 | - new EE_Restriction_Generator_Event_Related_Protected( |
|
80 | - $path_to_event_model, |
|
81 | - EEM_Base::caps_edit |
|
82 | - ); |
|
83 | - $path_to_tax_model = 'Term_Taxonomy.'; |
|
84 | - // add cap restrictions for editing term relations to the "ee_assign_*" |
|
85 | - // and for deleting term relations too |
|
86 | - $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete); |
|
87 | - foreach ($cap_contexts_affected as $cap_context_affected) { |
|
88 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] = |
|
89 | - new EE_Default_Where_Conditions( |
|
90 | - array( |
|
91 | - $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array( |
|
92 | - '!=', |
|
93 | - 'espresso_event_categories', |
|
94 | - ), |
|
95 | - ) |
|
96 | - ); |
|
97 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] = |
|
98 | - new EE_Default_Where_Conditions( |
|
99 | - array( |
|
100 | - $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array( |
|
101 | - '!=', |
|
102 | - 'espresso_venue_categories', |
|
103 | - ), |
|
104 | - ) |
|
105 | - ); |
|
106 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
107 | - array( |
|
108 | - $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
109 | - ) |
|
110 | - ); |
|
111 | - } |
|
112 | - parent::__construct($timezone); |
|
113 | - add_filter( |
|
114 | - 'FHEE__Read__create_model_query_params', |
|
115 | - array('EEM_Term_Relationship', 'rest_api_query_params'), |
|
116 | - 10, |
|
117 | - 3 |
|
118 | - ); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * Makes sure all term-taxonomy counts are correct |
|
124 | - * |
|
125 | - * @param int $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL |
|
126 | - * @global wpdb $wpdb |
|
127 | - * @return int the number of rows affected |
|
128 | - * @throws EE_Error |
|
129 | - */ |
|
130 | - public function update_term_taxonomy_counts($term_taxonomy_id = null) |
|
131 | - { |
|
132 | - // because this uses a subquery and sometimes assigning to column to be another column's |
|
133 | - // value, we just write the SQL directly. |
|
134 | - global $wpdb; |
|
135 | - |
|
136 | - $query = " |
|
12 | + // private instance of the Attendee object |
|
13 | + protected static $_instance = null; |
|
14 | + |
|
15 | + |
|
16 | + |
|
17 | + /** |
|
18 | + * EEM_Term_Relationship constructor. |
|
19 | + * |
|
20 | + * @param string $timezone |
|
21 | + */ |
|
22 | + protected function __construct($timezone = null) |
|
23 | + { |
|
24 | + $this->singular_item = esc_html__('Term Relationship', 'event_espresso'); |
|
25 | + $this->plural_item = esc_html__('Term Relationships', 'event_espresso'); |
|
26 | + $this->_tables = array( |
|
27 | + 'Term_Relationship' => new EE_Primary_Table('term_relationships'), |
|
28 | + ); |
|
29 | + $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
30 | + $this->_fields = array( |
|
31 | + 'Term_Relationship' => array( |
|
32 | + 'object_id' => new EE_Foreign_Key_Int_Field( |
|
33 | + 'object_id', |
|
34 | + esc_html__('Object(Post) ID', 'event_espresso'), |
|
35 | + false, |
|
36 | + 0, |
|
37 | + $models_this_can_attach_to |
|
38 | + ), |
|
39 | + 'term_taxonomy_id' => new EE_Foreign_Key_Int_Field( |
|
40 | + 'term_taxonomy_id', |
|
41 | + esc_html__( |
|
42 | + 'Term (in context of a taxonomy) ID', |
|
43 | + 'event_espresso' |
|
44 | + ), |
|
45 | + false, |
|
46 | + 0, |
|
47 | + 'Term_Taxonomy' |
|
48 | + ), |
|
49 | + 'term_order' => new EE_Integer_Field( |
|
50 | + 'term_order', |
|
51 | + esc_html__('Term Order', 'event_espresso'), |
|
52 | + false, |
|
53 | + 0 |
|
54 | + ), |
|
55 | + ), |
|
56 | + ); |
|
57 | + $this->_model_relations = array( |
|
58 | + 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
|
59 | + ); |
|
60 | + foreach ($models_this_can_attach_to as $model_name) { |
|
61 | + $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation(); |
|
62 | + } |
|
63 | + $this->_wp_core_model = true; |
|
64 | + $this->_indexes = array( |
|
65 | + 'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')), |
|
66 | + ); |
|
67 | + $path_to_event_model = 'Event'; |
|
68 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
69 | + $path_to_event_model |
|
70 | + ); |
|
71 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
72 | + new EE_Restriction_Generator_Event_Related_Protected( |
|
73 | + $path_to_event_model |
|
74 | + ); |
|
75 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
76 | + $path_to_event_model |
|
77 | + ); |
|
78 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
79 | + new EE_Restriction_Generator_Event_Related_Protected( |
|
80 | + $path_to_event_model, |
|
81 | + EEM_Base::caps_edit |
|
82 | + ); |
|
83 | + $path_to_tax_model = 'Term_Taxonomy.'; |
|
84 | + // add cap restrictions for editing term relations to the "ee_assign_*" |
|
85 | + // and for deleting term relations too |
|
86 | + $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete); |
|
87 | + foreach ($cap_contexts_affected as $cap_context_affected) { |
|
88 | + $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] = |
|
89 | + new EE_Default_Where_Conditions( |
|
90 | + array( |
|
91 | + $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array( |
|
92 | + '!=', |
|
93 | + 'espresso_event_categories', |
|
94 | + ), |
|
95 | + ) |
|
96 | + ); |
|
97 | + $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] = |
|
98 | + new EE_Default_Where_Conditions( |
|
99 | + array( |
|
100 | + $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array( |
|
101 | + '!=', |
|
102 | + 'espresso_venue_categories', |
|
103 | + ), |
|
104 | + ) |
|
105 | + ); |
|
106 | + $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
107 | + array( |
|
108 | + $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
109 | + ) |
|
110 | + ); |
|
111 | + } |
|
112 | + parent::__construct($timezone); |
|
113 | + add_filter( |
|
114 | + 'FHEE__Read__create_model_query_params', |
|
115 | + array('EEM_Term_Relationship', 'rest_api_query_params'), |
|
116 | + 10, |
|
117 | + 3 |
|
118 | + ); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * Makes sure all term-taxonomy counts are correct |
|
124 | + * |
|
125 | + * @param int $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL |
|
126 | + * @global wpdb $wpdb |
|
127 | + * @return int the number of rows affected |
|
128 | + * @throws EE_Error |
|
129 | + */ |
|
130 | + public function update_term_taxonomy_counts($term_taxonomy_id = null) |
|
131 | + { |
|
132 | + // because this uses a subquery and sometimes assigning to column to be another column's |
|
133 | + // value, we just write the SQL directly. |
|
134 | + global $wpdb; |
|
135 | + |
|
136 | + $query = " |
|
137 | 137 | UPDATE {$wpdb->term_taxonomy} AS tt |
138 | 138 | SET count = ( |
139 | 139 | select count(*) as proper_count from {$wpdb->term_relationships} AS tr |
140 | 140 | WHERE tt.term_taxonomy_id = tr.term_taxonomy_id |
141 | 141 | )"; |
142 | 142 | |
143 | - if ($term_taxonomy_id) { |
|
144 | - $query .= ' WHERE tt.term_taxonomy_id = %d'; |
|
145 | - $query = $wpdb->prepare( |
|
146 | - $query, |
|
147 | - $term_taxonomy_id |
|
148 | - ); |
|
149 | - } |
|
150 | - $rows_affected = $this->_do_wpdb_query( |
|
151 | - 'query', |
|
152 | - array( |
|
153 | - $query, |
|
154 | - ) |
|
155 | - ); |
|
156 | - return $rows_affected; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Overrides the parent to also make sure term-taxonomy counts are up-to-date after |
|
163 | - * inserting |
|
164 | - * |
|
165 | - * @param array $field_n_values @see EEM_Base::insert |
|
166 | - * @return boolean |
|
167 | - */ |
|
168 | - public function insert($field_n_values) |
|
169 | - { |
|
170 | - $return = parent::insert($field_n_values); |
|
171 | - if (isset($field_n_values['term_taxonomy_id'])) { |
|
172 | - $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']); |
|
173 | - } |
|
174 | - return $return; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Overrides parent so that after an update, we also check the term_taxonomy_counts are |
|
181 | - * all ok |
|
182 | - * |
|
183 | - * @param array $fields_n_values see EEM_Base::update |
|
184 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
185 | - * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects |
|
186 | - * in this model's entity map according to $fields_n_values that match |
|
187 | - * $query_params. This obviously has some overhead, so you can disable it |
|
188 | - * by setting this to FALSE, but be aware that model objects being used |
|
189 | - * could get out-of-sync with the database |
|
190 | - * @return int |
|
191 | - */ |
|
192 | - public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true) |
|
193 | - { |
|
194 | - $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
195 | - if ($count) { |
|
196 | - $this->update_term_taxonomy_counts(); |
|
197 | - } |
|
198 | - return $count; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * Overrides parent so that after running this, we also double-check |
|
205 | - * the term taxonomy counts are up-to-date |
|
206 | - * |
|
207 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
208 | - * @param boolean $allow_blocking |
|
209 | - * @return int @see EEM_Base::delete |
|
210 | - */ |
|
211 | - public function delete($query_params, $allow_blocking = true) |
|
212 | - { |
|
213 | - $count = parent::delete($query_params, $allow_blocking); |
|
214 | - if ($count) { |
|
215 | - $this->update_term_taxonomy_counts(); |
|
216 | - } |
|
217 | - return $count; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * Makes sure that during REST API queries, we only return term relationships |
|
224 | - * for term taxonomies which should be shown in the rest api |
|
225 | - * |
|
226 | - * @param array $model_query_params |
|
227 | - * @param array $querystring_query_params |
|
228 | - * @param EEM_Base $model |
|
229 | - * @return array |
|
230 | - */ |
|
231 | - public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
232 | - { |
|
233 | - if ($model === EEM_Term_Relationship::instance()) { |
|
234 | - $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
235 | - if (! empty($taxonomies)) { |
|
236 | - $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
237 | - } |
|
238 | - } |
|
239 | - return $model_query_params; |
|
240 | - } |
|
143 | + if ($term_taxonomy_id) { |
|
144 | + $query .= ' WHERE tt.term_taxonomy_id = %d'; |
|
145 | + $query = $wpdb->prepare( |
|
146 | + $query, |
|
147 | + $term_taxonomy_id |
|
148 | + ); |
|
149 | + } |
|
150 | + $rows_affected = $this->_do_wpdb_query( |
|
151 | + 'query', |
|
152 | + array( |
|
153 | + $query, |
|
154 | + ) |
|
155 | + ); |
|
156 | + return $rows_affected; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Overrides the parent to also make sure term-taxonomy counts are up-to-date after |
|
163 | + * inserting |
|
164 | + * |
|
165 | + * @param array $field_n_values @see EEM_Base::insert |
|
166 | + * @return boolean |
|
167 | + */ |
|
168 | + public function insert($field_n_values) |
|
169 | + { |
|
170 | + $return = parent::insert($field_n_values); |
|
171 | + if (isset($field_n_values['term_taxonomy_id'])) { |
|
172 | + $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']); |
|
173 | + } |
|
174 | + return $return; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Overrides parent so that after an update, we also check the term_taxonomy_counts are |
|
181 | + * all ok |
|
182 | + * |
|
183 | + * @param array $fields_n_values see EEM_Base::update |
|
184 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
185 | + * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects |
|
186 | + * in this model's entity map according to $fields_n_values that match |
|
187 | + * $query_params. This obviously has some overhead, so you can disable it |
|
188 | + * by setting this to FALSE, but be aware that model objects being used |
|
189 | + * could get out-of-sync with the database |
|
190 | + * @return int |
|
191 | + */ |
|
192 | + public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true) |
|
193 | + { |
|
194 | + $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
195 | + if ($count) { |
|
196 | + $this->update_term_taxonomy_counts(); |
|
197 | + } |
|
198 | + return $count; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * Overrides parent so that after running this, we also double-check |
|
205 | + * the term taxonomy counts are up-to-date |
|
206 | + * |
|
207 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
208 | + * @param boolean $allow_blocking |
|
209 | + * @return int @see EEM_Base::delete |
|
210 | + */ |
|
211 | + public function delete($query_params, $allow_blocking = true) |
|
212 | + { |
|
213 | + $count = parent::delete($query_params, $allow_blocking); |
|
214 | + if ($count) { |
|
215 | + $this->update_term_taxonomy_counts(); |
|
216 | + } |
|
217 | + return $count; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * Makes sure that during REST API queries, we only return term relationships |
|
224 | + * for term taxonomies which should be shown in the rest api |
|
225 | + * |
|
226 | + * @param array $model_query_params |
|
227 | + * @param array $querystring_query_params |
|
228 | + * @param EEM_Base $model |
|
229 | + * @return array |
|
230 | + */ |
|
231 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
232 | + { |
|
233 | + if ($model === EEM_Term_Relationship::instance()) { |
|
234 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
235 | + if (! empty($taxonomies)) { |
|
236 | + $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
237 | + } |
|
238 | + } |
|
239 | + return $model_query_params; |
|
240 | + } |
|
241 | 241 | } |
@@ -195,20 +195,20 @@ |
||
195 | 195 | ); |
196 | 196 | // this model is generally available for reading |
197 | 197 | $path_to_event = 'Datetime.Event'; |
198 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public( |
|
198 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public( |
|
199 | 199 | 'TKT_is_default', |
200 | 200 | $path_to_event |
201 | 201 | ); |
202 | 202 | // account for default tickets in the caps |
203 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected( |
|
203 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected( |
|
204 | 204 | 'TKT_is_default', |
205 | 205 | $path_to_event |
206 | 206 | ); |
207 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected( |
|
207 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected( |
|
208 | 208 | 'TKT_is_default', |
209 | 209 | $path_to_event |
210 | 210 | ); |
211 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected( |
|
211 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected( |
|
212 | 212 | 'TKT_is_default', |
213 | 213 | $path_to_event |
214 | 214 | ); |
@@ -9,322 +9,322 @@ |
||
9 | 9 | */ |
10 | 10 | class EEM_Ticket extends EEM_Soft_Delete_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * private instance of the EEM_Ticket object |
|
14 | - * |
|
15 | - * @var EEM_Ticket $_instance |
|
16 | - */ |
|
17 | - protected static $_instance; |
|
12 | + /** |
|
13 | + * private instance of the EEM_Ticket object |
|
14 | + * |
|
15 | + * @var EEM_Ticket $_instance |
|
16 | + */ |
|
17 | + protected static $_instance; |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * private constructor to prevent direct creation |
|
22 | - * |
|
23 | - * @Constructor |
|
24 | - * @access private |
|
25 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
26 | - * (and any incoming timezone data that gets saved). |
|
27 | - * Note this just sends the timezone info to the date time model field objects. |
|
28 | - * Default is NULL |
|
29 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
30 | - * @throws EE_Error |
|
31 | - */ |
|
32 | - protected function __construct($timezone) |
|
33 | - { |
|
34 | - $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
35 | - $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
36 | - $this->_tables = array( |
|
37 | - 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
38 | - ); |
|
39 | - $this->_fields = array( |
|
40 | - 'Ticket' => array( |
|
41 | - 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
42 | - 'TKT_ID', |
|
43 | - esc_html__('Ticket ID', 'event_espresso') |
|
44 | - ), |
|
45 | - 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
46 | - 'TTM_ID', |
|
47 | - esc_html__('Ticket Template ID', 'event_espresso'), |
|
48 | - false, |
|
49 | - 0, |
|
50 | - 'Ticket_Template' |
|
51 | - ), |
|
52 | - 'TKT_name' => new EE_Plain_Text_Field( |
|
53 | - 'TKT_name', |
|
54 | - esc_html__('Ticket Name', 'event_espresso'), |
|
55 | - false, |
|
56 | - '' |
|
57 | - ), |
|
58 | - 'TKT_description' => new EE_Post_Content_Field( |
|
59 | - 'TKT_description', |
|
60 | - esc_html__('Description of Ticket', 'event_espresso'), |
|
61 | - false, |
|
62 | - '' |
|
63 | - ), |
|
64 | - 'TKT_start_date' => new EE_Datetime_Field( |
|
65 | - 'TKT_start_date', |
|
66 | - esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
67 | - false, |
|
68 | - EE_Datetime_Field::now, |
|
69 | - $timezone |
|
70 | - ), |
|
71 | - 'TKT_end_date' => new EE_Datetime_Field( |
|
72 | - 'TKT_end_date', |
|
73 | - esc_html__('End time/date of Ticket', 'event_espresso'), |
|
74 | - false, |
|
75 | - EE_Datetime_Field::now, |
|
76 | - $timezone |
|
77 | - ), |
|
78 | - 'TKT_min' => new EE_Integer_Field( |
|
79 | - 'TKT_min', |
|
80 | - esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
81 | - false, |
|
82 | - 0 |
|
83 | - ), |
|
84 | - 'TKT_max' => new EE_Infinite_Integer_Field( |
|
85 | - 'TKT_max', |
|
86 | - esc_html__( |
|
87 | - 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
88 | - 'event_espresso' |
|
89 | - ), |
|
90 | - false, |
|
91 | - EE_INF |
|
92 | - ), |
|
93 | - 'TKT_price' => new EE_Money_Field( |
|
94 | - 'TKT_price', |
|
95 | - esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
96 | - false, |
|
97 | - 0 |
|
98 | - ), |
|
99 | - 'TKT_sold' => new EE_Integer_Field( |
|
100 | - 'TKT_sold', |
|
101 | - esc_html__('Number of this ticket sold', 'event_espresso'), |
|
102 | - false, |
|
103 | - 0 |
|
104 | - ), |
|
105 | - 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
106 | - 'TKT_qty', |
|
107 | - esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
108 | - false, |
|
109 | - EE_INF |
|
110 | - ), |
|
111 | - 'TKT_reserved' => new EE_Integer_Field( |
|
112 | - 'TKT_reserved', |
|
113 | - esc_html__( |
|
114 | - 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
115 | - 'event_espresso' |
|
116 | - ), |
|
117 | - false, |
|
118 | - 0 |
|
119 | - ), |
|
120 | - 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
121 | - 'TKT_uses', |
|
122 | - esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
123 | - false, |
|
124 | - EE_INF |
|
125 | - ), |
|
126 | - 'TKT_required' => new EE_Boolean_Field( |
|
127 | - 'TKT_required', |
|
128 | - esc_html__( |
|
129 | - 'Flag indicating whether this ticket must be purchased with a transaction', |
|
130 | - 'event_espresso' |
|
131 | - ), |
|
132 | - false, |
|
133 | - false |
|
134 | - ), |
|
135 | - 'TKT_taxable' => new EE_Boolean_Field( |
|
136 | - 'TKT_taxable', |
|
137 | - esc_html__( |
|
138 | - 'Flag indicating whether there is tax applied on this ticket', |
|
139 | - 'event_espresso' |
|
140 | - ), |
|
141 | - false, |
|
142 | - false |
|
143 | - ), |
|
144 | - 'TKT_is_default' => new EE_Boolean_Field( |
|
145 | - 'TKT_is_default', |
|
146 | - esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
147 | - false, |
|
148 | - false |
|
149 | - ), |
|
150 | - 'TKT_order' => new EE_Integer_Field( |
|
151 | - 'TKT_order', |
|
152 | - esc_html__( |
|
153 | - 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
154 | - 'event_espresso' |
|
155 | - ), |
|
156 | - false, |
|
157 | - 0 |
|
158 | - ), |
|
159 | - 'TKT_row' => new EE_Integer_Field( |
|
160 | - 'TKT_row', |
|
161 | - esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
162 | - false, |
|
163 | - 0 |
|
164 | - ), |
|
165 | - 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
166 | - 'TKT_deleted', |
|
167 | - esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
168 | - false, |
|
169 | - false |
|
170 | - ), |
|
171 | - 'TKT_wp_user' => new EE_WP_User_Field( |
|
172 | - 'TKT_wp_user', |
|
173 | - esc_html__('Ticket Creator ID', 'event_espresso'), |
|
174 | - false |
|
175 | - ), |
|
176 | - 'TKT_parent' => new EE_Integer_Field( |
|
177 | - 'TKT_parent', |
|
178 | - esc_html__( |
|
179 | - 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
180 | - 'event_espresso' |
|
181 | - ), |
|
182 | - true, |
|
183 | - 0 |
|
184 | - ), |
|
185 | - ), |
|
186 | - ); |
|
187 | - $this->_model_relations = array( |
|
188 | - 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
189 | - 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
190 | - 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
191 | - 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
192 | - 'Registration' => new EE_Has_Many_Relation(), |
|
193 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
194 | - ); |
|
195 | - // this model is generally available for reading |
|
196 | - $path_to_event = 'Datetime.Event'; |
|
197 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public( |
|
198 | - 'TKT_is_default', |
|
199 | - $path_to_event |
|
200 | - ); |
|
201 | - // account for default tickets in the caps |
|
202 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected( |
|
203 | - 'TKT_is_default', |
|
204 | - $path_to_event |
|
205 | - ); |
|
206 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected( |
|
207 | - 'TKT_is_default', |
|
208 | - $path_to_event |
|
209 | - ); |
|
210 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected( |
|
211 | - 'TKT_is_default', |
|
212 | - $path_to_event |
|
213 | - ); |
|
214 | - $this->model_chain_to_password = $path_to_event; |
|
215 | - parent::__construct($timezone); |
|
216 | - } |
|
20 | + /** |
|
21 | + * private constructor to prevent direct creation |
|
22 | + * |
|
23 | + * @Constructor |
|
24 | + * @access private |
|
25 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
26 | + * (and any incoming timezone data that gets saved). |
|
27 | + * Note this just sends the timezone info to the date time model field objects. |
|
28 | + * Default is NULL |
|
29 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
30 | + * @throws EE_Error |
|
31 | + */ |
|
32 | + protected function __construct($timezone) |
|
33 | + { |
|
34 | + $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
35 | + $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
36 | + $this->_tables = array( |
|
37 | + 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
38 | + ); |
|
39 | + $this->_fields = array( |
|
40 | + 'Ticket' => array( |
|
41 | + 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
42 | + 'TKT_ID', |
|
43 | + esc_html__('Ticket ID', 'event_espresso') |
|
44 | + ), |
|
45 | + 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
46 | + 'TTM_ID', |
|
47 | + esc_html__('Ticket Template ID', 'event_espresso'), |
|
48 | + false, |
|
49 | + 0, |
|
50 | + 'Ticket_Template' |
|
51 | + ), |
|
52 | + 'TKT_name' => new EE_Plain_Text_Field( |
|
53 | + 'TKT_name', |
|
54 | + esc_html__('Ticket Name', 'event_espresso'), |
|
55 | + false, |
|
56 | + '' |
|
57 | + ), |
|
58 | + 'TKT_description' => new EE_Post_Content_Field( |
|
59 | + 'TKT_description', |
|
60 | + esc_html__('Description of Ticket', 'event_espresso'), |
|
61 | + false, |
|
62 | + '' |
|
63 | + ), |
|
64 | + 'TKT_start_date' => new EE_Datetime_Field( |
|
65 | + 'TKT_start_date', |
|
66 | + esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
67 | + false, |
|
68 | + EE_Datetime_Field::now, |
|
69 | + $timezone |
|
70 | + ), |
|
71 | + 'TKT_end_date' => new EE_Datetime_Field( |
|
72 | + 'TKT_end_date', |
|
73 | + esc_html__('End time/date of Ticket', 'event_espresso'), |
|
74 | + false, |
|
75 | + EE_Datetime_Field::now, |
|
76 | + $timezone |
|
77 | + ), |
|
78 | + 'TKT_min' => new EE_Integer_Field( |
|
79 | + 'TKT_min', |
|
80 | + esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
81 | + false, |
|
82 | + 0 |
|
83 | + ), |
|
84 | + 'TKT_max' => new EE_Infinite_Integer_Field( |
|
85 | + 'TKT_max', |
|
86 | + esc_html__( |
|
87 | + 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
88 | + 'event_espresso' |
|
89 | + ), |
|
90 | + false, |
|
91 | + EE_INF |
|
92 | + ), |
|
93 | + 'TKT_price' => new EE_Money_Field( |
|
94 | + 'TKT_price', |
|
95 | + esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
96 | + false, |
|
97 | + 0 |
|
98 | + ), |
|
99 | + 'TKT_sold' => new EE_Integer_Field( |
|
100 | + 'TKT_sold', |
|
101 | + esc_html__('Number of this ticket sold', 'event_espresso'), |
|
102 | + false, |
|
103 | + 0 |
|
104 | + ), |
|
105 | + 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
106 | + 'TKT_qty', |
|
107 | + esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
108 | + false, |
|
109 | + EE_INF |
|
110 | + ), |
|
111 | + 'TKT_reserved' => new EE_Integer_Field( |
|
112 | + 'TKT_reserved', |
|
113 | + esc_html__( |
|
114 | + 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
115 | + 'event_espresso' |
|
116 | + ), |
|
117 | + false, |
|
118 | + 0 |
|
119 | + ), |
|
120 | + 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
121 | + 'TKT_uses', |
|
122 | + esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
123 | + false, |
|
124 | + EE_INF |
|
125 | + ), |
|
126 | + 'TKT_required' => new EE_Boolean_Field( |
|
127 | + 'TKT_required', |
|
128 | + esc_html__( |
|
129 | + 'Flag indicating whether this ticket must be purchased with a transaction', |
|
130 | + 'event_espresso' |
|
131 | + ), |
|
132 | + false, |
|
133 | + false |
|
134 | + ), |
|
135 | + 'TKT_taxable' => new EE_Boolean_Field( |
|
136 | + 'TKT_taxable', |
|
137 | + esc_html__( |
|
138 | + 'Flag indicating whether there is tax applied on this ticket', |
|
139 | + 'event_espresso' |
|
140 | + ), |
|
141 | + false, |
|
142 | + false |
|
143 | + ), |
|
144 | + 'TKT_is_default' => new EE_Boolean_Field( |
|
145 | + 'TKT_is_default', |
|
146 | + esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
147 | + false, |
|
148 | + false |
|
149 | + ), |
|
150 | + 'TKT_order' => new EE_Integer_Field( |
|
151 | + 'TKT_order', |
|
152 | + esc_html__( |
|
153 | + 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
154 | + 'event_espresso' |
|
155 | + ), |
|
156 | + false, |
|
157 | + 0 |
|
158 | + ), |
|
159 | + 'TKT_row' => new EE_Integer_Field( |
|
160 | + 'TKT_row', |
|
161 | + esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
162 | + false, |
|
163 | + 0 |
|
164 | + ), |
|
165 | + 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
166 | + 'TKT_deleted', |
|
167 | + esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
168 | + false, |
|
169 | + false |
|
170 | + ), |
|
171 | + 'TKT_wp_user' => new EE_WP_User_Field( |
|
172 | + 'TKT_wp_user', |
|
173 | + esc_html__('Ticket Creator ID', 'event_espresso'), |
|
174 | + false |
|
175 | + ), |
|
176 | + 'TKT_parent' => new EE_Integer_Field( |
|
177 | + 'TKT_parent', |
|
178 | + esc_html__( |
|
179 | + 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
180 | + 'event_espresso' |
|
181 | + ), |
|
182 | + true, |
|
183 | + 0 |
|
184 | + ), |
|
185 | + ), |
|
186 | + ); |
|
187 | + $this->_model_relations = array( |
|
188 | + 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
189 | + 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
190 | + 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
191 | + 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
192 | + 'Registration' => new EE_Has_Many_Relation(), |
|
193 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
194 | + ); |
|
195 | + // this model is generally available for reading |
|
196 | + $path_to_event = 'Datetime.Event'; |
|
197 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public( |
|
198 | + 'TKT_is_default', |
|
199 | + $path_to_event |
|
200 | + ); |
|
201 | + // account for default tickets in the caps |
|
202 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected( |
|
203 | + 'TKT_is_default', |
|
204 | + $path_to_event |
|
205 | + ); |
|
206 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected( |
|
207 | + 'TKT_is_default', |
|
208 | + $path_to_event |
|
209 | + ); |
|
210 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected( |
|
211 | + 'TKT_is_default', |
|
212 | + $path_to_event |
|
213 | + ); |
|
214 | + $this->model_chain_to_password = $path_to_event; |
|
215 | + parent::__construct($timezone); |
|
216 | + } |
|
217 | 217 | |
218 | 218 | |
219 | - /** |
|
220 | - * This returns all tickets that are defaults from the db |
|
221 | - * |
|
222 | - * @return EE_Ticket[] |
|
223 | - * @throws EE_Error |
|
224 | - */ |
|
225 | - public function get_all_default_tickets() |
|
226 | - { |
|
227 | - /** @type EE_Ticket[] $tickets */ |
|
228 | - $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC'))); |
|
229 | - // we need to set the start date and end date to today's date and the start of the default dtt |
|
230 | - return $this->_set_default_dates($tickets); |
|
231 | - } |
|
219 | + /** |
|
220 | + * This returns all tickets that are defaults from the db |
|
221 | + * |
|
222 | + * @return EE_Ticket[] |
|
223 | + * @throws EE_Error |
|
224 | + */ |
|
225 | + public function get_all_default_tickets() |
|
226 | + { |
|
227 | + /** @type EE_Ticket[] $tickets */ |
|
228 | + $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC'))); |
|
229 | + // we need to set the start date and end date to today's date and the start of the default dtt |
|
230 | + return $this->_set_default_dates($tickets); |
|
231 | + } |
|
232 | 232 | |
233 | 233 | |
234 | - /** |
|
235 | - * sets up relevant start and end date for EE_Ticket (s) |
|
236 | - * |
|
237 | - * @param EE_Ticket[] $tickets |
|
238 | - * @return EE_Ticket[] |
|
239 | - * @throws EE_Error |
|
240 | - */ |
|
241 | - private function _set_default_dates($tickets) |
|
242 | - { |
|
243 | - foreach ($tickets as $ticket) { |
|
244 | - $ticket->set( |
|
245 | - 'TKT_start_date', |
|
246 | - (int) $this->current_time_for_query('TKT_start_date', true) |
|
247 | - ); |
|
248 | - $ticket->set( |
|
249 | - 'TKT_end_date', |
|
250 | - (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
251 | - ); |
|
252 | - $ticket->set_end_time( |
|
253 | - $this->convert_datetime_for_query( |
|
254 | - 'TKT_end_date', |
|
255 | - '11:59 pm', |
|
256 | - 'g:i a', |
|
257 | - $this->_timezone |
|
258 | - ) |
|
259 | - ); |
|
260 | - } |
|
261 | - return $tickets; |
|
262 | - } |
|
234 | + /** |
|
235 | + * sets up relevant start and end date for EE_Ticket (s) |
|
236 | + * |
|
237 | + * @param EE_Ticket[] $tickets |
|
238 | + * @return EE_Ticket[] |
|
239 | + * @throws EE_Error |
|
240 | + */ |
|
241 | + private function _set_default_dates($tickets) |
|
242 | + { |
|
243 | + foreach ($tickets as $ticket) { |
|
244 | + $ticket->set( |
|
245 | + 'TKT_start_date', |
|
246 | + (int) $this->current_time_for_query('TKT_start_date', true) |
|
247 | + ); |
|
248 | + $ticket->set( |
|
249 | + 'TKT_end_date', |
|
250 | + (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
251 | + ); |
|
252 | + $ticket->set_end_time( |
|
253 | + $this->convert_datetime_for_query( |
|
254 | + 'TKT_end_date', |
|
255 | + '11:59 pm', |
|
256 | + 'g:i a', |
|
257 | + $this->_timezone |
|
258 | + ) |
|
259 | + ); |
|
260 | + } |
|
261 | + return $tickets; |
|
262 | + } |
|
263 | 263 | |
264 | 264 | |
265 | - /** |
|
266 | - * Gets the total number of tickets available at a particular datetime (does |
|
267 | - * NOT take int account the datetime's spaces available) |
|
268 | - * |
|
269 | - * @param int $DTT_ID |
|
270 | - * @param array $query_params |
|
271 | - * @return int |
|
272 | - */ |
|
273 | - public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
274 | - { |
|
275 | - return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
276 | - } |
|
265 | + /** |
|
266 | + * Gets the total number of tickets available at a particular datetime (does |
|
267 | + * NOT take int account the datetime's spaces available) |
|
268 | + * |
|
269 | + * @param int $DTT_ID |
|
270 | + * @param array $query_params |
|
271 | + * @return int |
|
272 | + */ |
|
273 | + public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
274 | + { |
|
275 | + return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
276 | + } |
|
277 | 277 | |
278 | 278 | |
279 | - /** |
|
280 | - * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
281 | - * |
|
282 | - * @param EE_Ticket[] $tickets |
|
283 | - * @return void |
|
284 | - * @throws EE_Error |
|
285 | - */ |
|
286 | - public function update_tickets_sold($tickets) |
|
287 | - { |
|
288 | - foreach ($tickets as $ticket) { |
|
289 | - /* @var $ticket EE_Ticket */ |
|
290 | - $ticket->update_tickets_sold(); |
|
291 | - } |
|
292 | - } |
|
279 | + /** |
|
280 | + * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
281 | + * |
|
282 | + * @param EE_Ticket[] $tickets |
|
283 | + * @return void |
|
284 | + * @throws EE_Error |
|
285 | + */ |
|
286 | + public function update_tickets_sold($tickets) |
|
287 | + { |
|
288 | + foreach ($tickets as $ticket) { |
|
289 | + /* @var $ticket EE_Ticket */ |
|
290 | + $ticket->update_tickets_sold(); |
|
291 | + } |
|
292 | + } |
|
293 | 293 | |
294 | 294 | |
295 | - /** |
|
296 | - * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
297 | - * |
|
298 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
299 | - * @throws EE_Error |
|
300 | - */ |
|
301 | - public function get_tickets_with_reservations() |
|
302 | - { |
|
303 | - return $this->get_all( |
|
304 | - array( |
|
305 | - array( |
|
306 | - 'TKT_reserved' => array('>', 0), |
|
307 | - ), |
|
308 | - ) |
|
309 | - ); |
|
310 | - } |
|
295 | + /** |
|
296 | + * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
297 | + * |
|
298 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
299 | + * @throws EE_Error |
|
300 | + */ |
|
301 | + public function get_tickets_with_reservations() |
|
302 | + { |
|
303 | + return $this->get_all( |
|
304 | + array( |
|
305 | + array( |
|
306 | + 'TKT_reserved' => array('>', 0), |
|
307 | + ), |
|
308 | + ) |
|
309 | + ); |
|
310 | + } |
|
311 | 311 | |
312 | 312 | |
313 | - /** |
|
314 | - * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
315 | - * |
|
316 | - * @param array $ticket_IDs |
|
317 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
318 | - * @throws EE_Error |
|
319 | - */ |
|
320 | - public function get_tickets_with_IDs(array $ticket_IDs) |
|
321 | - { |
|
322 | - return $this->get_all( |
|
323 | - array( |
|
324 | - array( |
|
325 | - 'TKT_ID' => array('IN', $ticket_IDs), |
|
326 | - ), |
|
327 | - ) |
|
328 | - ); |
|
329 | - } |
|
313 | + /** |
|
314 | + * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
315 | + * |
|
316 | + * @param array $ticket_IDs |
|
317 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
318 | + * @throws EE_Error |
|
319 | + */ |
|
320 | + public function get_tickets_with_IDs(array $ticket_IDs) |
|
321 | + { |
|
322 | + return $this->get_all( |
|
323 | + array( |
|
324 | + array( |
|
325 | + 'TKT_ID' => array('IN', $ticket_IDs), |
|
326 | + ), |
|
327 | + ) |
|
328 | + ); |
|
329 | + } |
|
330 | 330 | } |
@@ -191,7 +191,7 @@ |
||
191 | 191 | 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
192 | 192 | ); |
193 | 193 | // this model is generally available for reading |
194 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
194 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
195 | 195 | $this->model_chain_to_password = ''; |
196 | 196 | parent::__construct($timezone); |
197 | 197 | } |
@@ -10,189 +10,189 @@ |
||
10 | 10 | */ |
11 | 11 | class EEM_Venue extends EEM_CPT_Base |
12 | 12 | { |
13 | - // private instance of the Attendee object |
|
14 | - protected static $_instance = null; |
|
13 | + // private instance of the Attendee object |
|
14 | + protected static $_instance = null; |
|
15 | 15 | |
16 | 16 | |
17 | 17 | |
18 | - protected function __construct($timezone = null) |
|
19 | - { |
|
20 | - $this->singular_item = esc_html__('Venue', 'event_espresso'); |
|
21 | - $this->plural_item = esc_html__('Venues', 'event_espresso'); |
|
22 | - $this->_tables = array( |
|
23 | - 'Venue_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
24 | - 'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'), |
|
25 | - ); |
|
26 | - $this->_fields = array( |
|
27 | - 'Venue_CPT' => array( |
|
28 | - 'VNU_ID' => new EE_Primary_Key_Int_Field('ID', esc_html__("Venue ID", "event_espresso")), |
|
29 | - 'VNU_name' => new EE_Plain_Text_Field( |
|
30 | - 'post_title', |
|
31 | - esc_html__("Venue Name", "event_espresso"), |
|
32 | - false, |
|
33 | - '' |
|
34 | - ), |
|
35 | - 'VNU_desc' => new EE_Post_Content_Field( |
|
36 | - 'post_content', |
|
37 | - esc_html__("Venue Description", "event_espresso"), |
|
38 | - false, |
|
39 | - '' |
|
40 | - ), |
|
41 | - 'VNU_identifier' => new EE_Slug_Field('post_name', esc_html__("Venue Identifier", "event_espresso"), false, ''), |
|
42 | - 'VNU_created' => new EE_Datetime_Field( |
|
43 | - 'post_date', |
|
44 | - esc_html__("Date Venue Created", "event_espresso"), |
|
45 | - false, |
|
46 | - EE_Datetime_Field::now |
|
47 | - ), |
|
48 | - 'VNU_short_desc' => new EE_Plain_Text_Field( |
|
49 | - 'post_excerpt', |
|
50 | - esc_html__("Short Description of Venue", "event_espresso"), |
|
51 | - true, |
|
52 | - '' |
|
53 | - ), |
|
54 | - 'VNU_modified' => new EE_Datetime_Field( |
|
55 | - 'post_modified', |
|
56 | - esc_html__("Venue Modified Date", "event_espresso"), |
|
57 | - false, |
|
58 | - EE_Datetime_Field::now |
|
59 | - ), |
|
60 | - 'VNU_wp_user' => new EE_WP_User_Field( |
|
61 | - 'post_author', |
|
62 | - esc_html__("Venue Creator ID", "event_espresso"), |
|
63 | - false |
|
64 | - ), |
|
65 | - 'parent' => new EE_Integer_Field( |
|
66 | - 'post_parent', |
|
67 | - esc_html__("Venue Parent ID", "event_espresso"), |
|
68 | - false, |
|
69 | - 0 |
|
70 | - ), |
|
71 | - 'VNU_order' => new EE_Integer_Field('menu_order', esc_html__("Venue order", "event_espresso"), false, 1), |
|
72 | - 'post_type' => new EE_WP_Post_Type_Field('espresso_venues'), |
|
73 | - 'password' => new EE_Password_Field( |
|
74 | - 'post_password', |
|
75 | - esc_html__('Password', 'event_espresso'), |
|
76 | - false, |
|
77 | - '', |
|
78 | - array( |
|
79 | - 'VNU_desc', |
|
80 | - 'VNU_short_desc', |
|
81 | - 'VNU_address', |
|
82 | - 'VNU_address2', |
|
83 | - 'VNU_city', |
|
84 | - 'STA_ID', |
|
85 | - 'CNT_ISO', |
|
86 | - 'VNU_zip', |
|
87 | - 'VNU_phone', |
|
88 | - 'VNU_capacity', |
|
89 | - 'VNU_url', |
|
90 | - 'VNU_virtual_phone', |
|
91 | - 'VNU_virtual_url', |
|
92 | - 'VNU_google_map_link', |
|
93 | - 'VNU_enable_for_gmap', |
|
94 | - ) |
|
95 | - ) |
|
96 | - ), |
|
97 | - 'Venue_Meta' => array( |
|
98 | - 'VNUM_ID' => new EE_DB_Only_Int_Field( |
|
99 | - 'VNUM_ID', |
|
100 | - esc_html__("ID of Venue Meta Row", "event_espresso"), |
|
101 | - false |
|
102 | - ), |
|
103 | - 'VNU_ID_fk' => new EE_DB_Only_Int_Field( |
|
104 | - 'VNU_ID', |
|
105 | - esc_html__("Foreign Key to Venue Post ", "event_espresso"), |
|
106 | - false |
|
107 | - ), |
|
108 | - 'VNU_address' => new EE_Plain_Text_Field( |
|
109 | - 'VNU_address', |
|
110 | - esc_html__("Venue Address line 1", "event_espresso"), |
|
111 | - true, |
|
112 | - '' |
|
113 | - ), |
|
114 | - 'VNU_address2' => new EE_Plain_Text_Field( |
|
115 | - 'VNU_address2', |
|
116 | - esc_html__("Venue Address line 2", "event_espresso"), |
|
117 | - true, |
|
118 | - '' |
|
119 | - ), |
|
120 | - 'VNU_city' => new EE_Plain_Text_Field( |
|
121 | - 'VNU_city', |
|
122 | - esc_html__("Venue City", "event_espresso"), |
|
123 | - true, |
|
124 | - '' |
|
125 | - ), |
|
126 | - 'STA_ID' => new EE_Foreign_Key_Int_Field( |
|
127 | - 'STA_ID', |
|
128 | - esc_html__("State ID", "event_espresso"), |
|
129 | - true, |
|
130 | - null, |
|
131 | - 'State' |
|
132 | - ), |
|
133 | - 'CNT_ISO' => new EE_Foreign_Key_String_Field( |
|
134 | - 'CNT_ISO', |
|
135 | - esc_html__("Country Code", "event_espresso"), |
|
136 | - true, |
|
137 | - null, |
|
138 | - 'Country' |
|
139 | - ), |
|
140 | - 'VNU_zip' => new EE_Plain_Text_Field( |
|
141 | - 'VNU_zip', |
|
142 | - esc_html__("Venue Zip/Postal Code", "event_espresso"), |
|
143 | - true |
|
144 | - ), |
|
145 | - 'VNU_phone' => new EE_Plain_Text_Field( |
|
146 | - 'VNU_phone', |
|
147 | - esc_html__("Venue Phone", "event_espresso"), |
|
148 | - true |
|
149 | - ), |
|
150 | - 'VNU_capacity' => new EE_Infinite_Integer_Field( |
|
151 | - 'VNU_capacity', |
|
152 | - esc_html__("Venue Capacity", "event_espresso"), |
|
153 | - true, |
|
154 | - EE_INF |
|
155 | - ), |
|
156 | - 'VNU_url' => new EE_Plain_Text_Field( |
|
157 | - 'VNU_url', |
|
158 | - esc_html__('Venue Website', 'event_espresso'), |
|
159 | - true |
|
160 | - ), |
|
161 | - 'VNU_virtual_phone' => new EE_Plain_Text_Field( |
|
162 | - 'VNU_virtual_phone', |
|
163 | - esc_html__('Call in Number', 'event_espresso'), |
|
164 | - true |
|
165 | - ), |
|
166 | - 'VNU_virtual_url' => new EE_Plain_Text_Field( |
|
167 | - 'VNU_virtual_url', |
|
168 | - esc_html__('Virtual URL', 'event_espresso'), |
|
169 | - true |
|
170 | - ), |
|
171 | - 'VNU_google_map_link' => new EE_Plain_Text_Field( |
|
172 | - 'VNU_google_map_link', |
|
173 | - esc_html__('Google Map Link', 'event_espresso'), |
|
174 | - true |
|
175 | - ), |
|
176 | - 'VNU_enable_for_gmap' => new EE_Boolean_Field( |
|
177 | - 'VNU_enable_for_gmap', |
|
178 | - esc_html__('Show Google Map?', 'event_espresso'), |
|
179 | - false, |
|
180 | - false |
|
181 | - ), |
|
182 | - ), |
|
183 | - ); |
|
184 | - $this->_model_relations = array( |
|
185 | - 'Event' => new EE_HABTM_Relation('Event_Venue'), |
|
186 | - 'State' => new EE_Belongs_To_Relation(), |
|
187 | - 'Country' => new EE_Belongs_To_Relation(), |
|
188 | - 'Event_Venue' => new EE_Has_Many_Relation(), |
|
189 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
190 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
191 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
192 | - ); |
|
193 | - // this model is generally available for reading |
|
194 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
195 | - $this->model_chain_to_password = ''; |
|
196 | - parent::__construct($timezone); |
|
197 | - } |
|
18 | + protected function __construct($timezone = null) |
|
19 | + { |
|
20 | + $this->singular_item = esc_html__('Venue', 'event_espresso'); |
|
21 | + $this->plural_item = esc_html__('Venues', 'event_espresso'); |
|
22 | + $this->_tables = array( |
|
23 | + 'Venue_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
24 | + 'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'), |
|
25 | + ); |
|
26 | + $this->_fields = array( |
|
27 | + 'Venue_CPT' => array( |
|
28 | + 'VNU_ID' => new EE_Primary_Key_Int_Field('ID', esc_html__("Venue ID", "event_espresso")), |
|
29 | + 'VNU_name' => new EE_Plain_Text_Field( |
|
30 | + 'post_title', |
|
31 | + esc_html__("Venue Name", "event_espresso"), |
|
32 | + false, |
|
33 | + '' |
|
34 | + ), |
|
35 | + 'VNU_desc' => new EE_Post_Content_Field( |
|
36 | + 'post_content', |
|
37 | + esc_html__("Venue Description", "event_espresso"), |
|
38 | + false, |
|
39 | + '' |
|
40 | + ), |
|
41 | + 'VNU_identifier' => new EE_Slug_Field('post_name', esc_html__("Venue Identifier", "event_espresso"), false, ''), |
|
42 | + 'VNU_created' => new EE_Datetime_Field( |
|
43 | + 'post_date', |
|
44 | + esc_html__("Date Venue Created", "event_espresso"), |
|
45 | + false, |
|
46 | + EE_Datetime_Field::now |
|
47 | + ), |
|
48 | + 'VNU_short_desc' => new EE_Plain_Text_Field( |
|
49 | + 'post_excerpt', |
|
50 | + esc_html__("Short Description of Venue", "event_espresso"), |
|
51 | + true, |
|
52 | + '' |
|
53 | + ), |
|
54 | + 'VNU_modified' => new EE_Datetime_Field( |
|
55 | + 'post_modified', |
|
56 | + esc_html__("Venue Modified Date", "event_espresso"), |
|
57 | + false, |
|
58 | + EE_Datetime_Field::now |
|
59 | + ), |
|
60 | + 'VNU_wp_user' => new EE_WP_User_Field( |
|
61 | + 'post_author', |
|
62 | + esc_html__("Venue Creator ID", "event_espresso"), |
|
63 | + false |
|
64 | + ), |
|
65 | + 'parent' => new EE_Integer_Field( |
|
66 | + 'post_parent', |
|
67 | + esc_html__("Venue Parent ID", "event_espresso"), |
|
68 | + false, |
|
69 | + 0 |
|
70 | + ), |
|
71 | + 'VNU_order' => new EE_Integer_Field('menu_order', esc_html__("Venue order", "event_espresso"), false, 1), |
|
72 | + 'post_type' => new EE_WP_Post_Type_Field('espresso_venues'), |
|
73 | + 'password' => new EE_Password_Field( |
|
74 | + 'post_password', |
|
75 | + esc_html__('Password', 'event_espresso'), |
|
76 | + false, |
|
77 | + '', |
|
78 | + array( |
|
79 | + 'VNU_desc', |
|
80 | + 'VNU_short_desc', |
|
81 | + 'VNU_address', |
|
82 | + 'VNU_address2', |
|
83 | + 'VNU_city', |
|
84 | + 'STA_ID', |
|
85 | + 'CNT_ISO', |
|
86 | + 'VNU_zip', |
|
87 | + 'VNU_phone', |
|
88 | + 'VNU_capacity', |
|
89 | + 'VNU_url', |
|
90 | + 'VNU_virtual_phone', |
|
91 | + 'VNU_virtual_url', |
|
92 | + 'VNU_google_map_link', |
|
93 | + 'VNU_enable_for_gmap', |
|
94 | + ) |
|
95 | + ) |
|
96 | + ), |
|
97 | + 'Venue_Meta' => array( |
|
98 | + 'VNUM_ID' => new EE_DB_Only_Int_Field( |
|
99 | + 'VNUM_ID', |
|
100 | + esc_html__("ID of Venue Meta Row", "event_espresso"), |
|
101 | + false |
|
102 | + ), |
|
103 | + 'VNU_ID_fk' => new EE_DB_Only_Int_Field( |
|
104 | + 'VNU_ID', |
|
105 | + esc_html__("Foreign Key to Venue Post ", "event_espresso"), |
|
106 | + false |
|
107 | + ), |
|
108 | + 'VNU_address' => new EE_Plain_Text_Field( |
|
109 | + 'VNU_address', |
|
110 | + esc_html__("Venue Address line 1", "event_espresso"), |
|
111 | + true, |
|
112 | + '' |
|
113 | + ), |
|
114 | + 'VNU_address2' => new EE_Plain_Text_Field( |
|
115 | + 'VNU_address2', |
|
116 | + esc_html__("Venue Address line 2", "event_espresso"), |
|
117 | + true, |
|
118 | + '' |
|
119 | + ), |
|
120 | + 'VNU_city' => new EE_Plain_Text_Field( |
|
121 | + 'VNU_city', |
|
122 | + esc_html__("Venue City", "event_espresso"), |
|
123 | + true, |
|
124 | + '' |
|
125 | + ), |
|
126 | + 'STA_ID' => new EE_Foreign_Key_Int_Field( |
|
127 | + 'STA_ID', |
|
128 | + esc_html__("State ID", "event_espresso"), |
|
129 | + true, |
|
130 | + null, |
|
131 | + 'State' |
|
132 | + ), |
|
133 | + 'CNT_ISO' => new EE_Foreign_Key_String_Field( |
|
134 | + 'CNT_ISO', |
|
135 | + esc_html__("Country Code", "event_espresso"), |
|
136 | + true, |
|
137 | + null, |
|
138 | + 'Country' |
|
139 | + ), |
|
140 | + 'VNU_zip' => new EE_Plain_Text_Field( |
|
141 | + 'VNU_zip', |
|
142 | + esc_html__("Venue Zip/Postal Code", "event_espresso"), |
|
143 | + true |
|
144 | + ), |
|
145 | + 'VNU_phone' => new EE_Plain_Text_Field( |
|
146 | + 'VNU_phone', |
|
147 | + esc_html__("Venue Phone", "event_espresso"), |
|
148 | + true |
|
149 | + ), |
|
150 | + 'VNU_capacity' => new EE_Infinite_Integer_Field( |
|
151 | + 'VNU_capacity', |
|
152 | + esc_html__("Venue Capacity", "event_espresso"), |
|
153 | + true, |
|
154 | + EE_INF |
|
155 | + ), |
|
156 | + 'VNU_url' => new EE_Plain_Text_Field( |
|
157 | + 'VNU_url', |
|
158 | + esc_html__('Venue Website', 'event_espresso'), |
|
159 | + true |
|
160 | + ), |
|
161 | + 'VNU_virtual_phone' => new EE_Plain_Text_Field( |
|
162 | + 'VNU_virtual_phone', |
|
163 | + esc_html__('Call in Number', 'event_espresso'), |
|
164 | + true |
|
165 | + ), |
|
166 | + 'VNU_virtual_url' => new EE_Plain_Text_Field( |
|
167 | + 'VNU_virtual_url', |
|
168 | + esc_html__('Virtual URL', 'event_espresso'), |
|
169 | + true |
|
170 | + ), |
|
171 | + 'VNU_google_map_link' => new EE_Plain_Text_Field( |
|
172 | + 'VNU_google_map_link', |
|
173 | + esc_html__('Google Map Link', 'event_espresso'), |
|
174 | + true |
|
175 | + ), |
|
176 | + 'VNU_enable_for_gmap' => new EE_Boolean_Field( |
|
177 | + 'VNU_enable_for_gmap', |
|
178 | + esc_html__('Show Google Map?', 'event_espresso'), |
|
179 | + false, |
|
180 | + false |
|
181 | + ), |
|
182 | + ), |
|
183 | + ); |
|
184 | + $this->_model_relations = array( |
|
185 | + 'Event' => new EE_HABTM_Relation('Event_Venue'), |
|
186 | + 'State' => new EE_Belongs_To_Relation(), |
|
187 | + 'Country' => new EE_Belongs_To_Relation(), |
|
188 | + 'Event_Venue' => new EE_Has_Many_Relation(), |
|
189 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
190 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
191 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
192 | + ); |
|
193 | + // this model is generally available for reading |
|
194 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
195 | + $this->model_chain_to_password = ''; |
|
196 | + parent::__construct($timezone); |
|
197 | + } |
|
198 | 198 | } |