@@ -30,7 +30,7 @@ |
||
| 30 | 30 | * @param array $props_n_values incoming values from the database |
| 31 | 31 | * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
| 32 | 32 | * the website will be used. |
| 33 | - * @return EE_Attendee |
|
| 33 | + * @return EE_Price |
|
| 34 | 34 | */ |
| 35 | 35 | public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
| 36 | 36 | { |
@@ -10,290 +10,290 @@ |
||
| 10 | 10 | class EE_Price extends EE_Soft_Delete_Base_Class |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * |
|
| 15 | - * @param array $props_n_values incoming values |
|
| 16 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 17 | - * used.) |
|
| 18 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 19 | - * date_format and the second value is the time format |
|
| 20 | - * @return EE_Attendee |
|
| 21 | - */ |
|
| 22 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 23 | - { |
|
| 24 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 25 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @param array $props_n_values incoming values from the database |
|
| 31 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 32 | - * the website will be used. |
|
| 33 | - * @return EE_Attendee |
|
| 34 | - */ |
|
| 35 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 36 | - { |
|
| 37 | - return new self($props_n_values, true, $timezone); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Set Price type ID |
|
| 43 | - * |
|
| 44 | - * @access public |
|
| 45 | - * @param int $PRT_ID |
|
| 46 | - */ |
|
| 47 | - public function set_type($PRT_ID = 0) |
|
| 48 | - { |
|
| 49 | - $this->set('PRT_ID', $PRT_ID); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Set Price Amount |
|
| 55 | - * |
|
| 56 | - * @access public |
|
| 57 | - * @param float $PRC_amount |
|
| 58 | - */ |
|
| 59 | - public function set_amount($PRC_amount = 0.00) |
|
| 60 | - { |
|
| 61 | - $this->set('PRC_amount', $PRC_amount); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Set Price Name |
|
| 67 | - * |
|
| 68 | - * @access public |
|
| 69 | - * @param string $PRC_name |
|
| 70 | - */ |
|
| 71 | - public function set_name($PRC_name = '') |
|
| 72 | - { |
|
| 73 | - $this->set('PRC_name', $PRC_name); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Set Price Description |
|
| 79 | - * |
|
| 80 | - * @access public |
|
| 81 | - * @param string $PRC_desc |
|
| 82 | - */ |
|
| 83 | - public function set_description($PRC_desc = '') |
|
| 84 | - { |
|
| 85 | - $this->Set('PRC_desc', $PRC_desc); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * set is_default |
|
| 91 | - * |
|
| 92 | - * @access public |
|
| 93 | - * @param bool $PRC_is_default |
|
| 94 | - */ |
|
| 95 | - public function set_is_default($PRC_is_default = false) |
|
| 96 | - { |
|
| 97 | - $this->set('PRC_is_default', $PRC_is_default); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * set deleted |
|
| 103 | - * |
|
| 104 | - * @access public |
|
| 105 | - * @param bool $PRC_deleted |
|
| 106 | - */ |
|
| 107 | - public function set_deleted($PRC_deleted = null) |
|
| 108 | - { |
|
| 109 | - $this->set('PRC_deleted', $PRC_deleted); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * get Price type |
|
| 115 | - * |
|
| 116 | - * @access public |
|
| 117 | - * @return int |
|
| 118 | - */ |
|
| 119 | - public function type() |
|
| 120 | - { |
|
| 121 | - return $this->get('PRT_ID'); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * get Price Amount |
|
| 127 | - * |
|
| 128 | - * @access public |
|
| 129 | - * @return float |
|
| 130 | - */ |
|
| 131 | - public function amount() |
|
| 132 | - { |
|
| 133 | - return $this->get('PRC_amount'); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * get Price Name |
|
| 139 | - * |
|
| 140 | - * @access public |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - public function name() |
|
| 144 | - { |
|
| 145 | - return $this->get('PRC_name'); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * get Price description |
|
| 151 | - * |
|
| 152 | - * @access public |
|
| 153 | - * @return string |
|
| 154 | - */ |
|
| 155 | - public function desc() |
|
| 156 | - { |
|
| 157 | - return $this->get('PRC_desc'); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * get overrides |
|
| 163 | - * |
|
| 164 | - * @access public |
|
| 165 | - * @return int |
|
| 166 | - */ |
|
| 167 | - public function overrides() |
|
| 168 | - { |
|
| 169 | - return $this->get('PRC_overrides'); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * get order |
|
| 175 | - * |
|
| 176 | - * @access public |
|
| 177 | - * @return int |
|
| 178 | - */ |
|
| 179 | - public function order() |
|
| 180 | - { |
|
| 181 | - return $this->get('PRC_order'); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * get the author of the price |
|
| 187 | - * |
|
| 188 | - * @since 4.5.0 |
|
| 189 | - * |
|
| 190 | - * @return int |
|
| 191 | - */ |
|
| 192 | - public function wp_user() |
|
| 193 | - { |
|
| 194 | - return $this->get('PRC_wp_user'); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * get is_default |
|
| 200 | - * |
|
| 201 | - * @access public |
|
| 202 | - * @return bool |
|
| 203 | - */ |
|
| 204 | - public function is_default() |
|
| 205 | - { |
|
| 206 | - return $this->get('PRC_is_default'); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * get deleted |
|
| 212 | - * |
|
| 213 | - * @access public |
|
| 214 | - * @return bool |
|
| 215 | - */ |
|
| 216 | - public function deleted() |
|
| 217 | - { |
|
| 218 | - return $this->get('PRC_deleted'); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * @return bool |
|
| 224 | - */ |
|
| 225 | - public function parent() |
|
| 226 | - { |
|
| 227 | - return $this->get('PRC_parent'); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - // some helper methods for getting info on the price_type for this price |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * return whether the price is a base price or not |
|
| 235 | - * |
|
| 236 | - * @return boolean |
|
| 237 | - */ |
|
| 238 | - public function is_base_price() |
|
| 239 | - { |
|
| 240 | - $price_type = $this->type_obj(); |
|
| 241 | - return $price_type->base_type() === 1; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * |
|
| 247 | - * @return EE_Price_Type |
|
| 248 | - */ |
|
| 249 | - public function type_obj() |
|
| 250 | - { |
|
| 251 | - return $this->get_first_related('Price_Type'); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Simply indicates whether this price increases or decreases the total |
|
| 257 | - * |
|
| 258 | - * @return boolean true = discount, otherwise adds to the total |
|
| 259 | - */ |
|
| 260 | - public function is_discount() |
|
| 261 | - { |
|
| 262 | - $price_type = $this->type_obj(); |
|
| 263 | - return $price_type->is_discount(); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * whether the price is a percentage or not |
|
| 269 | - * |
|
| 270 | - * @return boolean |
|
| 271 | - */ |
|
| 272 | - public function is_percent() |
|
| 273 | - { |
|
| 274 | - $price_type = $this->type_obj(); |
|
| 275 | - return $price_type->get('PRT_is_percent'); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * return pretty price dependant on whether its a dollar or percent. |
|
| 281 | - * |
|
| 282 | - * @since 4.4.0 |
|
| 283 | - * |
|
| 284 | - * @return string |
|
| 285 | - */ |
|
| 286 | - public function pretty_price() |
|
| 287 | - { |
|
| 288 | - return ! $this->is_percent() ? $this->get_pretty('PRC_amount') : $this->get('PRC_amount') . '%'; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * @return mixed |
|
| 294 | - */ |
|
| 295 | - public function get_price_without_currency_symbol() |
|
| 296 | - { |
|
| 297 | - return str_replace(EE_Registry::instance()->CFG->currency->sign, '', $this->get_pretty('PRC_amount')); |
|
| 298 | - } |
|
| 13 | + /** |
|
| 14 | + * |
|
| 15 | + * @param array $props_n_values incoming values |
|
| 16 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 17 | + * used.) |
|
| 18 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 19 | + * date_format and the second value is the time format |
|
| 20 | + * @return EE_Attendee |
|
| 21 | + */ |
|
| 22 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 23 | + { |
|
| 24 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 25 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @param array $props_n_values incoming values from the database |
|
| 31 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 32 | + * the website will be used. |
|
| 33 | + * @return EE_Attendee |
|
| 34 | + */ |
|
| 35 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 36 | + { |
|
| 37 | + return new self($props_n_values, true, $timezone); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Set Price type ID |
|
| 43 | + * |
|
| 44 | + * @access public |
|
| 45 | + * @param int $PRT_ID |
|
| 46 | + */ |
|
| 47 | + public function set_type($PRT_ID = 0) |
|
| 48 | + { |
|
| 49 | + $this->set('PRT_ID', $PRT_ID); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Set Price Amount |
|
| 55 | + * |
|
| 56 | + * @access public |
|
| 57 | + * @param float $PRC_amount |
|
| 58 | + */ |
|
| 59 | + public function set_amount($PRC_amount = 0.00) |
|
| 60 | + { |
|
| 61 | + $this->set('PRC_amount', $PRC_amount); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Set Price Name |
|
| 67 | + * |
|
| 68 | + * @access public |
|
| 69 | + * @param string $PRC_name |
|
| 70 | + */ |
|
| 71 | + public function set_name($PRC_name = '') |
|
| 72 | + { |
|
| 73 | + $this->set('PRC_name', $PRC_name); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Set Price Description |
|
| 79 | + * |
|
| 80 | + * @access public |
|
| 81 | + * @param string $PRC_desc |
|
| 82 | + */ |
|
| 83 | + public function set_description($PRC_desc = '') |
|
| 84 | + { |
|
| 85 | + $this->Set('PRC_desc', $PRC_desc); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * set is_default |
|
| 91 | + * |
|
| 92 | + * @access public |
|
| 93 | + * @param bool $PRC_is_default |
|
| 94 | + */ |
|
| 95 | + public function set_is_default($PRC_is_default = false) |
|
| 96 | + { |
|
| 97 | + $this->set('PRC_is_default', $PRC_is_default); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * set deleted |
|
| 103 | + * |
|
| 104 | + * @access public |
|
| 105 | + * @param bool $PRC_deleted |
|
| 106 | + */ |
|
| 107 | + public function set_deleted($PRC_deleted = null) |
|
| 108 | + { |
|
| 109 | + $this->set('PRC_deleted', $PRC_deleted); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * get Price type |
|
| 115 | + * |
|
| 116 | + * @access public |
|
| 117 | + * @return int |
|
| 118 | + */ |
|
| 119 | + public function type() |
|
| 120 | + { |
|
| 121 | + return $this->get('PRT_ID'); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * get Price Amount |
|
| 127 | + * |
|
| 128 | + * @access public |
|
| 129 | + * @return float |
|
| 130 | + */ |
|
| 131 | + public function amount() |
|
| 132 | + { |
|
| 133 | + return $this->get('PRC_amount'); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * get Price Name |
|
| 139 | + * |
|
| 140 | + * @access public |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + public function name() |
|
| 144 | + { |
|
| 145 | + return $this->get('PRC_name'); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * get Price description |
|
| 151 | + * |
|
| 152 | + * @access public |
|
| 153 | + * @return string |
|
| 154 | + */ |
|
| 155 | + public function desc() |
|
| 156 | + { |
|
| 157 | + return $this->get('PRC_desc'); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * get overrides |
|
| 163 | + * |
|
| 164 | + * @access public |
|
| 165 | + * @return int |
|
| 166 | + */ |
|
| 167 | + public function overrides() |
|
| 168 | + { |
|
| 169 | + return $this->get('PRC_overrides'); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * get order |
|
| 175 | + * |
|
| 176 | + * @access public |
|
| 177 | + * @return int |
|
| 178 | + */ |
|
| 179 | + public function order() |
|
| 180 | + { |
|
| 181 | + return $this->get('PRC_order'); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * get the author of the price |
|
| 187 | + * |
|
| 188 | + * @since 4.5.0 |
|
| 189 | + * |
|
| 190 | + * @return int |
|
| 191 | + */ |
|
| 192 | + public function wp_user() |
|
| 193 | + { |
|
| 194 | + return $this->get('PRC_wp_user'); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * get is_default |
|
| 200 | + * |
|
| 201 | + * @access public |
|
| 202 | + * @return bool |
|
| 203 | + */ |
|
| 204 | + public function is_default() |
|
| 205 | + { |
|
| 206 | + return $this->get('PRC_is_default'); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * get deleted |
|
| 212 | + * |
|
| 213 | + * @access public |
|
| 214 | + * @return bool |
|
| 215 | + */ |
|
| 216 | + public function deleted() |
|
| 217 | + { |
|
| 218 | + return $this->get('PRC_deleted'); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * @return bool |
|
| 224 | + */ |
|
| 225 | + public function parent() |
|
| 226 | + { |
|
| 227 | + return $this->get('PRC_parent'); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + // some helper methods for getting info on the price_type for this price |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * return whether the price is a base price or not |
|
| 235 | + * |
|
| 236 | + * @return boolean |
|
| 237 | + */ |
|
| 238 | + public function is_base_price() |
|
| 239 | + { |
|
| 240 | + $price_type = $this->type_obj(); |
|
| 241 | + return $price_type->base_type() === 1; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * |
|
| 247 | + * @return EE_Price_Type |
|
| 248 | + */ |
|
| 249 | + public function type_obj() |
|
| 250 | + { |
|
| 251 | + return $this->get_first_related('Price_Type'); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Simply indicates whether this price increases or decreases the total |
|
| 257 | + * |
|
| 258 | + * @return boolean true = discount, otherwise adds to the total |
|
| 259 | + */ |
|
| 260 | + public function is_discount() |
|
| 261 | + { |
|
| 262 | + $price_type = $this->type_obj(); |
|
| 263 | + return $price_type->is_discount(); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * whether the price is a percentage or not |
|
| 269 | + * |
|
| 270 | + * @return boolean |
|
| 271 | + */ |
|
| 272 | + public function is_percent() |
|
| 273 | + { |
|
| 274 | + $price_type = $this->type_obj(); |
|
| 275 | + return $price_type->get('PRT_is_percent'); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * return pretty price dependant on whether its a dollar or percent. |
|
| 281 | + * |
|
| 282 | + * @since 4.4.0 |
|
| 283 | + * |
|
| 284 | + * @return string |
|
| 285 | + */ |
|
| 286 | + public function pretty_price() |
|
| 287 | + { |
|
| 288 | + return ! $this->is_percent() ? $this->get_pretty('PRC_amount') : $this->get('PRC_amount') . '%'; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * @return mixed |
|
| 294 | + */ |
|
| 295 | + public function get_price_without_currency_symbol() |
|
| 296 | + { |
|
| 297 | + return str_replace(EE_Registry::instance()->CFG->currency->sign, '', $this->get_pretty('PRC_amount')); |
|
| 298 | + } |
|
| 299 | 299 | } |
@@ -285,7 +285,7 @@ |
||
| 285 | 285 | */ |
| 286 | 286 | public function pretty_price() |
| 287 | 287 | { |
| 288 | - return ! $this->is_percent() ? $this->get_pretty('PRC_amount') : $this->get('PRC_amount') . '%'; |
|
| 288 | + return ! $this->is_percent() ? $this->get_pretty('PRC_amount') : $this->get('PRC_amount').'%'; |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | * Question, that relationship will be overwritten. |
| 372 | 372 | * |
| 373 | 373 | * @param EE_Question_Option $option |
| 374 | - * @return boolean success |
|
| 374 | + * @return EE_Base_Class success |
|
| 375 | 375 | */ |
| 376 | 376 | public function add_option(EE_Question_Option $option) |
| 377 | 377 | { |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | * Marks the option as deleted. |
| 397 | 397 | * |
| 398 | 398 | * @param EE_Question_Option $option |
| 399 | - * @return boolean success |
|
| 399 | + * @return EE_Base_Class success |
|
| 400 | 400 | */ |
| 401 | 401 | public function remove_option(EE_Question_Option $option) |
| 402 | 402 | { |
@@ -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,661 +14,661 @@ |
||
| 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 ($answer instanceof EE_Answer |
|
| 519 | - && $answer->value() !== '' |
|
| 520 | - ) { |
|
| 521 | - // answer gets htmlspecialchars called on it, undo that please |
|
| 522 | - // because the form input's display strategy may call esc_attr too |
|
| 523 | - // which also does html special characters |
|
| 524 | - $values_with_html_special_chars = $answer->value(); |
|
| 525 | - if (is_array($values_with_html_special_chars)) { |
|
| 526 | - $default_value = array_map('htmlspecialchars_decode', $values_with_html_special_chars); |
|
| 527 | - } else { |
|
| 528 | - $default_value = htmlspecialchars_decode($values_with_html_special_chars); |
|
| 529 | - } |
|
| 530 | - $input_constructor_args['default'] = $default_value; |
|
| 531 | - } |
|
| 532 | - $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID()); |
|
| 533 | - if (in_array( |
|
| 534 | - $this->type(), |
|
| 535 | - EEM_Question::instance()->questionTypesWithMaxLength(), |
|
| 536 | - true |
|
| 537 | - )) { |
|
| 538 | - $input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy( |
|
| 539 | - null, |
|
| 540 | - min($max_max_for_question, $this->max()) |
|
| 541 | - ); |
|
| 542 | - } |
|
| 543 | - $input_constructor_args = apply_filters( |
|
| 544 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__input_constructor_args', |
|
| 545 | - $input_constructor_args, |
|
| 546 | - $registration, |
|
| 547 | - $this, |
|
| 548 | - $answer |
|
| 549 | - ); |
|
| 550 | - |
|
| 551 | - $result = null; |
|
| 552 | - switch ($this->type()) { |
|
| 553 | - // Text |
|
| 554 | - case EEM_Question::QST_type_text: |
|
| 555 | - $result = new EE_Text_Input($input_constructor_args); |
|
| 556 | - break; |
|
| 557 | - // Textarea |
|
| 558 | - case EEM_Question::QST_type_textarea: |
|
| 559 | - $result = new EE_Text_Area_Input($input_constructor_args); |
|
| 560 | - break; |
|
| 561 | - // Radio Buttons |
|
| 562 | - case EEM_Question::QST_type_radio: |
|
| 563 | - $result = new EE_Radio_Button_Input($this->options(), $input_constructor_args); |
|
| 564 | - break; |
|
| 565 | - // Dropdown |
|
| 566 | - case EEM_Question::QST_type_dropdown: |
|
| 567 | - $result = new EE_Select_Input($this->options(), $input_constructor_args); |
|
| 568 | - break; |
|
| 569 | - // State Dropdown |
|
| 570 | - case EEM_Question::QST_type_state: |
|
| 571 | - $state_options = apply_filters( |
|
| 572 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
| 573 | - null, |
|
| 574 | - $this, |
|
| 575 | - $registration, |
|
| 576 | - $answer |
|
| 577 | - ); |
|
| 578 | - $result = new EE_State_Select_Input($state_options, $input_constructor_args); |
|
| 579 | - break; |
|
| 580 | - // Country Dropdown |
|
| 581 | - case EEM_Question::QST_type_country: |
|
| 582 | - $country_options = apply_filters( |
|
| 583 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
| 584 | - null, |
|
| 585 | - $this, |
|
| 586 | - $registration, |
|
| 587 | - $answer |
|
| 588 | - ); |
|
| 589 | - $result = new EE_Country_Select_Input($country_options, $input_constructor_args); |
|
| 590 | - break; |
|
| 591 | - // Checkboxes |
|
| 592 | - case EEM_Question::QST_type_checkbox: |
|
| 593 | - $result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args); |
|
| 594 | - break; |
|
| 595 | - // Date |
|
| 596 | - case EEM_Question::QST_type_date: |
|
| 597 | - $result = new EE_Datepicker_Input($input_constructor_args); |
|
| 598 | - break; |
|
| 599 | - case EEM_Question::QST_type_html_textarea: |
|
| 600 | - $input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy(); |
|
| 601 | - $result = new EE_Text_Area_Input($input_constructor_args); |
|
| 602 | - $result->remove_validation_strategy('EE_Plaintext_Validation_Strategy'); |
|
| 603 | - break; |
|
| 604 | - case EEM_Question::QST_type_email: |
|
| 605 | - $result = new EE_Email_Input($input_constructor_args); |
|
| 606 | - break; |
|
| 607 | - case EEM_Question::QST_type_us_phone: |
|
| 608 | - $result = new EE_Phone_Input($input_constructor_args); |
|
| 609 | - break; |
|
| 610 | - case EEM_Question::QST_type_int: |
|
| 611 | - $result = new EE_Integer_Input($input_constructor_args); |
|
| 612 | - break; |
|
| 613 | - case EEM_Question::QST_type_decimal: |
|
| 614 | - $result = new EE_Float_Input($input_constructor_args); |
|
| 615 | - break; |
|
| 616 | - case EEM_Question::QST_type_url: |
|
| 617 | - $input_constructor_args['validation_strategies'][] = LoaderFactory::getLoader()->getNew('EE_URL_Validation_Strategy'); |
|
| 618 | - $result = new EE_Text_Input($input_constructor_args); |
|
| 619 | - break; |
|
| 620 | - case EEM_Question::QST_type_year: |
|
| 621 | - $result = new EE_Year_Input( |
|
| 622 | - $input_constructor_args, |
|
| 623 | - apply_filters( |
|
| 624 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', |
|
| 625 | - true, |
|
| 626 | - $this |
|
| 627 | - ), |
|
| 628 | - apply_filters( |
|
| 629 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', |
|
| 630 | - 100, |
|
| 631 | - $this |
|
| 632 | - ), |
|
| 633 | - apply_filters( |
|
| 634 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', |
|
| 635 | - 100, |
|
| 636 | - $this |
|
| 637 | - ) |
|
| 638 | - ); |
|
| 639 | - break; |
|
| 640 | - case EEM_Question::QST_type_multi_select: |
|
| 641 | - $result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args); |
|
| 642 | - break; |
|
| 643 | - // fallback |
|
| 644 | - default: |
|
| 645 | - $default_input = apply_filters( |
|
| 646 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__default', |
|
| 647 | - null, |
|
| 648 | - $this->type(), |
|
| 649 | - $this, |
|
| 650 | - $input_constructor_args |
|
| 651 | - ); |
|
| 652 | - if (! $default_input) { |
|
| 653 | - $default_input = new EE_Text_Input($input_constructor_args); |
|
| 654 | - } |
|
| 655 | - $result = $default_input; |
|
| 656 | - } |
|
| 657 | - return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer); |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * Returns whether or not this question type should have question option entries |
|
| 663 | - * |
|
| 664 | - * @return bool |
|
| 665 | - */ |
|
| 666 | - public function should_have_question_options() |
|
| 667 | - { |
|
| 668 | - return in_array( |
|
| 669 | - $this->type(), |
|
| 670 | - $this->_model->question_types_with_options(), |
|
| 671 | - true |
|
| 672 | - ); |
|
| 673 | - } |
|
| 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 ($answer instanceof EE_Answer |
|
| 519 | + && $answer->value() !== '' |
|
| 520 | + ) { |
|
| 521 | + // answer gets htmlspecialchars called on it, undo that please |
|
| 522 | + // because the form input's display strategy may call esc_attr too |
|
| 523 | + // which also does html special characters |
|
| 524 | + $values_with_html_special_chars = $answer->value(); |
|
| 525 | + if (is_array($values_with_html_special_chars)) { |
|
| 526 | + $default_value = array_map('htmlspecialchars_decode', $values_with_html_special_chars); |
|
| 527 | + } else { |
|
| 528 | + $default_value = htmlspecialchars_decode($values_with_html_special_chars); |
|
| 529 | + } |
|
| 530 | + $input_constructor_args['default'] = $default_value; |
|
| 531 | + } |
|
| 532 | + $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID()); |
|
| 533 | + if (in_array( |
|
| 534 | + $this->type(), |
|
| 535 | + EEM_Question::instance()->questionTypesWithMaxLength(), |
|
| 536 | + true |
|
| 537 | + )) { |
|
| 538 | + $input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy( |
|
| 539 | + null, |
|
| 540 | + min($max_max_for_question, $this->max()) |
|
| 541 | + ); |
|
| 542 | + } |
|
| 543 | + $input_constructor_args = apply_filters( |
|
| 544 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__input_constructor_args', |
|
| 545 | + $input_constructor_args, |
|
| 546 | + $registration, |
|
| 547 | + $this, |
|
| 548 | + $answer |
|
| 549 | + ); |
|
| 550 | + |
|
| 551 | + $result = null; |
|
| 552 | + switch ($this->type()) { |
|
| 553 | + // Text |
|
| 554 | + case EEM_Question::QST_type_text: |
|
| 555 | + $result = new EE_Text_Input($input_constructor_args); |
|
| 556 | + break; |
|
| 557 | + // Textarea |
|
| 558 | + case EEM_Question::QST_type_textarea: |
|
| 559 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
| 560 | + break; |
|
| 561 | + // Radio Buttons |
|
| 562 | + case EEM_Question::QST_type_radio: |
|
| 563 | + $result = new EE_Radio_Button_Input($this->options(), $input_constructor_args); |
|
| 564 | + break; |
|
| 565 | + // Dropdown |
|
| 566 | + case EEM_Question::QST_type_dropdown: |
|
| 567 | + $result = new EE_Select_Input($this->options(), $input_constructor_args); |
|
| 568 | + break; |
|
| 569 | + // State Dropdown |
|
| 570 | + case EEM_Question::QST_type_state: |
|
| 571 | + $state_options = apply_filters( |
|
| 572 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
| 573 | + null, |
|
| 574 | + $this, |
|
| 575 | + $registration, |
|
| 576 | + $answer |
|
| 577 | + ); |
|
| 578 | + $result = new EE_State_Select_Input($state_options, $input_constructor_args); |
|
| 579 | + break; |
|
| 580 | + // Country Dropdown |
|
| 581 | + case EEM_Question::QST_type_country: |
|
| 582 | + $country_options = apply_filters( |
|
| 583 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
| 584 | + null, |
|
| 585 | + $this, |
|
| 586 | + $registration, |
|
| 587 | + $answer |
|
| 588 | + ); |
|
| 589 | + $result = new EE_Country_Select_Input($country_options, $input_constructor_args); |
|
| 590 | + break; |
|
| 591 | + // Checkboxes |
|
| 592 | + case EEM_Question::QST_type_checkbox: |
|
| 593 | + $result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args); |
|
| 594 | + break; |
|
| 595 | + // Date |
|
| 596 | + case EEM_Question::QST_type_date: |
|
| 597 | + $result = new EE_Datepicker_Input($input_constructor_args); |
|
| 598 | + break; |
|
| 599 | + case EEM_Question::QST_type_html_textarea: |
|
| 600 | + $input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy(); |
|
| 601 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
| 602 | + $result->remove_validation_strategy('EE_Plaintext_Validation_Strategy'); |
|
| 603 | + break; |
|
| 604 | + case EEM_Question::QST_type_email: |
|
| 605 | + $result = new EE_Email_Input($input_constructor_args); |
|
| 606 | + break; |
|
| 607 | + case EEM_Question::QST_type_us_phone: |
|
| 608 | + $result = new EE_Phone_Input($input_constructor_args); |
|
| 609 | + break; |
|
| 610 | + case EEM_Question::QST_type_int: |
|
| 611 | + $result = new EE_Integer_Input($input_constructor_args); |
|
| 612 | + break; |
|
| 613 | + case EEM_Question::QST_type_decimal: |
|
| 614 | + $result = new EE_Float_Input($input_constructor_args); |
|
| 615 | + break; |
|
| 616 | + case EEM_Question::QST_type_url: |
|
| 617 | + $input_constructor_args['validation_strategies'][] = LoaderFactory::getLoader()->getNew('EE_URL_Validation_Strategy'); |
|
| 618 | + $result = new EE_Text_Input($input_constructor_args); |
|
| 619 | + break; |
|
| 620 | + case EEM_Question::QST_type_year: |
|
| 621 | + $result = new EE_Year_Input( |
|
| 622 | + $input_constructor_args, |
|
| 623 | + apply_filters( |
|
| 624 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', |
|
| 625 | + true, |
|
| 626 | + $this |
|
| 627 | + ), |
|
| 628 | + apply_filters( |
|
| 629 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', |
|
| 630 | + 100, |
|
| 631 | + $this |
|
| 632 | + ), |
|
| 633 | + apply_filters( |
|
| 634 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', |
|
| 635 | + 100, |
|
| 636 | + $this |
|
| 637 | + ) |
|
| 638 | + ); |
|
| 639 | + break; |
|
| 640 | + case EEM_Question::QST_type_multi_select: |
|
| 641 | + $result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args); |
|
| 642 | + break; |
|
| 643 | + // fallback |
|
| 644 | + default: |
|
| 645 | + $default_input = apply_filters( |
|
| 646 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__default', |
|
| 647 | + null, |
|
| 648 | + $this->type(), |
|
| 649 | + $this, |
|
| 650 | + $input_constructor_args |
|
| 651 | + ); |
|
| 652 | + if (! $default_input) { |
|
| 653 | + $default_input = new EE_Text_Input($input_constructor_args); |
|
| 654 | + } |
|
| 655 | + $result = $default_input; |
|
| 656 | + } |
|
| 657 | + return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer); |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * Returns whether or not this question type should have question option entries |
|
| 663 | + * |
|
| 664 | + * @return bool |
|
| 665 | + */ |
|
| 666 | + public function should_have_question_options() |
|
| 667 | + { |
|
| 668 | + return in_array( |
|
| 669 | + $this->type(), |
|
| 670 | + $this->_model->question_types_with_options(), |
|
| 671 | + true |
|
| 672 | + ); |
|
| 673 | + } |
|
| 674 | 674 | } |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * generate_question_form_inputs_for_object |
| 242 | 242 | * |
| 243 | 243 | * @access protected |
| 244 | - * @param bool|object $object $object |
|
| 244 | + * @param EE_Base_Class|null $object $object |
|
| 245 | 245 | * @param array $input_types |
| 246 | 246 | * @return array |
| 247 | 247 | */ |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | * |
| 355 | 355 | * @access public |
| 356 | 356 | * @param \EE_Question_Option $QSO EE_Question_Option |
| 357 | - * @return boolean |
|
| 357 | + * @return boolean|null |
|
| 358 | 358 | */ |
| 359 | 359 | public function add_temp_option(EE_Question_Option $QSO) |
| 360 | 360 | { |
@@ -367,8 +367,8 @@ discard block |
||
| 367 | 367 | * |
| 368 | 368 | * @access public |
| 369 | 369 | * @param string $property |
| 370 | - * @param mixed $value |
|
| 371 | - * @return mixed |
|
| 370 | + * @param boolean $value |
|
| 371 | + * @return boolean|null |
|
| 372 | 372 | */ |
| 373 | 373 | public function set($property = null, $value = null) |
| 374 | 374 | { |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * get_meta |
| 417 | 417 | * |
| 418 | 418 | * @access public |
| 419 | - * @param mixed $key |
|
| 419 | + * @param string $key |
|
| 420 | 420 | * @return mixed |
| 421 | 421 | */ |
| 422 | 422 | public function get_meta($key = false) |
@@ -13,435 +13,435 @@ |
||
| 13 | 13 | class EE_Question_Form_Input |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * EE_Question object |
|
| 18 | - * |
|
| 19 | - * @access private |
|
| 20 | - * @var object |
|
| 21 | - */ |
|
| 22 | - private $_QST = null; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * EE_Answer object |
|
| 26 | - * |
|
| 27 | - * @access private |
|
| 28 | - * @var object |
|
| 29 | - */ |
|
| 30 | - private $_ANS = null; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * $_QST_meta |
|
| 34 | - * @access private |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - private $_QST_meta = array(); |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * $QST_input_name |
|
| 41 | - * @access private |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 44 | - private $QST_input_name = ''; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * $QST_input_id |
|
| 48 | - * @access private |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 51 | - private $QST_input_id = ''; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * $QST_input_class |
|
| 55 | - * @access private |
|
| 56 | - * @var string |
|
| 57 | - */ |
|
| 58 | - private $QST_input_class = ''; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var bool $QST_disabled |
|
| 62 | - */ |
|
| 63 | - private $QST_disabled = false; |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * constructor for questions |
|
| 68 | - * |
|
| 69 | - * @param \EE_Question $QST EE_Question object |
|
| 70 | - * @param \EE_Answer $ANS EE_Answer object |
|
| 71 | - * @param array $q_meta |
|
| 72 | - * @access public |
|
| 73 | - * @return \EE_Question_Form_Input |
|
| 74 | - */ |
|
| 75 | - public function __construct(EE_Question $QST = null, EE_Answer $ANS = null, $q_meta = array()) |
|
| 76 | - { |
|
| 77 | - if (empty($QST) || empty($ANS)) { |
|
| 78 | - EE_Error::add_error( |
|
| 79 | - __('An error occurred. A valid EE_Question or EE_Answer object was not received.', 'event_espresso'), |
|
| 80 | - __FILE__, |
|
| 81 | - __FUNCTION__, |
|
| 82 | - __LINE__ |
|
| 83 | - ); |
|
| 84 | - return null; |
|
| 85 | - } |
|
| 86 | - $this->_QST = $QST; |
|
| 87 | - $this->_ANS = $ANS; |
|
| 88 | - $this->set_question_form_input_meta($q_meta); |
|
| 89 | - $this->set_question_form_input_init(); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * sets meta data for the question form input |
|
| 95 | - * |
|
| 96 | - * @access public |
|
| 97 | - * @param array $q_meta |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - public function set_question_form_input_meta($q_meta = array()) |
|
| 101 | - { |
|
| 102 | - $default_q_meta = array( |
|
| 103 | - 'att_nmbr' => 1, |
|
| 104 | - 'ticket_id' => '', |
|
| 105 | - 'date' => '', |
|
| 106 | - 'time' => '', |
|
| 107 | - 'input_name' => '', |
|
| 108 | - 'input_id' => '', |
|
| 109 | - 'input_class' => '', |
|
| 110 | - 'input_prefix' => 'qstn', |
|
| 111 | - 'append_qstn_id' => true, |
|
| 112 | - 'htmlentities' => true, |
|
| 113 | - 'allow_null' => false, |
|
| 114 | - ); |
|
| 115 | - $this->_QST_meta = array_merge($default_q_meta, $q_meta); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * set_question_form_input_init |
|
| 121 | - * |
|
| 122 | - * @access public |
|
| 123 | - * @return void |
|
| 124 | - */ |
|
| 125 | - public function set_question_form_input_init() |
|
| 126 | - { |
|
| 127 | - $qstn_id = $this->_QST->system_ID() ? $this->_QST->system_ID() : $this->_QST->ID(); |
|
| 128 | - $this->_set_input_name($qstn_id); |
|
| 129 | - $this->_set_input_id($qstn_id); |
|
| 130 | - $this->_set_input_class($qstn_id); |
|
| 131 | - $this->set_question_form_input_answer($qstn_id); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * set_input_name |
|
| 137 | - * |
|
| 138 | - * @access private |
|
| 139 | - * @param $qstn_id |
|
| 140 | - * @return void |
|
| 141 | - */ |
|
| 142 | - private function _set_input_name($qstn_id) |
|
| 143 | - { |
|
| 144 | - if (! empty($qstn_id)) { |
|
| 145 | - $ANS_ID = $this->get('ANS_ID'); |
|
| 146 | - $qstn_id = ! empty($ANS_ID) ? '[' . $qstn_id . '][' . $ANS_ID . ']' : '[' . $qstn_id . ']'; |
|
| 147 | - } |
|
| 148 | - $this->QST_input_name = $this->_QST_meta['append_qstn_id'] && ! empty($qstn_id) |
|
| 149 | - ? $this->_QST_meta['input_prefix'] . $this->_QST_meta['input_name'] . $qstn_id |
|
| 150 | - : $this->_QST_meta['input_prefix'] . $this->_QST_meta['input_name']; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * get property values for question form input |
|
| 156 | - * |
|
| 157 | - * @access public |
|
| 158 | - * @param string $property |
|
| 159 | - * @return mixed |
|
| 160 | - */ |
|
| 161 | - public function get($property = null) |
|
| 162 | - { |
|
| 163 | - if (! empty($property)) { |
|
| 164 | - if (EEM_Question::instance()->has_field($property)) { |
|
| 165 | - return $this->_QST->get($property); |
|
| 166 | - } elseif (EEM_Answer::instance()->has_field($property)) { |
|
| 167 | - return $this->_ANS->get($property); |
|
| 168 | - } elseif ($this->_question_form_input_property_exists(__CLASS__, $property)) { |
|
| 169 | - return $this->{$property}; |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - return null; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * _question_form_input_property_exists |
|
| 178 | - * |
|
| 179 | - * @access private |
|
| 180 | - * @param string $classname |
|
| 181 | - * @param string $property |
|
| 182 | - * @return boolean |
|
| 183 | - */ |
|
| 184 | - private function _question_form_input_property_exists($classname, $property) |
|
| 185 | - { |
|
| 186 | - // first try regular property exists method which works as expected in PHP 5.3+ |
|
| 187 | - $prop = EEH_Class_Tools::has_property($classname, $property); |
|
| 188 | - if (! $prop) { |
|
| 189 | - // use reflection for < PHP 5.3 as a double check when property is not found, possible due to access restriction |
|
| 190 | - $reflector = new ReflectionClass($classname); |
|
| 191 | - $prop = $reflector->hasProperty($property); |
|
| 192 | - } |
|
| 193 | - return $prop; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * set_input_id |
|
| 199 | - * |
|
| 200 | - * @access private |
|
| 201 | - * @param $qstn_id |
|
| 202 | - * @return void |
|
| 203 | - */ |
|
| 204 | - private function _set_input_id($qstn_id) |
|
| 205 | - { |
|
| 206 | - $input_id = isset($this->_QST_meta['input_id']) && ! empty($this->_QST_meta['input_id']) |
|
| 207 | - ? $this->_QST_meta['input_id'] |
|
| 208 | - : sanitize_key(strip_tags($this->_QST->get('QST_display_text'))); |
|
| 209 | - $this->QST_input_id = $this->_QST_meta['append_qstn_id'] && ! empty($qstn_id) |
|
| 210 | - ? $input_id . '-' . $qstn_id |
|
| 211 | - : $input_id; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * set_input_class |
|
| 217 | - * |
|
| 218 | - * @access private |
|
| 219 | - * @return void |
|
| 220 | - */ |
|
| 221 | - private function _set_input_class() |
|
| 222 | - { |
|
| 223 | - $this->QST_input_class = isset($this->_QST_meta['input_class']) ? $this->_QST_meta['input_class'] : ''; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * set_question_form_input_answer |
|
| 229 | - * |
|
| 230 | - * @access public |
|
| 231 | - * @param mixed int | string $qstn_id |
|
| 232 | - * @return void |
|
| 233 | - */ |
|
| 234 | - public function set_question_form_input_answer($qstn_id) |
|
| 235 | - { |
|
| 236 | - // check for answer in $_REQUEST in case we are reprocessing a form after an error |
|
| 237 | - if (isset($this->_QST_meta['EVT_ID']) |
|
| 238 | - && isset($this->_QST_meta['att_nmbr']) |
|
| 239 | - && isset($this->_QST_meta['date']) |
|
| 240 | - && isset($this->_QST_meta['time']) |
|
| 241 | - && isset($this->_QST_meta['price_id']) |
|
| 242 | - ) { |
|
| 243 | - if (isset($_REQUEST['qstn'][ $this->_QST_meta['EVT_ID'] ][ $this->_QST_meta['att_nmbr'] ][ $this->_QST_meta['date'] ][ $this->_QST_meta['time'] ][ $this->_QST_meta['price_id'] ][ $qstn_id ]) |
|
| 244 | - ) { |
|
| 245 | - $answer = $_REQUEST['qstn'][ $this->_QST_meta['EVT_ID'] ][ $this->_QST_meta['att_nmbr'] ][ $this->_QST_meta['date'] ][ $this->_QST_meta['time'] ][ $this->_QST_meta['price_id'] ][ $qstn_id ]; |
|
| 246 | - $this->_ANS->set('ANS_value', $answer); |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * generate_question_form_inputs_for_object |
|
| 254 | - * |
|
| 255 | - * @access protected |
|
| 256 | - * @param bool|object $object $object |
|
| 257 | - * @param array $input_types |
|
| 258 | - * @return array |
|
| 259 | - */ |
|
| 260 | - public static function generate_question_form_inputs_for_object($object = false, $input_types = array()) |
|
| 261 | - { |
|
| 262 | - if (! is_object($object)) { |
|
| 263 | - return false; |
|
| 264 | - } |
|
| 265 | - $inputs = array(); |
|
| 266 | - $fields = $object->get_model()->field_settings(false); |
|
| 267 | - // $pk = $object->ID(); <<< NO! |
|
| 268 | - // EEH_Debug_Tools::printr( $object, get_class( $object ) . '<br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 269 | - // EEH_Debug_Tools::printr( $fields, '$fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 270 | - // EEH_Debug_Tools::printr( $input_types, '$input_types <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 271 | - foreach ($fields as $field_ID => $field) { |
|
| 272 | - if ($field instanceof EE_Model_Field_Base) { |
|
| 273 | - // echo '<h4>$field_ID : ' . $field_ID . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
|
| 274 | - // EEH_Debug_Tools::printr( $field, '$field <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 275 | - if (isset($input_types[ $field_ID ])) { |
|
| 276 | - // get saved value for field |
|
| 277 | - $value = $object->get($field_ID); |
|
| 278 | - // echo '<h4>$value : ' . $value . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
|
| 279 | - // if no saved value, then use default |
|
| 280 | - $value = $value !== null ? $value : $field->get_default_value(); |
|
| 281 | - // if ( $field_ID == 'CNT_active' ) |
|
| 282 | - // echo '<h4>$value : ' . $value . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
|
| 283 | - // determine question type |
|
| 284 | - $type = isset($input_types[ $field_ID ]) ? $input_types[ $field_ID ]['type'] : 'TEXT'; |
|
| 285 | - // input name |
|
| 286 | - $input_name = isset($input_types[ $field_ID ]) && isset($input_types[ $field_ID ]['input_name']) |
|
| 287 | - ? $input_types[ $field_ID ]['input_name'] . '[' . $field_ID . ']' |
|
| 288 | - : $field_ID; |
|
| 289 | - // css class for input |
|
| 290 | - $class = isset($input_types[ $field_ID ]['class']) && ! empty($input_types[ $field_ID ]['class']) |
|
| 291 | - ? ' ' . $input_types[ $field_ID ]['class'] |
|
| 292 | - : ''; |
|
| 293 | - // whether to apply htmlentities to answer |
|
| 294 | - $htmlentities = isset($input_types[ $field_ID ]['htmlentities']) |
|
| 295 | - ? $input_types[ $field_ID ]['htmlentities'] |
|
| 296 | - : true; |
|
| 297 | - // whether to apply htmlentities to answer |
|
| 298 | - $label_b4 = isset($input_types[ $field_ID ]['label_b4']) |
|
| 299 | - ? $input_types[ $field_ID ]['label_b4'] |
|
| 300 | - : false; |
|
| 301 | - // whether to apply htmlentities to answer |
|
| 302 | - $use_desc_4_label = isset($input_types[ $field_ID ]['use_desc_4_label']) |
|
| 303 | - ? $input_types[ $field_ID ]['use_desc_4_label'] |
|
| 304 | - : false; |
|
| 305 | - // whether input is disabled |
|
| 306 | - $disabled = isset($input_types[ $field_ID ]['disabled']) |
|
| 307 | - ? $input_types[ $field_ID ]['disabled'] |
|
| 308 | - : false; |
|
| 309 | - |
|
| 310 | - // create EE_Question_Form_Input object |
|
| 311 | - $QFI = new EE_Question_Form_Input( |
|
| 312 | - EE_Question::new_instance( |
|
| 313 | - array( |
|
| 314 | - 'QST_ID' => 0, |
|
| 315 | - 'QST_display_text' => $field->get_nicename(), |
|
| 316 | - 'QST_type' => $type, |
|
| 317 | - ) |
|
| 318 | - ), |
|
| 319 | - EE_Answer::new_instance( |
|
| 320 | - array( |
|
| 321 | - 'ANS_ID' => 0, |
|
| 322 | - 'QST_ID' => 0, |
|
| 323 | - 'REG_ID' => 0, |
|
| 324 | - 'ANS_value' => $value, |
|
| 325 | - ) |
|
| 326 | - ), |
|
| 327 | - array( |
|
| 328 | - 'input_id' => $field_ID . '-' . $object->ID(), |
|
| 329 | - 'input_name' => $input_name, |
|
| 330 | - 'input_class' => $field_ID . $class, |
|
| 331 | - 'input_prefix' => '', |
|
| 332 | - 'append_qstn_id' => false, |
|
| 333 | - 'htmlentities' => $htmlentities, |
|
| 334 | - 'label_b4' => $label_b4, |
|
| 335 | - 'use_desc_4_label' => $use_desc_4_label, |
|
| 336 | - ) |
|
| 337 | - ); |
|
| 338 | - // does question type have options ? |
|
| 339 | - if (in_array($type, array('DROPDOWN', 'RADIO_BTN', 'CHECKBOX')) |
|
| 340 | - && isset($input_types[ $field_ID ]) |
|
| 341 | - && isset($input_types[ $field_ID ]['options']) |
|
| 342 | - ) { |
|
| 343 | - foreach ($input_types[ $field_ID ]['options'] as $option) { |
|
| 344 | - $option = stripslashes_deep($option); |
|
| 345 | - $option_id = ! empty($option['id']) ? $option['id'] : 0; |
|
| 346 | - $QSO = EE_Question_Option::new_instance( |
|
| 347 | - array( |
|
| 348 | - 'QSO_value' => (string) $option_id, |
|
| 349 | - 'QSO_desc' => $option['text'], |
|
| 350 | - 'QSO_deleted' => false, |
|
| 351 | - ) |
|
| 352 | - ); |
|
| 353 | - // all QST (and ANS) properties can be accessed indirectly thru QFI |
|
| 354 | - $QFI->add_temp_option($QSO); |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - // we don't want ppl manually changing primary keys cuz that would just lead to total craziness man |
|
| 358 | - if ($disabled || $field_ID == $object->get_model()->primary_key_name()) { |
|
| 359 | - $QFI->set('QST_disabled', true); |
|
| 360 | - } |
|
| 361 | - // EEH_Debug_Tools::printr( $QFI, '$QFI <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 362 | - $inputs[ $field_ID ] = $QFI; |
|
| 363 | - // if ( $field_ID == 'CNT_active' ) { |
|
| 364 | - // EEH_Debug_Tools::printr( $QFI, '$QFI <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 365 | - // } |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - return $inputs; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * add_temp_option |
|
| 375 | - * |
|
| 376 | - * @access public |
|
| 377 | - * @param \EE_Question_Option $QSO EE_Question_Option |
|
| 378 | - * @return boolean |
|
| 379 | - */ |
|
| 380 | - public function add_temp_option(EE_Question_Option $QSO) |
|
| 381 | - { |
|
| 382 | - $this->_QST->add_temp_option($QSO); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * set property values for question form input |
|
| 388 | - * |
|
| 389 | - * @access public |
|
| 390 | - * @param string $property |
|
| 391 | - * @param mixed $value |
|
| 392 | - * @return mixed |
|
| 393 | - */ |
|
| 394 | - public function set($property = null, $value = null) |
|
| 395 | - { |
|
| 396 | - if (! empty($property)) { |
|
| 397 | - if (EEM_Question::instance()->has_field($property)) { |
|
| 398 | - $this->_QST->set($property, $value); |
|
| 399 | - } elseif (EEM_Answer::instance()->has_field($property)) { |
|
| 400 | - $this->_ANS->set($property, $value); |
|
| 401 | - } elseif ($this->_question_form_input_property_exists(__CLASS__, $property)) { |
|
| 402 | - // echo "<hr>$property is a prop of QFI"; |
|
| 403 | - $this->{$property} = $value; |
|
| 404 | - return true; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - return null; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * _question_form_input_property_exists |
|
| 413 | - * |
|
| 414 | - * @access public |
|
| 415 | - * @param boolean $notDeletedOptionsOnly 1 |
|
| 416 | - * whether to return ALL options, or only the ones which have |
|
| 417 | - * not yet been deleted |
|
| 418 | - * @param string|array $selected_value_to_always_include , when retrieving options to an ANSWERED question, |
|
| 419 | - * we want to usually only show non-deleted options AND the |
|
| 420 | - * value that was selected for the answer, whether it was |
|
| 421 | - * trashed or not. |
|
| 422 | - * @return EE_Question_Option |
|
| 423 | - */ |
|
| 424 | - public function options($notDeletedOptionsOnly = true, $selected_value_to_always_include = null) |
|
| 425 | - { |
|
| 426 | - $temp_options = $this->_QST->temp_options(); |
|
| 427 | - return ! empty($temp_options) |
|
| 428 | - ? $temp_options |
|
| 429 | - : $this->_QST->options( |
|
| 430 | - $notDeletedOptionsOnly, |
|
| 431 | - $selected_value_to_always_include |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * get_meta |
|
| 438 | - * |
|
| 439 | - * @access public |
|
| 440 | - * @param mixed $key |
|
| 441 | - * @return mixed |
|
| 442 | - */ |
|
| 443 | - public function get_meta($key = false) |
|
| 444 | - { |
|
| 445 | - return $key && isset($this->_QST_meta[ $key ]) ? $this->_QST_meta[ $key ] : false; |
|
| 446 | - } |
|
| 16 | + /** |
|
| 17 | + * EE_Question object |
|
| 18 | + * |
|
| 19 | + * @access private |
|
| 20 | + * @var object |
|
| 21 | + */ |
|
| 22 | + private $_QST = null; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * EE_Answer object |
|
| 26 | + * |
|
| 27 | + * @access private |
|
| 28 | + * @var object |
|
| 29 | + */ |
|
| 30 | + private $_ANS = null; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * $_QST_meta |
|
| 34 | + * @access private |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + private $_QST_meta = array(); |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * $QST_input_name |
|
| 41 | + * @access private |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | + private $QST_input_name = ''; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * $QST_input_id |
|
| 48 | + * @access private |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | + private $QST_input_id = ''; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * $QST_input_class |
|
| 55 | + * @access private |
|
| 56 | + * @var string |
|
| 57 | + */ |
|
| 58 | + private $QST_input_class = ''; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var bool $QST_disabled |
|
| 62 | + */ |
|
| 63 | + private $QST_disabled = false; |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * constructor for questions |
|
| 68 | + * |
|
| 69 | + * @param \EE_Question $QST EE_Question object |
|
| 70 | + * @param \EE_Answer $ANS EE_Answer object |
|
| 71 | + * @param array $q_meta |
|
| 72 | + * @access public |
|
| 73 | + * @return \EE_Question_Form_Input |
|
| 74 | + */ |
|
| 75 | + public function __construct(EE_Question $QST = null, EE_Answer $ANS = null, $q_meta = array()) |
|
| 76 | + { |
|
| 77 | + if (empty($QST) || empty($ANS)) { |
|
| 78 | + EE_Error::add_error( |
|
| 79 | + __('An error occurred. A valid EE_Question or EE_Answer object was not received.', 'event_espresso'), |
|
| 80 | + __FILE__, |
|
| 81 | + __FUNCTION__, |
|
| 82 | + __LINE__ |
|
| 83 | + ); |
|
| 84 | + return null; |
|
| 85 | + } |
|
| 86 | + $this->_QST = $QST; |
|
| 87 | + $this->_ANS = $ANS; |
|
| 88 | + $this->set_question_form_input_meta($q_meta); |
|
| 89 | + $this->set_question_form_input_init(); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * sets meta data for the question form input |
|
| 95 | + * |
|
| 96 | + * @access public |
|
| 97 | + * @param array $q_meta |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + public function set_question_form_input_meta($q_meta = array()) |
|
| 101 | + { |
|
| 102 | + $default_q_meta = array( |
|
| 103 | + 'att_nmbr' => 1, |
|
| 104 | + 'ticket_id' => '', |
|
| 105 | + 'date' => '', |
|
| 106 | + 'time' => '', |
|
| 107 | + 'input_name' => '', |
|
| 108 | + 'input_id' => '', |
|
| 109 | + 'input_class' => '', |
|
| 110 | + 'input_prefix' => 'qstn', |
|
| 111 | + 'append_qstn_id' => true, |
|
| 112 | + 'htmlentities' => true, |
|
| 113 | + 'allow_null' => false, |
|
| 114 | + ); |
|
| 115 | + $this->_QST_meta = array_merge($default_q_meta, $q_meta); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * set_question_form_input_init |
|
| 121 | + * |
|
| 122 | + * @access public |
|
| 123 | + * @return void |
|
| 124 | + */ |
|
| 125 | + public function set_question_form_input_init() |
|
| 126 | + { |
|
| 127 | + $qstn_id = $this->_QST->system_ID() ? $this->_QST->system_ID() : $this->_QST->ID(); |
|
| 128 | + $this->_set_input_name($qstn_id); |
|
| 129 | + $this->_set_input_id($qstn_id); |
|
| 130 | + $this->_set_input_class($qstn_id); |
|
| 131 | + $this->set_question_form_input_answer($qstn_id); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * set_input_name |
|
| 137 | + * |
|
| 138 | + * @access private |
|
| 139 | + * @param $qstn_id |
|
| 140 | + * @return void |
|
| 141 | + */ |
|
| 142 | + private function _set_input_name($qstn_id) |
|
| 143 | + { |
|
| 144 | + if (! empty($qstn_id)) { |
|
| 145 | + $ANS_ID = $this->get('ANS_ID'); |
|
| 146 | + $qstn_id = ! empty($ANS_ID) ? '[' . $qstn_id . '][' . $ANS_ID . ']' : '[' . $qstn_id . ']'; |
|
| 147 | + } |
|
| 148 | + $this->QST_input_name = $this->_QST_meta['append_qstn_id'] && ! empty($qstn_id) |
|
| 149 | + ? $this->_QST_meta['input_prefix'] . $this->_QST_meta['input_name'] . $qstn_id |
|
| 150 | + : $this->_QST_meta['input_prefix'] . $this->_QST_meta['input_name']; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * get property values for question form input |
|
| 156 | + * |
|
| 157 | + * @access public |
|
| 158 | + * @param string $property |
|
| 159 | + * @return mixed |
|
| 160 | + */ |
|
| 161 | + public function get($property = null) |
|
| 162 | + { |
|
| 163 | + if (! empty($property)) { |
|
| 164 | + if (EEM_Question::instance()->has_field($property)) { |
|
| 165 | + return $this->_QST->get($property); |
|
| 166 | + } elseif (EEM_Answer::instance()->has_field($property)) { |
|
| 167 | + return $this->_ANS->get($property); |
|
| 168 | + } elseif ($this->_question_form_input_property_exists(__CLASS__, $property)) { |
|
| 169 | + return $this->{$property}; |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + return null; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * _question_form_input_property_exists |
|
| 178 | + * |
|
| 179 | + * @access private |
|
| 180 | + * @param string $classname |
|
| 181 | + * @param string $property |
|
| 182 | + * @return boolean |
|
| 183 | + */ |
|
| 184 | + private function _question_form_input_property_exists($classname, $property) |
|
| 185 | + { |
|
| 186 | + // first try regular property exists method which works as expected in PHP 5.3+ |
|
| 187 | + $prop = EEH_Class_Tools::has_property($classname, $property); |
|
| 188 | + if (! $prop) { |
|
| 189 | + // use reflection for < PHP 5.3 as a double check when property is not found, possible due to access restriction |
|
| 190 | + $reflector = new ReflectionClass($classname); |
|
| 191 | + $prop = $reflector->hasProperty($property); |
|
| 192 | + } |
|
| 193 | + return $prop; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * set_input_id |
|
| 199 | + * |
|
| 200 | + * @access private |
|
| 201 | + * @param $qstn_id |
|
| 202 | + * @return void |
|
| 203 | + */ |
|
| 204 | + private function _set_input_id($qstn_id) |
|
| 205 | + { |
|
| 206 | + $input_id = isset($this->_QST_meta['input_id']) && ! empty($this->_QST_meta['input_id']) |
|
| 207 | + ? $this->_QST_meta['input_id'] |
|
| 208 | + : sanitize_key(strip_tags($this->_QST->get('QST_display_text'))); |
|
| 209 | + $this->QST_input_id = $this->_QST_meta['append_qstn_id'] && ! empty($qstn_id) |
|
| 210 | + ? $input_id . '-' . $qstn_id |
|
| 211 | + : $input_id; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * set_input_class |
|
| 217 | + * |
|
| 218 | + * @access private |
|
| 219 | + * @return void |
|
| 220 | + */ |
|
| 221 | + private function _set_input_class() |
|
| 222 | + { |
|
| 223 | + $this->QST_input_class = isset($this->_QST_meta['input_class']) ? $this->_QST_meta['input_class'] : ''; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * set_question_form_input_answer |
|
| 229 | + * |
|
| 230 | + * @access public |
|
| 231 | + * @param mixed int | string $qstn_id |
|
| 232 | + * @return void |
|
| 233 | + */ |
|
| 234 | + public function set_question_form_input_answer($qstn_id) |
|
| 235 | + { |
|
| 236 | + // check for answer in $_REQUEST in case we are reprocessing a form after an error |
|
| 237 | + if (isset($this->_QST_meta['EVT_ID']) |
|
| 238 | + && isset($this->_QST_meta['att_nmbr']) |
|
| 239 | + && isset($this->_QST_meta['date']) |
|
| 240 | + && isset($this->_QST_meta['time']) |
|
| 241 | + && isset($this->_QST_meta['price_id']) |
|
| 242 | + ) { |
|
| 243 | + if (isset($_REQUEST['qstn'][ $this->_QST_meta['EVT_ID'] ][ $this->_QST_meta['att_nmbr'] ][ $this->_QST_meta['date'] ][ $this->_QST_meta['time'] ][ $this->_QST_meta['price_id'] ][ $qstn_id ]) |
|
| 244 | + ) { |
|
| 245 | + $answer = $_REQUEST['qstn'][ $this->_QST_meta['EVT_ID'] ][ $this->_QST_meta['att_nmbr'] ][ $this->_QST_meta['date'] ][ $this->_QST_meta['time'] ][ $this->_QST_meta['price_id'] ][ $qstn_id ]; |
|
| 246 | + $this->_ANS->set('ANS_value', $answer); |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * generate_question_form_inputs_for_object |
|
| 254 | + * |
|
| 255 | + * @access protected |
|
| 256 | + * @param bool|object $object $object |
|
| 257 | + * @param array $input_types |
|
| 258 | + * @return array |
|
| 259 | + */ |
|
| 260 | + public static function generate_question_form_inputs_for_object($object = false, $input_types = array()) |
|
| 261 | + { |
|
| 262 | + if (! is_object($object)) { |
|
| 263 | + return false; |
|
| 264 | + } |
|
| 265 | + $inputs = array(); |
|
| 266 | + $fields = $object->get_model()->field_settings(false); |
|
| 267 | + // $pk = $object->ID(); <<< NO! |
|
| 268 | + // EEH_Debug_Tools::printr( $object, get_class( $object ) . '<br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 269 | + // EEH_Debug_Tools::printr( $fields, '$fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 270 | + // EEH_Debug_Tools::printr( $input_types, '$input_types <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 271 | + foreach ($fields as $field_ID => $field) { |
|
| 272 | + if ($field instanceof EE_Model_Field_Base) { |
|
| 273 | + // echo '<h4>$field_ID : ' . $field_ID . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
|
| 274 | + // EEH_Debug_Tools::printr( $field, '$field <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 275 | + if (isset($input_types[ $field_ID ])) { |
|
| 276 | + // get saved value for field |
|
| 277 | + $value = $object->get($field_ID); |
|
| 278 | + // echo '<h4>$value : ' . $value . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
|
| 279 | + // if no saved value, then use default |
|
| 280 | + $value = $value !== null ? $value : $field->get_default_value(); |
|
| 281 | + // if ( $field_ID == 'CNT_active' ) |
|
| 282 | + // echo '<h4>$value : ' . $value . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
|
| 283 | + // determine question type |
|
| 284 | + $type = isset($input_types[ $field_ID ]) ? $input_types[ $field_ID ]['type'] : 'TEXT'; |
|
| 285 | + // input name |
|
| 286 | + $input_name = isset($input_types[ $field_ID ]) && isset($input_types[ $field_ID ]['input_name']) |
|
| 287 | + ? $input_types[ $field_ID ]['input_name'] . '[' . $field_ID . ']' |
|
| 288 | + : $field_ID; |
|
| 289 | + // css class for input |
|
| 290 | + $class = isset($input_types[ $field_ID ]['class']) && ! empty($input_types[ $field_ID ]['class']) |
|
| 291 | + ? ' ' . $input_types[ $field_ID ]['class'] |
|
| 292 | + : ''; |
|
| 293 | + // whether to apply htmlentities to answer |
|
| 294 | + $htmlentities = isset($input_types[ $field_ID ]['htmlentities']) |
|
| 295 | + ? $input_types[ $field_ID ]['htmlentities'] |
|
| 296 | + : true; |
|
| 297 | + // whether to apply htmlentities to answer |
|
| 298 | + $label_b4 = isset($input_types[ $field_ID ]['label_b4']) |
|
| 299 | + ? $input_types[ $field_ID ]['label_b4'] |
|
| 300 | + : false; |
|
| 301 | + // whether to apply htmlentities to answer |
|
| 302 | + $use_desc_4_label = isset($input_types[ $field_ID ]['use_desc_4_label']) |
|
| 303 | + ? $input_types[ $field_ID ]['use_desc_4_label'] |
|
| 304 | + : false; |
|
| 305 | + // whether input is disabled |
|
| 306 | + $disabled = isset($input_types[ $field_ID ]['disabled']) |
|
| 307 | + ? $input_types[ $field_ID ]['disabled'] |
|
| 308 | + : false; |
|
| 309 | + |
|
| 310 | + // create EE_Question_Form_Input object |
|
| 311 | + $QFI = new EE_Question_Form_Input( |
|
| 312 | + EE_Question::new_instance( |
|
| 313 | + array( |
|
| 314 | + 'QST_ID' => 0, |
|
| 315 | + 'QST_display_text' => $field->get_nicename(), |
|
| 316 | + 'QST_type' => $type, |
|
| 317 | + ) |
|
| 318 | + ), |
|
| 319 | + EE_Answer::new_instance( |
|
| 320 | + array( |
|
| 321 | + 'ANS_ID' => 0, |
|
| 322 | + 'QST_ID' => 0, |
|
| 323 | + 'REG_ID' => 0, |
|
| 324 | + 'ANS_value' => $value, |
|
| 325 | + ) |
|
| 326 | + ), |
|
| 327 | + array( |
|
| 328 | + 'input_id' => $field_ID . '-' . $object->ID(), |
|
| 329 | + 'input_name' => $input_name, |
|
| 330 | + 'input_class' => $field_ID . $class, |
|
| 331 | + 'input_prefix' => '', |
|
| 332 | + 'append_qstn_id' => false, |
|
| 333 | + 'htmlentities' => $htmlentities, |
|
| 334 | + 'label_b4' => $label_b4, |
|
| 335 | + 'use_desc_4_label' => $use_desc_4_label, |
|
| 336 | + ) |
|
| 337 | + ); |
|
| 338 | + // does question type have options ? |
|
| 339 | + if (in_array($type, array('DROPDOWN', 'RADIO_BTN', 'CHECKBOX')) |
|
| 340 | + && isset($input_types[ $field_ID ]) |
|
| 341 | + && isset($input_types[ $field_ID ]['options']) |
|
| 342 | + ) { |
|
| 343 | + foreach ($input_types[ $field_ID ]['options'] as $option) { |
|
| 344 | + $option = stripslashes_deep($option); |
|
| 345 | + $option_id = ! empty($option['id']) ? $option['id'] : 0; |
|
| 346 | + $QSO = EE_Question_Option::new_instance( |
|
| 347 | + array( |
|
| 348 | + 'QSO_value' => (string) $option_id, |
|
| 349 | + 'QSO_desc' => $option['text'], |
|
| 350 | + 'QSO_deleted' => false, |
|
| 351 | + ) |
|
| 352 | + ); |
|
| 353 | + // all QST (and ANS) properties can be accessed indirectly thru QFI |
|
| 354 | + $QFI->add_temp_option($QSO); |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + // we don't want ppl manually changing primary keys cuz that would just lead to total craziness man |
|
| 358 | + if ($disabled || $field_ID == $object->get_model()->primary_key_name()) { |
|
| 359 | + $QFI->set('QST_disabled', true); |
|
| 360 | + } |
|
| 361 | + // EEH_Debug_Tools::printr( $QFI, '$QFI <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 362 | + $inputs[ $field_ID ] = $QFI; |
|
| 363 | + // if ( $field_ID == 'CNT_active' ) { |
|
| 364 | + // EEH_Debug_Tools::printr( $QFI, '$QFI <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 365 | + // } |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + return $inputs; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * add_temp_option |
|
| 375 | + * |
|
| 376 | + * @access public |
|
| 377 | + * @param \EE_Question_Option $QSO EE_Question_Option |
|
| 378 | + * @return boolean |
|
| 379 | + */ |
|
| 380 | + public function add_temp_option(EE_Question_Option $QSO) |
|
| 381 | + { |
|
| 382 | + $this->_QST->add_temp_option($QSO); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * set property values for question form input |
|
| 388 | + * |
|
| 389 | + * @access public |
|
| 390 | + * @param string $property |
|
| 391 | + * @param mixed $value |
|
| 392 | + * @return mixed |
|
| 393 | + */ |
|
| 394 | + public function set($property = null, $value = null) |
|
| 395 | + { |
|
| 396 | + if (! empty($property)) { |
|
| 397 | + if (EEM_Question::instance()->has_field($property)) { |
|
| 398 | + $this->_QST->set($property, $value); |
|
| 399 | + } elseif (EEM_Answer::instance()->has_field($property)) { |
|
| 400 | + $this->_ANS->set($property, $value); |
|
| 401 | + } elseif ($this->_question_form_input_property_exists(__CLASS__, $property)) { |
|
| 402 | + // echo "<hr>$property is a prop of QFI"; |
|
| 403 | + $this->{$property} = $value; |
|
| 404 | + return true; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + return null; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * _question_form_input_property_exists |
|
| 413 | + * |
|
| 414 | + * @access public |
|
| 415 | + * @param boolean $notDeletedOptionsOnly 1 |
|
| 416 | + * whether to return ALL options, or only the ones which have |
|
| 417 | + * not yet been deleted |
|
| 418 | + * @param string|array $selected_value_to_always_include , when retrieving options to an ANSWERED question, |
|
| 419 | + * we want to usually only show non-deleted options AND the |
|
| 420 | + * value that was selected for the answer, whether it was |
|
| 421 | + * trashed or not. |
|
| 422 | + * @return EE_Question_Option |
|
| 423 | + */ |
|
| 424 | + public function options($notDeletedOptionsOnly = true, $selected_value_to_always_include = null) |
|
| 425 | + { |
|
| 426 | + $temp_options = $this->_QST->temp_options(); |
|
| 427 | + return ! empty($temp_options) |
|
| 428 | + ? $temp_options |
|
| 429 | + : $this->_QST->options( |
|
| 430 | + $notDeletedOptionsOnly, |
|
| 431 | + $selected_value_to_always_include |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * get_meta |
|
| 438 | + * |
|
| 439 | + * @access public |
|
| 440 | + * @param mixed $key |
|
| 441 | + * @return mixed |
|
| 442 | + */ |
|
| 443 | + public function get_meta($key = false) |
|
| 444 | + { |
|
| 445 | + return $key && isset($this->_QST_meta[ $key ]) ? $this->_QST_meta[ $key ] : false; |
|
| 446 | + } |
|
| 447 | 447 | } |
@@ -141,13 +141,13 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | private function _set_input_name($qstn_id) |
| 143 | 143 | { |
| 144 | - if (! empty($qstn_id)) { |
|
| 144 | + if ( ! empty($qstn_id)) { |
|
| 145 | 145 | $ANS_ID = $this->get('ANS_ID'); |
| 146 | - $qstn_id = ! empty($ANS_ID) ? '[' . $qstn_id . '][' . $ANS_ID . ']' : '[' . $qstn_id . ']'; |
|
| 146 | + $qstn_id = ! empty($ANS_ID) ? '['.$qstn_id.']['.$ANS_ID.']' : '['.$qstn_id.']'; |
|
| 147 | 147 | } |
| 148 | 148 | $this->QST_input_name = $this->_QST_meta['append_qstn_id'] && ! empty($qstn_id) |
| 149 | - ? $this->_QST_meta['input_prefix'] . $this->_QST_meta['input_name'] . $qstn_id |
|
| 150 | - : $this->_QST_meta['input_prefix'] . $this->_QST_meta['input_name']; |
|
| 149 | + ? $this->_QST_meta['input_prefix'].$this->_QST_meta['input_name'].$qstn_id |
|
| 150 | + : $this->_QST_meta['input_prefix'].$this->_QST_meta['input_name']; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | public function get($property = null) |
| 162 | 162 | { |
| 163 | - if (! empty($property)) { |
|
| 163 | + if ( ! empty($property)) { |
|
| 164 | 164 | if (EEM_Question::instance()->has_field($property)) { |
| 165 | 165 | return $this->_QST->get($property); |
| 166 | 166 | } elseif (EEM_Answer::instance()->has_field($property)) { |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | { |
| 186 | 186 | // first try regular property exists method which works as expected in PHP 5.3+ |
| 187 | 187 | $prop = EEH_Class_Tools::has_property($classname, $property); |
| 188 | - if (! $prop) { |
|
| 188 | + if ( ! $prop) { |
|
| 189 | 189 | // use reflection for < PHP 5.3 as a double check when property is not found, possible due to access restriction |
| 190 | 190 | $reflector = new ReflectionClass($classname); |
| 191 | 191 | $prop = $reflector->hasProperty($property); |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | ? $this->_QST_meta['input_id'] |
| 208 | 208 | : sanitize_key(strip_tags($this->_QST->get('QST_display_text'))); |
| 209 | 209 | $this->QST_input_id = $this->_QST_meta['append_qstn_id'] && ! empty($qstn_id) |
| 210 | - ? $input_id . '-' . $qstn_id |
|
| 210 | + ? $input_id.'-'.$qstn_id |
|
| 211 | 211 | : $input_id; |
| 212 | 212 | } |
| 213 | 213 | |
@@ -240,9 +240,9 @@ discard block |
||
| 240 | 240 | && isset($this->_QST_meta['time']) |
| 241 | 241 | && isset($this->_QST_meta['price_id']) |
| 242 | 242 | ) { |
| 243 | - if (isset($_REQUEST['qstn'][ $this->_QST_meta['EVT_ID'] ][ $this->_QST_meta['att_nmbr'] ][ $this->_QST_meta['date'] ][ $this->_QST_meta['time'] ][ $this->_QST_meta['price_id'] ][ $qstn_id ]) |
|
| 243 | + if (isset($_REQUEST['qstn'][$this->_QST_meta['EVT_ID']][$this->_QST_meta['att_nmbr']][$this->_QST_meta['date']][$this->_QST_meta['time']][$this->_QST_meta['price_id']][$qstn_id]) |
|
| 244 | 244 | ) { |
| 245 | - $answer = $_REQUEST['qstn'][ $this->_QST_meta['EVT_ID'] ][ $this->_QST_meta['att_nmbr'] ][ $this->_QST_meta['date'] ][ $this->_QST_meta['time'] ][ $this->_QST_meta['price_id'] ][ $qstn_id ]; |
|
| 245 | + $answer = $_REQUEST['qstn'][$this->_QST_meta['EVT_ID']][$this->_QST_meta['att_nmbr']][$this->_QST_meta['date']][$this->_QST_meta['time']][$this->_QST_meta['price_id']][$qstn_id]; |
|
| 246 | 246 | $this->_ANS->set('ANS_value', $answer); |
| 247 | 247 | } |
| 248 | 248 | } |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | public static function generate_question_form_inputs_for_object($object = false, $input_types = array()) |
| 261 | 261 | { |
| 262 | - if (! is_object($object)) { |
|
| 262 | + if ( ! is_object($object)) { |
|
| 263 | 263 | return false; |
| 264 | 264 | } |
| 265 | 265 | $inputs = array(); |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | if ($field instanceof EE_Model_Field_Base) { |
| 273 | 273 | // echo '<h4>$field_ID : ' . $field_ID . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
| 274 | 274 | // EEH_Debug_Tools::printr( $field, '$field <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
| 275 | - if (isset($input_types[ $field_ID ])) { |
|
| 275 | + if (isset($input_types[$field_ID])) { |
|
| 276 | 276 | // get saved value for field |
| 277 | 277 | $value = $object->get($field_ID); |
| 278 | 278 | // echo '<h4>$value : ' . $value . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
@@ -281,30 +281,30 @@ discard block |
||
| 281 | 281 | // if ( $field_ID == 'CNT_active' ) |
| 282 | 282 | // echo '<h4>$value : ' . $value . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
| 283 | 283 | // determine question type |
| 284 | - $type = isset($input_types[ $field_ID ]) ? $input_types[ $field_ID ]['type'] : 'TEXT'; |
|
| 284 | + $type = isset($input_types[$field_ID]) ? $input_types[$field_ID]['type'] : 'TEXT'; |
|
| 285 | 285 | // input name |
| 286 | - $input_name = isset($input_types[ $field_ID ]) && isset($input_types[ $field_ID ]['input_name']) |
|
| 287 | - ? $input_types[ $field_ID ]['input_name'] . '[' . $field_ID . ']' |
|
| 286 | + $input_name = isset($input_types[$field_ID]) && isset($input_types[$field_ID]['input_name']) |
|
| 287 | + ? $input_types[$field_ID]['input_name'].'['.$field_ID.']' |
|
| 288 | 288 | : $field_ID; |
| 289 | 289 | // css class for input |
| 290 | - $class = isset($input_types[ $field_ID ]['class']) && ! empty($input_types[ $field_ID ]['class']) |
|
| 291 | - ? ' ' . $input_types[ $field_ID ]['class'] |
|
| 290 | + $class = isset($input_types[$field_ID]['class']) && ! empty($input_types[$field_ID]['class']) |
|
| 291 | + ? ' '.$input_types[$field_ID]['class'] |
|
| 292 | 292 | : ''; |
| 293 | 293 | // whether to apply htmlentities to answer |
| 294 | - $htmlentities = isset($input_types[ $field_ID ]['htmlentities']) |
|
| 295 | - ? $input_types[ $field_ID ]['htmlentities'] |
|
| 294 | + $htmlentities = isset($input_types[$field_ID]['htmlentities']) |
|
| 295 | + ? $input_types[$field_ID]['htmlentities'] |
|
| 296 | 296 | : true; |
| 297 | 297 | // whether to apply htmlentities to answer |
| 298 | - $label_b4 = isset($input_types[ $field_ID ]['label_b4']) |
|
| 299 | - ? $input_types[ $field_ID ]['label_b4'] |
|
| 298 | + $label_b4 = isset($input_types[$field_ID]['label_b4']) |
|
| 299 | + ? $input_types[$field_ID]['label_b4'] |
|
| 300 | 300 | : false; |
| 301 | 301 | // whether to apply htmlentities to answer |
| 302 | - $use_desc_4_label = isset($input_types[ $field_ID ]['use_desc_4_label']) |
|
| 303 | - ? $input_types[ $field_ID ]['use_desc_4_label'] |
|
| 302 | + $use_desc_4_label = isset($input_types[$field_ID]['use_desc_4_label']) |
|
| 303 | + ? $input_types[$field_ID]['use_desc_4_label'] |
|
| 304 | 304 | : false; |
| 305 | 305 | // whether input is disabled |
| 306 | - $disabled = isset($input_types[ $field_ID ]['disabled']) |
|
| 307 | - ? $input_types[ $field_ID ]['disabled'] |
|
| 306 | + $disabled = isset($input_types[$field_ID]['disabled']) |
|
| 307 | + ? $input_types[$field_ID]['disabled'] |
|
| 308 | 308 | : false; |
| 309 | 309 | |
| 310 | 310 | // create EE_Question_Form_Input object |
@@ -325,9 +325,9 @@ discard block |
||
| 325 | 325 | ) |
| 326 | 326 | ), |
| 327 | 327 | array( |
| 328 | - 'input_id' => $field_ID . '-' . $object->ID(), |
|
| 328 | + 'input_id' => $field_ID.'-'.$object->ID(), |
|
| 329 | 329 | 'input_name' => $input_name, |
| 330 | - 'input_class' => $field_ID . $class, |
|
| 330 | + 'input_class' => $field_ID.$class, |
|
| 331 | 331 | 'input_prefix' => '', |
| 332 | 332 | 'append_qstn_id' => false, |
| 333 | 333 | 'htmlentities' => $htmlentities, |
@@ -337,10 +337,10 @@ discard block |
||
| 337 | 337 | ); |
| 338 | 338 | // does question type have options ? |
| 339 | 339 | if (in_array($type, array('DROPDOWN', 'RADIO_BTN', 'CHECKBOX')) |
| 340 | - && isset($input_types[ $field_ID ]) |
|
| 341 | - && isset($input_types[ $field_ID ]['options']) |
|
| 340 | + && isset($input_types[$field_ID]) |
|
| 341 | + && isset($input_types[$field_ID]['options']) |
|
| 342 | 342 | ) { |
| 343 | - foreach ($input_types[ $field_ID ]['options'] as $option) { |
|
| 343 | + foreach ($input_types[$field_ID]['options'] as $option) { |
|
| 344 | 344 | $option = stripslashes_deep($option); |
| 345 | 345 | $option_id = ! empty($option['id']) ? $option['id'] : 0; |
| 346 | 346 | $QSO = EE_Question_Option::new_instance( |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | $QFI->set('QST_disabled', true); |
| 360 | 360 | } |
| 361 | 361 | // EEH_Debug_Tools::printr( $QFI, '$QFI <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
| 362 | - $inputs[ $field_ID ] = $QFI; |
|
| 362 | + $inputs[$field_ID] = $QFI; |
|
| 363 | 363 | // if ( $field_ID == 'CNT_active' ) { |
| 364 | 364 | // EEH_Debug_Tools::printr( $QFI, '$QFI <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
| 365 | 365 | // } |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | */ |
| 394 | 394 | public function set($property = null, $value = null) |
| 395 | 395 | { |
| 396 | - if (! empty($property)) { |
|
| 396 | + if ( ! empty($property)) { |
|
| 397 | 397 | if (EEM_Question::instance()->has_field($property)) { |
| 398 | 398 | $this->_QST->set($property, $value); |
| 399 | 399 | } elseif (EEM_Answer::instance()->has_field($property)) { |
@@ -442,6 +442,6 @@ discard block |
||
| 442 | 442 | */ |
| 443 | 443 | public function get_meta($key = false) |
| 444 | 444 | { |
| 445 | - return $key && isset($this->_QST_meta[ $key ]) ? $this->_QST_meta[ $key ] : false; |
|
| 445 | + return $key && isset($this->_QST_meta[$key]) ? $this->_QST_meta[$key] : false; |
|
| 446 | 446 | } |
| 447 | 447 | } |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * Adds the question to this question group |
| 216 | 216 | * |
| 217 | 217 | * @param EE_Question || int $question object or ID |
| 218 | - * @return boolean if successful |
|
| 218 | + * @return EE_Base_Class if successful |
|
| 219 | 219 | */ |
| 220 | 220 | public function add_question($questionObjectOrID) |
| 221 | 221 | { |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | * Removes the question from this question group |
| 228 | 228 | * |
| 229 | 229 | * @param EE_Question || int $question object or ID |
| 230 | - * @return boolean of success |
|
| 230 | + * @return EE_Base_Class of success |
|
| 231 | 231 | */ |
| 232 | 232 | public function remove_question($questionObjectOrID) |
| 233 | 233 | { |
@@ -12,280 +12,280 @@ |
||
| 12 | 12 | class EE_Question_Group extends EE_Soft_Delete_Base_Class |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @param array $props_n_values |
|
| 17 | - * @return EE_Question_Group|mixed |
|
| 18 | - */ |
|
| 19 | - public static function new_instance($props_n_values = array()) |
|
| 20 | - { |
|
| 21 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 22 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @param array $props_n_values |
|
| 28 | - * @return EE_Question_Group |
|
| 29 | - */ |
|
| 30 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 31 | - { |
|
| 32 | - return new self($props_n_values, true); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * gets the question group's name |
|
| 38 | - * |
|
| 39 | - * @access public |
|
| 40 | - * @param bool $pretty |
|
| 41 | - * @return string |
|
| 42 | - */ |
|
| 43 | - public function name($pretty = false) |
|
| 44 | - { |
|
| 45 | - return $pretty ? $this->get_pretty('QSG_name') : $this->get('QSG_name'); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Gets the question group's internal name |
|
| 51 | - * |
|
| 52 | - * @access public |
|
| 53 | - * @return string |
|
| 54 | - */ |
|
| 55 | - public function identifier() |
|
| 56 | - { |
|
| 57 | - return $this->get('QSG_identifier'); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Gets the question group's description |
|
| 63 | - * |
|
| 64 | - * @access public |
|
| 65 | - * @param bool $pretty |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 68 | - public function desc($pretty = false) |
|
| 69 | - { |
|
| 70 | - return $pretty ? $this->get_pretty('QSG_desc') : $this->get('QSG_desc'); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Gets the question group's order number in a sequence |
|
| 76 | - * of other question groups |
|
| 77 | - * |
|
| 78 | - * @access public |
|
| 79 | - * @return int |
|
| 80 | - */ |
|
| 81 | - public function order() |
|
| 82 | - { |
|
| 83 | - return $this->get('QSG_order'); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Returns whether to show the group's name on the frontend |
|
| 89 | - * |
|
| 90 | - * @access public |
|
| 91 | - * @return boolean |
|
| 92 | - */ |
|
| 93 | - public function show_group_name() |
|
| 94 | - { |
|
| 95 | - return $this->get('QSG_show_group_name'); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Returns whether to show the group's description |
|
| 101 | - * on the frontend |
|
| 102 | - * |
|
| 103 | - * @access public |
|
| 104 | - * @return boolean |
|
| 105 | - */ |
|
| 106 | - public function show_group_desc() |
|
| 107 | - { |
|
| 108 | - return $this->get('QSG_show_group_desc'); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Returns whether this is a 'system group' (meaning |
|
| 114 | - * a question group integral to the system, whose questions |
|
| 115 | - * relate to the attendee table) |
|
| 116 | - * |
|
| 117 | - * @access public |
|
| 118 | - * @return int |
|
| 119 | - */ |
|
| 120 | - public function system_group() |
|
| 121 | - { |
|
| 122 | - return $this->get('QSG_system'); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * get the author of the question group. |
|
| 128 | - * |
|
| 129 | - * @since 4.5.0 |
|
| 130 | - * |
|
| 131 | - * @return int |
|
| 132 | - */ |
|
| 133 | - public function wp_user() |
|
| 134 | - { |
|
| 135 | - return $this->get('QSG_wp_user'); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Returns whether this question group has |
|
| 141 | - * been deleted |
|
| 142 | - * |
|
| 143 | - * @access public |
|
| 144 | - * @return boolean |
|
| 145 | - */ |
|
| 146 | - public function deleted() |
|
| 147 | - { |
|
| 148 | - return $this->get('QST_deleted'); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Gets an array of questions with questions IN the group at the start of the array and questions NOT in the group |
|
| 154 | - * at the end of the array. Questions in the group are ordered by Question_Group_Question.QGQ_order and questions |
|
| 155 | - * NOT in the group are ordered by Question.QGQ_order |
|
| 156 | - * |
|
| 157 | - * @return EE_Question[] |
|
| 158 | - */ |
|
| 159 | - public function questions_in_and_not_in_group() |
|
| 160 | - { |
|
| 161 | - $questions_in_group = $this->questions(); |
|
| 162 | - $exclude_question_ids = ! empty($questions_in_group) ? array_keys($questions_in_group) : array(); |
|
| 163 | - $questions_not_in_group = $this->questions_not_in_group($exclude_question_ids); |
|
| 164 | - return $questions_in_group + $questions_not_in_group; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Gets all the questions which are part of this question group (ordered Question_Group_Question.QGQ_order) |
|
| 170 | - * |
|
| 171 | - * @param array $query_params |
|
| 172 | - * @return EE_Question[] |
|
| 173 | - */ |
|
| 174 | - public function questions($query_params = array()) |
|
| 175 | - { |
|
| 176 | - $query_params = ! empty($query_params) ? $query_params |
|
| 177 | - : array('order_by' => array('Question_Group_Question.QGQ_order' => 'ASC')); |
|
| 178 | - return $this->ID() ? $this->get_many_related('Question', $query_params) : array(); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Gets all the questions which are NOT part of this question group. |
|
| 184 | - * |
|
| 185 | - * @param mixed $question_IDS_in_group if empty array then all questions returned. if FALSE then we first get |
|
| 186 | - * questions in this group and exclude them from questions get all. IF empty |
|
| 187 | - * array then we just return all questions. |
|
| 188 | - * @return EE_Question[] |
|
| 189 | - */ |
|
| 190 | - public function questions_not_in_group($question_IDS_in_group = false) |
|
| 191 | - { |
|
| 192 | - if ($question_IDS_in_group === false) { |
|
| 193 | - $questions = $this->questions(); |
|
| 194 | - $question_IDS_in_group = ! empty($questions) ? array_keys($questions) : array(); |
|
| 195 | - } |
|
| 196 | - $_where = ! empty($question_IDS_in_group) ? array('QST_ID' => array('not_in', $question_IDS_in_group)) |
|
| 197 | - : array(); |
|
| 198 | - |
|
| 199 | - return EEM_Question::instance()->get_all(array($_where, 'order_by' => array('QST_ID' => 'ASC'))); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Gets all events which are related to this question group |
|
| 205 | - * |
|
| 206 | - * @return EE_Event[] |
|
| 207 | - */ |
|
| 208 | - public function events() |
|
| 209 | - { |
|
| 210 | - return $this->get_many_related('Event'); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Adds the question to this question group |
|
| 216 | - * |
|
| 217 | - * @param EE_Question || int $question object or ID |
|
| 218 | - * @return boolean if successful |
|
| 219 | - */ |
|
| 220 | - public function add_question($questionObjectOrID) |
|
| 221 | - { |
|
| 222 | - return $this->_add_relation_to($questionObjectOrID, 'Question'); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Removes the question from this question group |
|
| 228 | - * |
|
| 229 | - * @param EE_Question || int $question object or ID |
|
| 230 | - * @return boolean of success |
|
| 231 | - */ |
|
| 232 | - public function remove_question($questionObjectOrID) |
|
| 233 | - { |
|
| 234 | - return $this->_remove_relation_to($questionObjectOrID, 'Question'); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @param $questionObjectOrID |
|
| 240 | - * @param $qst_order |
|
| 241 | - * @return int |
|
| 242 | - */ |
|
| 243 | - public function update_question_order($questionObjectOrID, $qst_order) |
|
| 244 | - { |
|
| 245 | - $qst_ID = $questionObjectOrID instanceof EE_Question ? $questionObjectOrID->ID() : (int) $questionObjectOrID; |
|
| 246 | - return EEM_Question_Group_Question::instance()->update( |
|
| 247 | - array('QGQ_order' => $qst_order), |
|
| 248 | - array( |
|
| 249 | - array( |
|
| 250 | - 'QST_ID' => $qst_ID, |
|
| 251 | - 'QSG_ID' => $this->ID(), |
|
| 252 | - ), |
|
| 253 | - ) |
|
| 254 | - ); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Basically this is method just returns whether the question group has any questions with answers. This is used |
|
| 260 | - * by the admin currently to determine whether we should display the ui for deleting permanently or not b/c |
|
| 261 | - * question groups with questions that have answers should not be possible to delete permanently |
|
| 262 | - * |
|
| 263 | - * @return boolean true if has questions with answers, false if not. |
|
| 264 | - */ |
|
| 265 | - public function has_questions_with_answers() |
|
| 266 | - { |
|
| 267 | - $has_answers = false; |
|
| 268 | - $questions = $this->get_many_related('Question'); |
|
| 269 | - foreach ($questions as $question) { |
|
| 270 | - if ($question->count_related('Answer') > 0) { |
|
| 271 | - $has_answers = true; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - return $has_answers; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * The purpose of this method is set the question group order for this question group to be the max out of all |
|
| 280 | - * question groups |
|
| 281 | - * |
|
| 282 | - * @access public |
|
| 283 | - * @return void |
|
| 284 | - */ |
|
| 285 | - public function set_order_to_latest() |
|
| 286 | - { |
|
| 287 | - $latest_order = $this->get_model()->get_latest_question_group_order(); |
|
| 288 | - $latest_order++; |
|
| 289 | - $this->set('QSG_order', $latest_order); |
|
| 290 | - } |
|
| 15 | + /** |
|
| 16 | + * @param array $props_n_values |
|
| 17 | + * @return EE_Question_Group|mixed |
|
| 18 | + */ |
|
| 19 | + public static function new_instance($props_n_values = array()) |
|
| 20 | + { |
|
| 21 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 22 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @param array $props_n_values |
|
| 28 | + * @return EE_Question_Group |
|
| 29 | + */ |
|
| 30 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 31 | + { |
|
| 32 | + return new self($props_n_values, true); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * gets the question group's name |
|
| 38 | + * |
|
| 39 | + * @access public |
|
| 40 | + * @param bool $pretty |
|
| 41 | + * @return string |
|
| 42 | + */ |
|
| 43 | + public function name($pretty = false) |
|
| 44 | + { |
|
| 45 | + return $pretty ? $this->get_pretty('QSG_name') : $this->get('QSG_name'); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Gets the question group's internal name |
|
| 51 | + * |
|
| 52 | + * @access public |
|
| 53 | + * @return string |
|
| 54 | + */ |
|
| 55 | + public function identifier() |
|
| 56 | + { |
|
| 57 | + return $this->get('QSG_identifier'); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Gets the question group's description |
|
| 63 | + * |
|
| 64 | + * @access public |
|
| 65 | + * @param bool $pretty |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | + public function desc($pretty = false) |
|
| 69 | + { |
|
| 70 | + return $pretty ? $this->get_pretty('QSG_desc') : $this->get('QSG_desc'); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Gets the question group's order number in a sequence |
|
| 76 | + * of other question groups |
|
| 77 | + * |
|
| 78 | + * @access public |
|
| 79 | + * @return int |
|
| 80 | + */ |
|
| 81 | + public function order() |
|
| 82 | + { |
|
| 83 | + return $this->get('QSG_order'); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Returns whether to show the group's name on the frontend |
|
| 89 | + * |
|
| 90 | + * @access public |
|
| 91 | + * @return boolean |
|
| 92 | + */ |
|
| 93 | + public function show_group_name() |
|
| 94 | + { |
|
| 95 | + return $this->get('QSG_show_group_name'); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Returns whether to show the group's description |
|
| 101 | + * on the frontend |
|
| 102 | + * |
|
| 103 | + * @access public |
|
| 104 | + * @return boolean |
|
| 105 | + */ |
|
| 106 | + public function show_group_desc() |
|
| 107 | + { |
|
| 108 | + return $this->get('QSG_show_group_desc'); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Returns whether this is a 'system group' (meaning |
|
| 114 | + * a question group integral to the system, whose questions |
|
| 115 | + * relate to the attendee table) |
|
| 116 | + * |
|
| 117 | + * @access public |
|
| 118 | + * @return int |
|
| 119 | + */ |
|
| 120 | + public function system_group() |
|
| 121 | + { |
|
| 122 | + return $this->get('QSG_system'); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * get the author of the question group. |
|
| 128 | + * |
|
| 129 | + * @since 4.5.0 |
|
| 130 | + * |
|
| 131 | + * @return int |
|
| 132 | + */ |
|
| 133 | + public function wp_user() |
|
| 134 | + { |
|
| 135 | + return $this->get('QSG_wp_user'); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Returns whether this question group has |
|
| 141 | + * been deleted |
|
| 142 | + * |
|
| 143 | + * @access public |
|
| 144 | + * @return boolean |
|
| 145 | + */ |
|
| 146 | + public function deleted() |
|
| 147 | + { |
|
| 148 | + return $this->get('QST_deleted'); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Gets an array of questions with questions IN the group at the start of the array and questions NOT in the group |
|
| 154 | + * at the end of the array. Questions in the group are ordered by Question_Group_Question.QGQ_order and questions |
|
| 155 | + * NOT in the group are ordered by Question.QGQ_order |
|
| 156 | + * |
|
| 157 | + * @return EE_Question[] |
|
| 158 | + */ |
|
| 159 | + public function questions_in_and_not_in_group() |
|
| 160 | + { |
|
| 161 | + $questions_in_group = $this->questions(); |
|
| 162 | + $exclude_question_ids = ! empty($questions_in_group) ? array_keys($questions_in_group) : array(); |
|
| 163 | + $questions_not_in_group = $this->questions_not_in_group($exclude_question_ids); |
|
| 164 | + return $questions_in_group + $questions_not_in_group; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Gets all the questions which are part of this question group (ordered Question_Group_Question.QGQ_order) |
|
| 170 | + * |
|
| 171 | + * @param array $query_params |
|
| 172 | + * @return EE_Question[] |
|
| 173 | + */ |
|
| 174 | + public function questions($query_params = array()) |
|
| 175 | + { |
|
| 176 | + $query_params = ! empty($query_params) ? $query_params |
|
| 177 | + : array('order_by' => array('Question_Group_Question.QGQ_order' => 'ASC')); |
|
| 178 | + return $this->ID() ? $this->get_many_related('Question', $query_params) : array(); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Gets all the questions which are NOT part of this question group. |
|
| 184 | + * |
|
| 185 | + * @param mixed $question_IDS_in_group if empty array then all questions returned. if FALSE then we first get |
|
| 186 | + * questions in this group and exclude them from questions get all. IF empty |
|
| 187 | + * array then we just return all questions. |
|
| 188 | + * @return EE_Question[] |
|
| 189 | + */ |
|
| 190 | + public function questions_not_in_group($question_IDS_in_group = false) |
|
| 191 | + { |
|
| 192 | + if ($question_IDS_in_group === false) { |
|
| 193 | + $questions = $this->questions(); |
|
| 194 | + $question_IDS_in_group = ! empty($questions) ? array_keys($questions) : array(); |
|
| 195 | + } |
|
| 196 | + $_where = ! empty($question_IDS_in_group) ? array('QST_ID' => array('not_in', $question_IDS_in_group)) |
|
| 197 | + : array(); |
|
| 198 | + |
|
| 199 | + return EEM_Question::instance()->get_all(array($_where, 'order_by' => array('QST_ID' => 'ASC'))); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Gets all events which are related to this question group |
|
| 205 | + * |
|
| 206 | + * @return EE_Event[] |
|
| 207 | + */ |
|
| 208 | + public function events() |
|
| 209 | + { |
|
| 210 | + return $this->get_many_related('Event'); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Adds the question to this question group |
|
| 216 | + * |
|
| 217 | + * @param EE_Question || int $question object or ID |
|
| 218 | + * @return boolean if successful |
|
| 219 | + */ |
|
| 220 | + public function add_question($questionObjectOrID) |
|
| 221 | + { |
|
| 222 | + return $this->_add_relation_to($questionObjectOrID, 'Question'); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Removes the question from this question group |
|
| 228 | + * |
|
| 229 | + * @param EE_Question || int $question object or ID |
|
| 230 | + * @return boolean of success |
|
| 231 | + */ |
|
| 232 | + public function remove_question($questionObjectOrID) |
|
| 233 | + { |
|
| 234 | + return $this->_remove_relation_to($questionObjectOrID, 'Question'); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @param $questionObjectOrID |
|
| 240 | + * @param $qst_order |
|
| 241 | + * @return int |
|
| 242 | + */ |
|
| 243 | + public function update_question_order($questionObjectOrID, $qst_order) |
|
| 244 | + { |
|
| 245 | + $qst_ID = $questionObjectOrID instanceof EE_Question ? $questionObjectOrID->ID() : (int) $questionObjectOrID; |
|
| 246 | + return EEM_Question_Group_Question::instance()->update( |
|
| 247 | + array('QGQ_order' => $qst_order), |
|
| 248 | + array( |
|
| 249 | + array( |
|
| 250 | + 'QST_ID' => $qst_ID, |
|
| 251 | + 'QSG_ID' => $this->ID(), |
|
| 252 | + ), |
|
| 253 | + ) |
|
| 254 | + ); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Basically this is method just returns whether the question group has any questions with answers. This is used |
|
| 260 | + * by the admin currently to determine whether we should display the ui for deleting permanently or not b/c |
|
| 261 | + * question groups with questions that have answers should not be possible to delete permanently |
|
| 262 | + * |
|
| 263 | + * @return boolean true if has questions with answers, false if not. |
|
| 264 | + */ |
|
| 265 | + public function has_questions_with_answers() |
|
| 266 | + { |
|
| 267 | + $has_answers = false; |
|
| 268 | + $questions = $this->get_many_related('Question'); |
|
| 269 | + foreach ($questions as $question) { |
|
| 270 | + if ($question->count_related('Answer') > 0) { |
|
| 271 | + $has_answers = true; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + return $has_answers; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * The purpose of this method is set the question group order for this question group to be the max out of all |
|
| 280 | + * question groups |
|
| 281 | + * |
|
| 282 | + * @access public |
|
| 283 | + * @return void |
|
| 284 | + */ |
|
| 285 | + public function set_order_to_latest() |
|
| 286 | + { |
|
| 287 | + $latest_order = $this->get_model()->get_latest_question_group_order(); |
|
| 288 | + $latest_order++; |
|
| 289 | + $this->set('QSG_order', $latest_order); |
|
| 290 | + } |
|
| 291 | 291 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param array $props_n_values incoming values from the database |
| 40 | 40 | * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
| 41 | 41 | * the website will be used. |
| 42 | - * @return EE_Attendee |
|
| 42 | + * @return EE_Question_Option |
|
| 43 | 43 | */ |
| 44 | 44 | public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
| 45 | 45 | { |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * Sets the option's key value |
| 52 | 52 | * |
| 53 | 53 | * @param string $value |
| 54 | - * @return bool success |
|
| 54 | + * @return boolean|null success |
|
| 55 | 55 | */ |
| 56 | 56 | public function set_value($value) |
| 57 | 57 | { |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * Sets the option's Display Text |
| 64 | 64 | * |
| 65 | 65 | * @param string $text |
| 66 | - * @return bool success |
|
| 66 | + * @return boolean|null success |
|
| 67 | 67 | */ |
| 68 | 68 | public function set_desc($text) |
| 69 | 69 | { |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @access public |
| 78 | 78 | * @param integer $order |
| 79 | - * @return bool $success |
|
| 79 | + * @return boolean|null $success |
|
| 80 | 80 | */ |
| 81 | 81 | public function set_order($order) |
| 82 | 82 | { |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * Sets the ID of the related question |
| 89 | 89 | * |
| 90 | 90 | * @param int $question_ID |
| 91 | - * @return bool success |
|
| 91 | + * @return boolean|null success |
|
| 92 | 92 | */ |
| 93 | 93 | public function set_question_ID($question_ID) |
| 94 | 94 | { |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * Sets the option's opt_group |
| 101 | 101 | * |
| 102 | 102 | * @param string $text |
| 103 | - * @return bool success |
|
| 103 | + * @return string success |
|
| 104 | 104 | */ |
| 105 | 105 | public function set_opt_group($text) |
| 106 | 106 | { |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | * Sets QSO_system |
| 221 | 221 | * |
| 222 | 222 | * @param string $QSO_system |
| 223 | - * @return bool |
|
| 223 | + * @return boolean|null |
|
| 224 | 224 | */ |
| 225 | 225 | public function set_system($QSO_system) |
| 226 | 226 | { |
@@ -10,220 +10,220 @@ |
||
| 10 | 10 | class EE_Question_Option extends EE_Soft_Delete_Base_Class implements EEI_Duplicatable |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Question Option Opt Group Name |
|
| 15 | - * |
|
| 16 | - * @access protected |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - protected $_QSO_opt_group = null; |
|
| 20 | - |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * |
|
| 24 | - * @param array $props_n_values incoming values |
|
| 25 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 26 | - * used.) |
|
| 27 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 28 | - * date_format and the second value is the time format |
|
| 29 | - * @return EE_Attendee |
|
| 30 | - */ |
|
| 31 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 32 | - { |
|
| 33 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 34 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @param array $props_n_values incoming values from the database |
|
| 40 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 41 | - * the website will be used. |
|
| 42 | - * @return EE_Attendee |
|
| 43 | - */ |
|
| 44 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 45 | - { |
|
| 46 | - return new self($props_n_values, true, $timezone); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Sets the option's key value |
|
| 52 | - * |
|
| 53 | - * @param string $value |
|
| 54 | - * @return bool success |
|
| 55 | - */ |
|
| 56 | - public function set_value($value) |
|
| 57 | - { |
|
| 58 | - $this->set('QSO_value', $value); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Sets the option's Display Text |
|
| 64 | - * |
|
| 65 | - * @param string $text |
|
| 66 | - * @return bool success |
|
| 67 | - */ |
|
| 68 | - public function set_desc($text) |
|
| 69 | - { |
|
| 70 | - $this->set('QSO_desc', $text); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Sets the order for this option |
|
| 76 | - * |
|
| 77 | - * @access public |
|
| 78 | - * @param integer $order |
|
| 79 | - * @return bool $success |
|
| 80 | - */ |
|
| 81 | - public function set_order($order) |
|
| 82 | - { |
|
| 83 | - $this->set('QSO_order', $order); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Sets the ID of the related question |
|
| 89 | - * |
|
| 90 | - * @param int $question_ID |
|
| 91 | - * @return bool success |
|
| 92 | - */ |
|
| 93 | - public function set_question_ID($question_ID) |
|
| 94 | - { |
|
| 95 | - $this->set('QST_ID', $question_ID); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Sets the option's opt_group |
|
| 101 | - * |
|
| 102 | - * @param string $text |
|
| 103 | - * @return bool success |
|
| 104 | - */ |
|
| 105 | - public function set_opt_group($text) |
|
| 106 | - { |
|
| 107 | - return $this->_QSO_opt_group = $text; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Gets the option's key value |
|
| 113 | - * |
|
| 114 | - * @return string |
|
| 115 | - */ |
|
| 116 | - public function value() |
|
| 117 | - { |
|
| 118 | - return $this->get('QSO_value'); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Gets the option's display text |
|
| 124 | - * |
|
| 125 | - * @return string |
|
| 126 | - */ |
|
| 127 | - public function desc() |
|
| 128 | - { |
|
| 129 | - return $this->get('QSO_desc'); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Returns whether this option has been deleted or not |
|
| 135 | - * |
|
| 136 | - * @return boolean |
|
| 137 | - */ |
|
| 138 | - public function deleted() |
|
| 139 | - { |
|
| 140 | - return $this->get('QSO_deleted'); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Returns the order or the Question Option |
|
| 146 | - * |
|
| 147 | - * @access public |
|
| 148 | - * @return integer |
|
| 149 | - */ |
|
| 150 | - public function order() |
|
| 151 | - { |
|
| 152 | - return $this->get('QSO_option'); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Gets the related question's ID |
|
| 158 | - * |
|
| 159 | - * @return int |
|
| 160 | - */ |
|
| 161 | - public function question_ID() |
|
| 162 | - { |
|
| 163 | - return $this->get('QST_ID'); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Returns the question related to this question option |
|
| 169 | - * |
|
| 170 | - * @return EE_Question |
|
| 171 | - */ |
|
| 172 | - public function question() |
|
| 173 | - { |
|
| 174 | - return $this->get_first_related('Question'); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Gets the option's opt_group |
|
| 180 | - * |
|
| 181 | - * @return string |
|
| 182 | - */ |
|
| 183 | - public function opt_group() |
|
| 184 | - { |
|
| 185 | - return $this->_QSO_opt_group; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Duplicates this question option. By default the new question option will be for the same question, |
|
| 190 | - * but that can be overriden by setting the 'QST_ID' option |
|
| 191 | - * |
|
| 192 | - * @param array $options { |
|
| 193 | - * @type int $QST_ID the QST_ID attribute of this question option, otherwise it will be for the same question |
|
| 194 | - * as the original |
|
| 195 | - */ |
|
| 196 | - public function duplicate($options = array()) |
|
| 197 | - { |
|
| 198 | - $new_question_option = clone $this; |
|
| 199 | - $new_question_option->set('QSO_ID', null); |
|
| 200 | - if (array_key_exists( |
|
| 201 | - 'QST_ID', |
|
| 202 | - $options |
|
| 203 | - )) {// use array_key_exists instead of isset because NULL might be a valid value |
|
| 204 | - $new_question_option->set_question_ID($options['QST_ID']); |
|
| 205 | - } |
|
| 206 | - $new_question_option->save(); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Gets the QSO_system value |
|
| 211 | - * |
|
| 212 | - * @return string|null |
|
| 213 | - */ |
|
| 214 | - public function system() |
|
| 215 | - { |
|
| 216 | - return $this->get('QSO_system'); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Sets QSO_system |
|
| 221 | - * |
|
| 222 | - * @param string $QSO_system |
|
| 223 | - * @return bool |
|
| 224 | - */ |
|
| 225 | - public function set_system($QSO_system) |
|
| 226 | - { |
|
| 227 | - return $this->set('QSO_system', $QSO_system); |
|
| 228 | - } |
|
| 13 | + /** |
|
| 14 | + * Question Option Opt Group Name |
|
| 15 | + * |
|
| 16 | + * @access protected |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + protected $_QSO_opt_group = null; |
|
| 20 | + |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * |
|
| 24 | + * @param array $props_n_values incoming values |
|
| 25 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 26 | + * used.) |
|
| 27 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 28 | + * date_format and the second value is the time format |
|
| 29 | + * @return EE_Attendee |
|
| 30 | + */ |
|
| 31 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 32 | + { |
|
| 33 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 34 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @param array $props_n_values incoming values from the database |
|
| 40 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 41 | + * the website will be used. |
|
| 42 | + * @return EE_Attendee |
|
| 43 | + */ |
|
| 44 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 45 | + { |
|
| 46 | + return new self($props_n_values, true, $timezone); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Sets the option's key value |
|
| 52 | + * |
|
| 53 | + * @param string $value |
|
| 54 | + * @return bool success |
|
| 55 | + */ |
|
| 56 | + public function set_value($value) |
|
| 57 | + { |
|
| 58 | + $this->set('QSO_value', $value); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Sets the option's Display Text |
|
| 64 | + * |
|
| 65 | + * @param string $text |
|
| 66 | + * @return bool success |
|
| 67 | + */ |
|
| 68 | + public function set_desc($text) |
|
| 69 | + { |
|
| 70 | + $this->set('QSO_desc', $text); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Sets the order for this option |
|
| 76 | + * |
|
| 77 | + * @access public |
|
| 78 | + * @param integer $order |
|
| 79 | + * @return bool $success |
|
| 80 | + */ |
|
| 81 | + public function set_order($order) |
|
| 82 | + { |
|
| 83 | + $this->set('QSO_order', $order); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Sets the ID of the related question |
|
| 89 | + * |
|
| 90 | + * @param int $question_ID |
|
| 91 | + * @return bool success |
|
| 92 | + */ |
|
| 93 | + public function set_question_ID($question_ID) |
|
| 94 | + { |
|
| 95 | + $this->set('QST_ID', $question_ID); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Sets the option's opt_group |
|
| 101 | + * |
|
| 102 | + * @param string $text |
|
| 103 | + * @return bool success |
|
| 104 | + */ |
|
| 105 | + public function set_opt_group($text) |
|
| 106 | + { |
|
| 107 | + return $this->_QSO_opt_group = $text; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Gets the option's key value |
|
| 113 | + * |
|
| 114 | + * @return string |
|
| 115 | + */ |
|
| 116 | + public function value() |
|
| 117 | + { |
|
| 118 | + return $this->get('QSO_value'); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Gets the option's display text |
|
| 124 | + * |
|
| 125 | + * @return string |
|
| 126 | + */ |
|
| 127 | + public function desc() |
|
| 128 | + { |
|
| 129 | + return $this->get('QSO_desc'); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Returns whether this option has been deleted or not |
|
| 135 | + * |
|
| 136 | + * @return boolean |
|
| 137 | + */ |
|
| 138 | + public function deleted() |
|
| 139 | + { |
|
| 140 | + return $this->get('QSO_deleted'); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Returns the order or the Question Option |
|
| 146 | + * |
|
| 147 | + * @access public |
|
| 148 | + * @return integer |
|
| 149 | + */ |
|
| 150 | + public function order() |
|
| 151 | + { |
|
| 152 | + return $this->get('QSO_option'); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Gets the related question's ID |
|
| 158 | + * |
|
| 159 | + * @return int |
|
| 160 | + */ |
|
| 161 | + public function question_ID() |
|
| 162 | + { |
|
| 163 | + return $this->get('QST_ID'); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Returns the question related to this question option |
|
| 169 | + * |
|
| 170 | + * @return EE_Question |
|
| 171 | + */ |
|
| 172 | + public function question() |
|
| 173 | + { |
|
| 174 | + return $this->get_first_related('Question'); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Gets the option's opt_group |
|
| 180 | + * |
|
| 181 | + * @return string |
|
| 182 | + */ |
|
| 183 | + public function opt_group() |
|
| 184 | + { |
|
| 185 | + return $this->_QSO_opt_group; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Duplicates this question option. By default the new question option will be for the same question, |
|
| 190 | + * but that can be overriden by setting the 'QST_ID' option |
|
| 191 | + * |
|
| 192 | + * @param array $options { |
|
| 193 | + * @type int $QST_ID the QST_ID attribute of this question option, otherwise it will be for the same question |
|
| 194 | + * as the original |
|
| 195 | + */ |
|
| 196 | + public function duplicate($options = array()) |
|
| 197 | + { |
|
| 198 | + $new_question_option = clone $this; |
|
| 199 | + $new_question_option->set('QSO_ID', null); |
|
| 200 | + if (array_key_exists( |
|
| 201 | + 'QST_ID', |
|
| 202 | + $options |
|
| 203 | + )) {// use array_key_exists instead of isset because NULL might be a valid value |
|
| 204 | + $new_question_option->set_question_ID($options['QST_ID']); |
|
| 205 | + } |
|
| 206 | + $new_question_option->save(); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Gets the QSO_system value |
|
| 211 | + * |
|
| 212 | + * @return string|null |
|
| 213 | + */ |
|
| 214 | + public function system() |
|
| 215 | + { |
|
| 216 | + return $this->get('QSO_system'); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Sets QSO_system |
|
| 221 | + * |
|
| 222 | + * @param string $QSO_system |
|
| 223 | + * @return bool |
|
| 224 | + */ |
|
| 225 | + public function set_system($QSO_system) |
|
| 226 | + { |
|
| 227 | + return $this->set('QSO_system', $QSO_system); |
|
| 228 | + } |
|
| 229 | 229 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * Sets code |
| 53 | 53 | * |
| 54 | 54 | * @param string $code |
| 55 | - * @return boolean |
|
| 55 | + * @return boolean|null |
|
| 56 | 56 | */ |
| 57 | 57 | public function set_code($code) |
| 58 | 58 | { |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * Sets desc |
| 76 | 76 | * |
| 77 | 77 | * @param string $desc |
| 78 | - * @return boolean |
|
| 78 | + * @return boolean|null |
|
| 79 | 79 | */ |
| 80 | 80 | public function set_desc($desc) |
| 81 | 81 | { |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * Sets type |
| 99 | 99 | * |
| 100 | 100 | * @param string $type |
| 101 | - * @return boolean |
|
| 101 | + * @return boolean|null |
|
| 102 | 102 | */ |
| 103 | 103 | public function set_type($type) |
| 104 | 104 | { |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * Sets can_edit |
| 122 | 122 | * |
| 123 | 123 | * @param boolean $can_edit |
| 124 | - * @return boolean |
|
| 124 | + * @return boolean|null |
|
| 125 | 125 | */ |
| 126 | 126 | public function set_can_edit($can_edit) |
| 127 | 127 | { |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * Sets open |
| 145 | 145 | * |
| 146 | 146 | * @param boolean $open |
| 147 | - * @return boolean |
|
| 147 | + * @return boolean|null |
|
| 148 | 148 | */ |
| 149 | 149 | public function set_open($open) |
| 150 | 150 | { |
@@ -12,142 +12,142 @@ |
||
| 12 | 12 | class EE_Status extends EE_Base_Class |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @param array $props_n_values |
|
| 17 | - * @return EE_Status |
|
| 18 | - */ |
|
| 19 | - public static function new_instance($props_n_values = array()) |
|
| 20 | - { |
|
| 21 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 22 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @param array $props_n_values |
|
| 28 | - * @return EE_Status |
|
| 29 | - */ |
|
| 30 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 31 | - { |
|
| 32 | - return new self($props_n_values, true); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Gets code |
|
| 38 | - * |
|
| 39 | - * @param bool $plural |
|
| 40 | - * @param string $schema |
|
| 41 | - * @return string |
|
| 42 | - */ |
|
| 43 | - public function code($plural = false, $schema = 'upper') |
|
| 44 | - { |
|
| 45 | - $id = $this->get('STS_ID'); |
|
| 46 | - $code = EEM_Status::instance()->localized_status(array($id => $this->get('STS_code')), $plural, $schema); |
|
| 47 | - return $code[ $id ]; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Sets code |
|
| 53 | - * |
|
| 54 | - * @param string $code |
|
| 55 | - * @return boolean |
|
| 56 | - */ |
|
| 57 | - public function set_code($code) |
|
| 58 | - { |
|
| 59 | - $this->set('STS_code', $code); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Gets desc |
|
| 65 | - * |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 68 | - public function desc() |
|
| 69 | - { |
|
| 70 | - return $this->get('STS_desc'); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Sets desc |
|
| 76 | - * |
|
| 77 | - * @param string $desc |
|
| 78 | - * @return boolean |
|
| 79 | - */ |
|
| 80 | - public function set_desc($desc) |
|
| 81 | - { |
|
| 82 | - $this->set('STS_desc', $desc); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Gets type |
|
| 88 | - * |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public function type() |
|
| 92 | - { |
|
| 93 | - return $this->get('STS_type'); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Sets type |
|
| 99 | - * |
|
| 100 | - * @param string $type |
|
| 101 | - * @return boolean |
|
| 102 | - */ |
|
| 103 | - public function set_type($type) |
|
| 104 | - { |
|
| 105 | - $this->set('STS_type', $type); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Gets can_edit |
|
| 111 | - * |
|
| 112 | - * @return boolean |
|
| 113 | - */ |
|
| 114 | - public function can_edit() |
|
| 115 | - { |
|
| 116 | - return $this->get('STS_can_edit'); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Sets can_edit |
|
| 122 | - * |
|
| 123 | - * @param boolean $can_edit |
|
| 124 | - * @return boolean |
|
| 125 | - */ |
|
| 126 | - public function set_can_edit($can_edit) |
|
| 127 | - { |
|
| 128 | - $this->set('STS_can_edit', $can_edit); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Gets open |
|
| 134 | - * |
|
| 135 | - * @return boolean |
|
| 136 | - */ |
|
| 137 | - public function open() |
|
| 138 | - { |
|
| 139 | - return $this->get('STS_open'); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Sets open |
|
| 145 | - * |
|
| 146 | - * @param boolean $open |
|
| 147 | - * @return boolean |
|
| 148 | - */ |
|
| 149 | - public function set_open($open) |
|
| 150 | - { |
|
| 151 | - $this->set('STS_open', $open); |
|
| 152 | - } |
|
| 15 | + /** |
|
| 16 | + * @param array $props_n_values |
|
| 17 | + * @return EE_Status |
|
| 18 | + */ |
|
| 19 | + public static function new_instance($props_n_values = array()) |
|
| 20 | + { |
|
| 21 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 22 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @param array $props_n_values |
|
| 28 | + * @return EE_Status |
|
| 29 | + */ |
|
| 30 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 31 | + { |
|
| 32 | + return new self($props_n_values, true); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Gets code |
|
| 38 | + * |
|
| 39 | + * @param bool $plural |
|
| 40 | + * @param string $schema |
|
| 41 | + * @return string |
|
| 42 | + */ |
|
| 43 | + public function code($plural = false, $schema = 'upper') |
|
| 44 | + { |
|
| 45 | + $id = $this->get('STS_ID'); |
|
| 46 | + $code = EEM_Status::instance()->localized_status(array($id => $this->get('STS_code')), $plural, $schema); |
|
| 47 | + return $code[ $id ]; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Sets code |
|
| 53 | + * |
|
| 54 | + * @param string $code |
|
| 55 | + * @return boolean |
|
| 56 | + */ |
|
| 57 | + public function set_code($code) |
|
| 58 | + { |
|
| 59 | + $this->set('STS_code', $code); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Gets desc |
|
| 65 | + * |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | + public function desc() |
|
| 69 | + { |
|
| 70 | + return $this->get('STS_desc'); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Sets desc |
|
| 76 | + * |
|
| 77 | + * @param string $desc |
|
| 78 | + * @return boolean |
|
| 79 | + */ |
|
| 80 | + public function set_desc($desc) |
|
| 81 | + { |
|
| 82 | + $this->set('STS_desc', $desc); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Gets type |
|
| 88 | + * |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public function type() |
|
| 92 | + { |
|
| 93 | + return $this->get('STS_type'); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Sets type |
|
| 99 | + * |
|
| 100 | + * @param string $type |
|
| 101 | + * @return boolean |
|
| 102 | + */ |
|
| 103 | + public function set_type($type) |
|
| 104 | + { |
|
| 105 | + $this->set('STS_type', $type); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Gets can_edit |
|
| 111 | + * |
|
| 112 | + * @return boolean |
|
| 113 | + */ |
|
| 114 | + public function can_edit() |
|
| 115 | + { |
|
| 116 | + return $this->get('STS_can_edit'); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Sets can_edit |
|
| 122 | + * |
|
| 123 | + * @param boolean $can_edit |
|
| 124 | + * @return boolean |
|
| 125 | + */ |
|
| 126 | + public function set_can_edit($can_edit) |
|
| 127 | + { |
|
| 128 | + $this->set('STS_can_edit', $can_edit); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Gets open |
|
| 134 | + * |
|
| 135 | + * @return boolean |
|
| 136 | + */ |
|
| 137 | + public function open() |
|
| 138 | + { |
|
| 139 | + return $this->get('STS_open'); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Sets open |
|
| 145 | + * |
|
| 146 | + * @param boolean $open |
|
| 147 | + * @return boolean |
|
| 148 | + */ |
|
| 149 | + public function set_open($open) |
|
| 150 | + { |
|
| 151 | + $this->set('STS_open', $open); |
|
| 152 | + } |
|
| 153 | 153 | } |
@@ -44,7 +44,7 @@ |
||
| 44 | 44 | { |
| 45 | 45 | $id = $this->get('STS_ID'); |
| 46 | 46 | $code = EEM_Status::instance()->localized_status(array($id => $this->get('STS_code')), $plural, $schema); |
| 47 | - return $code[ $id ]; |
|
| 47 | + return $code[$id]; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * Sets name |
| 67 | 67 | * |
| 68 | 68 | * @param string $name |
| 69 | - * @return boolean |
|
| 69 | + * @return boolean|null |
|
| 70 | 70 | */ |
| 71 | 71 | public function set_name($name) |
| 72 | 72 | { |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * Sets slug |
| 90 | 90 | * |
| 91 | 91 | * @param string $slug |
| 92 | - * @return boolean |
|
| 92 | + * @return boolean|null |
|
| 93 | 93 | */ |
| 94 | 94 | public function set_slug($slug) |
| 95 | 95 | { |
@@ -12,87 +12,87 @@ |
||
| 12 | 12 | class EE_Term extends EE_Base_Class |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - public $post_type; |
|
| 15 | + public $post_type; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Sets some dynamic defaults |
|
| 19 | - * |
|
| 20 | - * @param array $fieldValues |
|
| 21 | - * @param bool $bydb |
|
| 22 | - * @param string $timezone |
|
| 23 | - */ |
|
| 24 | - protected function __construct($fieldValues = array(), $bydb = false, $timezone = '') |
|
| 25 | - { |
|
| 26 | - if (! isset($fieldValues['slug'])) { |
|
| 27 | - $fieldValues['slug'] = $fieldValues['name']; |
|
| 28 | - } |
|
| 29 | - parent::__construct($fieldValues, $bydb, $timezone); |
|
| 30 | - } |
|
| 17 | + /** |
|
| 18 | + * Sets some dynamic defaults |
|
| 19 | + * |
|
| 20 | + * @param array $fieldValues |
|
| 21 | + * @param bool $bydb |
|
| 22 | + * @param string $timezone |
|
| 23 | + */ |
|
| 24 | + protected function __construct($fieldValues = array(), $bydb = false, $timezone = '') |
|
| 25 | + { |
|
| 26 | + if (! isset($fieldValues['slug'])) { |
|
| 27 | + $fieldValues['slug'] = $fieldValues['name']; |
|
| 28 | + } |
|
| 29 | + parent::__construct($fieldValues, $bydb, $timezone); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param array $props_n_values |
|
| 35 | - * @return EE_Term|mixed |
|
| 36 | - */ |
|
| 37 | - public static function new_instance($props_n_values = array()) |
|
| 38 | - { |
|
| 39 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 40 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 41 | - } |
|
| 33 | + /** |
|
| 34 | + * @param array $props_n_values |
|
| 35 | + * @return EE_Term|mixed |
|
| 36 | + */ |
|
| 37 | + public static function new_instance($props_n_values = array()) |
|
| 38 | + { |
|
| 39 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 40 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param array $props_n_values |
|
| 46 | - * @return EE_Term |
|
| 47 | - */ |
|
| 48 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 49 | - { |
|
| 50 | - return new self($props_n_values, true); |
|
| 51 | - } |
|
| 44 | + /** |
|
| 45 | + * @param array $props_n_values |
|
| 46 | + * @return EE_Term |
|
| 47 | + */ |
|
| 48 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 49 | + { |
|
| 50 | + return new self($props_n_values, true); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Gets name |
|
| 56 | - * |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 59 | - public function name() |
|
| 60 | - { |
|
| 61 | - return $this->get('name'); |
|
| 62 | - } |
|
| 54 | + /** |
|
| 55 | + * Gets name |
|
| 56 | + * |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | + public function name() |
|
| 60 | + { |
|
| 61 | + return $this->get('name'); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Sets name |
|
| 67 | - * |
|
| 68 | - * @param string $name |
|
| 69 | - * @return boolean |
|
| 70 | - */ |
|
| 71 | - public function set_name($name) |
|
| 72 | - { |
|
| 73 | - $this->set('name', $name); |
|
| 74 | - } |
|
| 65 | + /** |
|
| 66 | + * Sets name |
|
| 67 | + * |
|
| 68 | + * @param string $name |
|
| 69 | + * @return boolean |
|
| 70 | + */ |
|
| 71 | + public function set_name($name) |
|
| 72 | + { |
|
| 73 | + $this->set('name', $name); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Gets slug |
|
| 79 | - * |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function slug() |
|
| 83 | - { |
|
| 84 | - return $this->get('slug'); |
|
| 85 | - } |
|
| 77 | + /** |
|
| 78 | + * Gets slug |
|
| 79 | + * |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function slug() |
|
| 83 | + { |
|
| 84 | + return $this->get('slug'); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Sets slug |
|
| 90 | - * |
|
| 91 | - * @param string $slug |
|
| 92 | - * @return boolean |
|
| 93 | - */ |
|
| 94 | - public function set_slug($slug) |
|
| 95 | - { |
|
| 96 | - $this->set('slug', $slug); |
|
| 97 | - } |
|
| 88 | + /** |
|
| 89 | + * Sets slug |
|
| 90 | + * |
|
| 91 | + * @param string $slug |
|
| 92 | + * @return boolean |
|
| 93 | + */ |
|
| 94 | + public function set_slug($slug) |
|
| 95 | + { |
|
| 96 | + $this->set('slug', $slug); |
|
| 97 | + } |
|
| 98 | 98 | } |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | protected function __construct($fieldValues = array(), $bydb = false, $timezone = '') |
| 25 | 25 | { |
| 26 | - if (! isset($fieldValues['slug'])) { |
|
| 26 | + if ( ! isset($fieldValues['slug'])) { |
|
| 27 | 27 | $fieldValues['slug'] = $fieldValues['name']; |
| 28 | 28 | } |
| 29 | 29 | parent::__construct($fieldValues, $bydb, $timezone); |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * Sets taxonomy |
| 48 | 48 | * |
| 49 | 49 | * @param string $taxonomy |
| 50 | - * @return boolean |
|
| 50 | + * @return boolean|null |
|
| 51 | 51 | */ |
| 52 | 52 | public function set_taxonomy($taxonomy) |
| 53 | 53 | { |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * Sets term_count |
| 71 | 71 | * |
| 72 | 72 | * @param int $term_count |
| 73 | - * @return boolean |
|
| 73 | + * @return boolean|null |
|
| 74 | 74 | */ |
| 75 | 75 | public function set_count($term_count) |
| 76 | 76 | { |
@@ -11,80 +11,80 @@ |
||
| 11 | 11 | class EE_Term_Taxonomy extends EE_Base_Class |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @param array $props_n_values |
|
| 16 | - * @return EE_Term_Taxonomy |
|
| 17 | - */ |
|
| 18 | - public static function new_instance($props_n_values = array()) |
|
| 19 | - { |
|
| 20 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 21 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 22 | - } |
|
| 14 | + /** |
|
| 15 | + * @param array $props_n_values |
|
| 16 | + * @return EE_Term_Taxonomy |
|
| 17 | + */ |
|
| 18 | + public static function new_instance($props_n_values = array()) |
|
| 19 | + { |
|
| 20 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 21 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @param array $props_n_values |
|
| 27 | - * @return EE_Term_Taxonomy |
|
| 28 | - */ |
|
| 29 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 30 | - { |
|
| 31 | - return new self($props_n_values, true); |
|
| 32 | - } |
|
| 25 | + /** |
|
| 26 | + * @param array $props_n_values |
|
| 27 | + * @return EE_Term_Taxonomy |
|
| 28 | + */ |
|
| 29 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 30 | + { |
|
| 31 | + return new self($props_n_values, true); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Gets taxonomy |
|
| 37 | - * |
|
| 38 | - * @return string |
|
| 39 | - */ |
|
| 40 | - public function taxonomy() |
|
| 41 | - { |
|
| 42 | - return $this->get('taxonomy'); |
|
| 43 | - } |
|
| 35 | + /** |
|
| 36 | + * Gets taxonomy |
|
| 37 | + * |
|
| 38 | + * @return string |
|
| 39 | + */ |
|
| 40 | + public function taxonomy() |
|
| 41 | + { |
|
| 42 | + return $this->get('taxonomy'); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Sets taxonomy |
|
| 48 | - * |
|
| 49 | - * @param string $taxonomy |
|
| 50 | - * @return boolean |
|
| 51 | - */ |
|
| 52 | - public function set_taxonomy($taxonomy) |
|
| 53 | - { |
|
| 54 | - $this->set('taxonomy', $taxonomy); |
|
| 55 | - } |
|
| 46 | + /** |
|
| 47 | + * Sets taxonomy |
|
| 48 | + * |
|
| 49 | + * @param string $taxonomy |
|
| 50 | + * @return boolean |
|
| 51 | + */ |
|
| 52 | + public function set_taxonomy($taxonomy) |
|
| 53 | + { |
|
| 54 | + $this->set('taxonomy', $taxonomy); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Gets term_count |
|
| 60 | - * |
|
| 61 | - * @return int |
|
| 62 | - */ |
|
| 63 | - public function count() |
|
| 64 | - { |
|
| 65 | - return $this->get('term_count'); |
|
| 66 | - } |
|
| 58 | + /** |
|
| 59 | + * Gets term_count |
|
| 60 | + * |
|
| 61 | + * @return int |
|
| 62 | + */ |
|
| 63 | + public function count() |
|
| 64 | + { |
|
| 65 | + return $this->get('term_count'); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Sets term_count |
|
| 71 | - * |
|
| 72 | - * @param int $term_count |
|
| 73 | - * @return boolean |
|
| 74 | - */ |
|
| 75 | - public function set_count($term_count) |
|
| 76 | - { |
|
| 77 | - $this->set('term_count', $term_count); |
|
| 78 | - } |
|
| 69 | + /** |
|
| 70 | + * Sets term_count |
|
| 71 | + * |
|
| 72 | + * @param int $term_count |
|
| 73 | + * @return boolean |
|
| 74 | + */ |
|
| 75 | + public function set_count($term_count) |
|
| 76 | + { |
|
| 77 | + $this->set('term_count', $term_count); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Gets the term for this term taxonomy |
|
| 83 | - * |
|
| 84 | - * @return EE_Term |
|
| 85 | - */ |
|
| 86 | - public function term() |
|
| 87 | - { |
|
| 88 | - return $this->get_first_related('Term'); |
|
| 89 | - } |
|
| 81 | + /** |
|
| 82 | + * Gets the term for this term taxonomy |
|
| 83 | + * |
|
| 84 | + * @return EE_Term |
|
| 85 | + */ |
|
| 86 | + public function term() |
|
| 87 | + { |
|
| 88 | + return $this->get_first_related('Term'); |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -121,7 +121,8 @@ |
||
| 121 | 121 | * relevant status const |
| 122 | 122 | * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
| 123 | 123 | * further processing |
| 124 | - * @return mixed status int if the display string isn't requested |
|
| 124 | + * @param boolean $remaining |
|
| 125 | + * @return string status int if the display string isn't requested |
|
| 125 | 126 | * @throws \EE_Error |
| 126 | 127 | */ |
| 127 | 128 | public function ticket_status($display = false, $remaining = null) |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | public function ticket_status($display = false, $remaining = null) |
| 128 | 128 | { |
| 129 | 129 | $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
| 130 | - if (! $remaining) { |
|
| 130 | + if ( ! $remaining) { |
|
| 131 | 131 | return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
| 132 | 132 | } |
| 133 | 133 | if ($this->get('TKT_deleted')) { |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | : ''; |
| 246 | 246 | $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date($dt_frmt) : ''; |
| 247 | 247 | |
| 248 | - return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
| 248 | + return $first_date && $last_date ? $first_date.$conjunction.$last_date : ''; |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | */ |
| 273 | 273 | public function datetimes($query_params = array()) |
| 274 | 274 | { |
| 275 | - if (! isset($query_params['order_by'])) { |
|
| 275 | + if ( ! isset($query_params['order_by'])) { |
|
| 276 | 276 | $query_params['order_by']['DTT_order'] = 'ASC'; |
| 277 | 277 | } |
| 278 | 278 | return $this->get_many_related('Datetime', $query_params); |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | if (empty($tickets_sold['datetime'])) { |
| 318 | 318 | return $total; |
| 319 | 319 | } |
| 320 | - if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
| 320 | + if ( ! empty($dtt_id) && ! isset($tickets_sold['datetime'][$dtt_id])) { |
|
| 321 | 321 | EE_Error::add_error( |
| 322 | 322 | __( |
| 323 | 323 | 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | ); |
| 330 | 330 | return $total; |
| 331 | 331 | } |
| 332 | - return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
| 332 | + return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][$dtt_id]; |
|
| 333 | 333 | break; |
| 334 | 334 | default: |
| 335 | 335 | return $total; |
@@ -347,9 +347,9 @@ discard block |
||
| 347 | 347 | { |
| 348 | 348 | $datetimes = $this->get_many_related('Datetime'); |
| 349 | 349 | $tickets_sold = array(); |
| 350 | - if (! empty($datetimes)) { |
|
| 350 | + if ( ! empty($datetimes)) { |
|
| 351 | 351 | foreach ($datetimes as $datetime) { |
| 352 | - $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
| 352 | + $tickets_sold['datetime'][$datetime->ID()] = $datetime->get('DTT_sold'); |
|
| 353 | 353 | } |
| 354 | 354 | } |
| 355 | 355 | // Tickets sold |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | $sold = $this->sold() + $qty; |
| 757 | 757 | // remove ticket reservation, but don't adjust datetime reservations, because that will happen |
| 758 | 758 | // via \EE_Datetime::increase_sold() when \EE_Ticket::_increase_sold_for_datetimes() is called |
| 759 | - $this->decrease_reserved($qty, false, "TKT: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 759 | + $this->decrease_reserved($qty, false, "TKT: {$this->ID()} (ln:".__LINE__.')'); |
|
| 760 | 760 | $this->_increase_sold_for_datetimes($qty); |
| 761 | 761 | $this->set_sold($sold); |
| 762 | 762 | do_action( |
@@ -1300,7 +1300,7 @@ discard block |
||
| 1300 | 1300 | foreach ($this->datetimes() as $datetime) { |
| 1301 | 1301 | $times[] = $datetime->start_date_and_time(); |
| 1302 | 1302 | } |
| 1303 | - return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
| 1303 | + return $this->name().' @ '.implode(', ', $times).' for '.$this->pretty_price(); |
|
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | 1306 | |
@@ -1406,7 +1406,7 @@ discard block |
||
| 1406 | 1406 | { |
| 1407 | 1407 | // get one datetime to use for getting the event |
| 1408 | 1408 | $datetime = $this->first_datetime(); |
| 1409 | - if (! $datetime instanceof \EE_Datetime) { |
|
| 1409 | + if ( ! $datetime instanceof \EE_Datetime) { |
|
| 1410 | 1410 | throw new UnexpectedEntityException( |
| 1411 | 1411 | $datetime, |
| 1412 | 1412 | 'EE_Datetime', |
@@ -1417,7 +1417,7 @@ discard block |
||
| 1417 | 1417 | ); |
| 1418 | 1418 | } |
| 1419 | 1419 | $event = $datetime->event(); |
| 1420 | - if (! $event instanceof \EE_Event) { |
|
| 1420 | + if ( ! $event instanceof \EE_Event) { |
|
| 1421 | 1421 | throw new UnexpectedEntityException( |
| 1422 | 1422 | $event, |
| 1423 | 1423 | 'EE_Event', |
@@ -12,1464 +12,1464 @@ |
||
| 12 | 12 | class EE_Ticket extends EE_Soft_Delete_Base_Class implements EEI_Line_Item_Object, EEI_Event_Relation, EEI_Has_Icon |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * The following constants are used by the ticket_status() method to indicate whether a ticket is on sale or not. |
|
| 17 | - */ |
|
| 18 | - const sold_out = 'TKS'; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * |
|
| 22 | - */ |
|
| 23 | - const expired = 'TKE'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * |
|
| 27 | - */ |
|
| 28 | - const archived = 'TKA'; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * |
|
| 32 | - */ |
|
| 33 | - const pending = 'TKP'; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * |
|
| 37 | - */ |
|
| 38 | - const onsale = 'TKO'; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * extra meta key for tracking ticket reservations |
|
| 42 | - * |
|
| 43 | - * @type string |
|
| 44 | - */ |
|
| 45 | - const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * cached result from method of the same name |
|
| 49 | - * |
|
| 50 | - * @var float $_ticket_total_with_taxes |
|
| 51 | - */ |
|
| 52 | - private $_ticket_total_with_taxes; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param array $props_n_values incoming values |
|
| 57 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 58 | - * used.) |
|
| 59 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 60 | - * date_format and the second value is the time format |
|
| 61 | - * @return EE_Ticket |
|
| 62 | - * @throws \EE_Error |
|
| 63 | - */ |
|
| 64 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 65 | - { |
|
| 66 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 67 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @param array $props_n_values incoming values from the database |
|
| 73 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 74 | - * the website will be used. |
|
| 75 | - * @return EE_Ticket |
|
| 76 | - * @throws \EE_Error |
|
| 77 | - */ |
|
| 78 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 79 | - { |
|
| 80 | - return new self($props_n_values, true, $timezone); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @return bool |
|
| 86 | - * @throws \EE_Error |
|
| 87 | - */ |
|
| 88 | - public function parent() |
|
| 89 | - { |
|
| 90 | - return $this->get('TKT_parent'); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * return if a ticket has quantities available for purchase |
|
| 96 | - * |
|
| 97 | - * @param int $DTT_ID the primary key for a particular datetime |
|
| 98 | - * @return boolean |
|
| 99 | - * @throws \EE_Error |
|
| 100 | - */ |
|
| 101 | - public function available($DTT_ID = 0) |
|
| 102 | - { |
|
| 103 | - // are we checking availability for a particular datetime ? |
|
| 104 | - if ($DTT_ID) { |
|
| 105 | - // get that datetime object |
|
| 106 | - $datetime = $this->get_first_related('Datetime', array(array('DTT_ID' => $DTT_ID))); |
|
| 107 | - // if ticket sales for this datetime have exceeded the reg limit... |
|
| 108 | - if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
| 109 | - return false; |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - // datetime is still open for registration, but is this ticket sold out ? |
|
| 113 | - return $this->qty() < 1 || $this->qty() > $this->sold() ? true : false; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
| 119 | - * |
|
| 120 | - * @param bool $display true = we'll return a localized string, otherwise we just return the value of the |
|
| 121 | - * relevant status const |
|
| 122 | - * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
|
| 123 | - * further processing |
|
| 124 | - * @return mixed status int if the display string isn't requested |
|
| 125 | - * @throws \EE_Error |
|
| 126 | - */ |
|
| 127 | - public function ticket_status($display = false, $remaining = null) |
|
| 128 | - { |
|
| 129 | - $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
|
| 130 | - if (! $remaining) { |
|
| 131 | - return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
|
| 132 | - } |
|
| 133 | - if ($this->get('TKT_deleted')) { |
|
| 134 | - return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived; |
|
| 135 | - } |
|
| 136 | - if ($this->is_expired()) { |
|
| 137 | - return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired; |
|
| 138 | - } |
|
| 139 | - if ($this->is_pending()) { |
|
| 140 | - return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending; |
|
| 141 | - } |
|
| 142 | - if ($this->is_on_sale()) { |
|
| 143 | - return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale; |
|
| 144 | - } |
|
| 145 | - return ''; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale |
|
| 151 | - * considering ALL the factors used for figuring that out. |
|
| 152 | - * |
|
| 153 | - * @access public |
|
| 154 | - * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
| 155 | - * @return boolean true = tickets remaining, false not. |
|
| 156 | - * @throws \EE_Error |
|
| 157 | - */ |
|
| 158 | - public function is_remaining($DTT_ID = 0) |
|
| 159 | - { |
|
| 160 | - $num_remaining = $this->remaining($DTT_ID); |
|
| 161 | - if ($num_remaining === 0) { |
|
| 162 | - return false; |
|
| 163 | - } |
|
| 164 | - if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
| 165 | - return false; |
|
| 166 | - } |
|
| 167 | - return true; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * return the total number of tickets available for purchase |
|
| 173 | - * |
|
| 174 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
| 175 | - * set to 0 for all related datetimes |
|
| 176 | - * @return int |
|
| 177 | - * @throws \EE_Error |
|
| 178 | - */ |
|
| 179 | - public function remaining($DTT_ID = 0) |
|
| 180 | - { |
|
| 181 | - return $this->real_quantity_on_ticket('saleable', $DTT_ID); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Gets min |
|
| 187 | - * |
|
| 188 | - * @return int |
|
| 189 | - * @throws \EE_Error |
|
| 190 | - */ |
|
| 191 | - public function min() |
|
| 192 | - { |
|
| 193 | - return $this->get('TKT_min'); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * return if a ticket is no longer available cause its available dates have expired. |
|
| 199 | - * |
|
| 200 | - * @return boolean |
|
| 201 | - * @throws \EE_Error |
|
| 202 | - */ |
|
| 203 | - public function is_expired() |
|
| 204 | - { |
|
| 205 | - return ($this->get_raw('TKT_end_date') < time()); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Return if a ticket is yet to go on sale or not |
|
| 211 | - * |
|
| 212 | - * @return boolean |
|
| 213 | - * @throws \EE_Error |
|
| 214 | - */ |
|
| 215 | - public function is_pending() |
|
| 216 | - { |
|
| 217 | - return ($this->get_raw('TKT_start_date') > time()); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Return if a ticket is on sale or not |
|
| 223 | - * |
|
| 224 | - * @return boolean |
|
| 225 | - * @throws \EE_Error |
|
| 226 | - */ |
|
| 227 | - public function is_on_sale() |
|
| 228 | - { |
|
| 229 | - return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time()); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * This returns the chronologically last datetime that this ticket is associated with |
|
| 235 | - * |
|
| 236 | - * @param string $dt_frmt |
|
| 237 | - * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
|
| 238 | - * the end date ie: Jan 01 "to" Dec 31 |
|
| 239 | - * @return string |
|
| 240 | - * @throws \EE_Error |
|
| 241 | - */ |
|
| 242 | - public function date_range($dt_frmt = '', $conjunction = ' - ') |
|
| 243 | - { |
|
| 244 | - $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date($dt_frmt) |
|
| 245 | - : ''; |
|
| 246 | - $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date($dt_frmt) : ''; |
|
| 247 | - |
|
| 248 | - return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * This returns the chronologically first datetime that this ticket is associated with |
|
| 254 | - * |
|
| 255 | - * @return EE_Datetime |
|
| 256 | - * @throws \EE_Error |
|
| 257 | - */ |
|
| 258 | - public function first_datetime() |
|
| 259 | - { |
|
| 260 | - $datetimes = $this->datetimes(array('limit' => 1)); |
|
| 261 | - return reset($datetimes); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Gets all the datetimes this ticket can be used for attending. |
|
| 267 | - * Unless otherwise specified, orders datetimes by start date. |
|
| 268 | - * |
|
| 269 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 270 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
| 271 | - * @throws \EE_Error |
|
| 272 | - */ |
|
| 273 | - public function datetimes($query_params = array()) |
|
| 274 | - { |
|
| 275 | - if (! isset($query_params['order_by'])) { |
|
| 276 | - $query_params['order_by']['DTT_order'] = 'ASC'; |
|
| 277 | - } |
|
| 278 | - return $this->get_many_related('Datetime', $query_params); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * This returns the chronologically last datetime that this ticket is associated with |
|
| 284 | - * |
|
| 285 | - * @return EE_Datetime |
|
| 286 | - * @throws \EE_Error |
|
| 287 | - */ |
|
| 288 | - public function last_datetime() |
|
| 289 | - { |
|
| 290 | - $datetimes = $this->datetimes(array('limit' => 1, 'order_by' => array('DTT_EVT_start' => 'DESC'))); |
|
| 291 | - return end($datetimes); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * This returns the total tickets sold depending on the given parameters. |
|
| 297 | - * |
|
| 298 | - * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
| 299 | - * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
| 300 | - * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
| 301 | - * 'datetime' = total ticket sales in the datetime_ticket table. |
|
| 302 | - * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
| 303 | - * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
| 304 | - * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
| 305 | - * @return mixed (array|int) how many tickets have sold |
|
| 306 | - * @throws \EE_Error |
|
| 307 | - */ |
|
| 308 | - public function tickets_sold($what = 'ticket', $dtt_id = null) |
|
| 309 | - { |
|
| 310 | - $total = 0; |
|
| 311 | - $tickets_sold = $this->_all_tickets_sold(); |
|
| 312 | - switch ($what) { |
|
| 313 | - case 'ticket': |
|
| 314 | - return $tickets_sold['ticket']; |
|
| 315 | - break; |
|
| 316 | - case 'datetime': |
|
| 317 | - if (empty($tickets_sold['datetime'])) { |
|
| 318 | - return $total; |
|
| 319 | - } |
|
| 320 | - if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
| 321 | - EE_Error::add_error( |
|
| 322 | - __( |
|
| 323 | - 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
|
| 324 | - 'event_espresso' |
|
| 325 | - ), |
|
| 326 | - __FILE__, |
|
| 327 | - __FUNCTION__, |
|
| 328 | - __LINE__ |
|
| 329 | - ); |
|
| 330 | - return $total; |
|
| 331 | - } |
|
| 332 | - return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
| 333 | - break; |
|
| 334 | - default: |
|
| 335 | - return $total; |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
| 342 | - * |
|
| 343 | - * @return EE_Ticket[] |
|
| 344 | - * @throws \EE_Error |
|
| 345 | - */ |
|
| 346 | - protected function _all_tickets_sold() |
|
| 347 | - { |
|
| 348 | - $datetimes = $this->get_many_related('Datetime'); |
|
| 349 | - $tickets_sold = array(); |
|
| 350 | - if (! empty($datetimes)) { |
|
| 351 | - foreach ($datetimes as $datetime) { |
|
| 352 | - $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - // Tickets sold |
|
| 356 | - $tickets_sold['ticket'] = $this->sold(); |
|
| 357 | - return $tickets_sold; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * This returns the base price object for the ticket. |
|
| 363 | - * |
|
| 364 | - * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
| 365 | - * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
| 366 | - * @throws \EE_Error |
|
| 367 | - */ |
|
| 368 | - public function base_price($return_array = false) |
|
| 369 | - { |
|
| 370 | - $_where = array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price); |
|
| 371 | - return $return_array |
|
| 372 | - ? $this->get_many_related('Price', array($_where)) |
|
| 373 | - : $this->get_first_related('Price', array($_where)); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 379 | - * |
|
| 380 | - * @access public |
|
| 381 | - * @return EE_Price[] |
|
| 382 | - * @throws \EE_Error |
|
| 383 | - */ |
|
| 384 | - public function price_modifiers() |
|
| 385 | - { |
|
| 386 | - $query_params = array( |
|
| 387 | - 0 => array( |
|
| 388 | - 'Price_Type.PBT_ID' => array( |
|
| 389 | - 'NOT IN', |
|
| 390 | - array(EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax), |
|
| 391 | - ), |
|
| 392 | - ), |
|
| 393 | - ); |
|
| 394 | - return $this->prices($query_params); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Gets all the prices that combine to form the final price of this ticket |
|
| 400 | - * |
|
| 401 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 402 | - * @return EE_Price[]|EE_Base_Class[] |
|
| 403 | - * @throws \EE_Error |
|
| 404 | - */ |
|
| 405 | - public function prices($query_params = array()) |
|
| 406 | - { |
|
| 407 | - return $this->get_many_related('Price', $query_params); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
|
| 413 | - * |
|
| 414 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 415 | - * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
| 416 | - * @throws \EE_Error |
|
| 417 | - */ |
|
| 418 | - public function datetime_tickets($query_params = array()) |
|
| 419 | - { |
|
| 420 | - return $this->get_many_related('Datetime_Ticket', $query_params); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Gets all the datetimes from the db ordered by DTT_order |
|
| 426 | - * |
|
| 427 | - * @param boolean $show_expired |
|
| 428 | - * @param boolean $show_deleted |
|
| 429 | - * @return EE_Datetime[] |
|
| 430 | - * @throws \EE_Error |
|
| 431 | - */ |
|
| 432 | - public function datetimes_ordered($show_expired = true, $show_deleted = false) |
|
| 433 | - { |
|
| 434 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order( |
|
| 435 | - $this->ID(), |
|
| 436 | - $show_expired, |
|
| 437 | - $show_deleted |
|
| 438 | - ); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * Gets ID |
|
| 444 | - * |
|
| 445 | - * @return string |
|
| 446 | - * @throws \EE_Error |
|
| 447 | - */ |
|
| 448 | - public function ID() |
|
| 449 | - { |
|
| 450 | - return $this->get('TKT_ID'); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * get the author of the ticket. |
|
| 456 | - * |
|
| 457 | - * @since 4.5.0 |
|
| 458 | - * @return int |
|
| 459 | - * @throws \EE_Error |
|
| 460 | - */ |
|
| 461 | - public function wp_user() |
|
| 462 | - { |
|
| 463 | - return $this->get('TKT_wp_user'); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Gets the template for the ticket |
|
| 469 | - * |
|
| 470 | - * @return EE_Ticket_Template|EE_Base_Class |
|
| 471 | - * @throws \EE_Error |
|
| 472 | - */ |
|
| 473 | - public function template() |
|
| 474 | - { |
|
| 475 | - return $this->get_first_related('Ticket_Template'); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Simply returns an array of EE_Price objects that are taxes. |
|
| 481 | - * |
|
| 482 | - * @return EE_Price[] |
|
| 483 | - * @throws \EE_Error |
|
| 484 | - */ |
|
| 485 | - public function get_ticket_taxes_for_admin() |
|
| 486 | - { |
|
| 487 | - return EE_Taxes::get_taxes_for_admin(); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * @return float |
|
| 493 | - * @throws \EE_Error |
|
| 494 | - */ |
|
| 495 | - public function ticket_price() |
|
| 496 | - { |
|
| 497 | - return $this->get('TKT_price'); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * @return mixed |
|
| 503 | - * @throws \EE_Error |
|
| 504 | - */ |
|
| 505 | - public function pretty_price() |
|
| 506 | - { |
|
| 507 | - return $this->get_pretty('TKT_price'); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * @return bool |
|
| 513 | - * @throws \EE_Error |
|
| 514 | - */ |
|
| 515 | - public function is_free() |
|
| 516 | - { |
|
| 517 | - return $this->get_ticket_total_with_taxes() === (float) 0; |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * get_ticket_total_with_taxes |
|
| 523 | - * |
|
| 524 | - * @param bool $no_cache |
|
| 525 | - * @return float |
|
| 526 | - * @throws \EE_Error |
|
| 527 | - */ |
|
| 528 | - public function get_ticket_total_with_taxes($no_cache = false) |
|
| 529 | - { |
|
| 530 | - if ($this->_ticket_total_with_taxes === null || $no_cache) { |
|
| 531 | - $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
|
| 532 | - } |
|
| 533 | - return (float) $this->_ticket_total_with_taxes; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - public function ensure_TKT_Price_correct() |
|
| 538 | - { |
|
| 539 | - $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
| 540 | - $this->save(); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * @return float |
|
| 546 | - * @throws \EE_Error |
|
| 547 | - */ |
|
| 548 | - public function get_ticket_subtotal() |
|
| 549 | - { |
|
| 550 | - return EE_Taxes::get_subtotal_for_admin($this); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * Returns the total taxes applied to this ticket |
|
| 556 | - * |
|
| 557 | - * @return float |
|
| 558 | - * @throws \EE_Error |
|
| 559 | - */ |
|
| 560 | - public function get_ticket_taxes_total_for_admin() |
|
| 561 | - { |
|
| 562 | - return EE_Taxes::get_total_taxes_for_admin($this); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Sets name |
|
| 568 | - * |
|
| 569 | - * @param string $name |
|
| 570 | - * @throws \EE_Error |
|
| 571 | - */ |
|
| 572 | - public function set_name($name) |
|
| 573 | - { |
|
| 574 | - $this->set('TKT_name', $name); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * Gets description |
|
| 580 | - * |
|
| 581 | - * @return string |
|
| 582 | - * @throws \EE_Error |
|
| 583 | - */ |
|
| 584 | - public function description() |
|
| 585 | - { |
|
| 586 | - return $this->get('TKT_description'); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - |
|
| 590 | - /** |
|
| 591 | - * Sets description |
|
| 592 | - * |
|
| 593 | - * @param string $description |
|
| 594 | - * @throws \EE_Error |
|
| 595 | - */ |
|
| 596 | - public function set_description($description) |
|
| 597 | - { |
|
| 598 | - $this->set('TKT_description', $description); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * Gets start_date |
|
| 604 | - * |
|
| 605 | - * @param string $dt_frmt |
|
| 606 | - * @param string $tm_frmt |
|
| 607 | - * @return string |
|
| 608 | - * @throws \EE_Error |
|
| 609 | - */ |
|
| 610 | - public function start_date($dt_frmt = '', $tm_frmt = '') |
|
| 611 | - { |
|
| 612 | - return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt); |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * Sets start_date |
|
| 618 | - * |
|
| 619 | - * @param string $start_date |
|
| 620 | - * @return void |
|
| 621 | - * @throws \EE_Error |
|
| 622 | - */ |
|
| 623 | - public function set_start_date($start_date) |
|
| 624 | - { |
|
| 625 | - $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * Gets end_date |
|
| 631 | - * |
|
| 632 | - * @param string $dt_frmt |
|
| 633 | - * @param string $tm_frmt |
|
| 634 | - * @return string |
|
| 635 | - * @throws \EE_Error |
|
| 636 | - */ |
|
| 637 | - public function end_date($dt_frmt = '', $tm_frmt = '') |
|
| 638 | - { |
|
| 639 | - return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - /** |
|
| 644 | - * Sets end_date |
|
| 645 | - * |
|
| 646 | - * @param string $end_date |
|
| 647 | - * @return void |
|
| 648 | - * @throws \EE_Error |
|
| 649 | - */ |
|
| 650 | - public function set_end_date($end_date) |
|
| 651 | - { |
|
| 652 | - $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * Sets sell until time |
|
| 658 | - * |
|
| 659 | - * @since 4.5.0 |
|
| 660 | - * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
| 661 | - * @throws \EE_Error |
|
| 662 | - */ |
|
| 663 | - public function set_end_time($time) |
|
| 664 | - { |
|
| 665 | - $this->_set_time_for($time, 'TKT_end_date'); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - /** |
|
| 670 | - * Sets min |
|
| 671 | - * |
|
| 672 | - * @param int $min |
|
| 673 | - * @return void |
|
| 674 | - * @throws \EE_Error |
|
| 675 | - */ |
|
| 676 | - public function set_min($min) |
|
| 677 | - { |
|
| 678 | - $this->set('TKT_min', $min); |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * Gets max |
|
| 684 | - * |
|
| 685 | - * @return int |
|
| 686 | - * @throws \EE_Error |
|
| 687 | - */ |
|
| 688 | - public function max() |
|
| 689 | - { |
|
| 690 | - return $this->get('TKT_max'); |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * Sets max |
|
| 696 | - * |
|
| 697 | - * @param int $max |
|
| 698 | - * @return void |
|
| 699 | - * @throws \EE_Error |
|
| 700 | - */ |
|
| 701 | - public function set_max($max) |
|
| 702 | - { |
|
| 703 | - $this->set('TKT_max', $max); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * Sets price |
|
| 709 | - * |
|
| 710 | - * @param float $price |
|
| 711 | - * @return void |
|
| 712 | - * @throws \EE_Error |
|
| 713 | - */ |
|
| 714 | - public function set_price($price) |
|
| 715 | - { |
|
| 716 | - $this->set('TKT_price', $price); |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - |
|
| 720 | - /** |
|
| 721 | - * Gets sold |
|
| 722 | - * |
|
| 723 | - * @return int |
|
| 724 | - * @throws \EE_Error |
|
| 725 | - */ |
|
| 726 | - public function sold() |
|
| 727 | - { |
|
| 728 | - return $this->get_raw('TKT_sold'); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - |
|
| 732 | - /** |
|
| 733 | - * Sets sold |
|
| 734 | - * |
|
| 735 | - * @param int $sold |
|
| 736 | - * @return void |
|
| 737 | - * @throws \EE_Error |
|
| 738 | - */ |
|
| 739 | - public function set_sold($sold) |
|
| 740 | - { |
|
| 741 | - // sold can not go below zero |
|
| 742 | - $sold = max(0, $sold); |
|
| 743 | - $this->set('TKT_sold', $sold); |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * increments sold by amount passed by $qty |
|
| 749 | - * |
|
| 750 | - * @param int $qty |
|
| 751 | - * @return void |
|
| 752 | - * @throws \EE_Error |
|
| 753 | - */ |
|
| 754 | - public function increase_sold($qty = 1) |
|
| 755 | - { |
|
| 756 | - $sold = $this->sold() + $qty; |
|
| 757 | - // remove ticket reservation, but don't adjust datetime reservations, because that will happen |
|
| 758 | - // via \EE_Datetime::increase_sold() when \EE_Ticket::_increase_sold_for_datetimes() is called |
|
| 759 | - $this->decrease_reserved($qty, false, "TKT: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 760 | - $this->_increase_sold_for_datetimes($qty); |
|
| 761 | - $this->set_sold($sold); |
|
| 762 | - do_action( |
|
| 763 | - 'AHEE__EE_Ticket__increase_sold', |
|
| 764 | - $this, |
|
| 765 | - $qty, |
|
| 766 | - $sold |
|
| 767 | - ); |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - |
|
| 771 | - /** |
|
| 772 | - * Increases sold on related datetimes |
|
| 773 | - * |
|
| 774 | - * @param int $qty |
|
| 775 | - * @return void |
|
| 776 | - * @throws \EE_Error |
|
| 777 | - */ |
|
| 778 | - protected function _increase_sold_for_datetimes($qty = 1) |
|
| 779 | - { |
|
| 780 | - $datetimes = $this->datetimes(); |
|
| 781 | - if (is_array($datetimes)) { |
|
| 782 | - foreach ($datetimes as $datetime) { |
|
| 783 | - if ($datetime instanceof EE_Datetime) { |
|
| 784 | - $datetime->increase_sold($qty); |
|
| 785 | - $datetime->save(); |
|
| 786 | - } |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - |
|
| 792 | - /** |
|
| 793 | - * decrements (subtracts) sold by amount passed by $qty |
|
| 794 | - * |
|
| 795 | - * @param int $qty |
|
| 796 | - * @return void |
|
| 797 | - * @throws \EE_Error |
|
| 798 | - */ |
|
| 799 | - public function decrease_sold($qty = 1) |
|
| 800 | - { |
|
| 801 | - $sold = $this->sold() - $qty; |
|
| 802 | - $this->_decrease_sold_for_datetimes($qty); |
|
| 803 | - $this->set_sold($sold); |
|
| 804 | - do_action( |
|
| 805 | - 'AHEE__EE_Ticket__decrease_sold', |
|
| 806 | - $this, |
|
| 807 | - $qty, |
|
| 808 | - $sold |
|
| 809 | - ); |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - |
|
| 813 | - /** |
|
| 814 | - * Decreases sold on related datetimes |
|
| 815 | - * |
|
| 816 | - * @param int $qty |
|
| 817 | - * @return void |
|
| 818 | - * @throws \EE_Error |
|
| 819 | - */ |
|
| 820 | - protected function _decrease_sold_for_datetimes($qty = 1) |
|
| 821 | - { |
|
| 822 | - $datetimes = $this->datetimes(); |
|
| 823 | - if (is_array($datetimes)) { |
|
| 824 | - foreach ($datetimes as $datetime) { |
|
| 825 | - if ($datetime instanceof EE_Datetime) { |
|
| 826 | - $datetime->decrease_sold($qty); |
|
| 827 | - $datetime->save(); |
|
| 828 | - } |
|
| 829 | - } |
|
| 830 | - } |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - |
|
| 834 | - /** |
|
| 835 | - * Gets qty of reserved tickets |
|
| 836 | - * |
|
| 837 | - * @return int |
|
| 838 | - * @throws \EE_Error |
|
| 839 | - */ |
|
| 840 | - public function reserved() |
|
| 841 | - { |
|
| 842 | - return $this->get_raw('TKT_reserved'); |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - |
|
| 846 | - /** |
|
| 847 | - * Sets reserved |
|
| 848 | - * |
|
| 849 | - * @param int $reserved |
|
| 850 | - * @return void |
|
| 851 | - * @throws \EE_Error |
|
| 852 | - */ |
|
| 853 | - public function set_reserved($reserved) |
|
| 854 | - { |
|
| 855 | - // reserved can not go below zero |
|
| 856 | - $reserved = max(0, (int) $reserved); |
|
| 857 | - $this->set('TKT_reserved', $reserved); |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - |
|
| 861 | - /** |
|
| 862 | - * increments reserved by amount passed by $qty |
|
| 863 | - * |
|
| 864 | - * @param int $qty |
|
| 865 | - * @param string $source |
|
| 866 | - * @return void |
|
| 867 | - * @throws EE_Error |
|
| 868 | - * @throws InvalidArgumentException |
|
| 869 | - * @throws ReflectionException |
|
| 870 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 871 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 872 | - */ |
|
| 873 | - public function increase_reserved($qty = 1, $source = 'unknown') |
|
| 874 | - { |
|
| 875 | - $qty = absint($qty); |
|
| 876 | - $reserved = $this->reserved() + $qty; |
|
| 877 | - if ($reserved |
|
| 878 | - && $this->add_extra_meta( |
|
| 879 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 880 | - "{$qty} from {$source}" |
|
| 881 | - ) |
|
| 882 | - ) { |
|
| 883 | - $this->_increase_reserved_for_datetimes($qty); |
|
| 884 | - $this->set_reserved($reserved); |
|
| 885 | - do_action( |
|
| 886 | - 'AHEE__EE_Ticket__increase_reserved', |
|
| 887 | - $this, |
|
| 888 | - $qty, |
|
| 889 | - $reserved |
|
| 890 | - ); |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - /** |
|
| 896 | - * Increases sold on related datetimes |
|
| 897 | - * |
|
| 898 | - * @param int $qty |
|
| 899 | - * @return void |
|
| 900 | - * @throws \EE_Error |
|
| 901 | - */ |
|
| 902 | - protected function _increase_reserved_for_datetimes($qty = 1) |
|
| 903 | - { |
|
| 904 | - $datetimes = $this->datetimes(); |
|
| 905 | - if (is_array($datetimes)) { |
|
| 906 | - foreach ($datetimes as $datetime) { |
|
| 907 | - if ($datetime instanceof EE_Datetime) { |
|
| 908 | - $datetime->increase_reserved($qty); |
|
| 909 | - $datetime->save(); |
|
| 910 | - } |
|
| 911 | - } |
|
| 912 | - } |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - |
|
| 916 | - /** |
|
| 917 | - * decrements (subtracts) reserved by amount passed by $qty |
|
| 918 | - * |
|
| 919 | - * @param int $qty |
|
| 920 | - * @param bool $adjust_datetimes |
|
| 921 | - * @param string $source |
|
| 922 | - * @return void |
|
| 923 | - * @throws EE_Error |
|
| 924 | - * @throws InvalidArgumentException |
|
| 925 | - * @throws ReflectionException |
|
| 926 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 927 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 928 | - */ |
|
| 929 | - public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
| 930 | - { |
|
| 931 | - $reserved = $this->reserved() - absint($qty); |
|
| 932 | - if ($this->add_extra_meta( |
|
| 933 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 934 | - "-{$qty} from {$source}" |
|
| 935 | - )) { |
|
| 936 | - if ($adjust_datetimes) { |
|
| 937 | - $this->_decrease_reserved_for_datetimes($qty); |
|
| 938 | - } |
|
| 939 | - $this->set_reserved($reserved); |
|
| 940 | - do_action( |
|
| 941 | - 'AHEE__EE_Ticket__decrease_reserved', |
|
| 942 | - $this, |
|
| 943 | - $qty, |
|
| 944 | - $reserved |
|
| 945 | - ); |
|
| 946 | - } |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - |
|
| 950 | - /** |
|
| 951 | - * Increases sold on related datetimes |
|
| 952 | - * |
|
| 953 | - * @param int $qty |
|
| 954 | - * @return void |
|
| 955 | - * @throws \EE_Error |
|
| 956 | - */ |
|
| 957 | - protected function _decrease_reserved_for_datetimes($qty = 1) |
|
| 958 | - { |
|
| 959 | - $datetimes = $this->datetimes(); |
|
| 960 | - if (is_array($datetimes)) { |
|
| 961 | - foreach ($datetimes as $datetime) { |
|
| 962 | - if ($datetime instanceof EE_Datetime) { |
|
| 963 | - $datetime->decrease_reserved($qty); |
|
| 964 | - $datetime->save(); |
|
| 965 | - } |
|
| 966 | - } |
|
| 967 | - } |
|
| 968 | - } |
|
| 969 | - |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * Gets ticket quantity |
|
| 973 | - * |
|
| 974 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 975 | - * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
| 976 | - * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
| 977 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 978 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 979 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 980 | - * @return int |
|
| 981 | - * @throws \EE_Error |
|
| 982 | - */ |
|
| 983 | - public function qty($context = '') |
|
| 984 | - { |
|
| 985 | - switch ($context) { |
|
| 986 | - case 'reg_limit': |
|
| 987 | - return $this->real_quantity_on_ticket(); |
|
| 988 | - case 'saleable': |
|
| 989 | - return $this->real_quantity_on_ticket('saleable'); |
|
| 990 | - default: |
|
| 991 | - return $this->get_raw('TKT_qty'); |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - |
|
| 996 | - /** |
|
| 997 | - * Gets ticket quantity |
|
| 998 | - * |
|
| 999 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1000 | - * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
| 1001 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1002 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1003 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1004 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
| 1005 | - * set to 0 for all related datetimes |
|
| 1006 | - * @return int |
|
| 1007 | - * @throws \EE_Error |
|
| 1008 | - */ |
|
| 1009 | - public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) |
|
| 1010 | - { |
|
| 1011 | - $raw = $this->get_raw('TKT_qty'); |
|
| 1012 | - // return immediately if it's zero |
|
| 1013 | - if ($raw === 0) { |
|
| 1014 | - return $raw; |
|
| 1015 | - } |
|
| 1016 | - // echo "\n\n<br />Ticket: " . $this->name() . '<br />'; |
|
| 1017 | - // ensure qty doesn't exceed raw value for THIS ticket |
|
| 1018 | - $qty = min(EE_INF, $raw); |
|
| 1019 | - // echo "\n . qty: " . $qty . '<br />'; |
|
| 1020 | - // calculate this ticket's total sales and reservations |
|
| 1021 | - $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved(); |
|
| 1022 | - // echo "\n . sold: " . $this->sold() . '<br />'; |
|
| 1023 | - // echo "\n . reserved: " . $this->reserved() . '<br />'; |
|
| 1024 | - // echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />'; |
|
| 1025 | - // first we need to calculate the maximum number of tickets available for the datetime |
|
| 1026 | - // do we want data for one datetime or all of them ? |
|
| 1027 | - $query_params = $DTT_ID ? array(array('DTT_ID' => $DTT_ID)) : array(); |
|
| 1028 | - $datetimes = $this->datetimes($query_params); |
|
| 1029 | - if (is_array($datetimes) && ! empty($datetimes)) { |
|
| 1030 | - foreach ($datetimes as $datetime) { |
|
| 1031 | - if ($datetime instanceof EE_Datetime) { |
|
| 1032 | - $datetime->refresh_from_db(); |
|
| 1033 | - // echo "\n . . datetime name: " . $datetime->name() . '<br />'; |
|
| 1034 | - // echo "\n . . datetime ID: " . $datetime->ID() . '<br />'; |
|
| 1035 | - // initialize with no restrictions for each datetime |
|
| 1036 | - // but adjust datetime qty based on datetime reg limit |
|
| 1037 | - $datetime_qty = min(EE_INF, $datetime->reg_limit()); |
|
| 1038 | - // echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />'; |
|
| 1039 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1040 | - // if we want the actual saleable amount, then we need to consider OTHER ticket sales |
|
| 1041 | - // and reservations for this datetime, that do NOT include sales and reservations |
|
| 1042 | - // for this ticket (so we add $this->sold() and $this->reserved() back in) |
|
| 1043 | - if ($context === 'saleable') { |
|
| 1044 | - $datetime_qty = max( |
|
| 1045 | - $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket, |
|
| 1046 | - 0 |
|
| 1047 | - ); |
|
| 1048 | - // echo "\n . . . datetime sold: " . $datetime->sold() . '<br />'; |
|
| 1049 | - // echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />'; |
|
| 1050 | - // echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />'; |
|
| 1051 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1052 | - $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0; |
|
| 1053 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1054 | - } |
|
| 1055 | - $qty = min($datetime_qty, $qty); |
|
| 1056 | - // echo "\n . . qty: " . $qty . '<br />'; |
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1059 | - } |
|
| 1060 | - // NOW that we know the maximum number of tickets available for the datetime |
|
| 1061 | - // we can finally factor in the details for this specific ticket |
|
| 1062 | - if ($qty > 0 && $context === 'saleable') { |
|
| 1063 | - // and subtract the sales for THIS ticket |
|
| 1064 | - $qty = max($qty - $sold_and_reserved_for_this_ticket, 0); |
|
| 1065 | - // echo "\n . qty: " . $qty . '<br />'; |
|
| 1066 | - } |
|
| 1067 | - // echo "\nFINAL QTY: " . $qty . "<br /><br />"; |
|
| 1068 | - return $qty; |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - |
|
| 1072 | - /** |
|
| 1073 | - * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes |
|
| 1074 | - * |
|
| 1075 | - * @param int $qty |
|
| 1076 | - * @return void |
|
| 1077 | - * @throws \EE_Error |
|
| 1078 | - */ |
|
| 1079 | - public function set_qty($qty) |
|
| 1080 | - { |
|
| 1081 | - $datetimes = $this->datetimes(); |
|
| 1082 | - foreach ($datetimes as $datetime) { |
|
| 1083 | - if ($datetime instanceof EE_Datetime) { |
|
| 1084 | - $qty = min($qty, $datetime->reg_limit()); |
|
| 1085 | - } |
|
| 1086 | - } |
|
| 1087 | - $this->set('TKT_qty', $qty); |
|
| 1088 | - } |
|
| 1089 | - |
|
| 1090 | - |
|
| 1091 | - /** |
|
| 1092 | - * Gets uses |
|
| 1093 | - * |
|
| 1094 | - * @return int |
|
| 1095 | - * @throws \EE_Error |
|
| 1096 | - */ |
|
| 1097 | - public function uses() |
|
| 1098 | - { |
|
| 1099 | - return $this->get('TKT_uses'); |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - |
|
| 1103 | - /** |
|
| 1104 | - * Sets uses |
|
| 1105 | - * |
|
| 1106 | - * @param int $uses |
|
| 1107 | - * @return void |
|
| 1108 | - * @throws \EE_Error |
|
| 1109 | - */ |
|
| 1110 | - public function set_uses($uses) |
|
| 1111 | - { |
|
| 1112 | - $this->set('TKT_uses', $uses); |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - |
|
| 1116 | - /** |
|
| 1117 | - * returns whether ticket is required or not. |
|
| 1118 | - * |
|
| 1119 | - * @return boolean |
|
| 1120 | - * @throws \EE_Error |
|
| 1121 | - */ |
|
| 1122 | - public function required() |
|
| 1123 | - { |
|
| 1124 | - return $this->get('TKT_required'); |
|
| 1125 | - } |
|
| 1126 | - |
|
| 1127 | - |
|
| 1128 | - /** |
|
| 1129 | - * sets the TKT_required property |
|
| 1130 | - * |
|
| 1131 | - * @param boolean $required |
|
| 1132 | - * @return void |
|
| 1133 | - * @throws \EE_Error |
|
| 1134 | - */ |
|
| 1135 | - public function set_required($required) |
|
| 1136 | - { |
|
| 1137 | - $this->set('TKT_required', $required); |
|
| 1138 | - } |
|
| 1139 | - |
|
| 1140 | - |
|
| 1141 | - /** |
|
| 1142 | - * Gets taxable |
|
| 1143 | - * |
|
| 1144 | - * @return boolean |
|
| 1145 | - * @throws \EE_Error |
|
| 1146 | - */ |
|
| 1147 | - public function taxable() |
|
| 1148 | - { |
|
| 1149 | - return $this->get('TKT_taxable'); |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - |
|
| 1153 | - /** |
|
| 1154 | - * Sets taxable |
|
| 1155 | - * |
|
| 1156 | - * @param boolean $taxable |
|
| 1157 | - * @return void |
|
| 1158 | - * @throws \EE_Error |
|
| 1159 | - */ |
|
| 1160 | - public function set_taxable($taxable) |
|
| 1161 | - { |
|
| 1162 | - $this->set('TKT_taxable', $taxable); |
|
| 1163 | - } |
|
| 1164 | - |
|
| 1165 | - |
|
| 1166 | - /** |
|
| 1167 | - * Gets is_default |
|
| 1168 | - * |
|
| 1169 | - * @return boolean |
|
| 1170 | - * @throws \EE_Error |
|
| 1171 | - */ |
|
| 1172 | - public function is_default() |
|
| 1173 | - { |
|
| 1174 | - return $this->get('TKT_is_default'); |
|
| 1175 | - } |
|
| 1176 | - |
|
| 1177 | - |
|
| 1178 | - /** |
|
| 1179 | - * Sets is_default |
|
| 1180 | - * |
|
| 1181 | - * @param boolean $is_default |
|
| 1182 | - * @return void |
|
| 1183 | - * @throws \EE_Error |
|
| 1184 | - */ |
|
| 1185 | - public function set_is_default($is_default) |
|
| 1186 | - { |
|
| 1187 | - $this->set('TKT_is_default', $is_default); |
|
| 1188 | - } |
|
| 1189 | - |
|
| 1190 | - |
|
| 1191 | - /** |
|
| 1192 | - * Gets order |
|
| 1193 | - * |
|
| 1194 | - * @return int |
|
| 1195 | - * @throws \EE_Error |
|
| 1196 | - */ |
|
| 1197 | - public function order() |
|
| 1198 | - { |
|
| 1199 | - return $this->get('TKT_order'); |
|
| 1200 | - } |
|
| 1201 | - |
|
| 1202 | - |
|
| 1203 | - /** |
|
| 1204 | - * Sets order |
|
| 1205 | - * |
|
| 1206 | - * @param int $order |
|
| 1207 | - * @return void |
|
| 1208 | - * @throws \EE_Error |
|
| 1209 | - */ |
|
| 1210 | - public function set_order($order) |
|
| 1211 | - { |
|
| 1212 | - $this->set('TKT_order', $order); |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - |
|
| 1216 | - /** |
|
| 1217 | - * Gets row |
|
| 1218 | - * |
|
| 1219 | - * @return int |
|
| 1220 | - * @throws \EE_Error |
|
| 1221 | - */ |
|
| 1222 | - public function row() |
|
| 1223 | - { |
|
| 1224 | - return $this->get('TKT_row'); |
|
| 1225 | - } |
|
| 1226 | - |
|
| 1227 | - |
|
| 1228 | - /** |
|
| 1229 | - * Sets row |
|
| 1230 | - * |
|
| 1231 | - * @param int $row |
|
| 1232 | - * @return void |
|
| 1233 | - * @throws \EE_Error |
|
| 1234 | - */ |
|
| 1235 | - public function set_row($row) |
|
| 1236 | - { |
|
| 1237 | - $this->set('TKT_row', $row); |
|
| 1238 | - } |
|
| 1239 | - |
|
| 1240 | - |
|
| 1241 | - /** |
|
| 1242 | - * Gets deleted |
|
| 1243 | - * |
|
| 1244 | - * @return boolean |
|
| 1245 | - * @throws \EE_Error |
|
| 1246 | - */ |
|
| 1247 | - public function deleted() |
|
| 1248 | - { |
|
| 1249 | - return $this->get('TKT_deleted'); |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - |
|
| 1253 | - /** |
|
| 1254 | - * Sets deleted |
|
| 1255 | - * |
|
| 1256 | - * @param boolean $deleted |
|
| 1257 | - * @return void |
|
| 1258 | - * @throws \EE_Error |
|
| 1259 | - */ |
|
| 1260 | - public function set_deleted($deleted) |
|
| 1261 | - { |
|
| 1262 | - $this->set('TKT_deleted', $deleted); |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - |
|
| 1266 | - /** |
|
| 1267 | - * Gets parent |
|
| 1268 | - * |
|
| 1269 | - * @return int |
|
| 1270 | - * @throws \EE_Error |
|
| 1271 | - */ |
|
| 1272 | - public function parent_ID() |
|
| 1273 | - { |
|
| 1274 | - return $this->get('TKT_parent'); |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - |
|
| 1278 | - /** |
|
| 1279 | - * Sets parent |
|
| 1280 | - * |
|
| 1281 | - * @param int $parent |
|
| 1282 | - * @return void |
|
| 1283 | - * @throws \EE_Error |
|
| 1284 | - */ |
|
| 1285 | - public function set_parent_ID($parent) |
|
| 1286 | - { |
|
| 1287 | - $this->set('TKT_parent', $parent); |
|
| 1288 | - } |
|
| 1289 | - |
|
| 1290 | - |
|
| 1291 | - /** |
|
| 1292 | - * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
| 1293 | - * |
|
| 1294 | - * @return string |
|
| 1295 | - * @throws \EE_Error |
|
| 1296 | - */ |
|
| 1297 | - public function name_and_info() |
|
| 1298 | - { |
|
| 1299 | - $times = array(); |
|
| 1300 | - foreach ($this->datetimes() as $datetime) { |
|
| 1301 | - $times[] = $datetime->start_date_and_time(); |
|
| 1302 | - } |
|
| 1303 | - return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
| 1304 | - } |
|
| 1305 | - |
|
| 1306 | - |
|
| 1307 | - /** |
|
| 1308 | - * Gets name |
|
| 1309 | - * |
|
| 1310 | - * @return string |
|
| 1311 | - * @throws \EE_Error |
|
| 1312 | - */ |
|
| 1313 | - public function name() |
|
| 1314 | - { |
|
| 1315 | - return $this->get('TKT_name'); |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - |
|
| 1319 | - /** |
|
| 1320 | - * Gets price |
|
| 1321 | - * |
|
| 1322 | - * @return float |
|
| 1323 | - * @throws \EE_Error |
|
| 1324 | - */ |
|
| 1325 | - public function price() |
|
| 1326 | - { |
|
| 1327 | - return $this->get('TKT_price'); |
|
| 1328 | - } |
|
| 1329 | - |
|
| 1330 | - |
|
| 1331 | - /** |
|
| 1332 | - * Gets all the registrations for this ticket |
|
| 1333 | - * |
|
| 1334 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1335 | - * @return EE_Registration[]|EE_Base_Class[] |
|
| 1336 | - * @throws \EE_Error |
|
| 1337 | - */ |
|
| 1338 | - public function registrations($query_params = array()) |
|
| 1339 | - { |
|
| 1340 | - return $this->get_many_related('Registration', $query_params); |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - |
|
| 1344 | - /** |
|
| 1345 | - * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
| 1346 | - * into account |
|
| 1347 | - * |
|
| 1348 | - * @return int |
|
| 1349 | - * @throws \EE_Error |
|
| 1350 | - */ |
|
| 1351 | - public function update_tickets_sold() |
|
| 1352 | - { |
|
| 1353 | - $count_regs_for_this_ticket = $this->count_registrations( |
|
| 1354 | - array( |
|
| 1355 | - array( |
|
| 1356 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1357 | - 'REG_deleted' => 0, |
|
| 1358 | - ), |
|
| 1359 | - ) |
|
| 1360 | - ); |
|
| 1361 | - $sold = $this->sold(); |
|
| 1362 | - if ($count_regs_for_this_ticket > $sold) { |
|
| 1363 | - $this->increase_sold($count_regs_for_this_ticket - $sold); |
|
| 1364 | - $this->save(); |
|
| 1365 | - } elseif ($count_regs_for_this_ticket < $sold) { |
|
| 1366 | - $this->decrease_sold($count_regs_for_this_ticket - $sold); |
|
| 1367 | - $this->save(); |
|
| 1368 | - } |
|
| 1369 | - return $count_regs_for_this_ticket; |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - |
|
| 1373 | - /** |
|
| 1374 | - * Counts the registrations for this ticket |
|
| 1375 | - * |
|
| 1376 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1377 | - * @return int |
|
| 1378 | - */ |
|
| 1379 | - public function count_registrations($query_params = array()) |
|
| 1380 | - { |
|
| 1381 | - return $this->count_related('Registration', $query_params); |
|
| 1382 | - } |
|
| 1383 | - |
|
| 1384 | - |
|
| 1385 | - /** |
|
| 1386 | - * Implementation for EEI_Has_Icon interface method. |
|
| 1387 | - * |
|
| 1388 | - * @see EEI_Visual_Representation for comments |
|
| 1389 | - * @return string |
|
| 1390 | - */ |
|
| 1391 | - public function get_icon() |
|
| 1392 | - { |
|
| 1393 | - return '<span class="dashicons dashicons-tickets-alt"></span>'; |
|
| 1394 | - } |
|
| 1395 | - |
|
| 1396 | - |
|
| 1397 | - /** |
|
| 1398 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1399 | - * |
|
| 1400 | - * @see EEI_Event_Relation for comments |
|
| 1401 | - * @return EE_Event |
|
| 1402 | - * @throws \EE_Error |
|
| 1403 | - * @throws UnexpectedEntityException |
|
| 1404 | - */ |
|
| 1405 | - public function get_related_event() |
|
| 1406 | - { |
|
| 1407 | - // get one datetime to use for getting the event |
|
| 1408 | - $datetime = $this->first_datetime(); |
|
| 1409 | - if (! $datetime instanceof \EE_Datetime) { |
|
| 1410 | - throw new UnexpectedEntityException( |
|
| 1411 | - $datetime, |
|
| 1412 | - 'EE_Datetime', |
|
| 1413 | - sprintf( |
|
| 1414 | - __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
| 1415 | - $this->name() |
|
| 1416 | - ) |
|
| 1417 | - ); |
|
| 1418 | - } |
|
| 1419 | - $event = $datetime->event(); |
|
| 1420 | - if (! $event instanceof \EE_Event) { |
|
| 1421 | - throw new UnexpectedEntityException( |
|
| 1422 | - $event, |
|
| 1423 | - 'EE_Event', |
|
| 1424 | - sprintf( |
|
| 1425 | - __('The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
| 1426 | - $this->name() |
|
| 1427 | - ) |
|
| 1428 | - ); |
|
| 1429 | - } |
|
| 1430 | - return $event; |
|
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - |
|
| 1434 | - /** |
|
| 1435 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1436 | - * |
|
| 1437 | - * @see EEI_Event_Relation for comments |
|
| 1438 | - * @return string |
|
| 1439 | - * @throws UnexpectedEntityException |
|
| 1440 | - * @throws \EE_Error |
|
| 1441 | - */ |
|
| 1442 | - public function get_event_name() |
|
| 1443 | - { |
|
| 1444 | - $event = $this->get_related_event(); |
|
| 1445 | - return $event instanceof EE_Event ? $event->name() : ''; |
|
| 1446 | - } |
|
| 1447 | - |
|
| 1448 | - |
|
| 1449 | - /** |
|
| 1450 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1451 | - * |
|
| 1452 | - * @see EEI_Event_Relation for comments |
|
| 1453 | - * @return int |
|
| 1454 | - * @throws UnexpectedEntityException |
|
| 1455 | - * @throws \EE_Error |
|
| 1456 | - */ |
|
| 1457 | - public function get_event_ID() |
|
| 1458 | - { |
|
| 1459 | - $event = $this->get_related_event(); |
|
| 1460 | - return $event instanceof EE_Event ? $event->ID() : 0; |
|
| 1461 | - } |
|
| 1462 | - |
|
| 1463 | - |
|
| 1464 | - /** |
|
| 1465 | - * This simply returns whether a ticket can be permanently deleted or not. |
|
| 1466 | - * The criteria for determining this is whether the ticket has any related registrations. |
|
| 1467 | - * If there are none then it can be permanently deleted. |
|
| 1468 | - * |
|
| 1469 | - * @return bool |
|
| 1470 | - */ |
|
| 1471 | - public function is_permanently_deleteable() |
|
| 1472 | - { |
|
| 1473 | - return $this->count_registrations() === 0; |
|
| 1474 | - } |
|
| 15 | + /** |
|
| 16 | + * The following constants are used by the ticket_status() method to indicate whether a ticket is on sale or not. |
|
| 17 | + */ |
|
| 18 | + const sold_out = 'TKS'; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * |
|
| 22 | + */ |
|
| 23 | + const expired = 'TKE'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * |
|
| 27 | + */ |
|
| 28 | + const archived = 'TKA'; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * |
|
| 32 | + */ |
|
| 33 | + const pending = 'TKP'; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * |
|
| 37 | + */ |
|
| 38 | + const onsale = 'TKO'; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * extra meta key for tracking ticket reservations |
|
| 42 | + * |
|
| 43 | + * @type string |
|
| 44 | + */ |
|
| 45 | + const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * cached result from method of the same name |
|
| 49 | + * |
|
| 50 | + * @var float $_ticket_total_with_taxes |
|
| 51 | + */ |
|
| 52 | + private $_ticket_total_with_taxes; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param array $props_n_values incoming values |
|
| 57 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 58 | + * used.) |
|
| 59 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 60 | + * date_format and the second value is the time format |
|
| 61 | + * @return EE_Ticket |
|
| 62 | + * @throws \EE_Error |
|
| 63 | + */ |
|
| 64 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 65 | + { |
|
| 66 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 67 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @param array $props_n_values incoming values from the database |
|
| 73 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 74 | + * the website will be used. |
|
| 75 | + * @return EE_Ticket |
|
| 76 | + * @throws \EE_Error |
|
| 77 | + */ |
|
| 78 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 79 | + { |
|
| 80 | + return new self($props_n_values, true, $timezone); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @return bool |
|
| 86 | + * @throws \EE_Error |
|
| 87 | + */ |
|
| 88 | + public function parent() |
|
| 89 | + { |
|
| 90 | + return $this->get('TKT_parent'); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * return if a ticket has quantities available for purchase |
|
| 96 | + * |
|
| 97 | + * @param int $DTT_ID the primary key for a particular datetime |
|
| 98 | + * @return boolean |
|
| 99 | + * @throws \EE_Error |
|
| 100 | + */ |
|
| 101 | + public function available($DTT_ID = 0) |
|
| 102 | + { |
|
| 103 | + // are we checking availability for a particular datetime ? |
|
| 104 | + if ($DTT_ID) { |
|
| 105 | + // get that datetime object |
|
| 106 | + $datetime = $this->get_first_related('Datetime', array(array('DTT_ID' => $DTT_ID))); |
|
| 107 | + // if ticket sales for this datetime have exceeded the reg limit... |
|
| 108 | + if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
| 109 | + return false; |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + // datetime is still open for registration, but is this ticket sold out ? |
|
| 113 | + return $this->qty() < 1 || $this->qty() > $this->sold() ? true : false; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
| 119 | + * |
|
| 120 | + * @param bool $display true = we'll return a localized string, otherwise we just return the value of the |
|
| 121 | + * relevant status const |
|
| 122 | + * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
|
| 123 | + * further processing |
|
| 124 | + * @return mixed status int if the display string isn't requested |
|
| 125 | + * @throws \EE_Error |
|
| 126 | + */ |
|
| 127 | + public function ticket_status($display = false, $remaining = null) |
|
| 128 | + { |
|
| 129 | + $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
|
| 130 | + if (! $remaining) { |
|
| 131 | + return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
|
| 132 | + } |
|
| 133 | + if ($this->get('TKT_deleted')) { |
|
| 134 | + return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived; |
|
| 135 | + } |
|
| 136 | + if ($this->is_expired()) { |
|
| 137 | + return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired; |
|
| 138 | + } |
|
| 139 | + if ($this->is_pending()) { |
|
| 140 | + return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending; |
|
| 141 | + } |
|
| 142 | + if ($this->is_on_sale()) { |
|
| 143 | + return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale; |
|
| 144 | + } |
|
| 145 | + return ''; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale |
|
| 151 | + * considering ALL the factors used for figuring that out. |
|
| 152 | + * |
|
| 153 | + * @access public |
|
| 154 | + * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
| 155 | + * @return boolean true = tickets remaining, false not. |
|
| 156 | + * @throws \EE_Error |
|
| 157 | + */ |
|
| 158 | + public function is_remaining($DTT_ID = 0) |
|
| 159 | + { |
|
| 160 | + $num_remaining = $this->remaining($DTT_ID); |
|
| 161 | + if ($num_remaining === 0) { |
|
| 162 | + return false; |
|
| 163 | + } |
|
| 164 | + if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
| 165 | + return false; |
|
| 166 | + } |
|
| 167 | + return true; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * return the total number of tickets available for purchase |
|
| 173 | + * |
|
| 174 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
| 175 | + * set to 0 for all related datetimes |
|
| 176 | + * @return int |
|
| 177 | + * @throws \EE_Error |
|
| 178 | + */ |
|
| 179 | + public function remaining($DTT_ID = 0) |
|
| 180 | + { |
|
| 181 | + return $this->real_quantity_on_ticket('saleable', $DTT_ID); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Gets min |
|
| 187 | + * |
|
| 188 | + * @return int |
|
| 189 | + * @throws \EE_Error |
|
| 190 | + */ |
|
| 191 | + public function min() |
|
| 192 | + { |
|
| 193 | + return $this->get('TKT_min'); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * return if a ticket is no longer available cause its available dates have expired. |
|
| 199 | + * |
|
| 200 | + * @return boolean |
|
| 201 | + * @throws \EE_Error |
|
| 202 | + */ |
|
| 203 | + public function is_expired() |
|
| 204 | + { |
|
| 205 | + return ($this->get_raw('TKT_end_date') < time()); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Return if a ticket is yet to go on sale or not |
|
| 211 | + * |
|
| 212 | + * @return boolean |
|
| 213 | + * @throws \EE_Error |
|
| 214 | + */ |
|
| 215 | + public function is_pending() |
|
| 216 | + { |
|
| 217 | + return ($this->get_raw('TKT_start_date') > time()); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Return if a ticket is on sale or not |
|
| 223 | + * |
|
| 224 | + * @return boolean |
|
| 225 | + * @throws \EE_Error |
|
| 226 | + */ |
|
| 227 | + public function is_on_sale() |
|
| 228 | + { |
|
| 229 | + return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time()); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * This returns the chronologically last datetime that this ticket is associated with |
|
| 235 | + * |
|
| 236 | + * @param string $dt_frmt |
|
| 237 | + * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
|
| 238 | + * the end date ie: Jan 01 "to" Dec 31 |
|
| 239 | + * @return string |
|
| 240 | + * @throws \EE_Error |
|
| 241 | + */ |
|
| 242 | + public function date_range($dt_frmt = '', $conjunction = ' - ') |
|
| 243 | + { |
|
| 244 | + $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date($dt_frmt) |
|
| 245 | + : ''; |
|
| 246 | + $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date($dt_frmt) : ''; |
|
| 247 | + |
|
| 248 | + return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * This returns the chronologically first datetime that this ticket is associated with |
|
| 254 | + * |
|
| 255 | + * @return EE_Datetime |
|
| 256 | + * @throws \EE_Error |
|
| 257 | + */ |
|
| 258 | + public function first_datetime() |
|
| 259 | + { |
|
| 260 | + $datetimes = $this->datetimes(array('limit' => 1)); |
|
| 261 | + return reset($datetimes); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Gets all the datetimes this ticket can be used for attending. |
|
| 267 | + * Unless otherwise specified, orders datetimes by start date. |
|
| 268 | + * |
|
| 269 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 270 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
| 271 | + * @throws \EE_Error |
|
| 272 | + */ |
|
| 273 | + public function datetimes($query_params = array()) |
|
| 274 | + { |
|
| 275 | + if (! isset($query_params['order_by'])) { |
|
| 276 | + $query_params['order_by']['DTT_order'] = 'ASC'; |
|
| 277 | + } |
|
| 278 | + return $this->get_many_related('Datetime', $query_params); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * This returns the chronologically last datetime that this ticket is associated with |
|
| 284 | + * |
|
| 285 | + * @return EE_Datetime |
|
| 286 | + * @throws \EE_Error |
|
| 287 | + */ |
|
| 288 | + public function last_datetime() |
|
| 289 | + { |
|
| 290 | + $datetimes = $this->datetimes(array('limit' => 1, 'order_by' => array('DTT_EVT_start' => 'DESC'))); |
|
| 291 | + return end($datetimes); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * This returns the total tickets sold depending on the given parameters. |
|
| 297 | + * |
|
| 298 | + * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
| 299 | + * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
| 300 | + * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
| 301 | + * 'datetime' = total ticket sales in the datetime_ticket table. |
|
| 302 | + * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
| 303 | + * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
| 304 | + * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
| 305 | + * @return mixed (array|int) how many tickets have sold |
|
| 306 | + * @throws \EE_Error |
|
| 307 | + */ |
|
| 308 | + public function tickets_sold($what = 'ticket', $dtt_id = null) |
|
| 309 | + { |
|
| 310 | + $total = 0; |
|
| 311 | + $tickets_sold = $this->_all_tickets_sold(); |
|
| 312 | + switch ($what) { |
|
| 313 | + case 'ticket': |
|
| 314 | + return $tickets_sold['ticket']; |
|
| 315 | + break; |
|
| 316 | + case 'datetime': |
|
| 317 | + if (empty($tickets_sold['datetime'])) { |
|
| 318 | + return $total; |
|
| 319 | + } |
|
| 320 | + if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
| 321 | + EE_Error::add_error( |
|
| 322 | + __( |
|
| 323 | + 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
|
| 324 | + 'event_espresso' |
|
| 325 | + ), |
|
| 326 | + __FILE__, |
|
| 327 | + __FUNCTION__, |
|
| 328 | + __LINE__ |
|
| 329 | + ); |
|
| 330 | + return $total; |
|
| 331 | + } |
|
| 332 | + return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
| 333 | + break; |
|
| 334 | + default: |
|
| 335 | + return $total; |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
| 342 | + * |
|
| 343 | + * @return EE_Ticket[] |
|
| 344 | + * @throws \EE_Error |
|
| 345 | + */ |
|
| 346 | + protected function _all_tickets_sold() |
|
| 347 | + { |
|
| 348 | + $datetimes = $this->get_many_related('Datetime'); |
|
| 349 | + $tickets_sold = array(); |
|
| 350 | + if (! empty($datetimes)) { |
|
| 351 | + foreach ($datetimes as $datetime) { |
|
| 352 | + $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + // Tickets sold |
|
| 356 | + $tickets_sold['ticket'] = $this->sold(); |
|
| 357 | + return $tickets_sold; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * This returns the base price object for the ticket. |
|
| 363 | + * |
|
| 364 | + * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
| 365 | + * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
| 366 | + * @throws \EE_Error |
|
| 367 | + */ |
|
| 368 | + public function base_price($return_array = false) |
|
| 369 | + { |
|
| 370 | + $_where = array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price); |
|
| 371 | + return $return_array |
|
| 372 | + ? $this->get_many_related('Price', array($_where)) |
|
| 373 | + : $this->get_first_related('Price', array($_where)); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 379 | + * |
|
| 380 | + * @access public |
|
| 381 | + * @return EE_Price[] |
|
| 382 | + * @throws \EE_Error |
|
| 383 | + */ |
|
| 384 | + public function price_modifiers() |
|
| 385 | + { |
|
| 386 | + $query_params = array( |
|
| 387 | + 0 => array( |
|
| 388 | + 'Price_Type.PBT_ID' => array( |
|
| 389 | + 'NOT IN', |
|
| 390 | + array(EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax), |
|
| 391 | + ), |
|
| 392 | + ), |
|
| 393 | + ); |
|
| 394 | + return $this->prices($query_params); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Gets all the prices that combine to form the final price of this ticket |
|
| 400 | + * |
|
| 401 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 402 | + * @return EE_Price[]|EE_Base_Class[] |
|
| 403 | + * @throws \EE_Error |
|
| 404 | + */ |
|
| 405 | + public function prices($query_params = array()) |
|
| 406 | + { |
|
| 407 | + return $this->get_many_related('Price', $query_params); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
|
| 413 | + * |
|
| 414 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 415 | + * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
| 416 | + * @throws \EE_Error |
|
| 417 | + */ |
|
| 418 | + public function datetime_tickets($query_params = array()) |
|
| 419 | + { |
|
| 420 | + return $this->get_many_related('Datetime_Ticket', $query_params); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Gets all the datetimes from the db ordered by DTT_order |
|
| 426 | + * |
|
| 427 | + * @param boolean $show_expired |
|
| 428 | + * @param boolean $show_deleted |
|
| 429 | + * @return EE_Datetime[] |
|
| 430 | + * @throws \EE_Error |
|
| 431 | + */ |
|
| 432 | + public function datetimes_ordered($show_expired = true, $show_deleted = false) |
|
| 433 | + { |
|
| 434 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order( |
|
| 435 | + $this->ID(), |
|
| 436 | + $show_expired, |
|
| 437 | + $show_deleted |
|
| 438 | + ); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * Gets ID |
|
| 444 | + * |
|
| 445 | + * @return string |
|
| 446 | + * @throws \EE_Error |
|
| 447 | + */ |
|
| 448 | + public function ID() |
|
| 449 | + { |
|
| 450 | + return $this->get('TKT_ID'); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * get the author of the ticket. |
|
| 456 | + * |
|
| 457 | + * @since 4.5.0 |
|
| 458 | + * @return int |
|
| 459 | + * @throws \EE_Error |
|
| 460 | + */ |
|
| 461 | + public function wp_user() |
|
| 462 | + { |
|
| 463 | + return $this->get('TKT_wp_user'); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Gets the template for the ticket |
|
| 469 | + * |
|
| 470 | + * @return EE_Ticket_Template|EE_Base_Class |
|
| 471 | + * @throws \EE_Error |
|
| 472 | + */ |
|
| 473 | + public function template() |
|
| 474 | + { |
|
| 475 | + return $this->get_first_related('Ticket_Template'); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Simply returns an array of EE_Price objects that are taxes. |
|
| 481 | + * |
|
| 482 | + * @return EE_Price[] |
|
| 483 | + * @throws \EE_Error |
|
| 484 | + */ |
|
| 485 | + public function get_ticket_taxes_for_admin() |
|
| 486 | + { |
|
| 487 | + return EE_Taxes::get_taxes_for_admin(); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * @return float |
|
| 493 | + * @throws \EE_Error |
|
| 494 | + */ |
|
| 495 | + public function ticket_price() |
|
| 496 | + { |
|
| 497 | + return $this->get('TKT_price'); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * @return mixed |
|
| 503 | + * @throws \EE_Error |
|
| 504 | + */ |
|
| 505 | + public function pretty_price() |
|
| 506 | + { |
|
| 507 | + return $this->get_pretty('TKT_price'); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * @return bool |
|
| 513 | + * @throws \EE_Error |
|
| 514 | + */ |
|
| 515 | + public function is_free() |
|
| 516 | + { |
|
| 517 | + return $this->get_ticket_total_with_taxes() === (float) 0; |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * get_ticket_total_with_taxes |
|
| 523 | + * |
|
| 524 | + * @param bool $no_cache |
|
| 525 | + * @return float |
|
| 526 | + * @throws \EE_Error |
|
| 527 | + */ |
|
| 528 | + public function get_ticket_total_with_taxes($no_cache = false) |
|
| 529 | + { |
|
| 530 | + if ($this->_ticket_total_with_taxes === null || $no_cache) { |
|
| 531 | + $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
|
| 532 | + } |
|
| 533 | + return (float) $this->_ticket_total_with_taxes; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + public function ensure_TKT_Price_correct() |
|
| 538 | + { |
|
| 539 | + $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
| 540 | + $this->save(); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * @return float |
|
| 546 | + * @throws \EE_Error |
|
| 547 | + */ |
|
| 548 | + public function get_ticket_subtotal() |
|
| 549 | + { |
|
| 550 | + return EE_Taxes::get_subtotal_for_admin($this); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * Returns the total taxes applied to this ticket |
|
| 556 | + * |
|
| 557 | + * @return float |
|
| 558 | + * @throws \EE_Error |
|
| 559 | + */ |
|
| 560 | + public function get_ticket_taxes_total_for_admin() |
|
| 561 | + { |
|
| 562 | + return EE_Taxes::get_total_taxes_for_admin($this); |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Sets name |
|
| 568 | + * |
|
| 569 | + * @param string $name |
|
| 570 | + * @throws \EE_Error |
|
| 571 | + */ |
|
| 572 | + public function set_name($name) |
|
| 573 | + { |
|
| 574 | + $this->set('TKT_name', $name); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Gets description |
|
| 580 | + * |
|
| 581 | + * @return string |
|
| 582 | + * @throws \EE_Error |
|
| 583 | + */ |
|
| 584 | + public function description() |
|
| 585 | + { |
|
| 586 | + return $this->get('TKT_description'); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + |
|
| 590 | + /** |
|
| 591 | + * Sets description |
|
| 592 | + * |
|
| 593 | + * @param string $description |
|
| 594 | + * @throws \EE_Error |
|
| 595 | + */ |
|
| 596 | + public function set_description($description) |
|
| 597 | + { |
|
| 598 | + $this->set('TKT_description', $description); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * Gets start_date |
|
| 604 | + * |
|
| 605 | + * @param string $dt_frmt |
|
| 606 | + * @param string $tm_frmt |
|
| 607 | + * @return string |
|
| 608 | + * @throws \EE_Error |
|
| 609 | + */ |
|
| 610 | + public function start_date($dt_frmt = '', $tm_frmt = '') |
|
| 611 | + { |
|
| 612 | + return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt); |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * Sets start_date |
|
| 618 | + * |
|
| 619 | + * @param string $start_date |
|
| 620 | + * @return void |
|
| 621 | + * @throws \EE_Error |
|
| 622 | + */ |
|
| 623 | + public function set_start_date($start_date) |
|
| 624 | + { |
|
| 625 | + $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * Gets end_date |
|
| 631 | + * |
|
| 632 | + * @param string $dt_frmt |
|
| 633 | + * @param string $tm_frmt |
|
| 634 | + * @return string |
|
| 635 | + * @throws \EE_Error |
|
| 636 | + */ |
|
| 637 | + public function end_date($dt_frmt = '', $tm_frmt = '') |
|
| 638 | + { |
|
| 639 | + return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + /** |
|
| 644 | + * Sets end_date |
|
| 645 | + * |
|
| 646 | + * @param string $end_date |
|
| 647 | + * @return void |
|
| 648 | + * @throws \EE_Error |
|
| 649 | + */ |
|
| 650 | + public function set_end_date($end_date) |
|
| 651 | + { |
|
| 652 | + $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * Sets sell until time |
|
| 658 | + * |
|
| 659 | + * @since 4.5.0 |
|
| 660 | + * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
| 661 | + * @throws \EE_Error |
|
| 662 | + */ |
|
| 663 | + public function set_end_time($time) |
|
| 664 | + { |
|
| 665 | + $this->_set_time_for($time, 'TKT_end_date'); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + /** |
|
| 670 | + * Sets min |
|
| 671 | + * |
|
| 672 | + * @param int $min |
|
| 673 | + * @return void |
|
| 674 | + * @throws \EE_Error |
|
| 675 | + */ |
|
| 676 | + public function set_min($min) |
|
| 677 | + { |
|
| 678 | + $this->set('TKT_min', $min); |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * Gets max |
|
| 684 | + * |
|
| 685 | + * @return int |
|
| 686 | + * @throws \EE_Error |
|
| 687 | + */ |
|
| 688 | + public function max() |
|
| 689 | + { |
|
| 690 | + return $this->get('TKT_max'); |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * Sets max |
|
| 696 | + * |
|
| 697 | + * @param int $max |
|
| 698 | + * @return void |
|
| 699 | + * @throws \EE_Error |
|
| 700 | + */ |
|
| 701 | + public function set_max($max) |
|
| 702 | + { |
|
| 703 | + $this->set('TKT_max', $max); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * Sets price |
|
| 709 | + * |
|
| 710 | + * @param float $price |
|
| 711 | + * @return void |
|
| 712 | + * @throws \EE_Error |
|
| 713 | + */ |
|
| 714 | + public function set_price($price) |
|
| 715 | + { |
|
| 716 | + $this->set('TKT_price', $price); |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + |
|
| 720 | + /** |
|
| 721 | + * Gets sold |
|
| 722 | + * |
|
| 723 | + * @return int |
|
| 724 | + * @throws \EE_Error |
|
| 725 | + */ |
|
| 726 | + public function sold() |
|
| 727 | + { |
|
| 728 | + return $this->get_raw('TKT_sold'); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + |
|
| 732 | + /** |
|
| 733 | + * Sets sold |
|
| 734 | + * |
|
| 735 | + * @param int $sold |
|
| 736 | + * @return void |
|
| 737 | + * @throws \EE_Error |
|
| 738 | + */ |
|
| 739 | + public function set_sold($sold) |
|
| 740 | + { |
|
| 741 | + // sold can not go below zero |
|
| 742 | + $sold = max(0, $sold); |
|
| 743 | + $this->set('TKT_sold', $sold); |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * increments sold by amount passed by $qty |
|
| 749 | + * |
|
| 750 | + * @param int $qty |
|
| 751 | + * @return void |
|
| 752 | + * @throws \EE_Error |
|
| 753 | + */ |
|
| 754 | + public function increase_sold($qty = 1) |
|
| 755 | + { |
|
| 756 | + $sold = $this->sold() + $qty; |
|
| 757 | + // remove ticket reservation, but don't adjust datetime reservations, because that will happen |
|
| 758 | + // via \EE_Datetime::increase_sold() when \EE_Ticket::_increase_sold_for_datetimes() is called |
|
| 759 | + $this->decrease_reserved($qty, false, "TKT: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 760 | + $this->_increase_sold_for_datetimes($qty); |
|
| 761 | + $this->set_sold($sold); |
|
| 762 | + do_action( |
|
| 763 | + 'AHEE__EE_Ticket__increase_sold', |
|
| 764 | + $this, |
|
| 765 | + $qty, |
|
| 766 | + $sold |
|
| 767 | + ); |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + |
|
| 771 | + /** |
|
| 772 | + * Increases sold on related datetimes |
|
| 773 | + * |
|
| 774 | + * @param int $qty |
|
| 775 | + * @return void |
|
| 776 | + * @throws \EE_Error |
|
| 777 | + */ |
|
| 778 | + protected function _increase_sold_for_datetimes($qty = 1) |
|
| 779 | + { |
|
| 780 | + $datetimes = $this->datetimes(); |
|
| 781 | + if (is_array($datetimes)) { |
|
| 782 | + foreach ($datetimes as $datetime) { |
|
| 783 | + if ($datetime instanceof EE_Datetime) { |
|
| 784 | + $datetime->increase_sold($qty); |
|
| 785 | + $datetime->save(); |
|
| 786 | + } |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + |
|
| 792 | + /** |
|
| 793 | + * decrements (subtracts) sold by amount passed by $qty |
|
| 794 | + * |
|
| 795 | + * @param int $qty |
|
| 796 | + * @return void |
|
| 797 | + * @throws \EE_Error |
|
| 798 | + */ |
|
| 799 | + public function decrease_sold($qty = 1) |
|
| 800 | + { |
|
| 801 | + $sold = $this->sold() - $qty; |
|
| 802 | + $this->_decrease_sold_for_datetimes($qty); |
|
| 803 | + $this->set_sold($sold); |
|
| 804 | + do_action( |
|
| 805 | + 'AHEE__EE_Ticket__decrease_sold', |
|
| 806 | + $this, |
|
| 807 | + $qty, |
|
| 808 | + $sold |
|
| 809 | + ); |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + |
|
| 813 | + /** |
|
| 814 | + * Decreases sold on related datetimes |
|
| 815 | + * |
|
| 816 | + * @param int $qty |
|
| 817 | + * @return void |
|
| 818 | + * @throws \EE_Error |
|
| 819 | + */ |
|
| 820 | + protected function _decrease_sold_for_datetimes($qty = 1) |
|
| 821 | + { |
|
| 822 | + $datetimes = $this->datetimes(); |
|
| 823 | + if (is_array($datetimes)) { |
|
| 824 | + foreach ($datetimes as $datetime) { |
|
| 825 | + if ($datetime instanceof EE_Datetime) { |
|
| 826 | + $datetime->decrease_sold($qty); |
|
| 827 | + $datetime->save(); |
|
| 828 | + } |
|
| 829 | + } |
|
| 830 | + } |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + |
|
| 834 | + /** |
|
| 835 | + * Gets qty of reserved tickets |
|
| 836 | + * |
|
| 837 | + * @return int |
|
| 838 | + * @throws \EE_Error |
|
| 839 | + */ |
|
| 840 | + public function reserved() |
|
| 841 | + { |
|
| 842 | + return $this->get_raw('TKT_reserved'); |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + |
|
| 846 | + /** |
|
| 847 | + * Sets reserved |
|
| 848 | + * |
|
| 849 | + * @param int $reserved |
|
| 850 | + * @return void |
|
| 851 | + * @throws \EE_Error |
|
| 852 | + */ |
|
| 853 | + public function set_reserved($reserved) |
|
| 854 | + { |
|
| 855 | + // reserved can not go below zero |
|
| 856 | + $reserved = max(0, (int) $reserved); |
|
| 857 | + $this->set('TKT_reserved', $reserved); |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + |
|
| 861 | + /** |
|
| 862 | + * increments reserved by amount passed by $qty |
|
| 863 | + * |
|
| 864 | + * @param int $qty |
|
| 865 | + * @param string $source |
|
| 866 | + * @return void |
|
| 867 | + * @throws EE_Error |
|
| 868 | + * @throws InvalidArgumentException |
|
| 869 | + * @throws ReflectionException |
|
| 870 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 871 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 872 | + */ |
|
| 873 | + public function increase_reserved($qty = 1, $source = 'unknown') |
|
| 874 | + { |
|
| 875 | + $qty = absint($qty); |
|
| 876 | + $reserved = $this->reserved() + $qty; |
|
| 877 | + if ($reserved |
|
| 878 | + && $this->add_extra_meta( |
|
| 879 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 880 | + "{$qty} from {$source}" |
|
| 881 | + ) |
|
| 882 | + ) { |
|
| 883 | + $this->_increase_reserved_for_datetimes($qty); |
|
| 884 | + $this->set_reserved($reserved); |
|
| 885 | + do_action( |
|
| 886 | + 'AHEE__EE_Ticket__increase_reserved', |
|
| 887 | + $this, |
|
| 888 | + $qty, |
|
| 889 | + $reserved |
|
| 890 | + ); |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + /** |
|
| 896 | + * Increases sold on related datetimes |
|
| 897 | + * |
|
| 898 | + * @param int $qty |
|
| 899 | + * @return void |
|
| 900 | + * @throws \EE_Error |
|
| 901 | + */ |
|
| 902 | + protected function _increase_reserved_for_datetimes($qty = 1) |
|
| 903 | + { |
|
| 904 | + $datetimes = $this->datetimes(); |
|
| 905 | + if (is_array($datetimes)) { |
|
| 906 | + foreach ($datetimes as $datetime) { |
|
| 907 | + if ($datetime instanceof EE_Datetime) { |
|
| 908 | + $datetime->increase_reserved($qty); |
|
| 909 | + $datetime->save(); |
|
| 910 | + } |
|
| 911 | + } |
|
| 912 | + } |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + |
|
| 916 | + /** |
|
| 917 | + * decrements (subtracts) reserved by amount passed by $qty |
|
| 918 | + * |
|
| 919 | + * @param int $qty |
|
| 920 | + * @param bool $adjust_datetimes |
|
| 921 | + * @param string $source |
|
| 922 | + * @return void |
|
| 923 | + * @throws EE_Error |
|
| 924 | + * @throws InvalidArgumentException |
|
| 925 | + * @throws ReflectionException |
|
| 926 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 927 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 928 | + */ |
|
| 929 | + public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
| 930 | + { |
|
| 931 | + $reserved = $this->reserved() - absint($qty); |
|
| 932 | + if ($this->add_extra_meta( |
|
| 933 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 934 | + "-{$qty} from {$source}" |
|
| 935 | + )) { |
|
| 936 | + if ($adjust_datetimes) { |
|
| 937 | + $this->_decrease_reserved_for_datetimes($qty); |
|
| 938 | + } |
|
| 939 | + $this->set_reserved($reserved); |
|
| 940 | + do_action( |
|
| 941 | + 'AHEE__EE_Ticket__decrease_reserved', |
|
| 942 | + $this, |
|
| 943 | + $qty, |
|
| 944 | + $reserved |
|
| 945 | + ); |
|
| 946 | + } |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + |
|
| 950 | + /** |
|
| 951 | + * Increases sold on related datetimes |
|
| 952 | + * |
|
| 953 | + * @param int $qty |
|
| 954 | + * @return void |
|
| 955 | + * @throws \EE_Error |
|
| 956 | + */ |
|
| 957 | + protected function _decrease_reserved_for_datetimes($qty = 1) |
|
| 958 | + { |
|
| 959 | + $datetimes = $this->datetimes(); |
|
| 960 | + if (is_array($datetimes)) { |
|
| 961 | + foreach ($datetimes as $datetime) { |
|
| 962 | + if ($datetime instanceof EE_Datetime) { |
|
| 963 | + $datetime->decrease_reserved($qty); |
|
| 964 | + $datetime->save(); |
|
| 965 | + } |
|
| 966 | + } |
|
| 967 | + } |
|
| 968 | + } |
|
| 969 | + |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * Gets ticket quantity |
|
| 973 | + * |
|
| 974 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 975 | + * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
| 976 | + * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
| 977 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 978 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 979 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 980 | + * @return int |
|
| 981 | + * @throws \EE_Error |
|
| 982 | + */ |
|
| 983 | + public function qty($context = '') |
|
| 984 | + { |
|
| 985 | + switch ($context) { |
|
| 986 | + case 'reg_limit': |
|
| 987 | + return $this->real_quantity_on_ticket(); |
|
| 988 | + case 'saleable': |
|
| 989 | + return $this->real_quantity_on_ticket('saleable'); |
|
| 990 | + default: |
|
| 991 | + return $this->get_raw('TKT_qty'); |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + |
|
| 996 | + /** |
|
| 997 | + * Gets ticket quantity |
|
| 998 | + * |
|
| 999 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1000 | + * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
| 1001 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1002 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1003 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1004 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
| 1005 | + * set to 0 for all related datetimes |
|
| 1006 | + * @return int |
|
| 1007 | + * @throws \EE_Error |
|
| 1008 | + */ |
|
| 1009 | + public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) |
|
| 1010 | + { |
|
| 1011 | + $raw = $this->get_raw('TKT_qty'); |
|
| 1012 | + // return immediately if it's zero |
|
| 1013 | + if ($raw === 0) { |
|
| 1014 | + return $raw; |
|
| 1015 | + } |
|
| 1016 | + // echo "\n\n<br />Ticket: " . $this->name() . '<br />'; |
|
| 1017 | + // ensure qty doesn't exceed raw value for THIS ticket |
|
| 1018 | + $qty = min(EE_INF, $raw); |
|
| 1019 | + // echo "\n . qty: " . $qty . '<br />'; |
|
| 1020 | + // calculate this ticket's total sales and reservations |
|
| 1021 | + $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved(); |
|
| 1022 | + // echo "\n . sold: " . $this->sold() . '<br />'; |
|
| 1023 | + // echo "\n . reserved: " . $this->reserved() . '<br />'; |
|
| 1024 | + // echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />'; |
|
| 1025 | + // first we need to calculate the maximum number of tickets available for the datetime |
|
| 1026 | + // do we want data for one datetime or all of them ? |
|
| 1027 | + $query_params = $DTT_ID ? array(array('DTT_ID' => $DTT_ID)) : array(); |
|
| 1028 | + $datetimes = $this->datetimes($query_params); |
|
| 1029 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
| 1030 | + foreach ($datetimes as $datetime) { |
|
| 1031 | + if ($datetime instanceof EE_Datetime) { |
|
| 1032 | + $datetime->refresh_from_db(); |
|
| 1033 | + // echo "\n . . datetime name: " . $datetime->name() . '<br />'; |
|
| 1034 | + // echo "\n . . datetime ID: " . $datetime->ID() . '<br />'; |
|
| 1035 | + // initialize with no restrictions for each datetime |
|
| 1036 | + // but adjust datetime qty based on datetime reg limit |
|
| 1037 | + $datetime_qty = min(EE_INF, $datetime->reg_limit()); |
|
| 1038 | + // echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />'; |
|
| 1039 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1040 | + // if we want the actual saleable amount, then we need to consider OTHER ticket sales |
|
| 1041 | + // and reservations for this datetime, that do NOT include sales and reservations |
|
| 1042 | + // for this ticket (so we add $this->sold() and $this->reserved() back in) |
|
| 1043 | + if ($context === 'saleable') { |
|
| 1044 | + $datetime_qty = max( |
|
| 1045 | + $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket, |
|
| 1046 | + 0 |
|
| 1047 | + ); |
|
| 1048 | + // echo "\n . . . datetime sold: " . $datetime->sold() . '<br />'; |
|
| 1049 | + // echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />'; |
|
| 1050 | + // echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />'; |
|
| 1051 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1052 | + $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0; |
|
| 1053 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1054 | + } |
|
| 1055 | + $qty = min($datetime_qty, $qty); |
|
| 1056 | + // echo "\n . . qty: " . $qty . '<br />'; |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | + } |
|
| 1060 | + // NOW that we know the maximum number of tickets available for the datetime |
|
| 1061 | + // we can finally factor in the details for this specific ticket |
|
| 1062 | + if ($qty > 0 && $context === 'saleable') { |
|
| 1063 | + // and subtract the sales for THIS ticket |
|
| 1064 | + $qty = max($qty - $sold_and_reserved_for_this_ticket, 0); |
|
| 1065 | + // echo "\n . qty: " . $qty . '<br />'; |
|
| 1066 | + } |
|
| 1067 | + // echo "\nFINAL QTY: " . $qty . "<br /><br />"; |
|
| 1068 | + return $qty; |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + |
|
| 1072 | + /** |
|
| 1073 | + * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes |
|
| 1074 | + * |
|
| 1075 | + * @param int $qty |
|
| 1076 | + * @return void |
|
| 1077 | + * @throws \EE_Error |
|
| 1078 | + */ |
|
| 1079 | + public function set_qty($qty) |
|
| 1080 | + { |
|
| 1081 | + $datetimes = $this->datetimes(); |
|
| 1082 | + foreach ($datetimes as $datetime) { |
|
| 1083 | + if ($datetime instanceof EE_Datetime) { |
|
| 1084 | + $qty = min($qty, $datetime->reg_limit()); |
|
| 1085 | + } |
|
| 1086 | + } |
|
| 1087 | + $this->set('TKT_qty', $qty); |
|
| 1088 | + } |
|
| 1089 | + |
|
| 1090 | + |
|
| 1091 | + /** |
|
| 1092 | + * Gets uses |
|
| 1093 | + * |
|
| 1094 | + * @return int |
|
| 1095 | + * @throws \EE_Error |
|
| 1096 | + */ |
|
| 1097 | + public function uses() |
|
| 1098 | + { |
|
| 1099 | + return $this->get('TKT_uses'); |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + |
|
| 1103 | + /** |
|
| 1104 | + * Sets uses |
|
| 1105 | + * |
|
| 1106 | + * @param int $uses |
|
| 1107 | + * @return void |
|
| 1108 | + * @throws \EE_Error |
|
| 1109 | + */ |
|
| 1110 | + public function set_uses($uses) |
|
| 1111 | + { |
|
| 1112 | + $this->set('TKT_uses', $uses); |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + |
|
| 1116 | + /** |
|
| 1117 | + * returns whether ticket is required or not. |
|
| 1118 | + * |
|
| 1119 | + * @return boolean |
|
| 1120 | + * @throws \EE_Error |
|
| 1121 | + */ |
|
| 1122 | + public function required() |
|
| 1123 | + { |
|
| 1124 | + return $this->get('TKT_required'); |
|
| 1125 | + } |
|
| 1126 | + |
|
| 1127 | + |
|
| 1128 | + /** |
|
| 1129 | + * sets the TKT_required property |
|
| 1130 | + * |
|
| 1131 | + * @param boolean $required |
|
| 1132 | + * @return void |
|
| 1133 | + * @throws \EE_Error |
|
| 1134 | + */ |
|
| 1135 | + public function set_required($required) |
|
| 1136 | + { |
|
| 1137 | + $this->set('TKT_required', $required); |
|
| 1138 | + } |
|
| 1139 | + |
|
| 1140 | + |
|
| 1141 | + /** |
|
| 1142 | + * Gets taxable |
|
| 1143 | + * |
|
| 1144 | + * @return boolean |
|
| 1145 | + * @throws \EE_Error |
|
| 1146 | + */ |
|
| 1147 | + public function taxable() |
|
| 1148 | + { |
|
| 1149 | + return $this->get('TKT_taxable'); |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + |
|
| 1153 | + /** |
|
| 1154 | + * Sets taxable |
|
| 1155 | + * |
|
| 1156 | + * @param boolean $taxable |
|
| 1157 | + * @return void |
|
| 1158 | + * @throws \EE_Error |
|
| 1159 | + */ |
|
| 1160 | + public function set_taxable($taxable) |
|
| 1161 | + { |
|
| 1162 | + $this->set('TKT_taxable', $taxable); |
|
| 1163 | + } |
|
| 1164 | + |
|
| 1165 | + |
|
| 1166 | + /** |
|
| 1167 | + * Gets is_default |
|
| 1168 | + * |
|
| 1169 | + * @return boolean |
|
| 1170 | + * @throws \EE_Error |
|
| 1171 | + */ |
|
| 1172 | + public function is_default() |
|
| 1173 | + { |
|
| 1174 | + return $this->get('TKT_is_default'); |
|
| 1175 | + } |
|
| 1176 | + |
|
| 1177 | + |
|
| 1178 | + /** |
|
| 1179 | + * Sets is_default |
|
| 1180 | + * |
|
| 1181 | + * @param boolean $is_default |
|
| 1182 | + * @return void |
|
| 1183 | + * @throws \EE_Error |
|
| 1184 | + */ |
|
| 1185 | + public function set_is_default($is_default) |
|
| 1186 | + { |
|
| 1187 | + $this->set('TKT_is_default', $is_default); |
|
| 1188 | + } |
|
| 1189 | + |
|
| 1190 | + |
|
| 1191 | + /** |
|
| 1192 | + * Gets order |
|
| 1193 | + * |
|
| 1194 | + * @return int |
|
| 1195 | + * @throws \EE_Error |
|
| 1196 | + */ |
|
| 1197 | + public function order() |
|
| 1198 | + { |
|
| 1199 | + return $this->get('TKT_order'); |
|
| 1200 | + } |
|
| 1201 | + |
|
| 1202 | + |
|
| 1203 | + /** |
|
| 1204 | + * Sets order |
|
| 1205 | + * |
|
| 1206 | + * @param int $order |
|
| 1207 | + * @return void |
|
| 1208 | + * @throws \EE_Error |
|
| 1209 | + */ |
|
| 1210 | + public function set_order($order) |
|
| 1211 | + { |
|
| 1212 | + $this->set('TKT_order', $order); |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + |
|
| 1216 | + /** |
|
| 1217 | + * Gets row |
|
| 1218 | + * |
|
| 1219 | + * @return int |
|
| 1220 | + * @throws \EE_Error |
|
| 1221 | + */ |
|
| 1222 | + public function row() |
|
| 1223 | + { |
|
| 1224 | + return $this->get('TKT_row'); |
|
| 1225 | + } |
|
| 1226 | + |
|
| 1227 | + |
|
| 1228 | + /** |
|
| 1229 | + * Sets row |
|
| 1230 | + * |
|
| 1231 | + * @param int $row |
|
| 1232 | + * @return void |
|
| 1233 | + * @throws \EE_Error |
|
| 1234 | + */ |
|
| 1235 | + public function set_row($row) |
|
| 1236 | + { |
|
| 1237 | + $this->set('TKT_row', $row); |
|
| 1238 | + } |
|
| 1239 | + |
|
| 1240 | + |
|
| 1241 | + /** |
|
| 1242 | + * Gets deleted |
|
| 1243 | + * |
|
| 1244 | + * @return boolean |
|
| 1245 | + * @throws \EE_Error |
|
| 1246 | + */ |
|
| 1247 | + public function deleted() |
|
| 1248 | + { |
|
| 1249 | + return $this->get('TKT_deleted'); |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + |
|
| 1253 | + /** |
|
| 1254 | + * Sets deleted |
|
| 1255 | + * |
|
| 1256 | + * @param boolean $deleted |
|
| 1257 | + * @return void |
|
| 1258 | + * @throws \EE_Error |
|
| 1259 | + */ |
|
| 1260 | + public function set_deleted($deleted) |
|
| 1261 | + { |
|
| 1262 | + $this->set('TKT_deleted', $deleted); |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + |
|
| 1266 | + /** |
|
| 1267 | + * Gets parent |
|
| 1268 | + * |
|
| 1269 | + * @return int |
|
| 1270 | + * @throws \EE_Error |
|
| 1271 | + */ |
|
| 1272 | + public function parent_ID() |
|
| 1273 | + { |
|
| 1274 | + return $this->get('TKT_parent'); |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + |
|
| 1278 | + /** |
|
| 1279 | + * Sets parent |
|
| 1280 | + * |
|
| 1281 | + * @param int $parent |
|
| 1282 | + * @return void |
|
| 1283 | + * @throws \EE_Error |
|
| 1284 | + */ |
|
| 1285 | + public function set_parent_ID($parent) |
|
| 1286 | + { |
|
| 1287 | + $this->set('TKT_parent', $parent); |
|
| 1288 | + } |
|
| 1289 | + |
|
| 1290 | + |
|
| 1291 | + /** |
|
| 1292 | + * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
| 1293 | + * |
|
| 1294 | + * @return string |
|
| 1295 | + * @throws \EE_Error |
|
| 1296 | + */ |
|
| 1297 | + public function name_and_info() |
|
| 1298 | + { |
|
| 1299 | + $times = array(); |
|
| 1300 | + foreach ($this->datetimes() as $datetime) { |
|
| 1301 | + $times[] = $datetime->start_date_and_time(); |
|
| 1302 | + } |
|
| 1303 | + return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
| 1304 | + } |
|
| 1305 | + |
|
| 1306 | + |
|
| 1307 | + /** |
|
| 1308 | + * Gets name |
|
| 1309 | + * |
|
| 1310 | + * @return string |
|
| 1311 | + * @throws \EE_Error |
|
| 1312 | + */ |
|
| 1313 | + public function name() |
|
| 1314 | + { |
|
| 1315 | + return $this->get('TKT_name'); |
|
| 1316 | + } |
|
| 1317 | + |
|
| 1318 | + |
|
| 1319 | + /** |
|
| 1320 | + * Gets price |
|
| 1321 | + * |
|
| 1322 | + * @return float |
|
| 1323 | + * @throws \EE_Error |
|
| 1324 | + */ |
|
| 1325 | + public function price() |
|
| 1326 | + { |
|
| 1327 | + return $this->get('TKT_price'); |
|
| 1328 | + } |
|
| 1329 | + |
|
| 1330 | + |
|
| 1331 | + /** |
|
| 1332 | + * Gets all the registrations for this ticket |
|
| 1333 | + * |
|
| 1334 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1335 | + * @return EE_Registration[]|EE_Base_Class[] |
|
| 1336 | + * @throws \EE_Error |
|
| 1337 | + */ |
|
| 1338 | + public function registrations($query_params = array()) |
|
| 1339 | + { |
|
| 1340 | + return $this->get_many_related('Registration', $query_params); |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + |
|
| 1344 | + /** |
|
| 1345 | + * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
| 1346 | + * into account |
|
| 1347 | + * |
|
| 1348 | + * @return int |
|
| 1349 | + * @throws \EE_Error |
|
| 1350 | + */ |
|
| 1351 | + public function update_tickets_sold() |
|
| 1352 | + { |
|
| 1353 | + $count_regs_for_this_ticket = $this->count_registrations( |
|
| 1354 | + array( |
|
| 1355 | + array( |
|
| 1356 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1357 | + 'REG_deleted' => 0, |
|
| 1358 | + ), |
|
| 1359 | + ) |
|
| 1360 | + ); |
|
| 1361 | + $sold = $this->sold(); |
|
| 1362 | + if ($count_regs_for_this_ticket > $sold) { |
|
| 1363 | + $this->increase_sold($count_regs_for_this_ticket - $sold); |
|
| 1364 | + $this->save(); |
|
| 1365 | + } elseif ($count_regs_for_this_ticket < $sold) { |
|
| 1366 | + $this->decrease_sold($count_regs_for_this_ticket - $sold); |
|
| 1367 | + $this->save(); |
|
| 1368 | + } |
|
| 1369 | + return $count_regs_for_this_ticket; |
|
| 1370 | + } |
|
| 1371 | + |
|
| 1372 | + |
|
| 1373 | + /** |
|
| 1374 | + * Counts the registrations for this ticket |
|
| 1375 | + * |
|
| 1376 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1377 | + * @return int |
|
| 1378 | + */ |
|
| 1379 | + public function count_registrations($query_params = array()) |
|
| 1380 | + { |
|
| 1381 | + return $this->count_related('Registration', $query_params); |
|
| 1382 | + } |
|
| 1383 | + |
|
| 1384 | + |
|
| 1385 | + /** |
|
| 1386 | + * Implementation for EEI_Has_Icon interface method. |
|
| 1387 | + * |
|
| 1388 | + * @see EEI_Visual_Representation for comments |
|
| 1389 | + * @return string |
|
| 1390 | + */ |
|
| 1391 | + public function get_icon() |
|
| 1392 | + { |
|
| 1393 | + return '<span class="dashicons dashicons-tickets-alt"></span>'; |
|
| 1394 | + } |
|
| 1395 | + |
|
| 1396 | + |
|
| 1397 | + /** |
|
| 1398 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1399 | + * |
|
| 1400 | + * @see EEI_Event_Relation for comments |
|
| 1401 | + * @return EE_Event |
|
| 1402 | + * @throws \EE_Error |
|
| 1403 | + * @throws UnexpectedEntityException |
|
| 1404 | + */ |
|
| 1405 | + public function get_related_event() |
|
| 1406 | + { |
|
| 1407 | + // get one datetime to use for getting the event |
|
| 1408 | + $datetime = $this->first_datetime(); |
|
| 1409 | + if (! $datetime instanceof \EE_Datetime) { |
|
| 1410 | + throw new UnexpectedEntityException( |
|
| 1411 | + $datetime, |
|
| 1412 | + 'EE_Datetime', |
|
| 1413 | + sprintf( |
|
| 1414 | + __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
| 1415 | + $this->name() |
|
| 1416 | + ) |
|
| 1417 | + ); |
|
| 1418 | + } |
|
| 1419 | + $event = $datetime->event(); |
|
| 1420 | + if (! $event instanceof \EE_Event) { |
|
| 1421 | + throw new UnexpectedEntityException( |
|
| 1422 | + $event, |
|
| 1423 | + 'EE_Event', |
|
| 1424 | + sprintf( |
|
| 1425 | + __('The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
| 1426 | + $this->name() |
|
| 1427 | + ) |
|
| 1428 | + ); |
|
| 1429 | + } |
|
| 1430 | + return $event; |
|
| 1431 | + } |
|
| 1432 | + |
|
| 1433 | + |
|
| 1434 | + /** |
|
| 1435 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1436 | + * |
|
| 1437 | + * @see EEI_Event_Relation for comments |
|
| 1438 | + * @return string |
|
| 1439 | + * @throws UnexpectedEntityException |
|
| 1440 | + * @throws \EE_Error |
|
| 1441 | + */ |
|
| 1442 | + public function get_event_name() |
|
| 1443 | + { |
|
| 1444 | + $event = $this->get_related_event(); |
|
| 1445 | + return $event instanceof EE_Event ? $event->name() : ''; |
|
| 1446 | + } |
|
| 1447 | + |
|
| 1448 | + |
|
| 1449 | + /** |
|
| 1450 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1451 | + * |
|
| 1452 | + * @see EEI_Event_Relation for comments |
|
| 1453 | + * @return int |
|
| 1454 | + * @throws UnexpectedEntityException |
|
| 1455 | + * @throws \EE_Error |
|
| 1456 | + */ |
|
| 1457 | + public function get_event_ID() |
|
| 1458 | + { |
|
| 1459 | + $event = $this->get_related_event(); |
|
| 1460 | + return $event instanceof EE_Event ? $event->ID() : 0; |
|
| 1461 | + } |
|
| 1462 | + |
|
| 1463 | + |
|
| 1464 | + /** |
|
| 1465 | + * This simply returns whether a ticket can be permanently deleted or not. |
|
| 1466 | + * The criteria for determining this is whether the ticket has any related registrations. |
|
| 1467 | + * If there are none then it can be permanently deleted. |
|
| 1468 | + * |
|
| 1469 | + * @return bool |
|
| 1470 | + */ |
|
| 1471 | + public function is_permanently_deleteable() |
|
| 1472 | + { |
|
| 1473 | + return $this->count_registrations() === 0; |
|
| 1474 | + } |
|
| 1475 | 1475 | } |