@@ -7,129 +7,129 @@ |
||
| 7 | 7 | class EE_Post_Content_Field extends EE_Text_Field_Base |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * @param string $table_column |
|
| 12 | - * @param string $nicename |
|
| 13 | - * @param bool $nullable |
|
| 14 | - * @param null $default_value |
|
| 15 | - */ |
|
| 16 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 17 | - { |
|
| 18 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 19 | - $this->setSchemaType('object'); |
|
| 20 | - } |
|
| 10 | + /** |
|
| 11 | + * @param string $table_column |
|
| 12 | + * @param string $nicename |
|
| 13 | + * @param bool $nullable |
|
| 14 | + * @param null $default_value |
|
| 15 | + */ |
|
| 16 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 17 | + { |
|
| 18 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 19 | + $this->setSchemaType('object'); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * removes all tags which a WP Post wouldn't allow in its content normally |
|
| 25 | - * |
|
| 26 | - * @param string $value |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function prepare_for_set($value) |
|
| 30 | - { |
|
| 31 | - if (! current_user_can('unfiltered_html')) { |
|
| 32 | - $value = wp_kses("$value", wp_kses_allowed_html('post')); |
|
| 33 | - } |
|
| 34 | - return parent::prepare_for_set($value); |
|
| 35 | - } |
|
| 23 | + /** |
|
| 24 | + * removes all tags which a WP Post wouldn't allow in its content normally |
|
| 25 | + * |
|
| 26 | + * @param string $value |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function prepare_for_set($value) |
|
| 30 | + { |
|
| 31 | + if (! current_user_can('unfiltered_html')) { |
|
| 32 | + $value = wp_kses("$value", wp_kses_allowed_html('post')); |
|
| 33 | + } |
|
| 34 | + return parent::prepare_for_set($value); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Runs the content through `the_content`, or if prepares the content for placing in a form input |
|
| 41 | - * @param string $value_on_field_to_be_outputted |
|
| 42 | - * @param string $schema possible values: 'form_input' or null (if null, will run through 'the_content') |
|
| 43 | - * @return string |
|
| 44 | - * @throws EE_Error when WP_DEBUG is on and recursive calling is detected |
|
| 45 | - */ |
|
| 46 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 47 | - { |
|
| 48 | - switch ($schema) { |
|
| 49 | - case 'form_input': |
|
| 50 | - return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
| 51 | - case 'the_content': |
|
| 52 | - if (doing_filter('the_content')) { |
|
| 53 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 54 | - throw new EE_Error( |
|
| 55 | - sprintf( |
|
| 56 | - esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'), |
|
| 57 | - 'EE_Post_Content_Field::prepare_for_pretty_echoing', |
|
| 58 | - '$schema', |
|
| 59 | - 'the_content', |
|
| 60 | - 'the_content_wp_core_only' |
|
| 61 | - ) |
|
| 62 | - ); |
|
| 63 | - } else { |
|
| 64 | - return $this->prepare_for_pretty_echoing($value_on_field_to_be_outputted, 'the_content_wp_core_only'); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - return apply_filters( |
|
| 68 | - 'the_content', |
|
| 69 | - parent::prepare_for_pretty_echoing( |
|
| 70 | - $value_on_field_to_be_outputted, |
|
| 71 | - $schema |
|
| 72 | - ) |
|
| 73 | - ); |
|
| 74 | - case 'the_content_wp_core_only': |
|
| 75 | - default: |
|
| 76 | - self::_setup_the_content_wp_core_only_filters(); |
|
| 77 | - $return_value = apply_filters( |
|
| 78 | - 'the_content_wp_core_only', |
|
| 79 | - parent::prepare_for_pretty_echoing( |
|
| 80 | - $value_on_field_to_be_outputted, |
|
| 81 | - $schema |
|
| 82 | - ) |
|
| 83 | - ); |
|
| 84 | - // ya know what? adding these filters is super fast. Let's just |
|
| 85 | - // avoid needing to maintain global state and set this up as-needed |
|
| 86 | - remove_all_filters('the_content_wp_core_only'); |
|
| 87 | - do_action('AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done'); |
|
| 88 | - return $return_value; |
|
| 89 | - } |
|
| 90 | - } |
|
| 39 | + /** |
|
| 40 | + * Runs the content through `the_content`, or if prepares the content for placing in a form input |
|
| 41 | + * @param string $value_on_field_to_be_outputted |
|
| 42 | + * @param string $schema possible values: 'form_input' or null (if null, will run through 'the_content') |
|
| 43 | + * @return string |
|
| 44 | + * @throws EE_Error when WP_DEBUG is on and recursive calling is detected |
|
| 45 | + */ |
|
| 46 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 47 | + { |
|
| 48 | + switch ($schema) { |
|
| 49 | + case 'form_input': |
|
| 50 | + return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
| 51 | + case 'the_content': |
|
| 52 | + if (doing_filter('the_content')) { |
|
| 53 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 54 | + throw new EE_Error( |
|
| 55 | + sprintf( |
|
| 56 | + esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'), |
|
| 57 | + 'EE_Post_Content_Field::prepare_for_pretty_echoing', |
|
| 58 | + '$schema', |
|
| 59 | + 'the_content', |
|
| 60 | + 'the_content_wp_core_only' |
|
| 61 | + ) |
|
| 62 | + ); |
|
| 63 | + } else { |
|
| 64 | + return $this->prepare_for_pretty_echoing($value_on_field_to_be_outputted, 'the_content_wp_core_only'); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + return apply_filters( |
|
| 68 | + 'the_content', |
|
| 69 | + parent::prepare_for_pretty_echoing( |
|
| 70 | + $value_on_field_to_be_outputted, |
|
| 71 | + $schema |
|
| 72 | + ) |
|
| 73 | + ); |
|
| 74 | + case 'the_content_wp_core_only': |
|
| 75 | + default: |
|
| 76 | + self::_setup_the_content_wp_core_only_filters(); |
|
| 77 | + $return_value = apply_filters( |
|
| 78 | + 'the_content_wp_core_only', |
|
| 79 | + parent::prepare_for_pretty_echoing( |
|
| 80 | + $value_on_field_to_be_outputted, |
|
| 81 | + $schema |
|
| 82 | + ) |
|
| 83 | + ); |
|
| 84 | + // ya know what? adding these filters is super fast. Let's just |
|
| 85 | + // avoid needing to maintain global state and set this up as-needed |
|
| 86 | + remove_all_filters('the_content_wp_core_only'); |
|
| 87 | + do_action('AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done'); |
|
| 88 | + return $return_value; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | 92 | |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Verifies we've setup the standard WP core filters on 'the_content_wp_core_only' filter |
|
| 96 | - */ |
|
| 97 | - protected static function _setup_the_content_wp_core_only_filters() |
|
| 98 | - { |
|
| 99 | - add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8); |
|
| 100 | - add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8); |
|
| 101 | - add_filter('the_content_wp_core_only', 'wptexturize', 10); |
|
| 102 | - add_filter('the_content_wp_core_only', 'wpautop', 10); |
|
| 103 | - add_filter('the_content_wp_core_only', 'shortcode_unautop', 10); |
|
| 104 | - add_filter('the_content_wp_core_only', 'prepend_attachment', 10); |
|
| 105 | - if (function_exists('wp_filter_content_tags')) { |
|
| 106 | - add_filter('the_content_wp_core_only', 'wp_filter_content_tags', 10); |
|
| 107 | - } elseif (function_exists('wp_make_content_images_responsive')) { |
|
| 108 | - add_filter('the_content_wp_core_only', 'wp_make_content_images_responsive', 10); |
|
| 109 | - } |
|
| 110 | - add_filter('the_content_wp_core_only', 'do_shortcode', 11); |
|
| 111 | - add_filter('the_content_wp_core_only', 'convert_smilies', 20); |
|
| 112 | - } |
|
| 94 | + /** |
|
| 95 | + * Verifies we've setup the standard WP core filters on 'the_content_wp_core_only' filter |
|
| 96 | + */ |
|
| 97 | + protected static function _setup_the_content_wp_core_only_filters() |
|
| 98 | + { |
|
| 99 | + add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8); |
|
| 100 | + add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8); |
|
| 101 | + add_filter('the_content_wp_core_only', 'wptexturize', 10); |
|
| 102 | + add_filter('the_content_wp_core_only', 'wpautop', 10); |
|
| 103 | + add_filter('the_content_wp_core_only', 'shortcode_unautop', 10); |
|
| 104 | + add_filter('the_content_wp_core_only', 'prepend_attachment', 10); |
|
| 105 | + if (function_exists('wp_filter_content_tags')) { |
|
| 106 | + add_filter('the_content_wp_core_only', 'wp_filter_content_tags', 10); |
|
| 107 | + } elseif (function_exists('wp_make_content_images_responsive')) { |
|
| 108 | + add_filter('the_content_wp_core_only', 'wp_make_content_images_responsive', 10); |
|
| 109 | + } |
|
| 110 | + add_filter('the_content_wp_core_only', 'do_shortcode', 11); |
|
| 111 | + add_filter('the_content_wp_core_only', 'convert_smilies', 20); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | 114 | |
| 115 | 115 | |
| 116 | - public function getSchemaProperties() |
|
| 117 | - { |
|
| 118 | - return array( |
|
| 119 | - 'raw' => array( |
|
| 120 | - 'description' => sprintf( |
|
| 121 | - esc_html__('%s - the content as it exists in the database.', 'event_espresso'), |
|
| 122 | - $this->get_nicename() |
|
| 123 | - ), |
|
| 124 | - 'type' => 'string' |
|
| 125 | - ), |
|
| 126 | - 'rendered' => array( |
|
| 127 | - 'description' => sprintf( |
|
| 128 | - esc_html__('%s - the content rendered for display.', 'event_espresso'), |
|
| 129 | - $this->get_nicename() |
|
| 130 | - ), |
|
| 131 | - 'type' => 'string' |
|
| 132 | - ) |
|
| 133 | - ); |
|
| 134 | - } |
|
| 116 | + public function getSchemaProperties() |
|
| 117 | + { |
|
| 118 | + return array( |
|
| 119 | + 'raw' => array( |
|
| 120 | + 'description' => sprintf( |
|
| 121 | + esc_html__('%s - the content as it exists in the database.', 'event_espresso'), |
|
| 122 | + $this->get_nicename() |
|
| 123 | + ), |
|
| 124 | + 'type' => 'string' |
|
| 125 | + ), |
|
| 126 | + 'rendered' => array( |
|
| 127 | + 'description' => sprintf( |
|
| 128 | + esc_html__('%s - the content rendered for display.', 'event_espresso'), |
|
| 129 | + $this->get_nicename() |
|
| 130 | + ), |
|
| 131 | + 'type' => 'string' |
|
| 132 | + ) |
|
| 133 | + ); |
|
| 134 | + } |
|
| 135 | 135 | } |
@@ -14,57 +14,57 @@ |
||
| 14 | 14 | class EE_Full_HTML_Field extends EE_Text_Field_Base |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param string $table_column |
|
| 19 | - * @param string $nicename |
|
| 20 | - * @param bool $nullable |
|
| 21 | - * @param null $default_value |
|
| 22 | - */ |
|
| 23 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 24 | - { |
|
| 25 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 26 | - $this->setSchemaType('object'); |
|
| 27 | - } |
|
| 17 | + /** |
|
| 18 | + * @param string $table_column |
|
| 19 | + * @param string $nicename |
|
| 20 | + * @param bool $nullable |
|
| 21 | + * @param null $default_value |
|
| 22 | + */ |
|
| 23 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 24 | + { |
|
| 25 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 26 | + $this->setSchemaType('object'); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Does shortcodes and auto-paragraphs the content (unless schema is 'no_wpautop') |
|
| 32 | - * |
|
| 33 | - * @param type $value_on_field_to_be_outputted |
|
| 34 | - * @param type $schema |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 38 | - { |
|
| 39 | - if ($schema == 'form_input') { |
|
| 40 | - return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
| 41 | - } elseif ($schema == 'no_wpautop') { |
|
| 42 | - return do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema)); |
|
| 43 | - } else { |
|
| 44 | - return wpautop(do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema))); |
|
| 45 | - } |
|
| 46 | - } |
|
| 30 | + /** |
|
| 31 | + * Does shortcodes and auto-paragraphs the content (unless schema is 'no_wpautop') |
|
| 32 | + * |
|
| 33 | + * @param type $value_on_field_to_be_outputted |
|
| 34 | + * @param type $schema |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 38 | + { |
|
| 39 | + if ($schema == 'form_input') { |
|
| 40 | + return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
| 41 | + } elseif ($schema == 'no_wpautop') { |
|
| 42 | + return do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema)); |
|
| 43 | + } else { |
|
| 44 | + return wpautop(do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema))); |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | |
| 50 | - public function getSchemaProperties() |
|
| 51 | - { |
|
| 52 | - return array( |
|
| 53 | - 'raw' => array( |
|
| 54 | - 'description' => sprintf( |
|
| 55 | - esc_html__('%s - the value in the database.', 'event_espresso'), |
|
| 56 | - $this->get_nicename() |
|
| 57 | - ), |
|
| 58 | - 'type' => 'string' |
|
| 59 | - ), |
|
| 60 | - 'rendered' => array( |
|
| 61 | - 'description' => sprintf( |
|
| 62 | - esc_html__('%s - transformed for display.', 'event_espresso'), |
|
| 63 | - $this->get_nicename() |
|
| 64 | - ), |
|
| 65 | - 'type' => 'string', |
|
| 66 | - 'readonly' => true |
|
| 67 | - ) |
|
| 68 | - ); |
|
| 69 | - } |
|
| 50 | + public function getSchemaProperties() |
|
| 51 | + { |
|
| 52 | + return array( |
|
| 53 | + 'raw' => array( |
|
| 54 | + 'description' => sprintf( |
|
| 55 | + esc_html__('%s - the value in the database.', 'event_espresso'), |
|
| 56 | + $this->get_nicename() |
|
| 57 | + ), |
|
| 58 | + 'type' => 'string' |
|
| 59 | + ), |
|
| 60 | + 'rendered' => array( |
|
| 61 | + 'description' => sprintf( |
|
| 62 | + esc_html__('%s - transformed for display.', 'event_espresso'), |
|
| 63 | + $this->get_nicename() |
|
| 64 | + ), |
|
| 65 | + 'type' => 'string', |
|
| 66 | + 'readonly' => true |
|
| 67 | + ) |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -10,78 +10,78 @@ |
||
| 10 | 10 | class EE_Infinite_Integer_Field extends EE_Model_Field_Base |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param string $table_column |
|
| 15 | - * @param string $nicename |
|
| 16 | - * @param bool $nullable |
|
| 17 | - * @param null $default_value |
|
| 18 | - */ |
|
| 19 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 20 | - { |
|
| 21 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 22 | - $this->setSchemaType(array('integer', 'null')); |
|
| 23 | - } |
|
| 13 | + /** |
|
| 14 | + * @param string $table_column |
|
| 15 | + * @param string $nicename |
|
| 16 | + * @param bool $nullable |
|
| 17 | + * @param null $default_value |
|
| 18 | + */ |
|
| 19 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 20 | + { |
|
| 21 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 22 | + $this->setSchemaType(array('integer', 'null')); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - public function prepare_for_use_in_db($value_of_field_on_model_object) |
|
| 27 | - { |
|
| 28 | - if ($value_of_field_on_model_object === EE_INF) { |
|
| 29 | - return EE_INF_IN_DB; |
|
| 30 | - } else { |
|
| 31 | - return intval($value_of_field_on_model_object); |
|
| 32 | - } |
|
| 33 | - } |
|
| 26 | + public function prepare_for_use_in_db($value_of_field_on_model_object) |
|
| 27 | + { |
|
| 28 | + if ($value_of_field_on_model_object === EE_INF) { |
|
| 29 | + return EE_INF_IN_DB; |
|
| 30 | + } else { |
|
| 31 | + return intval($value_of_field_on_model_object); |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 36 | - { |
|
| 37 | - if ( |
|
| 38 | - $value_inputted_for_field_on_model_object === EE_INF_IN_DB || |
|
| 39 | - $value_inputted_for_field_on_model_object === EE_INF || |
|
| 40 | - $value_inputted_for_field_on_model_object === "EE_INF" || |
|
| 41 | - $value_inputted_for_field_on_model_object === "" |
|
| 42 | - ) { |
|
| 43 | - return EE_INF; |
|
| 44 | - } else { |
|
| 45 | - return intval($value_inputted_for_field_on_model_object); |
|
| 46 | - } |
|
| 47 | - } |
|
| 35 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 36 | + { |
|
| 37 | + if ( |
|
| 38 | + $value_inputted_for_field_on_model_object === EE_INF_IN_DB || |
|
| 39 | + $value_inputted_for_field_on_model_object === EE_INF || |
|
| 40 | + $value_inputted_for_field_on_model_object === "EE_INF" || |
|
| 41 | + $value_inputted_for_field_on_model_object === "" |
|
| 42 | + ) { |
|
| 43 | + return EE_INF; |
|
| 44 | + } else { |
|
| 45 | + return intval($value_inputted_for_field_on_model_object); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public function prepare_for_set_from_db($value_inputted_for_field_on_model_object) |
|
| 50 | - { |
|
| 51 | - $intval = intval($value_inputted_for_field_on_model_object); |
|
| 52 | - if ($intval == EE_INF_IN_DB) { |
|
| 53 | - return EE_INF; |
|
| 54 | - } else { |
|
| 55 | - return $intval; |
|
| 56 | - } |
|
| 57 | - } |
|
| 49 | + public function prepare_for_set_from_db($value_inputted_for_field_on_model_object) |
|
| 50 | + { |
|
| 51 | + $intval = intval($value_inputted_for_field_on_model_object); |
|
| 52 | + if ($intval == EE_INF_IN_DB) { |
|
| 53 | + return EE_INF; |
|
| 54 | + } else { |
|
| 55 | + return $intval; |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * For outputting this field's value. If you want to output it into an input or something, |
|
| 61 | - * use $schema=='input', as it will replace EE_INF with ''. If you want a readable version, use $schema=='text' |
|
| 62 | - * as it will replace EE_INF with i18n Infinite |
|
| 63 | - * |
|
| 64 | - * @param type $value_on_field_to_be_outputted |
|
| 65 | - * @param string $schema input, symbol, text; or any string you want to show if the value equals EE_INF |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 68 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 69 | - { |
|
| 70 | - if ($value_on_field_to_be_outputted === EE_INF) { |
|
| 71 | - switch ($schema) { |
|
| 72 | - case 'input': |
|
| 73 | - case 'form_input': |
|
| 74 | - return ''; |
|
| 75 | - case 'symbol': |
|
| 76 | - return "∞"; |
|
| 77 | - case 'text': |
|
| 78 | - case null: |
|
| 79 | - return esc_html__("Unlimited", "event_espresso"); |
|
| 80 | - default: |
|
| 81 | - return $schema; |
|
| 82 | - } |
|
| 83 | - } else { |
|
| 84 | - return $value_on_field_to_be_outputted; |
|
| 85 | - } |
|
| 86 | - } |
|
| 59 | + /** |
|
| 60 | + * For outputting this field's value. If you want to output it into an input or something, |
|
| 61 | + * use $schema=='input', as it will replace EE_INF with ''. If you want a readable version, use $schema=='text' |
|
| 62 | + * as it will replace EE_INF with i18n Infinite |
|
| 63 | + * |
|
| 64 | + * @param type $value_on_field_to_be_outputted |
|
| 65 | + * @param string $schema input, symbol, text; or any string you want to show if the value equals EE_INF |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 69 | + { |
|
| 70 | + if ($value_on_field_to_be_outputted === EE_INF) { |
|
| 71 | + switch ($schema) { |
|
| 72 | + case 'input': |
|
| 73 | + case 'form_input': |
|
| 74 | + return ''; |
|
| 75 | + case 'symbol': |
|
| 76 | + return "∞"; |
|
| 77 | + case 'text': |
|
| 78 | + case null: |
|
| 79 | + return esc_html__("Unlimited", "event_espresso"); |
|
| 80 | + default: |
|
| 81 | + return $schema; |
|
| 82 | + } |
|
| 83 | + } else { |
|
| 84 | + return $value_on_field_to_be_outputted; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -3,39 +3,39 @@ |
||
| 3 | 3 | class EE_Foreign_Key_Int_Field extends EE_Foreign_Key_Field_Base |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - /** |
|
| 7 | - * @param string $table_column name fo column for field |
|
| 8 | - * @param string $nice_name should eb internationalized with esc_html__('blah','event_espresso') |
|
| 9 | - * @param boolean $nullable |
|
| 10 | - * @param mixed $default_value if this is a integer field, it should be an int. |
|
| 11 | - * if it's a string field, it should be a string |
|
| 12 | - * @param string|array $model_name eg 'Event','Answer','Term', etc. |
|
| 13 | - * Basically its the model class's name without the "EEM_" |
|
| 14 | - */ |
|
| 15 | - public function __construct($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 16 | - { |
|
| 17 | - parent::__construct($table_column, $nice_name, $nullable, $default_value, $model_name); |
|
| 18 | - $this->setSchemaType('integer'); |
|
| 19 | - } |
|
| 6 | + /** |
|
| 7 | + * @param string $table_column name fo column for field |
|
| 8 | + * @param string $nice_name should eb internationalized with esc_html__('blah','event_espresso') |
|
| 9 | + * @param boolean $nullable |
|
| 10 | + * @param mixed $default_value if this is a integer field, it should be an int. |
|
| 11 | + * if it's a string field, it should be a string |
|
| 12 | + * @param string|array $model_name eg 'Event','Answer','Term', etc. |
|
| 13 | + * Basically its the model class's name without the "EEM_" |
|
| 14 | + */ |
|
| 15 | + public function __construct($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 16 | + { |
|
| 17 | + parent::__construct($table_column, $nice_name, $nullable, $default_value, $model_name); |
|
| 18 | + $this->setSchemaType('integer'); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
| 24 | - * @return int |
|
| 25 | - * @throws EE_Error |
|
| 26 | - * @throws EE_Error |
|
| 27 | - */ |
|
| 28 | - public function prepare_for_set($value_inputted_for_field_on_model_object): int |
|
| 29 | - { |
|
| 30 | - if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
| 31 | - $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
| 32 | - } |
|
| 33 | - return absint($value_inputted_for_field_on_model_object); |
|
| 34 | - } |
|
| 22 | + /** |
|
| 23 | + * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
| 24 | + * @return int |
|
| 25 | + * @throws EE_Error |
|
| 26 | + * @throws EE_Error |
|
| 27 | + */ |
|
| 28 | + public function prepare_for_set($value_inputted_for_field_on_model_object): int |
|
| 29 | + { |
|
| 30 | + if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
| 31 | + $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
| 32 | + } |
|
| 33 | + return absint($value_inputted_for_field_on_model_object); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | |
| 37 | - public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
| 38 | - { |
|
| 39 | - return intval($value_found_in_db_for_model_object); |
|
| 40 | - } |
|
| 37 | + public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
| 38 | + { |
|
| 39 | + return intval($value_found_in_db_for_model_object); |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -13,39 +13,39 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class EE_WP_User_Field extends EE_Foreign_Key_Int_Field |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * No need to provide a default or the model pointed to- the default is |
|
| 18 | - * always get_current_user_id() and the model pointed to is always WP_User |
|
| 19 | - * |
|
| 20 | - * @param string $table_column name fo column for field |
|
| 21 | - * @param string $nice_name should eb internationalized with esc_html__('blah','event_espresso') |
|
| 22 | - * @param boolean $nullable |
|
| 23 | - */ |
|
| 24 | - public function __construct($table_column, $nice_name, $nullable) |
|
| 25 | - { |
|
| 26 | - parent::__construct($table_column, $nice_name, $nullable, get_current_user_id(), 'WP_User'); |
|
| 27 | - } |
|
| 16 | + /** |
|
| 17 | + * No need to provide a default or the model pointed to- the default is |
|
| 18 | + * always get_current_user_id() and the model pointed to is always WP_User |
|
| 19 | + * |
|
| 20 | + * @param string $table_column name fo column for field |
|
| 21 | + * @param string $nice_name should eb internationalized with esc_html__('blah','event_espresso') |
|
| 22 | + * @param boolean $nullable |
|
| 23 | + */ |
|
| 24 | + public function __construct($table_column, $nice_name, $nullable) |
|
| 25 | + { |
|
| 26 | + parent::__construct($table_column, $nice_name, $nullable, get_current_user_id(), 'WP_User'); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Gets the default which is always the current user. This can't be set when initially |
|
| 31 | - * constructing the model field because that's done before $current_user is set |
|
| 32 | - * |
|
| 33 | - * @return mixed |
|
| 34 | - */ |
|
| 35 | - public function get_default_value() |
|
| 36 | - { |
|
| 37 | - if (did_action('init')) { |
|
| 38 | - return get_current_user_id(); |
|
| 39 | - } else { |
|
| 40 | - EE_Error::doing_it_wrong( |
|
| 41 | - 'EE_WP_User_Field::get_default_value', |
|
| 42 | - esc_html__( |
|
| 43 | - 'You cant get a default value for a wp_User_Field because the "init" action is called, because current_user global hasnt yet been setup. Consider doing your business logic on the "init" hook or later.', |
|
| 44 | - 'event_espresso' |
|
| 45 | - ), |
|
| 46 | - '4.6.20' |
|
| 47 | - ); |
|
| 48 | - return 1; |
|
| 49 | - } |
|
| 50 | - } |
|
| 29 | + /** |
|
| 30 | + * Gets the default which is always the current user. This can't be set when initially |
|
| 31 | + * constructing the model field because that's done before $current_user is set |
|
| 32 | + * |
|
| 33 | + * @return mixed |
|
| 34 | + */ |
|
| 35 | + public function get_default_value() |
|
| 36 | + { |
|
| 37 | + if (did_action('init')) { |
|
| 38 | + return get_current_user_id(); |
|
| 39 | + } else { |
|
| 40 | + EE_Error::doing_it_wrong( |
|
| 41 | + 'EE_WP_User_Field::get_default_value', |
|
| 42 | + esc_html__( |
|
| 43 | + 'You cant get a default value for a wp_User_Field because the "init" action is called, because current_user global hasnt yet been setup. Consider doing your business logic on the "init" hook or later.', |
|
| 44 | + 'event_espresso' |
|
| 45 | + ), |
|
| 46 | + '4.6.20' |
|
| 47 | + ); |
|
| 48 | + return 1; |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -7,92 +7,92 @@ |
||
| 7 | 7 | class EE_Money_Field extends EE_Float_Field |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * @param string $table_column |
|
| 12 | - * @param string $nicename |
|
| 13 | - * @param bool $nullable |
|
| 14 | - * @param null $default_value |
|
| 15 | - */ |
|
| 16 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 17 | - { |
|
| 18 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 19 | - $this->setSchemaType('object'); |
|
| 20 | - } |
|
| 10 | + /** |
|
| 11 | + * @param string $table_column |
|
| 12 | + * @param string $nicename |
|
| 13 | + * @param bool $nullable |
|
| 14 | + * @param null $default_value |
|
| 15 | + */ |
|
| 16 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 17 | + { |
|
| 18 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 19 | + $this->setSchemaType('object'); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Schemas: |
|
| 25 | - * 'localized_float': "3,023.00" |
|
| 26 | - * 'no_currency_code': "$3,023.00" |
|
| 27 | - * null: "$3,023.00<span>USD</span>" |
|
| 28 | - * |
|
| 29 | - * @param string $value_on_field_to_be_outputted |
|
| 30 | - * @param string $schema |
|
| 31 | - * @return string |
|
| 32 | - */ |
|
| 33 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 34 | - { |
|
| 35 | - $pretty_float = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted); |
|
| 23 | + /** |
|
| 24 | + * Schemas: |
|
| 25 | + * 'localized_float': "3,023.00" |
|
| 26 | + * 'no_currency_code': "$3,023.00" |
|
| 27 | + * null: "$3,023.00<span>USD</span>" |
|
| 28 | + * |
|
| 29 | + * @param string $value_on_field_to_be_outputted |
|
| 30 | + * @param string $schema |
|
| 31 | + * @return string |
|
| 32 | + */ |
|
| 33 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 34 | + { |
|
| 35 | + $pretty_float = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted); |
|
| 36 | 36 | |
| 37 | - if ($schema == 'localized_float') { |
|
| 38 | - return $pretty_float; |
|
| 39 | - } |
|
| 40 | - if ($schema == 'no_currency_code') { |
|
| 37 | + if ($schema == 'localized_float') { |
|
| 38 | + return $pretty_float; |
|
| 39 | + } |
|
| 40 | + if ($schema == 'no_currency_code') { |
|
| 41 | 41 | // echo "schema no currency!"; |
| 42 | - $display_code = false; |
|
| 43 | - } else { |
|
| 44 | - $display_code = true; |
|
| 45 | - } |
|
| 46 | - // we don't use the $pretty_float because format_currency will take care of it. |
|
| 47 | - return EEH_Template::format_currency($value_on_field_to_be_outputted, false, $display_code); |
|
| 48 | - } |
|
| 42 | + $display_code = false; |
|
| 43 | + } else { |
|
| 44 | + $display_code = true; |
|
| 45 | + } |
|
| 46 | + // we don't use the $pretty_float because format_currency will take care of it. |
|
| 47 | + return EEH_Template::format_currency($value_on_field_to_be_outputted, false, $display_code); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * If provided with a string, strips out money-related formatting to turn it into a proper float. |
|
| 52 | - * Rounds the float to the correct number of decimal places for this country's currency. |
|
| 53 | - * Also, interprets periods and commas according to the country's currency settings. |
|
| 54 | - * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
| 55 | - * |
|
| 56 | - * @param string $value_inputted_for_field_on_model_object |
|
| 57 | - * @return float |
|
| 58 | - */ |
|
| 59 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 60 | - { |
|
| 61 | - // remove any currencies etc. |
|
| 50 | + /** |
|
| 51 | + * If provided with a string, strips out money-related formatting to turn it into a proper float. |
|
| 52 | + * Rounds the float to the correct number of decimal places for this country's currency. |
|
| 53 | + * Also, interprets periods and commas according to the country's currency settings. |
|
| 54 | + * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
| 55 | + * |
|
| 56 | + * @param string $value_inputted_for_field_on_model_object |
|
| 57 | + * @return float |
|
| 58 | + */ |
|
| 59 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 60 | + { |
|
| 61 | + // remove any currencies etc. |
|
| 62 | 62 | // if(is_string($value_inputted_for_field_on_model_object)){ |
| 63 | 63 | // $value_inputted_for_field_on_model_object = preg_replace("/[^0-9,.]/", "", $value_inputted_for_field_on_model_object); |
| 64 | 64 | // } |
| 65 | - // now it's a float-style string or number |
|
| 66 | - $float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object); |
|
| 67 | - // round to the correctly number of decimal places for this currency |
|
| 68 | - $rounded_value = round($float_val, EE_Registry::instance()->CFG->currency->dec_plc); |
|
| 69 | - return $rounded_value; |
|
| 70 | - } |
|
| 65 | + // now it's a float-style string or number |
|
| 66 | + $float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object); |
|
| 67 | + // round to the correctly number of decimal places for this currency |
|
| 68 | + $rounded_value = round($float_val, EE_Registry::instance()->CFG->currency->dec_plc); |
|
| 69 | + return $rounded_value; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - public function prepare_for_get($value_of_field_on_model_object) |
|
| 73 | - { |
|
| 74 | - $c = EE_Registry::instance()->CFG->currency; |
|
| 75 | - return round(parent::prepare_for_get($value_of_field_on_model_object), $c->dec_plc); |
|
| 76 | - } |
|
| 72 | + public function prepare_for_get($value_of_field_on_model_object) |
|
| 73 | + { |
|
| 74 | + $c = EE_Registry::instance()->CFG->currency; |
|
| 75 | + return round(parent::prepare_for_get($value_of_field_on_model_object), $c->dec_plc); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - public function getSchemaProperties() |
|
| 79 | - { |
|
| 80 | - return array( |
|
| 81 | - 'raw' => array( |
|
| 82 | - 'description' => sprintf( |
|
| 83 | - esc_html__('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'), |
|
| 84 | - $this->get_nicename() |
|
| 85 | - ), |
|
| 86 | - 'type' => 'number', |
|
| 87 | - ), |
|
| 88 | - 'pretty' => array( |
|
| 89 | - 'description' => sprintf( |
|
| 90 | - esc_html__('%s - formatted for display in the set currency and decimal places.', 'event_espresso'), |
|
| 91 | - $this->get_nicename() |
|
| 92 | - ), |
|
| 93 | - 'type' => 'string', |
|
| 94 | - 'format' => 'money' |
|
| 95 | - ) |
|
| 96 | - ); |
|
| 97 | - } |
|
| 78 | + public function getSchemaProperties() |
|
| 79 | + { |
|
| 80 | + return array( |
|
| 81 | + 'raw' => array( |
|
| 82 | + 'description' => sprintf( |
|
| 83 | + esc_html__('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'), |
|
| 84 | + $this->get_nicename() |
|
| 85 | + ), |
|
| 86 | + 'type' => 'number', |
|
| 87 | + ), |
|
| 88 | + 'pretty' => array( |
|
| 89 | + 'description' => sprintf( |
|
| 90 | + esc_html__('%s - formatted for display in the set currency and decimal places.', 'event_espresso'), |
|
| 91 | + $this->get_nicename() |
|
| 92 | + ), |
|
| 93 | + 'type' => 'string', |
|
| 94 | + 'format' => 'money' |
|
| 95 | + ) |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | 98 | } |
@@ -2,24 +2,24 @@ |
||
| 2 | 2 | |
| 3 | 3 | abstract class EE_Primary_Key_Field_Base extends EE_Field_With_Model_Name |
| 4 | 4 | { |
| 5 | - /** |
|
| 6 | - * Overrides parent so it doesn't need to provide so many non-applicable fields |
|
| 7 | - * |
|
| 8 | - * @param string $table_column |
|
| 9 | - * @param string $nicename |
|
| 10 | - */ |
|
| 11 | - public function __construct($table_column, $nicename, $default) |
|
| 12 | - { |
|
| 13 | - parent::__construct($table_column, $nicename, false, $default, ''); |
|
| 14 | - } |
|
| 5 | + /** |
|
| 6 | + * Overrides parent so it doesn't need to provide so many non-applicable fields |
|
| 7 | + * |
|
| 8 | + * @param string $table_column |
|
| 9 | + * @param string $nicename |
|
| 10 | + */ |
|
| 11 | + public function __construct($table_column, $nicename, $default) |
|
| 12 | + { |
|
| 13 | + parent::__construct($table_column, $nicename, false, $default, ''); |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param $table_alias |
|
| 18 | - * @param $name |
|
| 19 | - */ |
|
| 20 | - public function _construct_finalize($table_alias, $name, $model_name) |
|
| 21 | - { |
|
| 22 | - $this->_model_name_pointed_to = $model_name; |
|
| 23 | - parent::_construct_finalize($table_alias, $name, $model_name); |
|
| 24 | - } |
|
| 16 | + /** |
|
| 17 | + * @param $table_alias |
|
| 18 | + * @param $name |
|
| 19 | + */ |
|
| 20 | + public function _construct_finalize($table_alias, $name, $model_name) |
|
| 21 | + { |
|
| 22 | + $this->_model_name_pointed_to = $model_name; |
|
| 23 | + parent::_construct_finalize($table_alias, $name, $model_name); |
|
| 24 | + } |
|
| 25 | 25 | } |
@@ -3,114 +3,114 @@ |
||
| 3 | 3 | class EE_WP_Post_Status_Field extends EE_Enum_Text_Field |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - protected $_wp_post_stati; |
|
| 6 | + protected $_wp_post_stati; |
|
| 7 | 7 | |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * constructor |
|
| 11 | - * |
|
| 12 | - * @param string $table_column column on table |
|
| 13 | - * @param string $nicename nice name for column(field) |
|
| 14 | - * @param bool $nullable is this field nullable |
|
| 15 | - * @param string $default_value default status |
|
| 16 | - * @param array $new_stati If additional stati are to be used other than the default WP statuses then |
|
| 17 | - * they can be registered via this property. The format of the array should be |
|
| 18 | - * as follows: array( |
|
| 19 | - * 'status_reference' => array( |
|
| 20 | - * 'label' => esc_html__('Status Reference Label', 'event_espresso') |
|
| 21 | - * 'public' => true, //'Whether posts of this status should be shown on the |
|
| 22 | - * frontend of the site' |
|
| 23 | - * 'exclude_from_search' => false, //'Whether posts of this status should be |
|
| 24 | - * excluded from wp searches' |
|
| 25 | - * 'show_in_admin_all_list' => true, //whether posts of this status are included |
|
| 26 | - * in queries for the admin "all" view in list table views. |
|
| 27 | - * 'show_in_admin_status_list' => true, //Show in the list of statuses with post |
|
| 28 | - * counts at the top of the admin list tables (i.e. Status Reference(2) ) |
|
| 29 | - * 'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>', |
|
| 30 | - * 'Status References <span class="count">(%s)</span>' ), //the text to display |
|
| 31 | - * on the admin screen( or you won't see your status count ). |
|
| 32 | - * ) |
|
| 33 | - * ) |
|
| 34 | - * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
|
| 35 | - * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is |
|
| 36 | - * set to true, it will be stored as an INT |
|
| 37 | - */ |
|
| 38 | - public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array()) |
|
| 39 | - { |
|
| 40 | - $this->_register_new_stati($new_stati); |
|
| 41 | - $this->_set_allowed_enum_values(); |
|
| 42 | - parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values); |
|
| 43 | - } |
|
| 9 | + /** |
|
| 10 | + * constructor |
|
| 11 | + * |
|
| 12 | + * @param string $table_column column on table |
|
| 13 | + * @param string $nicename nice name for column(field) |
|
| 14 | + * @param bool $nullable is this field nullable |
|
| 15 | + * @param string $default_value default status |
|
| 16 | + * @param array $new_stati If additional stati are to be used other than the default WP statuses then |
|
| 17 | + * they can be registered via this property. The format of the array should be |
|
| 18 | + * as follows: array( |
|
| 19 | + * 'status_reference' => array( |
|
| 20 | + * 'label' => esc_html__('Status Reference Label', 'event_espresso') |
|
| 21 | + * 'public' => true, //'Whether posts of this status should be shown on the |
|
| 22 | + * frontend of the site' |
|
| 23 | + * 'exclude_from_search' => false, //'Whether posts of this status should be |
|
| 24 | + * excluded from wp searches' |
|
| 25 | + * 'show_in_admin_all_list' => true, //whether posts of this status are included |
|
| 26 | + * in queries for the admin "all" view in list table views. |
|
| 27 | + * 'show_in_admin_status_list' => true, //Show in the list of statuses with post |
|
| 28 | + * counts at the top of the admin list tables (i.e. Status Reference(2) ) |
|
| 29 | + * 'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>', |
|
| 30 | + * 'Status References <span class="count">(%s)</span>' ), //the text to display |
|
| 31 | + * on the admin screen( or you won't see your status count ). |
|
| 32 | + * ) |
|
| 33 | + * ) |
|
| 34 | + * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
|
| 35 | + * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is |
|
| 36 | + * set to true, it will be stored as an INT |
|
| 37 | + */ |
|
| 38 | + public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array()) |
|
| 39 | + { |
|
| 40 | + $this->_register_new_stati($new_stati); |
|
| 41 | + $this->_set_allowed_enum_values(); |
|
| 42 | + parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * This registers any new statuses sent via the $new_stati array on construct |
|
| 48 | - * |
|
| 49 | - * @access protected |
|
| 50 | - * @param array $new_stati statuses |
|
| 51 | - * @return void |
|
| 52 | - */ |
|
| 53 | - protected function _register_new_stati($new_stati) |
|
| 54 | - { |
|
| 46 | + /** |
|
| 47 | + * This registers any new statuses sent via the $new_stati array on construct |
|
| 48 | + * |
|
| 49 | + * @access protected |
|
| 50 | + * @param array $new_stati statuses |
|
| 51 | + * @return void |
|
| 52 | + */ |
|
| 53 | + protected function _register_new_stati($new_stati) |
|
| 54 | + { |
|
| 55 | 55 | |
| 56 | - foreach ((array) $new_stati as $status_key => $status_args) { |
|
| 57 | - $args = array( |
|
| 58 | - 'label' => isset($status_args['label']) ? $status_args['label'] : $status_key, |
|
| 59 | - 'public' => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true, |
|
| 60 | - 'exclude_from_search' => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false, |
|
| 61 | - 'show_in_admin_all_list' => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false, |
|
| 62 | - 'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true, |
|
| 63 | - 'label_count' => isset($status_args['label_count']) ? $status_args['label_count'] : '', |
|
| 64 | - ); |
|
| 65 | - register_post_status($status_key, $status_args); |
|
| 66 | - } |
|
| 67 | - } |
|
| 56 | + foreach ((array) $new_stati as $status_key => $status_args) { |
|
| 57 | + $args = array( |
|
| 58 | + 'label' => isset($status_args['label']) ? $status_args['label'] : $status_key, |
|
| 59 | + 'public' => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true, |
|
| 60 | + 'exclude_from_search' => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false, |
|
| 61 | + 'show_in_admin_all_list' => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false, |
|
| 62 | + 'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true, |
|
| 63 | + 'label_count' => isset($status_args['label_count']) ? $status_args['label_count'] : '', |
|
| 64 | + ); |
|
| 65 | + register_post_status($status_key, $status_args); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * This sets the _allowed_enum_values property using the $wp_post_stati array |
|
| 72 | - * |
|
| 73 | - * @access protected |
|
| 74 | - * @regurn void |
|
| 75 | - */ |
|
| 76 | - protected function _set_allowed_enum_values() |
|
| 77 | - { |
|
| 78 | - // first let's get the post_statuses |
|
| 79 | - global $wp_post_statuses; |
|
| 80 | - $this->_wp_post_stati = $wp_post_statuses; |
|
| 70 | + /** |
|
| 71 | + * This sets the _allowed_enum_values property using the $wp_post_stati array |
|
| 72 | + * |
|
| 73 | + * @access protected |
|
| 74 | + * @regurn void |
|
| 75 | + */ |
|
| 76 | + protected function _set_allowed_enum_values() |
|
| 77 | + { |
|
| 78 | + // first let's get the post_statuses |
|
| 79 | + global $wp_post_statuses; |
|
| 80 | + $this->_wp_post_stati = $wp_post_statuses; |
|
| 81 | 81 | |
| 82 | - foreach ($this->_wp_post_stati as $post_status => $args_object) { |
|
| 83 | - $this->_allowed_enum_values[ $post_status ] = $args_object->label; |
|
| 84 | - } |
|
| 85 | - } |
|
| 82 | + foreach ($this->_wp_post_stati as $post_status => $args_object) { |
|
| 83 | + $this->_allowed_enum_values[ $post_status ] = $args_object->label; |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Before calling parent, first double-checks our list of acceptable post |
|
| 89 | - * types is up-to-date |
|
| 90 | - * |
|
| 91 | - * @param string $value_inputted_for_field_on_model_object |
|
| 92 | - * @return string |
|
| 93 | - */ |
|
| 94 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 95 | - { |
|
| 96 | - $this->_set_allowed_enum_values(); |
|
| 97 | - return parent::prepare_for_set($value_inputted_for_field_on_model_object); |
|
| 98 | - } |
|
| 87 | + /** |
|
| 88 | + * Before calling parent, first double-checks our list of acceptable post |
|
| 89 | + * types is up-to-date |
|
| 90 | + * |
|
| 91 | + * @param string $value_inputted_for_field_on_model_object |
|
| 92 | + * @return string |
|
| 93 | + */ |
|
| 94 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 95 | + { |
|
| 96 | + $this->_set_allowed_enum_values(); |
|
| 97 | + return parent::prepare_for_set($value_inputted_for_field_on_model_object); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | 100 | |
| 101 | 101 | |
| 102 | - // helper methods for getting various $wp_post_statuses stuff. |
|
| 102 | + // helper methods for getting various $wp_post_statuses stuff. |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * This just returns the status object for the given status |
|
| 106 | - * |
|
| 107 | - * @access public |
|
| 108 | - * @see wp_register_post_status in wp-includes/post.php for a list of properties of the status object |
|
| 109 | - * @param string $status What status object you want |
|
| 110 | - * @return std_object the status object or FALSE if it doesn't exist. |
|
| 111 | - */ |
|
| 112 | - public function get_status_object($status) |
|
| 113 | - { |
|
| 114 | - return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false; |
|
| 115 | - } |
|
| 104 | + /** |
|
| 105 | + * This just returns the status object for the given status |
|
| 106 | + * |
|
| 107 | + * @access public |
|
| 108 | + * @see wp_register_post_status in wp-includes/post.php for a list of properties of the status object |
|
| 109 | + * @param string $status What status object you want |
|
| 110 | + * @return std_object the status object or FALSE if it doesn't exist. |
|
| 111 | + */ |
|
| 112 | + public function get_status_object($status) |
|
| 113 | + { |
|
| 114 | + return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false; |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -13,382 +13,382 @@ |
||
| 13 | 13 | class EEM_Price extends EEM_Soft_Delete_Base |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var EEM_Price |
|
| 18 | - */ |
|
| 19 | - protected static $_instance; |
|
| 16 | + /** |
|
| 17 | + * @var EEM_Price |
|
| 18 | + */ |
|
| 19 | + protected static $_instance; |
|
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * private constructor to prevent direct creation |
|
| 24 | - * |
|
| 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(string $timezone = '') |
|
| 33 | - { |
|
| 34 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 35 | - $this->singular_item = esc_html__('Price', 'event_espresso'); |
|
| 36 | - $this->plural_item = esc_html__('Prices', 'event_espresso'); |
|
| 22 | + /** |
|
| 23 | + * private constructor to prevent direct creation |
|
| 24 | + * |
|
| 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(string $timezone = '') |
|
| 33 | + { |
|
| 34 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 35 | + $this->singular_item = esc_html__('Price', 'event_espresso'); |
|
| 36 | + $this->plural_item = esc_html__('Prices', 'event_espresso'); |
|
| 37 | 37 | |
| 38 | - $this->_tables = [ |
|
| 39 | - 'Price' => new EE_Primary_Table('esp_price', 'PRC_ID'), |
|
| 40 | - ]; |
|
| 41 | - $this->_fields = [ |
|
| 42 | - 'Price' => [ |
|
| 43 | - 'PRC_ID' => new EE_Primary_Key_Int_Field( |
|
| 44 | - 'PRC_ID', |
|
| 45 | - 'Price ID' |
|
| 46 | - ), |
|
| 47 | - 'PRT_ID' => new EE_Foreign_Key_Int_Field( |
|
| 48 | - 'PRT_ID', |
|
| 49 | - esc_html__('Price type Id', 'event_espresso'), |
|
| 50 | - false, |
|
| 51 | - null, |
|
| 52 | - 'Price_Type' |
|
| 53 | - ), |
|
| 54 | - 'PRC_amount' => new EE_Money_Field( |
|
| 55 | - 'PRC_amount', |
|
| 56 | - esc_html__('Price Amount', 'event_espresso'), |
|
| 57 | - false, |
|
| 58 | - 0 |
|
| 59 | - ), |
|
| 60 | - 'PRC_name' => new EE_Plain_Text_Field( |
|
| 61 | - 'PRC_name', |
|
| 62 | - esc_html__('Name of Price', 'event_espresso'), |
|
| 63 | - false, |
|
| 64 | - '' |
|
| 65 | - ), |
|
| 66 | - 'PRC_desc' => new EE_Post_Content_Field( |
|
| 67 | - 'PRC_desc', |
|
| 68 | - esc_html__('Price Description', 'event_espresso'), |
|
| 69 | - false, |
|
| 70 | - '' |
|
| 71 | - ), |
|
| 72 | - 'PRC_is_default' => new EE_Boolean_Field( |
|
| 73 | - 'PRC_is_default', |
|
| 74 | - esc_html__('Flag indicating whether price is a default price', 'event_espresso'), |
|
| 75 | - false, |
|
| 76 | - false |
|
| 77 | - ), |
|
| 78 | - 'PRC_overrides' => new EE_Integer_Field( |
|
| 79 | - 'PRC_overrides', |
|
| 80 | - esc_html__( |
|
| 81 | - 'Price ID for a global Price that will be overridden by this Price ( for replacing default prices )', |
|
| 82 | - 'event_espresso' |
|
| 83 | - ), |
|
| 84 | - true, |
|
| 85 | - 0 |
|
| 86 | - ), |
|
| 87 | - 'PRC_order' => new EE_Integer_Field( |
|
| 88 | - 'PRC_order', |
|
| 89 | - esc_html__( |
|
| 90 | - 'Order of Application of Price (lower numbers apply first?)', |
|
| 91 | - 'event_espresso' |
|
| 92 | - ), |
|
| 93 | - false, |
|
| 94 | - 1 |
|
| 95 | - ), |
|
| 96 | - 'PRC_deleted' => new EE_Trashed_Flag_Field( |
|
| 97 | - 'PRC_deleted', |
|
| 98 | - esc_html__('Flag Indicating if this has been deleted or not', 'event_espresso'), |
|
| 99 | - false, |
|
| 100 | - false |
|
| 101 | - ), |
|
| 102 | - 'PRC_parent' => new EE_Integer_Field( |
|
| 103 | - 'PRC_parent', |
|
| 104 | - esc_html__('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), |
|
| 105 | - true, |
|
| 106 | - 0 |
|
| 107 | - ), |
|
| 108 | - 'PRC_wp_user' => new EE_WP_User_Field( |
|
| 109 | - 'PRC_wp_user', |
|
| 110 | - esc_html__('Price Creator ID', 'event_espresso'), |
|
| 111 | - false |
|
| 112 | - ), |
|
| 113 | - ], |
|
| 114 | - ]; |
|
| 115 | - $this->_model_relations = [ |
|
| 116 | - 'Ticket' => new EE_HABTM_Relation('Ticket_Price'), |
|
| 117 | - 'Price_Type' => new EE_Belongs_To_Relation(), |
|
| 118 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 119 | - ]; |
|
| 120 | - // this model is generally available for reading |
|
| 121 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] |
|
| 122 | - = new EE_Restriction_Generator_Default_Public( |
|
| 123 | - 'PRC_is_default', |
|
| 124 | - 'Ticket.Datetime.Event' |
|
| 125 | - ); |
|
| 126 | - // account for default tickets in the caps |
|
| 127 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] |
|
| 128 | - = new EE_Restriction_Generator_Default_Protected( |
|
| 129 | - 'PRC_is_default', |
|
| 130 | - 'Ticket.Datetime.Event' |
|
| 131 | - ); |
|
| 132 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] |
|
| 133 | - = new EE_Restriction_Generator_Default_Protected( |
|
| 134 | - 'PRC_is_default', |
|
| 135 | - 'Ticket.Datetime.Event' |
|
| 136 | - ); |
|
| 137 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] |
|
| 138 | - = new EE_Restriction_Generator_Default_Protected( |
|
| 139 | - 'PRC_is_default', |
|
| 140 | - 'Ticket.Datetime.Event' |
|
| 141 | - ); |
|
| 142 | - parent::__construct($timezone); |
|
| 143 | - } |
|
| 38 | + $this->_tables = [ |
|
| 39 | + 'Price' => new EE_Primary_Table('esp_price', 'PRC_ID'), |
|
| 40 | + ]; |
|
| 41 | + $this->_fields = [ |
|
| 42 | + 'Price' => [ |
|
| 43 | + 'PRC_ID' => new EE_Primary_Key_Int_Field( |
|
| 44 | + 'PRC_ID', |
|
| 45 | + 'Price ID' |
|
| 46 | + ), |
|
| 47 | + 'PRT_ID' => new EE_Foreign_Key_Int_Field( |
|
| 48 | + 'PRT_ID', |
|
| 49 | + esc_html__('Price type Id', 'event_espresso'), |
|
| 50 | + false, |
|
| 51 | + null, |
|
| 52 | + 'Price_Type' |
|
| 53 | + ), |
|
| 54 | + 'PRC_amount' => new EE_Money_Field( |
|
| 55 | + 'PRC_amount', |
|
| 56 | + esc_html__('Price Amount', 'event_espresso'), |
|
| 57 | + false, |
|
| 58 | + 0 |
|
| 59 | + ), |
|
| 60 | + 'PRC_name' => new EE_Plain_Text_Field( |
|
| 61 | + 'PRC_name', |
|
| 62 | + esc_html__('Name of Price', 'event_espresso'), |
|
| 63 | + false, |
|
| 64 | + '' |
|
| 65 | + ), |
|
| 66 | + 'PRC_desc' => new EE_Post_Content_Field( |
|
| 67 | + 'PRC_desc', |
|
| 68 | + esc_html__('Price Description', 'event_espresso'), |
|
| 69 | + false, |
|
| 70 | + '' |
|
| 71 | + ), |
|
| 72 | + 'PRC_is_default' => new EE_Boolean_Field( |
|
| 73 | + 'PRC_is_default', |
|
| 74 | + esc_html__('Flag indicating whether price is a default price', 'event_espresso'), |
|
| 75 | + false, |
|
| 76 | + false |
|
| 77 | + ), |
|
| 78 | + 'PRC_overrides' => new EE_Integer_Field( |
|
| 79 | + 'PRC_overrides', |
|
| 80 | + esc_html__( |
|
| 81 | + 'Price ID for a global Price that will be overridden by this Price ( for replacing default prices )', |
|
| 82 | + 'event_espresso' |
|
| 83 | + ), |
|
| 84 | + true, |
|
| 85 | + 0 |
|
| 86 | + ), |
|
| 87 | + 'PRC_order' => new EE_Integer_Field( |
|
| 88 | + 'PRC_order', |
|
| 89 | + esc_html__( |
|
| 90 | + 'Order of Application of Price (lower numbers apply first?)', |
|
| 91 | + 'event_espresso' |
|
| 92 | + ), |
|
| 93 | + false, |
|
| 94 | + 1 |
|
| 95 | + ), |
|
| 96 | + 'PRC_deleted' => new EE_Trashed_Flag_Field( |
|
| 97 | + 'PRC_deleted', |
|
| 98 | + esc_html__('Flag Indicating if this has been deleted or not', 'event_espresso'), |
|
| 99 | + false, |
|
| 100 | + false |
|
| 101 | + ), |
|
| 102 | + 'PRC_parent' => new EE_Integer_Field( |
|
| 103 | + 'PRC_parent', |
|
| 104 | + esc_html__('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), |
|
| 105 | + true, |
|
| 106 | + 0 |
|
| 107 | + ), |
|
| 108 | + 'PRC_wp_user' => new EE_WP_User_Field( |
|
| 109 | + 'PRC_wp_user', |
|
| 110 | + esc_html__('Price Creator ID', 'event_espresso'), |
|
| 111 | + false |
|
| 112 | + ), |
|
| 113 | + ], |
|
| 114 | + ]; |
|
| 115 | + $this->_model_relations = [ |
|
| 116 | + 'Ticket' => new EE_HABTM_Relation('Ticket_Price'), |
|
| 117 | + 'Price_Type' => new EE_Belongs_To_Relation(), |
|
| 118 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 119 | + ]; |
|
| 120 | + // this model is generally available for reading |
|
| 121 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] |
|
| 122 | + = new EE_Restriction_Generator_Default_Public( |
|
| 123 | + 'PRC_is_default', |
|
| 124 | + 'Ticket.Datetime.Event' |
|
| 125 | + ); |
|
| 126 | + // account for default tickets in the caps |
|
| 127 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] |
|
| 128 | + = new EE_Restriction_Generator_Default_Protected( |
|
| 129 | + 'PRC_is_default', |
|
| 130 | + 'Ticket.Datetime.Event' |
|
| 131 | + ); |
|
| 132 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] |
|
| 133 | + = new EE_Restriction_Generator_Default_Protected( |
|
| 134 | + 'PRC_is_default', |
|
| 135 | + 'Ticket.Datetime.Event' |
|
| 136 | + ); |
|
| 137 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] |
|
| 138 | + = new EE_Restriction_Generator_Default_Protected( |
|
| 139 | + 'PRC_is_default', |
|
| 140 | + 'Ticket.Datetime.Event' |
|
| 141 | + ); |
|
| 142 | + parent::__construct($timezone); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * instantiate a new price object with blank/empty properties |
|
| 148 | - * |
|
| 149 | - * @return EE_Price |
|
| 150 | - * @throws EE_Error |
|
| 151 | - * @throws ReflectionException |
|
| 152 | - */ |
|
| 153 | - public function get_new_price(): EE_Price |
|
| 154 | - { |
|
| 155 | - return $this->create_default_object(); |
|
| 156 | - } |
|
| 146 | + /** |
|
| 147 | + * instantiate a new price object with blank/empty properties |
|
| 148 | + * |
|
| 149 | + * @return EE_Price |
|
| 150 | + * @throws EE_Error |
|
| 151 | + * @throws ReflectionException |
|
| 152 | + */ |
|
| 153 | + public function get_new_price(): EE_Price |
|
| 154 | + { |
|
| 155 | + return $this->create_default_object(); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * retrieve ALL prices from db |
|
| 161 | - * |
|
| 162 | - * @return EE_Price[] |
|
| 163 | - * @throws EE_Error |
|
| 164 | - * @throws ReflectionException |
|
| 165 | - */ |
|
| 166 | - public function get_all_prices(): array |
|
| 167 | - { |
|
| 168 | - // retrieve all prices |
|
| 169 | - return $this->get_all(['order_by' => ['PRC_amount' => 'ASC']]); |
|
| 170 | - } |
|
| 159 | + /** |
|
| 160 | + * retrieve ALL prices from db |
|
| 161 | + * |
|
| 162 | + * @return EE_Price[] |
|
| 163 | + * @throws EE_Error |
|
| 164 | + * @throws ReflectionException |
|
| 165 | + */ |
|
| 166 | + public function get_all_prices(): array |
|
| 167 | + { |
|
| 168 | + // retrieve all prices |
|
| 169 | + return $this->get_all(['order_by' => ['PRC_amount' => 'ASC']]); |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | 172 | |
| 173 | - /** |
|
| 174 | - * retrieve all active prices for a particular event |
|
| 175 | - * |
|
| 176 | - * @param int $EVT_ID |
|
| 177 | - * @return array on success |
|
| 178 | - * @throws EE_Error |
|
| 179 | - * @throws ReflectionException |
|
| 180 | - */ |
|
| 181 | - public function get_all_event_prices(int $EVT_ID = 0): array |
|
| 182 | - { |
|
| 183 | - return $this->get_all( |
|
| 184 | - [ |
|
| 185 | - [ |
|
| 186 | - 'EVT_ID' => $EVT_ID, |
|
| 187 | - 'Price_Type.PBT_ID' => ['!=', EEM_Price_Type::base_type_tax], |
|
| 188 | - ], |
|
| 189 | - 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
| 190 | - ] |
|
| 191 | - ); |
|
| 192 | - } |
|
| 173 | + /** |
|
| 174 | + * retrieve all active prices for a particular event |
|
| 175 | + * |
|
| 176 | + * @param int $EVT_ID |
|
| 177 | + * @return array on success |
|
| 178 | + * @throws EE_Error |
|
| 179 | + * @throws ReflectionException |
|
| 180 | + */ |
|
| 181 | + public function get_all_event_prices(int $EVT_ID = 0): array |
|
| 182 | + { |
|
| 183 | + return $this->get_all( |
|
| 184 | + [ |
|
| 185 | + [ |
|
| 186 | + 'EVT_ID' => $EVT_ID, |
|
| 187 | + 'Price_Type.PBT_ID' => ['!=', EEM_Price_Type::base_type_tax], |
|
| 188 | + ], |
|
| 189 | + 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
| 190 | + ] |
|
| 191 | + ); |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event |
|
| 197 | - * |
|
| 198 | - * @param boolean $count return count |
|
| 199 | - * @param bool $include_taxes |
|
| 200 | - * @return int|EE_Price[] |
|
| 201 | - * @throws EE_Error |
|
| 202 | - * @throws ReflectionException |
|
| 203 | - */ |
|
| 204 | - public function get_all_default_prices(bool $count = false, bool $include_taxes = false) |
|
| 205 | - { |
|
| 206 | - $_where = [ |
|
| 207 | - 'PRC_deleted' => 0, |
|
| 208 | - 'PRC_is_default' => 1, |
|
| 209 | - ]; |
|
| 210 | - if (! $include_taxes) { |
|
| 211 | - $_where['Price_Type.PBT_ID'] = ['!=', 4]; |
|
| 212 | - } |
|
| 213 | - $_query_params = [ |
|
| 214 | - $_where, |
|
| 215 | - 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
| 216 | - ]; |
|
| 217 | - return $count ? $this->count([$_where]) : $this->get_all($_query_params); |
|
| 218 | - } |
|
| 195 | + /** |
|
| 196 | + * retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event |
|
| 197 | + * |
|
| 198 | + * @param boolean $count return count |
|
| 199 | + * @param bool $include_taxes |
|
| 200 | + * @return int|EE_Price[] |
|
| 201 | + * @throws EE_Error |
|
| 202 | + * @throws ReflectionException |
|
| 203 | + */ |
|
| 204 | + public function get_all_default_prices(bool $count = false, bool $include_taxes = false) |
|
| 205 | + { |
|
| 206 | + $_where = [ |
|
| 207 | + 'PRC_deleted' => 0, |
|
| 208 | + 'PRC_is_default' => 1, |
|
| 209 | + ]; |
|
| 210 | + if (! $include_taxes) { |
|
| 211 | + $_where['Price_Type.PBT_ID'] = ['!=', 4]; |
|
| 212 | + } |
|
| 213 | + $_query_params = [ |
|
| 214 | + $_where, |
|
| 215 | + 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
| 216 | + ]; |
|
| 217 | + return $count ? $this->count([$_where]) : $this->get_all($_query_params); |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * retrieve all active global prices that are taxes |
|
| 223 | - * |
|
| 224 | - * @return EE_Price[] |
|
| 225 | - * @throws EE_Error |
|
| 226 | - * @throws ReflectionException |
|
| 227 | - * @since $VID:$ |
|
| 228 | - */ |
|
| 229 | - public function getAllDefaultTaxes(): array |
|
| 230 | - { |
|
| 231 | - return $this->get_all( |
|
| 232 | - [ |
|
| 233 | - [ |
|
| 234 | - 'PRC_deleted' => 0, |
|
| 235 | - 'PRC_is_default' => 1, |
|
| 236 | - 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, |
|
| 237 | - ], |
|
| 238 | - 'order_by' => [ |
|
| 239 | - 'Price_Type.PRT_order' => 'ASC', |
|
| 240 | - 'PRC_order' => 'ASC', |
|
| 241 | - ], |
|
| 242 | - ] |
|
| 243 | - ); |
|
| 244 | - } |
|
| 221 | + /** |
|
| 222 | + * retrieve all active global prices that are taxes |
|
| 223 | + * |
|
| 224 | + * @return EE_Price[] |
|
| 225 | + * @throws EE_Error |
|
| 226 | + * @throws ReflectionException |
|
| 227 | + * @since $VID:$ |
|
| 228 | + */ |
|
| 229 | + public function getAllDefaultTaxes(): array |
|
| 230 | + { |
|
| 231 | + return $this->get_all( |
|
| 232 | + [ |
|
| 233 | + [ |
|
| 234 | + 'PRC_deleted' => 0, |
|
| 235 | + 'PRC_is_default' => 1, |
|
| 236 | + 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, |
|
| 237 | + ], |
|
| 238 | + 'order_by' => [ |
|
| 239 | + 'Price_Type.PRT_order' => 'ASC', |
|
| 240 | + 'PRC_order' => 'ASC', |
|
| 241 | + ], |
|
| 242 | + ] |
|
| 243 | + ); |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * retrieve all prices that are taxes |
|
| 249 | - * |
|
| 250 | - * @return EE_Price[] |
|
| 251 | - * @throws EE_Error |
|
| 252 | - * @throws InvalidArgumentException |
|
| 253 | - * @throws ReflectionException |
|
| 254 | - * @throws InvalidDataTypeException |
|
| 255 | - * @throws InvalidInterfaceException |
|
| 256 | - */ |
|
| 257 | - public function get_all_prices_that_are_taxes(): array |
|
| 258 | - { |
|
| 259 | - $taxes = []; |
|
| 260 | - $all_taxes = $this->get_all( |
|
| 261 | - [ |
|
| 262 | - ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax], |
|
| 263 | - 'order_by' => ['Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC'], |
|
| 264 | - ] |
|
| 265 | - ); |
|
| 266 | - foreach ($all_taxes as $tax) { |
|
| 267 | - if ($tax instanceof EE_Price) { |
|
| 268 | - $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - return $taxes; |
|
| 272 | - } |
|
| 247 | + /** |
|
| 248 | + * retrieve all prices that are taxes |
|
| 249 | + * |
|
| 250 | + * @return EE_Price[] |
|
| 251 | + * @throws EE_Error |
|
| 252 | + * @throws InvalidArgumentException |
|
| 253 | + * @throws ReflectionException |
|
| 254 | + * @throws InvalidDataTypeException |
|
| 255 | + * @throws InvalidInterfaceException |
|
| 256 | + */ |
|
| 257 | + public function get_all_prices_that_are_taxes(): array |
|
| 258 | + { |
|
| 259 | + $taxes = []; |
|
| 260 | + $all_taxes = $this->get_all( |
|
| 261 | + [ |
|
| 262 | + ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax], |
|
| 263 | + 'order_by' => ['Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC'], |
|
| 264 | + ] |
|
| 265 | + ); |
|
| 266 | + foreach ($all_taxes as $tax) { |
|
| 267 | + if ($tax instanceof EE_Price) { |
|
| 268 | + $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + return $taxes; |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | 274 | |
| 275 | - /** |
|
| 276 | - * retrieve all prices for an ticket plus default global prices, but not taxes |
|
| 277 | - * |
|
| 278 | - * @param int $TKT_ID the id of the event. If not included then we assume that this is a new ticket. |
|
| 279 | - * @return EE_Price[] |
|
| 280 | - * @throws EE_Error |
|
| 281 | - * @throws ReflectionException |
|
| 282 | - */ |
|
| 283 | - public function get_all_ticket_prices_for_admin(int $TKT_ID = 0): array |
|
| 284 | - { |
|
| 285 | - $array_of_price_objects = []; |
|
| 286 | - if (empty($TKT_ID)) { |
|
| 287 | - // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active |
|
| 288 | - // return that list |
|
| 289 | - $default_prices = $this->get_all_default_prices(); |
|
| 275 | + /** |
|
| 276 | + * retrieve all prices for an ticket plus default global prices, but not taxes |
|
| 277 | + * |
|
| 278 | + * @param int $TKT_ID the id of the event. If not included then we assume that this is a new ticket. |
|
| 279 | + * @return EE_Price[] |
|
| 280 | + * @throws EE_Error |
|
| 281 | + * @throws ReflectionException |
|
| 282 | + */ |
|
| 283 | + public function get_all_ticket_prices_for_admin(int $TKT_ID = 0): array |
|
| 284 | + { |
|
| 285 | + $array_of_price_objects = []; |
|
| 286 | + if (empty($TKT_ID)) { |
|
| 287 | + // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active |
|
| 288 | + // return that list |
|
| 289 | + $default_prices = $this->get_all_default_prices(); |
|
| 290 | 290 | |
| 291 | - if ($default_prices) { |
|
| 292 | - foreach ($default_prices as $price) { |
|
| 293 | - if ($price instanceof EE_Price) { |
|
| 294 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - return $array_of_price_objects; |
|
| 298 | - } |
|
| 299 | - return []; |
|
| 300 | - } |
|
| 301 | - $ticket_prices = $this->get_all( |
|
| 302 | - [ |
|
| 303 | - [ |
|
| 304 | - 'TKT_ID' => $TKT_ID, |
|
| 305 | - 'PRC_deleted' => 0, |
|
| 306 | - ], |
|
| 307 | - 'order_by' => ['PRC_order' => 'ASC'], |
|
| 308 | - ] |
|
| 309 | - ); |
|
| 291 | + if ($default_prices) { |
|
| 292 | + foreach ($default_prices as $price) { |
|
| 293 | + if ($price instanceof EE_Price) { |
|
| 294 | + $array_of_price_objects[ $price->type() ][] = $price; |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + return $array_of_price_objects; |
|
| 298 | + } |
|
| 299 | + return []; |
|
| 300 | + } |
|
| 301 | + $ticket_prices = $this->get_all( |
|
| 302 | + [ |
|
| 303 | + [ |
|
| 304 | + 'TKT_ID' => $TKT_ID, |
|
| 305 | + 'PRC_deleted' => 0, |
|
| 306 | + ], |
|
| 307 | + 'order_by' => ['PRC_order' => 'ASC'], |
|
| 308 | + ] |
|
| 309 | + ); |
|
| 310 | 310 | |
| 311 | - if (! empty($ticket_prices)) { |
|
| 312 | - foreach ($ticket_prices as $price) { |
|
| 313 | - if ($price instanceof EE_Price) { |
|
| 314 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - return $array_of_price_objects; |
|
| 319 | - } |
|
| 311 | + if (! empty($ticket_prices)) { |
|
| 312 | + foreach ($ticket_prices as $price) { |
|
| 313 | + if ($price instanceof EE_Price) { |
|
| 314 | + $array_of_price_objects[ $price->type() ][] = $price; |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + return $array_of_price_objects; |
|
| 319 | + } |
|
| 320 | 320 | |
| 321 | 321 | |
| 322 | - /** |
|
| 323 | - * _sort_event_prices_by_type |
|
| 324 | - * |
|
| 325 | - * @param EE_Price $price_a |
|
| 326 | - * @param EE_Price $price_b |
|
| 327 | - * @return int |
|
| 328 | - * @throws EE_Error |
|
| 329 | - * @throws ReflectionException |
|
| 330 | - */ |
|
| 331 | - public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b): int |
|
| 332 | - { |
|
| 333 | - if ($price_a->type_obj()->order() === $price_b->type_obj()->order()) { |
|
| 334 | - return $this->_sort_event_prices_by_order($price_a, $price_b); |
|
| 335 | - } |
|
| 336 | - return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1; |
|
| 337 | - } |
|
| 322 | + /** |
|
| 323 | + * _sort_event_prices_by_type |
|
| 324 | + * |
|
| 325 | + * @param EE_Price $price_a |
|
| 326 | + * @param EE_Price $price_b |
|
| 327 | + * @return int |
|
| 328 | + * @throws EE_Error |
|
| 329 | + * @throws ReflectionException |
|
| 330 | + */ |
|
| 331 | + public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b): int |
|
| 332 | + { |
|
| 333 | + if ($price_a->type_obj()->order() === $price_b->type_obj()->order()) { |
|
| 334 | + return $this->_sort_event_prices_by_order($price_a, $price_b); |
|
| 335 | + } |
|
| 336 | + return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | 339 | |
| 340 | - /** |
|
| 341 | - * _sort_event_prices_by_order |
|
| 342 | - * |
|
| 343 | - * @param EE_Price $price_a |
|
| 344 | - * @param EE_Price $price_b |
|
| 345 | - * @return int |
|
| 346 | - * @throws EE_Error |
|
| 347 | - * @throws ReflectionException |
|
| 348 | - */ |
|
| 349 | - public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b): int |
|
| 350 | - { |
|
| 351 | - if ($price_a->order() === $price_b->order()) { |
|
| 352 | - return 0; |
|
| 353 | - } |
|
| 354 | - return $price_a->order() < $price_b->order() ? -1 : 1; |
|
| 355 | - } |
|
| 340 | + /** |
|
| 341 | + * _sort_event_prices_by_order |
|
| 342 | + * |
|
| 343 | + * @param EE_Price $price_a |
|
| 344 | + * @param EE_Price $price_b |
|
| 345 | + * @return int |
|
| 346 | + * @throws EE_Error |
|
| 347 | + * @throws ReflectionException |
|
| 348 | + */ |
|
| 349 | + public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b): int |
|
| 350 | + { |
|
| 351 | + if ($price_a->order() === $price_b->order()) { |
|
| 352 | + return 0; |
|
| 353 | + } |
|
| 354 | + return $price_a->order() < $price_b->order() ? -1 : 1; |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | 357 | |
| 358 | - /** |
|
| 359 | - * get all prices of a specific type |
|
| 360 | - * |
|
| 361 | - * @param int $PRT_ID - PRT_ID |
|
| 362 | - * @return EE_Price[] |
|
| 363 | - * @throws EE_Error |
|
| 364 | - * @throws ReflectionException |
|
| 365 | - */ |
|
| 366 | - public function get_all_prices_that_are_type(int $PRT_ID): array |
|
| 367 | - { |
|
| 368 | - return $this->get_all( |
|
| 369 | - [ |
|
| 370 | - [ |
|
| 371 | - 'PRT_ID' => $PRT_ID, |
|
| 372 | - ], |
|
| 373 | - 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
| 374 | - ] |
|
| 375 | - ); |
|
| 376 | - } |
|
| 358 | + /** |
|
| 359 | + * get all prices of a specific type |
|
| 360 | + * |
|
| 361 | + * @param int $PRT_ID - PRT_ID |
|
| 362 | + * @return EE_Price[] |
|
| 363 | + * @throws EE_Error |
|
| 364 | + * @throws ReflectionException |
|
| 365 | + */ |
|
| 366 | + public function get_all_prices_that_are_type(int $PRT_ID): array |
|
| 367 | + { |
|
| 368 | + return $this->get_all( |
|
| 369 | + [ |
|
| 370 | + [ |
|
| 371 | + 'PRT_ID' => $PRT_ID, |
|
| 372 | + ], |
|
| 373 | + 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
| 374 | + ] |
|
| 375 | + ); |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | 378 | |
| 379 | - /** |
|
| 380 | - * Returns an array of the normal 'order_by' query parameter provided to the get_all query. |
|
| 381 | - * Of course you don't have to use it, but this is the order we usually want to sort prices by |
|
| 382 | - * |
|
| 383 | - * @return array which can be used like so: $this->get_all(array(array(...where |
|
| 384 | - * stuff...),'order_by'=>$this->_order_by_array_for_get_all_method())); |
|
| 385 | - */ |
|
| 386 | - public function _order_by_array_for_get_all_method(): array |
|
| 387 | - { |
|
| 388 | - return [ |
|
| 389 | - 'PRC_order' => 'ASC', |
|
| 390 | - 'Price_Type.PRT_order' => 'ASC', |
|
| 391 | - 'PRC_ID' => 'ASC', |
|
| 392 | - ]; |
|
| 393 | - } |
|
| 379 | + /** |
|
| 380 | + * Returns an array of the normal 'order_by' query parameter provided to the get_all query. |
|
| 381 | + * Of course you don't have to use it, but this is the order we usually want to sort prices by |
|
| 382 | + * |
|
| 383 | + * @return array which can be used like so: $this->get_all(array(array(...where |
|
| 384 | + * stuff...),'order_by'=>$this->_order_by_array_for_get_all_method())); |
|
| 385 | + */ |
|
| 386 | + public function _order_by_array_for_get_all_method(): array |
|
| 387 | + { |
|
| 388 | + return [ |
|
| 389 | + 'PRC_order' => 'ASC', |
|
| 390 | + 'Price_Type.PRT_order' => 'ASC', |
|
| 391 | + 'PRC_ID' => 'ASC', |
|
| 392 | + ]; |
|
| 393 | + } |
|
| 394 | 394 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | protected function __construct(string $timezone = '') |
| 33 | 33 | { |
| 34 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 34 | + require_once(EE_MODELS.'EEM_Price_Type.model.php'); |
|
| 35 | 35 | $this->singular_item = esc_html__('Price', 'event_espresso'); |
| 36 | 36 | $this->plural_item = esc_html__('Prices', 'event_espresso'); |
| 37 | 37 | |
@@ -118,23 +118,23 @@ discard block |
||
| 118 | 118 | 'WP_User' => new EE_Belongs_To_Relation(), |
| 119 | 119 | ]; |
| 120 | 120 | // this model is generally available for reading |
| 121 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] |
|
| 121 | + $this->_cap_restriction_generators[EEM_Base::caps_read] |
|
| 122 | 122 | = new EE_Restriction_Generator_Default_Public( |
| 123 | 123 | 'PRC_is_default', |
| 124 | 124 | 'Ticket.Datetime.Event' |
| 125 | 125 | ); |
| 126 | 126 | // account for default tickets in the caps |
| 127 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] |
|
| 127 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] |
|
| 128 | 128 | = new EE_Restriction_Generator_Default_Protected( |
| 129 | 129 | 'PRC_is_default', |
| 130 | 130 | 'Ticket.Datetime.Event' |
| 131 | 131 | ); |
| 132 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] |
|
| 132 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] |
|
| 133 | 133 | = new EE_Restriction_Generator_Default_Protected( |
| 134 | 134 | 'PRC_is_default', |
| 135 | 135 | 'Ticket.Datetime.Event' |
| 136 | 136 | ); |
| 137 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] |
|
| 137 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] |
|
| 138 | 138 | = new EE_Restriction_Generator_Default_Protected( |
| 139 | 139 | 'PRC_is_default', |
| 140 | 140 | 'Ticket.Datetime.Event' |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | 'PRC_deleted' => 0, |
| 208 | 208 | 'PRC_is_default' => 1, |
| 209 | 209 | ]; |
| 210 | - if (! $include_taxes) { |
|
| 210 | + if ( ! $include_taxes) { |
|
| 211 | 211 | $_where['Price_Type.PBT_ID'] = ['!=', 4]; |
| 212 | 212 | } |
| 213 | 213 | $_query_params = [ |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | ); |
| 266 | 266 | foreach ($all_taxes as $tax) { |
| 267 | 267 | if ($tax instanceof EE_Price) { |
| 268 | - $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
| 268 | + $taxes[$tax->order()][$tax->ID()] = $tax; |
|
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | return $taxes; |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | if ($default_prices) { |
| 292 | 292 | foreach ($default_prices as $price) { |
| 293 | 293 | if ($price instanceof EE_Price) { |
| 294 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
| 294 | + $array_of_price_objects[$price->type()][] = $price; |
|
| 295 | 295 | } |
| 296 | 296 | } |
| 297 | 297 | return $array_of_price_objects; |
@@ -308,10 +308,10 @@ discard block |
||
| 308 | 308 | ] |
| 309 | 309 | ); |
| 310 | 310 | |
| 311 | - if (! empty($ticket_prices)) { |
|
| 311 | + if ( ! empty($ticket_prices)) { |
|
| 312 | 312 | foreach ($ticket_prices as $price) { |
| 313 | 313 | if ($price instanceof EE_Price) { |
| 314 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
| 314 | + $array_of_price_objects[$price->type()][] = $price; |
|
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | } |