@@ -13,173 +13,173 @@ |
||
| 13 | 13 | class EE_Message_Template extends EE_Base_Class |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param array $props_n_values |
|
| 18 | - * @param string $timezone |
|
| 19 | - * @return EE_Message_Template|mixed |
|
| 20 | - */ |
|
| 21 | - public static function new_instance($props_n_values = array(), $timezone = '') |
|
| 22 | - { |
|
| 23 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
| 24 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @param array $props_n_values |
|
| 30 | - * @param string $timezone |
|
| 31 | - * @return EE_Message_Template |
|
| 32 | - */ |
|
| 33 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 34 | - { |
|
| 35 | - return new self($props_n_values, true, $timezone); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @param bool $GRP_ID |
|
| 41 | - * @throws EE_Error |
|
| 42 | - */ |
|
| 43 | - public function set_group_template_id($GRP_ID = false) |
|
| 44 | - { |
|
| 45 | - if (! $GRP_ID) { |
|
| 46 | - throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso')); |
|
| 47 | - } |
|
| 48 | - $this->set('GRP_ID', $GRP_ID); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * get Group ID |
|
| 54 | - * |
|
| 55 | - * @access public |
|
| 56 | - * @return int |
|
| 57 | - */ |
|
| 58 | - public function GRP_ID() |
|
| 59 | - { |
|
| 60 | - return $this->get('GRP_ID'); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * get User ID |
|
| 66 | - * |
|
| 67 | - * @access public |
|
| 68 | - * @return int |
|
| 69 | - */ |
|
| 70 | - public function user() |
|
| 71 | - { |
|
| 72 | - return $this->get_first_related('Message_Template_Group')->get('MTP_user_id'); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * get Message Messenger |
|
| 78 | - * |
|
| 79 | - * @access public |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function messenger() |
|
| 83 | - { |
|
| 84 | - return $this->get_first_related('Message_Template_Group')->messenger(); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * get Message Messenger OBJECT |
|
| 90 | - * |
|
| 91 | - * @access public |
|
| 92 | - * @return object Messenger Object for the given messenger |
|
| 93 | - */ |
|
| 94 | - public function messenger_obj() |
|
| 95 | - { |
|
| 96 | - return $this->get_first_related('Message_Template_Group')->messenger_obj(); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * get Message Type |
|
| 102 | - * |
|
| 103 | - * @access public |
|
| 104 | - * @return string |
|
| 105 | - */ |
|
| 106 | - public function message_type() |
|
| 107 | - { |
|
| 108 | - return $this->get_first_related('Message_Template_Group')->message_type(); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * get Message type OBJECT |
|
| 114 | - * |
|
| 115 | - * @access public |
|
| 116 | - * @return object Message Type object for the given message type |
|
| 117 | - */ |
|
| 118 | - public function message_type_obj() |
|
| 119 | - { |
|
| 120 | - return $this->get_first_related('Message_Template_Group')->message_type_obj(); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * This returns the set context array configured in the message type object |
|
| 126 | - * |
|
| 127 | - * @access public |
|
| 128 | - * @return array array of contexts and their configuration. |
|
| 129 | - */ |
|
| 130 | - public function contexts_config() |
|
| 131 | - { |
|
| 132 | - return $this->get_first_related('Message_Template_Group')->contexts_config(); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * This returns the context_label for contexts as set in the message type object |
|
| 138 | - * |
|
| 139 | - * @access public |
|
| 140 | - * @return string label for "context" |
|
| 141 | - */ |
|
| 142 | - public function context_label() |
|
| 143 | - { |
|
| 144 | - return $this->get_first_related('Message_Template_Group')->context_label(); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * this returns if the template group this template belongs to is global |
|
| 150 | - * |
|
| 151 | - * @return boolean true if it is, false if it isn't |
|
| 152 | - */ |
|
| 153 | - public function is_global() |
|
| 154 | - { |
|
| 155 | - return $this->get_first_related('Message_Template_Group')->is_global(); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
| 161 | - * |
|
| 162 | - * @return boolean true if it is, false if it isn't |
|
| 163 | - */ |
|
| 164 | - public function is_active() |
|
| 165 | - { |
|
| 166 | - return $this->get_first_related('Message_Template_Group')->is_active(); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
| 172 | - * this template. |
|
| 173 | - * |
|
| 174 | - * @access public |
|
| 175 | - * @param string $context what context we're going to return shortcodes for |
|
| 176 | - * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
| 177 | - * to be merged and returned. |
|
| 178 | - * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
| 179 | - * shortcodes found. |
|
| 180 | - */ |
|
| 181 | - public function get_shortcodes($context, $fields = array()) |
|
| 182 | - { |
|
| 183 | - return $this->get_first_related('Message_Template_Group')->get_shortcodes($context, $fields); |
|
| 184 | - } |
|
| 16 | + /** |
|
| 17 | + * @param array $props_n_values |
|
| 18 | + * @param string $timezone |
|
| 19 | + * @return EE_Message_Template|mixed |
|
| 20 | + */ |
|
| 21 | + public static function new_instance($props_n_values = array(), $timezone = '') |
|
| 22 | + { |
|
| 23 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
| 24 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @param array $props_n_values |
|
| 30 | + * @param string $timezone |
|
| 31 | + * @return EE_Message_Template |
|
| 32 | + */ |
|
| 33 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 34 | + { |
|
| 35 | + return new self($props_n_values, true, $timezone); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @param bool $GRP_ID |
|
| 41 | + * @throws EE_Error |
|
| 42 | + */ |
|
| 43 | + public function set_group_template_id($GRP_ID = false) |
|
| 44 | + { |
|
| 45 | + if (! $GRP_ID) { |
|
| 46 | + throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso')); |
|
| 47 | + } |
|
| 48 | + $this->set('GRP_ID', $GRP_ID); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * get Group ID |
|
| 54 | + * |
|
| 55 | + * @access public |
|
| 56 | + * @return int |
|
| 57 | + */ |
|
| 58 | + public function GRP_ID() |
|
| 59 | + { |
|
| 60 | + return $this->get('GRP_ID'); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * get User ID |
|
| 66 | + * |
|
| 67 | + * @access public |
|
| 68 | + * @return int |
|
| 69 | + */ |
|
| 70 | + public function user() |
|
| 71 | + { |
|
| 72 | + return $this->get_first_related('Message_Template_Group')->get('MTP_user_id'); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * get Message Messenger |
|
| 78 | + * |
|
| 79 | + * @access public |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function messenger() |
|
| 83 | + { |
|
| 84 | + return $this->get_first_related('Message_Template_Group')->messenger(); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * get Message Messenger OBJECT |
|
| 90 | + * |
|
| 91 | + * @access public |
|
| 92 | + * @return object Messenger Object for the given messenger |
|
| 93 | + */ |
|
| 94 | + public function messenger_obj() |
|
| 95 | + { |
|
| 96 | + return $this->get_first_related('Message_Template_Group')->messenger_obj(); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * get Message Type |
|
| 102 | + * |
|
| 103 | + * @access public |
|
| 104 | + * @return string |
|
| 105 | + */ |
|
| 106 | + public function message_type() |
|
| 107 | + { |
|
| 108 | + return $this->get_first_related('Message_Template_Group')->message_type(); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * get Message type OBJECT |
|
| 114 | + * |
|
| 115 | + * @access public |
|
| 116 | + * @return object Message Type object for the given message type |
|
| 117 | + */ |
|
| 118 | + public function message_type_obj() |
|
| 119 | + { |
|
| 120 | + return $this->get_first_related('Message_Template_Group')->message_type_obj(); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * This returns the set context array configured in the message type object |
|
| 126 | + * |
|
| 127 | + * @access public |
|
| 128 | + * @return array array of contexts and their configuration. |
|
| 129 | + */ |
|
| 130 | + public function contexts_config() |
|
| 131 | + { |
|
| 132 | + return $this->get_first_related('Message_Template_Group')->contexts_config(); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * This returns the context_label for contexts as set in the message type object |
|
| 138 | + * |
|
| 139 | + * @access public |
|
| 140 | + * @return string label for "context" |
|
| 141 | + */ |
|
| 142 | + public function context_label() |
|
| 143 | + { |
|
| 144 | + return $this->get_first_related('Message_Template_Group')->context_label(); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * this returns if the template group this template belongs to is global |
|
| 150 | + * |
|
| 151 | + * @return boolean true if it is, false if it isn't |
|
| 152 | + */ |
|
| 153 | + public function is_global() |
|
| 154 | + { |
|
| 155 | + return $this->get_first_related('Message_Template_Group')->is_global(); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
| 161 | + * |
|
| 162 | + * @return boolean true if it is, false if it isn't |
|
| 163 | + */ |
|
| 164 | + public function is_active() |
|
| 165 | + { |
|
| 166 | + return $this->get_first_related('Message_Template_Group')->is_active(); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
| 172 | + * this template. |
|
| 173 | + * |
|
| 174 | + * @access public |
|
| 175 | + * @param string $context what context we're going to return shortcodes for |
|
| 176 | + * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
| 177 | + * to be merged and returned. |
|
| 178 | + * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
| 179 | + * shortcodes found. |
|
| 180 | + */ |
|
| 181 | + public function get_shortcodes($context, $fields = array()) |
|
| 182 | + { |
|
| 183 | + return $this->get_first_related('Message_Template_Group')->get_shortcodes($context, $fields); |
|
| 184 | + } |
|
| 185 | 185 | } |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | public function set_group_template_id($GRP_ID = false) |
| 44 | 44 | { |
| 45 | - if (! $GRP_ID) { |
|
| 45 | + if ( ! $GRP_ID) { |
|
| 46 | 46 | throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso')); |
| 47 | 47 | } |
| 48 | 48 | $this->set('GRP_ID', $GRP_ID); |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | public function wp_post() |
| 41 | 41 | { |
| 42 | 42 | global $wpdb; |
| 43 | - if (! $this->_wp_post instanceof WP_Post) { |
|
| 43 | + if ( ! $this->_wp_post instanceof WP_Post) { |
|
| 44 | 44 | if ($this->ID()) { |
| 45 | 45 | $this->_wp_post = get_post($this->ID()); |
| 46 | 46 | } else { |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | // and let's make retrieving the EE CPT object easy too |
| 67 | 67 | $classname = get_class($this); |
| 68 | - if (! isset($this->_wp_post->{$classname})) { |
|
| 68 | + if ( ! isset($this->_wp_post->{$classname})) { |
|
| 69 | 69 | $this->_wp_post->{$classname} = $this; |
| 70 | 70 | } |
| 71 | 71 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | public function remove_relation_to_term_taxonomy($term_taxonomy) |
| 146 | 146 | { |
| 147 | - if (! $term_taxonomy) { |
|
| 147 | + if ( ! $term_taxonomy) { |
|
| 148 | 148 | EE_Error::add_error( |
| 149 | 149 | sprintf( |
| 150 | 150 | __( |
@@ -225,10 +225,10 @@ discard block |
||
| 225 | 225 | { |
| 226 | 226 | // first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size |
| 227 | 227 | $attr_key = is_array($attr) ? implode('_', $attr) : $attr; |
| 228 | - $cache_key = is_array($size) ? implode('_', $size) . $attr_key : $size . $attr_key; |
|
| 229 | - $this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ]) |
|
| 230 | - ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image($this->ID(), $size, $attr); |
|
| 231 | - return $this->_feature_image[ $cache_key ]; |
|
| 228 | + $cache_key = is_array($size) ? implode('_', $size).$attr_key : $size.$attr_key; |
|
| 229 | + $this->_feature_image[$cache_key] = isset($this->_feature_image[$cache_key]) |
|
| 230 | + ? $this->_feature_image[$cache_key] : $this->get_model()->get_feature_image($this->ID(), $size, $attr); |
|
| 231 | + return $this->_feature_image[$cache_key]; |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | foreach ($related_obj_names as $related_name) { |
| 296 | 296 | // related_obj_name so we're saving a revision on an object related to this object |
| 297 | 297 | // do we have $where_query params for this related object? If we do then we include that. |
| 298 | - $cols_n_values = isset($where_query[ $related_name ]) ? $where_query[ $related_name ] : array(); |
|
| 298 | + $cols_n_values = isset($where_query[$related_name]) ? $where_query[$related_name] : array(); |
|
| 299 | 299 | $where_params = ! empty($cols_n_values) ? array($cols_n_values) : array(); |
| 300 | 300 | $related_objs = $this->get_many_related($related_name, $where_params); |
| 301 | 301 | $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params); |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | */ |
| 345 | 345 | public function update_post_meta($meta_key, $meta_value, $prev_value = null) |
| 346 | 346 | { |
| 347 | - if (! $this->ID()) { |
|
| 347 | + if ( ! $this->ID()) { |
|
| 348 | 348 | $this->save(); |
| 349 | 349 | } |
| 350 | 350 | return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value); |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | */ |
| 379 | 379 | public function delete_post_meta($meta_key, $meta_value = '') |
| 380 | 380 | { |
| 381 | - if (! $this->ID()) { |
|
| 381 | + if ( ! $this->ID()) { |
|
| 382 | 382 | // there are obviously no postmetas for this if it's not saved |
| 383 | 383 | // so let's just report this as a success |
| 384 | 384 | return true; |
@@ -14,432 +14,432 @@ |
||
| 14 | 14 | abstract class EE_CPT_Base extends EE_Soft_Delete_Base_Class |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * This is a property for holding cached feature images on CPT objects. Cache's are set on the first |
|
| 19 | - * "feature_image()" method call. Each key in the array corresponds to the requested size. |
|
| 20 | - * |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - protected $_feature_image = array(); |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var WP_Post the WP_Post that corresponds with this CPT model object |
|
| 27 | - */ |
|
| 28 | - protected $_wp_post; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - abstract public function wp_user(); |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it |
|
| 36 | - * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally. |
|
| 37 | - * |
|
| 38 | - * @return WP_Post |
|
| 39 | - */ |
|
| 40 | - public function wp_post() |
|
| 41 | - { |
|
| 42 | - global $wpdb; |
|
| 43 | - if (! $this->_wp_post instanceof WP_Post) { |
|
| 44 | - if ($this->ID()) { |
|
| 45 | - $this->_wp_post = get_post($this->ID()); |
|
| 46 | - } else { |
|
| 47 | - $simulated_db_result = new stdClass(); |
|
| 48 | - foreach ($this->get_model()->field_settings(true) as $field_name => $field_obj) { |
|
| 49 | - if ( |
|
| 50 | - $this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() |
|
| 51 | - === $wpdb->posts |
|
| 52 | - ) { |
|
| 53 | - $column = $field_obj->get_table_column(); |
|
| 54 | - |
|
| 55 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
| 56 | - $value_on_model_obj = $this->get_DateTime_object($field_name); |
|
| 57 | - } elseif ($field_obj->is_db_only_field()) { |
|
| 58 | - $value_on_model_obj = $field_obj->get_default_value(); |
|
| 59 | - } else { |
|
| 60 | - $value_on_model_obj = $this->get_raw($field_name); |
|
| 61 | - } |
|
| 62 | - $simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj); |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - $this->_wp_post = new WP_Post($simulated_db_result); |
|
| 66 | - } |
|
| 67 | - // and let's make retrieving the EE CPT object easy too |
|
| 68 | - $classname = get_class($this); |
|
| 69 | - if (! isset($this->_wp_post->{$classname})) { |
|
| 70 | - $this->_wp_post->{$classname} = $this; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - return $this->_wp_post; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * When fetching a new value for a post field that uses the global $post for rendering, |
|
| 78 | - * set the global $post temporarily to be this model object; and afterwards restore it |
|
| 79 | - * |
|
| 80 | - * @param string $fieldname |
|
| 81 | - * @param bool $pretty |
|
| 82 | - * @param string $extra_cache_ref |
|
| 83 | - * @return mixed |
|
| 84 | - */ |
|
| 85 | - protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
| 86 | - { |
|
| 87 | - global $post; |
|
| 88 | - |
|
| 89 | - if ( |
|
| 90 | - $pretty |
|
| 91 | - && ( |
|
| 92 | - ! ( |
|
| 93 | - $post instanceof WP_Post |
|
| 94 | - && $post->ID |
|
| 95 | - ) |
|
| 96 | - || (int) $post->ID !== $this->ID() |
|
| 97 | - ) |
|
| 98 | - && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field |
|
| 99 | - ) { |
|
| 100 | - $old_post = $post; |
|
| 101 | - $post = $this->wp_post(); |
|
| 102 | - $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
| 103 | - $post = $old_post; |
|
| 104 | - } else { |
|
| 105 | - $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
| 106 | - } |
|
| 107 | - return $return_value; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Adds to the specified event category. If it category doesn't exist, creates it. |
|
| 112 | - * |
|
| 113 | - * @param string $category_name |
|
| 114 | - * @param string $category_description optional |
|
| 115 | - * @param int $parent_term_taxonomy_id optional |
|
| 116 | - * @return EE_Term_Taxonomy |
|
| 117 | - */ |
|
| 118 | - public function add_event_category($category_name, $category_description = null, $parent_term_taxonomy_id = null) |
|
| 119 | - { |
|
| 120 | - return $this->get_model()->add_event_category( |
|
| 121 | - $this, |
|
| 122 | - $category_name, |
|
| 123 | - $category_description, |
|
| 124 | - $parent_term_taxonomy_id |
|
| 125 | - ); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Removes the event category by specified name from being related ot this event |
|
| 131 | - * |
|
| 132 | - * @param string $category_name |
|
| 133 | - * @return bool |
|
| 134 | - */ |
|
| 135 | - public function remove_event_category($category_name) |
|
| 136 | - { |
|
| 137 | - return $this->get_model()->remove_event_category($this, $category_name); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Removes the relation to the specified term taxonomy, and maintains the |
|
| 143 | - * data integrity of the term taxonomy provided |
|
| 144 | - * |
|
| 145 | - * @param EE_Term_Taxonomy $term_taxonomy |
|
| 146 | - * @return EE_Base_Class the relation was removed from |
|
| 147 | - */ |
|
| 148 | - public function remove_relation_to_term_taxonomy($term_taxonomy) |
|
| 149 | - { |
|
| 150 | - if (! $term_taxonomy) { |
|
| 151 | - EE_Error::add_error( |
|
| 152 | - sprintf( |
|
| 153 | - __( |
|
| 154 | - "No Term_Taxonomy provided which to remove from model object of type %s and id %d", |
|
| 155 | - "event_espresso" |
|
| 156 | - ), |
|
| 157 | - get_class($this), |
|
| 158 | - $this->ID() |
|
| 159 | - ), |
|
| 160 | - __FILE__, |
|
| 161 | - __FUNCTION__, |
|
| 162 | - __LINE__ |
|
| 163 | - ); |
|
| 164 | - return null; |
|
| 165 | - } |
|
| 166 | - $term_taxonomy->set_count($term_taxonomy->count() - 1); |
|
| 167 | - $term_taxonomy->save(); |
|
| 168 | - return $this->_remove_relation_to($term_taxonomy, 'Term_Taxonomy'); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * The main purpose of this method is to return the post type for the model object |
|
| 174 | - * |
|
| 175 | - * @access public |
|
| 176 | - * @return string |
|
| 177 | - */ |
|
| 178 | - public function post_type() |
|
| 179 | - { |
|
| 180 | - return $this->get_model()->post_type(); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * The main purpose of this method is to return the parent for the model object |
|
| 186 | - * |
|
| 187 | - * @access public |
|
| 188 | - * @return int |
|
| 189 | - */ |
|
| 190 | - public function parent() |
|
| 191 | - { |
|
| 192 | - return $this->get('parent'); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * return the _status property |
|
| 198 | - * |
|
| 199 | - * @return string |
|
| 200 | - */ |
|
| 201 | - public function status() |
|
| 202 | - { |
|
| 203 | - return $this->get('status'); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * @param string $status |
|
| 209 | - */ |
|
| 210 | - public function set_status($status) |
|
| 211 | - { |
|
| 212 | - $this->set('status', $status); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * This calls the equivalent model method for retrieving the feature image which in turn is a wrapper for |
|
| 218 | - * WordPress' get_the_post_thumbnail() function. |
|
| 219 | - * |
|
| 220 | - * @link http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail |
|
| 221 | - * @access protected |
|
| 222 | - * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array |
|
| 223 | - * representing width and height in pixels (i.e. array(32,32) ). |
|
| 224 | - * @param string|array $attr Optional. Query string or array of attributes. |
|
| 225 | - * @return string HTML image element |
|
| 226 | - */ |
|
| 227 | - protected function _get_feature_image($size, $attr) |
|
| 228 | - { |
|
| 229 | - // first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size |
|
| 230 | - $attr_key = is_array($attr) ? implode('_', $attr) : $attr; |
|
| 231 | - $cache_key = is_array($size) ? implode('_', $size) . $attr_key : $size . $attr_key; |
|
| 232 | - $this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ]) |
|
| 233 | - ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image($this->ID(), $size, $attr); |
|
| 234 | - return $this->_feature_image[ $cache_key ]; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * See _get_feature_image. Returns the HTML to display a featured image |
|
| 240 | - * |
|
| 241 | - * @param string $size |
|
| 242 | - * @param string|array $attr |
|
| 243 | - * @return string of html |
|
| 244 | - */ |
|
| 245 | - public function feature_image($size = 'thumbnail', $attr = '') |
|
| 246 | - { |
|
| 247 | - return $this->_get_feature_image($size, $attr); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * This uses the wp "wp_get_attachment_image_src()" function to return the feature image for the current class |
|
| 253 | - * using the given size params. |
|
| 254 | - * |
|
| 255 | - * @param string|array $size can either be a string: 'thumbnail', 'medium', 'large', 'full' OR 2-item array |
|
| 256 | - * representing width and height in pixels eg. array(32,32). |
|
| 257 | - * @return string|boolean the url of the image or false if not found |
|
| 258 | - */ |
|
| 259 | - public function feature_image_url($size = 'thumbnail') |
|
| 260 | - { |
|
| 261 | - $attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->ID()), $size); |
|
| 262 | - return ! empty($attachment) ? $attachment[0] : false; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * This is a method for restoring this_obj using details from the given $revision_id |
|
| 268 | - * |
|
| 269 | - * @param int $revision_id ID of the revision we're getting data from |
|
| 270 | - * @param array $related_obj_names if included this will be used to restore for related obj |
|
| 271 | - * if not included then we just do restore on the meta. |
|
| 272 | - * We will accept an array of related_obj_names for restoration here. |
|
| 273 | - * @param array $where_query You can optionally include an array of key=>value pairs |
|
| 274 | - * that allow you to further constrict the relation to being added. |
|
| 275 | - * However, keep in mind that the columns (keys) given |
|
| 276 | - * must match a column on the JOIN table and currently |
|
| 277 | - * only the HABTM models accept these additional conditions. |
|
| 278 | - * Also remember that if an exact match isn't found for these extra cols/val pairs, |
|
| 279 | - * then a NEW row is created in the join table. |
|
| 280 | - * This array is INDEXED by RELATED OBJ NAME (so it corresponds with the obj_names |
|
| 281 | - * sent); |
|
| 282 | - * @return void |
|
| 283 | - */ |
|
| 284 | - public function restore_revision($revision_id, $related_obj_names = array(), $where_query = array()) |
|
| 285 | - { |
|
| 286 | - // get revision object |
|
| 287 | - $revision_obj = $this->get_model()->get_one_by_ID($revision_id); |
|
| 288 | - if ($revision_obj instanceof EE_CPT_Base) { |
|
| 289 | - // no related_obj_name so we assume we're saving a revision on this object. |
|
| 290 | - if (empty($related_obj_names)) { |
|
| 291 | - $fields = $this->get_model()->get_meta_table_fields(); |
|
| 292 | - foreach ($fields as $field) { |
|
| 293 | - $this->set($field, $revision_obj->get($field)); |
|
| 294 | - } |
|
| 295 | - $this->save(); |
|
| 296 | - } |
|
| 297 | - $related_obj_names = (array) $related_obj_names; |
|
| 298 | - foreach ($related_obj_names as $related_name) { |
|
| 299 | - // related_obj_name so we're saving a revision on an object related to this object |
|
| 300 | - // do we have $where_query params for this related object? If we do then we include that. |
|
| 301 | - $cols_n_values = isset($where_query[ $related_name ]) ? $where_query[ $related_name ] : array(); |
|
| 302 | - $where_params = ! empty($cols_n_values) ? array($cols_n_values) : array(); |
|
| 303 | - $related_objs = $this->get_many_related($related_name, $where_params); |
|
| 304 | - $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params); |
|
| 305 | - // load helper |
|
| 306 | - // remove related objs from this object that are not in revision |
|
| 307 | - // array_diff *should* work cause I think objects are indexed by ID? |
|
| 308 | - $related_to_remove = EEH_Array::object_array_diff($related_objs, $revision_related_objs); |
|
| 309 | - foreach ($related_to_remove as $rr) { |
|
| 310 | - $this->_remove_relation_to($rr, $related_name, $cols_n_values); |
|
| 311 | - } |
|
| 312 | - // add all related objs attached to revision to this object |
|
| 313 | - foreach ($revision_related_objs as $r_obj) { |
|
| 314 | - $this->_add_relation_to($r_obj, $related_name, $cols_n_values); |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Wrapper for get_post_meta, http://codex.wordpress.org/Function_Reference/get_post_meta |
|
| 323 | - * |
|
| 324 | - * @param string $meta_key |
|
| 325 | - * @param boolean $single |
|
| 326 | - * @return mixed <ul><li>If only $id is set it will return all meta values in an associative array.</li> |
|
| 327 | - * <li>If $single is set to false, or left blank, the function returns an array containing all values of the |
|
| 328 | - * specified key.</li> |
|
| 329 | - * <li>If $single is set to true, the function returns the first value of the specified key (not in an |
|
| 330 | - * array</li></ul> |
|
| 331 | - */ |
|
| 332 | - public function get_post_meta($meta_key = null, $single = false) |
|
| 333 | - { |
|
| 334 | - return get_post_meta($this->ID(), $meta_key, $single); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * Wrapper for update_post_meta, http://codex.wordpress.org/Function_Reference/update_post_meta |
|
| 340 | - * |
|
| 341 | - * @param string $meta_key |
|
| 342 | - * @param mixed $meta_value |
|
| 343 | - * @param mixed $prev_value |
|
| 344 | - * @return mixed Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure. |
|
| 345 | - * NOTE: If the meta_value passed to this function is the same as the value that is already in the |
|
| 346 | - * database, this function returns false. |
|
| 347 | - */ |
|
| 348 | - public function update_post_meta($meta_key, $meta_value, $prev_value = null) |
|
| 349 | - { |
|
| 350 | - if (! $this->ID()) { |
|
| 351 | - $this->save(); |
|
| 352 | - } |
|
| 353 | - return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Wrapper for add_post_meta, http://codex.wordpress.org/Function_Reference/add_post_meta |
|
| 359 | - * |
|
| 360 | - * @param mixed $meta_key |
|
| 361 | - * @param mixed $meta_value |
|
| 362 | - * @param bool $unique . If postmeta for this $meta_key already exists, whether to add an additional item or not |
|
| 363 | - * @return boolean Boolean true, except if the $unique argument was set to true and a custom field with the given |
|
| 364 | - * key already exists, in which case false is returned. |
|
| 365 | - */ |
|
| 366 | - public function add_post_meta($meta_key, $meta_value, $unique = false) |
|
| 367 | - { |
|
| 368 | - if ($this->ID()) { |
|
| 369 | - $this->save(); |
|
| 370 | - } |
|
| 371 | - return add_post_meta($this->ID(), $meta_key, $meta_value, $unique); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Wrapper for delete_post_meta, http://codex.wordpress.org/Function_Reference/delete_post_meta |
|
| 377 | - * |
|
| 378 | - * @param mixed $meta_key |
|
| 379 | - * @param mixed $meta_value |
|
| 380 | - * @return boolean False for failure. True for success. |
|
| 381 | - */ |
|
| 382 | - public function delete_post_meta($meta_key, $meta_value = '') |
|
| 383 | - { |
|
| 384 | - if (! $this->ID()) { |
|
| 385 | - // there are obviously no postmetas for this if it's not saved |
|
| 386 | - // so let's just report this as a success |
|
| 387 | - return true; |
|
| 388 | - } |
|
| 389 | - return delete_post_meta($this->ID(), $meta_key, $meta_value); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * Gets the URL for viewing this event on the front-end |
|
| 395 | - * |
|
| 396 | - * @return string |
|
| 397 | - */ |
|
| 398 | - public function get_permalink() |
|
| 399 | - { |
|
| 400 | - return get_permalink($this->ID()); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Gets all the term-taxonomies for this CPT |
|
| 406 | - * |
|
| 407 | - * @param array $query_params |
|
| 408 | - * @return EE_Term_Taxonomy |
|
| 409 | - */ |
|
| 410 | - public function term_taxonomies($query_params = array()) |
|
| 411 | - { |
|
| 412 | - return $this->get_many_related('Term_Taxonomy', $query_params); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * @return mixed |
|
| 418 | - */ |
|
| 419 | - public function get_custom_post_statuses() |
|
| 420 | - { |
|
| 421 | - return $this->get_model()->get_custom_post_statuses(); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * @return mixed |
|
| 427 | - */ |
|
| 428 | - public function get_all_post_statuses() |
|
| 429 | - { |
|
| 430 | - return $this->get_model()->get_status_array(); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion |
|
| 436 | - * |
|
| 437 | - * @return array |
|
| 438 | - */ |
|
| 439 | - public function __sleep() |
|
| 440 | - { |
|
| 441 | - $properties_to_serialize = parent::__sleep(); |
|
| 442 | - $properties_to_serialize = array_diff($properties_to_serialize, array('_wp_post')); |
|
| 443 | - return $properties_to_serialize; |
|
| 444 | - } |
|
| 17 | + /** |
|
| 18 | + * This is a property for holding cached feature images on CPT objects. Cache's are set on the first |
|
| 19 | + * "feature_image()" method call. Each key in the array corresponds to the requested size. |
|
| 20 | + * |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + protected $_feature_image = array(); |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var WP_Post the WP_Post that corresponds with this CPT model object |
|
| 27 | + */ |
|
| 28 | + protected $_wp_post; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + abstract public function wp_user(); |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it |
|
| 36 | + * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally. |
|
| 37 | + * |
|
| 38 | + * @return WP_Post |
|
| 39 | + */ |
|
| 40 | + public function wp_post() |
|
| 41 | + { |
|
| 42 | + global $wpdb; |
|
| 43 | + if (! $this->_wp_post instanceof WP_Post) { |
|
| 44 | + if ($this->ID()) { |
|
| 45 | + $this->_wp_post = get_post($this->ID()); |
|
| 46 | + } else { |
|
| 47 | + $simulated_db_result = new stdClass(); |
|
| 48 | + foreach ($this->get_model()->field_settings(true) as $field_name => $field_obj) { |
|
| 49 | + if ( |
|
| 50 | + $this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() |
|
| 51 | + === $wpdb->posts |
|
| 52 | + ) { |
|
| 53 | + $column = $field_obj->get_table_column(); |
|
| 54 | + |
|
| 55 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 56 | + $value_on_model_obj = $this->get_DateTime_object($field_name); |
|
| 57 | + } elseif ($field_obj->is_db_only_field()) { |
|
| 58 | + $value_on_model_obj = $field_obj->get_default_value(); |
|
| 59 | + } else { |
|
| 60 | + $value_on_model_obj = $this->get_raw($field_name); |
|
| 61 | + } |
|
| 62 | + $simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + $this->_wp_post = new WP_Post($simulated_db_result); |
|
| 66 | + } |
|
| 67 | + // and let's make retrieving the EE CPT object easy too |
|
| 68 | + $classname = get_class($this); |
|
| 69 | + if (! isset($this->_wp_post->{$classname})) { |
|
| 70 | + $this->_wp_post->{$classname} = $this; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + return $this->_wp_post; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * When fetching a new value for a post field that uses the global $post for rendering, |
|
| 78 | + * set the global $post temporarily to be this model object; and afterwards restore it |
|
| 79 | + * |
|
| 80 | + * @param string $fieldname |
|
| 81 | + * @param bool $pretty |
|
| 82 | + * @param string $extra_cache_ref |
|
| 83 | + * @return mixed |
|
| 84 | + */ |
|
| 85 | + protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
| 86 | + { |
|
| 87 | + global $post; |
|
| 88 | + |
|
| 89 | + if ( |
|
| 90 | + $pretty |
|
| 91 | + && ( |
|
| 92 | + ! ( |
|
| 93 | + $post instanceof WP_Post |
|
| 94 | + && $post->ID |
|
| 95 | + ) |
|
| 96 | + || (int) $post->ID !== $this->ID() |
|
| 97 | + ) |
|
| 98 | + && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field |
|
| 99 | + ) { |
|
| 100 | + $old_post = $post; |
|
| 101 | + $post = $this->wp_post(); |
|
| 102 | + $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
| 103 | + $post = $old_post; |
|
| 104 | + } else { |
|
| 105 | + $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
| 106 | + } |
|
| 107 | + return $return_value; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Adds to the specified event category. If it category doesn't exist, creates it. |
|
| 112 | + * |
|
| 113 | + * @param string $category_name |
|
| 114 | + * @param string $category_description optional |
|
| 115 | + * @param int $parent_term_taxonomy_id optional |
|
| 116 | + * @return EE_Term_Taxonomy |
|
| 117 | + */ |
|
| 118 | + public function add_event_category($category_name, $category_description = null, $parent_term_taxonomy_id = null) |
|
| 119 | + { |
|
| 120 | + return $this->get_model()->add_event_category( |
|
| 121 | + $this, |
|
| 122 | + $category_name, |
|
| 123 | + $category_description, |
|
| 124 | + $parent_term_taxonomy_id |
|
| 125 | + ); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Removes the event category by specified name from being related ot this event |
|
| 131 | + * |
|
| 132 | + * @param string $category_name |
|
| 133 | + * @return bool |
|
| 134 | + */ |
|
| 135 | + public function remove_event_category($category_name) |
|
| 136 | + { |
|
| 137 | + return $this->get_model()->remove_event_category($this, $category_name); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Removes the relation to the specified term taxonomy, and maintains the |
|
| 143 | + * data integrity of the term taxonomy provided |
|
| 144 | + * |
|
| 145 | + * @param EE_Term_Taxonomy $term_taxonomy |
|
| 146 | + * @return EE_Base_Class the relation was removed from |
|
| 147 | + */ |
|
| 148 | + public function remove_relation_to_term_taxonomy($term_taxonomy) |
|
| 149 | + { |
|
| 150 | + if (! $term_taxonomy) { |
|
| 151 | + EE_Error::add_error( |
|
| 152 | + sprintf( |
|
| 153 | + __( |
|
| 154 | + "No Term_Taxonomy provided which to remove from model object of type %s and id %d", |
|
| 155 | + "event_espresso" |
|
| 156 | + ), |
|
| 157 | + get_class($this), |
|
| 158 | + $this->ID() |
|
| 159 | + ), |
|
| 160 | + __FILE__, |
|
| 161 | + __FUNCTION__, |
|
| 162 | + __LINE__ |
|
| 163 | + ); |
|
| 164 | + return null; |
|
| 165 | + } |
|
| 166 | + $term_taxonomy->set_count($term_taxonomy->count() - 1); |
|
| 167 | + $term_taxonomy->save(); |
|
| 168 | + return $this->_remove_relation_to($term_taxonomy, 'Term_Taxonomy'); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * The main purpose of this method is to return the post type for the model object |
|
| 174 | + * |
|
| 175 | + * @access public |
|
| 176 | + * @return string |
|
| 177 | + */ |
|
| 178 | + public function post_type() |
|
| 179 | + { |
|
| 180 | + return $this->get_model()->post_type(); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * The main purpose of this method is to return the parent for the model object |
|
| 186 | + * |
|
| 187 | + * @access public |
|
| 188 | + * @return int |
|
| 189 | + */ |
|
| 190 | + public function parent() |
|
| 191 | + { |
|
| 192 | + return $this->get('parent'); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * return the _status property |
|
| 198 | + * |
|
| 199 | + * @return string |
|
| 200 | + */ |
|
| 201 | + public function status() |
|
| 202 | + { |
|
| 203 | + return $this->get('status'); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * @param string $status |
|
| 209 | + */ |
|
| 210 | + public function set_status($status) |
|
| 211 | + { |
|
| 212 | + $this->set('status', $status); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * This calls the equivalent model method for retrieving the feature image which in turn is a wrapper for |
|
| 218 | + * WordPress' get_the_post_thumbnail() function. |
|
| 219 | + * |
|
| 220 | + * @link http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail |
|
| 221 | + * @access protected |
|
| 222 | + * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array |
|
| 223 | + * representing width and height in pixels (i.e. array(32,32) ). |
|
| 224 | + * @param string|array $attr Optional. Query string or array of attributes. |
|
| 225 | + * @return string HTML image element |
|
| 226 | + */ |
|
| 227 | + protected function _get_feature_image($size, $attr) |
|
| 228 | + { |
|
| 229 | + // first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size |
|
| 230 | + $attr_key = is_array($attr) ? implode('_', $attr) : $attr; |
|
| 231 | + $cache_key = is_array($size) ? implode('_', $size) . $attr_key : $size . $attr_key; |
|
| 232 | + $this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ]) |
|
| 233 | + ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image($this->ID(), $size, $attr); |
|
| 234 | + return $this->_feature_image[ $cache_key ]; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * See _get_feature_image. Returns the HTML to display a featured image |
|
| 240 | + * |
|
| 241 | + * @param string $size |
|
| 242 | + * @param string|array $attr |
|
| 243 | + * @return string of html |
|
| 244 | + */ |
|
| 245 | + public function feature_image($size = 'thumbnail', $attr = '') |
|
| 246 | + { |
|
| 247 | + return $this->_get_feature_image($size, $attr); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * This uses the wp "wp_get_attachment_image_src()" function to return the feature image for the current class |
|
| 253 | + * using the given size params. |
|
| 254 | + * |
|
| 255 | + * @param string|array $size can either be a string: 'thumbnail', 'medium', 'large', 'full' OR 2-item array |
|
| 256 | + * representing width and height in pixels eg. array(32,32). |
|
| 257 | + * @return string|boolean the url of the image or false if not found |
|
| 258 | + */ |
|
| 259 | + public function feature_image_url($size = 'thumbnail') |
|
| 260 | + { |
|
| 261 | + $attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->ID()), $size); |
|
| 262 | + return ! empty($attachment) ? $attachment[0] : false; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * This is a method for restoring this_obj using details from the given $revision_id |
|
| 268 | + * |
|
| 269 | + * @param int $revision_id ID of the revision we're getting data from |
|
| 270 | + * @param array $related_obj_names if included this will be used to restore for related obj |
|
| 271 | + * if not included then we just do restore on the meta. |
|
| 272 | + * We will accept an array of related_obj_names for restoration here. |
|
| 273 | + * @param array $where_query You can optionally include an array of key=>value pairs |
|
| 274 | + * that allow you to further constrict the relation to being added. |
|
| 275 | + * However, keep in mind that the columns (keys) given |
|
| 276 | + * must match a column on the JOIN table and currently |
|
| 277 | + * only the HABTM models accept these additional conditions. |
|
| 278 | + * Also remember that if an exact match isn't found for these extra cols/val pairs, |
|
| 279 | + * then a NEW row is created in the join table. |
|
| 280 | + * This array is INDEXED by RELATED OBJ NAME (so it corresponds with the obj_names |
|
| 281 | + * sent); |
|
| 282 | + * @return void |
|
| 283 | + */ |
|
| 284 | + public function restore_revision($revision_id, $related_obj_names = array(), $where_query = array()) |
|
| 285 | + { |
|
| 286 | + // get revision object |
|
| 287 | + $revision_obj = $this->get_model()->get_one_by_ID($revision_id); |
|
| 288 | + if ($revision_obj instanceof EE_CPT_Base) { |
|
| 289 | + // no related_obj_name so we assume we're saving a revision on this object. |
|
| 290 | + if (empty($related_obj_names)) { |
|
| 291 | + $fields = $this->get_model()->get_meta_table_fields(); |
|
| 292 | + foreach ($fields as $field) { |
|
| 293 | + $this->set($field, $revision_obj->get($field)); |
|
| 294 | + } |
|
| 295 | + $this->save(); |
|
| 296 | + } |
|
| 297 | + $related_obj_names = (array) $related_obj_names; |
|
| 298 | + foreach ($related_obj_names as $related_name) { |
|
| 299 | + // related_obj_name so we're saving a revision on an object related to this object |
|
| 300 | + // do we have $where_query params for this related object? If we do then we include that. |
|
| 301 | + $cols_n_values = isset($where_query[ $related_name ]) ? $where_query[ $related_name ] : array(); |
|
| 302 | + $where_params = ! empty($cols_n_values) ? array($cols_n_values) : array(); |
|
| 303 | + $related_objs = $this->get_many_related($related_name, $where_params); |
|
| 304 | + $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params); |
|
| 305 | + // load helper |
|
| 306 | + // remove related objs from this object that are not in revision |
|
| 307 | + // array_diff *should* work cause I think objects are indexed by ID? |
|
| 308 | + $related_to_remove = EEH_Array::object_array_diff($related_objs, $revision_related_objs); |
|
| 309 | + foreach ($related_to_remove as $rr) { |
|
| 310 | + $this->_remove_relation_to($rr, $related_name, $cols_n_values); |
|
| 311 | + } |
|
| 312 | + // add all related objs attached to revision to this object |
|
| 313 | + foreach ($revision_related_objs as $r_obj) { |
|
| 314 | + $this->_add_relation_to($r_obj, $related_name, $cols_n_values); |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Wrapper for get_post_meta, http://codex.wordpress.org/Function_Reference/get_post_meta |
|
| 323 | + * |
|
| 324 | + * @param string $meta_key |
|
| 325 | + * @param boolean $single |
|
| 326 | + * @return mixed <ul><li>If only $id is set it will return all meta values in an associative array.</li> |
|
| 327 | + * <li>If $single is set to false, or left blank, the function returns an array containing all values of the |
|
| 328 | + * specified key.</li> |
|
| 329 | + * <li>If $single is set to true, the function returns the first value of the specified key (not in an |
|
| 330 | + * array</li></ul> |
|
| 331 | + */ |
|
| 332 | + public function get_post_meta($meta_key = null, $single = false) |
|
| 333 | + { |
|
| 334 | + return get_post_meta($this->ID(), $meta_key, $single); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * Wrapper for update_post_meta, http://codex.wordpress.org/Function_Reference/update_post_meta |
|
| 340 | + * |
|
| 341 | + * @param string $meta_key |
|
| 342 | + * @param mixed $meta_value |
|
| 343 | + * @param mixed $prev_value |
|
| 344 | + * @return mixed Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure. |
|
| 345 | + * NOTE: If the meta_value passed to this function is the same as the value that is already in the |
|
| 346 | + * database, this function returns false. |
|
| 347 | + */ |
|
| 348 | + public function update_post_meta($meta_key, $meta_value, $prev_value = null) |
|
| 349 | + { |
|
| 350 | + if (! $this->ID()) { |
|
| 351 | + $this->save(); |
|
| 352 | + } |
|
| 353 | + return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Wrapper for add_post_meta, http://codex.wordpress.org/Function_Reference/add_post_meta |
|
| 359 | + * |
|
| 360 | + * @param mixed $meta_key |
|
| 361 | + * @param mixed $meta_value |
|
| 362 | + * @param bool $unique . If postmeta for this $meta_key already exists, whether to add an additional item or not |
|
| 363 | + * @return boolean Boolean true, except if the $unique argument was set to true and a custom field with the given |
|
| 364 | + * key already exists, in which case false is returned. |
|
| 365 | + */ |
|
| 366 | + public function add_post_meta($meta_key, $meta_value, $unique = false) |
|
| 367 | + { |
|
| 368 | + if ($this->ID()) { |
|
| 369 | + $this->save(); |
|
| 370 | + } |
|
| 371 | + return add_post_meta($this->ID(), $meta_key, $meta_value, $unique); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Wrapper for delete_post_meta, http://codex.wordpress.org/Function_Reference/delete_post_meta |
|
| 377 | + * |
|
| 378 | + * @param mixed $meta_key |
|
| 379 | + * @param mixed $meta_value |
|
| 380 | + * @return boolean False for failure. True for success. |
|
| 381 | + */ |
|
| 382 | + public function delete_post_meta($meta_key, $meta_value = '') |
|
| 383 | + { |
|
| 384 | + if (! $this->ID()) { |
|
| 385 | + // there are obviously no postmetas for this if it's not saved |
|
| 386 | + // so let's just report this as a success |
|
| 387 | + return true; |
|
| 388 | + } |
|
| 389 | + return delete_post_meta($this->ID(), $meta_key, $meta_value); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * Gets the URL for viewing this event on the front-end |
|
| 395 | + * |
|
| 396 | + * @return string |
|
| 397 | + */ |
|
| 398 | + public function get_permalink() |
|
| 399 | + { |
|
| 400 | + return get_permalink($this->ID()); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Gets all the term-taxonomies for this CPT |
|
| 406 | + * |
|
| 407 | + * @param array $query_params |
|
| 408 | + * @return EE_Term_Taxonomy |
|
| 409 | + */ |
|
| 410 | + public function term_taxonomies($query_params = array()) |
|
| 411 | + { |
|
| 412 | + return $this->get_many_related('Term_Taxonomy', $query_params); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * @return mixed |
|
| 418 | + */ |
|
| 419 | + public function get_custom_post_statuses() |
|
| 420 | + { |
|
| 421 | + return $this->get_model()->get_custom_post_statuses(); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * @return mixed |
|
| 427 | + */ |
|
| 428 | + public function get_all_post_statuses() |
|
| 429 | + { |
|
| 430 | + return $this->get_model()->get_status_array(); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion |
|
| 436 | + * |
|
| 437 | + * @return array |
|
| 438 | + */ |
|
| 439 | + public function __sleep() |
|
| 440 | + { |
|
| 441 | + $properties_to_serialize = parent::__sleep(); |
|
| 442 | + $properties_to_serialize = array_diff($properties_to_serialize, array('_wp_post')); |
|
| 443 | + return $properties_to_serialize; |
|
| 444 | + } |
|
| 445 | 445 | } |
@@ -11,25 +11,25 @@ |
||
| 11 | 11 | class EE_Ticket_Price extends EE_Base_Class |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @param array $props_n_values |
|
| 16 | - * @param string $timezone |
|
| 17 | - * @return EE_Ticket_Price|mixed |
|
| 18 | - */ |
|
| 19 | - public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
| 20 | - { |
|
| 21 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 22 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 23 | - } |
|
| 14 | + /** |
|
| 15 | + * @param array $props_n_values |
|
| 16 | + * @param string $timezone |
|
| 17 | + * @return EE_Ticket_Price|mixed |
|
| 18 | + */ |
|
| 19 | + public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
| 20 | + { |
|
| 21 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 22 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @param array $props_n_values |
|
| 28 | - * @param string $timezone |
|
| 29 | - * @return EE_Ticket_Price |
|
| 30 | - */ |
|
| 31 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 32 | - { |
|
| 33 | - return new self($props_n_values, true, $timezone); |
|
| 34 | - } |
|
| 26 | + /** |
|
| 27 | + * @param array $props_n_values |
|
| 28 | + * @param string $timezone |
|
| 29 | + * @return EE_Ticket_Price |
|
| 30 | + */ |
|
| 31 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 32 | + { |
|
| 33 | + return new self($props_n_values, true, $timezone); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -12,25 +12,25 @@ |
||
| 12 | 12 | class EE_Ticket_Template extends EE_Base_Class |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @param array $props_n_values |
|
| 17 | - * @param string $timezone |
|
| 18 | - * @return EE_Ticket_Template|mixed |
|
| 19 | - */ |
|
| 20 | - public static function new_instance($props_n_values = array(), $timezone = '') |
|
| 21 | - { |
|
| 22 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
| 23 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
| 24 | - } |
|
| 15 | + /** |
|
| 16 | + * @param array $props_n_values |
|
| 17 | + * @param string $timezone |
|
| 18 | + * @return EE_Ticket_Template|mixed |
|
| 19 | + */ |
|
| 20 | + public static function new_instance($props_n_values = array(), $timezone = '') |
|
| 21 | + { |
|
| 22 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
| 23 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @param array $props_n_values |
|
| 29 | - * @param string $timezone |
|
| 30 | - * @return EE_Ticket_Template |
|
| 31 | - */ |
|
| 32 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 33 | - { |
|
| 34 | - return new self($props_n_values, true, $timezone); |
|
| 35 | - } |
|
| 27 | + /** |
|
| 28 | + * @param array $props_n_values |
|
| 29 | + * @param string $timezone |
|
| 30 | + * @return EE_Ticket_Template |
|
| 31 | + */ |
|
| 32 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 33 | + { |
|
| 34 | + return new self($props_n_values, true, $timezone); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -10,115 +10,115 @@ |
||
| 10 | 10 | class EE_Extra_Meta extends EE_Base_Class |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param array $props_n_values |
|
| 15 | - * @return EE_Extra_Meta|mixed |
|
| 16 | - */ |
|
| 17 | - public static function new_instance($props_n_values = array()) |
|
| 18 | - { |
|
| 19 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 20 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @param array $props_n_values |
|
| 26 | - * @return EE_Extra_Meta |
|
| 27 | - */ |
|
| 28 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 29 | - { |
|
| 30 | - return new self($props_n_values, true); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Gets FK_ID |
|
| 36 | - * |
|
| 37 | - * @return int |
|
| 38 | - */ |
|
| 39 | - public function FK_ID() |
|
| 40 | - { |
|
| 41 | - return $this->get('FK_ID'); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Sets FK_ID |
|
| 47 | - * |
|
| 48 | - * @param int $FK_ID |
|
| 49 | - * @return boolean |
|
| 50 | - */ |
|
| 51 | - public function set_FK_ID($FK_ID) |
|
| 52 | - { |
|
| 53 | - $this->set('FK_ID', $FK_ID); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Gets model |
|
| 59 | - * |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public function model() |
|
| 63 | - { |
|
| 64 | - return $this->get('EXM_model'); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Sets model |
|
| 70 | - * |
|
| 71 | - * @param string $model |
|
| 72 | - * @return boolean |
|
| 73 | - */ |
|
| 74 | - public function set_model($model) |
|
| 75 | - { |
|
| 76 | - $this->set('EXM_model', $model); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Gets key |
|
| 82 | - * |
|
| 83 | - * @return string |
|
| 84 | - */ |
|
| 85 | - public function key() |
|
| 86 | - { |
|
| 87 | - return $this->get('EXM_key'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Sets key |
|
| 93 | - * |
|
| 94 | - * @param string $key |
|
| 95 | - * @return boolean |
|
| 96 | - */ |
|
| 97 | - public function set_key($key) |
|
| 98 | - { |
|
| 99 | - $this->set('EXM_key', $key); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Gets value |
|
| 105 | - * |
|
| 106 | - * @return string |
|
| 107 | - */ |
|
| 108 | - public function value() |
|
| 109 | - { |
|
| 110 | - return $this->get('EXM_value'); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Sets value |
|
| 116 | - * |
|
| 117 | - * @param string $value |
|
| 118 | - * @return boolean |
|
| 119 | - */ |
|
| 120 | - public function set_value($value) |
|
| 121 | - { |
|
| 122 | - $this->set('EXM_value', $value); |
|
| 123 | - } |
|
| 13 | + /** |
|
| 14 | + * @param array $props_n_values |
|
| 15 | + * @return EE_Extra_Meta|mixed |
|
| 16 | + */ |
|
| 17 | + public static function new_instance($props_n_values = array()) |
|
| 18 | + { |
|
| 19 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 20 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @param array $props_n_values |
|
| 26 | + * @return EE_Extra_Meta |
|
| 27 | + */ |
|
| 28 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 29 | + { |
|
| 30 | + return new self($props_n_values, true); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Gets FK_ID |
|
| 36 | + * |
|
| 37 | + * @return int |
|
| 38 | + */ |
|
| 39 | + public function FK_ID() |
|
| 40 | + { |
|
| 41 | + return $this->get('FK_ID'); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Sets FK_ID |
|
| 47 | + * |
|
| 48 | + * @param int $FK_ID |
|
| 49 | + * @return boolean |
|
| 50 | + */ |
|
| 51 | + public function set_FK_ID($FK_ID) |
|
| 52 | + { |
|
| 53 | + $this->set('FK_ID', $FK_ID); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Gets model |
|
| 59 | + * |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public function model() |
|
| 63 | + { |
|
| 64 | + return $this->get('EXM_model'); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Sets model |
|
| 70 | + * |
|
| 71 | + * @param string $model |
|
| 72 | + * @return boolean |
|
| 73 | + */ |
|
| 74 | + public function set_model($model) |
|
| 75 | + { |
|
| 76 | + $this->set('EXM_model', $model); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Gets key |
|
| 82 | + * |
|
| 83 | + * @return string |
|
| 84 | + */ |
|
| 85 | + public function key() |
|
| 86 | + { |
|
| 87 | + return $this->get('EXM_key'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Sets key |
|
| 93 | + * |
|
| 94 | + * @param string $key |
|
| 95 | + * @return boolean |
|
| 96 | + */ |
|
| 97 | + public function set_key($key) |
|
| 98 | + { |
|
| 99 | + $this->set('EXM_key', $key); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Gets value |
|
| 105 | + * |
|
| 106 | + * @return string |
|
| 107 | + */ |
|
| 108 | + public function value() |
|
| 109 | + { |
|
| 110 | + return $this->get('EXM_value'); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Sets value |
|
| 116 | + * |
|
| 117 | + * @param string $value |
|
| 118 | + * @return boolean |
|
| 119 | + */ |
|
| 120 | + public function set_value($value) |
|
| 121 | + { |
|
| 122 | + $this->set('EXM_value', $value); |
|
| 123 | + } |
|
| 124 | 124 | } |
@@ -10,112 +10,112 @@ |
||
| 10 | 10 | class EE_Post_Meta extends EE_Base_Class |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param array $props_n_values |
|
| 15 | - * @return EE_Post_Meta|mixed |
|
| 16 | - */ |
|
| 17 | - public static function new_instance($props_n_values = array()) |
|
| 18 | - { |
|
| 19 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 20 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @param array $props_n_values |
|
| 26 | - * @return EE_Post_Meta |
|
| 27 | - */ |
|
| 28 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 29 | - { |
|
| 30 | - return new self($props_n_values, true); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Gets meta_id |
|
| 36 | - * |
|
| 37 | - * @return int |
|
| 38 | - */ |
|
| 39 | - public function meta_id() |
|
| 40 | - { |
|
| 41 | - return $this->get('meta_id'); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Sets meta_id |
|
| 47 | - * |
|
| 48 | - * @param int $meta_id |
|
| 49 | - * @return boolean |
|
| 50 | - */ |
|
| 51 | - public function set_meta_id($meta_id) |
|
| 52 | - { |
|
| 53 | - return $this->set('meta_id', $meta_id); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Gets post_id |
|
| 58 | - * |
|
| 59 | - * @return int |
|
| 60 | - */ |
|
| 61 | - public function post_id() |
|
| 62 | - { |
|
| 63 | - return $this->get('post_id'); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Sets post_id |
|
| 69 | - * |
|
| 70 | - * @param int $post_id |
|
| 71 | - * @return boolean |
|
| 72 | - */ |
|
| 73 | - public function set_post_id($post_id) |
|
| 74 | - { |
|
| 75 | - return $this->set('post_id', $post_id); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Gets meta_key |
|
| 80 | - * |
|
| 81 | - * @return string |
|
| 82 | - */ |
|
| 83 | - public function meta_key() |
|
| 84 | - { |
|
| 85 | - return $this->get('meta_key'); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Sets meta_key |
|
| 91 | - * |
|
| 92 | - * @param string $meta_key |
|
| 93 | - * @return boolean |
|
| 94 | - */ |
|
| 95 | - public function set_meta_key($meta_key) |
|
| 96 | - { |
|
| 97 | - return $this->set('meta_key', $meta_key); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Gets meta_value |
|
| 102 | - * |
|
| 103 | - * @return mixed |
|
| 104 | - */ |
|
| 105 | - public function meta_value() |
|
| 106 | - { |
|
| 107 | - return $this->get('meta_value'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Sets meta_value |
|
| 113 | - * |
|
| 114 | - * @param mixed $meta_value |
|
| 115 | - * @return boolean |
|
| 116 | - */ |
|
| 117 | - public function set_meta_value($meta_value) |
|
| 118 | - { |
|
| 119 | - return $this->set('meta_value', $meta_value); |
|
| 120 | - } |
|
| 13 | + /** |
|
| 14 | + * @param array $props_n_values |
|
| 15 | + * @return EE_Post_Meta|mixed |
|
| 16 | + */ |
|
| 17 | + public static function new_instance($props_n_values = array()) |
|
| 18 | + { |
|
| 19 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 20 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @param array $props_n_values |
|
| 26 | + * @return EE_Post_Meta |
|
| 27 | + */ |
|
| 28 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 29 | + { |
|
| 30 | + return new self($props_n_values, true); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Gets meta_id |
|
| 36 | + * |
|
| 37 | + * @return int |
|
| 38 | + */ |
|
| 39 | + public function meta_id() |
|
| 40 | + { |
|
| 41 | + return $this->get('meta_id'); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Sets meta_id |
|
| 47 | + * |
|
| 48 | + * @param int $meta_id |
|
| 49 | + * @return boolean |
|
| 50 | + */ |
|
| 51 | + public function set_meta_id($meta_id) |
|
| 52 | + { |
|
| 53 | + return $this->set('meta_id', $meta_id); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Gets post_id |
|
| 58 | + * |
|
| 59 | + * @return int |
|
| 60 | + */ |
|
| 61 | + public function post_id() |
|
| 62 | + { |
|
| 63 | + return $this->get('post_id'); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Sets post_id |
|
| 69 | + * |
|
| 70 | + * @param int $post_id |
|
| 71 | + * @return boolean |
|
| 72 | + */ |
|
| 73 | + public function set_post_id($post_id) |
|
| 74 | + { |
|
| 75 | + return $this->set('post_id', $post_id); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Gets meta_key |
|
| 80 | + * |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 83 | + public function meta_key() |
|
| 84 | + { |
|
| 85 | + return $this->get('meta_key'); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Sets meta_key |
|
| 91 | + * |
|
| 92 | + * @param string $meta_key |
|
| 93 | + * @return boolean |
|
| 94 | + */ |
|
| 95 | + public function set_meta_key($meta_key) |
|
| 96 | + { |
|
| 97 | + return $this->set('meta_key', $meta_key); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Gets meta_value |
|
| 102 | + * |
|
| 103 | + * @return mixed |
|
| 104 | + */ |
|
| 105 | + public function meta_value() |
|
| 106 | + { |
|
| 107 | + return $this->get('meta_value'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Sets meta_value |
|
| 113 | + * |
|
| 114 | + * @param mixed $meta_value |
|
| 115 | + * @return boolean |
|
| 116 | + */ |
|
| 117 | + public function set_meta_value($meta_value) |
|
| 118 | + { |
|
| 119 | + return $this->set('meta_value', $meta_value); |
|
| 120 | + } |
|
| 121 | 121 | } |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | public function options($notDeletedOptionsOnly = true, $selected_value_to_always_include = null) |
| 337 | 337 | { |
| 338 | - if (! $this->ID()) { |
|
| 338 | + if ( ! $this->ID()) { |
|
| 339 | 339 | return array(); |
| 340 | 340 | } |
| 341 | 341 | $query_params = array(); |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | ), |
| 510 | 510 | $input_constructor_args |
| 511 | 511 | ); |
| 512 | - if (! $answer instanceof EE_Answer && $registration instanceof EE_Registration) { |
|
| 512 | + if ( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration) { |
|
| 513 | 513 | $answer = EEM_Answer::instance()->get_registration_question_answer_object($registration, $this->ID()); |
| 514 | 514 | } |
| 515 | 515 | // has this question been answered ? |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | $this, |
| 648 | 648 | $input_constructor_args |
| 649 | 649 | ); |
| 650 | - if (! $default_input) { |
|
| 650 | + if ( ! $default_input) { |
|
| 651 | 651 | $default_input = new EE_Text_Input($input_constructor_args); |
| 652 | 652 | } |
| 653 | 653 | $result = $default_input; |
@@ -14,668 +14,668 @@ |
||
| 14 | 14 | class EE_Question extends EE_Soft_Delete_Base_Class implements EEI_Duplicatable |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * |
|
| 19 | - * @param array $props_n_values incoming values |
|
| 20 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 21 | - * used.) |
|
| 22 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 23 | - * date_format and the second value is the time format |
|
| 24 | - * @return EE_Question |
|
| 25 | - */ |
|
| 26 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 27 | - { |
|
| 28 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 29 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @param array $props_n_values incoming values from the database |
|
| 35 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 36 | - * the website will be used. |
|
| 37 | - * @return EE_Question |
|
| 38 | - */ |
|
| 39 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 40 | - { |
|
| 41 | - return new self($props_n_values, true, $timezone); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Set Question display text |
|
| 47 | - * |
|
| 48 | - * @access public |
|
| 49 | - * @param string $QST_display_text |
|
| 50 | - */ |
|
| 51 | - public function set_display_text($QST_display_text = '') |
|
| 52 | - { |
|
| 53 | - $this->set('QST_display_text', $QST_display_text); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Set Question admin text |
|
| 59 | - * |
|
| 60 | - * @access public |
|
| 61 | - * @param string $QST_admin_label |
|
| 62 | - */ |
|
| 63 | - public function set_admin_label($QST_admin_label = '') |
|
| 64 | - { |
|
| 65 | - $this->set('QST_admin_label', $QST_admin_label); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Set system name |
|
| 71 | - * |
|
| 72 | - * @access public |
|
| 73 | - * @param mixed $QST_system |
|
| 74 | - */ |
|
| 75 | - public function set_system_ID($QST_system = '') |
|
| 76 | - { |
|
| 77 | - $this->set('QST_system', $QST_system); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Set question's type |
|
| 83 | - * |
|
| 84 | - * @access public |
|
| 85 | - * @param string $QST_type |
|
| 86 | - */ |
|
| 87 | - public function set_question_type($QST_type = '') |
|
| 88 | - { |
|
| 89 | - $this->set('QST_type', $QST_type); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Sets whether this question must be answered when presented in a form |
|
| 95 | - * |
|
| 96 | - * @access public |
|
| 97 | - * @param bool $QST_required |
|
| 98 | - */ |
|
| 99 | - public function set_required($QST_required = false) |
|
| 100 | - { |
|
| 101 | - $this->set('QST_required', $QST_required); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Set Question display text |
|
| 107 | - * |
|
| 108 | - * @access public |
|
| 109 | - * @param string $QST_required_text |
|
| 110 | - */ |
|
| 111 | - public function set_required_text($QST_required_text = '') |
|
| 112 | - { |
|
| 113 | - $this->set('QST_required_text', $QST_required_text); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Sets the order of this question when placed in a sequence of questions |
|
| 119 | - * |
|
| 120 | - * @access public |
|
| 121 | - * @param int $QST_order |
|
| 122 | - */ |
|
| 123 | - public function set_order($QST_order = 0) |
|
| 124 | - { |
|
| 125 | - $this->set('QST_order', $QST_order); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Sets whether the question is admin-only |
|
| 131 | - * |
|
| 132 | - * @access public |
|
| 133 | - * @param bool $QST_admin_only |
|
| 134 | - */ |
|
| 135 | - public function set_admin_only($QST_admin_only = false) |
|
| 136 | - { |
|
| 137 | - $this->set('QST_admin_only', $QST_admin_only); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Sets the wordpress user ID on the question |
|
| 143 | - * |
|
| 144 | - * @access public |
|
| 145 | - * @param int $QST_wp_user |
|
| 146 | - */ |
|
| 147 | - public function set_wp_user($QST_wp_user = 1) |
|
| 148 | - { |
|
| 149 | - $this->set('QST_wp_user', $QST_wp_user); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Sets whether the question has been deleted |
|
| 155 | - * (we use this boolean instead of actually |
|
| 156 | - * deleting it because when users delete this question |
|
| 157 | - * they really want to remove the question from future |
|
| 158 | - * forms, BUT keep their old answers which depend |
|
| 159 | - * on this record actually existing. |
|
| 160 | - * |
|
| 161 | - * @access public |
|
| 162 | - * @param bool $QST_deleted |
|
| 163 | - */ |
|
| 164 | - public function set_deleted($QST_deleted = false) |
|
| 165 | - { |
|
| 166 | - $this->set('QST_deleted', $QST_deleted); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * returns the text for displaying the question to users |
|
| 172 | - * |
|
| 173 | - * @access public |
|
| 174 | - * @return string |
|
| 175 | - */ |
|
| 176 | - public function display_text() |
|
| 177 | - { |
|
| 178 | - return $this->get('QST_display_text'); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * returns the text for the administrative label |
|
| 184 | - * |
|
| 185 | - * @access public |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 188 | - public function admin_label() |
|
| 189 | - { |
|
| 190 | - return $this->get('QST_admin_label'); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * returns the attendee column name for this question |
|
| 196 | - * |
|
| 197 | - * @access public |
|
| 198 | - * @return string |
|
| 199 | - */ |
|
| 200 | - public function system_ID() |
|
| 201 | - { |
|
| 202 | - return $this->get('QST_system'); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * returns either a string of 'text', 'textfield', etc. |
|
| 208 | - * |
|
| 209 | - * @access public |
|
| 210 | - * @return boolean |
|
| 211 | - */ |
|
| 212 | - public function required() |
|
| 213 | - { |
|
| 214 | - return $this->get('QST_required'); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * returns the text which should be displayed when a user |
|
| 220 | - * doesn't answer this question in a form |
|
| 221 | - * |
|
| 222 | - * @access public |
|
| 223 | - * @return string |
|
| 224 | - */ |
|
| 225 | - public function required_text() |
|
| 226 | - { |
|
| 227 | - return $this->get('QST_required_text'); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * returns the type of this question |
|
| 233 | - * |
|
| 234 | - * @access public |
|
| 235 | - * @return string |
|
| 236 | - */ |
|
| 237 | - public function type() |
|
| 238 | - { |
|
| 239 | - return $this->get('QST_type'); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * returns an integer showing where this question should |
|
| 245 | - * be placed in a sequence of questions |
|
| 246 | - * |
|
| 247 | - * @access public |
|
| 248 | - * @return int |
|
| 249 | - */ |
|
| 250 | - public function order() |
|
| 251 | - { |
|
| 252 | - return $this->get('QST_order'); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * returns whether this question should only appears to admins, |
|
| 258 | - * or to everyone |
|
| 259 | - * |
|
| 260 | - * @access public |
|
| 261 | - * @return boolean |
|
| 262 | - */ |
|
| 263 | - public function admin_only() |
|
| 264 | - { |
|
| 265 | - return $this->get('QST_admin_only'); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * returns the id the wordpress user who created this question |
|
| 271 | - * |
|
| 272 | - * @access public |
|
| 273 | - * @return int |
|
| 274 | - */ |
|
| 275 | - public function wp_user() |
|
| 276 | - { |
|
| 277 | - return $this->get('QST_wp_user'); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * returns whether this question has been marked as 'deleted' |
|
| 283 | - * |
|
| 284 | - * @access public |
|
| 285 | - * @return boolean |
|
| 286 | - */ |
|
| 287 | - public function deleted() |
|
| 288 | - { |
|
| 289 | - return $this->get('QST_deleted'); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Gets an array of related EE_Answer to this EE_Question |
|
| 295 | - * |
|
| 296 | - * @return EE_Answer[] |
|
| 297 | - */ |
|
| 298 | - public function answers() |
|
| 299 | - { |
|
| 300 | - return $this->get_many_related('Answer'); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Boolean check for if there are answers on this question in th db |
|
| 306 | - * |
|
| 307 | - * @return boolean true = has answers, false = no answers. |
|
| 308 | - */ |
|
| 309 | - public function has_answers() |
|
| 310 | - { |
|
| 311 | - return $this->count_related('Answer') > 0 ? true : false; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * gets an array of EE_Question_Group which relate to this question |
|
| 317 | - * |
|
| 318 | - * @return EE_Question_Group[] |
|
| 319 | - */ |
|
| 320 | - public function question_groups() |
|
| 321 | - { |
|
| 322 | - return $this->get_many_related('Question_Group'); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Returns all the options for this question. By default, it returns only the not-yet-deleted ones. |
|
| 328 | - * |
|
| 329 | - * @param boolean $notDeletedOptionsOnly 1 |
|
| 330 | - * whether to return ALL options, or only the ones which have |
|
| 331 | - * not yet been deleleted |
|
| 332 | - * @param string|array $selected_value_to_always_include , when retrieving options to an ANSWERED question, |
|
| 333 | - * we want to usually only show non-deleted options AND the |
|
| 334 | - * value that was selected for the answer, whether it was |
|
| 335 | - * trashed or not. |
|
| 336 | - * @return EE_Question_Option[] |
|
| 337 | - */ |
|
| 338 | - public function options($notDeletedOptionsOnly = true, $selected_value_to_always_include = null) |
|
| 339 | - { |
|
| 340 | - if (! $this->ID()) { |
|
| 341 | - return array(); |
|
| 342 | - } |
|
| 343 | - $query_params = array(); |
|
| 344 | - if ($selected_value_to_always_include) { |
|
| 345 | - if (is_array($selected_value_to_always_include)) { |
|
| 346 | - $query_params[0]['OR*options-query']['QSO_value'] = array('IN', $selected_value_to_always_include); |
|
| 347 | - } else { |
|
| 348 | - $query_params[0]['OR*options-query']['QSO_value'] = $selected_value_to_always_include; |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - if ($notDeletedOptionsOnly) { |
|
| 352 | - $query_params[0]['OR*options-query']['QSO_deleted'] = false; |
|
| 353 | - } |
|
| 354 | - // order by QSO_order |
|
| 355 | - $query_params['order_by'] = array('QSO_order' => 'ASC'); |
|
| 356 | - return $this->get_many_related('Question_Option', $query_params); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * returns an array of EE_Question_Options which relate to this question |
|
| 362 | - * |
|
| 363 | - * @return \EE_Question_Option[] |
|
| 364 | - */ |
|
| 365 | - public function temp_options() |
|
| 366 | - { |
|
| 367 | - return $this->_model_relations['Question_Option']; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Adds an option for this question. Note: if the option were previously associated with a different |
|
| 373 | - * Question, that relationship will be overwritten. |
|
| 374 | - * |
|
| 375 | - * @param EE_Question_Option $option |
|
| 376 | - * @return boolean success |
|
| 377 | - */ |
|
| 378 | - public function add_option(EE_Question_Option $option) |
|
| 379 | - { |
|
| 380 | - return $this->_add_relation_to($option, 'Question_Option'); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Adds an option directly to this question without saving to the db |
|
| 386 | - * |
|
| 387 | - * @param EE_Question_Option $option |
|
| 388 | - * @return boolean success |
|
| 389 | - */ |
|
| 390 | - public function add_temp_option(EE_Question_Option $option) |
|
| 391 | - { |
|
| 392 | - $this->_model_relations['Question_Option'][] = $option; |
|
| 393 | - return true; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Marks the option as deleted. |
|
| 399 | - * |
|
| 400 | - * @param EE_Question_Option $option |
|
| 401 | - * @return boolean success |
|
| 402 | - */ |
|
| 403 | - public function remove_option(EE_Question_Option $option) |
|
| 404 | - { |
|
| 405 | - return $this->_remove_relation_to($option, 'Question_Option'); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * @return bool |
|
| 411 | - */ |
|
| 412 | - public function is_system_question() |
|
| 413 | - { |
|
| 414 | - $system_ID = $this->get('QST_system'); |
|
| 415 | - return ! empty($system_ID) ? true : false; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * The purpose of this method is set the question order this question order to be the max out of all questions |
|
| 421 | - * |
|
| 422 | - * @access public |
|
| 423 | - * @return void |
|
| 424 | - */ |
|
| 425 | - public function set_order_to_latest() |
|
| 426 | - { |
|
| 427 | - $latest_order = $this->get_model()->get_latest_question_order(); |
|
| 428 | - $latest_order++; |
|
| 429 | - $this->set('QST_order', $latest_order); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Retrieves the list of allowed question types from the model. |
|
| 435 | - * |
|
| 436 | - * @return string[] |
|
| 437 | - */ |
|
| 438 | - private function _allowed_question_types() |
|
| 439 | - { |
|
| 440 | - $questionModel = $this->get_model(); |
|
| 441 | - /* @var $questionModel EEM_Question */ |
|
| 442 | - return $questionModel->allowed_question_types(); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * Duplicates this question and its question options |
|
| 447 | - * |
|
| 448 | - * @return \EE_Question |
|
| 449 | - */ |
|
| 450 | - public function duplicate($options = array()) |
|
| 451 | - { |
|
| 452 | - $new_question = clone $this; |
|
| 453 | - $new_question->set('QST_ID', null); |
|
| 454 | - $new_question->set_display_text(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->display_text())); |
|
| 455 | - $new_question->set_admin_label(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->admin_label())); |
|
| 456 | - $new_question->set_system_ID(null); |
|
| 457 | - $new_question->set_wp_user(get_current_user_id()); |
|
| 458 | - // if we're duplicating a trashed question, assume we don't want the new one to be trashed |
|
| 459 | - $new_question->set_deleted(false); |
|
| 460 | - $success = $new_question->save(); |
|
| 461 | - if ($success) { |
|
| 462 | - // we don't totally want to duplicate the question options, because we want them to be for the NEW question |
|
| 463 | - foreach ($this->options() as $question_option) { |
|
| 464 | - $question_option->duplicate(array('QST_ID' => $new_question->ID())); |
|
| 465 | - } |
|
| 466 | - return $new_question; |
|
| 467 | - } else { |
|
| 468 | - return null; |
|
| 469 | - } |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * Returns the question's maximum allowed response size |
|
| 474 | - * |
|
| 475 | - * @return int|float |
|
| 476 | - */ |
|
| 477 | - public function max() |
|
| 478 | - { |
|
| 479 | - return $this->get('QST_max'); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * Sets the question's maximum allowed response size |
|
| 484 | - * |
|
| 485 | - * @param int|float $new_max |
|
| 486 | - * @return void |
|
| 487 | - */ |
|
| 488 | - public function set_max($new_max) |
|
| 489 | - { |
|
| 490 | - $this->set('QST_max', $new_max); |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * Creates a form input from this question which can be used in HTML forms |
|
| 496 | - * |
|
| 497 | - * @param EE_Registration $registration |
|
| 498 | - * @param EE_Answer $answer |
|
| 499 | - * @param array $input_constructor_args |
|
| 500 | - * @return EE_Form_Input_Base |
|
| 501 | - */ |
|
| 502 | - public function generate_form_input($registration = null, $answer = null, $input_constructor_args = array()) |
|
| 503 | - { |
|
| 504 | - $identifier = $this->is_system_question() ? $this->system_ID() : $this->ID(); |
|
| 505 | - |
|
| 506 | - $input_constructor_args = array_merge( |
|
| 507 | - array( |
|
| 508 | - 'required' => $this->required() ? true : false, |
|
| 509 | - 'html_label_text' => $this->display_text(), |
|
| 510 | - 'required_validation_error_message' => $this->required_text(), |
|
| 511 | - ), |
|
| 512 | - $input_constructor_args |
|
| 513 | - ); |
|
| 514 | - if (! $answer instanceof EE_Answer && $registration instanceof EE_Registration) { |
|
| 515 | - $answer = EEM_Answer::instance()->get_registration_question_answer_object($registration, $this->ID()); |
|
| 516 | - } |
|
| 517 | - // has this question been answered ? |
|
| 518 | - if ( |
|
| 519 | - $answer instanceof EE_Answer |
|
| 520 | - && $answer->value() !== '' |
|
| 521 | - ) { |
|
| 522 | - // answer gets htmlspecialchars called on it, undo that please |
|
| 523 | - // because the form input's display strategy may call esc_attr too |
|
| 524 | - // which also does html special characters |
|
| 525 | - $values_with_html_special_chars = $answer->value(); |
|
| 526 | - if (is_array($values_with_html_special_chars)) { |
|
| 527 | - $default_value = array_map('htmlspecialchars_decode', $values_with_html_special_chars); |
|
| 528 | - } else { |
|
| 529 | - $default_value = htmlspecialchars_decode($values_with_html_special_chars); |
|
| 530 | - } |
|
| 531 | - $input_constructor_args['default'] = $default_value; |
|
| 532 | - } |
|
| 533 | - $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID()); |
|
| 534 | - if ( |
|
| 535 | - in_array( |
|
| 536 | - $this->type(), |
|
| 537 | - EEM_Question::instance()->questionTypesWithMaxLength(), |
|
| 538 | - true |
|
| 539 | - ) |
|
| 540 | - ) { |
|
| 541 | - $input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy( |
|
| 542 | - null, |
|
| 543 | - min($max_max_for_question, $this->max()) |
|
| 544 | - ); |
|
| 545 | - } |
|
| 546 | - $input_constructor_args = apply_filters( |
|
| 547 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__input_constructor_args', |
|
| 548 | - $input_constructor_args, |
|
| 549 | - $registration, |
|
| 550 | - $this, |
|
| 551 | - $answer |
|
| 552 | - ); |
|
| 553 | - |
|
| 554 | - $result = null; |
|
| 555 | - switch ($this->type()) { |
|
| 556 | - // Text |
|
| 557 | - case EEM_Question::QST_type_text: |
|
| 558 | - $result = new EE_Text_Input($input_constructor_args); |
|
| 559 | - break; |
|
| 560 | - // Textarea |
|
| 561 | - case EEM_Question::QST_type_textarea: |
|
| 562 | - $result = new EE_Text_Area_Input($input_constructor_args); |
|
| 563 | - break; |
|
| 564 | - // Radio Buttons |
|
| 565 | - case EEM_Question::QST_type_radio: |
|
| 566 | - $result = new EE_Radio_Button_Input($this->options(), $input_constructor_args); |
|
| 567 | - break; |
|
| 568 | - // Dropdown |
|
| 569 | - case EEM_Question::QST_type_dropdown: |
|
| 570 | - $result = new EE_Select_Input($this->options(), $input_constructor_args); |
|
| 571 | - break; |
|
| 572 | - // State Dropdown |
|
| 573 | - case EEM_Question::QST_type_state: |
|
| 574 | - $state_options = apply_filters( |
|
| 575 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
| 576 | - null, |
|
| 577 | - $this, |
|
| 578 | - $registration, |
|
| 579 | - $answer |
|
| 580 | - ); |
|
| 581 | - $result = new EE_State_Select_Input($state_options, $input_constructor_args); |
|
| 582 | - break; |
|
| 583 | - // Country Dropdown |
|
| 584 | - case EEM_Question::QST_type_country: |
|
| 585 | - $country_options = apply_filters( |
|
| 586 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
| 587 | - null, |
|
| 588 | - $this, |
|
| 589 | - $registration, |
|
| 590 | - $answer |
|
| 591 | - ); |
|
| 592 | - $result = new EE_Country_Select_Input($country_options, $input_constructor_args); |
|
| 593 | - break; |
|
| 594 | - // Checkboxes |
|
| 595 | - case EEM_Question::QST_type_checkbox: |
|
| 596 | - $result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args); |
|
| 597 | - break; |
|
| 598 | - // Date |
|
| 599 | - case EEM_Question::QST_type_date: |
|
| 600 | - $result = new EE_Datepicker_Input($input_constructor_args); |
|
| 601 | - break; |
|
| 602 | - case EEM_Question::QST_type_html_textarea: |
|
| 603 | - $input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy(); |
|
| 604 | - $result = new EE_Text_Area_Input($input_constructor_args); |
|
| 605 | - $result->remove_validation_strategy('EE_Plaintext_Validation_Strategy'); |
|
| 606 | - break; |
|
| 607 | - case EEM_Question::QST_type_email: |
|
| 608 | - $result = new EE_Email_Input($input_constructor_args); |
|
| 609 | - break; |
|
| 610 | - // Email confirm |
|
| 611 | - case EEM_Question::QST_type_email_confirm: |
|
| 612 | - $result = new EE_Email_Confirm_Input($input_constructor_args); |
|
| 613 | - break; |
|
| 614 | - case EEM_Question::QST_type_us_phone: |
|
| 615 | - $result = new EE_Phone_Input($input_constructor_args); |
|
| 616 | - break; |
|
| 617 | - case EEM_Question::QST_type_int: |
|
| 618 | - $result = new EE_Integer_Input($input_constructor_args); |
|
| 619 | - break; |
|
| 620 | - case EEM_Question::QST_type_decimal: |
|
| 621 | - $result = new EE_Float_Input($input_constructor_args); |
|
| 622 | - break; |
|
| 623 | - case EEM_Question::QST_type_url: |
|
| 624 | - $input_constructor_args['validation_strategies'][] = LoaderFactory::getLoader()->getNew('EE_URL_Validation_Strategy'); |
|
| 625 | - $result = new EE_Text_Input($input_constructor_args); |
|
| 626 | - break; |
|
| 627 | - case EEM_Question::QST_type_year: |
|
| 628 | - $result = new EE_Year_Input( |
|
| 629 | - $input_constructor_args, |
|
| 630 | - apply_filters( |
|
| 631 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', |
|
| 632 | - true, |
|
| 633 | - $this |
|
| 634 | - ), |
|
| 635 | - apply_filters( |
|
| 636 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', |
|
| 637 | - 100, |
|
| 638 | - $this |
|
| 639 | - ), |
|
| 640 | - apply_filters( |
|
| 641 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', |
|
| 642 | - 100, |
|
| 643 | - $this |
|
| 644 | - ) |
|
| 645 | - ); |
|
| 646 | - break; |
|
| 647 | - case EEM_Question::QST_type_multi_select: |
|
| 648 | - $result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args); |
|
| 649 | - break; |
|
| 650 | - // fallback |
|
| 651 | - default: |
|
| 652 | - $default_input = apply_filters( |
|
| 653 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__default', |
|
| 654 | - null, |
|
| 655 | - $this->type(), |
|
| 656 | - $this, |
|
| 657 | - $input_constructor_args |
|
| 658 | - ); |
|
| 659 | - if (! $default_input) { |
|
| 660 | - $default_input = new EE_Text_Input($input_constructor_args); |
|
| 661 | - } |
|
| 662 | - $result = $default_input; |
|
| 663 | - } |
|
| 664 | - return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer); |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - |
|
| 668 | - /** |
|
| 669 | - * Returns whether or not this question type should have question option entries |
|
| 670 | - * |
|
| 671 | - * @return bool |
|
| 672 | - */ |
|
| 673 | - public function should_have_question_options() |
|
| 674 | - { |
|
| 675 | - return in_array( |
|
| 676 | - $this->type(), |
|
| 677 | - $this->_model->question_types_with_options(), |
|
| 678 | - true |
|
| 679 | - ); |
|
| 680 | - } |
|
| 17 | + /** |
|
| 18 | + * |
|
| 19 | + * @param array $props_n_values incoming values |
|
| 20 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 21 | + * used.) |
|
| 22 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 23 | + * date_format and the second value is the time format |
|
| 24 | + * @return EE_Question |
|
| 25 | + */ |
|
| 26 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 27 | + { |
|
| 28 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 29 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @param array $props_n_values incoming values from the database |
|
| 35 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 36 | + * the website will be used. |
|
| 37 | + * @return EE_Question |
|
| 38 | + */ |
|
| 39 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 40 | + { |
|
| 41 | + return new self($props_n_values, true, $timezone); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Set Question display text |
|
| 47 | + * |
|
| 48 | + * @access public |
|
| 49 | + * @param string $QST_display_text |
|
| 50 | + */ |
|
| 51 | + public function set_display_text($QST_display_text = '') |
|
| 52 | + { |
|
| 53 | + $this->set('QST_display_text', $QST_display_text); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Set Question admin text |
|
| 59 | + * |
|
| 60 | + * @access public |
|
| 61 | + * @param string $QST_admin_label |
|
| 62 | + */ |
|
| 63 | + public function set_admin_label($QST_admin_label = '') |
|
| 64 | + { |
|
| 65 | + $this->set('QST_admin_label', $QST_admin_label); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Set system name |
|
| 71 | + * |
|
| 72 | + * @access public |
|
| 73 | + * @param mixed $QST_system |
|
| 74 | + */ |
|
| 75 | + public function set_system_ID($QST_system = '') |
|
| 76 | + { |
|
| 77 | + $this->set('QST_system', $QST_system); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Set question's type |
|
| 83 | + * |
|
| 84 | + * @access public |
|
| 85 | + * @param string $QST_type |
|
| 86 | + */ |
|
| 87 | + public function set_question_type($QST_type = '') |
|
| 88 | + { |
|
| 89 | + $this->set('QST_type', $QST_type); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Sets whether this question must be answered when presented in a form |
|
| 95 | + * |
|
| 96 | + * @access public |
|
| 97 | + * @param bool $QST_required |
|
| 98 | + */ |
|
| 99 | + public function set_required($QST_required = false) |
|
| 100 | + { |
|
| 101 | + $this->set('QST_required', $QST_required); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Set Question display text |
|
| 107 | + * |
|
| 108 | + * @access public |
|
| 109 | + * @param string $QST_required_text |
|
| 110 | + */ |
|
| 111 | + public function set_required_text($QST_required_text = '') |
|
| 112 | + { |
|
| 113 | + $this->set('QST_required_text', $QST_required_text); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Sets the order of this question when placed in a sequence of questions |
|
| 119 | + * |
|
| 120 | + * @access public |
|
| 121 | + * @param int $QST_order |
|
| 122 | + */ |
|
| 123 | + public function set_order($QST_order = 0) |
|
| 124 | + { |
|
| 125 | + $this->set('QST_order', $QST_order); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Sets whether the question is admin-only |
|
| 131 | + * |
|
| 132 | + * @access public |
|
| 133 | + * @param bool $QST_admin_only |
|
| 134 | + */ |
|
| 135 | + public function set_admin_only($QST_admin_only = false) |
|
| 136 | + { |
|
| 137 | + $this->set('QST_admin_only', $QST_admin_only); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Sets the wordpress user ID on the question |
|
| 143 | + * |
|
| 144 | + * @access public |
|
| 145 | + * @param int $QST_wp_user |
|
| 146 | + */ |
|
| 147 | + public function set_wp_user($QST_wp_user = 1) |
|
| 148 | + { |
|
| 149 | + $this->set('QST_wp_user', $QST_wp_user); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Sets whether the question has been deleted |
|
| 155 | + * (we use this boolean instead of actually |
|
| 156 | + * deleting it because when users delete this question |
|
| 157 | + * they really want to remove the question from future |
|
| 158 | + * forms, BUT keep their old answers which depend |
|
| 159 | + * on this record actually existing. |
|
| 160 | + * |
|
| 161 | + * @access public |
|
| 162 | + * @param bool $QST_deleted |
|
| 163 | + */ |
|
| 164 | + public function set_deleted($QST_deleted = false) |
|
| 165 | + { |
|
| 166 | + $this->set('QST_deleted', $QST_deleted); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * returns the text for displaying the question to users |
|
| 172 | + * |
|
| 173 | + * @access public |
|
| 174 | + * @return string |
|
| 175 | + */ |
|
| 176 | + public function display_text() |
|
| 177 | + { |
|
| 178 | + return $this->get('QST_display_text'); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * returns the text for the administrative label |
|
| 184 | + * |
|
| 185 | + * @access public |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | + public function admin_label() |
|
| 189 | + { |
|
| 190 | + return $this->get('QST_admin_label'); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * returns the attendee column name for this question |
|
| 196 | + * |
|
| 197 | + * @access public |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 200 | + public function system_ID() |
|
| 201 | + { |
|
| 202 | + return $this->get('QST_system'); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * returns either a string of 'text', 'textfield', etc. |
|
| 208 | + * |
|
| 209 | + * @access public |
|
| 210 | + * @return boolean |
|
| 211 | + */ |
|
| 212 | + public function required() |
|
| 213 | + { |
|
| 214 | + return $this->get('QST_required'); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * returns the text which should be displayed when a user |
|
| 220 | + * doesn't answer this question in a form |
|
| 221 | + * |
|
| 222 | + * @access public |
|
| 223 | + * @return string |
|
| 224 | + */ |
|
| 225 | + public function required_text() |
|
| 226 | + { |
|
| 227 | + return $this->get('QST_required_text'); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * returns the type of this question |
|
| 233 | + * |
|
| 234 | + * @access public |
|
| 235 | + * @return string |
|
| 236 | + */ |
|
| 237 | + public function type() |
|
| 238 | + { |
|
| 239 | + return $this->get('QST_type'); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * returns an integer showing where this question should |
|
| 245 | + * be placed in a sequence of questions |
|
| 246 | + * |
|
| 247 | + * @access public |
|
| 248 | + * @return int |
|
| 249 | + */ |
|
| 250 | + public function order() |
|
| 251 | + { |
|
| 252 | + return $this->get('QST_order'); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * returns whether this question should only appears to admins, |
|
| 258 | + * or to everyone |
|
| 259 | + * |
|
| 260 | + * @access public |
|
| 261 | + * @return boolean |
|
| 262 | + */ |
|
| 263 | + public function admin_only() |
|
| 264 | + { |
|
| 265 | + return $this->get('QST_admin_only'); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * returns the id the wordpress user who created this question |
|
| 271 | + * |
|
| 272 | + * @access public |
|
| 273 | + * @return int |
|
| 274 | + */ |
|
| 275 | + public function wp_user() |
|
| 276 | + { |
|
| 277 | + return $this->get('QST_wp_user'); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * returns whether this question has been marked as 'deleted' |
|
| 283 | + * |
|
| 284 | + * @access public |
|
| 285 | + * @return boolean |
|
| 286 | + */ |
|
| 287 | + public function deleted() |
|
| 288 | + { |
|
| 289 | + return $this->get('QST_deleted'); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Gets an array of related EE_Answer to this EE_Question |
|
| 295 | + * |
|
| 296 | + * @return EE_Answer[] |
|
| 297 | + */ |
|
| 298 | + public function answers() |
|
| 299 | + { |
|
| 300 | + return $this->get_many_related('Answer'); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Boolean check for if there are answers on this question in th db |
|
| 306 | + * |
|
| 307 | + * @return boolean true = has answers, false = no answers. |
|
| 308 | + */ |
|
| 309 | + public function has_answers() |
|
| 310 | + { |
|
| 311 | + return $this->count_related('Answer') > 0 ? true : false; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * gets an array of EE_Question_Group which relate to this question |
|
| 317 | + * |
|
| 318 | + * @return EE_Question_Group[] |
|
| 319 | + */ |
|
| 320 | + public function question_groups() |
|
| 321 | + { |
|
| 322 | + return $this->get_many_related('Question_Group'); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Returns all the options for this question. By default, it returns only the not-yet-deleted ones. |
|
| 328 | + * |
|
| 329 | + * @param boolean $notDeletedOptionsOnly 1 |
|
| 330 | + * whether to return ALL options, or only the ones which have |
|
| 331 | + * not yet been deleleted |
|
| 332 | + * @param string|array $selected_value_to_always_include , when retrieving options to an ANSWERED question, |
|
| 333 | + * we want to usually only show non-deleted options AND the |
|
| 334 | + * value that was selected for the answer, whether it was |
|
| 335 | + * trashed or not. |
|
| 336 | + * @return EE_Question_Option[] |
|
| 337 | + */ |
|
| 338 | + public function options($notDeletedOptionsOnly = true, $selected_value_to_always_include = null) |
|
| 339 | + { |
|
| 340 | + if (! $this->ID()) { |
|
| 341 | + return array(); |
|
| 342 | + } |
|
| 343 | + $query_params = array(); |
|
| 344 | + if ($selected_value_to_always_include) { |
|
| 345 | + if (is_array($selected_value_to_always_include)) { |
|
| 346 | + $query_params[0]['OR*options-query']['QSO_value'] = array('IN', $selected_value_to_always_include); |
|
| 347 | + } else { |
|
| 348 | + $query_params[0]['OR*options-query']['QSO_value'] = $selected_value_to_always_include; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + if ($notDeletedOptionsOnly) { |
|
| 352 | + $query_params[0]['OR*options-query']['QSO_deleted'] = false; |
|
| 353 | + } |
|
| 354 | + // order by QSO_order |
|
| 355 | + $query_params['order_by'] = array('QSO_order' => 'ASC'); |
|
| 356 | + return $this->get_many_related('Question_Option', $query_params); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * returns an array of EE_Question_Options which relate to this question |
|
| 362 | + * |
|
| 363 | + * @return \EE_Question_Option[] |
|
| 364 | + */ |
|
| 365 | + public function temp_options() |
|
| 366 | + { |
|
| 367 | + return $this->_model_relations['Question_Option']; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Adds an option for this question. Note: if the option were previously associated with a different |
|
| 373 | + * Question, that relationship will be overwritten. |
|
| 374 | + * |
|
| 375 | + * @param EE_Question_Option $option |
|
| 376 | + * @return boolean success |
|
| 377 | + */ |
|
| 378 | + public function add_option(EE_Question_Option $option) |
|
| 379 | + { |
|
| 380 | + return $this->_add_relation_to($option, 'Question_Option'); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Adds an option directly to this question without saving to the db |
|
| 386 | + * |
|
| 387 | + * @param EE_Question_Option $option |
|
| 388 | + * @return boolean success |
|
| 389 | + */ |
|
| 390 | + public function add_temp_option(EE_Question_Option $option) |
|
| 391 | + { |
|
| 392 | + $this->_model_relations['Question_Option'][] = $option; |
|
| 393 | + return true; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Marks the option as deleted. |
|
| 399 | + * |
|
| 400 | + * @param EE_Question_Option $option |
|
| 401 | + * @return boolean success |
|
| 402 | + */ |
|
| 403 | + public function remove_option(EE_Question_Option $option) |
|
| 404 | + { |
|
| 405 | + return $this->_remove_relation_to($option, 'Question_Option'); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * @return bool |
|
| 411 | + */ |
|
| 412 | + public function is_system_question() |
|
| 413 | + { |
|
| 414 | + $system_ID = $this->get('QST_system'); |
|
| 415 | + return ! empty($system_ID) ? true : false; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * The purpose of this method is set the question order this question order to be the max out of all questions |
|
| 421 | + * |
|
| 422 | + * @access public |
|
| 423 | + * @return void |
|
| 424 | + */ |
|
| 425 | + public function set_order_to_latest() |
|
| 426 | + { |
|
| 427 | + $latest_order = $this->get_model()->get_latest_question_order(); |
|
| 428 | + $latest_order++; |
|
| 429 | + $this->set('QST_order', $latest_order); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Retrieves the list of allowed question types from the model. |
|
| 435 | + * |
|
| 436 | + * @return string[] |
|
| 437 | + */ |
|
| 438 | + private function _allowed_question_types() |
|
| 439 | + { |
|
| 440 | + $questionModel = $this->get_model(); |
|
| 441 | + /* @var $questionModel EEM_Question */ |
|
| 442 | + return $questionModel->allowed_question_types(); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * Duplicates this question and its question options |
|
| 447 | + * |
|
| 448 | + * @return \EE_Question |
|
| 449 | + */ |
|
| 450 | + public function duplicate($options = array()) |
|
| 451 | + { |
|
| 452 | + $new_question = clone $this; |
|
| 453 | + $new_question->set('QST_ID', null); |
|
| 454 | + $new_question->set_display_text(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->display_text())); |
|
| 455 | + $new_question->set_admin_label(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->admin_label())); |
|
| 456 | + $new_question->set_system_ID(null); |
|
| 457 | + $new_question->set_wp_user(get_current_user_id()); |
|
| 458 | + // if we're duplicating a trashed question, assume we don't want the new one to be trashed |
|
| 459 | + $new_question->set_deleted(false); |
|
| 460 | + $success = $new_question->save(); |
|
| 461 | + if ($success) { |
|
| 462 | + // we don't totally want to duplicate the question options, because we want them to be for the NEW question |
|
| 463 | + foreach ($this->options() as $question_option) { |
|
| 464 | + $question_option->duplicate(array('QST_ID' => $new_question->ID())); |
|
| 465 | + } |
|
| 466 | + return $new_question; |
|
| 467 | + } else { |
|
| 468 | + return null; |
|
| 469 | + } |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * Returns the question's maximum allowed response size |
|
| 474 | + * |
|
| 475 | + * @return int|float |
|
| 476 | + */ |
|
| 477 | + public function max() |
|
| 478 | + { |
|
| 479 | + return $this->get('QST_max'); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * Sets the question's maximum allowed response size |
|
| 484 | + * |
|
| 485 | + * @param int|float $new_max |
|
| 486 | + * @return void |
|
| 487 | + */ |
|
| 488 | + public function set_max($new_max) |
|
| 489 | + { |
|
| 490 | + $this->set('QST_max', $new_max); |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * Creates a form input from this question which can be used in HTML forms |
|
| 496 | + * |
|
| 497 | + * @param EE_Registration $registration |
|
| 498 | + * @param EE_Answer $answer |
|
| 499 | + * @param array $input_constructor_args |
|
| 500 | + * @return EE_Form_Input_Base |
|
| 501 | + */ |
|
| 502 | + public function generate_form_input($registration = null, $answer = null, $input_constructor_args = array()) |
|
| 503 | + { |
|
| 504 | + $identifier = $this->is_system_question() ? $this->system_ID() : $this->ID(); |
|
| 505 | + |
|
| 506 | + $input_constructor_args = array_merge( |
|
| 507 | + array( |
|
| 508 | + 'required' => $this->required() ? true : false, |
|
| 509 | + 'html_label_text' => $this->display_text(), |
|
| 510 | + 'required_validation_error_message' => $this->required_text(), |
|
| 511 | + ), |
|
| 512 | + $input_constructor_args |
|
| 513 | + ); |
|
| 514 | + if (! $answer instanceof EE_Answer && $registration instanceof EE_Registration) { |
|
| 515 | + $answer = EEM_Answer::instance()->get_registration_question_answer_object($registration, $this->ID()); |
|
| 516 | + } |
|
| 517 | + // has this question been answered ? |
|
| 518 | + if ( |
|
| 519 | + $answer instanceof EE_Answer |
|
| 520 | + && $answer->value() !== '' |
|
| 521 | + ) { |
|
| 522 | + // answer gets htmlspecialchars called on it, undo that please |
|
| 523 | + // because the form input's display strategy may call esc_attr too |
|
| 524 | + // which also does html special characters |
|
| 525 | + $values_with_html_special_chars = $answer->value(); |
|
| 526 | + if (is_array($values_with_html_special_chars)) { |
|
| 527 | + $default_value = array_map('htmlspecialchars_decode', $values_with_html_special_chars); |
|
| 528 | + } else { |
|
| 529 | + $default_value = htmlspecialchars_decode($values_with_html_special_chars); |
|
| 530 | + } |
|
| 531 | + $input_constructor_args['default'] = $default_value; |
|
| 532 | + } |
|
| 533 | + $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID()); |
|
| 534 | + if ( |
|
| 535 | + in_array( |
|
| 536 | + $this->type(), |
|
| 537 | + EEM_Question::instance()->questionTypesWithMaxLength(), |
|
| 538 | + true |
|
| 539 | + ) |
|
| 540 | + ) { |
|
| 541 | + $input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy( |
|
| 542 | + null, |
|
| 543 | + min($max_max_for_question, $this->max()) |
|
| 544 | + ); |
|
| 545 | + } |
|
| 546 | + $input_constructor_args = apply_filters( |
|
| 547 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__input_constructor_args', |
|
| 548 | + $input_constructor_args, |
|
| 549 | + $registration, |
|
| 550 | + $this, |
|
| 551 | + $answer |
|
| 552 | + ); |
|
| 553 | + |
|
| 554 | + $result = null; |
|
| 555 | + switch ($this->type()) { |
|
| 556 | + // Text |
|
| 557 | + case EEM_Question::QST_type_text: |
|
| 558 | + $result = new EE_Text_Input($input_constructor_args); |
|
| 559 | + break; |
|
| 560 | + // Textarea |
|
| 561 | + case EEM_Question::QST_type_textarea: |
|
| 562 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
| 563 | + break; |
|
| 564 | + // Radio Buttons |
|
| 565 | + case EEM_Question::QST_type_radio: |
|
| 566 | + $result = new EE_Radio_Button_Input($this->options(), $input_constructor_args); |
|
| 567 | + break; |
|
| 568 | + // Dropdown |
|
| 569 | + case EEM_Question::QST_type_dropdown: |
|
| 570 | + $result = new EE_Select_Input($this->options(), $input_constructor_args); |
|
| 571 | + break; |
|
| 572 | + // State Dropdown |
|
| 573 | + case EEM_Question::QST_type_state: |
|
| 574 | + $state_options = apply_filters( |
|
| 575 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
| 576 | + null, |
|
| 577 | + $this, |
|
| 578 | + $registration, |
|
| 579 | + $answer |
|
| 580 | + ); |
|
| 581 | + $result = new EE_State_Select_Input($state_options, $input_constructor_args); |
|
| 582 | + break; |
|
| 583 | + // Country Dropdown |
|
| 584 | + case EEM_Question::QST_type_country: |
|
| 585 | + $country_options = apply_filters( |
|
| 586 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
| 587 | + null, |
|
| 588 | + $this, |
|
| 589 | + $registration, |
|
| 590 | + $answer |
|
| 591 | + ); |
|
| 592 | + $result = new EE_Country_Select_Input($country_options, $input_constructor_args); |
|
| 593 | + break; |
|
| 594 | + // Checkboxes |
|
| 595 | + case EEM_Question::QST_type_checkbox: |
|
| 596 | + $result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args); |
|
| 597 | + break; |
|
| 598 | + // Date |
|
| 599 | + case EEM_Question::QST_type_date: |
|
| 600 | + $result = new EE_Datepicker_Input($input_constructor_args); |
|
| 601 | + break; |
|
| 602 | + case EEM_Question::QST_type_html_textarea: |
|
| 603 | + $input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy(); |
|
| 604 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
| 605 | + $result->remove_validation_strategy('EE_Plaintext_Validation_Strategy'); |
|
| 606 | + break; |
|
| 607 | + case EEM_Question::QST_type_email: |
|
| 608 | + $result = new EE_Email_Input($input_constructor_args); |
|
| 609 | + break; |
|
| 610 | + // Email confirm |
|
| 611 | + case EEM_Question::QST_type_email_confirm: |
|
| 612 | + $result = new EE_Email_Confirm_Input($input_constructor_args); |
|
| 613 | + break; |
|
| 614 | + case EEM_Question::QST_type_us_phone: |
|
| 615 | + $result = new EE_Phone_Input($input_constructor_args); |
|
| 616 | + break; |
|
| 617 | + case EEM_Question::QST_type_int: |
|
| 618 | + $result = new EE_Integer_Input($input_constructor_args); |
|
| 619 | + break; |
|
| 620 | + case EEM_Question::QST_type_decimal: |
|
| 621 | + $result = new EE_Float_Input($input_constructor_args); |
|
| 622 | + break; |
|
| 623 | + case EEM_Question::QST_type_url: |
|
| 624 | + $input_constructor_args['validation_strategies'][] = LoaderFactory::getLoader()->getNew('EE_URL_Validation_Strategy'); |
|
| 625 | + $result = new EE_Text_Input($input_constructor_args); |
|
| 626 | + break; |
|
| 627 | + case EEM_Question::QST_type_year: |
|
| 628 | + $result = new EE_Year_Input( |
|
| 629 | + $input_constructor_args, |
|
| 630 | + apply_filters( |
|
| 631 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', |
|
| 632 | + true, |
|
| 633 | + $this |
|
| 634 | + ), |
|
| 635 | + apply_filters( |
|
| 636 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', |
|
| 637 | + 100, |
|
| 638 | + $this |
|
| 639 | + ), |
|
| 640 | + apply_filters( |
|
| 641 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', |
|
| 642 | + 100, |
|
| 643 | + $this |
|
| 644 | + ) |
|
| 645 | + ); |
|
| 646 | + break; |
|
| 647 | + case EEM_Question::QST_type_multi_select: |
|
| 648 | + $result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args); |
|
| 649 | + break; |
|
| 650 | + // fallback |
|
| 651 | + default: |
|
| 652 | + $default_input = apply_filters( |
|
| 653 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__default', |
|
| 654 | + null, |
|
| 655 | + $this->type(), |
|
| 656 | + $this, |
|
| 657 | + $input_constructor_args |
|
| 658 | + ); |
|
| 659 | + if (! $default_input) { |
|
| 660 | + $default_input = new EE_Text_Input($input_constructor_args); |
|
| 661 | + } |
|
| 662 | + $result = $default_input; |
|
| 663 | + } |
|
| 664 | + return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer); |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + |
|
| 668 | + /** |
|
| 669 | + * Returns whether or not this question type should have question option entries |
|
| 670 | + * |
|
| 671 | + * @return bool |
|
| 672 | + */ |
|
| 673 | + public function should_have_question_options() |
|
| 674 | + { |
|
| 675 | + return in_array( |
|
| 676 | + $this->type(), |
|
| 677 | + $this->_model->question_types_with_options(), |
|
| 678 | + true |
|
| 679 | + ); |
|
| 680 | + } |
|
| 681 | 681 | } |
@@ -10,23 +10,23 @@ |
||
| 10 | 10 | class EE_Term_Relationship extends EE_Base_Class |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param array $props_n_values |
|
| 15 | - * @return EE_Term_Relationship |
|
| 16 | - */ |
|
| 17 | - public static function new_instance($props_n_values = array()) |
|
| 18 | - { |
|
| 19 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 20 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 21 | - } |
|
| 13 | + /** |
|
| 14 | + * @param array $props_n_values |
|
| 15 | + * @return EE_Term_Relationship |
|
| 16 | + */ |
|
| 17 | + public static function new_instance($props_n_values = array()) |
|
| 18 | + { |
|
| 19 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 20 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @param array $props_n_values |
|
| 26 | - * @return EE_Term_Relationship |
|
| 27 | - */ |
|
| 28 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 29 | - { |
|
| 30 | - return new self($props_n_values, true); |
|
| 31 | - } |
|
| 24 | + /** |
|
| 25 | + * @param array $props_n_values |
|
| 26 | + * @return EE_Term_Relationship |
|
| 27 | + */ |
|
| 28 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 29 | + { |
|
| 30 | + return new self($props_n_values, true); |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | { |
| 45 | 45 | $this->_req_data = $request_data; |
| 46 | 46 | $this->today = date("Y-m-d", time()); |
| 47 | - require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
| 47 | + require_once(EE_CLASSES.'EE_CSV.class.php'); |
|
| 48 | 48 | $this->EE_CSV = EE_CSV::instance(); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | $value_to_equal = $EVT_ID; |
| 168 | 168 | $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($EVT_ID); |
| 169 | 169 | |
| 170 | - $filename = 'event-' . ($event instanceof EE_Event ? $event->slug() : __('unknown', 'event_espresso')); |
|
| 170 | + $filename = 'event-'.($event instanceof EE_Event ? $event->slug() : __('unknown', 'event_espresso')); |
|
| 171 | 171 | } |
| 172 | 172 | $event_query_params[0]['EVT_ID'] = $value_to_equal; |
| 173 | 173 | $related_models_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | |
| 217 | 217 | $filename = $this->generate_filename($filename); |
| 218 | 218 | |
| 219 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
| 219 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
| 220 | 220 | EE_Error::add_error( |
| 221 | 221 | __( |
| 222 | 222 | "'An error occurred and the Event details could not be exported from the database.'", |
@@ -243,16 +243,16 @@ discard block |
||
| 243 | 243 | foreach (EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
| 244 | 244 | if ($field_name == 'STA_ID') { |
| 245 | 245 | $state_name_field = EEM_State::instance()->field_settings_for('STA_name'); |
| 246 | - $csv_row[ __('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column( |
|
| 247 | - ) ]; |
|
| 246 | + $csv_row[__('State', 'event_espresso')] = $attendee_row[$state_name_field->get_qualified_column( |
|
| 247 | + )]; |
|
| 248 | 248 | } elseif ($field_name == 'CNT_ISO') { |
| 249 | 249 | $country_name_field = EEM_Country::instance()->field_settings_for('CNT_name'); |
| 250 | - $csv_row[ __( |
|
| 250 | + $csv_row[__( |
|
| 251 | 251 | 'Country', |
| 252 | 252 | 'event_espresso' |
| 253 | - ) ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
| 253 | + )] = $attendee_row[$country_name_field->get_qualified_column()]; |
|
| 254 | 254 | } else { |
| 255 | - $csv_row[ $field_obj->get_nicename() ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
| 255 | + $csv_row[$field_obj->get_nicename()] = $attendee_row[$field_obj->get_qualified_column()]; |
|
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | $csv_data[] = $csv_row; |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | $model_data = $this->_get_export_data_for_models($models_to_export); |
| 292 | 292 | $filename = $this->generate_filename('all-attendees'); |
| 293 | 293 | |
| 294 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
| 294 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
| 295 | 295 | EE_Error::add_error( |
| 296 | 296 | __( |
| 297 | 297 | 'An error occurred and the Attendee data could not be exported from the database.', |
@@ -409,9 +409,9 @@ discard block |
||
| 409 | 409 | foreach ($registration_rows as $reg_row) { |
| 410 | 410 | if (is_array($reg_row)) { |
| 411 | 411 | $reg_csv_array = array(); |
| 412 | - if (! $event_id) { |
|
| 412 | + if ( ! $event_id) { |
|
| 413 | 413 | // get the event's name and Id |
| 414 | - $reg_csv_array[ __('Event', 'event_espresso') ] = sprintf( |
|
| 414 | + $reg_csv_array[__('Event', 'event_espresso')] = sprintf( |
|
| 415 | 415 | __('%1$s (%2$s)', 'event_espresso'), |
| 416 | 416 | $this->_prepare_value_from_db_for_display( |
| 417 | 417 | EEM_Event::instance(), |
@@ -457,13 +457,13 @@ discard block |
||
| 457 | 457 | $value = $this->_prepare_value_from_db_for_display( |
| 458 | 458 | $reg_model, |
| 459 | 459 | $field_name, |
| 460 | - $reg_row[ $field->get_qualified_column() ] |
|
| 460 | + $reg_row[$field->get_qualified_column()] |
|
| 461 | 461 | ); |
| 462 | 462 | } |
| 463 | - $reg_csv_array[ $this->_get_column_name_for_field($field) ] = $value; |
|
| 463 | + $reg_csv_array[$this->_get_column_name_for_field($field)] = $value; |
|
| 464 | 464 | if ($field_name == 'REG_final_price') { |
| 465 | 465 | // add a column named Currency after the final price |
| 466 | - $reg_csv_array[ __("Currency", "event_espresso") ] = EE_Config::instance()->currency->code; |
|
| 466 | + $reg_csv_array[__("Currency", "event_espresso")] = EE_Config::instance()->currency->code; |
|
| 467 | 467 | } |
| 468 | 468 | } |
| 469 | 469 | // get pretty status |
@@ -475,23 +475,23 @@ discard block |
||
| 475 | 475 | false, |
| 476 | 476 | 'sentence' |
| 477 | 477 | ); |
| 478 | - $reg_csv_array[ __( |
|
| 478 | + $reg_csv_array[__( |
|
| 479 | 479 | "Registration Status", |
| 480 | 480 | 'event_espresso' |
| 481 | - ) ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
| 481 | + )] = $stati[$reg_row['Registration.STS_ID']]; |
|
| 482 | 482 | // get pretty trnasaction status |
| 483 | - $reg_csv_array[ __( |
|
| 483 | + $reg_csv_array[__( |
|
| 484 | 484 | "Transaction Status", |
| 485 | 485 | 'event_espresso' |
| 486 | - ) ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
| 487 | - $reg_csv_array[ __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
| 486 | + )] = $stati[$reg_row['TransactionTable.STS_ID']]; |
|
| 487 | + $reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg |
|
| 488 | 488 | ? $this->_prepare_value_from_db_for_display( |
| 489 | 489 | EEM_Transaction::instance(), |
| 490 | 490 | 'TXN_total', |
| 491 | 491 | $reg_row['TransactionTable.TXN_total'], |
| 492 | 492 | 'localized_float' |
| 493 | 493 | ) : '0.00'; |
| 494 | - $reg_csv_array[ __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
| 494 | + $reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg |
|
| 495 | 495 | ? $this->_prepare_value_from_db_for_display( |
| 496 | 496 | EEM_Transaction::instance(), |
| 497 | 497 | 'TXN_paid', |
@@ -523,15 +523,15 @@ discard block |
||
| 523 | 523 | ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
| 524 | 524 | } |
| 525 | 525 | } |
| 526 | - $reg_csv_array[ __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
| 527 | - $reg_csv_array[ __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
| 528 | - $reg_csv_array[ __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
| 526 | + $reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times); |
|
| 527 | + $reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods); |
|
| 528 | + $reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode( |
|
| 529 | 529 | ',', |
| 530 | 530 | $gateway_txn_ids_etc |
| 531 | 531 | ); |
| 532 | 532 | |
| 533 | 533 | // get whether or not the user has checked in |
| 534 | - $reg_csv_array[ __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
| 534 | + $reg_csv_array[__("Check-Ins", "event_espresso")] = $reg_model->count_related( |
|
| 535 | 535 | $reg_row['Registration.REG_ID'], |
| 536 | 536 | 'Checkin' |
| 537 | 537 | ); |
@@ -561,8 +561,8 @@ discard block |
||
| 561 | 561 | $ticket_name = __('Unknown', 'event_espresso'); |
| 562 | 562 | $datetimes_strings = array(__('Unknown', 'event_espresso')); |
| 563 | 563 | } |
| 564 | - $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
| 565 | - $reg_csv_array[ __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
| 564 | + $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name; |
|
| 565 | + $reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings); |
|
| 566 | 566 | // get datetime(s) of registration |
| 567 | 567 | |
| 568 | 568 | // add attendee columns |
@@ -583,20 +583,20 @@ discard block |
||
| 583 | 583 | $value = $this->_prepare_value_from_db_for_display( |
| 584 | 584 | EEM_Attendee::instance(), |
| 585 | 585 | $att_field_name, |
| 586 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
| 586 | + $reg_row[$field_obj->get_qualified_column()] |
|
| 587 | 587 | ); |
| 588 | 588 | } |
| 589 | 589 | } else { |
| 590 | 590 | $value = ''; |
| 591 | 591 | } |
| 592 | 592 | |
| 593 | - $reg_csv_array[ $this->_get_column_name_for_field($field_obj) ] = $value; |
|
| 593 | + $reg_csv_array[$this->_get_column_name_for_field($field_obj)] = $value; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | // make sure each registration has the same questions in the same order |
| 597 | 597 | foreach ($questions_for_these_regs_rows as $question_row) { |
| 598 | - if (! isset($reg_csv_array[ $question_row['Question.QST_admin_label'] ])) { |
|
| 599 | - $reg_csv_array[ $question_row['Question.QST_admin_label'] ] = null; |
|
| 598 | + if ( ! isset($reg_csv_array[$question_row['Question.QST_admin_label']])) { |
|
| 599 | + $reg_csv_array[$question_row['Question.QST_admin_label']] = null; |
|
| 600 | 600 | } |
| 601 | 601 | } |
| 602 | 602 | // now fill out the questions THEY answered |
@@ -614,11 +614,11 @@ discard block |
||
| 614 | 614 | $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
| 615 | 615 | } |
| 616 | 616 | if (isset($answer_row['Question.QST_type']) && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state) { |
| 617 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
| 617 | + $reg_csv_array[$question_label] = EEM_State::instance()->get_state_name_by_ID( |
|
| 618 | 618 | $answer_row['Answer.ANS_value'] |
| 619 | 619 | ); |
| 620 | 620 | } else { |
| 621 | - $reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display( |
|
| 621 | + $reg_csv_array[$question_label] = $this->_prepare_value_from_db_for_display( |
|
| 622 | 622 | EEM_Answer::instance(), |
| 623 | 623 | 'ANS_value', |
| 624 | 624 | $answer_row['Answer.ANS_value'] |
@@ -644,16 +644,16 @@ discard block |
||
| 644 | 644 | $model = EE_Registry::instance()->load_model($model_name); |
| 645 | 645 | foreach ($field_list as $field_name) { |
| 646 | 646 | $field = $model->field_settings_for($field_name); |
| 647 | - $reg_csv_array[ $this->_get_column_name_for_field( |
|
| 647 | + $reg_csv_array[$this->_get_column_name_for_field( |
|
| 648 | 648 | $field |
| 649 | - ) ] = null;// $registration->get($field->get_name()); |
|
| 649 | + )] = null; // $registration->get($field->get_name()); |
|
| 650 | 650 | } |
| 651 | 651 | } |
| 652 | 652 | $registrations_csv_ready_array [] = $reg_csv_array; |
| 653 | 653 | } |
| 654 | 654 | if ($event_id) { |
| 655 | 655 | $event_slug = EEM_Event::instance()->get_var(array(array('EVT_ID' => $event_id)), 'EVT_slug'); |
| 656 | - if (! $event_slug) { |
|
| 656 | + if ( ! $event_slug) { |
|
| 657 | 657 | $event_slug = __('unknown', 'event_espresso'); |
| 658 | 658 | } |
| 659 | 659 | } else { |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | */ |
| 675 | 675 | protected function _get_column_name_for_field(EE_Model_Field_Base $field) |
| 676 | 676 | { |
| 677 | - return $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
| 677 | + return $field->get_nicename()."[".$field->get_name()."]"; |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | |
@@ -697,7 +697,7 @@ discard block |
||
| 697 | 697 | } else { |
| 698 | 698 | // generate regular where = clause |
| 699 | 699 | $EVT_CAT_ID = absint($this->_req_data['EVT_CAT_ID']); |
| 700 | - $filename = 'event-category#' . $EVT_CAT_ID; |
|
| 700 | + $filename = 'event-category#'.$EVT_CAT_ID; |
|
| 701 | 701 | $query_params[0]['term_taxonomy_id'] = $EVT_CAT_ID; |
| 702 | 702 | } |
| 703 | 703 | } else { |
@@ -712,7 +712,7 @@ discard block |
||
| 712 | 712 | $table_data = $this->_get_export_data_for_models($tables_to_export); |
| 713 | 713 | $filename = $this->generate_filename($filename); |
| 714 | 714 | |
| 715 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) { |
|
| 715 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) { |
|
| 716 | 716 | EE_Error::add_error( |
| 717 | 717 | __( |
| 718 | 718 | 'An error occurred and the Category details could not be exported from the database.', |
@@ -735,8 +735,8 @@ discard block |
||
| 735 | 735 | private function generate_filename($export_name = '') |
| 736 | 736 | { |
| 737 | 737 | if ($export_name != '') { |
| 738 | - $filename = get_bloginfo('name') . '-' . $export_name; |
|
| 739 | - $filename = sanitize_key($filename) . '-' . $this->today; |
|
| 738 | + $filename = get_bloginfo('name').'-'.$export_name; |
|
| 739 | + $filename = sanitize_key($filename).'-'.$this->today; |
|
| 740 | 740 | return $filename; |
| 741 | 741 | } else { |
| 742 | 742 | EE_Error::add_error(__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
@@ -765,25 +765,25 @@ discard block |
||
| 765 | 765 | $model = EE_Registry::instance()->load_model($model_name); |
| 766 | 766 | $model_objects = $model->get_all($query_params); |
| 767 | 767 | |
| 768 | - $table_data[ $model_name ] = array(); |
|
| 768 | + $table_data[$model_name] = array(); |
|
| 769 | 769 | foreach ($model_objects as $model_object) { |
| 770 | 770 | $model_data_array = array(); |
| 771 | 771 | $fields = $model->field_settings(); |
| 772 | 772 | foreach ($fields as $field) { |
| 773 | - $column_name = $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
| 773 | + $column_name = $field->get_nicename()."[".$field->get_name()."]"; |
|
| 774 | 774 | if ($field instanceof EE_Datetime_Field) { |
| 775 | 775 | // $field->set_date_format('Y-m-d'); |
| 776 | 776 | // $field->set_time_format('H:i:s'); |
| 777 | - $model_data_array[ $column_name ] = $model_object->get_datetime( |
|
| 777 | + $model_data_array[$column_name] = $model_object->get_datetime( |
|
| 778 | 778 | $field->get_name(), |
| 779 | 779 | 'Y-m-d', |
| 780 | 780 | 'H:i:s' |
| 781 | 781 | ); |
| 782 | 782 | } else { |
| 783 | - $model_data_array[ $column_name ] = $model_object->get($field->get_name()); |
|
| 783 | + $model_data_array[$column_name] = $model_object->get($field->get_name()); |
|
| 784 | 784 | } |
| 785 | 785 | } |
| 786 | - $table_data[ $model_name ][] = $model_data_array; |
|
| 786 | + $table_data[$model_name][] = $model_data_array; |
|
| 787 | 787 | } |
| 788 | 788 | } |
| 789 | 789 | } |
@@ -16,781 +16,781 @@ |
||
| 16 | 16 | class EE_Export |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - const option_prefix = 'ee_report_job_'; |
|
| 20 | - |
|
| 21 | - |
|
| 22 | - // instance of the EE_Export object |
|
| 23 | - private static $_instance = null; |
|
| 24 | - |
|
| 25 | - // instance of the EE_CSV object |
|
| 26 | - /** |
|
| 27 | - * |
|
| 28 | - * @var EE_CSV |
|
| 29 | - */ |
|
| 30 | - public $EE_CSV = null; |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - private $_req_data = array(); |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * private constructor to prevent direct creation |
|
| 38 | - * |
|
| 39 | - * @Constructor |
|
| 40 | - * @access private |
|
| 41 | - * @param array $request_data |
|
| 42 | - */ |
|
| 43 | - private function __construct($request_data = array()) |
|
| 44 | - { |
|
| 45 | - $this->_req_data = $request_data; |
|
| 46 | - $this->today = date("Y-m-d", time()); |
|
| 47 | - require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
| 48 | - $this->EE_CSV = EE_CSV::instance(); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @ singleton method used to instantiate class object |
|
| 54 | - * @ access public |
|
| 55 | - * |
|
| 56 | - * @param array $request_data |
|
| 57 | - * @return \EE_Export |
|
| 58 | - */ |
|
| 59 | - public static function instance($request_data = array()) |
|
| 60 | - { |
|
| 61 | - // check if class object is instantiated |
|
| 62 | - if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Export)) { |
|
| 63 | - self::$_instance = new self($request_data); |
|
| 64 | - } |
|
| 65 | - return self::$_instance; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @Export Event Espresso data - routes export requests |
|
| 71 | - * @access public |
|
| 72 | - * @return void | bool |
|
| 73 | - */ |
|
| 74 | - public function export() |
|
| 75 | - { |
|
| 76 | - // in case of bulk exports, the "actual" action will be in action2, but first check regular action for "export" keyword |
|
| 77 | - if (isset($this->_req_data['action']) && strpos($this->_req_data['action'], 'export') === false) { |
|
| 78 | - // check if action2 has export action |
|
| 79 | - if (isset($this->_req_data['action2']) && strpos($this->_req_data['action2'], 'export') !== false) { |
|
| 80 | - // whoop! there it is! |
|
| 81 | - $this->_req_data['action'] = $this->_req_data['action2']; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - $this->_req_data['export'] = isset($this->_req_data['export']) ? $this->_req_data['export'] : ''; |
|
| 86 | - |
|
| 87 | - switch ($this->_req_data['export']) { |
|
| 88 | - case 'report': |
|
| 89 | - switch ($this->_req_data['action']) { |
|
| 90 | - case "event": |
|
| 91 | - case "export_events": |
|
| 92 | - case 'all_event_data': |
|
| 93 | - $this->export_all_event_data(); |
|
| 94 | - break; |
|
| 95 | - |
|
| 96 | - case 'registrations_report_for_event': |
|
| 97 | - $this->report_registrations_for_event($this->_req_data['EVT_ID']); |
|
| 98 | - break; |
|
| 99 | - |
|
| 100 | - case 'attendees': |
|
| 101 | - $this->export_attendees(); |
|
| 102 | - break; |
|
| 103 | - |
|
| 104 | - case 'categories': |
|
| 105 | - $this->export_categories(); |
|
| 106 | - break; |
|
| 107 | - |
|
| 108 | - default: |
|
| 109 | - EE_Error::add_error( |
|
| 110 | - __('An error occurred! The requested export report could not be found.', 'event_espresso'), |
|
| 111 | - __FILE__, |
|
| 112 | - __FUNCTION__, |
|
| 113 | - __LINE__ |
|
| 114 | - ); |
|
| 115 | - return false; |
|
| 116 | - break; |
|
| 117 | - } |
|
| 118 | - break; // end of switch export : report |
|
| 119 | - default: |
|
| 120 | - break; |
|
| 121 | - } // end of switch export |
|
| 122 | - |
|
| 123 | - exit; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Downloads a CSV file with all the columns, but no data. This should be used for importing |
|
| 128 | - * |
|
| 129 | - * @return null kills execution |
|
| 130 | - */ |
|
| 131 | - public function export_sample() |
|
| 132 | - { |
|
| 133 | - $event = EEM_Event::instance()->get_one(); |
|
| 134 | - $this->_req_data['EVT_ID'] = $event->ID(); |
|
| 135 | - $this->export_all_event_data(); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @Export data for ALL events |
|
| 141 | - * @access public |
|
| 142 | - * @return void |
|
| 143 | - */ |
|
| 144 | - public function export_all_event_data() |
|
| 145 | - { |
|
| 146 | - // are any Event IDs set? |
|
| 147 | - $event_query_params = array(); |
|
| 148 | - $related_models_query_params = array(); |
|
| 149 | - $related_through_reg_query_params = array(); |
|
| 150 | - $datetime_ticket_query_params = array(); |
|
| 151 | - $price_query_params = array(); |
|
| 152 | - $price_type_query_params = array(); |
|
| 153 | - $term_query_params = array(); |
|
| 154 | - $state_country_query_params = array(); |
|
| 155 | - $question_group_query_params = array(); |
|
| 156 | - $question_query_params = array(); |
|
| 157 | - if (isset($this->_req_data['EVT_ID'])) { |
|
| 158 | - // do we have an array of IDs ? |
|
| 159 | - |
|
| 160 | - if (is_array($this->_req_data['EVT_ID'])) { |
|
| 161 | - $EVT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_ID']); |
|
| 162 | - $value_to_equal = array('IN', $EVT_IDs); |
|
| 163 | - $filename = 'events'; |
|
| 164 | - } else { |
|
| 165 | - // generate regular where = clause |
|
| 166 | - $EVT_ID = absint($this->_req_data['EVT_ID']); |
|
| 167 | - $value_to_equal = $EVT_ID; |
|
| 168 | - $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($EVT_ID); |
|
| 169 | - |
|
| 170 | - $filename = 'event-' . ($event instanceof EE_Event ? $event->slug() : __('unknown', 'event_espresso')); |
|
| 171 | - } |
|
| 172 | - $event_query_params[0]['EVT_ID'] = $value_to_equal; |
|
| 173 | - $related_models_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
|
| 174 | - $related_through_reg_query_params[0]['Registration.EVT_ID'] = $value_to_equal; |
|
| 175 | - $datetime_ticket_query_params[0]['Datetime.EVT_ID'] = $value_to_equal; |
|
| 176 | - $price_query_params[0]['Ticket.Datetime.EVT_ID'] = $value_to_equal; |
|
| 177 | - $price_type_query_params[0]['Price.Ticket.Datetime.EVT_ID'] = $value_to_equal; |
|
| 178 | - $term_query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $value_to_equal; |
|
| 179 | - $state_country_query_params[0]['Venue.Event.EVT_ID'] = $value_to_equal; |
|
| 180 | - $question_group_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
|
| 181 | - $question_query_params[0]['Question_Group.Event.EVT_ID'] = $value_to_equal; |
|
| 182 | - } else { |
|
| 183 | - $filename = 'all-events'; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - // array in the format: table name => query where clause |
|
| 188 | - $models_to_export = array( |
|
| 189 | - 'Event' => $event_query_params, |
|
| 190 | - 'Datetime' => $related_models_query_params, |
|
| 191 | - 'Ticket_Template' => $price_query_params, |
|
| 192 | - 'Ticket' => $datetime_ticket_query_params, |
|
| 193 | - 'Datetime_Ticket' => $datetime_ticket_query_params, |
|
| 194 | - 'Price_Type' => $price_type_query_params, |
|
| 195 | - 'Price' => $price_query_params, |
|
| 196 | - 'Ticket_Price' => $price_query_params, |
|
| 197 | - 'Term' => $term_query_params, |
|
| 198 | - 'Term_Taxonomy' => $related_models_query_params, |
|
| 199 | - 'Term_Relationship' => $related_models_query_params, // model has NO primary key... |
|
| 200 | - 'Country' => $state_country_query_params, |
|
| 201 | - 'State' => $state_country_query_params, |
|
| 202 | - 'Venue' => $related_models_query_params, |
|
| 203 | - 'Event_Venue' => $related_models_query_params, |
|
| 204 | - 'Question_Group' => $question_group_query_params, |
|
| 205 | - 'Event_Question_Group' => $question_group_query_params, |
|
| 206 | - 'Question' => $question_query_params, |
|
| 207 | - 'Question_Group_Question' => $question_query_params, |
|
| 208 | - // 'Transaction'=>$related_through_reg_query_params, |
|
| 209 | - // 'Registration'=>$related_models_query_params, |
|
| 210 | - // 'Attendee'=>$related_through_reg_query_params, |
|
| 211 | - // 'Line_Item'=> |
|
| 212 | - |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - $model_data = $this->_get_export_data_for_models($models_to_export); |
|
| 216 | - |
|
| 217 | - $filename = $this->generate_filename($filename); |
|
| 218 | - |
|
| 219 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
| 220 | - EE_Error::add_error( |
|
| 221 | - __( |
|
| 222 | - "'An error occurred and the Event details could not be exported from the database.'", |
|
| 223 | - "event_espresso" |
|
| 224 | - ), |
|
| 225 | - __FILE__, |
|
| 226 | - __FUNCTION__, |
|
| 227 | - __LINE__ |
|
| 228 | - ); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - public function report_attendees() |
|
| 233 | - { |
|
| 234 | - $attendee_rows = EEM_Attendee::instance()->get_all_wpdb_results( |
|
| 235 | - array( |
|
| 236 | - 'force_join' => array('State', 'Country'), |
|
| 237 | - 'caps' => EEM_Base::caps_read_admin, |
|
| 238 | - ) |
|
| 239 | - ); |
|
| 240 | - $csv_data = array(); |
|
| 241 | - foreach ($attendee_rows as $attendee_row) { |
|
| 242 | - $csv_row = array(); |
|
| 243 | - foreach (EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
|
| 244 | - if ($field_name == 'STA_ID') { |
|
| 245 | - $state_name_field = EEM_State::instance()->field_settings_for('STA_name'); |
|
| 246 | - $csv_row[ __('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column( |
|
| 247 | - ) ]; |
|
| 248 | - } elseif ($field_name == 'CNT_ISO') { |
|
| 249 | - $country_name_field = EEM_Country::instance()->field_settings_for('CNT_name'); |
|
| 250 | - $csv_row[ __( |
|
| 251 | - 'Country', |
|
| 252 | - 'event_espresso' |
|
| 253 | - ) ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
| 254 | - } else { |
|
| 255 | - $csv_row[ $field_obj->get_nicename() ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - $csv_data[] = $csv_row; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - $filename = $this->generate_filename('contact-list-report'); |
|
| 262 | - |
|
| 263 | - $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
| 264 | - $this->EE_CSV->write_data_array_to_csv($handle, $csv_data); |
|
| 265 | - $this->EE_CSV->end_sending_csv($handle); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * @Export data for ALL attendees |
|
| 271 | - * @access public |
|
| 272 | - * @return void |
|
| 273 | - */ |
|
| 274 | - public function export_attendees() |
|
| 275 | - { |
|
| 276 | - |
|
| 277 | - $states_that_have_an_attendee = EEM_State::instance()->get_all( |
|
| 278 | - array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL'))) |
|
| 279 | - ); |
|
| 280 | - $countries_that_have_an_attendee = EEM_Country::instance()->get_all( |
|
| 281 | - array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL'))) |
|
| 282 | - ); |
|
| 283 | - // $states_to_export_query_params |
|
| 284 | - $models_to_export = array( |
|
| 285 | - 'Country' => array(array('CNT_ISO' => array('IN', array_keys($countries_that_have_an_attendee)))), |
|
| 286 | - 'State' => array(array('STA_ID' => array('IN', array_keys($states_that_have_an_attendee)))), |
|
| 287 | - 'Attendee' => array(), |
|
| 288 | - ); |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - $model_data = $this->_get_export_data_for_models($models_to_export); |
|
| 292 | - $filename = $this->generate_filename('all-attendees'); |
|
| 293 | - |
|
| 294 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
| 295 | - EE_Error::add_error( |
|
| 296 | - __( |
|
| 297 | - 'An error occurred and the Attendee data could not be exported from the database.', |
|
| 298 | - 'event_espresso' |
|
| 299 | - ), |
|
| 300 | - __FILE__, |
|
| 301 | - __FUNCTION__, |
|
| 302 | - __LINE__ |
|
| 303 | - ); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Shortcut for preparing a database result for display |
|
| 309 | - * |
|
| 310 | - * @param EEM_Base $model |
|
| 311 | - * @param string $field_name |
|
| 312 | - * @param string $raw_db_value |
|
| 313 | - * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to |
|
| 314 | - * NOT display pretty |
|
| 315 | - * @return string |
|
| 316 | - */ |
|
| 317 | - protected function _prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true) |
|
| 318 | - { |
|
| 319 | - $field_obj = $model->field_settings_for($field_name); |
|
| 320 | - $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
| 321 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
| 322 | - $field_obj->set_date_format( |
|
| 323 | - EE_CSV::instance()->get_date_format_for_csv($field_obj->get_date_format($pretty_schema)), |
|
| 324 | - $pretty_schema |
|
| 325 | - ); |
|
| 326 | - $field_obj->set_time_format( |
|
| 327 | - EE_CSV::instance()->get_time_format_for_csv($field_obj->get_time_format($pretty_schema)), |
|
| 328 | - $pretty_schema |
|
| 329 | - ); |
|
| 330 | - } |
|
| 331 | - if ($pretty_schema === true) { |
|
| 332 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
| 333 | - } elseif (is_string($pretty_schema)) { |
|
| 334 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
| 335 | - } else { |
|
| 336 | - return $field_obj->prepare_for_get($value_on_model_obj); |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Export a custom CSV of registration info including: A bunch of the reg fields, the time of the event, the price |
|
| 342 | - * name, and the questions associated with the registrations |
|
| 343 | - * |
|
| 344 | - * @param int $event_id |
|
| 345 | - */ |
|
| 346 | - public function report_registrations_for_event($event_id = null) |
|
| 347 | - { |
|
| 348 | - $reg_fields_to_include = array( |
|
| 349 | - 'TXN_ID', |
|
| 350 | - 'ATT_ID', |
|
| 351 | - 'REG_ID', |
|
| 352 | - 'REG_date', |
|
| 353 | - 'REG_code', |
|
| 354 | - 'REG_count', |
|
| 355 | - 'REG_final_price', |
|
| 356 | - |
|
| 357 | - ); |
|
| 358 | - $att_fields_to_include = array( |
|
| 359 | - 'ATT_fname', |
|
| 360 | - 'ATT_lname', |
|
| 361 | - 'ATT_email', |
|
| 362 | - 'ATT_address', |
|
| 363 | - 'ATT_address2', |
|
| 364 | - 'ATT_city', |
|
| 365 | - 'STA_ID', |
|
| 366 | - 'CNT_ISO', |
|
| 367 | - 'ATT_zip', |
|
| 368 | - 'ATT_phone', |
|
| 369 | - ); |
|
| 370 | - |
|
| 371 | - $registrations_csv_ready_array = array(); |
|
| 372 | - $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
| 373 | - $query_params = apply_filters( |
|
| 374 | - 'FHEE__EE_Export__report_registration_for_event', |
|
| 375 | - array( |
|
| 376 | - array( |
|
| 377 | - 'OR' => array( |
|
| 378 | - // don't include registrations from failed or abandoned transactions... |
|
| 379 | - 'Transaction.STS_ID' => array( |
|
| 380 | - 'NOT IN', |
|
| 381 | - array(EEM_Transaction::failed_status_code, EEM_Transaction::abandoned_status_code), |
|
| 382 | - ), |
|
| 383 | - // unless the registration is approved, in which case include it regardless of transaction status |
|
| 384 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 385 | - ), |
|
| 386 | - 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
| 387 | - ), |
|
| 388 | - 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
| 389 | - 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
| 390 | - 'caps' => EEM_Base::caps_read_admin, |
|
| 391 | - ), |
|
| 392 | - $event_id |
|
| 393 | - ); |
|
| 394 | - if ($event_id) { |
|
| 395 | - $query_params[0]['EVT_ID'] = $event_id; |
|
| 396 | - } else { |
|
| 397 | - $query_params['force_join'][] = 'Event'; |
|
| 398 | - } |
|
| 399 | - $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
| 400 | - // get all questions which relate to someone in this group |
|
| 401 | - $registration_ids = array(); |
|
| 402 | - foreach ($registration_rows as $reg_row) { |
|
| 403 | - $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
| 404 | - } |
|
| 405 | - // EEM_Question::instance()->show_next_x_db_queries(); |
|
| 406 | - $questions_for_these_regs_rows = EEM_Question::instance()->get_all_wpdb_results( |
|
| 407 | - array(array('Answer.REG_ID' => array('IN', $registration_ids))) |
|
| 408 | - ); |
|
| 409 | - foreach ($registration_rows as $reg_row) { |
|
| 410 | - if (is_array($reg_row)) { |
|
| 411 | - $reg_csv_array = array(); |
|
| 412 | - if (! $event_id) { |
|
| 413 | - // get the event's name and Id |
|
| 414 | - $reg_csv_array[ __('Event', 'event_espresso') ] = sprintf( |
|
| 415 | - __('%1$s (%2$s)', 'event_espresso'), |
|
| 416 | - $this->_prepare_value_from_db_for_display( |
|
| 417 | - EEM_Event::instance(), |
|
| 418 | - 'EVT_name', |
|
| 419 | - $reg_row['Event_CPT.post_title'] |
|
| 420 | - ), |
|
| 421 | - $reg_row['Event_CPT.ID'] |
|
| 422 | - ); |
|
| 423 | - } |
|
| 424 | - $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
| 425 | - /*@var $reg_row EE_Registration */ |
|
| 426 | - foreach ($reg_fields_to_include as $field_name) { |
|
| 427 | - $field = $reg_model->field_settings_for($field_name); |
|
| 428 | - if ($field_name == 'REG_final_price') { |
|
| 429 | - $value = $this->_prepare_value_from_db_for_display( |
|
| 430 | - $reg_model, |
|
| 431 | - $field_name, |
|
| 432 | - $reg_row['Registration.REG_final_price'], |
|
| 433 | - 'localized_float' |
|
| 434 | - ); |
|
| 435 | - } elseif ($field_name == 'REG_count') { |
|
| 436 | - $value = sprintf( |
|
| 437 | - __('%s of %s', 'event_espresso'), |
|
| 438 | - $this->_prepare_value_from_db_for_display( |
|
| 439 | - $reg_model, |
|
| 440 | - 'REG_count', |
|
| 441 | - $reg_row['Registration.REG_count'] |
|
| 442 | - ), |
|
| 443 | - $this->_prepare_value_from_db_for_display( |
|
| 444 | - $reg_model, |
|
| 445 | - 'REG_group_size', |
|
| 446 | - $reg_row['Registration.REG_group_size'] |
|
| 447 | - ) |
|
| 448 | - ); |
|
| 449 | - } elseif ($field_name == 'REG_date') { |
|
| 450 | - $value = $this->_prepare_value_from_db_for_display( |
|
| 451 | - $reg_model, |
|
| 452 | - $field_name, |
|
| 453 | - $reg_row['Registration.REG_date'], |
|
| 454 | - 'no_html' |
|
| 455 | - ); |
|
| 456 | - } else { |
|
| 457 | - $value = $this->_prepare_value_from_db_for_display( |
|
| 458 | - $reg_model, |
|
| 459 | - $field_name, |
|
| 460 | - $reg_row[ $field->get_qualified_column() ] |
|
| 461 | - ); |
|
| 462 | - } |
|
| 463 | - $reg_csv_array[ $this->_get_column_name_for_field($field) ] = $value; |
|
| 464 | - if ($field_name == 'REG_final_price') { |
|
| 465 | - // add a column named Currency after the final price |
|
| 466 | - $reg_csv_array[ __("Currency", "event_espresso") ] = EE_Config::instance()->currency->code; |
|
| 467 | - } |
|
| 468 | - } |
|
| 469 | - // get pretty status |
|
| 470 | - $stati = EEM_Status::instance()->localized_status( |
|
| 471 | - array( |
|
| 472 | - $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
| 473 | - $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
| 474 | - ), |
|
| 475 | - false, |
|
| 476 | - 'sentence' |
|
| 477 | - ); |
|
| 478 | - $reg_csv_array[ __( |
|
| 479 | - "Registration Status", |
|
| 480 | - 'event_espresso' |
|
| 481 | - ) ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
| 482 | - // get pretty trnasaction status |
|
| 483 | - $reg_csv_array[ __( |
|
| 484 | - "Transaction Status", |
|
| 485 | - 'event_espresso' |
|
| 486 | - ) ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
| 487 | - $reg_csv_array[ __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
| 488 | - ? $this->_prepare_value_from_db_for_display( |
|
| 489 | - EEM_Transaction::instance(), |
|
| 490 | - 'TXN_total', |
|
| 491 | - $reg_row['TransactionTable.TXN_total'], |
|
| 492 | - 'localized_float' |
|
| 493 | - ) : '0.00'; |
|
| 494 | - $reg_csv_array[ __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
| 495 | - ? $this->_prepare_value_from_db_for_display( |
|
| 496 | - EEM_Transaction::instance(), |
|
| 497 | - 'TXN_paid', |
|
| 498 | - $reg_row['TransactionTable.TXN_paid'], |
|
| 499 | - 'localized_float' |
|
| 500 | - ) : '0.00'; |
|
| 501 | - $payment_methods = array(); |
|
| 502 | - $gateway_txn_ids_etc = array(); |
|
| 503 | - $payment_times = array(); |
|
| 504 | - if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
| 505 | - $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
| 506 | - array( |
|
| 507 | - array( |
|
| 508 | - 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
| 509 | - 'STS_ID' => EEM_Payment::status_id_approved, |
|
| 510 | - ), |
|
| 511 | - 'force_join' => array('Payment_Method'), |
|
| 512 | - ), |
|
| 513 | - ARRAY_A, |
|
| 514 | - 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
| 515 | - ); |
|
| 516 | - |
|
| 517 | - foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
| 518 | - $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
| 519 | - ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
| 520 | - $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
| 521 | - ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
| 522 | - $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
| 523 | - ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - $reg_csv_array[ __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
| 527 | - $reg_csv_array[ __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
| 528 | - $reg_csv_array[ __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
| 529 | - ',', |
|
| 530 | - $gateway_txn_ids_etc |
|
| 531 | - ); |
|
| 532 | - |
|
| 533 | - // get whether or not the user has checked in |
|
| 534 | - $reg_csv_array[ __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
| 535 | - $reg_row['Registration.REG_ID'], |
|
| 536 | - 'Checkin' |
|
| 537 | - ); |
|
| 538 | - // get ticket of registration and its price |
|
| 539 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 540 | - if ($reg_row['Ticket.TKT_ID']) { |
|
| 541 | - $ticket_name = $this->_prepare_value_from_db_for_display( |
|
| 542 | - $ticket_model, |
|
| 543 | - 'TKT_name', |
|
| 544 | - $reg_row['Ticket.TKT_name'] |
|
| 545 | - ); |
|
| 546 | - $datetimes_strings = array(); |
|
| 547 | - foreach ( |
|
| 548 | - EEM_Datetime::instance()->get_all_wpdb_results( |
|
| 549 | - array( |
|
| 550 | - array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
| 551 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 552 | - 'default_where_conditions' => 'none', |
|
| 553 | - ) |
|
| 554 | - ) as $datetime |
|
| 555 | - ) { |
|
| 556 | - $datetimes_strings[] = $this->_prepare_value_from_db_for_display( |
|
| 557 | - EEM_Datetime::instance(), |
|
| 558 | - 'DTT_EVT_start', |
|
| 559 | - $datetime['Datetime.DTT_EVT_start'] |
|
| 560 | - ); |
|
| 561 | - } |
|
| 562 | - } else { |
|
| 563 | - $ticket_name = __('Unknown', 'event_espresso'); |
|
| 564 | - $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
| 565 | - } |
|
| 566 | - $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
| 567 | - $reg_csv_array[ __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
| 568 | - // get datetime(s) of registration |
|
| 569 | - |
|
| 570 | - // add attendee columns |
|
| 571 | - foreach ($att_fields_to_include as $att_field_name) { |
|
| 572 | - $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
| 573 | - if ($reg_row['Attendee_CPT.ID']) { |
|
| 574 | - if ($att_field_name == 'STA_ID') { |
|
| 575 | - $value = EEM_State::instance()->get_var( |
|
| 576 | - array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
| 577 | - 'STA_name' |
|
| 578 | - ); |
|
| 579 | - } elseif ($att_field_name == 'CNT_ISO') { |
|
| 580 | - $value = EEM_Country::instance()->get_var( |
|
| 581 | - array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
| 582 | - 'CNT_name' |
|
| 583 | - ); |
|
| 584 | - } else { |
|
| 585 | - $value = $this->_prepare_value_from_db_for_display( |
|
| 586 | - EEM_Attendee::instance(), |
|
| 587 | - $att_field_name, |
|
| 588 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
| 589 | - ); |
|
| 590 | - } |
|
| 591 | - } else { |
|
| 592 | - $value = ''; |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - $reg_csv_array[ $this->_get_column_name_for_field($field_obj) ] = $value; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - // make sure each registration has the same questions in the same order |
|
| 599 | - foreach ($questions_for_these_regs_rows as $question_row) { |
|
| 600 | - if (! isset($reg_csv_array[ $question_row['Question.QST_admin_label'] ])) { |
|
| 601 | - $reg_csv_array[ $question_row['Question.QST_admin_label'] ] = null; |
|
| 602 | - } |
|
| 603 | - } |
|
| 604 | - // now fill out the questions THEY answered |
|
| 605 | - foreach ( |
|
| 606 | - EEM_Answer::instance()->get_all_wpdb_results( |
|
| 607 | - array(array('REG_ID' => $reg_row['Registration.REG_ID']), 'force_join' => array('Question')) |
|
| 608 | - ) as $answer_row |
|
| 609 | - ) { |
|
| 610 | - /* @var $answer EE_Answer */ |
|
| 611 | - if ($answer_row['Question.QST_ID']) { |
|
| 612 | - $question_label = $this->_prepare_value_from_db_for_display( |
|
| 613 | - EEM_Question::instance(), |
|
| 614 | - 'QST_admin_label', |
|
| 615 | - $answer_row['Question.QST_admin_label'] |
|
| 616 | - ); |
|
| 617 | - } else { |
|
| 618 | - $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
| 619 | - } |
|
| 620 | - if (isset($answer_row['Question.QST_type']) && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state) { |
|
| 621 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
| 622 | - $answer_row['Answer.ANS_value'] |
|
| 623 | - ); |
|
| 624 | - } else { |
|
| 625 | - $reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display( |
|
| 626 | - EEM_Answer::instance(), |
|
| 627 | - 'ANS_value', |
|
| 628 | - $answer_row['Answer.ANS_value'] |
|
| 629 | - ); |
|
| 630 | - } |
|
| 631 | - } |
|
| 632 | - $registrations_csv_ready_array[] = apply_filters( |
|
| 633 | - 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
| 634 | - $reg_csv_array, |
|
| 635 | - $reg_row |
|
| 636 | - ); |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - // if we couldn't export anything, we want to at least show the column headers |
|
| 641 | - if (empty($registrations_csv_ready_array)) { |
|
| 642 | - $reg_csv_array = array(); |
|
| 643 | - $model_and_fields_to_include = array( |
|
| 644 | - 'Registration' => $reg_fields_to_include, |
|
| 645 | - 'Attendee' => $att_fields_to_include, |
|
| 646 | - ); |
|
| 647 | - foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
| 648 | - $model = EE_Registry::instance()->load_model($model_name); |
|
| 649 | - foreach ($field_list as $field_name) { |
|
| 650 | - $field = $model->field_settings_for($field_name); |
|
| 651 | - $reg_csv_array[ $this->_get_column_name_for_field( |
|
| 652 | - $field |
|
| 653 | - ) ] = null;// $registration->get($field->get_name()); |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - $registrations_csv_ready_array [] = $reg_csv_array; |
|
| 657 | - } |
|
| 658 | - if ($event_id) { |
|
| 659 | - $event_slug = EEM_Event::instance()->get_var(array(array('EVT_ID' => $event_id)), 'EVT_slug'); |
|
| 660 | - if (! $event_slug) { |
|
| 661 | - $event_slug = __('unknown', 'event_espresso'); |
|
| 662 | - } |
|
| 663 | - } else { |
|
| 664 | - $event_slug = __('all', 'event_espresso'); |
|
| 665 | - } |
|
| 666 | - $filename = sprintf("registrations-for-%s", $event_slug); |
|
| 667 | - |
|
| 668 | - $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
| 669 | - $this->EE_CSV->write_data_array_to_csv($handle, $registrations_csv_ready_array); |
|
| 670 | - $this->EE_CSV->end_sending_csv($handle); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * Gets the 'normal' column named for fields |
|
| 675 | - * |
|
| 676 | - * @param EE_Model_Field_Base $field |
|
| 677 | - * @return string |
|
| 678 | - */ |
|
| 679 | - protected function _get_column_name_for_field(EE_Model_Field_Base $field) |
|
| 680 | - { |
|
| 681 | - return $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * @Export data for ALL events |
|
| 687 | - * @access public |
|
| 688 | - * @return void |
|
| 689 | - */ |
|
| 690 | - public function export_categories() |
|
| 691 | - { |
|
| 692 | - // are any Event IDs set? |
|
| 693 | - $query_params = array(); |
|
| 694 | - if (isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 695 | - // do we have an array of IDs ? |
|
| 696 | - if (is_array($this->_req_data['EVT_CAT_ID'])) { |
|
| 697 | - // generate an "IN (CSV)" where clause |
|
| 698 | - $EVT_CAT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_CAT_ID']); |
|
| 699 | - $filename = 'event-categories'; |
|
| 700 | - $query_params[0]['term_taxonomy_id'] = array('IN', $EVT_CAT_IDs); |
|
| 701 | - } else { |
|
| 702 | - // generate regular where = clause |
|
| 703 | - $EVT_CAT_ID = absint($this->_req_data['EVT_CAT_ID']); |
|
| 704 | - $filename = 'event-category#' . $EVT_CAT_ID; |
|
| 705 | - $query_params[0]['term_taxonomy_id'] = $EVT_CAT_ID; |
|
| 706 | - } |
|
| 707 | - } else { |
|
| 708 | - // no IDs means we will d/l the entire table |
|
| 709 | - $filename = 'all-categories'; |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - $tables_to_export = array( |
|
| 713 | - 'Term_Taxonomy' => $query_params, |
|
| 714 | - ); |
|
| 715 | - |
|
| 716 | - $table_data = $this->_get_export_data_for_models($tables_to_export); |
|
| 717 | - $filename = $this->generate_filename($filename); |
|
| 718 | - |
|
| 719 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) { |
|
| 720 | - EE_Error::add_error( |
|
| 721 | - __( |
|
| 722 | - 'An error occurred and the Category details could not be exported from the database.', |
|
| 723 | - 'event_espresso' |
|
| 724 | - ), |
|
| 725 | - __FILE__, |
|
| 726 | - __FUNCTION__, |
|
| 727 | - __LINE__ |
|
| 728 | - ); |
|
| 729 | - } |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * @process export name to create a suitable filename |
|
| 735 | - * @access private |
|
| 736 | - * @param string - export_name |
|
| 737 | - * @return string on success, FALSE on fail |
|
| 738 | - */ |
|
| 739 | - private function generate_filename($export_name = '') |
|
| 740 | - { |
|
| 741 | - if ($export_name != '') { |
|
| 742 | - $filename = get_bloginfo('name') . '-' . $export_name; |
|
| 743 | - $filename = sanitize_key($filename) . '-' . $this->today; |
|
| 744 | - return $filename; |
|
| 745 | - } else { |
|
| 746 | - EE_Error::add_error(__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
| 747 | - } |
|
| 748 | - return false; |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - |
|
| 752 | - /** |
|
| 753 | - * @recursive function for exporting table data and merging the results with the next results |
|
| 754 | - * @access private |
|
| 755 | - * @param array $models_to_export keys are model names (eg 'Event', 'Attendee', etc.) and values are arrays of |
|
| 756 | - * query params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 757 | - * @return array on success, FALSE on fail |
|
| 758 | - */ |
|
| 759 | - private function _get_export_data_for_models($models_to_export = array()) |
|
| 760 | - { |
|
| 761 | - $table_data = false; |
|
| 762 | - if (is_array($models_to_export)) { |
|
| 763 | - foreach ($models_to_export as $model_name => $query_params) { |
|
| 764 | - // check for a numerically-indexed array. in that case, $model_name is the value!! |
|
| 765 | - if (is_int($model_name)) { |
|
| 766 | - $model_name = $query_params; |
|
| 767 | - $query_params = array(); |
|
| 768 | - } |
|
| 769 | - $model = EE_Registry::instance()->load_model($model_name); |
|
| 770 | - $model_objects = $model->get_all($query_params); |
|
| 771 | - |
|
| 772 | - $table_data[ $model_name ] = array(); |
|
| 773 | - foreach ($model_objects as $model_object) { |
|
| 774 | - $model_data_array = array(); |
|
| 775 | - $fields = $model->field_settings(); |
|
| 776 | - foreach ($fields as $field) { |
|
| 777 | - $column_name = $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
| 778 | - if ($field instanceof EE_Datetime_Field) { |
|
| 779 | - // $field->set_date_format('Y-m-d'); |
|
| 780 | - // $field->set_time_format('H:i:s'); |
|
| 781 | - $model_data_array[ $column_name ] = $model_object->get_datetime( |
|
| 782 | - $field->get_name(), |
|
| 783 | - 'Y-m-d', |
|
| 784 | - 'H:i:s' |
|
| 785 | - ); |
|
| 786 | - } else { |
|
| 787 | - $model_data_array[ $column_name ] = $model_object->get($field->get_name()); |
|
| 788 | - } |
|
| 789 | - } |
|
| 790 | - $table_data[ $model_name ][] = $model_data_array; |
|
| 791 | - } |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - return $table_data; |
|
| 795 | - } |
|
| 19 | + const option_prefix = 'ee_report_job_'; |
|
| 20 | + |
|
| 21 | + |
|
| 22 | + // instance of the EE_Export object |
|
| 23 | + private static $_instance = null; |
|
| 24 | + |
|
| 25 | + // instance of the EE_CSV object |
|
| 26 | + /** |
|
| 27 | + * |
|
| 28 | + * @var EE_CSV |
|
| 29 | + */ |
|
| 30 | + public $EE_CSV = null; |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + private $_req_data = array(); |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * private constructor to prevent direct creation |
|
| 38 | + * |
|
| 39 | + * @Constructor |
|
| 40 | + * @access private |
|
| 41 | + * @param array $request_data |
|
| 42 | + */ |
|
| 43 | + private function __construct($request_data = array()) |
|
| 44 | + { |
|
| 45 | + $this->_req_data = $request_data; |
|
| 46 | + $this->today = date("Y-m-d", time()); |
|
| 47 | + require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
| 48 | + $this->EE_CSV = EE_CSV::instance(); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @ singleton method used to instantiate class object |
|
| 54 | + * @ access public |
|
| 55 | + * |
|
| 56 | + * @param array $request_data |
|
| 57 | + * @return \EE_Export |
|
| 58 | + */ |
|
| 59 | + public static function instance($request_data = array()) |
|
| 60 | + { |
|
| 61 | + // check if class object is instantiated |
|
| 62 | + if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Export)) { |
|
| 63 | + self::$_instance = new self($request_data); |
|
| 64 | + } |
|
| 65 | + return self::$_instance; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @Export Event Espresso data - routes export requests |
|
| 71 | + * @access public |
|
| 72 | + * @return void | bool |
|
| 73 | + */ |
|
| 74 | + public function export() |
|
| 75 | + { |
|
| 76 | + // in case of bulk exports, the "actual" action will be in action2, but first check regular action for "export" keyword |
|
| 77 | + if (isset($this->_req_data['action']) && strpos($this->_req_data['action'], 'export') === false) { |
|
| 78 | + // check if action2 has export action |
|
| 79 | + if (isset($this->_req_data['action2']) && strpos($this->_req_data['action2'], 'export') !== false) { |
|
| 80 | + // whoop! there it is! |
|
| 81 | + $this->_req_data['action'] = $this->_req_data['action2']; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + $this->_req_data['export'] = isset($this->_req_data['export']) ? $this->_req_data['export'] : ''; |
|
| 86 | + |
|
| 87 | + switch ($this->_req_data['export']) { |
|
| 88 | + case 'report': |
|
| 89 | + switch ($this->_req_data['action']) { |
|
| 90 | + case "event": |
|
| 91 | + case "export_events": |
|
| 92 | + case 'all_event_data': |
|
| 93 | + $this->export_all_event_data(); |
|
| 94 | + break; |
|
| 95 | + |
|
| 96 | + case 'registrations_report_for_event': |
|
| 97 | + $this->report_registrations_for_event($this->_req_data['EVT_ID']); |
|
| 98 | + break; |
|
| 99 | + |
|
| 100 | + case 'attendees': |
|
| 101 | + $this->export_attendees(); |
|
| 102 | + break; |
|
| 103 | + |
|
| 104 | + case 'categories': |
|
| 105 | + $this->export_categories(); |
|
| 106 | + break; |
|
| 107 | + |
|
| 108 | + default: |
|
| 109 | + EE_Error::add_error( |
|
| 110 | + __('An error occurred! The requested export report could not be found.', 'event_espresso'), |
|
| 111 | + __FILE__, |
|
| 112 | + __FUNCTION__, |
|
| 113 | + __LINE__ |
|
| 114 | + ); |
|
| 115 | + return false; |
|
| 116 | + break; |
|
| 117 | + } |
|
| 118 | + break; // end of switch export : report |
|
| 119 | + default: |
|
| 120 | + break; |
|
| 121 | + } // end of switch export |
|
| 122 | + |
|
| 123 | + exit; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Downloads a CSV file with all the columns, but no data. This should be used for importing |
|
| 128 | + * |
|
| 129 | + * @return null kills execution |
|
| 130 | + */ |
|
| 131 | + public function export_sample() |
|
| 132 | + { |
|
| 133 | + $event = EEM_Event::instance()->get_one(); |
|
| 134 | + $this->_req_data['EVT_ID'] = $event->ID(); |
|
| 135 | + $this->export_all_event_data(); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @Export data for ALL events |
|
| 141 | + * @access public |
|
| 142 | + * @return void |
|
| 143 | + */ |
|
| 144 | + public function export_all_event_data() |
|
| 145 | + { |
|
| 146 | + // are any Event IDs set? |
|
| 147 | + $event_query_params = array(); |
|
| 148 | + $related_models_query_params = array(); |
|
| 149 | + $related_through_reg_query_params = array(); |
|
| 150 | + $datetime_ticket_query_params = array(); |
|
| 151 | + $price_query_params = array(); |
|
| 152 | + $price_type_query_params = array(); |
|
| 153 | + $term_query_params = array(); |
|
| 154 | + $state_country_query_params = array(); |
|
| 155 | + $question_group_query_params = array(); |
|
| 156 | + $question_query_params = array(); |
|
| 157 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 158 | + // do we have an array of IDs ? |
|
| 159 | + |
|
| 160 | + if (is_array($this->_req_data['EVT_ID'])) { |
|
| 161 | + $EVT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_ID']); |
|
| 162 | + $value_to_equal = array('IN', $EVT_IDs); |
|
| 163 | + $filename = 'events'; |
|
| 164 | + } else { |
|
| 165 | + // generate regular where = clause |
|
| 166 | + $EVT_ID = absint($this->_req_data['EVT_ID']); |
|
| 167 | + $value_to_equal = $EVT_ID; |
|
| 168 | + $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($EVT_ID); |
|
| 169 | + |
|
| 170 | + $filename = 'event-' . ($event instanceof EE_Event ? $event->slug() : __('unknown', 'event_espresso')); |
|
| 171 | + } |
|
| 172 | + $event_query_params[0]['EVT_ID'] = $value_to_equal; |
|
| 173 | + $related_models_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
|
| 174 | + $related_through_reg_query_params[0]['Registration.EVT_ID'] = $value_to_equal; |
|
| 175 | + $datetime_ticket_query_params[0]['Datetime.EVT_ID'] = $value_to_equal; |
|
| 176 | + $price_query_params[0]['Ticket.Datetime.EVT_ID'] = $value_to_equal; |
|
| 177 | + $price_type_query_params[0]['Price.Ticket.Datetime.EVT_ID'] = $value_to_equal; |
|
| 178 | + $term_query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $value_to_equal; |
|
| 179 | + $state_country_query_params[0]['Venue.Event.EVT_ID'] = $value_to_equal; |
|
| 180 | + $question_group_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
|
| 181 | + $question_query_params[0]['Question_Group.Event.EVT_ID'] = $value_to_equal; |
|
| 182 | + } else { |
|
| 183 | + $filename = 'all-events'; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + // array in the format: table name => query where clause |
|
| 188 | + $models_to_export = array( |
|
| 189 | + 'Event' => $event_query_params, |
|
| 190 | + 'Datetime' => $related_models_query_params, |
|
| 191 | + 'Ticket_Template' => $price_query_params, |
|
| 192 | + 'Ticket' => $datetime_ticket_query_params, |
|
| 193 | + 'Datetime_Ticket' => $datetime_ticket_query_params, |
|
| 194 | + 'Price_Type' => $price_type_query_params, |
|
| 195 | + 'Price' => $price_query_params, |
|
| 196 | + 'Ticket_Price' => $price_query_params, |
|
| 197 | + 'Term' => $term_query_params, |
|
| 198 | + 'Term_Taxonomy' => $related_models_query_params, |
|
| 199 | + 'Term_Relationship' => $related_models_query_params, // model has NO primary key... |
|
| 200 | + 'Country' => $state_country_query_params, |
|
| 201 | + 'State' => $state_country_query_params, |
|
| 202 | + 'Venue' => $related_models_query_params, |
|
| 203 | + 'Event_Venue' => $related_models_query_params, |
|
| 204 | + 'Question_Group' => $question_group_query_params, |
|
| 205 | + 'Event_Question_Group' => $question_group_query_params, |
|
| 206 | + 'Question' => $question_query_params, |
|
| 207 | + 'Question_Group_Question' => $question_query_params, |
|
| 208 | + // 'Transaction'=>$related_through_reg_query_params, |
|
| 209 | + // 'Registration'=>$related_models_query_params, |
|
| 210 | + // 'Attendee'=>$related_through_reg_query_params, |
|
| 211 | + // 'Line_Item'=> |
|
| 212 | + |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + $model_data = $this->_get_export_data_for_models($models_to_export); |
|
| 216 | + |
|
| 217 | + $filename = $this->generate_filename($filename); |
|
| 218 | + |
|
| 219 | + if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
| 220 | + EE_Error::add_error( |
|
| 221 | + __( |
|
| 222 | + "'An error occurred and the Event details could not be exported from the database.'", |
|
| 223 | + "event_espresso" |
|
| 224 | + ), |
|
| 225 | + __FILE__, |
|
| 226 | + __FUNCTION__, |
|
| 227 | + __LINE__ |
|
| 228 | + ); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + public function report_attendees() |
|
| 233 | + { |
|
| 234 | + $attendee_rows = EEM_Attendee::instance()->get_all_wpdb_results( |
|
| 235 | + array( |
|
| 236 | + 'force_join' => array('State', 'Country'), |
|
| 237 | + 'caps' => EEM_Base::caps_read_admin, |
|
| 238 | + ) |
|
| 239 | + ); |
|
| 240 | + $csv_data = array(); |
|
| 241 | + foreach ($attendee_rows as $attendee_row) { |
|
| 242 | + $csv_row = array(); |
|
| 243 | + foreach (EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
|
| 244 | + if ($field_name == 'STA_ID') { |
|
| 245 | + $state_name_field = EEM_State::instance()->field_settings_for('STA_name'); |
|
| 246 | + $csv_row[ __('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column( |
|
| 247 | + ) ]; |
|
| 248 | + } elseif ($field_name == 'CNT_ISO') { |
|
| 249 | + $country_name_field = EEM_Country::instance()->field_settings_for('CNT_name'); |
|
| 250 | + $csv_row[ __( |
|
| 251 | + 'Country', |
|
| 252 | + 'event_espresso' |
|
| 253 | + ) ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
| 254 | + } else { |
|
| 255 | + $csv_row[ $field_obj->get_nicename() ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + $csv_data[] = $csv_row; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + $filename = $this->generate_filename('contact-list-report'); |
|
| 262 | + |
|
| 263 | + $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
| 264 | + $this->EE_CSV->write_data_array_to_csv($handle, $csv_data); |
|
| 265 | + $this->EE_CSV->end_sending_csv($handle); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * @Export data for ALL attendees |
|
| 271 | + * @access public |
|
| 272 | + * @return void |
|
| 273 | + */ |
|
| 274 | + public function export_attendees() |
|
| 275 | + { |
|
| 276 | + |
|
| 277 | + $states_that_have_an_attendee = EEM_State::instance()->get_all( |
|
| 278 | + array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL'))) |
|
| 279 | + ); |
|
| 280 | + $countries_that_have_an_attendee = EEM_Country::instance()->get_all( |
|
| 281 | + array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL'))) |
|
| 282 | + ); |
|
| 283 | + // $states_to_export_query_params |
|
| 284 | + $models_to_export = array( |
|
| 285 | + 'Country' => array(array('CNT_ISO' => array('IN', array_keys($countries_that_have_an_attendee)))), |
|
| 286 | + 'State' => array(array('STA_ID' => array('IN', array_keys($states_that_have_an_attendee)))), |
|
| 287 | + 'Attendee' => array(), |
|
| 288 | + ); |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + $model_data = $this->_get_export_data_for_models($models_to_export); |
|
| 292 | + $filename = $this->generate_filename('all-attendees'); |
|
| 293 | + |
|
| 294 | + if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
| 295 | + EE_Error::add_error( |
|
| 296 | + __( |
|
| 297 | + 'An error occurred and the Attendee data could not be exported from the database.', |
|
| 298 | + 'event_espresso' |
|
| 299 | + ), |
|
| 300 | + __FILE__, |
|
| 301 | + __FUNCTION__, |
|
| 302 | + __LINE__ |
|
| 303 | + ); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Shortcut for preparing a database result for display |
|
| 309 | + * |
|
| 310 | + * @param EEM_Base $model |
|
| 311 | + * @param string $field_name |
|
| 312 | + * @param string $raw_db_value |
|
| 313 | + * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to |
|
| 314 | + * NOT display pretty |
|
| 315 | + * @return string |
|
| 316 | + */ |
|
| 317 | + protected function _prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true) |
|
| 318 | + { |
|
| 319 | + $field_obj = $model->field_settings_for($field_name); |
|
| 320 | + $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
| 321 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 322 | + $field_obj->set_date_format( |
|
| 323 | + EE_CSV::instance()->get_date_format_for_csv($field_obj->get_date_format($pretty_schema)), |
|
| 324 | + $pretty_schema |
|
| 325 | + ); |
|
| 326 | + $field_obj->set_time_format( |
|
| 327 | + EE_CSV::instance()->get_time_format_for_csv($field_obj->get_time_format($pretty_schema)), |
|
| 328 | + $pretty_schema |
|
| 329 | + ); |
|
| 330 | + } |
|
| 331 | + if ($pretty_schema === true) { |
|
| 332 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
| 333 | + } elseif (is_string($pretty_schema)) { |
|
| 334 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
| 335 | + } else { |
|
| 336 | + return $field_obj->prepare_for_get($value_on_model_obj); |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Export a custom CSV of registration info including: A bunch of the reg fields, the time of the event, the price |
|
| 342 | + * name, and the questions associated with the registrations |
|
| 343 | + * |
|
| 344 | + * @param int $event_id |
|
| 345 | + */ |
|
| 346 | + public function report_registrations_for_event($event_id = null) |
|
| 347 | + { |
|
| 348 | + $reg_fields_to_include = array( |
|
| 349 | + 'TXN_ID', |
|
| 350 | + 'ATT_ID', |
|
| 351 | + 'REG_ID', |
|
| 352 | + 'REG_date', |
|
| 353 | + 'REG_code', |
|
| 354 | + 'REG_count', |
|
| 355 | + 'REG_final_price', |
|
| 356 | + |
|
| 357 | + ); |
|
| 358 | + $att_fields_to_include = array( |
|
| 359 | + 'ATT_fname', |
|
| 360 | + 'ATT_lname', |
|
| 361 | + 'ATT_email', |
|
| 362 | + 'ATT_address', |
|
| 363 | + 'ATT_address2', |
|
| 364 | + 'ATT_city', |
|
| 365 | + 'STA_ID', |
|
| 366 | + 'CNT_ISO', |
|
| 367 | + 'ATT_zip', |
|
| 368 | + 'ATT_phone', |
|
| 369 | + ); |
|
| 370 | + |
|
| 371 | + $registrations_csv_ready_array = array(); |
|
| 372 | + $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
| 373 | + $query_params = apply_filters( |
|
| 374 | + 'FHEE__EE_Export__report_registration_for_event', |
|
| 375 | + array( |
|
| 376 | + array( |
|
| 377 | + 'OR' => array( |
|
| 378 | + // don't include registrations from failed or abandoned transactions... |
|
| 379 | + 'Transaction.STS_ID' => array( |
|
| 380 | + 'NOT IN', |
|
| 381 | + array(EEM_Transaction::failed_status_code, EEM_Transaction::abandoned_status_code), |
|
| 382 | + ), |
|
| 383 | + // unless the registration is approved, in which case include it regardless of transaction status |
|
| 384 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 385 | + ), |
|
| 386 | + 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
| 387 | + ), |
|
| 388 | + 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
| 389 | + 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
| 390 | + 'caps' => EEM_Base::caps_read_admin, |
|
| 391 | + ), |
|
| 392 | + $event_id |
|
| 393 | + ); |
|
| 394 | + if ($event_id) { |
|
| 395 | + $query_params[0]['EVT_ID'] = $event_id; |
|
| 396 | + } else { |
|
| 397 | + $query_params['force_join'][] = 'Event'; |
|
| 398 | + } |
|
| 399 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
| 400 | + // get all questions which relate to someone in this group |
|
| 401 | + $registration_ids = array(); |
|
| 402 | + foreach ($registration_rows as $reg_row) { |
|
| 403 | + $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
| 404 | + } |
|
| 405 | + // EEM_Question::instance()->show_next_x_db_queries(); |
|
| 406 | + $questions_for_these_regs_rows = EEM_Question::instance()->get_all_wpdb_results( |
|
| 407 | + array(array('Answer.REG_ID' => array('IN', $registration_ids))) |
|
| 408 | + ); |
|
| 409 | + foreach ($registration_rows as $reg_row) { |
|
| 410 | + if (is_array($reg_row)) { |
|
| 411 | + $reg_csv_array = array(); |
|
| 412 | + if (! $event_id) { |
|
| 413 | + // get the event's name and Id |
|
| 414 | + $reg_csv_array[ __('Event', 'event_espresso') ] = sprintf( |
|
| 415 | + __('%1$s (%2$s)', 'event_espresso'), |
|
| 416 | + $this->_prepare_value_from_db_for_display( |
|
| 417 | + EEM_Event::instance(), |
|
| 418 | + 'EVT_name', |
|
| 419 | + $reg_row['Event_CPT.post_title'] |
|
| 420 | + ), |
|
| 421 | + $reg_row['Event_CPT.ID'] |
|
| 422 | + ); |
|
| 423 | + } |
|
| 424 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
| 425 | + /*@var $reg_row EE_Registration */ |
|
| 426 | + foreach ($reg_fields_to_include as $field_name) { |
|
| 427 | + $field = $reg_model->field_settings_for($field_name); |
|
| 428 | + if ($field_name == 'REG_final_price') { |
|
| 429 | + $value = $this->_prepare_value_from_db_for_display( |
|
| 430 | + $reg_model, |
|
| 431 | + $field_name, |
|
| 432 | + $reg_row['Registration.REG_final_price'], |
|
| 433 | + 'localized_float' |
|
| 434 | + ); |
|
| 435 | + } elseif ($field_name == 'REG_count') { |
|
| 436 | + $value = sprintf( |
|
| 437 | + __('%s of %s', 'event_espresso'), |
|
| 438 | + $this->_prepare_value_from_db_for_display( |
|
| 439 | + $reg_model, |
|
| 440 | + 'REG_count', |
|
| 441 | + $reg_row['Registration.REG_count'] |
|
| 442 | + ), |
|
| 443 | + $this->_prepare_value_from_db_for_display( |
|
| 444 | + $reg_model, |
|
| 445 | + 'REG_group_size', |
|
| 446 | + $reg_row['Registration.REG_group_size'] |
|
| 447 | + ) |
|
| 448 | + ); |
|
| 449 | + } elseif ($field_name == 'REG_date') { |
|
| 450 | + $value = $this->_prepare_value_from_db_for_display( |
|
| 451 | + $reg_model, |
|
| 452 | + $field_name, |
|
| 453 | + $reg_row['Registration.REG_date'], |
|
| 454 | + 'no_html' |
|
| 455 | + ); |
|
| 456 | + } else { |
|
| 457 | + $value = $this->_prepare_value_from_db_for_display( |
|
| 458 | + $reg_model, |
|
| 459 | + $field_name, |
|
| 460 | + $reg_row[ $field->get_qualified_column() ] |
|
| 461 | + ); |
|
| 462 | + } |
|
| 463 | + $reg_csv_array[ $this->_get_column_name_for_field($field) ] = $value; |
|
| 464 | + if ($field_name == 'REG_final_price') { |
|
| 465 | + // add a column named Currency after the final price |
|
| 466 | + $reg_csv_array[ __("Currency", "event_espresso") ] = EE_Config::instance()->currency->code; |
|
| 467 | + } |
|
| 468 | + } |
|
| 469 | + // get pretty status |
|
| 470 | + $stati = EEM_Status::instance()->localized_status( |
|
| 471 | + array( |
|
| 472 | + $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
| 473 | + $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
| 474 | + ), |
|
| 475 | + false, |
|
| 476 | + 'sentence' |
|
| 477 | + ); |
|
| 478 | + $reg_csv_array[ __( |
|
| 479 | + "Registration Status", |
|
| 480 | + 'event_espresso' |
|
| 481 | + ) ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
| 482 | + // get pretty trnasaction status |
|
| 483 | + $reg_csv_array[ __( |
|
| 484 | + "Transaction Status", |
|
| 485 | + 'event_espresso' |
|
| 486 | + ) ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
| 487 | + $reg_csv_array[ __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
| 488 | + ? $this->_prepare_value_from_db_for_display( |
|
| 489 | + EEM_Transaction::instance(), |
|
| 490 | + 'TXN_total', |
|
| 491 | + $reg_row['TransactionTable.TXN_total'], |
|
| 492 | + 'localized_float' |
|
| 493 | + ) : '0.00'; |
|
| 494 | + $reg_csv_array[ __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
| 495 | + ? $this->_prepare_value_from_db_for_display( |
|
| 496 | + EEM_Transaction::instance(), |
|
| 497 | + 'TXN_paid', |
|
| 498 | + $reg_row['TransactionTable.TXN_paid'], |
|
| 499 | + 'localized_float' |
|
| 500 | + ) : '0.00'; |
|
| 501 | + $payment_methods = array(); |
|
| 502 | + $gateway_txn_ids_etc = array(); |
|
| 503 | + $payment_times = array(); |
|
| 504 | + if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
| 505 | + $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
| 506 | + array( |
|
| 507 | + array( |
|
| 508 | + 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
| 509 | + 'STS_ID' => EEM_Payment::status_id_approved, |
|
| 510 | + ), |
|
| 511 | + 'force_join' => array('Payment_Method'), |
|
| 512 | + ), |
|
| 513 | + ARRAY_A, |
|
| 514 | + 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
| 515 | + ); |
|
| 516 | + |
|
| 517 | + foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
| 518 | + $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
| 519 | + ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
| 520 | + $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
| 521 | + ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
| 522 | + $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
| 523 | + ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + $reg_csv_array[ __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
| 527 | + $reg_csv_array[ __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
| 528 | + $reg_csv_array[ __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
| 529 | + ',', |
|
| 530 | + $gateway_txn_ids_etc |
|
| 531 | + ); |
|
| 532 | + |
|
| 533 | + // get whether or not the user has checked in |
|
| 534 | + $reg_csv_array[ __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
| 535 | + $reg_row['Registration.REG_ID'], |
|
| 536 | + 'Checkin' |
|
| 537 | + ); |
|
| 538 | + // get ticket of registration and its price |
|
| 539 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 540 | + if ($reg_row['Ticket.TKT_ID']) { |
|
| 541 | + $ticket_name = $this->_prepare_value_from_db_for_display( |
|
| 542 | + $ticket_model, |
|
| 543 | + 'TKT_name', |
|
| 544 | + $reg_row['Ticket.TKT_name'] |
|
| 545 | + ); |
|
| 546 | + $datetimes_strings = array(); |
|
| 547 | + foreach ( |
|
| 548 | + EEM_Datetime::instance()->get_all_wpdb_results( |
|
| 549 | + array( |
|
| 550 | + array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
| 551 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 552 | + 'default_where_conditions' => 'none', |
|
| 553 | + ) |
|
| 554 | + ) as $datetime |
|
| 555 | + ) { |
|
| 556 | + $datetimes_strings[] = $this->_prepare_value_from_db_for_display( |
|
| 557 | + EEM_Datetime::instance(), |
|
| 558 | + 'DTT_EVT_start', |
|
| 559 | + $datetime['Datetime.DTT_EVT_start'] |
|
| 560 | + ); |
|
| 561 | + } |
|
| 562 | + } else { |
|
| 563 | + $ticket_name = __('Unknown', 'event_espresso'); |
|
| 564 | + $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
| 565 | + } |
|
| 566 | + $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
| 567 | + $reg_csv_array[ __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
| 568 | + // get datetime(s) of registration |
|
| 569 | + |
|
| 570 | + // add attendee columns |
|
| 571 | + foreach ($att_fields_to_include as $att_field_name) { |
|
| 572 | + $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
| 573 | + if ($reg_row['Attendee_CPT.ID']) { |
|
| 574 | + if ($att_field_name == 'STA_ID') { |
|
| 575 | + $value = EEM_State::instance()->get_var( |
|
| 576 | + array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
| 577 | + 'STA_name' |
|
| 578 | + ); |
|
| 579 | + } elseif ($att_field_name == 'CNT_ISO') { |
|
| 580 | + $value = EEM_Country::instance()->get_var( |
|
| 581 | + array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
| 582 | + 'CNT_name' |
|
| 583 | + ); |
|
| 584 | + } else { |
|
| 585 | + $value = $this->_prepare_value_from_db_for_display( |
|
| 586 | + EEM_Attendee::instance(), |
|
| 587 | + $att_field_name, |
|
| 588 | + $reg_row[ $field_obj->get_qualified_column() ] |
|
| 589 | + ); |
|
| 590 | + } |
|
| 591 | + } else { |
|
| 592 | + $value = ''; |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + $reg_csv_array[ $this->_get_column_name_for_field($field_obj) ] = $value; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + // make sure each registration has the same questions in the same order |
|
| 599 | + foreach ($questions_for_these_regs_rows as $question_row) { |
|
| 600 | + if (! isset($reg_csv_array[ $question_row['Question.QST_admin_label'] ])) { |
|
| 601 | + $reg_csv_array[ $question_row['Question.QST_admin_label'] ] = null; |
|
| 602 | + } |
|
| 603 | + } |
|
| 604 | + // now fill out the questions THEY answered |
|
| 605 | + foreach ( |
|
| 606 | + EEM_Answer::instance()->get_all_wpdb_results( |
|
| 607 | + array(array('REG_ID' => $reg_row['Registration.REG_ID']), 'force_join' => array('Question')) |
|
| 608 | + ) as $answer_row |
|
| 609 | + ) { |
|
| 610 | + /* @var $answer EE_Answer */ |
|
| 611 | + if ($answer_row['Question.QST_ID']) { |
|
| 612 | + $question_label = $this->_prepare_value_from_db_for_display( |
|
| 613 | + EEM_Question::instance(), |
|
| 614 | + 'QST_admin_label', |
|
| 615 | + $answer_row['Question.QST_admin_label'] |
|
| 616 | + ); |
|
| 617 | + } else { |
|
| 618 | + $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
| 619 | + } |
|
| 620 | + if (isset($answer_row['Question.QST_type']) && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state) { |
|
| 621 | + $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
| 622 | + $answer_row['Answer.ANS_value'] |
|
| 623 | + ); |
|
| 624 | + } else { |
|
| 625 | + $reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display( |
|
| 626 | + EEM_Answer::instance(), |
|
| 627 | + 'ANS_value', |
|
| 628 | + $answer_row['Answer.ANS_value'] |
|
| 629 | + ); |
|
| 630 | + } |
|
| 631 | + } |
|
| 632 | + $registrations_csv_ready_array[] = apply_filters( |
|
| 633 | + 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
| 634 | + $reg_csv_array, |
|
| 635 | + $reg_row |
|
| 636 | + ); |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + // if we couldn't export anything, we want to at least show the column headers |
|
| 641 | + if (empty($registrations_csv_ready_array)) { |
|
| 642 | + $reg_csv_array = array(); |
|
| 643 | + $model_and_fields_to_include = array( |
|
| 644 | + 'Registration' => $reg_fields_to_include, |
|
| 645 | + 'Attendee' => $att_fields_to_include, |
|
| 646 | + ); |
|
| 647 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
| 648 | + $model = EE_Registry::instance()->load_model($model_name); |
|
| 649 | + foreach ($field_list as $field_name) { |
|
| 650 | + $field = $model->field_settings_for($field_name); |
|
| 651 | + $reg_csv_array[ $this->_get_column_name_for_field( |
|
| 652 | + $field |
|
| 653 | + ) ] = null;// $registration->get($field->get_name()); |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + $registrations_csv_ready_array [] = $reg_csv_array; |
|
| 657 | + } |
|
| 658 | + if ($event_id) { |
|
| 659 | + $event_slug = EEM_Event::instance()->get_var(array(array('EVT_ID' => $event_id)), 'EVT_slug'); |
|
| 660 | + if (! $event_slug) { |
|
| 661 | + $event_slug = __('unknown', 'event_espresso'); |
|
| 662 | + } |
|
| 663 | + } else { |
|
| 664 | + $event_slug = __('all', 'event_espresso'); |
|
| 665 | + } |
|
| 666 | + $filename = sprintf("registrations-for-%s", $event_slug); |
|
| 667 | + |
|
| 668 | + $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
| 669 | + $this->EE_CSV->write_data_array_to_csv($handle, $registrations_csv_ready_array); |
|
| 670 | + $this->EE_CSV->end_sending_csv($handle); |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * Gets the 'normal' column named for fields |
|
| 675 | + * |
|
| 676 | + * @param EE_Model_Field_Base $field |
|
| 677 | + * @return string |
|
| 678 | + */ |
|
| 679 | + protected function _get_column_name_for_field(EE_Model_Field_Base $field) |
|
| 680 | + { |
|
| 681 | + return $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * @Export data for ALL events |
|
| 687 | + * @access public |
|
| 688 | + * @return void |
|
| 689 | + */ |
|
| 690 | + public function export_categories() |
|
| 691 | + { |
|
| 692 | + // are any Event IDs set? |
|
| 693 | + $query_params = array(); |
|
| 694 | + if (isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 695 | + // do we have an array of IDs ? |
|
| 696 | + if (is_array($this->_req_data['EVT_CAT_ID'])) { |
|
| 697 | + // generate an "IN (CSV)" where clause |
|
| 698 | + $EVT_CAT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_CAT_ID']); |
|
| 699 | + $filename = 'event-categories'; |
|
| 700 | + $query_params[0]['term_taxonomy_id'] = array('IN', $EVT_CAT_IDs); |
|
| 701 | + } else { |
|
| 702 | + // generate regular where = clause |
|
| 703 | + $EVT_CAT_ID = absint($this->_req_data['EVT_CAT_ID']); |
|
| 704 | + $filename = 'event-category#' . $EVT_CAT_ID; |
|
| 705 | + $query_params[0]['term_taxonomy_id'] = $EVT_CAT_ID; |
|
| 706 | + } |
|
| 707 | + } else { |
|
| 708 | + // no IDs means we will d/l the entire table |
|
| 709 | + $filename = 'all-categories'; |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + $tables_to_export = array( |
|
| 713 | + 'Term_Taxonomy' => $query_params, |
|
| 714 | + ); |
|
| 715 | + |
|
| 716 | + $table_data = $this->_get_export_data_for_models($tables_to_export); |
|
| 717 | + $filename = $this->generate_filename($filename); |
|
| 718 | + |
|
| 719 | + if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) { |
|
| 720 | + EE_Error::add_error( |
|
| 721 | + __( |
|
| 722 | + 'An error occurred and the Category details could not be exported from the database.', |
|
| 723 | + 'event_espresso' |
|
| 724 | + ), |
|
| 725 | + __FILE__, |
|
| 726 | + __FUNCTION__, |
|
| 727 | + __LINE__ |
|
| 728 | + ); |
|
| 729 | + } |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * @process export name to create a suitable filename |
|
| 735 | + * @access private |
|
| 736 | + * @param string - export_name |
|
| 737 | + * @return string on success, FALSE on fail |
|
| 738 | + */ |
|
| 739 | + private function generate_filename($export_name = '') |
|
| 740 | + { |
|
| 741 | + if ($export_name != '') { |
|
| 742 | + $filename = get_bloginfo('name') . '-' . $export_name; |
|
| 743 | + $filename = sanitize_key($filename) . '-' . $this->today; |
|
| 744 | + return $filename; |
|
| 745 | + } else { |
|
| 746 | + EE_Error::add_error(__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
| 747 | + } |
|
| 748 | + return false; |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + |
|
| 752 | + /** |
|
| 753 | + * @recursive function for exporting table data and merging the results with the next results |
|
| 754 | + * @access private |
|
| 755 | + * @param array $models_to_export keys are model names (eg 'Event', 'Attendee', etc.) and values are arrays of |
|
| 756 | + * query params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 757 | + * @return array on success, FALSE on fail |
|
| 758 | + */ |
|
| 759 | + private function _get_export_data_for_models($models_to_export = array()) |
|
| 760 | + { |
|
| 761 | + $table_data = false; |
|
| 762 | + if (is_array($models_to_export)) { |
|
| 763 | + foreach ($models_to_export as $model_name => $query_params) { |
|
| 764 | + // check for a numerically-indexed array. in that case, $model_name is the value!! |
|
| 765 | + if (is_int($model_name)) { |
|
| 766 | + $model_name = $query_params; |
|
| 767 | + $query_params = array(); |
|
| 768 | + } |
|
| 769 | + $model = EE_Registry::instance()->load_model($model_name); |
|
| 770 | + $model_objects = $model->get_all($query_params); |
|
| 771 | + |
|
| 772 | + $table_data[ $model_name ] = array(); |
|
| 773 | + foreach ($model_objects as $model_object) { |
|
| 774 | + $model_data_array = array(); |
|
| 775 | + $fields = $model->field_settings(); |
|
| 776 | + foreach ($fields as $field) { |
|
| 777 | + $column_name = $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
| 778 | + if ($field instanceof EE_Datetime_Field) { |
|
| 779 | + // $field->set_date_format('Y-m-d'); |
|
| 780 | + // $field->set_time_format('H:i:s'); |
|
| 781 | + $model_data_array[ $column_name ] = $model_object->get_datetime( |
|
| 782 | + $field->get_name(), |
|
| 783 | + 'Y-m-d', |
|
| 784 | + 'H:i:s' |
|
| 785 | + ); |
|
| 786 | + } else { |
|
| 787 | + $model_data_array[ $column_name ] = $model_object->get($field->get_name()); |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | + $table_data[ $model_name ][] = $model_data_array; |
|
| 791 | + } |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + return $table_data; |
|
| 795 | + } |
|
| 796 | 796 | } |