@@ -14,228 +14,228 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class I18nRegistry |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @var DomainInterface |
|
| 19 | - */ |
|
| 20 | - private $domain; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Will hold all registered i18n scripts. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 27 | - private $registered_i18n = array(); |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Used to hold queued translations for the chunks loading in a view. |
|
| 32 | - * |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 35 | - private $queued_handle_translations = array(); |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to |
|
| 40 | - * translation strings. |
|
| 41 | - * |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - private $i18n_map; |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * I18nRegistry constructor. |
|
| 49 | - * |
|
| 50 | - * @param array() $i18n_map An array of script handle names and the strings translated for those handles. If not |
|
| 51 | - * provided, the class will look for map in root of plugin with filename of |
|
| 52 | - * 'translation-map.json'. |
|
| 53 | - * @param DomainInterface $domain |
|
| 54 | - */ |
|
| 55 | - public function __construct(array $i18n_map = array(), DomainInterface $domain) |
|
| 56 | - { |
|
| 57 | - $this->domain = $domain; |
|
| 58 | - $this->setI18nMap($i18n_map); |
|
| 59 | - add_filter('print_scripts_array', array($this, 'queueI18n')); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Used to register a script that has i18n strings for its $handle |
|
| 65 | - * |
|
| 66 | - * @param string $handle The script handle reference. |
|
| 67 | - * @param string $domain The i18n domain for the strings. |
|
| 68 | - */ |
|
| 69 | - public function registerScriptI18n($handle, $domain = 'event_espresso') |
|
| 70 | - { |
|
| 71 | - $this->registered_i18n[$handle] = $domain; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data. |
|
| 78 | - * |
|
| 79 | - * @param array $handles Array of registered script handles. |
|
| 80 | - * @return array |
|
| 81 | - */ |
|
| 82 | - public function queueI18n(array $handles) |
|
| 83 | - { |
|
| 84 | - if (empty($this->registered_i18n) || empty($this->i18n_map)) { |
|
| 85 | - return $handles; |
|
| 86 | - } |
|
| 87 | - foreach ($handles as $handle) { |
|
| 88 | - $this->queueI18nTranslationsForHandle($handle); |
|
| 89 | - } |
|
| 90 | - if ($this->queued_handle_translations) { |
|
| 91 | - foreach ($this->queued_handle_translations as $handle => $translations_for_domain) { |
|
| 92 | - $this->registerInlineScript( |
|
| 93 | - $handle, |
|
| 94 | - $translations_for_domain['translations'], |
|
| 95 | - $translations_for_domain['domain'] |
|
| 96 | - ); |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - return $handles; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Registers inline script with translations for given handle and domain. |
|
| 105 | - * |
|
| 106 | - * @param string $handle Handle used to register javascript file containing translations. |
|
| 107 | - * @param array $translations Array of string translations. |
|
| 108 | - * @param string $domain Domain for translations. If left empty then strings are registered with the default |
|
| 109 | - * domain for the javascript. |
|
| 110 | - */ |
|
| 111 | - private function registerInlineScript($handle, array $translations, $domain) |
|
| 112 | - { |
|
| 113 | - $script = $domain ? |
|
| 114 | - 'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ', ' . $domain . ' );' : |
|
| 115 | - 'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );'; |
|
| 116 | - wp_add_inline_script($handle, $script, 'before'); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Queues up the translation strings for the given handle. |
|
| 122 | - * |
|
| 123 | - * @param string $handle The script handle being queued up. |
|
| 124 | - */ |
|
| 125 | - private function queueI18nTranslationsForHandle($handle) |
|
| 126 | - { |
|
| 127 | - if (isset($this->registered_i18n[$handle])) { |
|
| 128 | - $domain = $this->registered_i18n[$handle]; |
|
| 129 | - $translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain); |
|
| 130 | - if (count($translations) > 1) { |
|
| 131 | - $this->queued_handle_translations[$handle] = array( |
|
| 132 | - 'domain' => $domain, |
|
| 133 | - 'translations' => $translations, |
|
| 134 | - ); |
|
| 135 | - } |
|
| 136 | - unset($this->registered_i18n[$handle]); |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Sets the internal i18n_map property. |
|
| 143 | - * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map. |
|
| 144 | - * |
|
| 145 | - * @param array $i18n_map If provided, an array of translation strings indexed by script handle names they |
|
| 146 | - * correspond to. |
|
| 147 | - */ |
|
| 148 | - private function setI18nMap(array $i18n_map) |
|
| 149 | - { |
|
| 150 | - if (empty($i18n_map)) { |
|
| 151 | - $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json') |
|
| 152 | - ? json_decode( |
|
| 153 | - file_get_contents($this->domain->pluginPath() . 'translation-map.json'), |
|
| 154 | - true |
|
| 155 | - ) |
|
| 156 | - : array(); |
|
| 157 | - } |
|
| 158 | - $this->i18n_map = $i18n_map; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Get the jed locale data for a given $handle and domain |
|
| 164 | - * |
|
| 165 | - * @param string $handle The name for the script handle we want strings returned for. |
|
| 166 | - * @param string $domain The i18n domain. |
|
| 167 | - * @return array |
|
| 168 | - */ |
|
| 169 | - protected function getJedLocaleDataForDomainAndChunk($handle, $domain) |
|
| 170 | - { |
|
| 171 | - $translations = $this->getJedLocaleData($domain); |
|
| 172 | - // get index for adding back after extracting strings for this $chunk. |
|
| 173 | - $index = $translations['']; |
|
| 174 | - $translations = $this->getLocaleDataMatchingMap( |
|
| 175 | - $this->getOriginalStringsForHandleFromMap($handle), |
|
| 176 | - $translations |
|
| 177 | - ); |
|
| 178 | - $translations[''] = $index; |
|
| 179 | - return $translations; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Get locale data for given strings from given translations |
|
| 185 | - * |
|
| 186 | - * @param array $string_set This is the subset of strings (msgIds) we want to extract from the translations array. |
|
| 187 | - * @param array $translations Translation data to extra strings from. |
|
| 188 | - * @return array |
|
| 189 | - */ |
|
| 190 | - protected function getLocaleDataMatchingMap(array $string_set, array $translations) |
|
| 191 | - { |
|
| 192 | - if (empty($string_set)) { |
|
| 193 | - return array(); |
|
| 194 | - } |
|
| 195 | - // some strings with quotes in them will break on the array_flip, so making sure quotes in the string are |
|
| 196 | - // slashed also filter falsey values. |
|
| 197 | - $string_set = array_unique(array_filter(wp_slash($string_set))); |
|
| 198 | - return array_intersect_key($translations, array_flip($string_set)); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Get original strings to translate for the given chunk from the map |
|
| 204 | - * |
|
| 205 | - * @param string $handle The script handle name to get strings from the map for. |
|
| 206 | - * @return array |
|
| 207 | - */ |
|
| 208 | - protected function getOriginalStringsForHandleFromMap($handle) |
|
| 209 | - { |
|
| 210 | - return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array(); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Returns Jed-formatted localization data. |
|
| 216 | - * |
|
| 217 | - * @param string $domain Translation domain. |
|
| 218 | - * @return array |
|
| 219 | - */ |
|
| 220 | - private function getJedLocaleData($domain) |
|
| 221 | - { |
|
| 222 | - $translations = get_translations_for_domain($domain); |
|
| 223 | - |
|
| 224 | - $locale = array( |
|
| 225 | - '' => array( |
|
| 226 | - 'domain' => $domain, |
|
| 227 | - 'lang' => is_admin() ? get_user_locale() : get_locale(), |
|
| 228 | - ), |
|
| 229 | - ); |
|
| 230 | - |
|
| 231 | - if (! empty($translations->headers['Plural-Forms'])) { |
|
| 232 | - $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - foreach ($translations->entries as $msgid => $entry) { |
|
| 236 | - $locale[$msgid] = $entry->translations; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $locale; |
|
| 240 | - } |
|
| 17 | + /** |
|
| 18 | + * @var DomainInterface |
|
| 19 | + */ |
|
| 20 | + private $domain; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Will hold all registered i18n scripts. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + private $registered_i18n = array(); |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Used to hold queued translations for the chunks loading in a view. |
|
| 32 | + * |
|
| 33 | + * @var array |
|
| 34 | + */ |
|
| 35 | + private $queued_handle_translations = array(); |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to |
|
| 40 | + * translation strings. |
|
| 41 | + * |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + private $i18n_map; |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * I18nRegistry constructor. |
|
| 49 | + * |
|
| 50 | + * @param array() $i18n_map An array of script handle names and the strings translated for those handles. If not |
|
| 51 | + * provided, the class will look for map in root of plugin with filename of |
|
| 52 | + * 'translation-map.json'. |
|
| 53 | + * @param DomainInterface $domain |
|
| 54 | + */ |
|
| 55 | + public function __construct(array $i18n_map = array(), DomainInterface $domain) |
|
| 56 | + { |
|
| 57 | + $this->domain = $domain; |
|
| 58 | + $this->setI18nMap($i18n_map); |
|
| 59 | + add_filter('print_scripts_array', array($this, 'queueI18n')); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Used to register a script that has i18n strings for its $handle |
|
| 65 | + * |
|
| 66 | + * @param string $handle The script handle reference. |
|
| 67 | + * @param string $domain The i18n domain for the strings. |
|
| 68 | + */ |
|
| 69 | + public function registerScriptI18n($handle, $domain = 'event_espresso') |
|
| 70 | + { |
|
| 71 | + $this->registered_i18n[$handle] = $domain; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data. |
|
| 78 | + * |
|
| 79 | + * @param array $handles Array of registered script handles. |
|
| 80 | + * @return array |
|
| 81 | + */ |
|
| 82 | + public function queueI18n(array $handles) |
|
| 83 | + { |
|
| 84 | + if (empty($this->registered_i18n) || empty($this->i18n_map)) { |
|
| 85 | + return $handles; |
|
| 86 | + } |
|
| 87 | + foreach ($handles as $handle) { |
|
| 88 | + $this->queueI18nTranslationsForHandle($handle); |
|
| 89 | + } |
|
| 90 | + if ($this->queued_handle_translations) { |
|
| 91 | + foreach ($this->queued_handle_translations as $handle => $translations_for_domain) { |
|
| 92 | + $this->registerInlineScript( |
|
| 93 | + $handle, |
|
| 94 | + $translations_for_domain['translations'], |
|
| 95 | + $translations_for_domain['domain'] |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + return $handles; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Registers inline script with translations for given handle and domain. |
|
| 105 | + * |
|
| 106 | + * @param string $handle Handle used to register javascript file containing translations. |
|
| 107 | + * @param array $translations Array of string translations. |
|
| 108 | + * @param string $domain Domain for translations. If left empty then strings are registered with the default |
|
| 109 | + * domain for the javascript. |
|
| 110 | + */ |
|
| 111 | + private function registerInlineScript($handle, array $translations, $domain) |
|
| 112 | + { |
|
| 113 | + $script = $domain ? |
|
| 114 | + 'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ', ' . $domain . ' );' : |
|
| 115 | + 'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );'; |
|
| 116 | + wp_add_inline_script($handle, $script, 'before'); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Queues up the translation strings for the given handle. |
|
| 122 | + * |
|
| 123 | + * @param string $handle The script handle being queued up. |
|
| 124 | + */ |
|
| 125 | + private function queueI18nTranslationsForHandle($handle) |
|
| 126 | + { |
|
| 127 | + if (isset($this->registered_i18n[$handle])) { |
|
| 128 | + $domain = $this->registered_i18n[$handle]; |
|
| 129 | + $translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain); |
|
| 130 | + if (count($translations) > 1) { |
|
| 131 | + $this->queued_handle_translations[$handle] = array( |
|
| 132 | + 'domain' => $domain, |
|
| 133 | + 'translations' => $translations, |
|
| 134 | + ); |
|
| 135 | + } |
|
| 136 | + unset($this->registered_i18n[$handle]); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Sets the internal i18n_map property. |
|
| 143 | + * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map. |
|
| 144 | + * |
|
| 145 | + * @param array $i18n_map If provided, an array of translation strings indexed by script handle names they |
|
| 146 | + * correspond to. |
|
| 147 | + */ |
|
| 148 | + private function setI18nMap(array $i18n_map) |
|
| 149 | + { |
|
| 150 | + if (empty($i18n_map)) { |
|
| 151 | + $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json') |
|
| 152 | + ? json_decode( |
|
| 153 | + file_get_contents($this->domain->pluginPath() . 'translation-map.json'), |
|
| 154 | + true |
|
| 155 | + ) |
|
| 156 | + : array(); |
|
| 157 | + } |
|
| 158 | + $this->i18n_map = $i18n_map; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Get the jed locale data for a given $handle and domain |
|
| 164 | + * |
|
| 165 | + * @param string $handle The name for the script handle we want strings returned for. |
|
| 166 | + * @param string $domain The i18n domain. |
|
| 167 | + * @return array |
|
| 168 | + */ |
|
| 169 | + protected function getJedLocaleDataForDomainAndChunk($handle, $domain) |
|
| 170 | + { |
|
| 171 | + $translations = $this->getJedLocaleData($domain); |
|
| 172 | + // get index for adding back after extracting strings for this $chunk. |
|
| 173 | + $index = $translations['']; |
|
| 174 | + $translations = $this->getLocaleDataMatchingMap( |
|
| 175 | + $this->getOriginalStringsForHandleFromMap($handle), |
|
| 176 | + $translations |
|
| 177 | + ); |
|
| 178 | + $translations[''] = $index; |
|
| 179 | + return $translations; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Get locale data for given strings from given translations |
|
| 185 | + * |
|
| 186 | + * @param array $string_set This is the subset of strings (msgIds) we want to extract from the translations array. |
|
| 187 | + * @param array $translations Translation data to extra strings from. |
|
| 188 | + * @return array |
|
| 189 | + */ |
|
| 190 | + protected function getLocaleDataMatchingMap(array $string_set, array $translations) |
|
| 191 | + { |
|
| 192 | + if (empty($string_set)) { |
|
| 193 | + return array(); |
|
| 194 | + } |
|
| 195 | + // some strings with quotes in them will break on the array_flip, so making sure quotes in the string are |
|
| 196 | + // slashed also filter falsey values. |
|
| 197 | + $string_set = array_unique(array_filter(wp_slash($string_set))); |
|
| 198 | + return array_intersect_key($translations, array_flip($string_set)); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Get original strings to translate for the given chunk from the map |
|
| 204 | + * |
|
| 205 | + * @param string $handle The script handle name to get strings from the map for. |
|
| 206 | + * @return array |
|
| 207 | + */ |
|
| 208 | + protected function getOriginalStringsForHandleFromMap($handle) |
|
| 209 | + { |
|
| 210 | + return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array(); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Returns Jed-formatted localization data. |
|
| 216 | + * |
|
| 217 | + * @param string $domain Translation domain. |
|
| 218 | + * @return array |
|
| 219 | + */ |
|
| 220 | + private function getJedLocaleData($domain) |
|
| 221 | + { |
|
| 222 | + $translations = get_translations_for_domain($domain); |
|
| 223 | + |
|
| 224 | + $locale = array( |
|
| 225 | + '' => array( |
|
| 226 | + 'domain' => $domain, |
|
| 227 | + 'lang' => is_admin() ? get_user_locale() : get_locale(), |
|
| 228 | + ), |
|
| 229 | + ); |
|
| 230 | + |
|
| 231 | + if (! empty($translations->headers['Plural-Forms'])) { |
|
| 232 | + $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + foreach ($translations->entries as $msgid => $entry) { |
|
| 236 | + $locale[$msgid] = $entry->translations; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $locale; |
|
| 240 | + } |
|
| 241 | 241 | } |
| 242 | 242 | \ No newline at end of file |
@@ -111,8 +111,7 @@ discard block |
||
| 111 | 111 | private function registerInlineScript($handle, array $translations, $domain) |
| 112 | 112 | { |
| 113 | 113 | $script = $domain ? |
| 114 | - 'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ', ' . $domain . ' );' : |
|
| 115 | - 'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );'; |
|
| 114 | + 'wp.i18n.setLocaleData( '.wp_json_encode($translations).', '.$domain.' );' : 'wp.i18n.setLocaleData( '.wp_json_encode($translations).' );'; |
|
| 116 | 115 | wp_add_inline_script($handle, $script, 'before'); |
| 117 | 116 | } |
| 118 | 117 | |
@@ -148,9 +147,9 @@ discard block |
||
| 148 | 147 | private function setI18nMap(array $i18n_map) |
| 149 | 148 | { |
| 150 | 149 | if (empty($i18n_map)) { |
| 151 | - $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json') |
|
| 150 | + $i18n_map = file_exists($this->domain->pluginPath().'translation-map.json') |
|
| 152 | 151 | ? json_decode( |
| 153 | - file_get_contents($this->domain->pluginPath() . 'translation-map.json'), |
|
| 152 | + file_get_contents($this->domain->pluginPath().'translation-map.json'), |
|
| 154 | 153 | true |
| 155 | 154 | ) |
| 156 | 155 | : array(); |
@@ -228,7 +227,7 @@ discard block |
||
| 228 | 227 | ), |
| 229 | 228 | ); |
| 230 | 229 | |
| 231 | - if (! empty($translations->headers['Plural-Forms'])) { |
|
| 230 | + if ( ! empty($translations->headers['Plural-Forms'])) { |
|
| 232 | 231 | $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
| 233 | 232 | } |
| 234 | 233 | |
@@ -19,2038 +19,2038 @@ |
||
| 19 | 19 | { |
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Used to reference when a registration has never been checked in. |
|
| 24 | - * |
|
| 25 | - * @deprecated use \EE_Checkin::status_checked_never instead |
|
| 26 | - * @type int |
|
| 27 | - */ |
|
| 28 | - const checkin_status_never = 2; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Used to reference when a registration has been checked in. |
|
| 32 | - * |
|
| 33 | - * @deprecated use \EE_Checkin::status_checked_in instead |
|
| 34 | - * @type int |
|
| 35 | - */ |
|
| 36 | - const checkin_status_in = 1; |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Used to reference when a registration has been checked out. |
|
| 41 | - * |
|
| 42 | - * @deprecated use \EE_Checkin::status_checked_out instead |
|
| 43 | - * @type int |
|
| 44 | - */ |
|
| 45 | - const checkin_status_out = 0; |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * extra meta key for tracking reg status os trashed registrations |
|
| 50 | - * |
|
| 51 | - * @type string |
|
| 52 | - */ |
|
| 53 | - const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * extra meta key for tracking if registration has reserved ticket |
|
| 58 | - * |
|
| 59 | - * @type string |
|
| 60 | - */ |
|
| 61 | - const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param array $props_n_values incoming values |
|
| 66 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 67 | - * used.) |
|
| 68 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 69 | - * date_format and the second value is the time format |
|
| 70 | - * @return EE_Registration |
|
| 71 | - * @throws EE_Error |
|
| 72 | - */ |
|
| 73 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 74 | - { |
|
| 75 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 76 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param array $props_n_values incoming values from the database |
|
| 82 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 83 | - * the website will be used. |
|
| 84 | - * @return EE_Registration |
|
| 85 | - */ |
|
| 86 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 87 | - { |
|
| 88 | - return new self($props_n_values, true, $timezone); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Set Event ID |
|
| 94 | - * |
|
| 95 | - * @param int $EVT_ID Event ID |
|
| 96 | - * @throws EE_Error |
|
| 97 | - * @throws RuntimeException |
|
| 98 | - */ |
|
| 99 | - public function set_event($EVT_ID = 0) |
|
| 100 | - { |
|
| 101 | - $this->set('EVT_ID', $EVT_ID); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can |
|
| 107 | - * be routed to internal methods |
|
| 108 | - * |
|
| 109 | - * @param string $field_name |
|
| 110 | - * @param mixed $field_value |
|
| 111 | - * @param bool $use_default |
|
| 112 | - * @throws EE_Error |
|
| 113 | - * @throws EntityNotFoundException |
|
| 114 | - * @throws InvalidArgumentException |
|
| 115 | - * @throws InvalidDataTypeException |
|
| 116 | - * @throws InvalidInterfaceException |
|
| 117 | - * @throws ReflectionException |
|
| 118 | - * @throws RuntimeException |
|
| 119 | - */ |
|
| 120 | - public function set($field_name, $field_value, $use_default = false) |
|
| 121 | - { |
|
| 122 | - switch ($field_name) { |
|
| 123 | - case 'REG_code': |
|
| 124 | - if (! empty($field_value) && $this->reg_code() === null) { |
|
| 125 | - $this->set_reg_code($field_value, $use_default); |
|
| 126 | - } |
|
| 127 | - break; |
|
| 128 | - case 'STS_ID': |
|
| 129 | - $this->set_status($field_value, $use_default); |
|
| 130 | - break; |
|
| 131 | - default: |
|
| 132 | - parent::set($field_name, $field_value, $use_default); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Set Status ID |
|
| 139 | - * updates the registration status and ALSO... |
|
| 140 | - * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
| 141 | - * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
| 142 | - * |
|
| 143 | - * @param string $new_STS_ID |
|
| 144 | - * @param boolean $use_default |
|
| 145 | - * @param ContextInterface|null $context |
|
| 146 | - * @return bool |
|
| 147 | - * @throws EE_Error |
|
| 148 | - * @throws EntityNotFoundException |
|
| 149 | - * @throws InvalidArgumentException |
|
| 150 | - * @throws ReflectionException |
|
| 151 | - * @throws RuntimeException |
|
| 152 | - * @throws InvalidDataTypeException |
|
| 153 | - * @throws InvalidInterfaceException |
|
| 154 | - */ |
|
| 155 | - public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null) |
|
| 156 | - { |
|
| 157 | - // get current REG_Status |
|
| 158 | - $old_STS_ID = $this->status_ID(); |
|
| 159 | - // if status has changed |
|
| 160 | - if ($old_STS_ID !== $new_STS_ID // and that status has actually changed |
|
| 161 | - && ! empty($old_STS_ID) // and that old status is actually set |
|
| 162 | - && ! empty($new_STS_ID) // as well as the new status |
|
| 163 | - && $this->ID() // ensure registration is in the db |
|
| 164 | - ) { |
|
| 165 | - // TO approved |
|
| 166 | - if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
| 167 | - // reserve a space by incrementing ticket and datetime sold values |
|
| 168 | - $this->_reserve_registration_space(); |
|
| 169 | - do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context); |
|
| 170 | - // OR FROM approved |
|
| 171 | - } elseif ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
| 172 | - // release a space by decrementing ticket and datetime sold values |
|
| 173 | - $this->_release_registration_space(); |
|
| 174 | - do_action( |
|
| 175 | - 'AHEE__EE_Registration__set_status__from_approved', |
|
| 176 | - $this, |
|
| 177 | - $old_STS_ID, |
|
| 178 | - $new_STS_ID, |
|
| 179 | - $context |
|
| 180 | - ); |
|
| 181 | - } |
|
| 182 | - // update status |
|
| 183 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
| 184 | - $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, $context); |
|
| 185 | - if($this->statusChangeUpdatesTransaction($context)) { |
|
| 186 | - $this->updateTransactionAfterStatusChange(); |
|
| 187 | - } |
|
| 188 | - do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context); |
|
| 189 | - return true; |
|
| 190 | - } |
|
| 191 | - //even though the old value matches the new value, it's still good to |
|
| 192 | - //allow the parent set method to have a say |
|
| 193 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
| 194 | - return true; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * update REGs and TXN when cancelled or declined registrations involved |
|
| 200 | - * |
|
| 201 | - * @param string $new_STS_ID |
|
| 202 | - * @param string $old_STS_ID |
|
| 203 | - * @param ContextInterface|null $context |
|
| 204 | - * @throws EE_Error |
|
| 205 | - * @throws InvalidArgumentException |
|
| 206 | - * @throws InvalidDataTypeException |
|
| 207 | - * @throws InvalidInterfaceException |
|
| 208 | - * @throws ReflectionException |
|
| 209 | - */ |
|
| 210 | - private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
| 211 | - { |
|
| 212 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
| 213 | - $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
| 214 | - // true if registration has been cancelled or declined |
|
| 215 | - $this->updateIfCanceled( |
|
| 216 | - $closed_reg_statuses, |
|
| 217 | - $new_STS_ID, |
|
| 218 | - $old_STS_ID, |
|
| 219 | - $context |
|
| 220 | - ); |
|
| 221 | - $this->updateIfDeclined( |
|
| 222 | - $closed_reg_statuses, |
|
| 223 | - $new_STS_ID, |
|
| 224 | - $old_STS_ID, |
|
| 225 | - $context |
|
| 226 | - ); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * update REGs and TXN when cancelled or declined registrations involved |
|
| 232 | - * |
|
| 233 | - * @param array $closed_reg_statuses |
|
| 234 | - * @param string $new_STS_ID |
|
| 235 | - * @param string $old_STS_ID |
|
| 236 | - * @param ContextInterface|null $context |
|
| 237 | - * @throws EE_Error |
|
| 238 | - * @throws InvalidArgumentException |
|
| 239 | - * @throws InvalidDataTypeException |
|
| 240 | - * @throws InvalidInterfaceException |
|
| 241 | - * @throws ReflectionException |
|
| 242 | - */ |
|
| 243 | - private function updateIfCanceled(array $closed_reg_statuses, $new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
| 244 | - { |
|
| 245 | - // true if registration has been cancelled or declined |
|
| 246 | - if (in_array($new_STS_ID, $closed_reg_statuses, true) |
|
| 247 | - && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
| 248 | - ) { |
|
| 249 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 250 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 251 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 252 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 253 | - // cancelled or declined registration |
|
| 254 | - $registration_processor->update_registration_after_being_canceled_or_declined( |
|
| 255 | - $this, |
|
| 256 | - $closed_reg_statuses |
|
| 257 | - ); |
|
| 258 | - $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
| 259 | - $this, |
|
| 260 | - $closed_reg_statuses, |
|
| 261 | - false |
|
| 262 | - ); |
|
| 263 | - do_action( |
|
| 264 | - 'AHEE__EE_Registration__set_status__canceled_or_declined', |
|
| 265 | - $this, |
|
| 266 | - $old_STS_ID, |
|
| 267 | - $new_STS_ID, |
|
| 268 | - $context |
|
| 269 | - ); |
|
| 270 | - return; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * update REGs and TXN when cancelled or declined registrations involved |
|
| 277 | - * |
|
| 278 | - * @param array $closed_reg_statuses |
|
| 279 | - * @param string $new_STS_ID |
|
| 280 | - * @param string $old_STS_ID |
|
| 281 | - * @param ContextInterface|null $context |
|
| 282 | - * @throws EE_Error |
|
| 283 | - * @throws InvalidArgumentException |
|
| 284 | - * @throws InvalidDataTypeException |
|
| 285 | - * @throws InvalidInterfaceException |
|
| 286 | - * @throws ReflectionException |
|
| 287 | - */ |
|
| 288 | - private function updateIfDeclined(array $closed_reg_statuses, $new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
| 289 | - { |
|
| 290 | - // true if reinstating cancelled or declined registration |
|
| 291 | - if (in_array($old_STS_ID, $closed_reg_statuses, true) |
|
| 292 | - && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
| 293 | - ) { |
|
| 294 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 295 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 296 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 297 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 298 | - // reinstating cancelled or declined registration |
|
| 299 | - $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
| 300 | - $this, |
|
| 301 | - $closed_reg_statuses |
|
| 302 | - ); |
|
| 303 | - $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
| 304 | - $this, |
|
| 305 | - $closed_reg_statuses, |
|
| 306 | - false |
|
| 307 | - ); |
|
| 308 | - do_action( |
|
| 309 | - 'AHEE__EE_Registration__set_status__after_reinstated', |
|
| 310 | - $this, |
|
| 311 | - $old_STS_ID, |
|
| 312 | - $new_STS_ID, |
|
| 313 | - $context |
|
| 314 | - ); |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * @param ContextInterface|null $context |
|
| 321 | - * @return bool |
|
| 322 | - */ |
|
| 323 | - private function statusChangeUpdatesTransaction(ContextInterface $context = null) |
|
| 324 | - { |
|
| 325 | - $contexts_that_do_not_update_transaction = (array) apply_filters( |
|
| 326 | - 'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction', |
|
| 327 | - array('spco_reg_step_attendee_information_process_registrations'), |
|
| 328 | - $context, |
|
| 329 | - $this |
|
| 330 | - ); |
|
| 331 | - return ! ( |
|
| 332 | - $context instanceof ContextInterface |
|
| 333 | - && in_array($context->slug(), $contexts_that_do_not_update_transaction, true) |
|
| 334 | - ); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * @throws EE_Error |
|
| 340 | - * @throws EntityNotFoundException |
|
| 341 | - * @throws InvalidArgumentException |
|
| 342 | - * @throws InvalidDataTypeException |
|
| 343 | - * @throws InvalidInterfaceException |
|
| 344 | - * @throws ReflectionException |
|
| 345 | - * @throws RuntimeException |
|
| 346 | - */ |
|
| 347 | - private function updateTransactionAfterStatusChange() |
|
| 348 | - { |
|
| 349 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 350 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 351 | - $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
| 352 | - $this->transaction()->update_status_based_on_total_paid(true); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * get Status ID |
|
| 358 | - */ |
|
| 359 | - public function status_ID() |
|
| 360 | - { |
|
| 361 | - return $this->get('STS_ID'); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Gets the ticket this registration is for |
|
| 367 | - * |
|
| 368 | - * @param boolean $include_archived whether to include archived tickets or not. |
|
| 369 | - * |
|
| 370 | - * @return EE_Ticket|EE_Base_Class |
|
| 371 | - * @throws EE_Error |
|
| 372 | - */ |
|
| 373 | - public function ticket($include_archived = true) |
|
| 374 | - { |
|
| 375 | - $query_params = array(); |
|
| 376 | - if ($include_archived) { |
|
| 377 | - $query_params['default_where_conditions'] = 'none'; |
|
| 378 | - } |
|
| 379 | - return $this->get_first_related('Ticket', $query_params); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Gets the event this registration is for |
|
| 385 | - * |
|
| 386 | - * @return EE_Event |
|
| 387 | - * @throws EE_Error |
|
| 388 | - * @throws EntityNotFoundException |
|
| 389 | - */ |
|
| 390 | - public function event() |
|
| 391 | - { |
|
| 392 | - $event = $this->get_first_related('Event'); |
|
| 393 | - if (! $event instanceof \EE_Event) { |
|
| 394 | - throw new EntityNotFoundException('Event ID', $this->event_ID()); |
|
| 395 | - } |
|
| 396 | - return $event; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond |
|
| 402 | - * with the author of the event this registration is for. |
|
| 403 | - * |
|
| 404 | - * @since 4.5.0 |
|
| 405 | - * @return int |
|
| 406 | - * @throws EE_Error |
|
| 407 | - * @throws EntityNotFoundException |
|
| 408 | - */ |
|
| 409 | - public function wp_user() |
|
| 410 | - { |
|
| 411 | - $event = $this->event(); |
|
| 412 | - if ($event instanceof EE_Event) { |
|
| 413 | - return $event->wp_user(); |
|
| 414 | - } |
|
| 415 | - return 0; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * increments this registration's related ticket sold and corresponding datetime sold values |
|
| 421 | - * |
|
| 422 | - * @return void |
|
| 423 | - * @throws DomainException |
|
| 424 | - * @throws EE_Error |
|
| 425 | - * @throws EntityNotFoundException |
|
| 426 | - * @throws InvalidArgumentException |
|
| 427 | - * @throws InvalidDataTypeException |
|
| 428 | - * @throws InvalidInterfaceException |
|
| 429 | - * @throws ReflectionException |
|
| 430 | - * @throws UnexpectedEntityException |
|
| 431 | - */ |
|
| 432 | - private function _reserve_registration_space() |
|
| 433 | - { |
|
| 434 | - // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
| 435 | - // so stop tracking that this reg has a ticket reserved |
|
| 436 | - $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 437 | - $ticket = $this->ticket(); |
|
| 438 | - $ticket->increase_sold(); |
|
| 439 | - $ticket->save(); |
|
| 440 | - // possibly set event status to sold out |
|
| 441 | - $this->event()->perform_sold_out_status_check(); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
| 447 | - * |
|
| 448 | - * @return void |
|
| 449 | - * @throws DomainException |
|
| 450 | - * @throws EE_Error |
|
| 451 | - * @throws EntityNotFoundException |
|
| 452 | - * @throws InvalidArgumentException |
|
| 453 | - * @throws InvalidDataTypeException |
|
| 454 | - * @throws InvalidInterfaceException |
|
| 455 | - * @throws ReflectionException |
|
| 456 | - * @throws UnexpectedEntityException |
|
| 457 | - */ |
|
| 458 | - private function _release_registration_space() |
|
| 459 | - { |
|
| 460 | - $ticket = $this->ticket(); |
|
| 461 | - $ticket->decrease_sold(); |
|
| 462 | - $ticket->save(); |
|
| 463 | - // possibly change event status from sold out back to previous status |
|
| 464 | - $this->event()->perform_sold_out_status_check(); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * tracks this registration's ticket reservation in extra meta |
|
| 470 | - * and can increment related ticket reserved and corresponding datetime reserved values |
|
| 471 | - * |
|
| 472 | - * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
| 473 | - * @return void |
|
| 474 | - * @throws EE_Error |
|
| 475 | - * @throws InvalidArgumentException |
|
| 476 | - * @throws InvalidDataTypeException |
|
| 477 | - * @throws InvalidInterfaceException |
|
| 478 | - * @throws ReflectionException |
|
| 479 | - */ |
|
| 480 | - public function reserve_ticket($update_ticket = false, $source = 'unknown') |
|
| 481 | - { |
|
| 482 | - // only reserve ticket if space is not currently reserved |
|
| 483 | - if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) { |
|
| 484 | - $this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}"); |
|
| 485 | - // IMPORTANT !!! |
|
| 486 | - // although checking $update_ticket first would be more efficient, |
|
| 487 | - // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
| 488 | - if ( |
|
| 489 | - $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) |
|
| 490 | - && $update_ticket |
|
| 491 | - ) { |
|
| 492 | - $ticket = $this->ticket(); |
|
| 493 | - $ticket->increase_reserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 494 | - $ticket->save(); |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * stops tracking this registration's ticket reservation in extra meta |
|
| 502 | - * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
| 503 | - * |
|
| 504 | - * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
| 505 | - * @return void |
|
| 506 | - * @throws EE_Error |
|
| 507 | - * @throws InvalidArgumentException |
|
| 508 | - * @throws InvalidDataTypeException |
|
| 509 | - * @throws InvalidInterfaceException |
|
| 510 | - * @throws ReflectionException |
|
| 511 | - */ |
|
| 512 | - public function release_reserved_ticket($update_ticket = false, $source = 'unknown') |
|
| 513 | - { |
|
| 514 | - // only release ticket if space is currently reserved |
|
| 515 | - if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) { |
|
| 516 | - $this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}"); |
|
| 517 | - // IMPORTANT !!! |
|
| 518 | - // although checking $update_ticket first would be more efficient, |
|
| 519 | - // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
| 520 | - if ( |
|
| 521 | - $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false) |
|
| 522 | - && $update_ticket |
|
| 523 | - ) { |
|
| 524 | - $ticket = $this->ticket(); |
|
| 525 | - $ticket->decrease_reserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 526 | - $ticket->save(); |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * Set Attendee ID |
|
| 534 | - * |
|
| 535 | - * @param int $ATT_ID Attendee ID |
|
| 536 | - * @throws EE_Error |
|
| 537 | - * @throws RuntimeException |
|
| 538 | - */ |
|
| 539 | - public function set_attendee_id($ATT_ID = 0) |
|
| 540 | - { |
|
| 541 | - $this->set('ATT_ID', $ATT_ID); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * Set Transaction ID |
|
| 547 | - * |
|
| 548 | - * @param int $TXN_ID Transaction ID |
|
| 549 | - * @throws EE_Error |
|
| 550 | - * @throws RuntimeException |
|
| 551 | - */ |
|
| 552 | - public function set_transaction_id($TXN_ID = 0) |
|
| 553 | - { |
|
| 554 | - $this->set('TXN_ID', $TXN_ID); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Set Session |
|
| 560 | - * |
|
| 561 | - * @param string $REG_session PHP Session ID |
|
| 562 | - * @throws EE_Error |
|
| 563 | - * @throws RuntimeException |
|
| 564 | - */ |
|
| 565 | - public function set_session($REG_session = '') |
|
| 566 | - { |
|
| 567 | - $this->set('REG_session', $REG_session); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * Set Registration URL Link |
|
| 573 | - * |
|
| 574 | - * @param string $REG_url_link Registration URL Link |
|
| 575 | - * @throws EE_Error |
|
| 576 | - * @throws RuntimeException |
|
| 577 | - */ |
|
| 578 | - public function set_reg_url_link($REG_url_link = '') |
|
| 579 | - { |
|
| 580 | - $this->set('REG_url_link', $REG_url_link); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * Set Attendee Counter |
|
| 586 | - * |
|
| 587 | - * @param int $REG_count Primary Attendee |
|
| 588 | - * @throws EE_Error |
|
| 589 | - * @throws RuntimeException |
|
| 590 | - */ |
|
| 591 | - public function set_count($REG_count = 1) |
|
| 592 | - { |
|
| 593 | - $this->set('REG_count', $REG_count); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * Set Group Size |
|
| 599 | - * |
|
| 600 | - * @param boolean $REG_group_size Group Registration |
|
| 601 | - * @throws EE_Error |
|
| 602 | - * @throws RuntimeException |
|
| 603 | - */ |
|
| 604 | - public function set_group_size($REG_group_size = false) |
|
| 605 | - { |
|
| 606 | - $this->set('REG_group_size', $REG_group_size); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - |
|
| 610 | - /** |
|
| 611 | - * is_not_approved - convenience method that returns TRUE if REG status ID == |
|
| 612 | - * EEM_Registration::status_id_not_approved |
|
| 613 | - * |
|
| 614 | - * @return boolean |
|
| 615 | - */ |
|
| 616 | - public function is_not_approved() |
|
| 617 | - { |
|
| 618 | - return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * is_pending_payment - convenience method that returns TRUE if REG status ID == |
|
| 624 | - * EEM_Registration::status_id_pending_payment |
|
| 625 | - * |
|
| 626 | - * @return boolean |
|
| 627 | - */ |
|
| 628 | - public function is_pending_payment() |
|
| 629 | - { |
|
| 630 | - return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - |
|
| 634 | - /** |
|
| 635 | - * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved |
|
| 636 | - * |
|
| 637 | - * @return boolean |
|
| 638 | - */ |
|
| 639 | - public function is_approved() |
|
| 640 | - { |
|
| 641 | - return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled |
|
| 647 | - * |
|
| 648 | - * @return boolean |
|
| 649 | - */ |
|
| 650 | - public function is_cancelled() |
|
| 651 | - { |
|
| 652 | - return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined |
|
| 658 | - * |
|
| 659 | - * @return boolean |
|
| 660 | - */ |
|
| 661 | - public function is_declined() |
|
| 662 | - { |
|
| 663 | - return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * is_incomplete - convenience method that returns TRUE if REG status ID == |
|
| 669 | - * EEM_Registration::status_id_incomplete |
|
| 670 | - * |
|
| 671 | - * @return boolean |
|
| 672 | - */ |
|
| 673 | - public function is_incomplete() |
|
| 674 | - { |
|
| 675 | - return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * Set Registration Date |
|
| 681 | - * |
|
| 682 | - * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of |
|
| 683 | - * Date |
|
| 684 | - * @throws EE_Error |
|
| 685 | - * @throws RuntimeException |
|
| 686 | - */ |
|
| 687 | - public function set_reg_date($REG_date = false) |
|
| 688 | - { |
|
| 689 | - $this->set('REG_date', $REG_date); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * Set final price owing for this registration after all ticket/price modifications |
|
| 695 | - * |
|
| 696 | - * @access public |
|
| 697 | - * @param float $REG_final_price |
|
| 698 | - * @throws EE_Error |
|
| 699 | - * @throws RuntimeException |
|
| 700 | - */ |
|
| 701 | - public function set_final_price($REG_final_price = 0.00) |
|
| 702 | - { |
|
| 703 | - $this->set('REG_final_price', $REG_final_price); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * Set amount paid towards this registration's final price |
|
| 709 | - * |
|
| 710 | - * @access public |
|
| 711 | - * @param float $REG_paid |
|
| 712 | - * @throws EE_Error |
|
| 713 | - * @throws RuntimeException |
|
| 714 | - */ |
|
| 715 | - public function set_paid($REG_paid = 0.00) |
|
| 716 | - { |
|
| 717 | - $this->set('REG_paid', $REG_paid); |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - |
|
| 721 | - /** |
|
| 722 | - * Attendee Is Going |
|
| 723 | - * |
|
| 724 | - * @param boolean $REG_att_is_going Attendee Is Going |
|
| 725 | - * @throws EE_Error |
|
| 726 | - * @throws RuntimeException |
|
| 727 | - */ |
|
| 728 | - public function set_att_is_going($REG_att_is_going = false) |
|
| 729 | - { |
|
| 730 | - $this->set('REG_att_is_going', $REG_att_is_going); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - |
|
| 734 | - /** |
|
| 735 | - * Gets the related attendee |
|
| 736 | - * |
|
| 737 | - * @return EE_Attendee |
|
| 738 | - * @throws EE_Error |
|
| 739 | - */ |
|
| 740 | - public function attendee() |
|
| 741 | - { |
|
| 742 | - return $this->get_first_related('Attendee'); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * get Event ID |
|
| 748 | - */ |
|
| 749 | - public function event_ID() |
|
| 750 | - { |
|
| 751 | - return $this->get('EVT_ID'); |
|
| 752 | - } |
|
| 753 | - |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * get Event ID |
|
| 757 | - */ |
|
| 758 | - public function event_name() |
|
| 759 | - { |
|
| 760 | - $event = $this->event_obj(); |
|
| 761 | - if ($event) { |
|
| 762 | - return $event->name(); |
|
| 763 | - } else { |
|
| 764 | - return null; |
|
| 765 | - } |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - |
|
| 769 | - /** |
|
| 770 | - * Fetches the event this registration is for |
|
| 771 | - * |
|
| 772 | - * @return EE_Event |
|
| 773 | - * @throws EE_Error |
|
| 774 | - */ |
|
| 775 | - public function event_obj() |
|
| 776 | - { |
|
| 777 | - return $this->get_first_related('Event'); |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - |
|
| 781 | - /** |
|
| 782 | - * get Attendee ID |
|
| 783 | - */ |
|
| 784 | - public function attendee_ID() |
|
| 785 | - { |
|
| 786 | - return $this->get('ATT_ID'); |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - |
|
| 790 | - /** |
|
| 791 | - * get PHP Session ID |
|
| 792 | - */ |
|
| 793 | - public function session_ID() |
|
| 794 | - { |
|
| 795 | - return $this->get('REG_session'); |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - /** |
|
| 800 | - * Gets the string which represents the URL trigger for the receipt template in the message template system. |
|
| 801 | - * |
|
| 802 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
| 803 | - * @return string |
|
| 804 | - */ |
|
| 805 | - public function receipt_url($messenger = 'html') |
|
| 806 | - { |
|
| 807 | - |
|
| 808 | - /** |
|
| 809 | - * The below will be deprecated one version after this. We check first if there is a custom receipt template |
|
| 810 | - * already in use on old system. If there is then we just return the standard url for it. |
|
| 811 | - * |
|
| 812 | - * @since 4.5.0 |
|
| 813 | - */ |
|
| 814 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
|
| 815 | - $has_custom = EEH_Template::locate_template( |
|
| 816 | - $template_relative_path, |
|
| 817 | - array(), |
|
| 818 | - true, |
|
| 819 | - true, |
|
| 820 | - true |
|
| 821 | - ); |
|
| 822 | - |
|
| 823 | - if ($has_custom) { |
|
| 824 | - return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
| 825 | - } |
|
| 826 | - return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - |
|
| 830 | - /** |
|
| 831 | - * Gets the string which represents the URL trigger for the invoice template in the message template system. |
|
| 832 | - * |
|
| 833 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
| 834 | - * @return string |
|
| 835 | - * @throws EE_Error |
|
| 836 | - */ |
|
| 837 | - public function invoice_url($messenger = 'html') |
|
| 838 | - { |
|
| 839 | - /** |
|
| 840 | - * The below will be deprecated one version after this. We check first if there is a custom invoice template |
|
| 841 | - * already in use on old system. If there is then we just return the standard url for it. |
|
| 842 | - * |
|
| 843 | - * @since 4.5.0 |
|
| 844 | - */ |
|
| 845 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
|
| 846 | - $has_custom = EEH_Template::locate_template( |
|
| 847 | - $template_relative_path, |
|
| 848 | - array(), |
|
| 849 | - true, |
|
| 850 | - true, |
|
| 851 | - true |
|
| 852 | - ); |
|
| 853 | - |
|
| 854 | - if ($has_custom) { |
|
| 855 | - if ($messenger == 'html') { |
|
| 856 | - return $this->invoice_url('launch'); |
|
| 857 | - } |
|
| 858 | - $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
|
| 859 | - |
|
| 860 | - $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
| 861 | - if ($messenger == 'html') { |
|
| 862 | - $query_args['html'] = true; |
|
| 863 | - } |
|
| 864 | - return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
| 865 | - } |
|
| 866 | - return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * get Registration URL Link |
|
| 872 | - * |
|
| 873 | - * @access public |
|
| 874 | - * @return string |
|
| 875 | - * @throws EE_Error |
|
| 876 | - */ |
|
| 877 | - public function reg_url_link() |
|
| 878 | - { |
|
| 879 | - return (string) $this->get('REG_url_link'); |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - |
|
| 883 | - /** |
|
| 884 | - * Echoes out invoice_url() |
|
| 885 | - * |
|
| 886 | - * @param string $type 'download','launch', or 'html' (default is 'launch') |
|
| 887 | - * @return void |
|
| 888 | - * @throws EE_Error |
|
| 889 | - */ |
|
| 890 | - public function e_invoice_url($type = 'launch') |
|
| 891 | - { |
|
| 892 | - echo $this->invoice_url($type); |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - |
|
| 896 | - /** |
|
| 897 | - * Echoes out payment_overview_url |
|
| 898 | - */ |
|
| 899 | - public function e_payment_overview_url() |
|
| 900 | - { |
|
| 901 | - echo $this->payment_overview_url(); |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - |
|
| 905 | - /** |
|
| 906 | - * Gets the URL for the checkout payment options reg step |
|
| 907 | - * with this registration's REG_url_link added as a query parameter |
|
| 908 | - * |
|
| 909 | - * @param bool $clear_session Set to true when you want to clear the session on revisiting the |
|
| 910 | - * payment overview url. |
|
| 911 | - * @return string |
|
| 912 | - * @throws InvalidInterfaceException |
|
| 913 | - * @throws InvalidDataTypeException |
|
| 914 | - * @throws EE_Error |
|
| 915 | - * @throws InvalidArgumentException |
|
| 916 | - */ |
|
| 917 | - public function payment_overview_url($clear_session = false) |
|
| 918 | - { |
|
| 919 | - return add_query_arg( |
|
| 920 | - (array) apply_filters( |
|
| 921 | - 'FHEE__EE_Registration__payment_overview_url__query_args', |
|
| 922 | - array( |
|
| 923 | - 'e_reg_url_link' => $this->reg_url_link(), |
|
| 924 | - 'step' => 'payment_options', |
|
| 925 | - 'revisit' => true, |
|
| 926 | - 'clear_session' => (bool) $clear_session, |
|
| 927 | - ), |
|
| 928 | - $this |
|
| 929 | - ), |
|
| 930 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 931 | - ); |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - |
|
| 935 | - /** |
|
| 936 | - * Gets the URL for the checkout attendee information reg step |
|
| 937 | - * with this registration's REG_url_link added as a query parameter |
|
| 938 | - * |
|
| 939 | - * @return string |
|
| 940 | - * @throws InvalidInterfaceException |
|
| 941 | - * @throws InvalidDataTypeException |
|
| 942 | - * @throws EE_Error |
|
| 943 | - * @throws InvalidArgumentException |
|
| 944 | - */ |
|
| 945 | - public function edit_attendee_information_url() |
|
| 946 | - { |
|
| 947 | - return add_query_arg( |
|
| 948 | - (array) apply_filters( |
|
| 949 | - 'FHEE__EE_Registration__edit_attendee_information_url__query_args', |
|
| 950 | - array( |
|
| 951 | - 'e_reg_url_link' => $this->reg_url_link(), |
|
| 952 | - 'step' => 'attendee_information', |
|
| 953 | - 'revisit' => true, |
|
| 954 | - ), |
|
| 955 | - $this |
|
| 956 | - ), |
|
| 957 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 958 | - ); |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - |
|
| 962 | - /** |
|
| 963 | - * Simply generates and returns the appropriate admin_url link to edit this registration |
|
| 964 | - * |
|
| 965 | - * @return string |
|
| 966 | - * @throws EE_Error |
|
| 967 | - */ |
|
| 968 | - public function get_admin_edit_url() |
|
| 969 | - { |
|
| 970 | - return EEH_URL::add_query_args_and_nonce(array( |
|
| 971 | - 'page' => 'espresso_registrations', |
|
| 972 | - 'action' => 'view_registration', |
|
| 973 | - '_REG_ID' => $this->ID(), |
|
| 974 | - ), admin_url('admin.php')); |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - /** |
|
| 979 | - * is_primary_registrant? |
|
| 980 | - */ |
|
| 981 | - public function is_primary_registrant() |
|
| 982 | - { |
|
| 983 | - return $this->get('REG_count') == 1 ? true : false; |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - |
|
| 987 | - /** |
|
| 988 | - * This returns the primary registration object for this registration group (which may be this object). |
|
| 989 | - * |
|
| 990 | - * @return EE_Registration |
|
| 991 | - * @throws EE_Error |
|
| 992 | - */ |
|
| 993 | - public function get_primary_registration() |
|
| 994 | - { |
|
| 995 | - if ($this->is_primary_registrant()) { |
|
| 996 | - return $this; |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
|
| 1000 | - /** @var EE_Registration $primary_registrant */ |
|
| 1001 | - $primary_registrant = EEM_Registration::instance()->get_one(array( |
|
| 1002 | - array( |
|
| 1003 | - 'TXN_ID' => $this->transaction_ID(), |
|
| 1004 | - 'REG_count' => 1, |
|
| 1005 | - ), |
|
| 1006 | - )); |
|
| 1007 | - return $primary_registrant; |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - /** |
|
| 1012 | - * get Attendee Number |
|
| 1013 | - * |
|
| 1014 | - * @access public |
|
| 1015 | - */ |
|
| 1016 | - public function count() |
|
| 1017 | - { |
|
| 1018 | - return $this->get('REG_count'); |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - |
|
| 1022 | - /** |
|
| 1023 | - * get Group Size |
|
| 1024 | - */ |
|
| 1025 | - public function group_size() |
|
| 1026 | - { |
|
| 1027 | - return $this->get('REG_group_size'); |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - |
|
| 1031 | - /** |
|
| 1032 | - * get Registration Date |
|
| 1033 | - */ |
|
| 1034 | - public function date() |
|
| 1035 | - { |
|
| 1036 | - return $this->get('REG_date'); |
|
| 1037 | - } |
|
| 1038 | - |
|
| 1039 | - |
|
| 1040 | - /** |
|
| 1041 | - * gets a pretty date |
|
| 1042 | - * |
|
| 1043 | - * @param string $date_format |
|
| 1044 | - * @param string $time_format |
|
| 1045 | - * @return string |
|
| 1046 | - * @throws EE_Error |
|
| 1047 | - */ |
|
| 1048 | - public function pretty_date($date_format = null, $time_format = null) |
|
| 1049 | - { |
|
| 1050 | - return $this->get_datetime('REG_date', $date_format, $time_format); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - |
|
| 1054 | - /** |
|
| 1055 | - * final_price |
|
| 1056 | - * the registration's share of the transaction total, so that the |
|
| 1057 | - * sum of all the transaction's REG_final_prices equal the transaction's total |
|
| 1058 | - * |
|
| 1059 | - * @return float |
|
| 1060 | - * @throws EE_Error |
|
| 1061 | - */ |
|
| 1062 | - public function final_price() |
|
| 1063 | - { |
|
| 1064 | - return $this->get('REG_final_price'); |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - |
|
| 1068 | - /** |
|
| 1069 | - * pretty_final_price |
|
| 1070 | - * final price as formatted string, with correct decimal places and currency symbol |
|
| 1071 | - * |
|
| 1072 | - * @return string |
|
| 1073 | - * @throws EE_Error |
|
| 1074 | - */ |
|
| 1075 | - public function pretty_final_price() |
|
| 1076 | - { |
|
| 1077 | - return $this->get_pretty('REG_final_price'); |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - |
|
| 1081 | - /** |
|
| 1082 | - * get paid (yeah) |
|
| 1083 | - * |
|
| 1084 | - * @return float |
|
| 1085 | - * @throws EE_Error |
|
| 1086 | - */ |
|
| 1087 | - public function paid() |
|
| 1088 | - { |
|
| 1089 | - return $this->get('REG_paid'); |
|
| 1090 | - } |
|
| 1091 | - |
|
| 1092 | - |
|
| 1093 | - /** |
|
| 1094 | - * pretty_paid |
|
| 1095 | - * |
|
| 1096 | - * @return float |
|
| 1097 | - * @throws EE_Error |
|
| 1098 | - */ |
|
| 1099 | - public function pretty_paid() |
|
| 1100 | - { |
|
| 1101 | - return $this->get_pretty('REG_paid'); |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * owes_monies_and_can_pay |
|
| 1107 | - * whether or not this registration has monies owing and it's' status allows payment |
|
| 1108 | - * |
|
| 1109 | - * @param array $requires_payment |
|
| 1110 | - * @return bool |
|
| 1111 | - * @throws EE_Error |
|
| 1112 | - */ |
|
| 1113 | - public function owes_monies_and_can_pay($requires_payment = array()) |
|
| 1114 | - { |
|
| 1115 | - // these reg statuses require payment (if event is not free) |
|
| 1116 | - $requires_payment = ! empty($requires_payment) |
|
| 1117 | - ? $requires_payment |
|
| 1118 | - : EEM_Registration::reg_statuses_that_allow_payment(); |
|
| 1119 | - if (in_array($this->status_ID(), $requires_payment) && |
|
| 1120 | - $this->final_price() != 0 && |
|
| 1121 | - $this->final_price() != $this->paid() |
|
| 1122 | - ) { |
|
| 1123 | - return true; |
|
| 1124 | - } else { |
|
| 1125 | - return false; |
|
| 1126 | - } |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - |
|
| 1130 | - /** |
|
| 1131 | - * Prints out the return value of $this->pretty_status() |
|
| 1132 | - * |
|
| 1133 | - * @param bool $show_icons |
|
| 1134 | - * @return void |
|
| 1135 | - * @throws EE_Error |
|
| 1136 | - */ |
|
| 1137 | - public function e_pretty_status($show_icons = false) |
|
| 1138 | - { |
|
| 1139 | - echo $this->pretty_status($show_icons); |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - |
|
| 1143 | - /** |
|
| 1144 | - * Returns a nice version of the status for displaying to customers |
|
| 1145 | - * |
|
| 1146 | - * @param bool $show_icons |
|
| 1147 | - * @return string |
|
| 1148 | - * @throws EE_Error |
|
| 1149 | - */ |
|
| 1150 | - public function pretty_status($show_icons = false) |
|
| 1151 | - { |
|
| 1152 | - $status = EEM_Status::instance()->localized_status( |
|
| 1153 | - array($this->status_ID() => esc_html__('unknown', 'event_espresso')), |
|
| 1154 | - false, |
|
| 1155 | - 'sentence' |
|
| 1156 | - ); |
|
| 1157 | - $icon = ''; |
|
| 1158 | - switch ($this->status_ID()) { |
|
| 1159 | - case EEM_Registration::status_id_approved: |
|
| 1160 | - $icon = $show_icons |
|
| 1161 | - ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' |
|
| 1162 | - : ''; |
|
| 1163 | - break; |
|
| 1164 | - case EEM_Registration::status_id_pending_payment: |
|
| 1165 | - $icon = $show_icons |
|
| 1166 | - ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' |
|
| 1167 | - : ''; |
|
| 1168 | - break; |
|
| 1169 | - case EEM_Registration::status_id_not_approved: |
|
| 1170 | - $icon = $show_icons |
|
| 1171 | - ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' |
|
| 1172 | - : ''; |
|
| 1173 | - break; |
|
| 1174 | - case EEM_Registration::status_id_cancelled: |
|
| 1175 | - $icon = $show_icons |
|
| 1176 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
| 1177 | - : ''; |
|
| 1178 | - break; |
|
| 1179 | - case EEM_Registration::status_id_incomplete: |
|
| 1180 | - $icon = $show_icons |
|
| 1181 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' |
|
| 1182 | - : ''; |
|
| 1183 | - break; |
|
| 1184 | - case EEM_Registration::status_id_declined: |
|
| 1185 | - $icon = $show_icons |
|
| 1186 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
| 1187 | - : ''; |
|
| 1188 | - break; |
|
| 1189 | - case EEM_Registration::status_id_wait_list: |
|
| 1190 | - $icon = $show_icons |
|
| 1191 | - ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' |
|
| 1192 | - : ''; |
|
| 1193 | - break; |
|
| 1194 | - } |
|
| 1195 | - return $icon . $status[$this->status_ID()]; |
|
| 1196 | - } |
|
| 1197 | - |
|
| 1198 | - |
|
| 1199 | - /** |
|
| 1200 | - * get Attendee Is Going |
|
| 1201 | - */ |
|
| 1202 | - public function att_is_going() |
|
| 1203 | - { |
|
| 1204 | - return $this->get('REG_att_is_going'); |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - |
|
| 1208 | - /** |
|
| 1209 | - * Gets related answers |
|
| 1210 | - * |
|
| 1211 | - * @param array $query_params like EEM_Base::get_all |
|
| 1212 | - * @return EE_Answer[] |
|
| 1213 | - * @throws EE_Error |
|
| 1214 | - */ |
|
| 1215 | - public function answers($query_params = null) |
|
| 1216 | - { |
|
| 1217 | - return $this->get_many_related('Answer', $query_params); |
|
| 1218 | - } |
|
| 1219 | - |
|
| 1220 | - |
|
| 1221 | - /** |
|
| 1222 | - * Gets the registration's answer value to the specified question |
|
| 1223 | - * (either the question's ID or a question object) |
|
| 1224 | - * |
|
| 1225 | - * @param EE_Question|int $question |
|
| 1226 | - * @param bool $pretty_value |
|
| 1227 | - * @return array|string if pretty_value= true, the result will always be a string |
|
| 1228 | - * (because the answer might be an array of answer values, so passing pretty_value=true |
|
| 1229 | - * will convert it into some kind of string) |
|
| 1230 | - * @throws EE_Error |
|
| 1231 | - */ |
|
| 1232 | - public function answer_value_to_question($question, $pretty_value = true) |
|
| 1233 | - { |
|
| 1234 | - $question_id = EEM_Question::instance()->ensure_is_ID($question); |
|
| 1235 | - return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - |
|
| 1239 | - /** |
|
| 1240 | - * question_groups |
|
| 1241 | - * returns an array of EE_Question_Group objects for this registration |
|
| 1242 | - * |
|
| 1243 | - * @return EE_Question_Group[] |
|
| 1244 | - * @throws EE_Error |
|
| 1245 | - * @throws EntityNotFoundException |
|
| 1246 | - */ |
|
| 1247 | - public function question_groups() |
|
| 1248 | - { |
|
| 1249 | - $question_groups = array(); |
|
| 1250 | - if ($this->event() instanceof EE_Event) { |
|
| 1251 | - $question_groups = $this->event()->question_groups( |
|
| 1252 | - array( |
|
| 1253 | - array( |
|
| 1254 | - 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
| 1255 | - ), |
|
| 1256 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
| 1257 | - ) |
|
| 1258 | - ); |
|
| 1259 | - } |
|
| 1260 | - return $question_groups; |
|
| 1261 | - } |
|
| 1262 | - |
|
| 1263 | - |
|
| 1264 | - /** |
|
| 1265 | - * count_question_groups |
|
| 1266 | - * returns a count of the number of EE_Question_Group objects for this registration |
|
| 1267 | - * |
|
| 1268 | - * @return int |
|
| 1269 | - * @throws EE_Error |
|
| 1270 | - * @throws EntityNotFoundException |
|
| 1271 | - */ |
|
| 1272 | - public function count_question_groups() |
|
| 1273 | - { |
|
| 1274 | - $qg_count = 0; |
|
| 1275 | - if ($this->event() instanceof EE_Event) { |
|
| 1276 | - $qg_count = $this->event()->count_related( |
|
| 1277 | - 'Question_Group', |
|
| 1278 | - array( |
|
| 1279 | - array( |
|
| 1280 | - 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
| 1281 | - ), |
|
| 1282 | - ) |
|
| 1283 | - ); |
|
| 1284 | - } |
|
| 1285 | - return $qg_count; |
|
| 1286 | - } |
|
| 1287 | - |
|
| 1288 | - |
|
| 1289 | - /** |
|
| 1290 | - * Returns the registration date in the 'standard' string format |
|
| 1291 | - * (function may be improved in the future to allow for different formats and timezones) |
|
| 1292 | - * |
|
| 1293 | - * @return string |
|
| 1294 | - * @throws EE_Error |
|
| 1295 | - */ |
|
| 1296 | - public function reg_date() |
|
| 1297 | - { |
|
| 1298 | - return $this->get_datetime('REG_date'); |
|
| 1299 | - } |
|
| 1300 | - |
|
| 1301 | - |
|
| 1302 | - /** |
|
| 1303 | - * Gets the datetime-ticket for this registration (ie, it can be used to isolate |
|
| 1304 | - * the ticket this registration purchased, or the datetime they have registered |
|
| 1305 | - * to attend) |
|
| 1306 | - * |
|
| 1307 | - * @return EE_Datetime_Ticket |
|
| 1308 | - * @throws EE_Error |
|
| 1309 | - */ |
|
| 1310 | - public function datetime_ticket() |
|
| 1311 | - { |
|
| 1312 | - return $this->get_first_related('Datetime_Ticket'); |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - |
|
| 1316 | - /** |
|
| 1317 | - * Sets the registration's datetime_ticket. |
|
| 1318 | - * |
|
| 1319 | - * @param EE_Datetime_Ticket $datetime_ticket |
|
| 1320 | - * @return EE_Datetime_Ticket |
|
| 1321 | - * @throws EE_Error |
|
| 1322 | - */ |
|
| 1323 | - public function set_datetime_ticket($datetime_ticket) |
|
| 1324 | - { |
|
| 1325 | - return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
| 1326 | - } |
|
| 1327 | - |
|
| 1328 | - /** |
|
| 1329 | - * Gets deleted |
|
| 1330 | - * |
|
| 1331 | - * @return bool |
|
| 1332 | - * @throws EE_Error |
|
| 1333 | - */ |
|
| 1334 | - public function deleted() |
|
| 1335 | - { |
|
| 1336 | - return $this->get('REG_deleted'); |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - /** |
|
| 1340 | - * Sets deleted |
|
| 1341 | - * |
|
| 1342 | - * @param boolean $deleted |
|
| 1343 | - * @return bool |
|
| 1344 | - * @throws EE_Error |
|
| 1345 | - * @throws RuntimeException |
|
| 1346 | - */ |
|
| 1347 | - public function set_deleted($deleted) |
|
| 1348 | - { |
|
| 1349 | - if ($deleted) { |
|
| 1350 | - $this->delete(); |
|
| 1351 | - } else { |
|
| 1352 | - $this->restore(); |
|
| 1353 | - } |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - |
|
| 1357 | - /** |
|
| 1358 | - * Get the status object of this object |
|
| 1359 | - * |
|
| 1360 | - * @return EE_Status |
|
| 1361 | - * @throws EE_Error |
|
| 1362 | - */ |
|
| 1363 | - public function status_obj() |
|
| 1364 | - { |
|
| 1365 | - return $this->get_first_related('Status'); |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - /** |
|
| 1370 | - * Returns the number of times this registration has checked into any of the datetimes |
|
| 1371 | - * its available for |
|
| 1372 | - * |
|
| 1373 | - * @return int |
|
| 1374 | - * @throws EE_Error |
|
| 1375 | - */ |
|
| 1376 | - public function count_checkins() |
|
| 1377 | - { |
|
| 1378 | - return $this->get_model()->count_related($this, 'Checkin'); |
|
| 1379 | - } |
|
| 1380 | - |
|
| 1381 | - |
|
| 1382 | - /** |
|
| 1383 | - * Returns the number of current Check-ins this registration is checked into for any of the datetimes the |
|
| 1384 | - * registration is for. Note, this is ONLY checked in (does not include checkedout) |
|
| 1385 | - * |
|
| 1386 | - * @return int |
|
| 1387 | - * @throws EE_Error |
|
| 1388 | - */ |
|
| 1389 | - public function count_checkins_not_checkedout() |
|
| 1390 | - { |
|
| 1391 | - return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
| 1392 | - } |
|
| 1393 | - |
|
| 1394 | - |
|
| 1395 | - /** |
|
| 1396 | - * The purpose of this method is simply to check whether this registration can checkin to the given datetime. |
|
| 1397 | - * |
|
| 1398 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
| 1399 | - * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
|
| 1400 | - * consider registration status as well as datetime access. |
|
| 1401 | - * @return bool |
|
| 1402 | - * @throws EE_Error |
|
| 1403 | - */ |
|
| 1404 | - public function can_checkin($DTT_OR_ID, $check_approved = true) |
|
| 1405 | - { |
|
| 1406 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
| 1407 | - |
|
| 1408 | - //first check registration status |
|
| 1409 | - if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
| 1410 | - return false; |
|
| 1411 | - } |
|
| 1412 | - //is there a datetime ticket that matches this dtt_ID? |
|
| 1413 | - if (! (EEM_Datetime_Ticket::instance()->exists(array( |
|
| 1414 | - array( |
|
| 1415 | - 'TKT_ID' => $this->get('TKT_ID'), |
|
| 1416 | - 'DTT_ID' => $DTT_ID, |
|
| 1417 | - ), |
|
| 1418 | - ))) |
|
| 1419 | - ) { |
|
| 1420 | - return false; |
|
| 1421 | - } |
|
| 1422 | - |
|
| 1423 | - //final check is against TKT_uses |
|
| 1424 | - return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
| 1425 | - } |
|
| 1426 | - |
|
| 1427 | - |
|
| 1428 | - /** |
|
| 1429 | - * This method verifies whether the user can checkin for the given datetime considering the max uses value set on |
|
| 1430 | - * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the |
|
| 1431 | - * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, |
|
| 1432 | - * then return false. Otherwise return true. |
|
| 1433 | - * |
|
| 1434 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
| 1435 | - * @return bool true means can checkin. false means cannot checkin. |
|
| 1436 | - * @throws EE_Error |
|
| 1437 | - */ |
|
| 1438 | - public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) |
|
| 1439 | - { |
|
| 1440 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
| 1441 | - |
|
| 1442 | - if (! $DTT_ID) { |
|
| 1443 | - return false; |
|
| 1444 | - } |
|
| 1445 | - |
|
| 1446 | - $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; |
|
| 1447 | - |
|
| 1448 | - // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
|
| 1449 | - // check-in or not. |
|
| 1450 | - if (! $max_uses || $max_uses === EE_INF) { |
|
| 1451 | - return true; |
|
| 1452 | - } |
|
| 1453 | - |
|
| 1454 | - //does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
|
| 1455 | - //go ahead and toggle. |
|
| 1456 | - if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
| 1457 | - return true; |
|
| 1458 | - } |
|
| 1459 | - |
|
| 1460 | - //made it here so the last check is whether the number of checkins per unique datetime on this registration |
|
| 1461 | - //disallows further check-ins. |
|
| 1462 | - $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array( |
|
| 1463 | - array( |
|
| 1464 | - 'REG_ID' => $this->ID(), |
|
| 1465 | - 'CHK_in' => true, |
|
| 1466 | - ), |
|
| 1467 | - ), 'DTT_ID', true); |
|
| 1468 | - // checkins have already reached their max number of uses |
|
| 1469 | - // so registrant can NOT checkin |
|
| 1470 | - if ($count_unique_dtt_checkins >= $max_uses) { |
|
| 1471 | - EE_Error::add_error( |
|
| 1472 | - esc_html__( |
|
| 1473 | - 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', |
|
| 1474 | - 'event_espresso' |
|
| 1475 | - ), |
|
| 1476 | - __FILE__, |
|
| 1477 | - __FUNCTION__, |
|
| 1478 | - __LINE__ |
|
| 1479 | - ); |
|
| 1480 | - return false; |
|
| 1481 | - } |
|
| 1482 | - return true; |
|
| 1483 | - } |
|
| 1484 | - |
|
| 1485 | - |
|
| 1486 | - /** |
|
| 1487 | - * toggle Check-in status for this registration |
|
| 1488 | - * Check-ins are toggled in the following order: |
|
| 1489 | - * never checked in -> checked in |
|
| 1490 | - * checked in -> checked out |
|
| 1491 | - * checked out -> checked in |
|
| 1492 | - * |
|
| 1493 | - * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
| 1494 | - * If not included or null, then it is assumed latest datetime is being toggled. |
|
| 1495 | - * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
| 1496 | - * can be checked in or not. Otherwise this forces change in checkin status. |
|
| 1497 | - * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
| 1498 | - * @throws EE_Error |
|
| 1499 | - */ |
|
| 1500 | - public function toggle_checkin_status($DTT_ID = null, $verify = false) |
|
| 1501 | - { |
|
| 1502 | - if (empty($DTT_ID)) { |
|
| 1503 | - $datetime = $this->get_latest_related_datetime(); |
|
| 1504 | - $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
|
| 1505 | - // verify the registration can checkin for the given DTT_ID |
|
| 1506 | - } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
| 1507 | - EE_Error::add_error( |
|
| 1508 | - sprintf( |
|
| 1509 | - esc_html__( |
|
| 1510 | - 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
|
| 1511 | - 'event_espresso' |
|
| 1512 | - ), |
|
| 1513 | - $this->ID(), |
|
| 1514 | - $DTT_ID |
|
| 1515 | - ), |
|
| 1516 | - __FILE__, |
|
| 1517 | - __FUNCTION__, |
|
| 1518 | - __LINE__ |
|
| 1519 | - ); |
|
| 1520 | - return false; |
|
| 1521 | - } |
|
| 1522 | - $status_paths = array( |
|
| 1523 | - EE_Checkin::status_checked_never => EE_Checkin::status_checked_in, |
|
| 1524 | - EE_Checkin::status_checked_in => EE_Checkin::status_checked_out, |
|
| 1525 | - EE_Checkin::status_checked_out => EE_Checkin::status_checked_in, |
|
| 1526 | - ); |
|
| 1527 | - //start by getting the current status so we know what status we'll be changing to. |
|
| 1528 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
|
| 1529 | - $status_to = $status_paths[$cur_status]; |
|
| 1530 | - // database only records true for checked IN or false for checked OUT |
|
| 1531 | - // no record ( null ) means checked in NEVER, but we obviously don't save that |
|
| 1532 | - $new_status = $status_to === EE_Checkin::status_checked_in ? true : false; |
|
| 1533 | - // add relation - note Check-ins are always creating new rows |
|
| 1534 | - // because we are keeping track of Check-ins over time. |
|
| 1535 | - // Eventually we'll probably want to show a list table |
|
| 1536 | - // for the individual Check-ins so that they can be managed. |
|
| 1537 | - $checkin = EE_Checkin::new_instance(array( |
|
| 1538 | - 'REG_ID' => $this->ID(), |
|
| 1539 | - 'DTT_ID' => $DTT_ID, |
|
| 1540 | - 'CHK_in' => $new_status, |
|
| 1541 | - )); |
|
| 1542 | - // if the record could not be saved then return false |
|
| 1543 | - if ($checkin->save() === 0) { |
|
| 1544 | - if (WP_DEBUG) { |
|
| 1545 | - global $wpdb; |
|
| 1546 | - $error = sprintf( |
|
| 1547 | - esc_html__( |
|
| 1548 | - 'Registration check in update failed because of the following database error: %1$s%2$s', |
|
| 1549 | - 'event_espresso' |
|
| 1550 | - ), |
|
| 1551 | - '<br />', |
|
| 1552 | - $wpdb->last_error |
|
| 1553 | - ); |
|
| 1554 | - } else { |
|
| 1555 | - $error = esc_html__( |
|
| 1556 | - 'Registration check in update failed because of an unknown database error', |
|
| 1557 | - 'event_espresso' |
|
| 1558 | - ); |
|
| 1559 | - } |
|
| 1560 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 1561 | - return false; |
|
| 1562 | - } |
|
| 1563 | - return $status_to; |
|
| 1564 | - } |
|
| 1565 | - |
|
| 1566 | - |
|
| 1567 | - /** |
|
| 1568 | - * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
| 1569 | - * "Latest" is defined by the `DTT_EVT_start` column. |
|
| 1570 | - * |
|
| 1571 | - * @return EE_Datetime|null |
|
| 1572 | - * @throws EE_Error |
|
| 1573 | - */ |
|
| 1574 | - public function get_latest_related_datetime() |
|
| 1575 | - { |
|
| 1576 | - return EEM_Datetime::instance()->get_one( |
|
| 1577 | - array( |
|
| 1578 | - array( |
|
| 1579 | - 'Ticket.Registration.REG_ID' => $this->ID(), |
|
| 1580 | - ), |
|
| 1581 | - 'order_by' => array('DTT_EVT_start' => 'DESC'), |
|
| 1582 | - ) |
|
| 1583 | - ); |
|
| 1584 | - } |
|
| 1585 | - |
|
| 1586 | - |
|
| 1587 | - /** |
|
| 1588 | - * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
| 1589 | - * "Earliest" is defined by the `DTT_EVT_start` column. |
|
| 1590 | - * |
|
| 1591 | - * @throws EE_Error |
|
| 1592 | - */ |
|
| 1593 | - public function get_earliest_related_datetime() |
|
| 1594 | - { |
|
| 1595 | - return EEM_Datetime::instance()->get_one( |
|
| 1596 | - array( |
|
| 1597 | - array( |
|
| 1598 | - 'Ticket.Registration.REG_ID' => $this->ID(), |
|
| 1599 | - ), |
|
| 1600 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 1601 | - ) |
|
| 1602 | - ); |
|
| 1603 | - } |
|
| 1604 | - |
|
| 1605 | - |
|
| 1606 | - /** |
|
| 1607 | - * This method simply returns the check-in status for this registration and the given datetime. |
|
| 1608 | - * If neither the datetime nor the checkin values are provided as arguments, |
|
| 1609 | - * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
| 1610 | - * |
|
| 1611 | - * @param int $DTT_ID The ID of the datetime we're checking against |
|
| 1612 | - * (if empty we'll get the primary datetime for |
|
| 1613 | - * this registration (via event) and use it's ID); |
|
| 1614 | - * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
| 1615 | - * |
|
| 1616 | - * @return int Integer representing Check-in status. |
|
| 1617 | - * @throws EE_Error |
|
| 1618 | - */ |
|
| 1619 | - public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) |
|
| 1620 | - { |
|
| 1621 | - $checkin_query_params = array( |
|
| 1622 | - 'order_by' => array('CHK_timestamp' => 'DESC'), |
|
| 1623 | - ); |
|
| 1624 | - |
|
| 1625 | - if ($DTT_ID > 0) { |
|
| 1626 | - $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
| 1627 | - } |
|
| 1628 | - |
|
| 1629 | - //get checkin object (if exists) |
|
| 1630 | - $checkin = $checkin instanceof EE_Checkin |
|
| 1631 | - ? $checkin |
|
| 1632 | - : $this->get_first_related('Checkin', $checkin_query_params); |
|
| 1633 | - if ($checkin instanceof EE_Checkin) { |
|
| 1634 | - if ($checkin->get('CHK_in')) { |
|
| 1635 | - return EE_Checkin::status_checked_in; //checked in |
|
| 1636 | - } |
|
| 1637 | - return EE_Checkin::status_checked_out; //had checked in but is now checked out. |
|
| 1638 | - } |
|
| 1639 | - return EE_Checkin::status_checked_never; //never been checked in |
|
| 1640 | - } |
|
| 1641 | - |
|
| 1642 | - |
|
| 1643 | - /** |
|
| 1644 | - * This method returns a localized message for the toggled Check-in message. |
|
| 1645 | - * |
|
| 1646 | - * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, |
|
| 1647 | - * then it is assumed Check-in for primary datetime was toggled. |
|
| 1648 | - * @param bool $error This just flags that you want an error message returned. This is put in so that the error |
|
| 1649 | - * message can be customized with the attendee name. |
|
| 1650 | - * @return string internationalized message |
|
| 1651 | - * @throws EE_Error |
|
| 1652 | - */ |
|
| 1653 | - public function get_checkin_msg($DTT_ID, $error = false) |
|
| 1654 | - { |
|
| 1655 | - //let's get the attendee first so we can include the name of the attendee |
|
| 1656 | - $attendee = $this->get_first_related('Attendee'); |
|
| 1657 | - if ($attendee instanceof EE_Attendee) { |
|
| 1658 | - if ($error) { |
|
| 1659 | - return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
| 1660 | - } |
|
| 1661 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
| 1662 | - //what is the status message going to be? |
|
| 1663 | - switch ($cur_status) { |
|
| 1664 | - case EE_Checkin::status_checked_never: |
|
| 1665 | - return sprintf(__("%s has been removed from Check-in records", "event_espresso"), |
|
| 1666 | - $attendee->full_name()); |
|
| 1667 | - break; |
|
| 1668 | - case EE_Checkin::status_checked_in: |
|
| 1669 | - return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
| 1670 | - break; |
|
| 1671 | - case EE_Checkin::status_checked_out: |
|
| 1672 | - return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
| 1673 | - break; |
|
| 1674 | - } |
|
| 1675 | - } |
|
| 1676 | - return esc_html__("The check-in status could not be determined.", "event_espresso"); |
|
| 1677 | - } |
|
| 1678 | - |
|
| 1679 | - |
|
| 1680 | - /** |
|
| 1681 | - * Returns the related EE_Transaction to this registration |
|
| 1682 | - * |
|
| 1683 | - * @return EE_Transaction |
|
| 1684 | - * @throws EE_Error |
|
| 1685 | - * @throws EntityNotFoundException |
|
| 1686 | - */ |
|
| 1687 | - public function transaction() |
|
| 1688 | - { |
|
| 1689 | - $transaction = $this->get_first_related('Transaction'); |
|
| 1690 | - if (! $transaction instanceof \EE_Transaction) { |
|
| 1691 | - throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
|
| 1692 | - } |
|
| 1693 | - return $transaction; |
|
| 1694 | - } |
|
| 1695 | - |
|
| 1696 | - |
|
| 1697 | - /** |
|
| 1698 | - * get Registration Code |
|
| 1699 | - */ |
|
| 1700 | - public function reg_code() |
|
| 1701 | - { |
|
| 1702 | - return $this->get('REG_code'); |
|
| 1703 | - } |
|
| 1704 | - |
|
| 1705 | - |
|
| 1706 | - /** |
|
| 1707 | - * get Transaction ID |
|
| 1708 | - */ |
|
| 1709 | - public function transaction_ID() |
|
| 1710 | - { |
|
| 1711 | - return $this->get('TXN_ID'); |
|
| 1712 | - } |
|
| 1713 | - |
|
| 1714 | - |
|
| 1715 | - /** |
|
| 1716 | - * @return int |
|
| 1717 | - * @throws EE_Error |
|
| 1718 | - */ |
|
| 1719 | - public function ticket_ID() |
|
| 1720 | - { |
|
| 1721 | - return $this->get('TKT_ID'); |
|
| 1722 | - } |
|
| 1723 | - |
|
| 1724 | - |
|
| 1725 | - /** |
|
| 1726 | - * Set Registration Code |
|
| 1727 | - * |
|
| 1728 | - * @access public |
|
| 1729 | - * @param string $REG_code Registration Code |
|
| 1730 | - * @param boolean $use_default |
|
| 1731 | - * @throws EE_Error |
|
| 1732 | - */ |
|
| 1733 | - public function set_reg_code($REG_code, $use_default = false) |
|
| 1734 | - { |
|
| 1735 | - if (empty($REG_code)) { |
|
| 1736 | - EE_Error::add_error( |
|
| 1737 | - esc_html__('REG_code can not be empty.', 'event_espresso'), |
|
| 1738 | - __FILE__, |
|
| 1739 | - __FUNCTION__, |
|
| 1740 | - __LINE__ |
|
| 1741 | - ); |
|
| 1742 | - return; |
|
| 1743 | - } |
|
| 1744 | - if (! $this->reg_code()) { |
|
| 1745 | - parent::set('REG_code', $REG_code, $use_default); |
|
| 1746 | - } else { |
|
| 1747 | - EE_Error::doing_it_wrong( |
|
| 1748 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 1749 | - esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
| 1750 | - '4.6.0' |
|
| 1751 | - ); |
|
| 1752 | - } |
|
| 1753 | - } |
|
| 1754 | - |
|
| 1755 | - |
|
| 1756 | - /** |
|
| 1757 | - * Returns all other registrations in the same group as this registrant who have the same ticket option. |
|
| 1758 | - * Note, if you want to just get all registrations in the same transaction (group), use: |
|
| 1759 | - * $registration->transaction()->registrations(); |
|
| 1760 | - * |
|
| 1761 | - * @since 4.5.0 |
|
| 1762 | - * @return EE_Registration[] or empty array if this isn't a group registration. |
|
| 1763 | - * @throws EE_Error |
|
| 1764 | - */ |
|
| 1765 | - public function get_all_other_registrations_in_group() |
|
| 1766 | - { |
|
| 1767 | - if ($this->group_size() < 2) { |
|
| 1768 | - return array(); |
|
| 1769 | - } |
|
| 1770 | - |
|
| 1771 | - $query[0] = array( |
|
| 1772 | - 'TXN_ID' => $this->transaction_ID(), |
|
| 1773 | - 'REG_ID' => array('!=', $this->ID()), |
|
| 1774 | - 'TKT_ID' => $this->ticket_ID(), |
|
| 1775 | - ); |
|
| 1776 | - /** @var EE_Registration[] $registrations */ |
|
| 1777 | - $registrations = $this->get_model()->get_all($query); |
|
| 1778 | - return $registrations; |
|
| 1779 | - } |
|
| 1780 | - |
|
| 1781 | - /** |
|
| 1782 | - * Return the link to the admin details for the object. |
|
| 1783 | - * |
|
| 1784 | - * @return string |
|
| 1785 | - * @throws EE_Error |
|
| 1786 | - */ |
|
| 1787 | - public function get_admin_details_link() |
|
| 1788 | - { |
|
| 1789 | - EE_Registry::instance()->load_helper('URL'); |
|
| 1790 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1791 | - array( |
|
| 1792 | - 'page' => 'espresso_registrations', |
|
| 1793 | - 'action' => 'view_registration', |
|
| 1794 | - '_REG_ID' => $this->ID(), |
|
| 1795 | - ), |
|
| 1796 | - admin_url('admin.php') |
|
| 1797 | - ); |
|
| 1798 | - } |
|
| 1799 | - |
|
| 1800 | - /** |
|
| 1801 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 1802 | - * |
|
| 1803 | - * @return string |
|
| 1804 | - * @throws EE_Error |
|
| 1805 | - */ |
|
| 1806 | - public function get_admin_edit_link() |
|
| 1807 | - { |
|
| 1808 | - return $this->get_admin_details_link(); |
|
| 1809 | - } |
|
| 1810 | - |
|
| 1811 | - /** |
|
| 1812 | - * Returns the link to a settings page for the object. |
|
| 1813 | - * |
|
| 1814 | - * @return string |
|
| 1815 | - * @throws EE_Error |
|
| 1816 | - */ |
|
| 1817 | - public function get_admin_settings_link() |
|
| 1818 | - { |
|
| 1819 | - return $this->get_admin_details_link(); |
|
| 1820 | - } |
|
| 1821 | - |
|
| 1822 | - /** |
|
| 1823 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 1824 | - * |
|
| 1825 | - * @return string |
|
| 1826 | - */ |
|
| 1827 | - public function get_admin_overview_link() |
|
| 1828 | - { |
|
| 1829 | - EE_Registry::instance()->load_helper('URL'); |
|
| 1830 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1831 | - array( |
|
| 1832 | - 'page' => 'espresso_registrations', |
|
| 1833 | - ), |
|
| 1834 | - admin_url('admin.php') |
|
| 1835 | - ); |
|
| 1836 | - } |
|
| 1837 | - |
|
| 1838 | - |
|
| 1839 | - /** |
|
| 1840 | - * @param array $query_params |
|
| 1841 | - * |
|
| 1842 | - * @return \EE_Registration[] |
|
| 1843 | - * @throws EE_Error |
|
| 1844 | - */ |
|
| 1845 | - public function payments($query_params = array()) |
|
| 1846 | - { |
|
| 1847 | - return $this->get_many_related('Payment', $query_params); |
|
| 1848 | - } |
|
| 1849 | - |
|
| 1850 | - |
|
| 1851 | - /** |
|
| 1852 | - * @param array $query_params |
|
| 1853 | - * |
|
| 1854 | - * @return \EE_Registration_Payment[] |
|
| 1855 | - * @throws EE_Error |
|
| 1856 | - */ |
|
| 1857 | - public function registration_payments($query_params = array()) |
|
| 1858 | - { |
|
| 1859 | - return $this->get_many_related('Registration_Payment', $query_params); |
|
| 1860 | - } |
|
| 1861 | - |
|
| 1862 | - |
|
| 1863 | - /** |
|
| 1864 | - * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
|
| 1865 | - * Note: if there are no payments on the registration there will be no payment method returned. |
|
| 1866 | - * |
|
| 1867 | - * @return EE_Payment_Method|null |
|
| 1868 | - */ |
|
| 1869 | - public function payment_method() |
|
| 1870 | - { |
|
| 1871 | - return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
| 1872 | - } |
|
| 1873 | - |
|
| 1874 | - |
|
| 1875 | - /** |
|
| 1876 | - * @return \EE_Line_Item |
|
| 1877 | - * @throws EntityNotFoundException |
|
| 1878 | - * @throws EE_Error |
|
| 1879 | - */ |
|
| 1880 | - public function ticket_line_item() |
|
| 1881 | - { |
|
| 1882 | - $ticket = $this->ticket(); |
|
| 1883 | - $transaction = $this->transaction(); |
|
| 1884 | - $line_item = null; |
|
| 1885 | - $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
| 1886 | - $transaction->total_line_item(), |
|
| 1887 | - 'Ticket', |
|
| 1888 | - array($ticket->ID()) |
|
| 1889 | - ); |
|
| 1890 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 1891 | - if ( |
|
| 1892 | - $ticket_line_item instanceof \EE_Line_Item |
|
| 1893 | - && $ticket_line_item->OBJ_type() === 'Ticket' |
|
| 1894 | - && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
| 1895 | - ) { |
|
| 1896 | - $line_item = $ticket_line_item; |
|
| 1897 | - break; |
|
| 1898 | - } |
|
| 1899 | - } |
|
| 1900 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
| 1901 | - throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
| 1902 | - } |
|
| 1903 | - return $line_item; |
|
| 1904 | - } |
|
| 1905 | - |
|
| 1906 | - |
|
| 1907 | - /** |
|
| 1908 | - * Soft Deletes this model object. |
|
| 1909 | - * |
|
| 1910 | - * @return boolean | int |
|
| 1911 | - * @throws RuntimeException |
|
| 1912 | - * @throws EE_Error |
|
| 1913 | - */ |
|
| 1914 | - public function delete() |
|
| 1915 | - { |
|
| 1916 | - if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
| 1917 | - $this->set_status(EEM_Registration::status_id_cancelled); |
|
| 1918 | - } |
|
| 1919 | - return parent::delete(); |
|
| 1920 | - } |
|
| 1921 | - |
|
| 1922 | - |
|
| 1923 | - /** |
|
| 1924 | - * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
| 1925 | - * |
|
| 1926 | - * @throws EE_Error |
|
| 1927 | - * @throws RuntimeException |
|
| 1928 | - */ |
|
| 1929 | - public function restore() |
|
| 1930 | - { |
|
| 1931 | - $previous_status = $this->get_extra_meta( |
|
| 1932 | - EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
| 1933 | - true, |
|
| 1934 | - EEM_Registration::status_id_cancelled |
|
| 1935 | - ); |
|
| 1936 | - if ($previous_status) { |
|
| 1937 | - $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
| 1938 | - $this->set_status($previous_status); |
|
| 1939 | - } |
|
| 1940 | - return parent::restore(); |
|
| 1941 | - } |
|
| 1942 | - |
|
| 1943 | - |
|
| 1944 | - /** |
|
| 1945 | - * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price |
|
| 1946 | - * |
|
| 1947 | - * @param boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic |
|
| 1948 | - * depending on whether the reg status changes to or from "Approved" |
|
| 1949 | - * @return boolean whether the Registration status was updated |
|
| 1950 | - * @throws EE_Error |
|
| 1951 | - * @throws RuntimeException |
|
| 1952 | - */ |
|
| 1953 | - public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true) |
|
| 1954 | - { |
|
| 1955 | - $paid = $this->paid(); |
|
| 1956 | - $price = $this->final_price(); |
|
| 1957 | - switch(true) { |
|
| 1958 | - // overpaid or paid |
|
| 1959 | - case EEH_Money::compare_floats($paid, $price, '>'): |
|
| 1960 | - case EEH_Money::compare_floats($paid, $price): |
|
| 1961 | - $new_status = EEM_Registration::status_id_approved; |
|
| 1962 | - break; |
|
| 1963 | - // underpaid |
|
| 1964 | - case EEH_Money::compare_floats($paid, $price, '<'): |
|
| 1965 | - $new_status = EEM_Registration::status_id_pending_payment; |
|
| 1966 | - break; |
|
| 1967 | - // uhhh Houston... |
|
| 1968 | - default: |
|
| 1969 | - throw new RuntimeException( |
|
| 1970 | - esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso') |
|
| 1971 | - ); |
|
| 1972 | - } |
|
| 1973 | - if ($new_status !== $this->status_ID()) { |
|
| 1974 | - if ($trigger_set_status_logic) { |
|
| 1975 | - return $this->set_status($new_status); |
|
| 1976 | - } |
|
| 1977 | - parent::set('STS_ID', $new_status); |
|
| 1978 | - return true; |
|
| 1979 | - } |
|
| 1980 | - return false; |
|
| 1981 | - } |
|
| 1982 | - |
|
| 1983 | - |
|
| 1984 | - /*************************** DEPRECATED ***************************/ |
|
| 1985 | - |
|
| 1986 | - |
|
| 1987 | - /** |
|
| 1988 | - * @deprecated |
|
| 1989 | - * @since 4.7.0 |
|
| 1990 | - * @access public |
|
| 1991 | - */ |
|
| 1992 | - public function price_paid() |
|
| 1993 | - { |
|
| 1994 | - EE_Error::doing_it_wrong('EE_Registration::price_paid()', |
|
| 1995 | - esc_html__('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'), |
|
| 1996 | - '4.7.0'); |
|
| 1997 | - return $this->final_price(); |
|
| 1998 | - } |
|
| 1999 | - |
|
| 2000 | - |
|
| 2001 | - /** |
|
| 2002 | - * @deprecated |
|
| 2003 | - * @since 4.7.0 |
|
| 2004 | - * @access public |
|
| 2005 | - * @param float $REG_final_price |
|
| 2006 | - * @throws EE_Error |
|
| 2007 | - * @throws RuntimeException |
|
| 2008 | - */ |
|
| 2009 | - public function set_price_paid($REG_final_price = 0.00) |
|
| 2010 | - { |
|
| 2011 | - EE_Error::doing_it_wrong('EE_Registration::set_price_paid()', |
|
| 2012 | - esc_html__('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'), |
|
| 2013 | - '4.7.0'); |
|
| 2014 | - $this->set_final_price($REG_final_price); |
|
| 2015 | - } |
|
| 2016 | - |
|
| 2017 | - |
|
| 2018 | - /** |
|
| 2019 | - * @deprecated |
|
| 2020 | - * @since 4.7.0 |
|
| 2021 | - * @return string |
|
| 2022 | - * @throws EE_Error |
|
| 2023 | - */ |
|
| 2024 | - public function pretty_price_paid() |
|
| 2025 | - { |
|
| 2026 | - EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()', |
|
| 2027 | - esc_html__('This method is deprecated, please use EE_Registration::pretty_final_price() instead.', |
|
| 2028 | - 'event_espresso'), '4.7.0'); |
|
| 2029 | - return $this->pretty_final_price(); |
|
| 2030 | - } |
|
| 2031 | - |
|
| 2032 | - |
|
| 2033 | - /** |
|
| 2034 | - * Gets the primary datetime related to this registration via the related Event to this registration |
|
| 2035 | - * |
|
| 2036 | - * @deprecated 4.9.17 |
|
| 2037 | - * @return EE_Datetime |
|
| 2038 | - * @throws EE_Error |
|
| 2039 | - * @throws EntityNotFoundException |
|
| 2040 | - */ |
|
| 2041 | - public function get_related_primary_datetime() |
|
| 2042 | - { |
|
| 2043 | - EE_Error::doing_it_wrong( |
|
| 2044 | - __METHOD__, |
|
| 2045 | - esc_html__( |
|
| 2046 | - 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
| 2047 | - 'event_espresso' |
|
| 2048 | - ), |
|
| 2049 | - '4.9.17', |
|
| 2050 | - '5.0.0' |
|
| 2051 | - ); |
|
| 2052 | - return $this->event()->primary_datetime(); |
|
| 2053 | - } |
|
| 22 | + /** |
|
| 23 | + * Used to reference when a registration has never been checked in. |
|
| 24 | + * |
|
| 25 | + * @deprecated use \EE_Checkin::status_checked_never instead |
|
| 26 | + * @type int |
|
| 27 | + */ |
|
| 28 | + const checkin_status_never = 2; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Used to reference when a registration has been checked in. |
|
| 32 | + * |
|
| 33 | + * @deprecated use \EE_Checkin::status_checked_in instead |
|
| 34 | + * @type int |
|
| 35 | + */ |
|
| 36 | + const checkin_status_in = 1; |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Used to reference when a registration has been checked out. |
|
| 41 | + * |
|
| 42 | + * @deprecated use \EE_Checkin::status_checked_out instead |
|
| 43 | + * @type int |
|
| 44 | + */ |
|
| 45 | + const checkin_status_out = 0; |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * extra meta key for tracking reg status os trashed registrations |
|
| 50 | + * |
|
| 51 | + * @type string |
|
| 52 | + */ |
|
| 53 | + const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * extra meta key for tracking if registration has reserved ticket |
|
| 58 | + * |
|
| 59 | + * @type string |
|
| 60 | + */ |
|
| 61 | + const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param array $props_n_values incoming values |
|
| 66 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 67 | + * used.) |
|
| 68 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 69 | + * date_format and the second value is the time format |
|
| 70 | + * @return EE_Registration |
|
| 71 | + * @throws EE_Error |
|
| 72 | + */ |
|
| 73 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 74 | + { |
|
| 75 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 76 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param array $props_n_values incoming values from the database |
|
| 82 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 83 | + * the website will be used. |
|
| 84 | + * @return EE_Registration |
|
| 85 | + */ |
|
| 86 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 87 | + { |
|
| 88 | + return new self($props_n_values, true, $timezone); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Set Event ID |
|
| 94 | + * |
|
| 95 | + * @param int $EVT_ID Event ID |
|
| 96 | + * @throws EE_Error |
|
| 97 | + * @throws RuntimeException |
|
| 98 | + */ |
|
| 99 | + public function set_event($EVT_ID = 0) |
|
| 100 | + { |
|
| 101 | + $this->set('EVT_ID', $EVT_ID); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can |
|
| 107 | + * be routed to internal methods |
|
| 108 | + * |
|
| 109 | + * @param string $field_name |
|
| 110 | + * @param mixed $field_value |
|
| 111 | + * @param bool $use_default |
|
| 112 | + * @throws EE_Error |
|
| 113 | + * @throws EntityNotFoundException |
|
| 114 | + * @throws InvalidArgumentException |
|
| 115 | + * @throws InvalidDataTypeException |
|
| 116 | + * @throws InvalidInterfaceException |
|
| 117 | + * @throws ReflectionException |
|
| 118 | + * @throws RuntimeException |
|
| 119 | + */ |
|
| 120 | + public function set($field_name, $field_value, $use_default = false) |
|
| 121 | + { |
|
| 122 | + switch ($field_name) { |
|
| 123 | + case 'REG_code': |
|
| 124 | + if (! empty($field_value) && $this->reg_code() === null) { |
|
| 125 | + $this->set_reg_code($field_value, $use_default); |
|
| 126 | + } |
|
| 127 | + break; |
|
| 128 | + case 'STS_ID': |
|
| 129 | + $this->set_status($field_value, $use_default); |
|
| 130 | + break; |
|
| 131 | + default: |
|
| 132 | + parent::set($field_name, $field_value, $use_default); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Set Status ID |
|
| 139 | + * updates the registration status and ALSO... |
|
| 140 | + * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
| 141 | + * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
| 142 | + * |
|
| 143 | + * @param string $new_STS_ID |
|
| 144 | + * @param boolean $use_default |
|
| 145 | + * @param ContextInterface|null $context |
|
| 146 | + * @return bool |
|
| 147 | + * @throws EE_Error |
|
| 148 | + * @throws EntityNotFoundException |
|
| 149 | + * @throws InvalidArgumentException |
|
| 150 | + * @throws ReflectionException |
|
| 151 | + * @throws RuntimeException |
|
| 152 | + * @throws InvalidDataTypeException |
|
| 153 | + * @throws InvalidInterfaceException |
|
| 154 | + */ |
|
| 155 | + public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null) |
|
| 156 | + { |
|
| 157 | + // get current REG_Status |
|
| 158 | + $old_STS_ID = $this->status_ID(); |
|
| 159 | + // if status has changed |
|
| 160 | + if ($old_STS_ID !== $new_STS_ID // and that status has actually changed |
|
| 161 | + && ! empty($old_STS_ID) // and that old status is actually set |
|
| 162 | + && ! empty($new_STS_ID) // as well as the new status |
|
| 163 | + && $this->ID() // ensure registration is in the db |
|
| 164 | + ) { |
|
| 165 | + // TO approved |
|
| 166 | + if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
| 167 | + // reserve a space by incrementing ticket and datetime sold values |
|
| 168 | + $this->_reserve_registration_space(); |
|
| 169 | + do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context); |
|
| 170 | + // OR FROM approved |
|
| 171 | + } elseif ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
| 172 | + // release a space by decrementing ticket and datetime sold values |
|
| 173 | + $this->_release_registration_space(); |
|
| 174 | + do_action( |
|
| 175 | + 'AHEE__EE_Registration__set_status__from_approved', |
|
| 176 | + $this, |
|
| 177 | + $old_STS_ID, |
|
| 178 | + $new_STS_ID, |
|
| 179 | + $context |
|
| 180 | + ); |
|
| 181 | + } |
|
| 182 | + // update status |
|
| 183 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
| 184 | + $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, $context); |
|
| 185 | + if($this->statusChangeUpdatesTransaction($context)) { |
|
| 186 | + $this->updateTransactionAfterStatusChange(); |
|
| 187 | + } |
|
| 188 | + do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context); |
|
| 189 | + return true; |
|
| 190 | + } |
|
| 191 | + //even though the old value matches the new value, it's still good to |
|
| 192 | + //allow the parent set method to have a say |
|
| 193 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
| 194 | + return true; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * update REGs and TXN when cancelled or declined registrations involved |
|
| 200 | + * |
|
| 201 | + * @param string $new_STS_ID |
|
| 202 | + * @param string $old_STS_ID |
|
| 203 | + * @param ContextInterface|null $context |
|
| 204 | + * @throws EE_Error |
|
| 205 | + * @throws InvalidArgumentException |
|
| 206 | + * @throws InvalidDataTypeException |
|
| 207 | + * @throws InvalidInterfaceException |
|
| 208 | + * @throws ReflectionException |
|
| 209 | + */ |
|
| 210 | + private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
| 211 | + { |
|
| 212 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
| 213 | + $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
| 214 | + // true if registration has been cancelled or declined |
|
| 215 | + $this->updateIfCanceled( |
|
| 216 | + $closed_reg_statuses, |
|
| 217 | + $new_STS_ID, |
|
| 218 | + $old_STS_ID, |
|
| 219 | + $context |
|
| 220 | + ); |
|
| 221 | + $this->updateIfDeclined( |
|
| 222 | + $closed_reg_statuses, |
|
| 223 | + $new_STS_ID, |
|
| 224 | + $old_STS_ID, |
|
| 225 | + $context |
|
| 226 | + ); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * update REGs and TXN when cancelled or declined registrations involved |
|
| 232 | + * |
|
| 233 | + * @param array $closed_reg_statuses |
|
| 234 | + * @param string $new_STS_ID |
|
| 235 | + * @param string $old_STS_ID |
|
| 236 | + * @param ContextInterface|null $context |
|
| 237 | + * @throws EE_Error |
|
| 238 | + * @throws InvalidArgumentException |
|
| 239 | + * @throws InvalidDataTypeException |
|
| 240 | + * @throws InvalidInterfaceException |
|
| 241 | + * @throws ReflectionException |
|
| 242 | + */ |
|
| 243 | + private function updateIfCanceled(array $closed_reg_statuses, $new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
| 244 | + { |
|
| 245 | + // true if registration has been cancelled or declined |
|
| 246 | + if (in_array($new_STS_ID, $closed_reg_statuses, true) |
|
| 247 | + && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
| 248 | + ) { |
|
| 249 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 250 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 251 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 252 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 253 | + // cancelled or declined registration |
|
| 254 | + $registration_processor->update_registration_after_being_canceled_or_declined( |
|
| 255 | + $this, |
|
| 256 | + $closed_reg_statuses |
|
| 257 | + ); |
|
| 258 | + $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
| 259 | + $this, |
|
| 260 | + $closed_reg_statuses, |
|
| 261 | + false |
|
| 262 | + ); |
|
| 263 | + do_action( |
|
| 264 | + 'AHEE__EE_Registration__set_status__canceled_or_declined', |
|
| 265 | + $this, |
|
| 266 | + $old_STS_ID, |
|
| 267 | + $new_STS_ID, |
|
| 268 | + $context |
|
| 269 | + ); |
|
| 270 | + return; |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * update REGs and TXN when cancelled or declined registrations involved |
|
| 277 | + * |
|
| 278 | + * @param array $closed_reg_statuses |
|
| 279 | + * @param string $new_STS_ID |
|
| 280 | + * @param string $old_STS_ID |
|
| 281 | + * @param ContextInterface|null $context |
|
| 282 | + * @throws EE_Error |
|
| 283 | + * @throws InvalidArgumentException |
|
| 284 | + * @throws InvalidDataTypeException |
|
| 285 | + * @throws InvalidInterfaceException |
|
| 286 | + * @throws ReflectionException |
|
| 287 | + */ |
|
| 288 | + private function updateIfDeclined(array $closed_reg_statuses, $new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
| 289 | + { |
|
| 290 | + // true if reinstating cancelled or declined registration |
|
| 291 | + if (in_array($old_STS_ID, $closed_reg_statuses, true) |
|
| 292 | + && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
| 293 | + ) { |
|
| 294 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 295 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 296 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 297 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 298 | + // reinstating cancelled or declined registration |
|
| 299 | + $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
| 300 | + $this, |
|
| 301 | + $closed_reg_statuses |
|
| 302 | + ); |
|
| 303 | + $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
| 304 | + $this, |
|
| 305 | + $closed_reg_statuses, |
|
| 306 | + false |
|
| 307 | + ); |
|
| 308 | + do_action( |
|
| 309 | + 'AHEE__EE_Registration__set_status__after_reinstated', |
|
| 310 | + $this, |
|
| 311 | + $old_STS_ID, |
|
| 312 | + $new_STS_ID, |
|
| 313 | + $context |
|
| 314 | + ); |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * @param ContextInterface|null $context |
|
| 321 | + * @return bool |
|
| 322 | + */ |
|
| 323 | + private function statusChangeUpdatesTransaction(ContextInterface $context = null) |
|
| 324 | + { |
|
| 325 | + $contexts_that_do_not_update_transaction = (array) apply_filters( |
|
| 326 | + 'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction', |
|
| 327 | + array('spco_reg_step_attendee_information_process_registrations'), |
|
| 328 | + $context, |
|
| 329 | + $this |
|
| 330 | + ); |
|
| 331 | + return ! ( |
|
| 332 | + $context instanceof ContextInterface |
|
| 333 | + && in_array($context->slug(), $contexts_that_do_not_update_transaction, true) |
|
| 334 | + ); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * @throws EE_Error |
|
| 340 | + * @throws EntityNotFoundException |
|
| 341 | + * @throws InvalidArgumentException |
|
| 342 | + * @throws InvalidDataTypeException |
|
| 343 | + * @throws InvalidInterfaceException |
|
| 344 | + * @throws ReflectionException |
|
| 345 | + * @throws RuntimeException |
|
| 346 | + */ |
|
| 347 | + private function updateTransactionAfterStatusChange() |
|
| 348 | + { |
|
| 349 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 350 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 351 | + $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
| 352 | + $this->transaction()->update_status_based_on_total_paid(true); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * get Status ID |
|
| 358 | + */ |
|
| 359 | + public function status_ID() |
|
| 360 | + { |
|
| 361 | + return $this->get('STS_ID'); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Gets the ticket this registration is for |
|
| 367 | + * |
|
| 368 | + * @param boolean $include_archived whether to include archived tickets or not. |
|
| 369 | + * |
|
| 370 | + * @return EE_Ticket|EE_Base_Class |
|
| 371 | + * @throws EE_Error |
|
| 372 | + */ |
|
| 373 | + public function ticket($include_archived = true) |
|
| 374 | + { |
|
| 375 | + $query_params = array(); |
|
| 376 | + if ($include_archived) { |
|
| 377 | + $query_params['default_where_conditions'] = 'none'; |
|
| 378 | + } |
|
| 379 | + return $this->get_first_related('Ticket', $query_params); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Gets the event this registration is for |
|
| 385 | + * |
|
| 386 | + * @return EE_Event |
|
| 387 | + * @throws EE_Error |
|
| 388 | + * @throws EntityNotFoundException |
|
| 389 | + */ |
|
| 390 | + public function event() |
|
| 391 | + { |
|
| 392 | + $event = $this->get_first_related('Event'); |
|
| 393 | + if (! $event instanceof \EE_Event) { |
|
| 394 | + throw new EntityNotFoundException('Event ID', $this->event_ID()); |
|
| 395 | + } |
|
| 396 | + return $event; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond |
|
| 402 | + * with the author of the event this registration is for. |
|
| 403 | + * |
|
| 404 | + * @since 4.5.0 |
|
| 405 | + * @return int |
|
| 406 | + * @throws EE_Error |
|
| 407 | + * @throws EntityNotFoundException |
|
| 408 | + */ |
|
| 409 | + public function wp_user() |
|
| 410 | + { |
|
| 411 | + $event = $this->event(); |
|
| 412 | + if ($event instanceof EE_Event) { |
|
| 413 | + return $event->wp_user(); |
|
| 414 | + } |
|
| 415 | + return 0; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * increments this registration's related ticket sold and corresponding datetime sold values |
|
| 421 | + * |
|
| 422 | + * @return void |
|
| 423 | + * @throws DomainException |
|
| 424 | + * @throws EE_Error |
|
| 425 | + * @throws EntityNotFoundException |
|
| 426 | + * @throws InvalidArgumentException |
|
| 427 | + * @throws InvalidDataTypeException |
|
| 428 | + * @throws InvalidInterfaceException |
|
| 429 | + * @throws ReflectionException |
|
| 430 | + * @throws UnexpectedEntityException |
|
| 431 | + */ |
|
| 432 | + private function _reserve_registration_space() |
|
| 433 | + { |
|
| 434 | + // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
| 435 | + // so stop tracking that this reg has a ticket reserved |
|
| 436 | + $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 437 | + $ticket = $this->ticket(); |
|
| 438 | + $ticket->increase_sold(); |
|
| 439 | + $ticket->save(); |
|
| 440 | + // possibly set event status to sold out |
|
| 441 | + $this->event()->perform_sold_out_status_check(); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
| 447 | + * |
|
| 448 | + * @return void |
|
| 449 | + * @throws DomainException |
|
| 450 | + * @throws EE_Error |
|
| 451 | + * @throws EntityNotFoundException |
|
| 452 | + * @throws InvalidArgumentException |
|
| 453 | + * @throws InvalidDataTypeException |
|
| 454 | + * @throws InvalidInterfaceException |
|
| 455 | + * @throws ReflectionException |
|
| 456 | + * @throws UnexpectedEntityException |
|
| 457 | + */ |
|
| 458 | + private function _release_registration_space() |
|
| 459 | + { |
|
| 460 | + $ticket = $this->ticket(); |
|
| 461 | + $ticket->decrease_sold(); |
|
| 462 | + $ticket->save(); |
|
| 463 | + // possibly change event status from sold out back to previous status |
|
| 464 | + $this->event()->perform_sold_out_status_check(); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * tracks this registration's ticket reservation in extra meta |
|
| 470 | + * and can increment related ticket reserved and corresponding datetime reserved values |
|
| 471 | + * |
|
| 472 | + * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
| 473 | + * @return void |
|
| 474 | + * @throws EE_Error |
|
| 475 | + * @throws InvalidArgumentException |
|
| 476 | + * @throws InvalidDataTypeException |
|
| 477 | + * @throws InvalidInterfaceException |
|
| 478 | + * @throws ReflectionException |
|
| 479 | + */ |
|
| 480 | + public function reserve_ticket($update_ticket = false, $source = 'unknown') |
|
| 481 | + { |
|
| 482 | + // only reserve ticket if space is not currently reserved |
|
| 483 | + if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) { |
|
| 484 | + $this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}"); |
|
| 485 | + // IMPORTANT !!! |
|
| 486 | + // although checking $update_ticket first would be more efficient, |
|
| 487 | + // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
| 488 | + if ( |
|
| 489 | + $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) |
|
| 490 | + && $update_ticket |
|
| 491 | + ) { |
|
| 492 | + $ticket = $this->ticket(); |
|
| 493 | + $ticket->increase_reserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 494 | + $ticket->save(); |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * stops tracking this registration's ticket reservation in extra meta |
|
| 502 | + * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
| 503 | + * |
|
| 504 | + * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
| 505 | + * @return void |
|
| 506 | + * @throws EE_Error |
|
| 507 | + * @throws InvalidArgumentException |
|
| 508 | + * @throws InvalidDataTypeException |
|
| 509 | + * @throws InvalidInterfaceException |
|
| 510 | + * @throws ReflectionException |
|
| 511 | + */ |
|
| 512 | + public function release_reserved_ticket($update_ticket = false, $source = 'unknown') |
|
| 513 | + { |
|
| 514 | + // only release ticket if space is currently reserved |
|
| 515 | + if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) { |
|
| 516 | + $this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}"); |
|
| 517 | + // IMPORTANT !!! |
|
| 518 | + // although checking $update_ticket first would be more efficient, |
|
| 519 | + // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
| 520 | + if ( |
|
| 521 | + $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false) |
|
| 522 | + && $update_ticket |
|
| 523 | + ) { |
|
| 524 | + $ticket = $this->ticket(); |
|
| 525 | + $ticket->decrease_reserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 526 | + $ticket->save(); |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Set Attendee ID |
|
| 534 | + * |
|
| 535 | + * @param int $ATT_ID Attendee ID |
|
| 536 | + * @throws EE_Error |
|
| 537 | + * @throws RuntimeException |
|
| 538 | + */ |
|
| 539 | + public function set_attendee_id($ATT_ID = 0) |
|
| 540 | + { |
|
| 541 | + $this->set('ATT_ID', $ATT_ID); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * Set Transaction ID |
|
| 547 | + * |
|
| 548 | + * @param int $TXN_ID Transaction ID |
|
| 549 | + * @throws EE_Error |
|
| 550 | + * @throws RuntimeException |
|
| 551 | + */ |
|
| 552 | + public function set_transaction_id($TXN_ID = 0) |
|
| 553 | + { |
|
| 554 | + $this->set('TXN_ID', $TXN_ID); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Set Session |
|
| 560 | + * |
|
| 561 | + * @param string $REG_session PHP Session ID |
|
| 562 | + * @throws EE_Error |
|
| 563 | + * @throws RuntimeException |
|
| 564 | + */ |
|
| 565 | + public function set_session($REG_session = '') |
|
| 566 | + { |
|
| 567 | + $this->set('REG_session', $REG_session); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * Set Registration URL Link |
|
| 573 | + * |
|
| 574 | + * @param string $REG_url_link Registration URL Link |
|
| 575 | + * @throws EE_Error |
|
| 576 | + * @throws RuntimeException |
|
| 577 | + */ |
|
| 578 | + public function set_reg_url_link($REG_url_link = '') |
|
| 579 | + { |
|
| 580 | + $this->set('REG_url_link', $REG_url_link); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * Set Attendee Counter |
|
| 586 | + * |
|
| 587 | + * @param int $REG_count Primary Attendee |
|
| 588 | + * @throws EE_Error |
|
| 589 | + * @throws RuntimeException |
|
| 590 | + */ |
|
| 591 | + public function set_count($REG_count = 1) |
|
| 592 | + { |
|
| 593 | + $this->set('REG_count', $REG_count); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * Set Group Size |
|
| 599 | + * |
|
| 600 | + * @param boolean $REG_group_size Group Registration |
|
| 601 | + * @throws EE_Error |
|
| 602 | + * @throws RuntimeException |
|
| 603 | + */ |
|
| 604 | + public function set_group_size($REG_group_size = false) |
|
| 605 | + { |
|
| 606 | + $this->set('REG_group_size', $REG_group_size); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + |
|
| 610 | + /** |
|
| 611 | + * is_not_approved - convenience method that returns TRUE if REG status ID == |
|
| 612 | + * EEM_Registration::status_id_not_approved |
|
| 613 | + * |
|
| 614 | + * @return boolean |
|
| 615 | + */ |
|
| 616 | + public function is_not_approved() |
|
| 617 | + { |
|
| 618 | + return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * is_pending_payment - convenience method that returns TRUE if REG status ID == |
|
| 624 | + * EEM_Registration::status_id_pending_payment |
|
| 625 | + * |
|
| 626 | + * @return boolean |
|
| 627 | + */ |
|
| 628 | + public function is_pending_payment() |
|
| 629 | + { |
|
| 630 | + return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + |
|
| 634 | + /** |
|
| 635 | + * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved |
|
| 636 | + * |
|
| 637 | + * @return boolean |
|
| 638 | + */ |
|
| 639 | + public function is_approved() |
|
| 640 | + { |
|
| 641 | + return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled |
|
| 647 | + * |
|
| 648 | + * @return boolean |
|
| 649 | + */ |
|
| 650 | + public function is_cancelled() |
|
| 651 | + { |
|
| 652 | + return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined |
|
| 658 | + * |
|
| 659 | + * @return boolean |
|
| 660 | + */ |
|
| 661 | + public function is_declined() |
|
| 662 | + { |
|
| 663 | + return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * is_incomplete - convenience method that returns TRUE if REG status ID == |
|
| 669 | + * EEM_Registration::status_id_incomplete |
|
| 670 | + * |
|
| 671 | + * @return boolean |
|
| 672 | + */ |
|
| 673 | + public function is_incomplete() |
|
| 674 | + { |
|
| 675 | + return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * Set Registration Date |
|
| 681 | + * |
|
| 682 | + * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of |
|
| 683 | + * Date |
|
| 684 | + * @throws EE_Error |
|
| 685 | + * @throws RuntimeException |
|
| 686 | + */ |
|
| 687 | + public function set_reg_date($REG_date = false) |
|
| 688 | + { |
|
| 689 | + $this->set('REG_date', $REG_date); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * Set final price owing for this registration after all ticket/price modifications |
|
| 695 | + * |
|
| 696 | + * @access public |
|
| 697 | + * @param float $REG_final_price |
|
| 698 | + * @throws EE_Error |
|
| 699 | + * @throws RuntimeException |
|
| 700 | + */ |
|
| 701 | + public function set_final_price($REG_final_price = 0.00) |
|
| 702 | + { |
|
| 703 | + $this->set('REG_final_price', $REG_final_price); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * Set amount paid towards this registration's final price |
|
| 709 | + * |
|
| 710 | + * @access public |
|
| 711 | + * @param float $REG_paid |
|
| 712 | + * @throws EE_Error |
|
| 713 | + * @throws RuntimeException |
|
| 714 | + */ |
|
| 715 | + public function set_paid($REG_paid = 0.00) |
|
| 716 | + { |
|
| 717 | + $this->set('REG_paid', $REG_paid); |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + |
|
| 721 | + /** |
|
| 722 | + * Attendee Is Going |
|
| 723 | + * |
|
| 724 | + * @param boolean $REG_att_is_going Attendee Is Going |
|
| 725 | + * @throws EE_Error |
|
| 726 | + * @throws RuntimeException |
|
| 727 | + */ |
|
| 728 | + public function set_att_is_going($REG_att_is_going = false) |
|
| 729 | + { |
|
| 730 | + $this->set('REG_att_is_going', $REG_att_is_going); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + |
|
| 734 | + /** |
|
| 735 | + * Gets the related attendee |
|
| 736 | + * |
|
| 737 | + * @return EE_Attendee |
|
| 738 | + * @throws EE_Error |
|
| 739 | + */ |
|
| 740 | + public function attendee() |
|
| 741 | + { |
|
| 742 | + return $this->get_first_related('Attendee'); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * get Event ID |
|
| 748 | + */ |
|
| 749 | + public function event_ID() |
|
| 750 | + { |
|
| 751 | + return $this->get('EVT_ID'); |
|
| 752 | + } |
|
| 753 | + |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * get Event ID |
|
| 757 | + */ |
|
| 758 | + public function event_name() |
|
| 759 | + { |
|
| 760 | + $event = $this->event_obj(); |
|
| 761 | + if ($event) { |
|
| 762 | + return $event->name(); |
|
| 763 | + } else { |
|
| 764 | + return null; |
|
| 765 | + } |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + |
|
| 769 | + /** |
|
| 770 | + * Fetches the event this registration is for |
|
| 771 | + * |
|
| 772 | + * @return EE_Event |
|
| 773 | + * @throws EE_Error |
|
| 774 | + */ |
|
| 775 | + public function event_obj() |
|
| 776 | + { |
|
| 777 | + return $this->get_first_related('Event'); |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + |
|
| 781 | + /** |
|
| 782 | + * get Attendee ID |
|
| 783 | + */ |
|
| 784 | + public function attendee_ID() |
|
| 785 | + { |
|
| 786 | + return $this->get('ATT_ID'); |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + |
|
| 790 | + /** |
|
| 791 | + * get PHP Session ID |
|
| 792 | + */ |
|
| 793 | + public function session_ID() |
|
| 794 | + { |
|
| 795 | + return $this->get('REG_session'); |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + /** |
|
| 800 | + * Gets the string which represents the URL trigger for the receipt template in the message template system. |
|
| 801 | + * |
|
| 802 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
| 803 | + * @return string |
|
| 804 | + */ |
|
| 805 | + public function receipt_url($messenger = 'html') |
|
| 806 | + { |
|
| 807 | + |
|
| 808 | + /** |
|
| 809 | + * The below will be deprecated one version after this. We check first if there is a custom receipt template |
|
| 810 | + * already in use on old system. If there is then we just return the standard url for it. |
|
| 811 | + * |
|
| 812 | + * @since 4.5.0 |
|
| 813 | + */ |
|
| 814 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
|
| 815 | + $has_custom = EEH_Template::locate_template( |
|
| 816 | + $template_relative_path, |
|
| 817 | + array(), |
|
| 818 | + true, |
|
| 819 | + true, |
|
| 820 | + true |
|
| 821 | + ); |
|
| 822 | + |
|
| 823 | + if ($has_custom) { |
|
| 824 | + return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
| 825 | + } |
|
| 826 | + return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + |
|
| 830 | + /** |
|
| 831 | + * Gets the string which represents the URL trigger for the invoice template in the message template system. |
|
| 832 | + * |
|
| 833 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
| 834 | + * @return string |
|
| 835 | + * @throws EE_Error |
|
| 836 | + */ |
|
| 837 | + public function invoice_url($messenger = 'html') |
|
| 838 | + { |
|
| 839 | + /** |
|
| 840 | + * The below will be deprecated one version after this. We check first if there is a custom invoice template |
|
| 841 | + * already in use on old system. If there is then we just return the standard url for it. |
|
| 842 | + * |
|
| 843 | + * @since 4.5.0 |
|
| 844 | + */ |
|
| 845 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
|
| 846 | + $has_custom = EEH_Template::locate_template( |
|
| 847 | + $template_relative_path, |
|
| 848 | + array(), |
|
| 849 | + true, |
|
| 850 | + true, |
|
| 851 | + true |
|
| 852 | + ); |
|
| 853 | + |
|
| 854 | + if ($has_custom) { |
|
| 855 | + if ($messenger == 'html') { |
|
| 856 | + return $this->invoice_url('launch'); |
|
| 857 | + } |
|
| 858 | + $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
|
| 859 | + |
|
| 860 | + $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
| 861 | + if ($messenger == 'html') { |
|
| 862 | + $query_args['html'] = true; |
|
| 863 | + } |
|
| 864 | + return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
| 865 | + } |
|
| 866 | + return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * get Registration URL Link |
|
| 872 | + * |
|
| 873 | + * @access public |
|
| 874 | + * @return string |
|
| 875 | + * @throws EE_Error |
|
| 876 | + */ |
|
| 877 | + public function reg_url_link() |
|
| 878 | + { |
|
| 879 | + return (string) $this->get('REG_url_link'); |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + |
|
| 883 | + /** |
|
| 884 | + * Echoes out invoice_url() |
|
| 885 | + * |
|
| 886 | + * @param string $type 'download','launch', or 'html' (default is 'launch') |
|
| 887 | + * @return void |
|
| 888 | + * @throws EE_Error |
|
| 889 | + */ |
|
| 890 | + public function e_invoice_url($type = 'launch') |
|
| 891 | + { |
|
| 892 | + echo $this->invoice_url($type); |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + |
|
| 896 | + /** |
|
| 897 | + * Echoes out payment_overview_url |
|
| 898 | + */ |
|
| 899 | + public function e_payment_overview_url() |
|
| 900 | + { |
|
| 901 | + echo $this->payment_overview_url(); |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + |
|
| 905 | + /** |
|
| 906 | + * Gets the URL for the checkout payment options reg step |
|
| 907 | + * with this registration's REG_url_link added as a query parameter |
|
| 908 | + * |
|
| 909 | + * @param bool $clear_session Set to true when you want to clear the session on revisiting the |
|
| 910 | + * payment overview url. |
|
| 911 | + * @return string |
|
| 912 | + * @throws InvalidInterfaceException |
|
| 913 | + * @throws InvalidDataTypeException |
|
| 914 | + * @throws EE_Error |
|
| 915 | + * @throws InvalidArgumentException |
|
| 916 | + */ |
|
| 917 | + public function payment_overview_url($clear_session = false) |
|
| 918 | + { |
|
| 919 | + return add_query_arg( |
|
| 920 | + (array) apply_filters( |
|
| 921 | + 'FHEE__EE_Registration__payment_overview_url__query_args', |
|
| 922 | + array( |
|
| 923 | + 'e_reg_url_link' => $this->reg_url_link(), |
|
| 924 | + 'step' => 'payment_options', |
|
| 925 | + 'revisit' => true, |
|
| 926 | + 'clear_session' => (bool) $clear_session, |
|
| 927 | + ), |
|
| 928 | + $this |
|
| 929 | + ), |
|
| 930 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 931 | + ); |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + |
|
| 935 | + /** |
|
| 936 | + * Gets the URL for the checkout attendee information reg step |
|
| 937 | + * with this registration's REG_url_link added as a query parameter |
|
| 938 | + * |
|
| 939 | + * @return string |
|
| 940 | + * @throws InvalidInterfaceException |
|
| 941 | + * @throws InvalidDataTypeException |
|
| 942 | + * @throws EE_Error |
|
| 943 | + * @throws InvalidArgumentException |
|
| 944 | + */ |
|
| 945 | + public function edit_attendee_information_url() |
|
| 946 | + { |
|
| 947 | + return add_query_arg( |
|
| 948 | + (array) apply_filters( |
|
| 949 | + 'FHEE__EE_Registration__edit_attendee_information_url__query_args', |
|
| 950 | + array( |
|
| 951 | + 'e_reg_url_link' => $this->reg_url_link(), |
|
| 952 | + 'step' => 'attendee_information', |
|
| 953 | + 'revisit' => true, |
|
| 954 | + ), |
|
| 955 | + $this |
|
| 956 | + ), |
|
| 957 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 958 | + ); |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + |
|
| 962 | + /** |
|
| 963 | + * Simply generates and returns the appropriate admin_url link to edit this registration |
|
| 964 | + * |
|
| 965 | + * @return string |
|
| 966 | + * @throws EE_Error |
|
| 967 | + */ |
|
| 968 | + public function get_admin_edit_url() |
|
| 969 | + { |
|
| 970 | + return EEH_URL::add_query_args_and_nonce(array( |
|
| 971 | + 'page' => 'espresso_registrations', |
|
| 972 | + 'action' => 'view_registration', |
|
| 973 | + '_REG_ID' => $this->ID(), |
|
| 974 | + ), admin_url('admin.php')); |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + /** |
|
| 979 | + * is_primary_registrant? |
|
| 980 | + */ |
|
| 981 | + public function is_primary_registrant() |
|
| 982 | + { |
|
| 983 | + return $this->get('REG_count') == 1 ? true : false; |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + |
|
| 987 | + /** |
|
| 988 | + * This returns the primary registration object for this registration group (which may be this object). |
|
| 989 | + * |
|
| 990 | + * @return EE_Registration |
|
| 991 | + * @throws EE_Error |
|
| 992 | + */ |
|
| 993 | + public function get_primary_registration() |
|
| 994 | + { |
|
| 995 | + if ($this->is_primary_registrant()) { |
|
| 996 | + return $this; |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
|
| 1000 | + /** @var EE_Registration $primary_registrant */ |
|
| 1001 | + $primary_registrant = EEM_Registration::instance()->get_one(array( |
|
| 1002 | + array( |
|
| 1003 | + 'TXN_ID' => $this->transaction_ID(), |
|
| 1004 | + 'REG_count' => 1, |
|
| 1005 | + ), |
|
| 1006 | + )); |
|
| 1007 | + return $primary_registrant; |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + /** |
|
| 1012 | + * get Attendee Number |
|
| 1013 | + * |
|
| 1014 | + * @access public |
|
| 1015 | + */ |
|
| 1016 | + public function count() |
|
| 1017 | + { |
|
| 1018 | + return $this->get('REG_count'); |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + |
|
| 1022 | + /** |
|
| 1023 | + * get Group Size |
|
| 1024 | + */ |
|
| 1025 | + public function group_size() |
|
| 1026 | + { |
|
| 1027 | + return $this->get('REG_group_size'); |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + |
|
| 1031 | + /** |
|
| 1032 | + * get Registration Date |
|
| 1033 | + */ |
|
| 1034 | + public function date() |
|
| 1035 | + { |
|
| 1036 | + return $this->get('REG_date'); |
|
| 1037 | + } |
|
| 1038 | + |
|
| 1039 | + |
|
| 1040 | + /** |
|
| 1041 | + * gets a pretty date |
|
| 1042 | + * |
|
| 1043 | + * @param string $date_format |
|
| 1044 | + * @param string $time_format |
|
| 1045 | + * @return string |
|
| 1046 | + * @throws EE_Error |
|
| 1047 | + */ |
|
| 1048 | + public function pretty_date($date_format = null, $time_format = null) |
|
| 1049 | + { |
|
| 1050 | + return $this->get_datetime('REG_date', $date_format, $time_format); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + |
|
| 1054 | + /** |
|
| 1055 | + * final_price |
|
| 1056 | + * the registration's share of the transaction total, so that the |
|
| 1057 | + * sum of all the transaction's REG_final_prices equal the transaction's total |
|
| 1058 | + * |
|
| 1059 | + * @return float |
|
| 1060 | + * @throws EE_Error |
|
| 1061 | + */ |
|
| 1062 | + public function final_price() |
|
| 1063 | + { |
|
| 1064 | + return $this->get('REG_final_price'); |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + |
|
| 1068 | + /** |
|
| 1069 | + * pretty_final_price |
|
| 1070 | + * final price as formatted string, with correct decimal places and currency symbol |
|
| 1071 | + * |
|
| 1072 | + * @return string |
|
| 1073 | + * @throws EE_Error |
|
| 1074 | + */ |
|
| 1075 | + public function pretty_final_price() |
|
| 1076 | + { |
|
| 1077 | + return $this->get_pretty('REG_final_price'); |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + |
|
| 1081 | + /** |
|
| 1082 | + * get paid (yeah) |
|
| 1083 | + * |
|
| 1084 | + * @return float |
|
| 1085 | + * @throws EE_Error |
|
| 1086 | + */ |
|
| 1087 | + public function paid() |
|
| 1088 | + { |
|
| 1089 | + return $this->get('REG_paid'); |
|
| 1090 | + } |
|
| 1091 | + |
|
| 1092 | + |
|
| 1093 | + /** |
|
| 1094 | + * pretty_paid |
|
| 1095 | + * |
|
| 1096 | + * @return float |
|
| 1097 | + * @throws EE_Error |
|
| 1098 | + */ |
|
| 1099 | + public function pretty_paid() |
|
| 1100 | + { |
|
| 1101 | + return $this->get_pretty('REG_paid'); |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * owes_monies_and_can_pay |
|
| 1107 | + * whether or not this registration has monies owing and it's' status allows payment |
|
| 1108 | + * |
|
| 1109 | + * @param array $requires_payment |
|
| 1110 | + * @return bool |
|
| 1111 | + * @throws EE_Error |
|
| 1112 | + */ |
|
| 1113 | + public function owes_monies_and_can_pay($requires_payment = array()) |
|
| 1114 | + { |
|
| 1115 | + // these reg statuses require payment (if event is not free) |
|
| 1116 | + $requires_payment = ! empty($requires_payment) |
|
| 1117 | + ? $requires_payment |
|
| 1118 | + : EEM_Registration::reg_statuses_that_allow_payment(); |
|
| 1119 | + if (in_array($this->status_ID(), $requires_payment) && |
|
| 1120 | + $this->final_price() != 0 && |
|
| 1121 | + $this->final_price() != $this->paid() |
|
| 1122 | + ) { |
|
| 1123 | + return true; |
|
| 1124 | + } else { |
|
| 1125 | + return false; |
|
| 1126 | + } |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + |
|
| 1130 | + /** |
|
| 1131 | + * Prints out the return value of $this->pretty_status() |
|
| 1132 | + * |
|
| 1133 | + * @param bool $show_icons |
|
| 1134 | + * @return void |
|
| 1135 | + * @throws EE_Error |
|
| 1136 | + */ |
|
| 1137 | + public function e_pretty_status($show_icons = false) |
|
| 1138 | + { |
|
| 1139 | + echo $this->pretty_status($show_icons); |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + |
|
| 1143 | + /** |
|
| 1144 | + * Returns a nice version of the status for displaying to customers |
|
| 1145 | + * |
|
| 1146 | + * @param bool $show_icons |
|
| 1147 | + * @return string |
|
| 1148 | + * @throws EE_Error |
|
| 1149 | + */ |
|
| 1150 | + public function pretty_status($show_icons = false) |
|
| 1151 | + { |
|
| 1152 | + $status = EEM_Status::instance()->localized_status( |
|
| 1153 | + array($this->status_ID() => esc_html__('unknown', 'event_espresso')), |
|
| 1154 | + false, |
|
| 1155 | + 'sentence' |
|
| 1156 | + ); |
|
| 1157 | + $icon = ''; |
|
| 1158 | + switch ($this->status_ID()) { |
|
| 1159 | + case EEM_Registration::status_id_approved: |
|
| 1160 | + $icon = $show_icons |
|
| 1161 | + ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' |
|
| 1162 | + : ''; |
|
| 1163 | + break; |
|
| 1164 | + case EEM_Registration::status_id_pending_payment: |
|
| 1165 | + $icon = $show_icons |
|
| 1166 | + ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' |
|
| 1167 | + : ''; |
|
| 1168 | + break; |
|
| 1169 | + case EEM_Registration::status_id_not_approved: |
|
| 1170 | + $icon = $show_icons |
|
| 1171 | + ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' |
|
| 1172 | + : ''; |
|
| 1173 | + break; |
|
| 1174 | + case EEM_Registration::status_id_cancelled: |
|
| 1175 | + $icon = $show_icons |
|
| 1176 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
| 1177 | + : ''; |
|
| 1178 | + break; |
|
| 1179 | + case EEM_Registration::status_id_incomplete: |
|
| 1180 | + $icon = $show_icons |
|
| 1181 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' |
|
| 1182 | + : ''; |
|
| 1183 | + break; |
|
| 1184 | + case EEM_Registration::status_id_declined: |
|
| 1185 | + $icon = $show_icons |
|
| 1186 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
| 1187 | + : ''; |
|
| 1188 | + break; |
|
| 1189 | + case EEM_Registration::status_id_wait_list: |
|
| 1190 | + $icon = $show_icons |
|
| 1191 | + ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' |
|
| 1192 | + : ''; |
|
| 1193 | + break; |
|
| 1194 | + } |
|
| 1195 | + return $icon . $status[$this->status_ID()]; |
|
| 1196 | + } |
|
| 1197 | + |
|
| 1198 | + |
|
| 1199 | + /** |
|
| 1200 | + * get Attendee Is Going |
|
| 1201 | + */ |
|
| 1202 | + public function att_is_going() |
|
| 1203 | + { |
|
| 1204 | + return $this->get('REG_att_is_going'); |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + |
|
| 1208 | + /** |
|
| 1209 | + * Gets related answers |
|
| 1210 | + * |
|
| 1211 | + * @param array $query_params like EEM_Base::get_all |
|
| 1212 | + * @return EE_Answer[] |
|
| 1213 | + * @throws EE_Error |
|
| 1214 | + */ |
|
| 1215 | + public function answers($query_params = null) |
|
| 1216 | + { |
|
| 1217 | + return $this->get_many_related('Answer', $query_params); |
|
| 1218 | + } |
|
| 1219 | + |
|
| 1220 | + |
|
| 1221 | + /** |
|
| 1222 | + * Gets the registration's answer value to the specified question |
|
| 1223 | + * (either the question's ID or a question object) |
|
| 1224 | + * |
|
| 1225 | + * @param EE_Question|int $question |
|
| 1226 | + * @param bool $pretty_value |
|
| 1227 | + * @return array|string if pretty_value= true, the result will always be a string |
|
| 1228 | + * (because the answer might be an array of answer values, so passing pretty_value=true |
|
| 1229 | + * will convert it into some kind of string) |
|
| 1230 | + * @throws EE_Error |
|
| 1231 | + */ |
|
| 1232 | + public function answer_value_to_question($question, $pretty_value = true) |
|
| 1233 | + { |
|
| 1234 | + $question_id = EEM_Question::instance()->ensure_is_ID($question); |
|
| 1235 | + return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + |
|
| 1239 | + /** |
|
| 1240 | + * question_groups |
|
| 1241 | + * returns an array of EE_Question_Group objects for this registration |
|
| 1242 | + * |
|
| 1243 | + * @return EE_Question_Group[] |
|
| 1244 | + * @throws EE_Error |
|
| 1245 | + * @throws EntityNotFoundException |
|
| 1246 | + */ |
|
| 1247 | + public function question_groups() |
|
| 1248 | + { |
|
| 1249 | + $question_groups = array(); |
|
| 1250 | + if ($this->event() instanceof EE_Event) { |
|
| 1251 | + $question_groups = $this->event()->question_groups( |
|
| 1252 | + array( |
|
| 1253 | + array( |
|
| 1254 | + 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
| 1255 | + ), |
|
| 1256 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
| 1257 | + ) |
|
| 1258 | + ); |
|
| 1259 | + } |
|
| 1260 | + return $question_groups; |
|
| 1261 | + } |
|
| 1262 | + |
|
| 1263 | + |
|
| 1264 | + /** |
|
| 1265 | + * count_question_groups |
|
| 1266 | + * returns a count of the number of EE_Question_Group objects for this registration |
|
| 1267 | + * |
|
| 1268 | + * @return int |
|
| 1269 | + * @throws EE_Error |
|
| 1270 | + * @throws EntityNotFoundException |
|
| 1271 | + */ |
|
| 1272 | + public function count_question_groups() |
|
| 1273 | + { |
|
| 1274 | + $qg_count = 0; |
|
| 1275 | + if ($this->event() instanceof EE_Event) { |
|
| 1276 | + $qg_count = $this->event()->count_related( |
|
| 1277 | + 'Question_Group', |
|
| 1278 | + array( |
|
| 1279 | + array( |
|
| 1280 | + 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
| 1281 | + ), |
|
| 1282 | + ) |
|
| 1283 | + ); |
|
| 1284 | + } |
|
| 1285 | + return $qg_count; |
|
| 1286 | + } |
|
| 1287 | + |
|
| 1288 | + |
|
| 1289 | + /** |
|
| 1290 | + * Returns the registration date in the 'standard' string format |
|
| 1291 | + * (function may be improved in the future to allow for different formats and timezones) |
|
| 1292 | + * |
|
| 1293 | + * @return string |
|
| 1294 | + * @throws EE_Error |
|
| 1295 | + */ |
|
| 1296 | + public function reg_date() |
|
| 1297 | + { |
|
| 1298 | + return $this->get_datetime('REG_date'); |
|
| 1299 | + } |
|
| 1300 | + |
|
| 1301 | + |
|
| 1302 | + /** |
|
| 1303 | + * Gets the datetime-ticket for this registration (ie, it can be used to isolate |
|
| 1304 | + * the ticket this registration purchased, or the datetime they have registered |
|
| 1305 | + * to attend) |
|
| 1306 | + * |
|
| 1307 | + * @return EE_Datetime_Ticket |
|
| 1308 | + * @throws EE_Error |
|
| 1309 | + */ |
|
| 1310 | + public function datetime_ticket() |
|
| 1311 | + { |
|
| 1312 | + return $this->get_first_related('Datetime_Ticket'); |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + |
|
| 1316 | + /** |
|
| 1317 | + * Sets the registration's datetime_ticket. |
|
| 1318 | + * |
|
| 1319 | + * @param EE_Datetime_Ticket $datetime_ticket |
|
| 1320 | + * @return EE_Datetime_Ticket |
|
| 1321 | + * @throws EE_Error |
|
| 1322 | + */ |
|
| 1323 | + public function set_datetime_ticket($datetime_ticket) |
|
| 1324 | + { |
|
| 1325 | + return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
| 1326 | + } |
|
| 1327 | + |
|
| 1328 | + /** |
|
| 1329 | + * Gets deleted |
|
| 1330 | + * |
|
| 1331 | + * @return bool |
|
| 1332 | + * @throws EE_Error |
|
| 1333 | + */ |
|
| 1334 | + public function deleted() |
|
| 1335 | + { |
|
| 1336 | + return $this->get('REG_deleted'); |
|
| 1337 | + } |
|
| 1338 | + |
|
| 1339 | + /** |
|
| 1340 | + * Sets deleted |
|
| 1341 | + * |
|
| 1342 | + * @param boolean $deleted |
|
| 1343 | + * @return bool |
|
| 1344 | + * @throws EE_Error |
|
| 1345 | + * @throws RuntimeException |
|
| 1346 | + */ |
|
| 1347 | + public function set_deleted($deleted) |
|
| 1348 | + { |
|
| 1349 | + if ($deleted) { |
|
| 1350 | + $this->delete(); |
|
| 1351 | + } else { |
|
| 1352 | + $this->restore(); |
|
| 1353 | + } |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + |
|
| 1357 | + /** |
|
| 1358 | + * Get the status object of this object |
|
| 1359 | + * |
|
| 1360 | + * @return EE_Status |
|
| 1361 | + * @throws EE_Error |
|
| 1362 | + */ |
|
| 1363 | + public function status_obj() |
|
| 1364 | + { |
|
| 1365 | + return $this->get_first_related('Status'); |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + /** |
|
| 1370 | + * Returns the number of times this registration has checked into any of the datetimes |
|
| 1371 | + * its available for |
|
| 1372 | + * |
|
| 1373 | + * @return int |
|
| 1374 | + * @throws EE_Error |
|
| 1375 | + */ |
|
| 1376 | + public function count_checkins() |
|
| 1377 | + { |
|
| 1378 | + return $this->get_model()->count_related($this, 'Checkin'); |
|
| 1379 | + } |
|
| 1380 | + |
|
| 1381 | + |
|
| 1382 | + /** |
|
| 1383 | + * Returns the number of current Check-ins this registration is checked into for any of the datetimes the |
|
| 1384 | + * registration is for. Note, this is ONLY checked in (does not include checkedout) |
|
| 1385 | + * |
|
| 1386 | + * @return int |
|
| 1387 | + * @throws EE_Error |
|
| 1388 | + */ |
|
| 1389 | + public function count_checkins_not_checkedout() |
|
| 1390 | + { |
|
| 1391 | + return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
| 1392 | + } |
|
| 1393 | + |
|
| 1394 | + |
|
| 1395 | + /** |
|
| 1396 | + * The purpose of this method is simply to check whether this registration can checkin to the given datetime. |
|
| 1397 | + * |
|
| 1398 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
| 1399 | + * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
|
| 1400 | + * consider registration status as well as datetime access. |
|
| 1401 | + * @return bool |
|
| 1402 | + * @throws EE_Error |
|
| 1403 | + */ |
|
| 1404 | + public function can_checkin($DTT_OR_ID, $check_approved = true) |
|
| 1405 | + { |
|
| 1406 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
| 1407 | + |
|
| 1408 | + //first check registration status |
|
| 1409 | + if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
| 1410 | + return false; |
|
| 1411 | + } |
|
| 1412 | + //is there a datetime ticket that matches this dtt_ID? |
|
| 1413 | + if (! (EEM_Datetime_Ticket::instance()->exists(array( |
|
| 1414 | + array( |
|
| 1415 | + 'TKT_ID' => $this->get('TKT_ID'), |
|
| 1416 | + 'DTT_ID' => $DTT_ID, |
|
| 1417 | + ), |
|
| 1418 | + ))) |
|
| 1419 | + ) { |
|
| 1420 | + return false; |
|
| 1421 | + } |
|
| 1422 | + |
|
| 1423 | + //final check is against TKT_uses |
|
| 1424 | + return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
| 1425 | + } |
|
| 1426 | + |
|
| 1427 | + |
|
| 1428 | + /** |
|
| 1429 | + * This method verifies whether the user can checkin for the given datetime considering the max uses value set on |
|
| 1430 | + * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the |
|
| 1431 | + * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, |
|
| 1432 | + * then return false. Otherwise return true. |
|
| 1433 | + * |
|
| 1434 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
| 1435 | + * @return bool true means can checkin. false means cannot checkin. |
|
| 1436 | + * @throws EE_Error |
|
| 1437 | + */ |
|
| 1438 | + public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) |
|
| 1439 | + { |
|
| 1440 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
| 1441 | + |
|
| 1442 | + if (! $DTT_ID) { |
|
| 1443 | + return false; |
|
| 1444 | + } |
|
| 1445 | + |
|
| 1446 | + $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; |
|
| 1447 | + |
|
| 1448 | + // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
|
| 1449 | + // check-in or not. |
|
| 1450 | + if (! $max_uses || $max_uses === EE_INF) { |
|
| 1451 | + return true; |
|
| 1452 | + } |
|
| 1453 | + |
|
| 1454 | + //does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
|
| 1455 | + //go ahead and toggle. |
|
| 1456 | + if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
| 1457 | + return true; |
|
| 1458 | + } |
|
| 1459 | + |
|
| 1460 | + //made it here so the last check is whether the number of checkins per unique datetime on this registration |
|
| 1461 | + //disallows further check-ins. |
|
| 1462 | + $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array( |
|
| 1463 | + array( |
|
| 1464 | + 'REG_ID' => $this->ID(), |
|
| 1465 | + 'CHK_in' => true, |
|
| 1466 | + ), |
|
| 1467 | + ), 'DTT_ID', true); |
|
| 1468 | + // checkins have already reached their max number of uses |
|
| 1469 | + // so registrant can NOT checkin |
|
| 1470 | + if ($count_unique_dtt_checkins >= $max_uses) { |
|
| 1471 | + EE_Error::add_error( |
|
| 1472 | + esc_html__( |
|
| 1473 | + 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', |
|
| 1474 | + 'event_espresso' |
|
| 1475 | + ), |
|
| 1476 | + __FILE__, |
|
| 1477 | + __FUNCTION__, |
|
| 1478 | + __LINE__ |
|
| 1479 | + ); |
|
| 1480 | + return false; |
|
| 1481 | + } |
|
| 1482 | + return true; |
|
| 1483 | + } |
|
| 1484 | + |
|
| 1485 | + |
|
| 1486 | + /** |
|
| 1487 | + * toggle Check-in status for this registration |
|
| 1488 | + * Check-ins are toggled in the following order: |
|
| 1489 | + * never checked in -> checked in |
|
| 1490 | + * checked in -> checked out |
|
| 1491 | + * checked out -> checked in |
|
| 1492 | + * |
|
| 1493 | + * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
| 1494 | + * If not included or null, then it is assumed latest datetime is being toggled. |
|
| 1495 | + * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
| 1496 | + * can be checked in or not. Otherwise this forces change in checkin status. |
|
| 1497 | + * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
| 1498 | + * @throws EE_Error |
|
| 1499 | + */ |
|
| 1500 | + public function toggle_checkin_status($DTT_ID = null, $verify = false) |
|
| 1501 | + { |
|
| 1502 | + if (empty($DTT_ID)) { |
|
| 1503 | + $datetime = $this->get_latest_related_datetime(); |
|
| 1504 | + $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
|
| 1505 | + // verify the registration can checkin for the given DTT_ID |
|
| 1506 | + } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
| 1507 | + EE_Error::add_error( |
|
| 1508 | + sprintf( |
|
| 1509 | + esc_html__( |
|
| 1510 | + 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
|
| 1511 | + 'event_espresso' |
|
| 1512 | + ), |
|
| 1513 | + $this->ID(), |
|
| 1514 | + $DTT_ID |
|
| 1515 | + ), |
|
| 1516 | + __FILE__, |
|
| 1517 | + __FUNCTION__, |
|
| 1518 | + __LINE__ |
|
| 1519 | + ); |
|
| 1520 | + return false; |
|
| 1521 | + } |
|
| 1522 | + $status_paths = array( |
|
| 1523 | + EE_Checkin::status_checked_never => EE_Checkin::status_checked_in, |
|
| 1524 | + EE_Checkin::status_checked_in => EE_Checkin::status_checked_out, |
|
| 1525 | + EE_Checkin::status_checked_out => EE_Checkin::status_checked_in, |
|
| 1526 | + ); |
|
| 1527 | + //start by getting the current status so we know what status we'll be changing to. |
|
| 1528 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
|
| 1529 | + $status_to = $status_paths[$cur_status]; |
|
| 1530 | + // database only records true for checked IN or false for checked OUT |
|
| 1531 | + // no record ( null ) means checked in NEVER, but we obviously don't save that |
|
| 1532 | + $new_status = $status_to === EE_Checkin::status_checked_in ? true : false; |
|
| 1533 | + // add relation - note Check-ins are always creating new rows |
|
| 1534 | + // because we are keeping track of Check-ins over time. |
|
| 1535 | + // Eventually we'll probably want to show a list table |
|
| 1536 | + // for the individual Check-ins so that they can be managed. |
|
| 1537 | + $checkin = EE_Checkin::new_instance(array( |
|
| 1538 | + 'REG_ID' => $this->ID(), |
|
| 1539 | + 'DTT_ID' => $DTT_ID, |
|
| 1540 | + 'CHK_in' => $new_status, |
|
| 1541 | + )); |
|
| 1542 | + // if the record could not be saved then return false |
|
| 1543 | + if ($checkin->save() === 0) { |
|
| 1544 | + if (WP_DEBUG) { |
|
| 1545 | + global $wpdb; |
|
| 1546 | + $error = sprintf( |
|
| 1547 | + esc_html__( |
|
| 1548 | + 'Registration check in update failed because of the following database error: %1$s%2$s', |
|
| 1549 | + 'event_espresso' |
|
| 1550 | + ), |
|
| 1551 | + '<br />', |
|
| 1552 | + $wpdb->last_error |
|
| 1553 | + ); |
|
| 1554 | + } else { |
|
| 1555 | + $error = esc_html__( |
|
| 1556 | + 'Registration check in update failed because of an unknown database error', |
|
| 1557 | + 'event_espresso' |
|
| 1558 | + ); |
|
| 1559 | + } |
|
| 1560 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 1561 | + return false; |
|
| 1562 | + } |
|
| 1563 | + return $status_to; |
|
| 1564 | + } |
|
| 1565 | + |
|
| 1566 | + |
|
| 1567 | + /** |
|
| 1568 | + * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
| 1569 | + * "Latest" is defined by the `DTT_EVT_start` column. |
|
| 1570 | + * |
|
| 1571 | + * @return EE_Datetime|null |
|
| 1572 | + * @throws EE_Error |
|
| 1573 | + */ |
|
| 1574 | + public function get_latest_related_datetime() |
|
| 1575 | + { |
|
| 1576 | + return EEM_Datetime::instance()->get_one( |
|
| 1577 | + array( |
|
| 1578 | + array( |
|
| 1579 | + 'Ticket.Registration.REG_ID' => $this->ID(), |
|
| 1580 | + ), |
|
| 1581 | + 'order_by' => array('DTT_EVT_start' => 'DESC'), |
|
| 1582 | + ) |
|
| 1583 | + ); |
|
| 1584 | + } |
|
| 1585 | + |
|
| 1586 | + |
|
| 1587 | + /** |
|
| 1588 | + * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
| 1589 | + * "Earliest" is defined by the `DTT_EVT_start` column. |
|
| 1590 | + * |
|
| 1591 | + * @throws EE_Error |
|
| 1592 | + */ |
|
| 1593 | + public function get_earliest_related_datetime() |
|
| 1594 | + { |
|
| 1595 | + return EEM_Datetime::instance()->get_one( |
|
| 1596 | + array( |
|
| 1597 | + array( |
|
| 1598 | + 'Ticket.Registration.REG_ID' => $this->ID(), |
|
| 1599 | + ), |
|
| 1600 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 1601 | + ) |
|
| 1602 | + ); |
|
| 1603 | + } |
|
| 1604 | + |
|
| 1605 | + |
|
| 1606 | + /** |
|
| 1607 | + * This method simply returns the check-in status for this registration and the given datetime. |
|
| 1608 | + * If neither the datetime nor the checkin values are provided as arguments, |
|
| 1609 | + * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
| 1610 | + * |
|
| 1611 | + * @param int $DTT_ID The ID of the datetime we're checking against |
|
| 1612 | + * (if empty we'll get the primary datetime for |
|
| 1613 | + * this registration (via event) and use it's ID); |
|
| 1614 | + * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
| 1615 | + * |
|
| 1616 | + * @return int Integer representing Check-in status. |
|
| 1617 | + * @throws EE_Error |
|
| 1618 | + */ |
|
| 1619 | + public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) |
|
| 1620 | + { |
|
| 1621 | + $checkin_query_params = array( |
|
| 1622 | + 'order_by' => array('CHK_timestamp' => 'DESC'), |
|
| 1623 | + ); |
|
| 1624 | + |
|
| 1625 | + if ($DTT_ID > 0) { |
|
| 1626 | + $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
| 1627 | + } |
|
| 1628 | + |
|
| 1629 | + //get checkin object (if exists) |
|
| 1630 | + $checkin = $checkin instanceof EE_Checkin |
|
| 1631 | + ? $checkin |
|
| 1632 | + : $this->get_first_related('Checkin', $checkin_query_params); |
|
| 1633 | + if ($checkin instanceof EE_Checkin) { |
|
| 1634 | + if ($checkin->get('CHK_in')) { |
|
| 1635 | + return EE_Checkin::status_checked_in; //checked in |
|
| 1636 | + } |
|
| 1637 | + return EE_Checkin::status_checked_out; //had checked in but is now checked out. |
|
| 1638 | + } |
|
| 1639 | + return EE_Checkin::status_checked_never; //never been checked in |
|
| 1640 | + } |
|
| 1641 | + |
|
| 1642 | + |
|
| 1643 | + /** |
|
| 1644 | + * This method returns a localized message for the toggled Check-in message. |
|
| 1645 | + * |
|
| 1646 | + * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, |
|
| 1647 | + * then it is assumed Check-in for primary datetime was toggled. |
|
| 1648 | + * @param bool $error This just flags that you want an error message returned. This is put in so that the error |
|
| 1649 | + * message can be customized with the attendee name. |
|
| 1650 | + * @return string internationalized message |
|
| 1651 | + * @throws EE_Error |
|
| 1652 | + */ |
|
| 1653 | + public function get_checkin_msg($DTT_ID, $error = false) |
|
| 1654 | + { |
|
| 1655 | + //let's get the attendee first so we can include the name of the attendee |
|
| 1656 | + $attendee = $this->get_first_related('Attendee'); |
|
| 1657 | + if ($attendee instanceof EE_Attendee) { |
|
| 1658 | + if ($error) { |
|
| 1659 | + return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
| 1660 | + } |
|
| 1661 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
| 1662 | + //what is the status message going to be? |
|
| 1663 | + switch ($cur_status) { |
|
| 1664 | + case EE_Checkin::status_checked_never: |
|
| 1665 | + return sprintf(__("%s has been removed from Check-in records", "event_espresso"), |
|
| 1666 | + $attendee->full_name()); |
|
| 1667 | + break; |
|
| 1668 | + case EE_Checkin::status_checked_in: |
|
| 1669 | + return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
| 1670 | + break; |
|
| 1671 | + case EE_Checkin::status_checked_out: |
|
| 1672 | + return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
| 1673 | + break; |
|
| 1674 | + } |
|
| 1675 | + } |
|
| 1676 | + return esc_html__("The check-in status could not be determined.", "event_espresso"); |
|
| 1677 | + } |
|
| 1678 | + |
|
| 1679 | + |
|
| 1680 | + /** |
|
| 1681 | + * Returns the related EE_Transaction to this registration |
|
| 1682 | + * |
|
| 1683 | + * @return EE_Transaction |
|
| 1684 | + * @throws EE_Error |
|
| 1685 | + * @throws EntityNotFoundException |
|
| 1686 | + */ |
|
| 1687 | + public function transaction() |
|
| 1688 | + { |
|
| 1689 | + $transaction = $this->get_first_related('Transaction'); |
|
| 1690 | + if (! $transaction instanceof \EE_Transaction) { |
|
| 1691 | + throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
|
| 1692 | + } |
|
| 1693 | + return $transaction; |
|
| 1694 | + } |
|
| 1695 | + |
|
| 1696 | + |
|
| 1697 | + /** |
|
| 1698 | + * get Registration Code |
|
| 1699 | + */ |
|
| 1700 | + public function reg_code() |
|
| 1701 | + { |
|
| 1702 | + return $this->get('REG_code'); |
|
| 1703 | + } |
|
| 1704 | + |
|
| 1705 | + |
|
| 1706 | + /** |
|
| 1707 | + * get Transaction ID |
|
| 1708 | + */ |
|
| 1709 | + public function transaction_ID() |
|
| 1710 | + { |
|
| 1711 | + return $this->get('TXN_ID'); |
|
| 1712 | + } |
|
| 1713 | + |
|
| 1714 | + |
|
| 1715 | + /** |
|
| 1716 | + * @return int |
|
| 1717 | + * @throws EE_Error |
|
| 1718 | + */ |
|
| 1719 | + public function ticket_ID() |
|
| 1720 | + { |
|
| 1721 | + return $this->get('TKT_ID'); |
|
| 1722 | + } |
|
| 1723 | + |
|
| 1724 | + |
|
| 1725 | + /** |
|
| 1726 | + * Set Registration Code |
|
| 1727 | + * |
|
| 1728 | + * @access public |
|
| 1729 | + * @param string $REG_code Registration Code |
|
| 1730 | + * @param boolean $use_default |
|
| 1731 | + * @throws EE_Error |
|
| 1732 | + */ |
|
| 1733 | + public function set_reg_code($REG_code, $use_default = false) |
|
| 1734 | + { |
|
| 1735 | + if (empty($REG_code)) { |
|
| 1736 | + EE_Error::add_error( |
|
| 1737 | + esc_html__('REG_code can not be empty.', 'event_espresso'), |
|
| 1738 | + __FILE__, |
|
| 1739 | + __FUNCTION__, |
|
| 1740 | + __LINE__ |
|
| 1741 | + ); |
|
| 1742 | + return; |
|
| 1743 | + } |
|
| 1744 | + if (! $this->reg_code()) { |
|
| 1745 | + parent::set('REG_code', $REG_code, $use_default); |
|
| 1746 | + } else { |
|
| 1747 | + EE_Error::doing_it_wrong( |
|
| 1748 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 1749 | + esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
| 1750 | + '4.6.0' |
|
| 1751 | + ); |
|
| 1752 | + } |
|
| 1753 | + } |
|
| 1754 | + |
|
| 1755 | + |
|
| 1756 | + /** |
|
| 1757 | + * Returns all other registrations in the same group as this registrant who have the same ticket option. |
|
| 1758 | + * Note, if you want to just get all registrations in the same transaction (group), use: |
|
| 1759 | + * $registration->transaction()->registrations(); |
|
| 1760 | + * |
|
| 1761 | + * @since 4.5.0 |
|
| 1762 | + * @return EE_Registration[] or empty array if this isn't a group registration. |
|
| 1763 | + * @throws EE_Error |
|
| 1764 | + */ |
|
| 1765 | + public function get_all_other_registrations_in_group() |
|
| 1766 | + { |
|
| 1767 | + if ($this->group_size() < 2) { |
|
| 1768 | + return array(); |
|
| 1769 | + } |
|
| 1770 | + |
|
| 1771 | + $query[0] = array( |
|
| 1772 | + 'TXN_ID' => $this->transaction_ID(), |
|
| 1773 | + 'REG_ID' => array('!=', $this->ID()), |
|
| 1774 | + 'TKT_ID' => $this->ticket_ID(), |
|
| 1775 | + ); |
|
| 1776 | + /** @var EE_Registration[] $registrations */ |
|
| 1777 | + $registrations = $this->get_model()->get_all($query); |
|
| 1778 | + return $registrations; |
|
| 1779 | + } |
|
| 1780 | + |
|
| 1781 | + /** |
|
| 1782 | + * Return the link to the admin details for the object. |
|
| 1783 | + * |
|
| 1784 | + * @return string |
|
| 1785 | + * @throws EE_Error |
|
| 1786 | + */ |
|
| 1787 | + public function get_admin_details_link() |
|
| 1788 | + { |
|
| 1789 | + EE_Registry::instance()->load_helper('URL'); |
|
| 1790 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1791 | + array( |
|
| 1792 | + 'page' => 'espresso_registrations', |
|
| 1793 | + 'action' => 'view_registration', |
|
| 1794 | + '_REG_ID' => $this->ID(), |
|
| 1795 | + ), |
|
| 1796 | + admin_url('admin.php') |
|
| 1797 | + ); |
|
| 1798 | + } |
|
| 1799 | + |
|
| 1800 | + /** |
|
| 1801 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 1802 | + * |
|
| 1803 | + * @return string |
|
| 1804 | + * @throws EE_Error |
|
| 1805 | + */ |
|
| 1806 | + public function get_admin_edit_link() |
|
| 1807 | + { |
|
| 1808 | + return $this->get_admin_details_link(); |
|
| 1809 | + } |
|
| 1810 | + |
|
| 1811 | + /** |
|
| 1812 | + * Returns the link to a settings page for the object. |
|
| 1813 | + * |
|
| 1814 | + * @return string |
|
| 1815 | + * @throws EE_Error |
|
| 1816 | + */ |
|
| 1817 | + public function get_admin_settings_link() |
|
| 1818 | + { |
|
| 1819 | + return $this->get_admin_details_link(); |
|
| 1820 | + } |
|
| 1821 | + |
|
| 1822 | + /** |
|
| 1823 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 1824 | + * |
|
| 1825 | + * @return string |
|
| 1826 | + */ |
|
| 1827 | + public function get_admin_overview_link() |
|
| 1828 | + { |
|
| 1829 | + EE_Registry::instance()->load_helper('URL'); |
|
| 1830 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1831 | + array( |
|
| 1832 | + 'page' => 'espresso_registrations', |
|
| 1833 | + ), |
|
| 1834 | + admin_url('admin.php') |
|
| 1835 | + ); |
|
| 1836 | + } |
|
| 1837 | + |
|
| 1838 | + |
|
| 1839 | + /** |
|
| 1840 | + * @param array $query_params |
|
| 1841 | + * |
|
| 1842 | + * @return \EE_Registration[] |
|
| 1843 | + * @throws EE_Error |
|
| 1844 | + */ |
|
| 1845 | + public function payments($query_params = array()) |
|
| 1846 | + { |
|
| 1847 | + return $this->get_many_related('Payment', $query_params); |
|
| 1848 | + } |
|
| 1849 | + |
|
| 1850 | + |
|
| 1851 | + /** |
|
| 1852 | + * @param array $query_params |
|
| 1853 | + * |
|
| 1854 | + * @return \EE_Registration_Payment[] |
|
| 1855 | + * @throws EE_Error |
|
| 1856 | + */ |
|
| 1857 | + public function registration_payments($query_params = array()) |
|
| 1858 | + { |
|
| 1859 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
| 1860 | + } |
|
| 1861 | + |
|
| 1862 | + |
|
| 1863 | + /** |
|
| 1864 | + * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
|
| 1865 | + * Note: if there are no payments on the registration there will be no payment method returned. |
|
| 1866 | + * |
|
| 1867 | + * @return EE_Payment_Method|null |
|
| 1868 | + */ |
|
| 1869 | + public function payment_method() |
|
| 1870 | + { |
|
| 1871 | + return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
| 1872 | + } |
|
| 1873 | + |
|
| 1874 | + |
|
| 1875 | + /** |
|
| 1876 | + * @return \EE_Line_Item |
|
| 1877 | + * @throws EntityNotFoundException |
|
| 1878 | + * @throws EE_Error |
|
| 1879 | + */ |
|
| 1880 | + public function ticket_line_item() |
|
| 1881 | + { |
|
| 1882 | + $ticket = $this->ticket(); |
|
| 1883 | + $transaction = $this->transaction(); |
|
| 1884 | + $line_item = null; |
|
| 1885 | + $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
| 1886 | + $transaction->total_line_item(), |
|
| 1887 | + 'Ticket', |
|
| 1888 | + array($ticket->ID()) |
|
| 1889 | + ); |
|
| 1890 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 1891 | + if ( |
|
| 1892 | + $ticket_line_item instanceof \EE_Line_Item |
|
| 1893 | + && $ticket_line_item->OBJ_type() === 'Ticket' |
|
| 1894 | + && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
| 1895 | + ) { |
|
| 1896 | + $line_item = $ticket_line_item; |
|
| 1897 | + break; |
|
| 1898 | + } |
|
| 1899 | + } |
|
| 1900 | + if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
| 1901 | + throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
| 1902 | + } |
|
| 1903 | + return $line_item; |
|
| 1904 | + } |
|
| 1905 | + |
|
| 1906 | + |
|
| 1907 | + /** |
|
| 1908 | + * Soft Deletes this model object. |
|
| 1909 | + * |
|
| 1910 | + * @return boolean | int |
|
| 1911 | + * @throws RuntimeException |
|
| 1912 | + * @throws EE_Error |
|
| 1913 | + */ |
|
| 1914 | + public function delete() |
|
| 1915 | + { |
|
| 1916 | + if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
| 1917 | + $this->set_status(EEM_Registration::status_id_cancelled); |
|
| 1918 | + } |
|
| 1919 | + return parent::delete(); |
|
| 1920 | + } |
|
| 1921 | + |
|
| 1922 | + |
|
| 1923 | + /** |
|
| 1924 | + * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
| 1925 | + * |
|
| 1926 | + * @throws EE_Error |
|
| 1927 | + * @throws RuntimeException |
|
| 1928 | + */ |
|
| 1929 | + public function restore() |
|
| 1930 | + { |
|
| 1931 | + $previous_status = $this->get_extra_meta( |
|
| 1932 | + EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
| 1933 | + true, |
|
| 1934 | + EEM_Registration::status_id_cancelled |
|
| 1935 | + ); |
|
| 1936 | + if ($previous_status) { |
|
| 1937 | + $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
| 1938 | + $this->set_status($previous_status); |
|
| 1939 | + } |
|
| 1940 | + return parent::restore(); |
|
| 1941 | + } |
|
| 1942 | + |
|
| 1943 | + |
|
| 1944 | + /** |
|
| 1945 | + * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price |
|
| 1946 | + * |
|
| 1947 | + * @param boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic |
|
| 1948 | + * depending on whether the reg status changes to or from "Approved" |
|
| 1949 | + * @return boolean whether the Registration status was updated |
|
| 1950 | + * @throws EE_Error |
|
| 1951 | + * @throws RuntimeException |
|
| 1952 | + */ |
|
| 1953 | + public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true) |
|
| 1954 | + { |
|
| 1955 | + $paid = $this->paid(); |
|
| 1956 | + $price = $this->final_price(); |
|
| 1957 | + switch(true) { |
|
| 1958 | + // overpaid or paid |
|
| 1959 | + case EEH_Money::compare_floats($paid, $price, '>'): |
|
| 1960 | + case EEH_Money::compare_floats($paid, $price): |
|
| 1961 | + $new_status = EEM_Registration::status_id_approved; |
|
| 1962 | + break; |
|
| 1963 | + // underpaid |
|
| 1964 | + case EEH_Money::compare_floats($paid, $price, '<'): |
|
| 1965 | + $new_status = EEM_Registration::status_id_pending_payment; |
|
| 1966 | + break; |
|
| 1967 | + // uhhh Houston... |
|
| 1968 | + default: |
|
| 1969 | + throw new RuntimeException( |
|
| 1970 | + esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso') |
|
| 1971 | + ); |
|
| 1972 | + } |
|
| 1973 | + if ($new_status !== $this->status_ID()) { |
|
| 1974 | + if ($trigger_set_status_logic) { |
|
| 1975 | + return $this->set_status($new_status); |
|
| 1976 | + } |
|
| 1977 | + parent::set('STS_ID', $new_status); |
|
| 1978 | + return true; |
|
| 1979 | + } |
|
| 1980 | + return false; |
|
| 1981 | + } |
|
| 1982 | + |
|
| 1983 | + |
|
| 1984 | + /*************************** DEPRECATED ***************************/ |
|
| 1985 | + |
|
| 1986 | + |
|
| 1987 | + /** |
|
| 1988 | + * @deprecated |
|
| 1989 | + * @since 4.7.0 |
|
| 1990 | + * @access public |
|
| 1991 | + */ |
|
| 1992 | + public function price_paid() |
|
| 1993 | + { |
|
| 1994 | + EE_Error::doing_it_wrong('EE_Registration::price_paid()', |
|
| 1995 | + esc_html__('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'), |
|
| 1996 | + '4.7.0'); |
|
| 1997 | + return $this->final_price(); |
|
| 1998 | + } |
|
| 1999 | + |
|
| 2000 | + |
|
| 2001 | + /** |
|
| 2002 | + * @deprecated |
|
| 2003 | + * @since 4.7.0 |
|
| 2004 | + * @access public |
|
| 2005 | + * @param float $REG_final_price |
|
| 2006 | + * @throws EE_Error |
|
| 2007 | + * @throws RuntimeException |
|
| 2008 | + */ |
|
| 2009 | + public function set_price_paid($REG_final_price = 0.00) |
|
| 2010 | + { |
|
| 2011 | + EE_Error::doing_it_wrong('EE_Registration::set_price_paid()', |
|
| 2012 | + esc_html__('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'), |
|
| 2013 | + '4.7.0'); |
|
| 2014 | + $this->set_final_price($REG_final_price); |
|
| 2015 | + } |
|
| 2016 | + |
|
| 2017 | + |
|
| 2018 | + /** |
|
| 2019 | + * @deprecated |
|
| 2020 | + * @since 4.7.0 |
|
| 2021 | + * @return string |
|
| 2022 | + * @throws EE_Error |
|
| 2023 | + */ |
|
| 2024 | + public function pretty_price_paid() |
|
| 2025 | + { |
|
| 2026 | + EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()', |
|
| 2027 | + esc_html__('This method is deprecated, please use EE_Registration::pretty_final_price() instead.', |
|
| 2028 | + 'event_espresso'), '4.7.0'); |
|
| 2029 | + return $this->pretty_final_price(); |
|
| 2030 | + } |
|
| 2031 | + |
|
| 2032 | + |
|
| 2033 | + /** |
|
| 2034 | + * Gets the primary datetime related to this registration via the related Event to this registration |
|
| 2035 | + * |
|
| 2036 | + * @deprecated 4.9.17 |
|
| 2037 | + * @return EE_Datetime |
|
| 2038 | + * @throws EE_Error |
|
| 2039 | + * @throws EntityNotFoundException |
|
| 2040 | + */ |
|
| 2041 | + public function get_related_primary_datetime() |
|
| 2042 | + { |
|
| 2043 | + EE_Error::doing_it_wrong( |
|
| 2044 | + __METHOD__, |
|
| 2045 | + esc_html__( |
|
| 2046 | + 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
| 2047 | + 'event_espresso' |
|
| 2048 | + ), |
|
| 2049 | + '4.9.17', |
|
| 2050 | + '5.0.0' |
|
| 2051 | + ); |
|
| 2052 | + return $this->event()->primary_datetime(); |
|
| 2053 | + } |
|
| 2054 | 2054 | |
| 2055 | 2055 | |
| 2056 | 2056 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | { |
| 122 | 122 | switch ($field_name) { |
| 123 | 123 | case 'REG_code': |
| 124 | - if (! empty($field_value) && $this->reg_code() === null) { |
|
| 124 | + if ( ! empty($field_value) && $this->reg_code() === null) { |
|
| 125 | 125 | $this->set_reg_code($field_value, $use_default); |
| 126 | 126 | } |
| 127 | 127 | break; |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | // update status |
| 183 | 183 | parent::set('STS_ID', $new_STS_ID, $use_default); |
| 184 | 184 | $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, $context); |
| 185 | - if($this->statusChangeUpdatesTransaction($context)) { |
|
| 185 | + if ($this->statusChangeUpdatesTransaction($context)) { |
|
| 186 | 186 | $this->updateTransactionAfterStatusChange(); |
| 187 | 187 | } |
| 188 | 188 | do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context); |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | public function event() |
| 391 | 391 | { |
| 392 | 392 | $event = $this->get_first_related('Event'); |
| 393 | - if (! $event instanceof \EE_Event) { |
|
| 393 | + if ( ! $event instanceof \EE_Event) { |
|
| 394 | 394 | throw new EntityNotFoundException('Event ID', $this->event_ID()); |
| 395 | 395 | } |
| 396 | 396 | return $event; |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | { |
| 434 | 434 | // reserved ticket and datetime counts will be decremented as sold counts are incremented |
| 435 | 435 | // so stop tracking that this reg has a ticket reserved |
| 436 | - $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 436 | + $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:".__LINE__.')'); |
|
| 437 | 437 | $ticket = $this->ticket(); |
| 438 | 438 | $ticket->increase_sold(); |
| 439 | 439 | $ticket->save(); |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | && $update_ticket |
| 491 | 491 | ) { |
| 492 | 492 | $ticket = $this->ticket(); |
| 493 | - $ticket->increase_reserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 493 | + $ticket->increase_reserved(1, "REG: {$this->ID()} (ln:".__LINE__.')'); |
|
| 494 | 494 | $ticket->save(); |
| 495 | 495 | } |
| 496 | 496 | } |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | && $update_ticket |
| 523 | 523 | ) { |
| 524 | 524 | $ticket = $this->ticket(); |
| 525 | - $ticket->decrease_reserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 525 | + $ticket->decrease_reserved(1, true, "REG: {$this->ID()} (ln:".__LINE__.')'); |
|
| 526 | 526 | $ticket->save(); |
| 527 | 527 | } |
| 528 | 528 | } |
@@ -1154,7 +1154,7 @@ discard block |
||
| 1154 | 1154 | false, |
| 1155 | 1155 | 'sentence' |
| 1156 | 1156 | ); |
| 1157 | - $icon = ''; |
|
| 1157 | + $icon = ''; |
|
| 1158 | 1158 | switch ($this->status_ID()) { |
| 1159 | 1159 | case EEM_Registration::status_id_approved: |
| 1160 | 1160 | $icon = $show_icons |
@@ -1192,7 +1192,7 @@ discard block |
||
| 1192 | 1192 | : ''; |
| 1193 | 1193 | break; |
| 1194 | 1194 | } |
| 1195 | - return $icon . $status[$this->status_ID()]; |
|
| 1195 | + return $icon.$status[$this->status_ID()]; |
|
| 1196 | 1196 | } |
| 1197 | 1197 | |
| 1198 | 1198 | |
@@ -1410,7 +1410,7 @@ discard block |
||
| 1410 | 1410 | return false; |
| 1411 | 1411 | } |
| 1412 | 1412 | //is there a datetime ticket that matches this dtt_ID? |
| 1413 | - if (! (EEM_Datetime_Ticket::instance()->exists(array( |
|
| 1413 | + if ( ! (EEM_Datetime_Ticket::instance()->exists(array( |
|
| 1414 | 1414 | array( |
| 1415 | 1415 | 'TKT_ID' => $this->get('TKT_ID'), |
| 1416 | 1416 | 'DTT_ID' => $DTT_ID, |
@@ -1439,7 +1439,7 @@ discard block |
||
| 1439 | 1439 | { |
| 1440 | 1440 | $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
| 1441 | 1441 | |
| 1442 | - if (! $DTT_ID) { |
|
| 1442 | + if ( ! $DTT_ID) { |
|
| 1443 | 1443 | return false; |
| 1444 | 1444 | } |
| 1445 | 1445 | |
@@ -1447,7 +1447,7 @@ discard block |
||
| 1447 | 1447 | |
| 1448 | 1448 | // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
| 1449 | 1449 | // check-in or not. |
| 1450 | - if (! $max_uses || $max_uses === EE_INF) { |
|
| 1450 | + if ( ! $max_uses || $max_uses === EE_INF) { |
|
| 1451 | 1451 | return true; |
| 1452 | 1452 | } |
| 1453 | 1453 | |
@@ -1503,7 +1503,7 @@ discard block |
||
| 1503 | 1503 | $datetime = $this->get_latest_related_datetime(); |
| 1504 | 1504 | $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
| 1505 | 1505 | // verify the registration can checkin for the given DTT_ID |
| 1506 | - } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
| 1506 | + } elseif ( ! $this->can_checkin($DTT_ID, $verify)) { |
|
| 1507 | 1507 | EE_Error::add_error( |
| 1508 | 1508 | sprintf( |
| 1509 | 1509 | esc_html__( |
@@ -1687,7 +1687,7 @@ discard block |
||
| 1687 | 1687 | public function transaction() |
| 1688 | 1688 | { |
| 1689 | 1689 | $transaction = $this->get_first_related('Transaction'); |
| 1690 | - if (! $transaction instanceof \EE_Transaction) { |
|
| 1690 | + if ( ! $transaction instanceof \EE_Transaction) { |
|
| 1691 | 1691 | throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
| 1692 | 1692 | } |
| 1693 | 1693 | return $transaction; |
@@ -1741,11 +1741,11 @@ discard block |
||
| 1741 | 1741 | ); |
| 1742 | 1742 | return; |
| 1743 | 1743 | } |
| 1744 | - if (! $this->reg_code()) { |
|
| 1744 | + if ( ! $this->reg_code()) { |
|
| 1745 | 1745 | parent::set('REG_code', $REG_code, $use_default); |
| 1746 | 1746 | } else { |
| 1747 | 1747 | EE_Error::doing_it_wrong( |
| 1748 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 1748 | + __CLASS__.'::'.__FUNCTION__, |
|
| 1749 | 1749 | esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
| 1750 | 1750 | '4.6.0' |
| 1751 | 1751 | ); |
@@ -1897,7 +1897,7 @@ discard block |
||
| 1897 | 1897 | break; |
| 1898 | 1898 | } |
| 1899 | 1899 | } |
| 1900 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
| 1900 | + if ( ! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
| 1901 | 1901 | throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
| 1902 | 1902 | } |
| 1903 | 1903 | return $line_item; |
@@ -1954,7 +1954,7 @@ discard block |
||
| 1954 | 1954 | { |
| 1955 | 1955 | $paid = $this->paid(); |
| 1956 | 1956 | $price = $this->final_price(); |
| 1957 | - switch(true) { |
|
| 1957 | + switch (true) { |
|
| 1958 | 1958 | // overpaid or paid |
| 1959 | 1959 | case EEH_Money::compare_floats($paid, $price, '>'): |
| 1960 | 1960 | case EEH_Money::compare_floats($paid, $price): |
@@ -19,94 +19,94 @@ |
||
| 19 | 19 | class ExitModal |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var Registry |
|
| 24 | - */ |
|
| 25 | - private $assets_registry; |
|
| 22 | + /** |
|
| 23 | + * @var Registry |
|
| 24 | + */ |
|
| 25 | + private $assets_registry; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * ExitModal constructor. |
|
| 29 | - * |
|
| 30 | - * @param Registry $assets_registry |
|
| 31 | - */ |
|
| 32 | - public function __construct(Registry $assets_registry) |
|
| 33 | - { |
|
| 34 | - $this->assets_registry = $assets_registry; |
|
| 35 | - add_action('in_admin_footer', array($this, 'modalContainer')); |
|
| 36 | - add_action('admin_enqueue_scripts', array($this, 'enqueues')); |
|
| 37 | - } |
|
| 27 | + /** |
|
| 28 | + * ExitModal constructor. |
|
| 29 | + * |
|
| 30 | + * @param Registry $assets_registry |
|
| 31 | + */ |
|
| 32 | + public function __construct(Registry $assets_registry) |
|
| 33 | + { |
|
| 34 | + $this->assets_registry = $assets_registry; |
|
| 35 | + add_action('in_admin_footer', array($this, 'modalContainer')); |
|
| 36 | + add_action('admin_enqueue_scripts', array($this, 'enqueues')); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Callback on in_admin_footer that is used to output the exit modal container. |
|
| 42 | - */ |
|
| 43 | - public function modalContainer() |
|
| 44 | - { |
|
| 45 | - echo '<div id="ee-exit-survey-modal"></div>'; |
|
| 46 | - } |
|
| 40 | + /** |
|
| 41 | + * Callback on in_admin_footer that is used to output the exit modal container. |
|
| 42 | + */ |
|
| 43 | + public function modalContainer() |
|
| 44 | + { |
|
| 45 | + echo '<div id="ee-exit-survey-modal"></div>'; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal. |
|
| 51 | - * |
|
| 52 | - * @throws InvalidArgumentException |
|
| 53 | - */ |
|
| 54 | - public function enqueues() |
|
| 55 | - { |
|
| 56 | - $current_user = new WP_User(get_current_user_id()); |
|
| 57 | - $this->assets_registry->addData( |
|
| 58 | - 'exitModali18n', |
|
| 59 | - array( |
|
| 60 | - 'introText' => htmlspecialchars( |
|
| 61 | - __( |
|
| 62 | - 'Do you have a moment to share why you are deactivating Event Espresso?', |
|
| 63 | - 'event_espresso' |
|
| 64 | - ), |
|
| 65 | - ENT_NOQUOTES |
|
| 66 | - ), |
|
| 67 | - 'doSurveyButtonText' => htmlspecialchars( |
|
| 68 | - __( |
|
| 69 | - 'Sure I\'ll help', |
|
| 70 | - 'event_espresso' |
|
| 71 | - ), |
|
| 72 | - ENT_NOQUOTES |
|
| 73 | - ), |
|
| 74 | - 'skipButtonText' => htmlspecialchars( |
|
| 75 | - __( |
|
| 76 | - 'Skip', |
|
| 77 | - 'event_espresso' |
|
| 78 | - ), |
|
| 79 | - ENT_NOQUOTES |
|
| 80 | - ) |
|
| 81 | - ) |
|
| 82 | - ); |
|
| 83 | - $this->assets_registry->addData( |
|
| 84 | - 'exitModalInfo', |
|
| 85 | - array( |
|
| 86 | - 'firstname' => htmlspecialchars($current_user->user_firstname), |
|
| 87 | - 'emailaddress' => htmlspecialchars($current_user->user_email), |
|
| 88 | - 'website' => htmlspecialchars(site_url()), |
|
| 89 | - 'isModalActive' => $this->isModalActive() |
|
| 90 | - ) |
|
| 91 | - ); |
|
| 49 | + /** |
|
| 50 | + * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal. |
|
| 51 | + * |
|
| 52 | + * @throws InvalidArgumentException |
|
| 53 | + */ |
|
| 54 | + public function enqueues() |
|
| 55 | + { |
|
| 56 | + $current_user = new WP_User(get_current_user_id()); |
|
| 57 | + $this->assets_registry->addData( |
|
| 58 | + 'exitModali18n', |
|
| 59 | + array( |
|
| 60 | + 'introText' => htmlspecialchars( |
|
| 61 | + __( |
|
| 62 | + 'Do you have a moment to share why you are deactivating Event Espresso?', |
|
| 63 | + 'event_espresso' |
|
| 64 | + ), |
|
| 65 | + ENT_NOQUOTES |
|
| 66 | + ), |
|
| 67 | + 'doSurveyButtonText' => htmlspecialchars( |
|
| 68 | + __( |
|
| 69 | + 'Sure I\'ll help', |
|
| 70 | + 'event_espresso' |
|
| 71 | + ), |
|
| 72 | + ENT_NOQUOTES |
|
| 73 | + ), |
|
| 74 | + 'skipButtonText' => htmlspecialchars( |
|
| 75 | + __( |
|
| 76 | + 'Skip', |
|
| 77 | + 'event_espresso' |
|
| 78 | + ), |
|
| 79 | + ENT_NOQUOTES |
|
| 80 | + ) |
|
| 81 | + ) |
|
| 82 | + ); |
|
| 83 | + $this->assets_registry->addData( |
|
| 84 | + 'exitModalInfo', |
|
| 85 | + array( |
|
| 86 | + 'firstname' => htmlspecialchars($current_user->user_firstname), |
|
| 87 | + 'emailaddress' => htmlspecialchars($current_user->user_email), |
|
| 88 | + 'website' => htmlspecialchars(site_url()), |
|
| 89 | + 'isModalActive' => $this->isModalActive() |
|
| 90 | + ) |
|
| 91 | + ); |
|
| 92 | 92 | |
| 93 | - wp_enqueue_script('ee-wp-plugins-page'); |
|
| 94 | - wp_enqueue_style('ee-wp-plugins-page'); |
|
| 95 | - } |
|
| 93 | + wp_enqueue_script('ee-wp-plugins-page'); |
|
| 94 | + wp_enqueue_style('ee-wp-plugins-page'); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Exposes a filter switch for turning off the enqueueing of the modal script. |
|
| 100 | - * @return bool |
|
| 101 | - */ |
|
| 102 | - private function isModalActive() |
|
| 103 | - { |
|
| 104 | - return filter_var( |
|
| 105 | - apply_filters( |
|
| 106 | - 'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive', |
|
| 107 | - true |
|
| 108 | - ), |
|
| 109 | - FILTER_VALIDATE_BOOLEAN |
|
| 110 | - ); |
|
| 111 | - } |
|
| 98 | + /** |
|
| 99 | + * Exposes a filter switch for turning off the enqueueing of the modal script. |
|
| 100 | + * @return bool |
|
| 101 | + */ |
|
| 102 | + private function isModalActive() |
|
| 103 | + { |
|
| 104 | + return filter_var( |
|
| 105 | + apply_filters( |
|
| 106 | + 'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive', |
|
| 107 | + true |
|
| 108 | + ), |
|
| 109 | + FILTER_VALIDATE_BOOLEAN |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -26,1260 +26,1260 @@ |
||
| 26 | 26 | class EED_Core_Rest_Api extends \EED_Module |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - const ee_api_namespace = Domain::API_NAMESPACE; |
|
| 29 | + const ee_api_namespace = Domain::API_NAMESPACE; |
|
| 30 | 30 | |
| 31 | - const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
| 32 | - |
|
| 33 | - const saved_routes_option_names = 'ee_core_routes'; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * string used in _links response bodies to make them globally unique. |
|
| 37 | - * |
|
| 38 | - * @see http://v2.wp-api.org/extending/linking/ |
|
| 39 | - */ |
|
| 40 | - const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var CalculatedModelFields |
|
| 44 | - */ |
|
| 45 | - protected static $_field_calculator; |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @return EED_Core_Rest_Api|EED_Module |
|
| 51 | - */ |
|
| 52 | - public static function instance() |
|
| 53 | - { |
|
| 54 | - self::$_field_calculator = new CalculatedModelFields(); |
|
| 55 | - return parent::get_instance(__CLASS__); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 62 | - * |
|
| 63 | - * @access public |
|
| 64 | - * @return void |
|
| 65 | - */ |
|
| 66 | - public static function set_hooks() |
|
| 67 | - { |
|
| 68 | - self::set_hooks_both(); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 75 | - * |
|
| 76 | - * @access public |
|
| 77 | - * @return void |
|
| 78 | - */ |
|
| 79 | - public static function set_hooks_admin() |
|
| 80 | - { |
|
| 81 | - self::set_hooks_both(); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - public static function set_hooks_both() |
|
| 87 | - { |
|
| 88 | - add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10); |
|
| 89 | - add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5); |
|
| 90 | - add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2); |
|
| 91 | - add_filter('rest_index', |
|
| 92 | - array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex')); |
|
| 93 | - EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * sets up hooks which only need to be included as part of REST API requests; |
|
| 100 | - * other requests like to the frontend or admin etc don't need them |
|
| 101 | - * |
|
| 102 | - * @throws \EE_Error |
|
| 103 | - */ |
|
| 104 | - public static function set_hooks_rest_api() |
|
| 105 | - { |
|
| 106 | - //set hooks which account for changes made to the API |
|
| 107 | - EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * public wrapper of _set_hooks_for_changes. |
|
| 114 | - * Loads all the hooks which make requests to old versions of the API |
|
| 115 | - * appear the same as they always did |
|
| 116 | - * |
|
| 117 | - * @throws EE_Error |
|
| 118 | - */ |
|
| 119 | - public static function set_hooks_for_changes() |
|
| 120 | - { |
|
| 121 | - self::_set_hooks_for_changes(); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Loads all the hooks which make requests to old versions of the API |
|
| 128 | - * appear the same as they always did |
|
| 129 | - * |
|
| 130 | - * @throws EE_Error |
|
| 131 | - */ |
|
| 132 | - protected static function _set_hooks_for_changes() |
|
| 133 | - { |
|
| 134 | - $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false); |
|
| 135 | - foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
| 136 | - //ignore the base parent class |
|
| 137 | - //and legacy named classes |
|
| 138 | - if ($classname_in_namespace === 'ChangesInBase' |
|
| 139 | - || strpos($classname_in_namespace, 'Changes_In_') === 0 |
|
| 140 | - ) { |
|
| 141 | - continue; |
|
| 142 | - } |
|
| 143 | - $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
| 144 | - if (class_exists($full_classname)) { |
|
| 145 | - $instance_of_class = new $full_classname; |
|
| 146 | - if ($instance_of_class instanceof ChangesInBase) { |
|
| 147 | - $instance_of_class->setHooks(); |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
| 157 | - * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
| 158 | - * |
|
| 159 | - * @throws \EE_Error |
|
| 160 | - */ |
|
| 161 | - public static function register_routes() |
|
| 162 | - { |
|
| 163 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) { |
|
| 164 | - foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) { |
|
| 165 | - /** |
|
| 166 | - * @var array $data_for_multiple_endpoints numerically indexed array |
|
| 167 | - * but can also contain route options like { |
|
| 168 | - * @type array $schema { |
|
| 169 | - * @type callable $schema_callback |
|
| 170 | - * @type array $callback_args arguments that will be passed to the callback, after the |
|
| 171 | - * WP_REST_Request of course |
|
| 172 | - * } |
|
| 173 | - * } |
|
| 174 | - */ |
|
| 175 | - //when registering routes, register all the endpoints' data at the same time |
|
| 176 | - $multiple_endpoint_args = array(); |
|
| 177 | - foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) { |
|
| 178 | - /** |
|
| 179 | - * @var array $data_for_single_endpoint { |
|
| 180 | - * @type callable $callback |
|
| 181 | - * @type string methods |
|
| 182 | - * @type array args |
|
| 183 | - * @type array _links |
|
| 184 | - * @type array $callback_args arguments that will be passed to the callback, after the |
|
| 185 | - * WP_REST_Request of course |
|
| 186 | - * } |
|
| 187 | - */ |
|
| 188 | - //skip route options |
|
| 189 | - if (! is_numeric($endpoint_key)) { |
|
| 190 | - continue; |
|
| 191 | - } |
|
| 192 | - if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
| 193 | - throw new EE_Error( |
|
| 194 | - esc_html__( |
|
| 195 | - // @codingStandardsIgnoreStart |
|
| 196 | - 'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).', |
|
| 197 | - // @codingStandardsIgnoreEnd |
|
| 198 | - 'event_espresso') |
|
| 199 | - ); |
|
| 200 | - } |
|
| 201 | - $callback = $data_for_single_endpoint['callback']; |
|
| 202 | - $single_endpoint_args = array( |
|
| 203 | - 'methods' => $data_for_single_endpoint['methods'], |
|
| 204 | - 'args' => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args'] |
|
| 205 | - : array(), |
|
| 206 | - ); |
|
| 207 | - if (isset($data_for_single_endpoint['_links'])) { |
|
| 208 | - $single_endpoint_args['_links'] = $data_for_single_endpoint['_links']; |
|
| 209 | - } |
|
| 210 | - if (isset($data_for_single_endpoint['callback_args'])) { |
|
| 211 | - $callback_args = $data_for_single_endpoint['callback_args']; |
|
| 212 | - $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use ( |
|
| 213 | - $callback, |
|
| 214 | - $callback_args |
|
| 215 | - ) { |
|
| 216 | - array_unshift($callback_args, $request); |
|
| 217 | - return call_user_func_array( |
|
| 218 | - $callback, |
|
| 219 | - $callback_args |
|
| 220 | - ); |
|
| 221 | - }; |
|
| 222 | - } else { |
|
| 223 | - $single_endpoint_args['callback'] = $data_for_single_endpoint['callback']; |
|
| 224 | - } |
|
| 225 | - $multiple_endpoint_args[] = $single_endpoint_args; |
|
| 226 | - } |
|
| 227 | - if (isset($data_for_multiple_endpoints['schema'])) { |
|
| 228 | - $schema_route_data = $data_for_multiple_endpoints['schema']; |
|
| 229 | - $schema_callback = $schema_route_data['schema_callback']; |
|
| 230 | - $callback_args = $schema_route_data['callback_args']; |
|
| 231 | - $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) { |
|
| 232 | - return call_user_func_array( |
|
| 233 | - $schema_callback, |
|
| 234 | - $callback_args |
|
| 235 | - ); |
|
| 236 | - }; |
|
| 237 | - } |
|
| 238 | - register_rest_route( |
|
| 239 | - $namespace, |
|
| 240 | - $relative_route, |
|
| 241 | - $multiple_endpoint_args |
|
| 242 | - ); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Checks if there was a version change or something that merits invalidating the cached |
|
| 251 | - * route data. If so, invalidates the cached route data so that it gets refreshed |
|
| 252 | - * next time the WP API is used |
|
| 253 | - */ |
|
| 254 | - public static function invalidate_cached_route_data_on_version_change() |
|
| 255 | - { |
|
| 256 | - if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) { |
|
| 257 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
| 258 | - } |
|
| 259 | - foreach (EE_Registry::instance()->addons as $addon) { |
|
| 260 | - if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) { |
|
| 261 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Removes the cached route data so it will get refreshed next time the WP API is used |
|
| 270 | - */ |
|
| 271 | - public static function invalidate_cached_route_data() |
|
| 272 | - { |
|
| 273 | - //delete the saved EE REST API routes |
|
| 274 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
| 275 | - delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Gets the EE route data |
|
| 283 | - * |
|
| 284 | - * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
| 285 | - * @throws \EE_Error |
|
| 286 | - * @type string|array $callback |
|
| 287 | - * @type string $methods |
|
| 288 | - * @type boolean $hidden_endpoint |
|
| 289 | - * } |
|
| 290 | - */ |
|
| 291 | - public static function get_ee_route_data() |
|
| 292 | - { |
|
| 293 | - $ee_routes = array(); |
|
| 294 | - foreach (self::versions_served() as $version => $hidden_endpoints) { |
|
| 295 | - $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version( |
|
| 296 | - $version, |
|
| 297 | - $hidden_endpoints |
|
| 298 | - ); |
|
| 299 | - } |
|
| 300 | - return $ee_routes; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Gets the EE route data from the wp options if it exists already, |
|
| 307 | - * otherwise re-generates it and saves it to the option |
|
| 308 | - * |
|
| 309 | - * @param string $version |
|
| 310 | - * @param boolean $hidden_endpoints |
|
| 311 | - * @return array |
|
| 312 | - * @throws \EE_Error |
|
| 313 | - */ |
|
| 314 | - protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 315 | - { |
|
| 316 | - $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
| 317 | - if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
| 318 | - $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
| 319 | - } |
|
| 320 | - return $ee_routes; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Saves the EE REST API route data to a wp option and returns it |
|
| 327 | - * |
|
| 328 | - * @param string $version |
|
| 329 | - * @param boolean $hidden_endpoints |
|
| 330 | - * @return mixed|null |
|
| 331 | - * @throws \EE_Error |
|
| 332 | - */ |
|
| 333 | - protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 334 | - { |
|
| 335 | - $instance = self::instance(); |
|
| 336 | - $routes = apply_filters( |
|
| 337 | - 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
| 338 | - array_replace_recursive( |
|
| 339 | - $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
| 340 | - $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
| 341 | - $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
| 342 | - $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
| 343 | - ) |
|
| 344 | - ); |
|
| 345 | - $option_name = self::saved_routes_option_names . $version; |
|
| 346 | - if (get_option($option_name)) { |
|
| 347 | - update_option($option_name, $routes, true); |
|
| 348 | - } else { |
|
| 349 | - add_option($option_name, $routes, null, 'no'); |
|
| 350 | - } |
|
| 351 | - return $routes; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Calculates all the EE routes and saves it to a WordPress option so we don't |
|
| 358 | - * need to calculate it on every request |
|
| 359 | - * |
|
| 360 | - * @deprecated since version 4.9.1 |
|
| 361 | - * @return void |
|
| 362 | - */ |
|
| 363 | - public static function save_ee_routes() |
|
| 364 | - { |
|
| 365 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 366 | - $instance = self::instance(); |
|
| 367 | - $routes = apply_filters( |
|
| 368 | - 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
| 369 | - array_replace_recursive( |
|
| 370 | - $instance->_register_config_routes(), |
|
| 371 | - $instance->_register_meta_routes(), |
|
| 372 | - $instance->_register_model_routes(), |
|
| 373 | - $instance->_register_rpc_routes() |
|
| 374 | - ) |
|
| 375 | - ); |
|
| 376 | - update_option(self::saved_routes_option_names, $routes, true); |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Gets all the route information relating to EE models |
|
| 384 | - * |
|
| 385 | - * @return array @see get_ee_route_data |
|
| 386 | - * @deprecated since version 4.9.1 |
|
| 387 | - */ |
|
| 388 | - protected function _register_model_routes() |
|
| 389 | - { |
|
| 390 | - $model_routes = array(); |
|
| 391 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 392 | - $model_routes[EED_Core_Rest_Api::ee_api_namespace |
|
| 393 | - . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
| 394 | - } |
|
| 395 | - return $model_routes; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * Decides whether or not to add write endpoints for this model. |
|
| 402 | - * |
|
| 403 | - * Currently, this defaults to exclude all global tables and models |
|
| 404 | - * which would allow inserting WP core data (we don't want to duplicate |
|
| 405 | - * what WP API does, as it's unnecessary, extra work, and potentially extra bugs) |
|
| 406 | - * @param EEM_Base $model |
|
| 407 | - * @return bool |
|
| 408 | - */ |
|
| 409 | - public static function should_have_write_endpoints(EEM_Base $model) |
|
| 410 | - { |
|
| 411 | - if ($model->is_wp_core_model()){ |
|
| 412 | - return false; |
|
| 413 | - } |
|
| 414 | - foreach($model->get_tables() as $table){ |
|
| 415 | - if( $table->is_global()){ |
|
| 416 | - return false; |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - return true; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`) |
|
| 426 | - * in this versioned namespace of EE4 |
|
| 427 | - * @param $version |
|
| 428 | - * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event') |
|
| 429 | - */ |
|
| 430 | - public static function model_names_with_plural_routes($version){ |
|
| 431 | - $model_version_info = new ModelVersionInfo($version); |
|
| 432 | - $models_to_register = $model_version_info->modelsForRequestedVersion(); |
|
| 433 | - //let's not bother having endpoints for extra metas |
|
| 434 | - unset( |
|
| 435 | - $models_to_register['Extra_Meta'], |
|
| 436 | - $models_to_register['Extra_Join'], |
|
| 437 | - $models_to_register['Post_Meta'] |
|
| 438 | - ); |
|
| 439 | - return apply_filters( |
|
| 440 | - 'FHEE__EED_Core_REST_API___register_model_routes', |
|
| 441 | - $models_to_register |
|
| 442 | - ); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Gets the route data for EE models in the specified version |
|
| 449 | - * |
|
| 450 | - * @param string $version |
|
| 451 | - * @param boolean $hidden_endpoint |
|
| 452 | - * @return array |
|
| 453 | - * @throws EE_Error |
|
| 454 | - */ |
|
| 455 | - protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
| 456 | - { |
|
| 457 | - $model_routes = array(); |
|
| 458 | - $model_version_info = new ModelVersionInfo($version); |
|
| 459 | - foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
|
| 460 | - $model = \EE_Registry::instance()->load_model($model_name); |
|
| 461 | - //if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
| 462 | - if (! $model instanceof EEM_Base) { |
|
| 463 | - continue; |
|
| 464 | - } |
|
| 465 | - //yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
| 466 | - $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
|
| 467 | - $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
|
| 468 | - $model_routes[$plural_model_route] = array( |
|
| 469 | - array( |
|
| 470 | - 'callback' => array( |
|
| 471 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 472 | - 'handleRequestGetAll', |
|
| 473 | - ), |
|
| 474 | - 'callback_args' => array($version, $model_name), |
|
| 475 | - 'methods' => WP_REST_Server::READABLE, |
|
| 476 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 477 | - 'args' => $this->_get_read_query_params($model, $version), |
|
| 478 | - '_links' => array( |
|
| 479 | - 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
| 480 | - ), |
|
| 481 | - ), |
|
| 482 | - 'schema' => array( |
|
| 483 | - 'schema_callback' => array( |
|
| 484 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 485 | - 'handleSchemaRequest', |
|
| 486 | - ), |
|
| 487 | - 'callback_args' => array($version, $model_name), |
|
| 488 | - ), |
|
| 489 | - ); |
|
| 490 | - $model_routes[$singular_model_route] = array( |
|
| 491 | - array( |
|
| 492 | - 'callback' => array( |
|
| 493 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 494 | - 'handleRequestGetOne', |
|
| 495 | - ), |
|
| 496 | - 'callback_args' => array($version, $model_name), |
|
| 497 | - 'methods' => WP_REST_Server::READABLE, |
|
| 498 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 499 | - 'args' => $this->_get_response_selection_query_params($model, $version), |
|
| 500 | - ), |
|
| 501 | - ); |
|
| 502 | - if( apply_filters( |
|
| 503 | - 'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints', |
|
| 504 | - EED_Core_Rest_Api::should_have_write_endpoints($model), |
|
| 505 | - $model |
|
| 506 | - )){ |
|
| 507 | - $model_routes[$plural_model_route][] = array( |
|
| 508 | - 'callback' => array( |
|
| 509 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 510 | - 'handleRequestInsert', |
|
| 511 | - ), |
|
| 512 | - 'callback_args' => array($version, $model_name), |
|
| 513 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 514 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 515 | - 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
|
| 516 | - ); |
|
| 517 | - $model_routes[$singular_model_route] = array_merge( |
|
| 518 | - $model_routes[$singular_model_route], |
|
| 519 | - array( |
|
| 520 | - array( |
|
| 521 | - 'callback' => array( |
|
| 522 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 523 | - 'handleRequestUpdate', |
|
| 524 | - ), |
|
| 525 | - 'callback_args' => array($version, $model_name), |
|
| 526 | - 'methods' => WP_REST_Server::EDITABLE, |
|
| 527 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 528 | - 'args' => $this->_get_write_params($model_name, $model_version_info), |
|
| 529 | - ), |
|
| 530 | - array( |
|
| 531 | - 'callback' => array( |
|
| 532 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 533 | - 'handleRequestDelete', |
|
| 534 | - ), |
|
| 535 | - 'callback_args' => array($version, $model_name), |
|
| 536 | - 'methods' => WP_REST_Server::DELETABLE, |
|
| 537 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 538 | - 'args' => $this->_get_delete_query_params($model, $version), |
|
| 539 | - ) |
|
| 540 | - ) |
|
| 541 | - ); |
|
| 542 | - } |
|
| 543 | - foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
| 544 | - |
|
| 545 | - $related_route = EED_Core_Rest_Api::get_relation_route_via( |
|
| 546 | - $model, |
|
| 547 | - '(?P<id>[^\/]+)', |
|
| 548 | - $relation_obj |
|
| 549 | - ); |
|
| 550 | - $endpoints = array( |
|
| 551 | - array( |
|
| 552 | - 'callback' => array( |
|
| 553 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 554 | - 'handleRequestGetRelated', |
|
| 555 | - ), |
|
| 556 | - 'callback_args' => array($version, $model_name, $relation_name), |
|
| 557 | - 'methods' => WP_REST_Server::READABLE, |
|
| 558 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 559 | - 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
| 560 | - ), |
|
| 561 | - ); |
|
| 562 | - $model_routes[$related_route] = $endpoints; |
|
| 563 | - } |
|
| 564 | - } |
|
| 565 | - return $model_routes; |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace, |
|
| 572 | - * excluding the preceding slash. |
|
| 573 | - * Eg you pass get_plural_route_to('Event') = 'events' |
|
| 574 | - * |
|
| 575 | - * @param EEM_Base $model |
|
| 576 | - * @return string |
|
| 577 | - */ |
|
| 578 | - public static function get_collection_route(EEM_Base $model) |
|
| 579 | - { |
|
| 580 | - return EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - |
|
| 585 | - /** |
|
| 586 | - * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
| 587 | - * excluding the preceding slash. |
|
| 588 | - * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
| 589 | - * |
|
| 590 | - * @param EEM_Base $model eg Event or Venue |
|
| 591 | - * @param string $id |
|
| 592 | - * @return string |
|
| 593 | - */ |
|
| 594 | - public static function get_entity_route($model, $id) |
|
| 595 | - { |
|
| 596 | - return EED_Core_Rest_Api::get_collection_route($model). '/' . $id; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - |
|
| 600 | - /** |
|
| 601 | - * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
| 602 | - * excluding the preceding slash. |
|
| 603 | - * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
| 604 | - * |
|
| 605 | - * @param EEM_Base $model eg Event or Venue |
|
| 606 | - * @param string $id |
|
| 607 | - * @param EE_Model_Relation_Base $relation_obj |
|
| 608 | - * @return string |
|
| 609 | - */ |
|
| 610 | - public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj) |
|
| 611 | - { |
|
| 612 | - $related_model_name_endpoint_part = ModelRead::getRelatedEntityName( |
|
| 613 | - $relation_obj->get_other_model()->get_this_model_name(), |
|
| 614 | - $relation_obj |
|
| 615 | - ); |
|
| 616 | - return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * Adds onto the $relative_route the EE4 REST API versioned namespace. |
|
| 623 | - * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events' |
|
| 624 | - * @param string $relative_route |
|
| 625 | - * @param string $version |
|
| 626 | - * @return string |
|
| 627 | - */ |
|
| 628 | - public static function get_versioned_route_to($relative_route, $version = '4.8.36'){ |
|
| 629 | - return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - |
|
| 633 | - |
|
| 634 | - /** |
|
| 635 | - * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
| 636 | - * routes that don't conform to the traditional REST CRUD-style). |
|
| 637 | - * |
|
| 638 | - * @deprecated since 4.9.1 |
|
| 639 | - */ |
|
| 640 | - protected function _register_rpc_routes() |
|
| 641 | - { |
|
| 642 | - $routes = array(); |
|
| 643 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 644 | - $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version( |
|
| 645 | - $version, |
|
| 646 | - $hidden_endpoint |
|
| 647 | - ); |
|
| 648 | - } |
|
| 649 | - return $routes; |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * @param string $version |
|
| 656 | - * @param boolean $hidden_endpoint |
|
| 657 | - * @return array |
|
| 658 | - */ |
|
| 659 | - protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
| 660 | - { |
|
| 661 | - $this_versions_routes = array(); |
|
| 662 | - //checkin endpoint |
|
| 663 | - $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array( |
|
| 664 | - array( |
|
| 665 | - 'callback' => array( |
|
| 666 | - 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
| 667 | - 'handleRequestToggleCheckin', |
|
| 668 | - ), |
|
| 669 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 670 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 671 | - 'args' => array( |
|
| 672 | - 'force' => array( |
|
| 673 | - 'required' => false, |
|
| 674 | - 'default' => false, |
|
| 675 | - 'description' => __( |
|
| 676 | - // @codingStandardsIgnoreStart |
|
| 677 | - 'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
| 678 | - // @codingStandardsIgnoreEnd |
|
| 679 | - 'event_espresso' |
|
| 680 | - ), |
|
| 681 | - ), |
|
| 682 | - ), |
|
| 683 | - 'callback_args' => array($version), |
|
| 684 | - ), |
|
| 685 | - ); |
|
| 686 | - return apply_filters( |
|
| 687 | - 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
| 688 | - $this_versions_routes, |
|
| 689 | - $version, |
|
| 690 | - $hidden_endpoint |
|
| 691 | - ); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * Gets the query params that can be used when request one or many |
|
| 698 | - * |
|
| 699 | - * @param EEM_Base $model |
|
| 700 | - * @param string $version |
|
| 701 | - * @return array |
|
| 702 | - */ |
|
| 703 | - protected function _get_response_selection_query_params(\EEM_Base $model, $version) |
|
| 704 | - { |
|
| 705 | - return apply_filters( |
|
| 706 | - 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
| 707 | - array( |
|
| 708 | - 'include' => array( |
|
| 709 | - 'required' => false, |
|
| 710 | - 'default' => '*', |
|
| 711 | - 'type' => 'string', |
|
| 712 | - ), |
|
| 713 | - 'calculate' => array( |
|
| 714 | - 'required' => false, |
|
| 715 | - 'default' => '', |
|
| 716 | - 'enum' => self::$_field_calculator->retrieveCalculatedFieldsForModel($model), |
|
| 717 | - 'type' => 'string', |
|
| 718 | - //because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization |
|
| 719 | - //freaks out. We'll just validate this argument while handling the request |
|
| 720 | - 'validate_callback' => null, |
|
| 721 | - 'sanitize_callback' => null, |
|
| 722 | - ), |
|
| 723 | - ), |
|
| 724 | - $model, |
|
| 725 | - $version |
|
| 726 | - ); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - |
|
| 730 | - |
|
| 731 | - /** |
|
| 732 | - * Gets the parameters acceptable for delete requests |
|
| 733 | - * |
|
| 734 | - * @param \EEM_Base $model |
|
| 735 | - * @param string $version |
|
| 736 | - * @return array |
|
| 737 | - */ |
|
| 738 | - protected function _get_delete_query_params(\EEM_Base $model, $version) |
|
| 739 | - { |
|
| 740 | - $params_for_delete = array( |
|
| 741 | - 'allow_blocking' => array( |
|
| 742 | - 'required' => false, |
|
| 743 | - 'default' => true, |
|
| 744 | - 'type' => 'boolean', |
|
| 745 | - ), |
|
| 746 | - ); |
|
| 747 | - $params_for_delete['force'] = array( |
|
| 748 | - 'required' => false, |
|
| 749 | - 'default' => false, |
|
| 750 | - 'type' => 'boolean', |
|
| 751 | - ); |
|
| 752 | - return apply_filters( |
|
| 753 | - 'FHEE__EED_Core_Rest_Api___get_delete_query_params', |
|
| 754 | - $params_for_delete, |
|
| 755 | - $model, |
|
| 756 | - $version |
|
| 757 | - ); |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - |
|
| 761 | - |
|
| 762 | - /** |
|
| 763 | - * Gets info about reading query params that are acceptable |
|
| 764 | - * |
|
| 765 | - * @param \EEM_Base $model eg 'Event' or 'Venue' |
|
| 766 | - * @param string $version |
|
| 767 | - * @return array describing the args acceptable when querying this model |
|
| 768 | - * @throws EE_Error |
|
| 769 | - */ |
|
| 770 | - protected function _get_read_query_params(\EEM_Base $model, $version) |
|
| 771 | - { |
|
| 772 | - $default_orderby = array(); |
|
| 773 | - foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
| 774 | - $default_orderby[$key_field->get_name()] = 'ASC'; |
|
| 775 | - } |
|
| 776 | - return array_merge( |
|
| 777 | - $this->_get_response_selection_query_params($model, $version), |
|
| 778 | - array( |
|
| 779 | - 'where' => array( |
|
| 780 | - 'required' => false, |
|
| 781 | - 'default' => array(), |
|
| 782 | - 'type' => 'object', |
|
| 783 | - //because we accept an almost infinite list of possible where conditions, WP |
|
| 784 | - // core validation and sanitization freaks out. We'll just validate this argument |
|
| 785 | - // while handling the request |
|
| 786 | - 'validate_callback' => null, |
|
| 787 | - 'sanitize_callback' => null, |
|
| 788 | - ), |
|
| 789 | - 'limit' => array( |
|
| 790 | - 'required' => false, |
|
| 791 | - 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
| 792 | - 'type' => array( |
|
| 793 | - 'array', |
|
| 794 | - 'string', |
|
| 795 | - 'integer', |
|
| 796 | - ), |
|
| 797 | - //because we accept a variety of types, WP core validation and sanitization |
|
| 798 | - //freaks out. We'll just validate this argument while handling the request |
|
| 799 | - 'validate_callback' => null, |
|
| 800 | - 'sanitize_callback' => null, |
|
| 801 | - ), |
|
| 802 | - 'order_by' => array( |
|
| 803 | - 'required' => false, |
|
| 804 | - 'default' => $default_orderby, |
|
| 805 | - 'type' => array( |
|
| 806 | - 'object', |
|
| 807 | - 'string', |
|
| 808 | - ),//because we accept a variety of types, WP core validation and sanitization |
|
| 809 | - //freaks out. We'll just validate this argument while handling the request |
|
| 810 | - 'validate_callback' => null, |
|
| 811 | - 'sanitize_callback' => null, |
|
| 812 | - ), |
|
| 813 | - 'group_by' => array( |
|
| 814 | - 'required' => false, |
|
| 815 | - 'default' => null, |
|
| 816 | - 'type' => array( |
|
| 817 | - 'object', |
|
| 818 | - 'string', |
|
| 819 | - ), |
|
| 820 | - //because we accept an almost infinite list of possible groupings, |
|
| 821 | - // WP core validation and sanitization |
|
| 822 | - //freaks out. We'll just validate this argument while handling the request |
|
| 823 | - 'validate_callback' => null, |
|
| 824 | - 'sanitize_callback' => null, |
|
| 825 | - ), |
|
| 826 | - 'having' => array( |
|
| 827 | - 'required' => false, |
|
| 828 | - 'default' => null, |
|
| 829 | - 'type' => 'object', |
|
| 830 | - //because we accept an almost infinite list of possible where conditions, WP |
|
| 831 | - // core validation and sanitization freaks out. We'll just validate this argument |
|
| 832 | - // while handling the request |
|
| 833 | - 'validate_callback' => null, |
|
| 834 | - 'sanitize_callback' => null, |
|
| 835 | - ), |
|
| 836 | - 'caps' => array( |
|
| 837 | - 'required' => false, |
|
| 838 | - 'default' => EEM_Base::caps_read, |
|
| 839 | - 'type' => 'string', |
|
| 840 | - 'enum' => array( |
|
| 841 | - EEM_Base::caps_read, |
|
| 842 | - EEM_Base::caps_read_admin, |
|
| 843 | - EEM_Base::caps_edit, |
|
| 844 | - EEM_Base::caps_delete |
|
| 845 | - ) |
|
| 846 | - ), |
|
| 847 | - ) |
|
| 848 | - ); |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * Gets parameter information for a model regarding writing data |
|
| 855 | - * |
|
| 856 | - * @param string $model_name |
|
| 857 | - * @param ModelVersionInfo $model_version_info |
|
| 858 | - * @param boolean $create whether this is for request to create (in which case we need |
|
| 859 | - * all required params) or just to update (in which case we don't need those on every request) |
|
| 860 | - * @return array |
|
| 861 | - */ |
|
| 862 | - protected function _get_write_params( |
|
| 863 | - $model_name, |
|
| 864 | - ModelVersionInfo $model_version_info, |
|
| 865 | - $create = false |
|
| 866 | - ) { |
|
| 867 | - $model = EE_Registry::instance()->load_model($model_name); |
|
| 868 | - $fields = $model_version_info->fieldsOnModelInThisVersion($model); |
|
| 869 | - $args_info = array(); |
|
| 870 | - foreach ($fields as $field_name => $field_obj) { |
|
| 871 | - if ($field_obj->is_auto_increment()) { |
|
| 872 | - //totally ignore auto increment IDs |
|
| 873 | - continue; |
|
| 874 | - } |
|
| 875 | - $arg_info = $field_obj->getSchema(); |
|
| 876 | - $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null; |
|
| 877 | - $arg_info['required'] = $required; |
|
| 878 | - //remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right? |
|
| 879 | - unset($arg_info['readonly']); |
|
| 880 | - $schema_properties = $field_obj->getSchemaProperties(); |
|
| 881 | - if ( |
|
| 882 | - isset($schema_properties['raw']) |
|
| 883 | - && $field_obj->getSchemaType() === 'object' |
|
| 884 | - ) { |
|
| 885 | - //if there's a "raw" form of this argument, use those properties instead |
|
| 886 | - $arg_info = array_replace( |
|
| 887 | - $arg_info, |
|
| 888 | - $schema_properties['raw'] |
|
| 889 | - ); |
|
| 890 | - } |
|
| 891 | - $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson( |
|
| 892 | - $field_obj, |
|
| 893 | - $field_obj->get_default_value(), |
|
| 894 | - $model_version_info->requestedVersion() |
|
| 895 | - ); |
|
| 896 | - //we do our own validation and sanitization within the controller |
|
| 897 | - if(function_exists('rest_validate_value_from_schema')){ |
|
| 898 | - $sanitize_callback = array( |
|
| 899 | - 'EED_Core_Rest_Api', |
|
| 900 | - 'default_sanitize_callback', |
|
| 901 | - ); |
|
| 902 | - } else { |
|
| 903 | - $sanitize_callback = null; |
|
| 904 | - } |
|
| 905 | - $arg_info['sanitize_callback'] = $sanitize_callback; |
|
| 906 | - $args_info[$field_name] = $arg_info; |
|
| 907 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
| 908 | - $gmt_arg_info = $arg_info; |
|
| 909 | - $gmt_arg_info['description'] = sprintf( |
|
| 910 | - esc_html__( |
|
| 911 | - '%1$s - the value for this field in UTC. Ignored if %2$s is provided.', |
|
| 912 | - 'event_espresso' |
|
| 913 | - ), |
|
| 914 | - $field_obj->get_nicename(), |
|
| 915 | - $field_name |
|
| 916 | - ); |
|
| 917 | - $args_info[$field_name . '_gmt'] = $gmt_arg_info; |
|
| 918 | - } |
|
| 919 | - } |
|
| 920 | - return $args_info; |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - |
|
| 924 | - |
|
| 925 | - /** |
|
| 926 | - * Replacement for WP API's 'rest_parse_request_arg'. |
|
| 927 | - * If the value is blank but not required, don't bother validating it. |
|
| 928 | - * Also, it uses our email validation instead of WP API's default. |
|
| 929 | - * |
|
| 930 | - * @param $value |
|
| 931 | - * @param WP_REST_Request $request |
|
| 932 | - * @param $param |
|
| 933 | - * @return bool|true|WP_Error |
|
| 934 | - * @throws InvalidArgumentException |
|
| 935 | - * @throws InvalidInterfaceException |
|
| 936 | - * @throws InvalidDataTypeException |
|
| 937 | - */ |
|
| 938 | - public static function default_sanitize_callback( $value, WP_REST_Request $request, $param) |
|
| 939 | - { |
|
| 940 | - $attributes = $request->get_attributes(); |
|
| 941 | - if (! isset($attributes['args'][$param]) |
|
| 942 | - || ! is_array($attributes['args'][$param])) { |
|
| 943 | - $validation_result = true; |
|
| 944 | - } else { |
|
| 945 | - $args = $attributes['args'][$param]; |
|
| 946 | - if (( |
|
| 947 | - $value === '' |
|
| 948 | - || $value === null |
|
| 949 | - ) |
|
| 950 | - && (! isset($args['required']) |
|
| 951 | - || $args['required'] === false |
|
| 952 | - ) |
|
| 953 | - ) { |
|
| 954 | - //not required and not provided? that's cool |
|
| 955 | - $validation_result = true; |
|
| 956 | - } elseif (isset($args['format']) |
|
| 957 | - && $args['format'] === 'email' |
|
| 958 | - ) { |
|
| 959 | - $validation_result = true; |
|
| 960 | - if (! self::_validate_email($value)) { |
|
| 961 | - $validation_result = new WP_Error( |
|
| 962 | - 'rest_invalid_param', |
|
| 963 | - esc_html__( |
|
| 964 | - 'The email address is not valid or does not exist.', |
|
| 965 | - 'event_espresso' |
|
| 966 | - ) |
|
| 967 | - ); |
|
| 968 | - } |
|
| 969 | - } else { |
|
| 970 | - $validation_result = rest_validate_value_from_schema($value, $args, $param); |
|
| 971 | - } |
|
| 972 | - } |
|
| 973 | - if (is_wp_error($validation_result)) { |
|
| 974 | - return $validation_result; |
|
| 975 | - } |
|
| 976 | - return rest_sanitize_request_arg($value, $request, $param); |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - |
|
| 980 | - |
|
| 981 | - /** |
|
| 982 | - * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email() |
|
| 983 | - * |
|
| 984 | - * @param $email |
|
| 985 | - * @return bool |
|
| 986 | - * @throws InvalidArgumentException |
|
| 987 | - * @throws InvalidInterfaceException |
|
| 988 | - * @throws InvalidDataTypeException |
|
| 989 | - */ |
|
| 990 | - protected static function _validate_email($email){ |
|
| 991 | - try { |
|
| 992 | - EmailAddressFactory::create($email); |
|
| 993 | - return true; |
|
| 994 | - } catch (EmailValidationException $e) { |
|
| 995 | - return false; |
|
| 996 | - } |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - |
|
| 1000 | - |
|
| 1001 | - /** |
|
| 1002 | - * Gets routes for the config |
|
| 1003 | - * |
|
| 1004 | - * @return array @see _register_model_routes |
|
| 1005 | - * @deprecated since version 4.9.1 |
|
| 1006 | - */ |
|
| 1007 | - protected function _register_config_routes() |
|
| 1008 | - { |
|
| 1009 | - $config_routes = array(); |
|
| 1010 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 1011 | - $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version( |
|
| 1012 | - $version, |
|
| 1013 | - $hidden_endpoint |
|
| 1014 | - ); |
|
| 1015 | - } |
|
| 1016 | - return $config_routes; |
|
| 1017 | - } |
|
| 1018 | - |
|
| 1019 | - |
|
| 1020 | - |
|
| 1021 | - /** |
|
| 1022 | - * Gets routes for the config for the specified version |
|
| 1023 | - * |
|
| 1024 | - * @param string $version |
|
| 1025 | - * @param boolean $hidden_endpoint |
|
| 1026 | - * @return array |
|
| 1027 | - */ |
|
| 1028 | - protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
| 1029 | - { |
|
| 1030 | - return array( |
|
| 1031 | - 'config' => array( |
|
| 1032 | - array( |
|
| 1033 | - 'callback' => array( |
|
| 1034 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 1035 | - 'handleRequest', |
|
| 1036 | - ), |
|
| 1037 | - 'methods' => WP_REST_Server::READABLE, |
|
| 1038 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 1039 | - 'callback_args' => array($version), |
|
| 1040 | - ), |
|
| 1041 | - ), |
|
| 1042 | - 'site_info' => array( |
|
| 1043 | - array( |
|
| 1044 | - 'callback' => array( |
|
| 1045 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 1046 | - 'handleRequestSiteInfo', |
|
| 1047 | - ), |
|
| 1048 | - 'methods' => WP_REST_Server::READABLE, |
|
| 1049 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 1050 | - 'callback_args' => array($version), |
|
| 1051 | - ), |
|
| 1052 | - ), |
|
| 1053 | - ); |
|
| 1054 | - } |
|
| 1055 | - |
|
| 1056 | - |
|
| 1057 | - |
|
| 1058 | - /** |
|
| 1059 | - * Gets the meta info routes |
|
| 1060 | - * |
|
| 1061 | - * @return array @see _register_model_routes |
|
| 1062 | - * @deprecated since version 4.9.1 |
|
| 1063 | - */ |
|
| 1064 | - protected function _register_meta_routes() |
|
| 1065 | - { |
|
| 1066 | - $meta_routes = array(); |
|
| 1067 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 1068 | - $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version( |
|
| 1069 | - $version, |
|
| 1070 | - $hidden_endpoint |
|
| 1071 | - ); |
|
| 1072 | - } |
|
| 1073 | - return $meta_routes; |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - |
|
| 1077 | - |
|
| 1078 | - /** |
|
| 1079 | - * @param string $version |
|
| 1080 | - * @param boolean $hidden_endpoint |
|
| 1081 | - * @return array |
|
| 1082 | - */ |
|
| 1083 | - protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
| 1084 | - { |
|
| 1085 | - return array( |
|
| 1086 | - 'resources' => array( |
|
| 1087 | - array( |
|
| 1088 | - 'callback' => array( |
|
| 1089 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
| 1090 | - 'handleRequestModelsMeta', |
|
| 1091 | - ), |
|
| 1092 | - 'methods' => WP_REST_Server::READABLE, |
|
| 1093 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 1094 | - 'callback_args' => array($version), |
|
| 1095 | - ), |
|
| 1096 | - ), |
|
| 1097 | - ); |
|
| 1098 | - } |
|
| 1099 | - |
|
| 1100 | - |
|
| 1101 | - |
|
| 1102 | - /** |
|
| 1103 | - * Tries to hide old 4.6 endpoints from the |
|
| 1104 | - * |
|
| 1105 | - * @param array $route_data |
|
| 1106 | - * @return array |
|
| 1107 | - * @throws \EE_Error |
|
| 1108 | - */ |
|
| 1109 | - public static function hide_old_endpoints($route_data) |
|
| 1110 | - { |
|
| 1111 | - //allow API clients to override which endpoints get hidden, in case |
|
| 1112 | - //they want to discover particular endpoints |
|
| 1113 | - //also, we don't have access to the request so we have to just grab it from the superglobal |
|
| 1114 | - $force_show_ee_namespace = ltrim( |
|
| 1115 | - EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''), |
|
| 1116 | - '/' |
|
| 1117 | - ); |
|
| 1118 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
| 1119 | - foreach ($relative_urls as $resource_name => $endpoints) { |
|
| 1120 | - foreach ($endpoints as $key => $endpoint) { |
|
| 1121 | - //skip schema and other route options |
|
| 1122 | - if (! is_numeric($key)) { |
|
| 1123 | - continue; |
|
| 1124 | - } |
|
| 1125 | - //by default, hide "hidden_endpoint"s, unless the request indicates |
|
| 1126 | - //to $force_show_ee_namespace, in which case only show that one |
|
| 1127 | - //namespace's endpoints (and hide all others) |
|
| 1128 | - if ( |
|
| 1129 | - ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
| 1130 | - || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
| 1131 | - ) { |
|
| 1132 | - $full_route = '/' . ltrim($namespace, '/'); |
|
| 1133 | - $full_route .= '/' . ltrim($resource_name, '/'); |
|
| 1134 | - unset($route_data[$full_route]); |
|
| 1135 | - } |
|
| 1136 | - } |
|
| 1137 | - } |
|
| 1138 | - } |
|
| 1139 | - return $route_data; |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - |
|
| 1143 | - |
|
| 1144 | - /** |
|
| 1145 | - * Returns an array describing which versions of core support serving requests for. |
|
| 1146 | - * Keys are core versions' major and minor version, and values are the |
|
| 1147 | - * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
| 1148 | - * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
| 1149 | - * the answers table entirely, in which case it would be very difficult for |
|
| 1150 | - * it to serve 4.6-style responses. |
|
| 1151 | - * Versions of core that are missing from this array are unknowns. |
|
| 1152 | - * previous ver |
|
| 1153 | - * |
|
| 1154 | - * @return array |
|
| 1155 | - */ |
|
| 1156 | - public static function version_compatibilities() |
|
| 1157 | - { |
|
| 1158 | - return apply_filters( |
|
| 1159 | - 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
| 1160 | - array( |
|
| 1161 | - '4.8.29' => '4.8.29', |
|
| 1162 | - '4.8.33' => '4.8.29', |
|
| 1163 | - '4.8.34' => '4.8.29', |
|
| 1164 | - '4.8.36' => '4.8.29', |
|
| 1165 | - ) |
|
| 1166 | - ); |
|
| 1167 | - } |
|
| 1168 | - |
|
| 1169 | - |
|
| 1170 | - |
|
| 1171 | - /** |
|
| 1172 | - * Gets the latest API version served. Eg if there |
|
| 1173 | - * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
| 1174 | - * we are on core version 4.8.34, it will return the string "4.8.32" |
|
| 1175 | - * |
|
| 1176 | - * @return string |
|
| 1177 | - */ |
|
| 1178 | - public static function latest_rest_api_version() |
|
| 1179 | - { |
|
| 1180 | - $versions_served = \EED_Core_Rest_Api::versions_served(); |
|
| 1181 | - $versions_served_keys = array_keys($versions_served); |
|
| 1182 | - return end($versions_served_keys); |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - |
|
| 1186 | - |
|
| 1187 | - /** |
|
| 1188 | - * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
| 1189 | - * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
| 1190 | - * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
| 1191 | - * We also indicate whether or not this version should be put in the index or not |
|
| 1192 | - * |
|
| 1193 | - * @return array keys are API version numbers (just major and minor numbers), and values |
|
| 1194 | - * are whether or not they should be hidden |
|
| 1195 | - */ |
|
| 1196 | - public static function versions_served() |
|
| 1197 | - { |
|
| 1198 | - $versions_served = array(); |
|
| 1199 | - $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
| 1200 | - $lowest_compatible_version = end($possibly_served_versions); |
|
| 1201 | - reset($possibly_served_versions); |
|
| 1202 | - $versions_served_historically = array_keys($possibly_served_versions); |
|
| 1203 | - $latest_version = end($versions_served_historically); |
|
| 1204 | - reset($versions_served_historically); |
|
| 1205 | - //for each version of core we have ever served: |
|
| 1206 | - foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
| 1207 | - //if it's not above the current core version, and it's compatible with the current version of core |
|
| 1208 | - if ($key_versioned_endpoint === $latest_version) { |
|
| 1209 | - //don't hide the latest version in the index |
|
| 1210 | - $versions_served[$key_versioned_endpoint] = false; |
|
| 1211 | - } elseif ( |
|
| 1212 | - $key_versioned_endpoint >= $lowest_compatible_version |
|
| 1213 | - && $key_versioned_endpoint < EED_Core_Rest_Api::core_version() |
|
| 1214 | - ) { |
|
| 1215 | - //include, but hide, previous versions which are still supported |
|
| 1216 | - $versions_served[$key_versioned_endpoint] = true; |
|
| 1217 | - } elseif (apply_filters( |
|
| 1218 | - 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
| 1219 | - false, |
|
| 1220 | - $possibly_served_versions |
|
| 1221 | - )) { |
|
| 1222 | - //if a version is no longer supported, don't include it in index or list of versions served |
|
| 1223 | - $versions_served[$key_versioned_endpoint] = true; |
|
| 1224 | - } |
|
| 1225 | - } |
|
| 1226 | - return $versions_served; |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - |
|
| 1230 | - |
|
| 1231 | - /** |
|
| 1232 | - * Gets the major and minor version of EE core's version string |
|
| 1233 | - * |
|
| 1234 | - * @return string |
|
| 1235 | - */ |
|
| 1236 | - public static function core_version() |
|
| 1237 | - { |
|
| 1238 | - return apply_filters( |
|
| 1239 | - 'FHEE__EED_Core_REST_API__core_version', |
|
| 1240 | - implode( |
|
| 1241 | - '.', |
|
| 1242 | - array_slice( |
|
| 1243 | - explode( |
|
| 1244 | - '.', |
|
| 1245 | - espresso_version() |
|
| 1246 | - ), |
|
| 1247 | - 0, |
|
| 1248 | - 3 |
|
| 1249 | - ) |
|
| 1250 | - ) |
|
| 1251 | - ); |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - |
|
| 1255 | - |
|
| 1256 | - /** |
|
| 1257 | - * Gets the default limit that should be used when querying for resources |
|
| 1258 | - * |
|
| 1259 | - * @return int |
|
| 1260 | - */ |
|
| 1261 | - public static function get_default_query_limit() |
|
| 1262 | - { |
|
| 1263 | - //we actually don't use a const because we want folks to always use |
|
| 1264 | - //this method, not the const directly |
|
| 1265 | - return apply_filters( |
|
| 1266 | - 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
| 1267 | - 50 |
|
| 1268 | - ); |
|
| 1269 | - } |
|
| 1270 | - |
|
| 1271 | - |
|
| 1272 | - |
|
| 1273 | - /** |
|
| 1274 | - * run - initial module setup |
|
| 1275 | - * |
|
| 1276 | - * @access public |
|
| 1277 | - * @param WP $WP |
|
| 1278 | - * @return void |
|
| 1279 | - */ |
|
| 1280 | - public function run($WP) |
|
| 1281 | - { |
|
| 1282 | - } |
|
| 31 | + const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
| 32 | + |
|
| 33 | + const saved_routes_option_names = 'ee_core_routes'; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * string used in _links response bodies to make them globally unique. |
|
| 37 | + * |
|
| 38 | + * @see http://v2.wp-api.org/extending/linking/ |
|
| 39 | + */ |
|
| 40 | + const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var CalculatedModelFields |
|
| 44 | + */ |
|
| 45 | + protected static $_field_calculator; |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @return EED_Core_Rest_Api|EED_Module |
|
| 51 | + */ |
|
| 52 | + public static function instance() |
|
| 53 | + { |
|
| 54 | + self::$_field_calculator = new CalculatedModelFields(); |
|
| 55 | + return parent::get_instance(__CLASS__); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 62 | + * |
|
| 63 | + * @access public |
|
| 64 | + * @return void |
|
| 65 | + */ |
|
| 66 | + public static function set_hooks() |
|
| 67 | + { |
|
| 68 | + self::set_hooks_both(); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 75 | + * |
|
| 76 | + * @access public |
|
| 77 | + * @return void |
|
| 78 | + */ |
|
| 79 | + public static function set_hooks_admin() |
|
| 80 | + { |
|
| 81 | + self::set_hooks_both(); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + public static function set_hooks_both() |
|
| 87 | + { |
|
| 88 | + add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10); |
|
| 89 | + add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5); |
|
| 90 | + add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2); |
|
| 91 | + add_filter('rest_index', |
|
| 92 | + array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex')); |
|
| 93 | + EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * sets up hooks which only need to be included as part of REST API requests; |
|
| 100 | + * other requests like to the frontend or admin etc don't need them |
|
| 101 | + * |
|
| 102 | + * @throws \EE_Error |
|
| 103 | + */ |
|
| 104 | + public static function set_hooks_rest_api() |
|
| 105 | + { |
|
| 106 | + //set hooks which account for changes made to the API |
|
| 107 | + EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * public wrapper of _set_hooks_for_changes. |
|
| 114 | + * Loads all the hooks which make requests to old versions of the API |
|
| 115 | + * appear the same as they always did |
|
| 116 | + * |
|
| 117 | + * @throws EE_Error |
|
| 118 | + */ |
|
| 119 | + public static function set_hooks_for_changes() |
|
| 120 | + { |
|
| 121 | + self::_set_hooks_for_changes(); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Loads all the hooks which make requests to old versions of the API |
|
| 128 | + * appear the same as they always did |
|
| 129 | + * |
|
| 130 | + * @throws EE_Error |
|
| 131 | + */ |
|
| 132 | + protected static function _set_hooks_for_changes() |
|
| 133 | + { |
|
| 134 | + $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false); |
|
| 135 | + foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
| 136 | + //ignore the base parent class |
|
| 137 | + //and legacy named classes |
|
| 138 | + if ($classname_in_namespace === 'ChangesInBase' |
|
| 139 | + || strpos($classname_in_namespace, 'Changes_In_') === 0 |
|
| 140 | + ) { |
|
| 141 | + continue; |
|
| 142 | + } |
|
| 143 | + $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
| 144 | + if (class_exists($full_classname)) { |
|
| 145 | + $instance_of_class = new $full_classname; |
|
| 146 | + if ($instance_of_class instanceof ChangesInBase) { |
|
| 147 | + $instance_of_class->setHooks(); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
| 157 | + * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
| 158 | + * |
|
| 159 | + * @throws \EE_Error |
|
| 160 | + */ |
|
| 161 | + public static function register_routes() |
|
| 162 | + { |
|
| 163 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) { |
|
| 164 | + foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) { |
|
| 165 | + /** |
|
| 166 | + * @var array $data_for_multiple_endpoints numerically indexed array |
|
| 167 | + * but can also contain route options like { |
|
| 168 | + * @type array $schema { |
|
| 169 | + * @type callable $schema_callback |
|
| 170 | + * @type array $callback_args arguments that will be passed to the callback, after the |
|
| 171 | + * WP_REST_Request of course |
|
| 172 | + * } |
|
| 173 | + * } |
|
| 174 | + */ |
|
| 175 | + //when registering routes, register all the endpoints' data at the same time |
|
| 176 | + $multiple_endpoint_args = array(); |
|
| 177 | + foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) { |
|
| 178 | + /** |
|
| 179 | + * @var array $data_for_single_endpoint { |
|
| 180 | + * @type callable $callback |
|
| 181 | + * @type string methods |
|
| 182 | + * @type array args |
|
| 183 | + * @type array _links |
|
| 184 | + * @type array $callback_args arguments that will be passed to the callback, after the |
|
| 185 | + * WP_REST_Request of course |
|
| 186 | + * } |
|
| 187 | + */ |
|
| 188 | + //skip route options |
|
| 189 | + if (! is_numeric($endpoint_key)) { |
|
| 190 | + continue; |
|
| 191 | + } |
|
| 192 | + if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
| 193 | + throw new EE_Error( |
|
| 194 | + esc_html__( |
|
| 195 | + // @codingStandardsIgnoreStart |
|
| 196 | + 'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).', |
|
| 197 | + // @codingStandardsIgnoreEnd |
|
| 198 | + 'event_espresso') |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | + $callback = $data_for_single_endpoint['callback']; |
|
| 202 | + $single_endpoint_args = array( |
|
| 203 | + 'methods' => $data_for_single_endpoint['methods'], |
|
| 204 | + 'args' => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args'] |
|
| 205 | + : array(), |
|
| 206 | + ); |
|
| 207 | + if (isset($data_for_single_endpoint['_links'])) { |
|
| 208 | + $single_endpoint_args['_links'] = $data_for_single_endpoint['_links']; |
|
| 209 | + } |
|
| 210 | + if (isset($data_for_single_endpoint['callback_args'])) { |
|
| 211 | + $callback_args = $data_for_single_endpoint['callback_args']; |
|
| 212 | + $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use ( |
|
| 213 | + $callback, |
|
| 214 | + $callback_args |
|
| 215 | + ) { |
|
| 216 | + array_unshift($callback_args, $request); |
|
| 217 | + return call_user_func_array( |
|
| 218 | + $callback, |
|
| 219 | + $callback_args |
|
| 220 | + ); |
|
| 221 | + }; |
|
| 222 | + } else { |
|
| 223 | + $single_endpoint_args['callback'] = $data_for_single_endpoint['callback']; |
|
| 224 | + } |
|
| 225 | + $multiple_endpoint_args[] = $single_endpoint_args; |
|
| 226 | + } |
|
| 227 | + if (isset($data_for_multiple_endpoints['schema'])) { |
|
| 228 | + $schema_route_data = $data_for_multiple_endpoints['schema']; |
|
| 229 | + $schema_callback = $schema_route_data['schema_callback']; |
|
| 230 | + $callback_args = $schema_route_data['callback_args']; |
|
| 231 | + $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) { |
|
| 232 | + return call_user_func_array( |
|
| 233 | + $schema_callback, |
|
| 234 | + $callback_args |
|
| 235 | + ); |
|
| 236 | + }; |
|
| 237 | + } |
|
| 238 | + register_rest_route( |
|
| 239 | + $namespace, |
|
| 240 | + $relative_route, |
|
| 241 | + $multiple_endpoint_args |
|
| 242 | + ); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Checks if there was a version change or something that merits invalidating the cached |
|
| 251 | + * route data. If so, invalidates the cached route data so that it gets refreshed |
|
| 252 | + * next time the WP API is used |
|
| 253 | + */ |
|
| 254 | + public static function invalidate_cached_route_data_on_version_change() |
|
| 255 | + { |
|
| 256 | + if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) { |
|
| 257 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
| 258 | + } |
|
| 259 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
| 260 | + if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) { |
|
| 261 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Removes the cached route data so it will get refreshed next time the WP API is used |
|
| 270 | + */ |
|
| 271 | + public static function invalidate_cached_route_data() |
|
| 272 | + { |
|
| 273 | + //delete the saved EE REST API routes |
|
| 274 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
| 275 | + delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Gets the EE route data |
|
| 283 | + * |
|
| 284 | + * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
| 285 | + * @throws \EE_Error |
|
| 286 | + * @type string|array $callback |
|
| 287 | + * @type string $methods |
|
| 288 | + * @type boolean $hidden_endpoint |
|
| 289 | + * } |
|
| 290 | + */ |
|
| 291 | + public static function get_ee_route_data() |
|
| 292 | + { |
|
| 293 | + $ee_routes = array(); |
|
| 294 | + foreach (self::versions_served() as $version => $hidden_endpoints) { |
|
| 295 | + $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version( |
|
| 296 | + $version, |
|
| 297 | + $hidden_endpoints |
|
| 298 | + ); |
|
| 299 | + } |
|
| 300 | + return $ee_routes; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Gets the EE route data from the wp options if it exists already, |
|
| 307 | + * otherwise re-generates it and saves it to the option |
|
| 308 | + * |
|
| 309 | + * @param string $version |
|
| 310 | + * @param boolean $hidden_endpoints |
|
| 311 | + * @return array |
|
| 312 | + * @throws \EE_Error |
|
| 313 | + */ |
|
| 314 | + protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 315 | + { |
|
| 316 | + $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
| 317 | + if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
| 318 | + $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
| 319 | + } |
|
| 320 | + return $ee_routes; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Saves the EE REST API route data to a wp option and returns it |
|
| 327 | + * |
|
| 328 | + * @param string $version |
|
| 329 | + * @param boolean $hidden_endpoints |
|
| 330 | + * @return mixed|null |
|
| 331 | + * @throws \EE_Error |
|
| 332 | + */ |
|
| 333 | + protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 334 | + { |
|
| 335 | + $instance = self::instance(); |
|
| 336 | + $routes = apply_filters( |
|
| 337 | + 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
| 338 | + array_replace_recursive( |
|
| 339 | + $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
| 340 | + $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
| 341 | + $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
| 342 | + $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
| 343 | + ) |
|
| 344 | + ); |
|
| 345 | + $option_name = self::saved_routes_option_names . $version; |
|
| 346 | + if (get_option($option_name)) { |
|
| 347 | + update_option($option_name, $routes, true); |
|
| 348 | + } else { |
|
| 349 | + add_option($option_name, $routes, null, 'no'); |
|
| 350 | + } |
|
| 351 | + return $routes; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Calculates all the EE routes and saves it to a WordPress option so we don't |
|
| 358 | + * need to calculate it on every request |
|
| 359 | + * |
|
| 360 | + * @deprecated since version 4.9.1 |
|
| 361 | + * @return void |
|
| 362 | + */ |
|
| 363 | + public static function save_ee_routes() |
|
| 364 | + { |
|
| 365 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 366 | + $instance = self::instance(); |
|
| 367 | + $routes = apply_filters( |
|
| 368 | + 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
| 369 | + array_replace_recursive( |
|
| 370 | + $instance->_register_config_routes(), |
|
| 371 | + $instance->_register_meta_routes(), |
|
| 372 | + $instance->_register_model_routes(), |
|
| 373 | + $instance->_register_rpc_routes() |
|
| 374 | + ) |
|
| 375 | + ); |
|
| 376 | + update_option(self::saved_routes_option_names, $routes, true); |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Gets all the route information relating to EE models |
|
| 384 | + * |
|
| 385 | + * @return array @see get_ee_route_data |
|
| 386 | + * @deprecated since version 4.9.1 |
|
| 387 | + */ |
|
| 388 | + protected function _register_model_routes() |
|
| 389 | + { |
|
| 390 | + $model_routes = array(); |
|
| 391 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 392 | + $model_routes[EED_Core_Rest_Api::ee_api_namespace |
|
| 393 | + . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
| 394 | + } |
|
| 395 | + return $model_routes; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * Decides whether or not to add write endpoints for this model. |
|
| 402 | + * |
|
| 403 | + * Currently, this defaults to exclude all global tables and models |
|
| 404 | + * which would allow inserting WP core data (we don't want to duplicate |
|
| 405 | + * what WP API does, as it's unnecessary, extra work, and potentially extra bugs) |
|
| 406 | + * @param EEM_Base $model |
|
| 407 | + * @return bool |
|
| 408 | + */ |
|
| 409 | + public static function should_have_write_endpoints(EEM_Base $model) |
|
| 410 | + { |
|
| 411 | + if ($model->is_wp_core_model()){ |
|
| 412 | + return false; |
|
| 413 | + } |
|
| 414 | + foreach($model->get_tables() as $table){ |
|
| 415 | + if( $table->is_global()){ |
|
| 416 | + return false; |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + return true; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`) |
|
| 426 | + * in this versioned namespace of EE4 |
|
| 427 | + * @param $version |
|
| 428 | + * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event') |
|
| 429 | + */ |
|
| 430 | + public static function model_names_with_plural_routes($version){ |
|
| 431 | + $model_version_info = new ModelVersionInfo($version); |
|
| 432 | + $models_to_register = $model_version_info->modelsForRequestedVersion(); |
|
| 433 | + //let's not bother having endpoints for extra metas |
|
| 434 | + unset( |
|
| 435 | + $models_to_register['Extra_Meta'], |
|
| 436 | + $models_to_register['Extra_Join'], |
|
| 437 | + $models_to_register['Post_Meta'] |
|
| 438 | + ); |
|
| 439 | + return apply_filters( |
|
| 440 | + 'FHEE__EED_Core_REST_API___register_model_routes', |
|
| 441 | + $models_to_register |
|
| 442 | + ); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * Gets the route data for EE models in the specified version |
|
| 449 | + * |
|
| 450 | + * @param string $version |
|
| 451 | + * @param boolean $hidden_endpoint |
|
| 452 | + * @return array |
|
| 453 | + * @throws EE_Error |
|
| 454 | + */ |
|
| 455 | + protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
| 456 | + { |
|
| 457 | + $model_routes = array(); |
|
| 458 | + $model_version_info = new ModelVersionInfo($version); |
|
| 459 | + foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
|
| 460 | + $model = \EE_Registry::instance()->load_model($model_name); |
|
| 461 | + //if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
| 462 | + if (! $model instanceof EEM_Base) { |
|
| 463 | + continue; |
|
| 464 | + } |
|
| 465 | + //yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
| 466 | + $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
|
| 467 | + $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
|
| 468 | + $model_routes[$plural_model_route] = array( |
|
| 469 | + array( |
|
| 470 | + 'callback' => array( |
|
| 471 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 472 | + 'handleRequestGetAll', |
|
| 473 | + ), |
|
| 474 | + 'callback_args' => array($version, $model_name), |
|
| 475 | + 'methods' => WP_REST_Server::READABLE, |
|
| 476 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 477 | + 'args' => $this->_get_read_query_params($model, $version), |
|
| 478 | + '_links' => array( |
|
| 479 | + 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
| 480 | + ), |
|
| 481 | + ), |
|
| 482 | + 'schema' => array( |
|
| 483 | + 'schema_callback' => array( |
|
| 484 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 485 | + 'handleSchemaRequest', |
|
| 486 | + ), |
|
| 487 | + 'callback_args' => array($version, $model_name), |
|
| 488 | + ), |
|
| 489 | + ); |
|
| 490 | + $model_routes[$singular_model_route] = array( |
|
| 491 | + array( |
|
| 492 | + 'callback' => array( |
|
| 493 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 494 | + 'handleRequestGetOne', |
|
| 495 | + ), |
|
| 496 | + 'callback_args' => array($version, $model_name), |
|
| 497 | + 'methods' => WP_REST_Server::READABLE, |
|
| 498 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 499 | + 'args' => $this->_get_response_selection_query_params($model, $version), |
|
| 500 | + ), |
|
| 501 | + ); |
|
| 502 | + if( apply_filters( |
|
| 503 | + 'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints', |
|
| 504 | + EED_Core_Rest_Api::should_have_write_endpoints($model), |
|
| 505 | + $model |
|
| 506 | + )){ |
|
| 507 | + $model_routes[$plural_model_route][] = array( |
|
| 508 | + 'callback' => array( |
|
| 509 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 510 | + 'handleRequestInsert', |
|
| 511 | + ), |
|
| 512 | + 'callback_args' => array($version, $model_name), |
|
| 513 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 514 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 515 | + 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
|
| 516 | + ); |
|
| 517 | + $model_routes[$singular_model_route] = array_merge( |
|
| 518 | + $model_routes[$singular_model_route], |
|
| 519 | + array( |
|
| 520 | + array( |
|
| 521 | + 'callback' => array( |
|
| 522 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 523 | + 'handleRequestUpdate', |
|
| 524 | + ), |
|
| 525 | + 'callback_args' => array($version, $model_name), |
|
| 526 | + 'methods' => WP_REST_Server::EDITABLE, |
|
| 527 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 528 | + 'args' => $this->_get_write_params($model_name, $model_version_info), |
|
| 529 | + ), |
|
| 530 | + array( |
|
| 531 | + 'callback' => array( |
|
| 532 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 533 | + 'handleRequestDelete', |
|
| 534 | + ), |
|
| 535 | + 'callback_args' => array($version, $model_name), |
|
| 536 | + 'methods' => WP_REST_Server::DELETABLE, |
|
| 537 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 538 | + 'args' => $this->_get_delete_query_params($model, $version), |
|
| 539 | + ) |
|
| 540 | + ) |
|
| 541 | + ); |
|
| 542 | + } |
|
| 543 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
| 544 | + |
|
| 545 | + $related_route = EED_Core_Rest_Api::get_relation_route_via( |
|
| 546 | + $model, |
|
| 547 | + '(?P<id>[^\/]+)', |
|
| 548 | + $relation_obj |
|
| 549 | + ); |
|
| 550 | + $endpoints = array( |
|
| 551 | + array( |
|
| 552 | + 'callback' => array( |
|
| 553 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 554 | + 'handleRequestGetRelated', |
|
| 555 | + ), |
|
| 556 | + 'callback_args' => array($version, $model_name, $relation_name), |
|
| 557 | + 'methods' => WP_REST_Server::READABLE, |
|
| 558 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 559 | + 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
| 560 | + ), |
|
| 561 | + ); |
|
| 562 | + $model_routes[$related_route] = $endpoints; |
|
| 563 | + } |
|
| 564 | + } |
|
| 565 | + return $model_routes; |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace, |
|
| 572 | + * excluding the preceding slash. |
|
| 573 | + * Eg you pass get_plural_route_to('Event') = 'events' |
|
| 574 | + * |
|
| 575 | + * @param EEM_Base $model |
|
| 576 | + * @return string |
|
| 577 | + */ |
|
| 578 | + public static function get_collection_route(EEM_Base $model) |
|
| 579 | + { |
|
| 580 | + return EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + |
|
| 585 | + /** |
|
| 586 | + * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
| 587 | + * excluding the preceding slash. |
|
| 588 | + * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
| 589 | + * |
|
| 590 | + * @param EEM_Base $model eg Event or Venue |
|
| 591 | + * @param string $id |
|
| 592 | + * @return string |
|
| 593 | + */ |
|
| 594 | + public static function get_entity_route($model, $id) |
|
| 595 | + { |
|
| 596 | + return EED_Core_Rest_Api::get_collection_route($model). '/' . $id; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + |
|
| 600 | + /** |
|
| 601 | + * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
| 602 | + * excluding the preceding slash. |
|
| 603 | + * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
| 604 | + * |
|
| 605 | + * @param EEM_Base $model eg Event or Venue |
|
| 606 | + * @param string $id |
|
| 607 | + * @param EE_Model_Relation_Base $relation_obj |
|
| 608 | + * @return string |
|
| 609 | + */ |
|
| 610 | + public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj) |
|
| 611 | + { |
|
| 612 | + $related_model_name_endpoint_part = ModelRead::getRelatedEntityName( |
|
| 613 | + $relation_obj->get_other_model()->get_this_model_name(), |
|
| 614 | + $relation_obj |
|
| 615 | + ); |
|
| 616 | + return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * Adds onto the $relative_route the EE4 REST API versioned namespace. |
|
| 623 | + * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events' |
|
| 624 | + * @param string $relative_route |
|
| 625 | + * @param string $version |
|
| 626 | + * @return string |
|
| 627 | + */ |
|
| 628 | + public static function get_versioned_route_to($relative_route, $version = '4.8.36'){ |
|
| 629 | + return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + |
|
| 633 | + |
|
| 634 | + /** |
|
| 635 | + * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
| 636 | + * routes that don't conform to the traditional REST CRUD-style). |
|
| 637 | + * |
|
| 638 | + * @deprecated since 4.9.1 |
|
| 639 | + */ |
|
| 640 | + protected function _register_rpc_routes() |
|
| 641 | + { |
|
| 642 | + $routes = array(); |
|
| 643 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 644 | + $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version( |
|
| 645 | + $version, |
|
| 646 | + $hidden_endpoint |
|
| 647 | + ); |
|
| 648 | + } |
|
| 649 | + return $routes; |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * @param string $version |
|
| 656 | + * @param boolean $hidden_endpoint |
|
| 657 | + * @return array |
|
| 658 | + */ |
|
| 659 | + protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
| 660 | + { |
|
| 661 | + $this_versions_routes = array(); |
|
| 662 | + //checkin endpoint |
|
| 663 | + $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array( |
|
| 664 | + array( |
|
| 665 | + 'callback' => array( |
|
| 666 | + 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
| 667 | + 'handleRequestToggleCheckin', |
|
| 668 | + ), |
|
| 669 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 670 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 671 | + 'args' => array( |
|
| 672 | + 'force' => array( |
|
| 673 | + 'required' => false, |
|
| 674 | + 'default' => false, |
|
| 675 | + 'description' => __( |
|
| 676 | + // @codingStandardsIgnoreStart |
|
| 677 | + 'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
| 678 | + // @codingStandardsIgnoreEnd |
|
| 679 | + 'event_espresso' |
|
| 680 | + ), |
|
| 681 | + ), |
|
| 682 | + ), |
|
| 683 | + 'callback_args' => array($version), |
|
| 684 | + ), |
|
| 685 | + ); |
|
| 686 | + return apply_filters( |
|
| 687 | + 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
| 688 | + $this_versions_routes, |
|
| 689 | + $version, |
|
| 690 | + $hidden_endpoint |
|
| 691 | + ); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * Gets the query params that can be used when request one or many |
|
| 698 | + * |
|
| 699 | + * @param EEM_Base $model |
|
| 700 | + * @param string $version |
|
| 701 | + * @return array |
|
| 702 | + */ |
|
| 703 | + protected function _get_response_selection_query_params(\EEM_Base $model, $version) |
|
| 704 | + { |
|
| 705 | + return apply_filters( |
|
| 706 | + 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
| 707 | + array( |
|
| 708 | + 'include' => array( |
|
| 709 | + 'required' => false, |
|
| 710 | + 'default' => '*', |
|
| 711 | + 'type' => 'string', |
|
| 712 | + ), |
|
| 713 | + 'calculate' => array( |
|
| 714 | + 'required' => false, |
|
| 715 | + 'default' => '', |
|
| 716 | + 'enum' => self::$_field_calculator->retrieveCalculatedFieldsForModel($model), |
|
| 717 | + 'type' => 'string', |
|
| 718 | + //because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization |
|
| 719 | + //freaks out. We'll just validate this argument while handling the request |
|
| 720 | + 'validate_callback' => null, |
|
| 721 | + 'sanitize_callback' => null, |
|
| 722 | + ), |
|
| 723 | + ), |
|
| 724 | + $model, |
|
| 725 | + $version |
|
| 726 | + ); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + |
|
| 730 | + |
|
| 731 | + /** |
|
| 732 | + * Gets the parameters acceptable for delete requests |
|
| 733 | + * |
|
| 734 | + * @param \EEM_Base $model |
|
| 735 | + * @param string $version |
|
| 736 | + * @return array |
|
| 737 | + */ |
|
| 738 | + protected function _get_delete_query_params(\EEM_Base $model, $version) |
|
| 739 | + { |
|
| 740 | + $params_for_delete = array( |
|
| 741 | + 'allow_blocking' => array( |
|
| 742 | + 'required' => false, |
|
| 743 | + 'default' => true, |
|
| 744 | + 'type' => 'boolean', |
|
| 745 | + ), |
|
| 746 | + ); |
|
| 747 | + $params_for_delete['force'] = array( |
|
| 748 | + 'required' => false, |
|
| 749 | + 'default' => false, |
|
| 750 | + 'type' => 'boolean', |
|
| 751 | + ); |
|
| 752 | + return apply_filters( |
|
| 753 | + 'FHEE__EED_Core_Rest_Api___get_delete_query_params', |
|
| 754 | + $params_for_delete, |
|
| 755 | + $model, |
|
| 756 | + $version |
|
| 757 | + ); |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + |
|
| 761 | + |
|
| 762 | + /** |
|
| 763 | + * Gets info about reading query params that are acceptable |
|
| 764 | + * |
|
| 765 | + * @param \EEM_Base $model eg 'Event' or 'Venue' |
|
| 766 | + * @param string $version |
|
| 767 | + * @return array describing the args acceptable when querying this model |
|
| 768 | + * @throws EE_Error |
|
| 769 | + */ |
|
| 770 | + protected function _get_read_query_params(\EEM_Base $model, $version) |
|
| 771 | + { |
|
| 772 | + $default_orderby = array(); |
|
| 773 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
| 774 | + $default_orderby[$key_field->get_name()] = 'ASC'; |
|
| 775 | + } |
|
| 776 | + return array_merge( |
|
| 777 | + $this->_get_response_selection_query_params($model, $version), |
|
| 778 | + array( |
|
| 779 | + 'where' => array( |
|
| 780 | + 'required' => false, |
|
| 781 | + 'default' => array(), |
|
| 782 | + 'type' => 'object', |
|
| 783 | + //because we accept an almost infinite list of possible where conditions, WP |
|
| 784 | + // core validation and sanitization freaks out. We'll just validate this argument |
|
| 785 | + // while handling the request |
|
| 786 | + 'validate_callback' => null, |
|
| 787 | + 'sanitize_callback' => null, |
|
| 788 | + ), |
|
| 789 | + 'limit' => array( |
|
| 790 | + 'required' => false, |
|
| 791 | + 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
| 792 | + 'type' => array( |
|
| 793 | + 'array', |
|
| 794 | + 'string', |
|
| 795 | + 'integer', |
|
| 796 | + ), |
|
| 797 | + //because we accept a variety of types, WP core validation and sanitization |
|
| 798 | + //freaks out. We'll just validate this argument while handling the request |
|
| 799 | + 'validate_callback' => null, |
|
| 800 | + 'sanitize_callback' => null, |
|
| 801 | + ), |
|
| 802 | + 'order_by' => array( |
|
| 803 | + 'required' => false, |
|
| 804 | + 'default' => $default_orderby, |
|
| 805 | + 'type' => array( |
|
| 806 | + 'object', |
|
| 807 | + 'string', |
|
| 808 | + ),//because we accept a variety of types, WP core validation and sanitization |
|
| 809 | + //freaks out. We'll just validate this argument while handling the request |
|
| 810 | + 'validate_callback' => null, |
|
| 811 | + 'sanitize_callback' => null, |
|
| 812 | + ), |
|
| 813 | + 'group_by' => array( |
|
| 814 | + 'required' => false, |
|
| 815 | + 'default' => null, |
|
| 816 | + 'type' => array( |
|
| 817 | + 'object', |
|
| 818 | + 'string', |
|
| 819 | + ), |
|
| 820 | + //because we accept an almost infinite list of possible groupings, |
|
| 821 | + // WP core validation and sanitization |
|
| 822 | + //freaks out. We'll just validate this argument while handling the request |
|
| 823 | + 'validate_callback' => null, |
|
| 824 | + 'sanitize_callback' => null, |
|
| 825 | + ), |
|
| 826 | + 'having' => array( |
|
| 827 | + 'required' => false, |
|
| 828 | + 'default' => null, |
|
| 829 | + 'type' => 'object', |
|
| 830 | + //because we accept an almost infinite list of possible where conditions, WP |
|
| 831 | + // core validation and sanitization freaks out. We'll just validate this argument |
|
| 832 | + // while handling the request |
|
| 833 | + 'validate_callback' => null, |
|
| 834 | + 'sanitize_callback' => null, |
|
| 835 | + ), |
|
| 836 | + 'caps' => array( |
|
| 837 | + 'required' => false, |
|
| 838 | + 'default' => EEM_Base::caps_read, |
|
| 839 | + 'type' => 'string', |
|
| 840 | + 'enum' => array( |
|
| 841 | + EEM_Base::caps_read, |
|
| 842 | + EEM_Base::caps_read_admin, |
|
| 843 | + EEM_Base::caps_edit, |
|
| 844 | + EEM_Base::caps_delete |
|
| 845 | + ) |
|
| 846 | + ), |
|
| 847 | + ) |
|
| 848 | + ); |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * Gets parameter information for a model regarding writing data |
|
| 855 | + * |
|
| 856 | + * @param string $model_name |
|
| 857 | + * @param ModelVersionInfo $model_version_info |
|
| 858 | + * @param boolean $create whether this is for request to create (in which case we need |
|
| 859 | + * all required params) or just to update (in which case we don't need those on every request) |
|
| 860 | + * @return array |
|
| 861 | + */ |
|
| 862 | + protected function _get_write_params( |
|
| 863 | + $model_name, |
|
| 864 | + ModelVersionInfo $model_version_info, |
|
| 865 | + $create = false |
|
| 866 | + ) { |
|
| 867 | + $model = EE_Registry::instance()->load_model($model_name); |
|
| 868 | + $fields = $model_version_info->fieldsOnModelInThisVersion($model); |
|
| 869 | + $args_info = array(); |
|
| 870 | + foreach ($fields as $field_name => $field_obj) { |
|
| 871 | + if ($field_obj->is_auto_increment()) { |
|
| 872 | + //totally ignore auto increment IDs |
|
| 873 | + continue; |
|
| 874 | + } |
|
| 875 | + $arg_info = $field_obj->getSchema(); |
|
| 876 | + $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null; |
|
| 877 | + $arg_info['required'] = $required; |
|
| 878 | + //remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right? |
|
| 879 | + unset($arg_info['readonly']); |
|
| 880 | + $schema_properties = $field_obj->getSchemaProperties(); |
|
| 881 | + if ( |
|
| 882 | + isset($schema_properties['raw']) |
|
| 883 | + && $field_obj->getSchemaType() === 'object' |
|
| 884 | + ) { |
|
| 885 | + //if there's a "raw" form of this argument, use those properties instead |
|
| 886 | + $arg_info = array_replace( |
|
| 887 | + $arg_info, |
|
| 888 | + $schema_properties['raw'] |
|
| 889 | + ); |
|
| 890 | + } |
|
| 891 | + $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson( |
|
| 892 | + $field_obj, |
|
| 893 | + $field_obj->get_default_value(), |
|
| 894 | + $model_version_info->requestedVersion() |
|
| 895 | + ); |
|
| 896 | + //we do our own validation and sanitization within the controller |
|
| 897 | + if(function_exists('rest_validate_value_from_schema')){ |
|
| 898 | + $sanitize_callback = array( |
|
| 899 | + 'EED_Core_Rest_Api', |
|
| 900 | + 'default_sanitize_callback', |
|
| 901 | + ); |
|
| 902 | + } else { |
|
| 903 | + $sanitize_callback = null; |
|
| 904 | + } |
|
| 905 | + $arg_info['sanitize_callback'] = $sanitize_callback; |
|
| 906 | + $args_info[$field_name] = $arg_info; |
|
| 907 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 908 | + $gmt_arg_info = $arg_info; |
|
| 909 | + $gmt_arg_info['description'] = sprintf( |
|
| 910 | + esc_html__( |
|
| 911 | + '%1$s - the value for this field in UTC. Ignored if %2$s is provided.', |
|
| 912 | + 'event_espresso' |
|
| 913 | + ), |
|
| 914 | + $field_obj->get_nicename(), |
|
| 915 | + $field_name |
|
| 916 | + ); |
|
| 917 | + $args_info[$field_name . '_gmt'] = $gmt_arg_info; |
|
| 918 | + } |
|
| 919 | + } |
|
| 920 | + return $args_info; |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + |
|
| 924 | + |
|
| 925 | + /** |
|
| 926 | + * Replacement for WP API's 'rest_parse_request_arg'. |
|
| 927 | + * If the value is blank but not required, don't bother validating it. |
|
| 928 | + * Also, it uses our email validation instead of WP API's default. |
|
| 929 | + * |
|
| 930 | + * @param $value |
|
| 931 | + * @param WP_REST_Request $request |
|
| 932 | + * @param $param |
|
| 933 | + * @return bool|true|WP_Error |
|
| 934 | + * @throws InvalidArgumentException |
|
| 935 | + * @throws InvalidInterfaceException |
|
| 936 | + * @throws InvalidDataTypeException |
|
| 937 | + */ |
|
| 938 | + public static function default_sanitize_callback( $value, WP_REST_Request $request, $param) |
|
| 939 | + { |
|
| 940 | + $attributes = $request->get_attributes(); |
|
| 941 | + if (! isset($attributes['args'][$param]) |
|
| 942 | + || ! is_array($attributes['args'][$param])) { |
|
| 943 | + $validation_result = true; |
|
| 944 | + } else { |
|
| 945 | + $args = $attributes['args'][$param]; |
|
| 946 | + if (( |
|
| 947 | + $value === '' |
|
| 948 | + || $value === null |
|
| 949 | + ) |
|
| 950 | + && (! isset($args['required']) |
|
| 951 | + || $args['required'] === false |
|
| 952 | + ) |
|
| 953 | + ) { |
|
| 954 | + //not required and not provided? that's cool |
|
| 955 | + $validation_result = true; |
|
| 956 | + } elseif (isset($args['format']) |
|
| 957 | + && $args['format'] === 'email' |
|
| 958 | + ) { |
|
| 959 | + $validation_result = true; |
|
| 960 | + if (! self::_validate_email($value)) { |
|
| 961 | + $validation_result = new WP_Error( |
|
| 962 | + 'rest_invalid_param', |
|
| 963 | + esc_html__( |
|
| 964 | + 'The email address is not valid or does not exist.', |
|
| 965 | + 'event_espresso' |
|
| 966 | + ) |
|
| 967 | + ); |
|
| 968 | + } |
|
| 969 | + } else { |
|
| 970 | + $validation_result = rest_validate_value_from_schema($value, $args, $param); |
|
| 971 | + } |
|
| 972 | + } |
|
| 973 | + if (is_wp_error($validation_result)) { |
|
| 974 | + return $validation_result; |
|
| 975 | + } |
|
| 976 | + return rest_sanitize_request_arg($value, $request, $param); |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + |
|
| 980 | + |
|
| 981 | + /** |
|
| 982 | + * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email() |
|
| 983 | + * |
|
| 984 | + * @param $email |
|
| 985 | + * @return bool |
|
| 986 | + * @throws InvalidArgumentException |
|
| 987 | + * @throws InvalidInterfaceException |
|
| 988 | + * @throws InvalidDataTypeException |
|
| 989 | + */ |
|
| 990 | + protected static function _validate_email($email){ |
|
| 991 | + try { |
|
| 992 | + EmailAddressFactory::create($email); |
|
| 993 | + return true; |
|
| 994 | + } catch (EmailValidationException $e) { |
|
| 995 | + return false; |
|
| 996 | + } |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + |
|
| 1000 | + |
|
| 1001 | + /** |
|
| 1002 | + * Gets routes for the config |
|
| 1003 | + * |
|
| 1004 | + * @return array @see _register_model_routes |
|
| 1005 | + * @deprecated since version 4.9.1 |
|
| 1006 | + */ |
|
| 1007 | + protected function _register_config_routes() |
|
| 1008 | + { |
|
| 1009 | + $config_routes = array(); |
|
| 1010 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 1011 | + $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version( |
|
| 1012 | + $version, |
|
| 1013 | + $hidden_endpoint |
|
| 1014 | + ); |
|
| 1015 | + } |
|
| 1016 | + return $config_routes; |
|
| 1017 | + } |
|
| 1018 | + |
|
| 1019 | + |
|
| 1020 | + |
|
| 1021 | + /** |
|
| 1022 | + * Gets routes for the config for the specified version |
|
| 1023 | + * |
|
| 1024 | + * @param string $version |
|
| 1025 | + * @param boolean $hidden_endpoint |
|
| 1026 | + * @return array |
|
| 1027 | + */ |
|
| 1028 | + protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
| 1029 | + { |
|
| 1030 | + return array( |
|
| 1031 | + 'config' => array( |
|
| 1032 | + array( |
|
| 1033 | + 'callback' => array( |
|
| 1034 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 1035 | + 'handleRequest', |
|
| 1036 | + ), |
|
| 1037 | + 'methods' => WP_REST_Server::READABLE, |
|
| 1038 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 1039 | + 'callback_args' => array($version), |
|
| 1040 | + ), |
|
| 1041 | + ), |
|
| 1042 | + 'site_info' => array( |
|
| 1043 | + array( |
|
| 1044 | + 'callback' => array( |
|
| 1045 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 1046 | + 'handleRequestSiteInfo', |
|
| 1047 | + ), |
|
| 1048 | + 'methods' => WP_REST_Server::READABLE, |
|
| 1049 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 1050 | + 'callback_args' => array($version), |
|
| 1051 | + ), |
|
| 1052 | + ), |
|
| 1053 | + ); |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + |
|
| 1057 | + |
|
| 1058 | + /** |
|
| 1059 | + * Gets the meta info routes |
|
| 1060 | + * |
|
| 1061 | + * @return array @see _register_model_routes |
|
| 1062 | + * @deprecated since version 4.9.1 |
|
| 1063 | + */ |
|
| 1064 | + protected function _register_meta_routes() |
|
| 1065 | + { |
|
| 1066 | + $meta_routes = array(); |
|
| 1067 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 1068 | + $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version( |
|
| 1069 | + $version, |
|
| 1070 | + $hidden_endpoint |
|
| 1071 | + ); |
|
| 1072 | + } |
|
| 1073 | + return $meta_routes; |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + |
|
| 1077 | + |
|
| 1078 | + /** |
|
| 1079 | + * @param string $version |
|
| 1080 | + * @param boolean $hidden_endpoint |
|
| 1081 | + * @return array |
|
| 1082 | + */ |
|
| 1083 | + protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
| 1084 | + { |
|
| 1085 | + return array( |
|
| 1086 | + 'resources' => array( |
|
| 1087 | + array( |
|
| 1088 | + 'callback' => array( |
|
| 1089 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
| 1090 | + 'handleRequestModelsMeta', |
|
| 1091 | + ), |
|
| 1092 | + 'methods' => WP_REST_Server::READABLE, |
|
| 1093 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 1094 | + 'callback_args' => array($version), |
|
| 1095 | + ), |
|
| 1096 | + ), |
|
| 1097 | + ); |
|
| 1098 | + } |
|
| 1099 | + |
|
| 1100 | + |
|
| 1101 | + |
|
| 1102 | + /** |
|
| 1103 | + * Tries to hide old 4.6 endpoints from the |
|
| 1104 | + * |
|
| 1105 | + * @param array $route_data |
|
| 1106 | + * @return array |
|
| 1107 | + * @throws \EE_Error |
|
| 1108 | + */ |
|
| 1109 | + public static function hide_old_endpoints($route_data) |
|
| 1110 | + { |
|
| 1111 | + //allow API clients to override which endpoints get hidden, in case |
|
| 1112 | + //they want to discover particular endpoints |
|
| 1113 | + //also, we don't have access to the request so we have to just grab it from the superglobal |
|
| 1114 | + $force_show_ee_namespace = ltrim( |
|
| 1115 | + EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''), |
|
| 1116 | + '/' |
|
| 1117 | + ); |
|
| 1118 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
| 1119 | + foreach ($relative_urls as $resource_name => $endpoints) { |
|
| 1120 | + foreach ($endpoints as $key => $endpoint) { |
|
| 1121 | + //skip schema and other route options |
|
| 1122 | + if (! is_numeric($key)) { |
|
| 1123 | + continue; |
|
| 1124 | + } |
|
| 1125 | + //by default, hide "hidden_endpoint"s, unless the request indicates |
|
| 1126 | + //to $force_show_ee_namespace, in which case only show that one |
|
| 1127 | + //namespace's endpoints (and hide all others) |
|
| 1128 | + if ( |
|
| 1129 | + ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
| 1130 | + || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
| 1131 | + ) { |
|
| 1132 | + $full_route = '/' . ltrim($namespace, '/'); |
|
| 1133 | + $full_route .= '/' . ltrim($resource_name, '/'); |
|
| 1134 | + unset($route_data[$full_route]); |
|
| 1135 | + } |
|
| 1136 | + } |
|
| 1137 | + } |
|
| 1138 | + } |
|
| 1139 | + return $route_data; |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + |
|
| 1143 | + |
|
| 1144 | + /** |
|
| 1145 | + * Returns an array describing which versions of core support serving requests for. |
|
| 1146 | + * Keys are core versions' major and minor version, and values are the |
|
| 1147 | + * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
| 1148 | + * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
| 1149 | + * the answers table entirely, in which case it would be very difficult for |
|
| 1150 | + * it to serve 4.6-style responses. |
|
| 1151 | + * Versions of core that are missing from this array are unknowns. |
|
| 1152 | + * previous ver |
|
| 1153 | + * |
|
| 1154 | + * @return array |
|
| 1155 | + */ |
|
| 1156 | + public static function version_compatibilities() |
|
| 1157 | + { |
|
| 1158 | + return apply_filters( |
|
| 1159 | + 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
| 1160 | + array( |
|
| 1161 | + '4.8.29' => '4.8.29', |
|
| 1162 | + '4.8.33' => '4.8.29', |
|
| 1163 | + '4.8.34' => '4.8.29', |
|
| 1164 | + '4.8.36' => '4.8.29', |
|
| 1165 | + ) |
|
| 1166 | + ); |
|
| 1167 | + } |
|
| 1168 | + |
|
| 1169 | + |
|
| 1170 | + |
|
| 1171 | + /** |
|
| 1172 | + * Gets the latest API version served. Eg if there |
|
| 1173 | + * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
| 1174 | + * we are on core version 4.8.34, it will return the string "4.8.32" |
|
| 1175 | + * |
|
| 1176 | + * @return string |
|
| 1177 | + */ |
|
| 1178 | + public static function latest_rest_api_version() |
|
| 1179 | + { |
|
| 1180 | + $versions_served = \EED_Core_Rest_Api::versions_served(); |
|
| 1181 | + $versions_served_keys = array_keys($versions_served); |
|
| 1182 | + return end($versions_served_keys); |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + |
|
| 1186 | + |
|
| 1187 | + /** |
|
| 1188 | + * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
| 1189 | + * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
| 1190 | + * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
| 1191 | + * We also indicate whether or not this version should be put in the index or not |
|
| 1192 | + * |
|
| 1193 | + * @return array keys are API version numbers (just major and minor numbers), and values |
|
| 1194 | + * are whether or not they should be hidden |
|
| 1195 | + */ |
|
| 1196 | + public static function versions_served() |
|
| 1197 | + { |
|
| 1198 | + $versions_served = array(); |
|
| 1199 | + $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
| 1200 | + $lowest_compatible_version = end($possibly_served_versions); |
|
| 1201 | + reset($possibly_served_versions); |
|
| 1202 | + $versions_served_historically = array_keys($possibly_served_versions); |
|
| 1203 | + $latest_version = end($versions_served_historically); |
|
| 1204 | + reset($versions_served_historically); |
|
| 1205 | + //for each version of core we have ever served: |
|
| 1206 | + foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
| 1207 | + //if it's not above the current core version, and it's compatible with the current version of core |
|
| 1208 | + if ($key_versioned_endpoint === $latest_version) { |
|
| 1209 | + //don't hide the latest version in the index |
|
| 1210 | + $versions_served[$key_versioned_endpoint] = false; |
|
| 1211 | + } elseif ( |
|
| 1212 | + $key_versioned_endpoint >= $lowest_compatible_version |
|
| 1213 | + && $key_versioned_endpoint < EED_Core_Rest_Api::core_version() |
|
| 1214 | + ) { |
|
| 1215 | + //include, but hide, previous versions which are still supported |
|
| 1216 | + $versions_served[$key_versioned_endpoint] = true; |
|
| 1217 | + } elseif (apply_filters( |
|
| 1218 | + 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
| 1219 | + false, |
|
| 1220 | + $possibly_served_versions |
|
| 1221 | + )) { |
|
| 1222 | + //if a version is no longer supported, don't include it in index or list of versions served |
|
| 1223 | + $versions_served[$key_versioned_endpoint] = true; |
|
| 1224 | + } |
|
| 1225 | + } |
|
| 1226 | + return $versions_served; |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + |
|
| 1230 | + |
|
| 1231 | + /** |
|
| 1232 | + * Gets the major and minor version of EE core's version string |
|
| 1233 | + * |
|
| 1234 | + * @return string |
|
| 1235 | + */ |
|
| 1236 | + public static function core_version() |
|
| 1237 | + { |
|
| 1238 | + return apply_filters( |
|
| 1239 | + 'FHEE__EED_Core_REST_API__core_version', |
|
| 1240 | + implode( |
|
| 1241 | + '.', |
|
| 1242 | + array_slice( |
|
| 1243 | + explode( |
|
| 1244 | + '.', |
|
| 1245 | + espresso_version() |
|
| 1246 | + ), |
|
| 1247 | + 0, |
|
| 1248 | + 3 |
|
| 1249 | + ) |
|
| 1250 | + ) |
|
| 1251 | + ); |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + |
|
| 1255 | + |
|
| 1256 | + /** |
|
| 1257 | + * Gets the default limit that should be used when querying for resources |
|
| 1258 | + * |
|
| 1259 | + * @return int |
|
| 1260 | + */ |
|
| 1261 | + public static function get_default_query_limit() |
|
| 1262 | + { |
|
| 1263 | + //we actually don't use a const because we want folks to always use |
|
| 1264 | + //this method, not the const directly |
|
| 1265 | + return apply_filters( |
|
| 1266 | + 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
| 1267 | + 50 |
|
| 1268 | + ); |
|
| 1269 | + } |
|
| 1270 | + |
|
| 1271 | + |
|
| 1272 | + |
|
| 1273 | + /** |
|
| 1274 | + * run - initial module setup |
|
| 1275 | + * |
|
| 1276 | + * @access public |
|
| 1277 | + * @param WP $WP |
|
| 1278 | + * @return void |
|
| 1279 | + */ |
|
| 1280 | + public function run($WP) |
|
| 1281 | + { |
|
| 1282 | + } |
|
| 1283 | 1283 | } |
| 1284 | 1284 | |
| 1285 | 1285 | // End of file EED_Core_Rest_Api.module.php |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | protected static function _set_hooks_for_changes() |
| 133 | 133 | { |
| 134 | - $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false); |
|
| 134 | + $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES.'rest_api'.DS.'changes'), false); |
|
| 135 | 135 | foreach ($folder_contents as $classname_in_namespace => $filepath) { |
| 136 | 136 | //ignore the base parent class |
| 137 | 137 | //and legacy named classes |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | ) { |
| 141 | 141 | continue; |
| 142 | 142 | } |
| 143 | - $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
| 143 | + $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\'.$classname_in_namespace; |
|
| 144 | 144 | if (class_exists($full_classname)) { |
| 145 | 145 | $instance_of_class = new $full_classname; |
| 146 | 146 | if ($instance_of_class instanceof ChangesInBase) { |
@@ -186,10 +186,10 @@ discard block |
||
| 186 | 186 | * } |
| 187 | 187 | */ |
| 188 | 188 | //skip route options |
| 189 | - if (! is_numeric($endpoint_key)) { |
|
| 189 | + if ( ! is_numeric($endpoint_key)) { |
|
| 190 | 190 | continue; |
| 191 | 191 | } |
| 192 | - if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
| 192 | + if ( ! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
| 193 | 193 | throw new EE_Error( |
| 194 | 194 | esc_html__( |
| 195 | 195 | // @codingStandardsIgnoreStart |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | } |
| 210 | 210 | if (isset($data_for_single_endpoint['callback_args'])) { |
| 211 | 211 | $callback_args = $data_for_single_endpoint['callback_args']; |
| 212 | - $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use ( |
|
| 212 | + $single_endpoint_args['callback'] = function(\WP_REST_Request $request) use ( |
|
| 213 | 213 | $callback, |
| 214 | 214 | $callback_args |
| 215 | 215 | ) { |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | $schema_route_data = $data_for_multiple_endpoints['schema']; |
| 229 | 229 | $schema_callback = $schema_route_data['schema_callback']; |
| 230 | 230 | $callback_args = $schema_route_data['callback_args']; |
| 231 | - $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) { |
|
| 231 | + $multiple_endpoint_args['schema'] = function() use ($schema_callback, $callback_args) { |
|
| 232 | 232 | return call_user_func_array( |
| 233 | 233 | $schema_callback, |
| 234 | 234 | $callback_args |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | { |
| 273 | 273 | //delete the saved EE REST API routes |
| 274 | 274 | foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
| 275 | - delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
| 275 | + delete_option(EED_Core_Rest_Api::saved_routes_option_names.$version); |
|
| 276 | 276 | } |
| 277 | 277 | } |
| 278 | 278 | |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | { |
| 293 | 293 | $ee_routes = array(); |
| 294 | 294 | foreach (self::versions_served() as $version => $hidden_endpoints) { |
| 295 | - $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version( |
|
| 295 | + $ee_routes[self::ee_api_namespace.$version] = self::_get_ee_route_data_for_version( |
|
| 296 | 296 | $version, |
| 297 | 297 | $hidden_endpoints |
| 298 | 298 | ); |
@@ -313,8 +313,8 @@ discard block |
||
| 313 | 313 | */ |
| 314 | 314 | protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
| 315 | 315 | { |
| 316 | - $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
| 317 | - if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
| 316 | + $ee_routes = get_option(self::saved_routes_option_names.$version, null); |
|
| 317 | + if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
| 318 | 318 | $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
| 319 | 319 | } |
| 320 | 320 | return $ee_routes; |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
| 343 | 343 | ) |
| 344 | 344 | ); |
| 345 | - $option_name = self::saved_routes_option_names . $version; |
|
| 345 | + $option_name = self::saved_routes_option_names.$version; |
|
| 346 | 346 | if (get_option($option_name)) { |
| 347 | 347 | update_option($option_name, $routes, true); |
| 348 | 348 | } else { |
@@ -408,11 +408,11 @@ discard block |
||
| 408 | 408 | */ |
| 409 | 409 | public static function should_have_write_endpoints(EEM_Base $model) |
| 410 | 410 | { |
| 411 | - if ($model->is_wp_core_model()){ |
|
| 411 | + if ($model->is_wp_core_model()) { |
|
| 412 | 412 | return false; |
| 413 | 413 | } |
| 414 | - foreach($model->get_tables() as $table){ |
|
| 415 | - if( $table->is_global()){ |
|
| 414 | + foreach ($model->get_tables() as $table) { |
|
| 415 | + if ($table->is_global()) { |
|
| 416 | 416 | return false; |
| 417 | 417 | } |
| 418 | 418 | } |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | * @param $version |
| 428 | 428 | * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event') |
| 429 | 429 | */ |
| 430 | - public static function model_names_with_plural_routes($version){ |
|
| 430 | + public static function model_names_with_plural_routes($version) { |
|
| 431 | 431 | $model_version_info = new ModelVersionInfo($version); |
| 432 | 432 | $models_to_register = $model_version_info->modelsForRequestedVersion(); |
| 433 | 433 | //let's not bother having endpoints for extra metas |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
| 460 | 460 | $model = \EE_Registry::instance()->load_model($model_name); |
| 461 | 461 | //if this isn't a valid model then let's skip iterate to the next item in the loop. |
| 462 | - if (! $model instanceof EEM_Base) { |
|
| 462 | + if ( ! $model instanceof EEM_Base) { |
|
| 463 | 463 | continue; |
| 464 | 464 | } |
| 465 | 465 | //yes we could just register one route for ALL models, but then they wouldn't show up in the index |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | 'hidden_endpoint' => $hidden_endpoint, |
| 477 | 477 | 'args' => $this->_get_read_query_params($model, $version), |
| 478 | 478 | '_links' => array( |
| 479 | - 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
| 479 | + 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace.$version.$singular_model_route), |
|
| 480 | 480 | ), |
| 481 | 481 | ), |
| 482 | 482 | 'schema' => array( |
@@ -499,11 +499,11 @@ discard block |
||
| 499 | 499 | 'args' => $this->_get_response_selection_query_params($model, $version), |
| 500 | 500 | ), |
| 501 | 501 | ); |
| 502 | - if( apply_filters( |
|
| 502 | + if (apply_filters( |
|
| 503 | 503 | 'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints', |
| 504 | 504 | EED_Core_Rest_Api::should_have_write_endpoints($model), |
| 505 | 505 | $model |
| 506 | - )){ |
|
| 506 | + )) { |
|
| 507 | 507 | $model_routes[$plural_model_route][] = array( |
| 508 | 508 | 'callback' => array( |
| 509 | 509 | 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | */ |
| 594 | 594 | public static function get_entity_route($model, $id) |
| 595 | 595 | { |
| 596 | - return EED_Core_Rest_Api::get_collection_route($model). '/' . $id; |
|
| 596 | + return EED_Core_Rest_Api::get_collection_route($model).'/'.$id; |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | $relation_obj->get_other_model()->get_this_model_name(), |
| 614 | 614 | $relation_obj |
| 615 | 615 | ); |
| 616 | - return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
| 616 | + return EED_Core_Rest_Api::get_entity_route($model, $id).'/'.$related_model_name_endpoint_part; |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | |
@@ -625,8 +625,8 @@ discard block |
||
| 625 | 625 | * @param string $version |
| 626 | 626 | * @return string |
| 627 | 627 | */ |
| 628 | - public static function get_versioned_route_to($relative_route, $version = '4.8.36'){ |
|
| 629 | - return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
| 628 | + public static function get_versioned_route_to($relative_route, $version = '4.8.36') { |
|
| 629 | + return '/'.EED_Core_Rest_Api::ee_api_namespace.$version.'/'.$relative_route; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | { |
| 642 | 642 | $routes = array(); |
| 643 | 643 | foreach (self::versions_served() as $version => $hidden_endpoint) { |
| 644 | - $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version( |
|
| 644 | + $routes[self::ee_api_namespace.$version] = $this->_get_rpc_route_data_for_version( |
|
| 645 | 645 | $version, |
| 646 | 646 | $hidden_endpoint |
| 647 | 647 | ); |
@@ -805,7 +805,7 @@ discard block |
||
| 805 | 805 | 'type' => array( |
| 806 | 806 | 'object', |
| 807 | 807 | 'string', |
| 808 | - ),//because we accept a variety of types, WP core validation and sanitization |
|
| 808 | + ), //because we accept a variety of types, WP core validation and sanitization |
|
| 809 | 809 | //freaks out. We'll just validate this argument while handling the request |
| 810 | 810 | 'validate_callback' => null, |
| 811 | 811 | 'sanitize_callback' => null, |
@@ -894,7 +894,7 @@ discard block |
||
| 894 | 894 | $model_version_info->requestedVersion() |
| 895 | 895 | ); |
| 896 | 896 | //we do our own validation and sanitization within the controller |
| 897 | - if(function_exists('rest_validate_value_from_schema')){ |
|
| 897 | + if (function_exists('rest_validate_value_from_schema')) { |
|
| 898 | 898 | $sanitize_callback = array( |
| 899 | 899 | 'EED_Core_Rest_Api', |
| 900 | 900 | 'default_sanitize_callback', |
@@ -914,7 +914,7 @@ discard block |
||
| 914 | 914 | $field_obj->get_nicename(), |
| 915 | 915 | $field_name |
| 916 | 916 | ); |
| 917 | - $args_info[$field_name . '_gmt'] = $gmt_arg_info; |
|
| 917 | + $args_info[$field_name.'_gmt'] = $gmt_arg_info; |
|
| 918 | 918 | } |
| 919 | 919 | } |
| 920 | 920 | return $args_info; |
@@ -935,10 +935,10 @@ discard block |
||
| 935 | 935 | * @throws InvalidInterfaceException |
| 936 | 936 | * @throws InvalidDataTypeException |
| 937 | 937 | */ |
| 938 | - public static function default_sanitize_callback( $value, WP_REST_Request $request, $param) |
|
| 938 | + public static function default_sanitize_callback($value, WP_REST_Request $request, $param) |
|
| 939 | 939 | { |
| 940 | 940 | $attributes = $request->get_attributes(); |
| 941 | - if (! isset($attributes['args'][$param]) |
|
| 941 | + if ( ! isset($attributes['args'][$param]) |
|
| 942 | 942 | || ! is_array($attributes['args'][$param])) { |
| 943 | 943 | $validation_result = true; |
| 944 | 944 | } else { |
@@ -947,7 +947,7 @@ discard block |
||
| 947 | 947 | $value === '' |
| 948 | 948 | || $value === null |
| 949 | 949 | ) |
| 950 | - && (! isset($args['required']) |
|
| 950 | + && ( ! isset($args['required']) |
|
| 951 | 951 | || $args['required'] === false |
| 952 | 952 | ) |
| 953 | 953 | ) { |
@@ -957,7 +957,7 @@ discard block |
||
| 957 | 957 | && $args['format'] === 'email' |
| 958 | 958 | ) { |
| 959 | 959 | $validation_result = true; |
| 960 | - if (! self::_validate_email($value)) { |
|
| 960 | + if ( ! self::_validate_email($value)) { |
|
| 961 | 961 | $validation_result = new WP_Error( |
| 962 | 962 | 'rest_invalid_param', |
| 963 | 963 | esc_html__( |
@@ -987,7 +987,7 @@ discard block |
||
| 987 | 987 | * @throws InvalidInterfaceException |
| 988 | 988 | * @throws InvalidDataTypeException |
| 989 | 989 | */ |
| 990 | - protected static function _validate_email($email){ |
|
| 990 | + protected static function _validate_email($email) { |
|
| 991 | 991 | try { |
| 992 | 992 | EmailAddressFactory::create($email); |
| 993 | 993 | return true; |
@@ -1008,7 +1008,7 @@ discard block |
||
| 1008 | 1008 | { |
| 1009 | 1009 | $config_routes = array(); |
| 1010 | 1010 | foreach (self::versions_served() as $version => $hidden_endpoint) { |
| 1011 | - $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version( |
|
| 1011 | + $config_routes[self::ee_api_namespace.$version] = $this->_get_config_route_data_for_version( |
|
| 1012 | 1012 | $version, |
| 1013 | 1013 | $hidden_endpoint |
| 1014 | 1014 | ); |
@@ -1065,7 +1065,7 @@ discard block |
||
| 1065 | 1065 | { |
| 1066 | 1066 | $meta_routes = array(); |
| 1067 | 1067 | foreach (self::versions_served() as $version => $hidden_endpoint) { |
| 1068 | - $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version( |
|
| 1068 | + $meta_routes[self::ee_api_namespace.$version] = $this->_get_meta_route_data_for_version( |
|
| 1069 | 1069 | $version, |
| 1070 | 1070 | $hidden_endpoint |
| 1071 | 1071 | ); |
@@ -1119,7 +1119,7 @@ discard block |
||
| 1119 | 1119 | foreach ($relative_urls as $resource_name => $endpoints) { |
| 1120 | 1120 | foreach ($endpoints as $key => $endpoint) { |
| 1121 | 1121 | //skip schema and other route options |
| 1122 | - if (! is_numeric($key)) { |
|
| 1122 | + if ( ! is_numeric($key)) { |
|
| 1123 | 1123 | continue; |
| 1124 | 1124 | } |
| 1125 | 1125 | //by default, hide "hidden_endpoint"s, unless the request indicates |
@@ -1129,8 +1129,8 @@ discard block |
||
| 1129 | 1129 | ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
| 1130 | 1130 | || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
| 1131 | 1131 | ) { |
| 1132 | - $full_route = '/' . ltrim($namespace, '/'); |
|
| 1133 | - $full_route .= '/' . ltrim($resource_name, '/'); |
|
| 1132 | + $full_route = '/'.ltrim($namespace, '/'); |
|
| 1133 | + $full_route .= '/'.ltrim($resource_name, '/'); |
|
| 1134 | 1134 | unset($route_data[$full_route]); |
| 1135 | 1135 | } |
| 1136 | 1136 | } |
@@ -21,369 +21,369 @@ |
||
| 21 | 21 | class TicketSelectorRowStandard extends TicketSelectorRow |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var TicketDetails $ticket_details |
|
| 26 | - */ |
|
| 27 | - protected $ticket_details; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var \EE_Ticket_Selector_Config $template_settings |
|
| 31 | - */ |
|
| 32 | - protected $template_settings; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var EE_Tax_Config $tax_settings |
|
| 36 | - */ |
|
| 37 | - protected $tax_settings; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var boolean $prices_displayed_including_taxes |
|
| 41 | - */ |
|
| 42 | - protected $prices_displayed_including_taxes; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var int $row |
|
| 46 | - */ |
|
| 47 | - protected $row; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var int $cols |
|
| 51 | - */ |
|
| 52 | - protected $cols; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var boolean $hidden_input_qty |
|
| 56 | - */ |
|
| 57 | - protected $hidden_input_qty; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @var string $ticket_datetime_classes |
|
| 61 | - */ |
|
| 62 | - protected $ticket_datetime_classes; |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * TicketDetails constructor. |
|
| 68 | - * |
|
| 69 | - * @param TicketDetails $ticket_details |
|
| 70 | - * @param EE_Tax_Config $tax_settings |
|
| 71 | - * @param int $total_tickets |
|
| 72 | - * @param int $max_attendees |
|
| 73 | - * @param int $row |
|
| 74 | - * @param int $cols |
|
| 75 | - * @param boolean $required_ticket_sold_out |
|
| 76 | - * @param string $event_status |
|
| 77 | - * @param string $ticket_datetime_classes |
|
| 78 | - * @throws EE_Error |
|
| 79 | - * @throws UnexpectedEntityException |
|
| 80 | - */ |
|
| 81 | - public function __construct( |
|
| 82 | - TicketDetails $ticket_details, |
|
| 83 | - EE_Tax_Config $tax_settings, |
|
| 84 | - $total_tickets, |
|
| 85 | - $max_attendees, |
|
| 86 | - $row, |
|
| 87 | - $cols, |
|
| 88 | - $required_ticket_sold_out, |
|
| 89 | - $event_status, |
|
| 90 | - $ticket_datetime_classes |
|
| 91 | - ) { |
|
| 92 | - $this->ticket_details = $ticket_details; |
|
| 93 | - $this->template_settings = $ticket_details->getTemplateSettings(); |
|
| 94 | - $this->tax_settings = $tax_settings; |
|
| 95 | - $this->row = $row; |
|
| 96 | - $this->cols = $cols; |
|
| 97 | - $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
| 98 | - parent::__construct( |
|
| 99 | - $ticket_details->getTicket(), |
|
| 100 | - $max_attendees, |
|
| 101 | - $ticket_details->getDateFormat(), |
|
| 102 | - $event_status, |
|
| 103 | - $required_ticket_sold_out, |
|
| 104 | - $total_tickets |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * other ticket rows will need to know if a required ticket is sold out, |
|
| 112 | - * so that they are not offered for sale |
|
| 113 | - * |
|
| 114 | - * @return boolean |
|
| 115 | - */ |
|
| 116 | - public function getRequiredTicketSoldOut() |
|
| 117 | - { |
|
| 118 | - return $this->required_ticket_sold_out; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @return int |
|
| 125 | - */ |
|
| 126 | - public function getCols() |
|
| 127 | - { |
|
| 128 | - return $this->cols; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * getHtml |
|
| 135 | - * |
|
| 136 | - * @return string |
|
| 137 | - * @throws EE_Error |
|
| 138 | - */ |
|
| 139 | - public function getHtml() |
|
| 140 | - { |
|
| 141 | - $this->min = 0; |
|
| 142 | - $this->max = $this->ticket->max(); |
|
| 143 | - $remaining = $this->ticket->remaining(); |
|
| 144 | - if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) { |
|
| 145 | - $this->setTicketMinAndMax($remaining); |
|
| 146 | - } else { |
|
| 147 | - // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
| 148 | - $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
| 149 | - ? $this->ticket->start_date() |
|
| 150 | - : $this->required_ticket_sold_out; |
|
| 151 | - } |
|
| 152 | - $this->setTicketPriceDetails(); |
|
| 153 | - $this->setTicketStatusClasses($remaining); |
|
| 154 | - $filtered_row_html = $this->getFilteredRowHtml(); |
|
| 155 | - if ($filtered_row_html !== false) { |
|
| 156 | - return $filtered_row_html; |
|
| 157 | - } |
|
| 158 | - $ticket_selector_row_html = EEH_HTML::tr( |
|
| 159 | - '', '', |
|
| 160 | - "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " |
|
| 161 | - . espresso_get_object_css_class($this->ticket) |
|
| 162 | - ); |
|
| 163 | - $filtered_row_content = $this->getFilteredRowContents(); |
|
| 164 | - if ($filtered_row_content !== false && $this->max_attendees === 1) { |
|
| 165 | - return $ticket_selector_row_html |
|
| 166 | - . $filtered_row_content |
|
| 167 | - . $this->ticketQtyAndIdHiddenInputs() |
|
| 168 | - . EEH_HTML::trx(); |
|
| 169 | - } |
|
| 170 | - if ($filtered_row_content !== false) { |
|
| 171 | - return $ticket_selector_row_html |
|
| 172 | - . $filtered_row_content |
|
| 173 | - . EEH_HTML::trx(); |
|
| 174 | - } |
|
| 175 | - $this->hidden_input_qty = $this->max_attendees > 1; |
|
| 176 | - |
|
| 177 | - $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
| 178 | - $ticket_selector_row_html .= $this->ticketPriceTableCell(); |
|
| 179 | - $ticket_selector_row_html .= EEH_HTML::td( |
|
| 180 | - '', |
|
| 181 | - '', |
|
| 182 | - 'tckt-slctr-tbl-td-qty cntr', |
|
| 183 | - '', |
|
| 184 | - 'headers="quantity-' . $this->EVT_ID . '"' |
|
| 185 | - ); |
|
| 186 | - $this->setTicketStatusDisplay($remaining); |
|
| 187 | - if (empty($this->ticket_status_display)) { |
|
| 188 | - if ($this->max_attendees === 1) { |
|
| 189 | - // only ONE attendee is allowed to register at a time |
|
| 190 | - $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
| 191 | - } elseif ($this->max > 0) { |
|
| 192 | - $ticket_selector_row_html .= $this->ticketQuantitySelector(); |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - $ticket_selector_row_html .= $this->ticket_status_display; |
|
| 196 | - $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
| 197 | - $ticket_selector_row_html .= $this->ticket_details->display( |
|
| 198 | - $this->ticket_price, |
|
| 199 | - $remaining, |
|
| 200 | - $this->cols |
|
| 201 | - ); |
|
| 202 | - $ticket_selector_row_html .= EEH_HTML::tdx(); |
|
| 203 | - $ticket_selector_row_html .= EEH_HTML::trx(); |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - $this->row++; |
|
| 207 | - return $ticket_selector_row_html; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * getTicketPriceDetails |
|
| 215 | - * |
|
| 216 | - * @return void |
|
| 217 | - * @throws EE_Error |
|
| 218 | - */ |
|
| 219 | - protected function setTicketPriceDetails() |
|
| 220 | - { |
|
| 221 | - $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
| 222 | - ? $this->ticket->get_ticket_total_with_taxes() |
|
| 223 | - : $this->ticket->get_ticket_subtotal(); |
|
| 224 | - $this->ticket_bundle = false; |
|
| 225 | - $ticket_min = $this->ticket->min(); |
|
| 226 | - // for ticket bundles, set min and max qty the same |
|
| 227 | - if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
| 228 | - $this->ticket_price *= $ticket_min; |
|
| 229 | - $this->ticket_bundle = true; |
|
| 230 | - } |
|
| 231 | - $this->ticket_price = apply_filters( |
|
| 232 | - 'FHEE__ticket_selector_chart_template__ticket_price', |
|
| 233 | - $this->ticket_price, |
|
| 234 | - $this->ticket |
|
| 235 | - ); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * ticketNameTableCell |
|
| 243 | - * |
|
| 244 | - * @return string |
|
| 245 | - * @throws EE_Error |
|
| 246 | - */ |
|
| 247 | - protected function ticketNameTableCell() |
|
| 248 | - { |
|
| 249 | - $html = EEH_HTML::td( |
|
| 250 | - '', |
|
| 251 | - '', |
|
| 252 | - 'tckt-slctr-tbl-td-name', |
|
| 253 | - '', |
|
| 254 | - 'headers="details-' . $this->EVT_ID . '"' |
|
| 255 | - ); |
|
| 256 | - $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
| 257 | - $html .= $this->ticket_details->getShowHideLinks(); |
|
| 258 | - if ($this->ticket->required()) { |
|
| 259 | - $html .= EEH_HTML::p( |
|
| 260 | - apply_filters( |
|
| 261 | - 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
| 262 | - esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
| 263 | - ), |
|
| 264 | - '', 'ticket-required-pg' |
|
| 265 | - ); |
|
| 266 | - } |
|
| 267 | - $html .= EEH_HTML::tdx(); |
|
| 268 | - return $html; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * ticketPriceTableCell |
|
| 275 | - * |
|
| 276 | - * @return string |
|
| 277 | - * @throws EE_Error |
|
| 278 | - */ |
|
| 279 | - protected function ticketPriceTableCell() |
|
| 280 | - { |
|
| 281 | - $html = ''; |
|
| 282 | - if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
| 283 | - $html .= EEH_HTML::td( |
|
| 284 | - '', |
|
| 285 | - '', |
|
| 286 | - 'tckt-slctr-tbl-td-price jst-rght', |
|
| 287 | - '', |
|
| 288 | - 'headers="price-' . $this->EVT_ID . '"' |
|
| 289 | - ); |
|
| 290 | - $html .= \EEH_Template::format_currency($this->ticket_price); |
|
| 291 | - $html .= $this->ticket->taxable() |
|
| 292 | - ? EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' ) |
|
| 293 | - : ''; |
|
| 294 | - $html .= ' '; |
|
| 295 | - $html .= EEH_HTML::span( |
|
| 296 | - $this->ticket_bundle |
|
| 297 | - ? apply_filters( |
|
| 298 | - 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
| 299 | - __(' / bundle', 'event_espresso') |
|
| 300 | - ) |
|
| 301 | - : apply_filters( |
|
| 302 | - 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
| 303 | - __('', 'event_espresso') |
|
| 304 | - ), |
|
| 305 | - '', 'smaller-text no-bold' |
|
| 306 | - ); |
|
| 307 | - $html .= ' '; |
|
| 308 | - $html .= EEH_HTML::tdx(); |
|
| 309 | - $this->cols++; |
|
| 310 | - } |
|
| 311 | - return $html; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * onlyOneAttendeeCanRegister |
|
| 318 | - * |
|
| 319 | - * @return string |
|
| 320 | - */ |
|
| 321 | - protected function onlyOneAttendeeCanRegister() |
|
| 322 | - { |
|
| 323 | - // display submit button since we have tickets available |
|
| 324 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 325 | - $this->hidden_input_qty = false; |
|
| 326 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
| 327 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
| 328 | - $html .= esc_html__('Select this ticket', 'event_espresso') . '</label>'; |
|
| 329 | - $html .= '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
| 330 | - $html .= ' id="' . $id . '"'; |
|
| 331 | - $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
| 332 | - $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
|
| 333 | - $html .= ' title=""/>'; |
|
| 334 | - return $html; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * ticketQuantitySelector |
|
| 341 | - * |
|
| 342 | - * @return string |
|
| 343 | - * @throws EE_Error |
|
| 344 | - */ |
|
| 345 | - protected function ticketQuantitySelector() |
|
| 346 | - { |
|
| 347 | - // display submit button since we have tickets available |
|
| 348 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 349 | - $this->hidden_input_qty = false; |
|
| 350 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
| 351 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
| 352 | - $html .= esc_html__('Quantity', 'event_espresso') . '</label>'; |
|
| 353 | - $html .= '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
| 354 | - $html .= ' id="' . $id . '"'; |
|
| 355 | - $html .= ' class="ticket-selector-tbl-qty-slct">'; |
|
| 356 | - // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
| 357 | - if ($this->min !== 0 && ! $this->ticket->required()) { |
|
| 358 | - $html .= '<option value="0"> 0 </option>'; |
|
| 359 | - } |
|
| 360 | - // offer ticket quantities from the min to the max |
|
| 361 | - for ($i = $this->min; $i <= $this->max; $i++) { |
|
| 362 | - $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
| 363 | - } |
|
| 364 | - $html .= '</select>'; |
|
| 365 | - return $html; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * getHiddenInputs |
|
| 372 | - * |
|
| 373 | - * @return string |
|
| 374 | - * @throws EE_Error |
|
| 375 | - */ |
|
| 376 | - protected function ticketQtyAndIdHiddenInputs() |
|
| 377 | - { |
|
| 378 | - $html = ''; |
|
| 379 | - // depending on group reg we need to change the format for qty |
|
| 380 | - if ($this->hidden_input_qty) { |
|
| 381 | - $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
| 382 | - } |
|
| 383 | - $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
| 384 | - $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
| 385 | - return $html; |
|
| 386 | - } |
|
| 24 | + /** |
|
| 25 | + * @var TicketDetails $ticket_details |
|
| 26 | + */ |
|
| 27 | + protected $ticket_details; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var \EE_Ticket_Selector_Config $template_settings |
|
| 31 | + */ |
|
| 32 | + protected $template_settings; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var EE_Tax_Config $tax_settings |
|
| 36 | + */ |
|
| 37 | + protected $tax_settings; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var boolean $prices_displayed_including_taxes |
|
| 41 | + */ |
|
| 42 | + protected $prices_displayed_including_taxes; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var int $row |
|
| 46 | + */ |
|
| 47 | + protected $row; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var int $cols |
|
| 51 | + */ |
|
| 52 | + protected $cols; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var boolean $hidden_input_qty |
|
| 56 | + */ |
|
| 57 | + protected $hidden_input_qty; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @var string $ticket_datetime_classes |
|
| 61 | + */ |
|
| 62 | + protected $ticket_datetime_classes; |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * TicketDetails constructor. |
|
| 68 | + * |
|
| 69 | + * @param TicketDetails $ticket_details |
|
| 70 | + * @param EE_Tax_Config $tax_settings |
|
| 71 | + * @param int $total_tickets |
|
| 72 | + * @param int $max_attendees |
|
| 73 | + * @param int $row |
|
| 74 | + * @param int $cols |
|
| 75 | + * @param boolean $required_ticket_sold_out |
|
| 76 | + * @param string $event_status |
|
| 77 | + * @param string $ticket_datetime_classes |
|
| 78 | + * @throws EE_Error |
|
| 79 | + * @throws UnexpectedEntityException |
|
| 80 | + */ |
|
| 81 | + public function __construct( |
|
| 82 | + TicketDetails $ticket_details, |
|
| 83 | + EE_Tax_Config $tax_settings, |
|
| 84 | + $total_tickets, |
|
| 85 | + $max_attendees, |
|
| 86 | + $row, |
|
| 87 | + $cols, |
|
| 88 | + $required_ticket_sold_out, |
|
| 89 | + $event_status, |
|
| 90 | + $ticket_datetime_classes |
|
| 91 | + ) { |
|
| 92 | + $this->ticket_details = $ticket_details; |
|
| 93 | + $this->template_settings = $ticket_details->getTemplateSettings(); |
|
| 94 | + $this->tax_settings = $tax_settings; |
|
| 95 | + $this->row = $row; |
|
| 96 | + $this->cols = $cols; |
|
| 97 | + $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
| 98 | + parent::__construct( |
|
| 99 | + $ticket_details->getTicket(), |
|
| 100 | + $max_attendees, |
|
| 101 | + $ticket_details->getDateFormat(), |
|
| 102 | + $event_status, |
|
| 103 | + $required_ticket_sold_out, |
|
| 104 | + $total_tickets |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * other ticket rows will need to know if a required ticket is sold out, |
|
| 112 | + * so that they are not offered for sale |
|
| 113 | + * |
|
| 114 | + * @return boolean |
|
| 115 | + */ |
|
| 116 | + public function getRequiredTicketSoldOut() |
|
| 117 | + { |
|
| 118 | + return $this->required_ticket_sold_out; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @return int |
|
| 125 | + */ |
|
| 126 | + public function getCols() |
|
| 127 | + { |
|
| 128 | + return $this->cols; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * getHtml |
|
| 135 | + * |
|
| 136 | + * @return string |
|
| 137 | + * @throws EE_Error |
|
| 138 | + */ |
|
| 139 | + public function getHtml() |
|
| 140 | + { |
|
| 141 | + $this->min = 0; |
|
| 142 | + $this->max = $this->ticket->max(); |
|
| 143 | + $remaining = $this->ticket->remaining(); |
|
| 144 | + if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) { |
|
| 145 | + $this->setTicketMinAndMax($remaining); |
|
| 146 | + } else { |
|
| 147 | + // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
| 148 | + $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
| 149 | + ? $this->ticket->start_date() |
|
| 150 | + : $this->required_ticket_sold_out; |
|
| 151 | + } |
|
| 152 | + $this->setTicketPriceDetails(); |
|
| 153 | + $this->setTicketStatusClasses($remaining); |
|
| 154 | + $filtered_row_html = $this->getFilteredRowHtml(); |
|
| 155 | + if ($filtered_row_html !== false) { |
|
| 156 | + return $filtered_row_html; |
|
| 157 | + } |
|
| 158 | + $ticket_selector_row_html = EEH_HTML::tr( |
|
| 159 | + '', '', |
|
| 160 | + "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " |
|
| 161 | + . espresso_get_object_css_class($this->ticket) |
|
| 162 | + ); |
|
| 163 | + $filtered_row_content = $this->getFilteredRowContents(); |
|
| 164 | + if ($filtered_row_content !== false && $this->max_attendees === 1) { |
|
| 165 | + return $ticket_selector_row_html |
|
| 166 | + . $filtered_row_content |
|
| 167 | + . $this->ticketQtyAndIdHiddenInputs() |
|
| 168 | + . EEH_HTML::trx(); |
|
| 169 | + } |
|
| 170 | + if ($filtered_row_content !== false) { |
|
| 171 | + return $ticket_selector_row_html |
|
| 172 | + . $filtered_row_content |
|
| 173 | + . EEH_HTML::trx(); |
|
| 174 | + } |
|
| 175 | + $this->hidden_input_qty = $this->max_attendees > 1; |
|
| 176 | + |
|
| 177 | + $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
| 178 | + $ticket_selector_row_html .= $this->ticketPriceTableCell(); |
|
| 179 | + $ticket_selector_row_html .= EEH_HTML::td( |
|
| 180 | + '', |
|
| 181 | + '', |
|
| 182 | + 'tckt-slctr-tbl-td-qty cntr', |
|
| 183 | + '', |
|
| 184 | + 'headers="quantity-' . $this->EVT_ID . '"' |
|
| 185 | + ); |
|
| 186 | + $this->setTicketStatusDisplay($remaining); |
|
| 187 | + if (empty($this->ticket_status_display)) { |
|
| 188 | + if ($this->max_attendees === 1) { |
|
| 189 | + // only ONE attendee is allowed to register at a time |
|
| 190 | + $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
| 191 | + } elseif ($this->max > 0) { |
|
| 192 | + $ticket_selector_row_html .= $this->ticketQuantitySelector(); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + $ticket_selector_row_html .= $this->ticket_status_display; |
|
| 196 | + $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
| 197 | + $ticket_selector_row_html .= $this->ticket_details->display( |
|
| 198 | + $this->ticket_price, |
|
| 199 | + $remaining, |
|
| 200 | + $this->cols |
|
| 201 | + ); |
|
| 202 | + $ticket_selector_row_html .= EEH_HTML::tdx(); |
|
| 203 | + $ticket_selector_row_html .= EEH_HTML::trx(); |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + $this->row++; |
|
| 207 | + return $ticket_selector_row_html; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * getTicketPriceDetails |
|
| 215 | + * |
|
| 216 | + * @return void |
|
| 217 | + * @throws EE_Error |
|
| 218 | + */ |
|
| 219 | + protected function setTicketPriceDetails() |
|
| 220 | + { |
|
| 221 | + $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
| 222 | + ? $this->ticket->get_ticket_total_with_taxes() |
|
| 223 | + : $this->ticket->get_ticket_subtotal(); |
|
| 224 | + $this->ticket_bundle = false; |
|
| 225 | + $ticket_min = $this->ticket->min(); |
|
| 226 | + // for ticket bundles, set min and max qty the same |
|
| 227 | + if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
| 228 | + $this->ticket_price *= $ticket_min; |
|
| 229 | + $this->ticket_bundle = true; |
|
| 230 | + } |
|
| 231 | + $this->ticket_price = apply_filters( |
|
| 232 | + 'FHEE__ticket_selector_chart_template__ticket_price', |
|
| 233 | + $this->ticket_price, |
|
| 234 | + $this->ticket |
|
| 235 | + ); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * ticketNameTableCell |
|
| 243 | + * |
|
| 244 | + * @return string |
|
| 245 | + * @throws EE_Error |
|
| 246 | + */ |
|
| 247 | + protected function ticketNameTableCell() |
|
| 248 | + { |
|
| 249 | + $html = EEH_HTML::td( |
|
| 250 | + '', |
|
| 251 | + '', |
|
| 252 | + 'tckt-slctr-tbl-td-name', |
|
| 253 | + '', |
|
| 254 | + 'headers="details-' . $this->EVT_ID . '"' |
|
| 255 | + ); |
|
| 256 | + $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
| 257 | + $html .= $this->ticket_details->getShowHideLinks(); |
|
| 258 | + if ($this->ticket->required()) { |
|
| 259 | + $html .= EEH_HTML::p( |
|
| 260 | + apply_filters( |
|
| 261 | + 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
| 262 | + esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
| 263 | + ), |
|
| 264 | + '', 'ticket-required-pg' |
|
| 265 | + ); |
|
| 266 | + } |
|
| 267 | + $html .= EEH_HTML::tdx(); |
|
| 268 | + return $html; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * ticketPriceTableCell |
|
| 275 | + * |
|
| 276 | + * @return string |
|
| 277 | + * @throws EE_Error |
|
| 278 | + */ |
|
| 279 | + protected function ticketPriceTableCell() |
|
| 280 | + { |
|
| 281 | + $html = ''; |
|
| 282 | + if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
| 283 | + $html .= EEH_HTML::td( |
|
| 284 | + '', |
|
| 285 | + '', |
|
| 286 | + 'tckt-slctr-tbl-td-price jst-rght', |
|
| 287 | + '', |
|
| 288 | + 'headers="price-' . $this->EVT_ID . '"' |
|
| 289 | + ); |
|
| 290 | + $html .= \EEH_Template::format_currency($this->ticket_price); |
|
| 291 | + $html .= $this->ticket->taxable() |
|
| 292 | + ? EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' ) |
|
| 293 | + : ''; |
|
| 294 | + $html .= ' '; |
|
| 295 | + $html .= EEH_HTML::span( |
|
| 296 | + $this->ticket_bundle |
|
| 297 | + ? apply_filters( |
|
| 298 | + 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
| 299 | + __(' / bundle', 'event_espresso') |
|
| 300 | + ) |
|
| 301 | + : apply_filters( |
|
| 302 | + 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
| 303 | + __('', 'event_espresso') |
|
| 304 | + ), |
|
| 305 | + '', 'smaller-text no-bold' |
|
| 306 | + ); |
|
| 307 | + $html .= ' '; |
|
| 308 | + $html .= EEH_HTML::tdx(); |
|
| 309 | + $this->cols++; |
|
| 310 | + } |
|
| 311 | + return $html; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * onlyOneAttendeeCanRegister |
|
| 318 | + * |
|
| 319 | + * @return string |
|
| 320 | + */ |
|
| 321 | + protected function onlyOneAttendeeCanRegister() |
|
| 322 | + { |
|
| 323 | + // display submit button since we have tickets available |
|
| 324 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 325 | + $this->hidden_input_qty = false; |
|
| 326 | + $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
| 327 | + $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
| 328 | + $html .= esc_html__('Select this ticket', 'event_espresso') . '</label>'; |
|
| 329 | + $html .= '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
| 330 | + $html .= ' id="' . $id . '"'; |
|
| 331 | + $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
| 332 | + $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
|
| 333 | + $html .= ' title=""/>'; |
|
| 334 | + return $html; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * ticketQuantitySelector |
|
| 341 | + * |
|
| 342 | + * @return string |
|
| 343 | + * @throws EE_Error |
|
| 344 | + */ |
|
| 345 | + protected function ticketQuantitySelector() |
|
| 346 | + { |
|
| 347 | + // display submit button since we have tickets available |
|
| 348 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 349 | + $this->hidden_input_qty = false; |
|
| 350 | + $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
| 351 | + $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
| 352 | + $html .= esc_html__('Quantity', 'event_espresso') . '</label>'; |
|
| 353 | + $html .= '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
| 354 | + $html .= ' id="' . $id . '"'; |
|
| 355 | + $html .= ' class="ticket-selector-tbl-qty-slct">'; |
|
| 356 | + // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
| 357 | + if ($this->min !== 0 && ! $this->ticket->required()) { |
|
| 358 | + $html .= '<option value="0"> 0 </option>'; |
|
| 359 | + } |
|
| 360 | + // offer ticket quantities from the min to the max |
|
| 361 | + for ($i = $this->min; $i <= $this->max; $i++) { |
|
| 362 | + $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
| 363 | + } |
|
| 364 | + $html .= '</select>'; |
|
| 365 | + return $html; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * getHiddenInputs |
|
| 372 | + * |
|
| 373 | + * @return string |
|
| 374 | + * @throws EE_Error |
|
| 375 | + */ |
|
| 376 | + protected function ticketQtyAndIdHiddenInputs() |
|
| 377 | + { |
|
| 378 | + $html = ''; |
|
| 379 | + // depending on group reg we need to change the format for qty |
|
| 380 | + if ($this->hidden_input_qty) { |
|
| 381 | + $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
| 382 | + } |
|
| 383 | + $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
| 384 | + $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
| 385 | + return $html; |
|
| 386 | + } |
|
| 387 | 387 | |
| 388 | 388 | } |
| 389 | 389 | // End of file TicketSelectorRowStandard.php |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | '', |
| 182 | 182 | 'tckt-slctr-tbl-td-qty cntr', |
| 183 | 183 | '', |
| 184 | - 'headers="quantity-' . $this->EVT_ID . '"' |
|
| 184 | + 'headers="quantity-'.$this->EVT_ID.'"' |
|
| 185 | 185 | ); |
| 186 | 186 | $this->setTicketStatusDisplay($remaining); |
| 187 | 187 | if (empty($this->ticket_status_display)) { |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | '', |
| 252 | 252 | 'tckt-slctr-tbl-td-name', |
| 253 | 253 | '', |
| 254 | - 'headers="details-' . $this->EVT_ID . '"' |
|
| 254 | + 'headers="details-'.$this->EVT_ID.'"' |
|
| 255 | 255 | ); |
| 256 | 256 | $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
| 257 | 257 | $html .= $this->ticket_details->getShowHideLinks(); |
@@ -285,11 +285,11 @@ discard block |
||
| 285 | 285 | '', |
| 286 | 286 | 'tckt-slctr-tbl-td-price jst-rght', |
| 287 | 287 | '', |
| 288 | - 'headers="price-' . $this->EVT_ID . '"' |
|
| 288 | + 'headers="price-'.$this->EVT_ID.'"' |
|
| 289 | 289 | ); |
| 290 | 290 | $html .= \EEH_Template::format_currency($this->ticket_price); |
| 291 | 291 | $html .= $this->ticket->taxable() |
| 292 | - ? EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' ) |
|
| 292 | + ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text') |
|
| 293 | 293 | : ''; |
| 294 | 294 | $html .= ' '; |
| 295 | 295 | $html .= EEH_HTML::span( |
@@ -323,12 +323,12 @@ discard block |
||
| 323 | 323 | // display submit button since we have tickets available |
| 324 | 324 | add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
| 325 | 325 | $this->hidden_input_qty = false; |
| 326 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
| 327 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
| 328 | - $html .= esc_html__('Select this ticket', 'event_espresso') . '</label>'; |
|
| 329 | - $html .= '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
| 330 | - $html .= ' id="' . $id . '"'; |
|
| 331 | - $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
| 326 | + $id = 'ticket-selector-tbl-qty-slct-'.$this->EVT_ID.'-'.$this->row; |
|
| 327 | + $html = '<label class="ee-a11y-screen-reader-text" for="'.$id.'">'; |
|
| 328 | + $html .= esc_html__('Select this ticket', 'event_espresso').'</label>'; |
|
| 329 | + $html .= '<input type="radio" name="tkt-slctr-qty-'.$this->EVT_ID.'"'; |
|
| 330 | + $html .= ' id="'.$id.'"'; |
|
| 331 | + $html .= ' class="ticket-selector-tbl-qty-slct" value="'.$this->row.'-1"'; |
|
| 332 | 332 | $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
| 333 | 333 | $html .= ' title=""/>'; |
| 334 | 334 | return $html; |
@@ -347,11 +347,11 @@ discard block |
||
| 347 | 347 | // display submit button since we have tickets available |
| 348 | 348 | add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
| 349 | 349 | $this->hidden_input_qty = false; |
| 350 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
| 351 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
| 352 | - $html .= esc_html__('Quantity', 'event_espresso') . '</label>'; |
|
| 353 | - $html .= '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
| 354 | - $html .= ' id="' . $id . '"'; |
|
| 350 | + $id = 'ticket-selector-tbl-qty-slct-'.$this->EVT_ID.'-'.$this->row; |
|
| 351 | + $html = '<label class="ee-a11y-screen-reader-text" for="'.$id.'">'; |
|
| 352 | + $html .= esc_html__('Quantity', 'event_espresso').'</label>'; |
|
| 353 | + $html .= '<select name="tkt-slctr-qty-'.$this->EVT_ID.'[]"'; |
|
| 354 | + $html .= ' id="'.$id.'"'; |
|
| 355 | 355 | $html .= ' class="ticket-selector-tbl-qty-slct">'; |
| 356 | 356 | // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
| 357 | 357 | if ($this->min !== 0 && ! $this->ticket->required()) { |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | } |
| 360 | 360 | // offer ticket quantities from the min to the max |
| 361 | 361 | for ($i = $this->min; $i <= $this->max; $i++) { |
| 362 | - $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
| 362 | + $html .= '<option value="'.$i.'"> '.$i.' </option>'; |
|
| 363 | 363 | } |
| 364 | 364 | $html .= '</select>'; |
| 365 | 365 | return $html; |
@@ -378,10 +378,10 @@ discard block |
||
| 378 | 378 | $html = ''; |
| 379 | 379 | // depending on group reg we need to change the format for qty |
| 380 | 380 | if ($this->hidden_input_qty) { |
| 381 | - $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
| 381 | + $html .= '<input type="hidden" name="tkt-slctr-qty-'.$this->EVT_ID.'[]" value="0"/>'; |
|
| 382 | 382 | } |
| 383 | - $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
| 384 | - $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
| 383 | + $html .= '<input type="hidden" name="tkt-slctr-ticket-id-'.$this->EVT_ID.'[]"'; |
|
| 384 | + $html .= ' value="'.$this->ticket->ID().'"/>'; |
|
| 385 | 385 | return $html; |
| 386 | 386 | } |
| 387 | 387 | |
@@ -12,13 +12,13 @@ discard block |
||
| 12 | 12 | /** @var string $price_breakdown_heading */ |
| 13 | 13 | /** @var \EventEspresso\modules\ticket_selector\TicketDetails $ticket_details */ |
| 14 | 14 | ?> |
| 15 | -<?php if ( $show_ticket_details ) : ?> |
|
| 15 | +<?php if ($show_ticket_details) : ?> |
|
| 16 | 16 | <tr class="tckt-slctr-tkt-details-tr <?php echo $ticket_details_row_class; ?>"> |
| 17 | 17 | <td class="tckt-slctr-tkt-details-td" colspan="<?php echo $cols; ?>"> |
| 18 | 18 | <div id="<?php echo $ticket_details_css_id; ?>-dv" class="tckt-slctr-tkt-details-dv" style="display: none;"> |
| 19 | 19 | |
| 20 | 20 | <section class="tckt-slctr-tkt-details-sctn"> |
| 21 | - <h4><?php echo esc_html__( 'Details', 'event_espresso' ); ?></h4> |
|
| 21 | + <h4><?php echo esc_html__('Details', 'event_espresso'); ?></h4> |
|
| 22 | 22 | <p><?php echo $ticket->description(); ?></p> |
| 23 | 23 | |
| 24 | 24 | <?php |
@@ -33,42 +33,42 @@ discard block |
||
| 33 | 33 | <section class="tckt-slctr-tkt-sale-dates-sctn"> |
| 34 | 34 | <h5><?php echo apply_filters( |
| 35 | 35 | 'FHEE__ticket_selector_chart_template__ticket_details_sales_date_heading', |
| 36 | - esc_html__( 'Sale Dates', 'event_espresso' ) |
|
| 36 | + esc_html__('Sale Dates', 'event_espresso') |
|
| 37 | 37 | ); ?> |
| 38 | 38 | </h5> |
| 39 | 39 | <span class="drk-grey-text small-text no-bold"> - <?php echo apply_filters( |
| 40 | 40 | 'FHEE__ticket_selector_chart_template__ticket_details_dates_available_message', |
| 41 | - esc_html__( 'The dates when this option is available for purchase.', 'event_espresso' ) |
|
| 41 | + esc_html__('The dates when this option is available for purchase.', 'event_espresso') |
|
| 42 | 42 | ); ?></span> |
| 43 | 43 | <br/> |
| 44 | 44 | <span class="ticket-details-label-spn drk-grey-text"><?php echo apply_filters( |
| 45 | 45 | 'FHEE__ticket_selector_chart_template__ticket_details_goes_on_sale', |
| 46 | - esc_html__( 'Goes On Sale:', 'event_espresso' ) |
|
| 46 | + esc_html__('Goes On Sale:', 'event_espresso') |
|
| 47 | 47 | ); ?></span> |
| 48 | 48 | <span class="dashicons dashicons-calendar"></span> |
| 49 | - <?php echo $ticket->get_i18n_datetime('TKT_start_date', $date_format) . ' '; ?> |
|
| 49 | + <?php echo $ticket->get_i18n_datetime('TKT_start_date', $date_format).' '; ?> |
|
| 50 | 50 | <span class="dashicons dashicons-clock"></span> |
| 51 | - <?php echo $ticket->get_i18n_datetime('TKT_start_date',$time_format); ?> |
|
| 51 | + <?php echo $ticket->get_i18n_datetime('TKT_start_date', $time_format); ?> |
|
| 52 | 52 | <br/> |
| 53 | 53 | <span class="ticket-details-label-spn drk-grey-text"><?php echo apply_filters( |
| 54 | 54 | 'FHEE__ticket_selector_chart_template__ticket_details_sales_end', |
| 55 | - esc_html__( 'Sales End:', 'event_espresso' ) |
|
| 55 | + esc_html__('Sales End:', 'event_espresso') |
|
| 56 | 56 | ); ?></span> |
| 57 | 57 | <span class="dashicons dashicons-calendar"></span> |
| 58 | - <?php echo $ticket->get_i18n_datetime('TKT_end_date', $date_format) . ' '; ?> |
|
| 58 | + <?php echo $ticket->get_i18n_datetime('TKT_end_date', $date_format).' '; ?> |
|
| 59 | 59 | <span class="dashicons dashicons-clock"></span> |
| 60 | 60 | <?php echo $ticket->get_i18n_datetime('TKT_end_date', $time_format); ?> |
| 61 | 61 | <br/> |
| 62 | 62 | </section> |
| 63 | 63 | <br/> |
| 64 | 64 | |
| 65 | - <?php do_action( 'AHEE__ticket_selector_chart_template__after_ticket_date', $ticket ); ?> |
|
| 65 | + <?php do_action('AHEE__ticket_selector_chart_template__after_ticket_date', $ticket); ?> |
|
| 66 | 66 | |
| 67 | - <?php if ( $ticket->min() && $ticket->max() ) { ?> |
|
| 67 | + <?php if ($ticket->min() && $ticket->max()) { ?> |
|
| 68 | 68 | <section class="tckt-slctr-tkt-quantities-sctn"> |
| 69 | 69 | <h5><?php echo apply_filters( |
| 70 | 70 | 'FHEE__ticket_selector_chart_template__ticket_details_purchasable_quantities_heading', |
| 71 | - esc_html__( 'Purchasable Quantities', 'event_espresso' ) |
|
| 71 | + esc_html__('Purchasable Quantities', 'event_espresso') |
|
| 72 | 72 | ); ?></h5> |
| 73 | 73 | <span class="drk-grey-text small-text no-bold"> - <?php echo apply_filters( |
| 74 | 74 | 'FHEE__ticket_selector_chart_template__ticket_details_purchasable_quantities_message', |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | ); ?></span><br/> |
| 80 | 80 | <span class="ticket-details-label-spn drk-grey-text"><?php echo apply_filters( |
| 81 | 81 | 'FHEE__ticket_selector_chart_template__ticket_details_purchasable_quantities_min_qty', |
| 82 | - esc_html__( 'Minimum Qty:', 'event_espresso' ) |
|
| 82 | + esc_html__('Minimum Qty:', 'event_espresso') |
|
| 83 | 83 | ); ?></span><?php echo $ticket->min() > 0 ? $ticket->min() : 0; ?> |
| 84 | - <?php if ( $ticket->min() > $remaining ) { ?> <span |
|
| 84 | + <?php if ($ticket->min() > $remaining) { ?> <span |
|
| 85 | 85 | class="important-notice small-text"><?php echo apply_filters( |
| 86 | 86 | 'FHEE__ticket_selector_chart_template__ticket_details_purchasable_quantities_min_qty_message', |
| 87 | 87 | esc_html__( |
@@ -92,18 +92,18 @@ discard block |
||
| 92 | 92 | <?php //$max = min( $max, $max_atndz );?> |
| 93 | 93 | <span class="ticket-details-label-spn drk-grey-text"><?php echo apply_filters( |
| 94 | 94 | 'FHEE__ticket_selector_chart_template__ticket_details_purchasable_quantities_max_qty', |
| 95 | - esc_html__( 'Maximum Qty:', 'event_espresso' ) |
|
| 96 | - ); ?></span><?php echo $ticket->max() === EE_INF ? esc_html__( 'no limit', 'event_espresso' ) |
|
| 97 | - : max( $ticket->max(), 1 ); ?><br/> |
|
| 95 | + esc_html__('Maximum Qty:', 'event_espresso') |
|
| 96 | + ); ?></span><?php echo $ticket->max() === EE_INF ? esc_html__('no limit', 'event_espresso') |
|
| 97 | + : max($ticket->max(), 1); ?><br/> |
|
| 98 | 98 | </section> |
| 99 | 99 | <br/> |
| 100 | 100 | <?php } ?> |
| 101 | 101 | |
| 102 | - <?php if ( ( ! defined( 'EE_DECAF' ) || EE_DECAF !== true ) && $ticket->uses() !== EE_INF ) { ?> |
|
| 102 | + <?php if (( ! defined('EE_DECAF') || EE_DECAF !== true) && $ticket->uses() !== EE_INF) { ?> |
|
| 103 | 103 | <section class="tckt-slctr-tkt-uses-sctn"> |
| 104 | 104 | <h5><?php echo apply_filters( |
| 105 | 105 | 'FHEE__ticket_selector_chart_template__ticket_details_event_date_ticket_uses_heading', |
| 106 | - esc_html__( 'Event Date Ticket Uses', 'event_espresso' ) |
|
| 106 | + esc_html__('Event Date Ticket Uses', 'event_espresso') |
|
| 107 | 107 | ); ?></h5> |
| 108 | 108 | <span class="drk-grey-text small-text no-bold"> - <?php |
| 109 | 109 | echo apply_filters( |
@@ -121,23 +121,23 @@ discard block |
||
| 121 | 121 | ?></span><br/> |
| 122 | 122 | <span class="ticket-details-label-spn drk-grey-text"><?php echo apply_filters( |
| 123 | 123 | 'FHEE__ticket_selector_chart_template__ticket_details_event_date_number_datetimes', |
| 124 | - esc_html__( '# Datetimes:', 'event_espresso' ) |
|
| 124 | + esc_html__('# Datetimes:', 'event_espresso') |
|
| 125 | 125 | ); ?></span><?php echo $ticket->uses(); ?><br/> |
| 126 | 126 | </section> |
| 127 | 127 | <?php } ?> |
| 128 | 128 | |
| 129 | 129 | <?php |
| 130 | - $datetimes = $ticket->datetimes_ordered( $event_is_expired, false ); |
|
| 130 | + $datetimes = $ticket->datetimes_ordered($event_is_expired, false); |
|
| 131 | 131 | $chart_column_width = $show_ticket_sale_columns ? ' ee-fourth-width' : ' ee-half-width'; |
| 132 | - if ( ! empty( $datetimes ) ) { ?> |
|
| 132 | + if ( ! empty($datetimes)) { ?> |
|
| 133 | 133 | <section class="tckt-slctr-tkt-datetimes-sctn"> |
| 134 | 134 | <h5><?php echo apply_filters( |
| 135 | 135 | 'FHEE__ticket_selector_chart_template__ticket_details_event_access_heading', |
| 136 | - esc_html__( 'Access', 'event_espresso' ) |
|
| 136 | + esc_html__('Access', 'event_espresso') |
|
| 137 | 137 | ); ?></h5> |
| 138 | 138 | <span class="drk-grey-text small-text no-bold"> - <?php echo apply_filters( |
| 139 | 139 | 'FHEE__ticket_selector_chart_template__ticket_details_event_access_message', |
| 140 | - esc_html__( 'This option allows access to the following dates and times.', 'event_espresso' ) |
|
| 140 | + esc_html__('This option allows access to the following dates and times.', 'event_espresso') |
|
| 141 | 141 | ); ?></span> |
| 142 | 142 | <div class="tckt-slctr-tkt-details-tbl-wrap-dv"> |
| 143 | 143 | <table class="tckt-slctr-tkt-details-tbl"> |
@@ -147,38 +147,38 @@ discard block |
||
| 147 | 147 | <span class="dashicons dashicons-calendar"></span><span |
| 148 | 148 | class="small-text"><?php echo apply_filters( |
| 149 | 149 | 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_event_date', |
| 150 | - esc_html__( 'Date ', 'event_espresso' ) |
|
| 150 | + esc_html__('Date ', 'event_espresso') |
|
| 151 | 151 | ); ?></span> |
| 152 | 152 | </th> |
| 153 | 153 | <th class="tckt-slctr-tkt-details-time-th <?php echo $chart_column_width; ?>"> |
| 154 | 154 | <span class="dashicons dashicons-clock"></span><span |
| 155 | - class="small-text"><?php esc_html_e( 'Time ', 'event_espresso' ); ?></span> |
|
| 155 | + class="small-text"><?php esc_html_e('Time ', 'event_espresso'); ?></span> |
|
| 156 | 156 | </th> |
| 157 | - <?php if ( $show_ticket_sale_columns ) : ?> |
|
| 157 | + <?php if ($show_ticket_sale_columns) : ?> |
|
| 158 | 158 | <th class="tckt-slctr-tkt-details-this-ticket-sold-th ee-fourth-width cntr"> |
| 159 | 159 | <span class="smaller-text"><?php echo apply_filters( |
| 160 | 160 | 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_this_ticket_sold', |
| 161 | - sprintf( esc_html__( 'Sold', 'event_espresso' ), '<br/>' ) |
|
| 161 | + sprintf(esc_html__('Sold', 'event_espresso'), '<br/>') |
|
| 162 | 162 | ); ?></span> |
| 163 | 163 | </th> |
| 164 | 164 | <th class="tckt-slctr-tkt-details-this-ticket-left-th ee-fourth-width cntr"> |
| 165 | 165 | <span class="smaller-text"><?php echo apply_filters( |
| 166 | 166 | 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_this_ticket_left', |
| 167 | - sprintf( esc_html__( 'Remaining', 'event_espresso' ), '<br/>' ) |
|
| 167 | + sprintf(esc_html__('Remaining', 'event_espresso'), '<br/>') |
|
| 168 | 168 | ); ?></span> |
| 169 | 169 | </th> |
| 170 | 170 | <th |
| 171 | 171 | class="tckt-slctr-tkt-details-total-tickets-sold-th ee-fourth-width cntr"> |
| 172 | 172 | <span class="smaller-text"><?php echo apply_filters( |
| 173 | 173 | 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_total_ticket_sold', |
| 174 | - sprintf( esc_html__( 'Total%sSold', 'event_espresso' ), '<br/>' ) |
|
| 174 | + sprintf(esc_html__('Total%sSold', 'event_espresso'), '<br/>') |
|
| 175 | 175 | ); ?></span> |
| 176 | 176 | </th> |
| 177 | 177 | <th |
| 178 | 178 | class="tckt-slctr-tkt-details-total-tickets-left-th ee-fourth-width cntr"> |
| 179 | 179 | <span class="smaller-text"><?php echo apply_filters( |
| 180 | 180 | 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_total_ticket_left', |
| 181 | - sprintf( esc_html__( 'Total Spaces%sLeft', 'event_espresso' ), '<br/>' ) |
|
| 181 | + sprintf(esc_html__('Total Spaces%sLeft', 'event_espresso'), '<br/>') |
|
| 182 | 182 | ); ?></span> |
| 183 | 183 | </th> |
| 184 | 184 | <?php endif; //end $show_ticket_sale_columns conditional ?> |
@@ -186,62 +186,62 @@ discard block |
||
| 186 | 186 | </thead> |
| 187 | 187 | <tbody> |
| 188 | 188 | <?php |
| 189 | - foreach ( $datetimes as $datetime ) { |
|
| 190 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 189 | + foreach ($datetimes as $datetime) { |
|
| 190 | + if ($datetime instanceof EE_Datetime) { |
|
| 191 | 191 | ?> |
| 192 | 192 | |
| 193 | 193 | <tr> |
| 194 | 194 | <td data-th="<?php echo apply_filters( |
| 195 | 195 | 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_event_date', |
| 196 | - esc_html__( 'Event Date ', 'event_espresso' ) |
|
| 196 | + esc_html__('Event Date ', 'event_espresso') |
|
| 197 | 197 | ); ?>" class="small-text"> |
| 198 | 198 | <?php $datetime_name = $datetime->name(); ?> |
| 199 | - <?php echo ! empty( $datetime_name ) ? '<b>' |
|
| 199 | + <?php echo ! empty($datetime_name) ? '<b>' |
|
| 200 | 200 | . $datetime_name |
| 201 | 201 | . '</b><br/>' : ''; ?> |
| 202 | 202 | <?php echo $datetime->date_range( |
| 203 | 203 | $date_format, |
| 204 | - esc_html__( ' to ', 'event_espresso' ) |
|
| 204 | + esc_html__(' to ', 'event_espresso') |
|
| 205 | 205 | ); ?> |
| 206 | 206 | </td> |
| 207 | - <td data-th="<?php esc_html_e( 'Time ', 'event_espresso' ); ?>" |
|
| 207 | + <td data-th="<?php esc_html_e('Time ', 'event_espresso'); ?>" |
|
| 208 | 208 | class="cntr small-text"> |
| 209 | 209 | <?php echo $datetime->time_range( |
| 210 | 210 | $time_format, |
| 211 | - esc_html__( ' to ', 'event_espresso' ) |
|
| 211 | + esc_html__(' to ', 'event_espresso') |
|
| 212 | 212 | ); ?> |
| 213 | 213 | </td> |
| 214 | - <?php if ( $show_ticket_sale_columns ) : ?> |
|
| 214 | + <?php if ($show_ticket_sale_columns) : ?> |
|
| 215 | 215 | <td data-th="<?php echo apply_filters( |
| 216 | 216 | 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_this_ticket_sold', |
| 217 | - esc_html__( 'Sold', 'event_espresso' ) |
|
| 217 | + esc_html__('Sold', 'event_espresso') |
|
| 218 | 218 | ); ?>" class="cntr small-text"> |
| 219 | 219 | <?php echo $ticket->sold(); ?> |
| 220 | 220 | </td> |
| 221 | 221 | <td data-th="<?php echo apply_filters( |
| 222 | 222 | 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_this_ticket_left', |
| 223 | - esc_html__( 'Remaining', 'event_espresso' ) |
|
| 223 | + esc_html__('Remaining', 'event_espresso') |
|
| 224 | 224 | ); ?>" class="cntr small-text"> |
| 225 | 225 | <?php echo $remaining === EE_INF |
| 226 | - ? '<span class="smaller-text">' . esc_html__( |
|
| 226 | + ? '<span class="smaller-text">'.esc_html__( |
|
| 227 | 227 | 'unlimited ', |
| 228 | 228 | 'event_espresso' |
| 229 | - ) . '</span>' : $remaining; ?> |
|
| 229 | + ).'</span>' : $remaining; ?> |
|
| 230 | 230 | </td> |
| 231 | 231 | <td data-th="<?php echo apply_filters( |
| 232 | 232 | 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_total_ticket_sold', |
| 233 | - esc_html__( 'Total Sold', 'event_espresso' ) |
|
| 233 | + esc_html__('Total Sold', 'event_espresso') |
|
| 234 | 234 | ); ?>" class="cntr small-text"> |
| 235 | 235 | <?php echo $datetime->sold(); ?> |
| 236 | 236 | </td> |
| 237 | 237 | <?php $tkts_left = $datetime->sold_out() |
| 238 | - ? '<span class="sold-out smaller-text">' . esc_html__( |
|
| 238 | + ? '<span class="sold-out smaller-text">'.esc_html__( |
|
| 239 | 239 | 'Sold Out', |
| 240 | 240 | 'event_espresso' |
| 241 | - ) . '</span>' : $datetime->spaces_remaining(); ?> |
|
| 241 | + ).'</span>' : $datetime->spaces_remaining(); ?> |
|
| 242 | 242 | <td data-th="<?php echo apply_filters( |
| 243 | 243 | 'FHEE__ticket_selector_chart_template__ticket_details_event_access_table_total_ticket_left', |
| 244 | - esc_html__( 'Total Spaces Left', 'event_espresso' ) |
|
| 244 | + esc_html__('Total Spaces Left', 'event_espresso') |
|
| 245 | 245 | ); ?>" class="cntr small-text"> |
| 246 | 246 | <?php echo $tkts_left === EE_INF ? '<span class="smaller-text">' |
| 247 | 247 | . esc_html__( |
@@ -266,4 +266,4 @@ discard block |
||
| 266 | 266 | </div> |
| 267 | 267 | </td> |
| 268 | 268 | </tr> |
| 269 | -<?php endif; //end template_settings->show_ticket_details check?> |
|
| 270 | 269 | \ No newline at end of file |
| 270 | +<?php endif; //end template_settings->show_ticket_details check?> |
|
| 271 | 271 | \ No newline at end of file |
@@ -29,12 +29,12 @@ discard block |
||
| 29 | 29 | <tr> |
| 30 | 30 | <th id="details-<?php echo $EVT_ID; ?>" scope="col" class="ee-ticket-selector-ticket-details-th"> |
| 31 | 31 | <?php |
| 32 | - echo apply_filters( |
|
| 33 | - 'FHEE__ticket_selector_chart_template__table_header_available_tickets', |
|
| 34 | - esc_html__( 'Details', 'event_espresso' ), |
|
| 35 | - $EVT_ID |
|
| 36 | - ); |
|
| 37 | - ?> |
|
| 32 | + echo apply_filters( |
|
| 33 | + 'FHEE__ticket_selector_chart_template__table_header_available_tickets', |
|
| 34 | + esc_html__( 'Details', 'event_espresso' ), |
|
| 35 | + $EVT_ID |
|
| 36 | + ); |
|
| 37 | + ?> |
|
| 38 | 38 | </th> |
| 39 | 39 | <?php if ( apply_filters( 'FHEE__ticket_selector_chart_template__display_ticket_price_details', TRUE ) ) { ?> |
| 40 | 40 | <th id="price-<?php echo $EVT_ID; ?>" scope="col" class="ee-ticket-selector-ticket-price-th cntr"> |
@@ -48,28 +48,28 @@ discard block |
||
| 48 | 48 | * @param int $EVT_ID The Event ID |
| 49 | 49 | */ |
| 50 | 50 | echo apply_filters( |
| 51 | - 'FHEE__ticket_selector_chart_template__table_header_price', |
|
| 52 | - esc_html__( 'Price', 'event_espresso' ), |
|
| 53 | - $EVT_ID |
|
| 54 | - ); |
|
| 51 | + 'FHEE__ticket_selector_chart_template__table_header_price', |
|
| 52 | + esc_html__( 'Price', 'event_espresso' ), |
|
| 53 | + $EVT_ID |
|
| 54 | + ); |
|
| 55 | 55 | ?> |
| 56 | 56 | </th> |
| 57 | 57 | <?php } ?> |
| 58 | 58 | <th id="quantity-<?php echo $EVT_ID; ?>" scope="col" class="ee-ticket-selector-ticket-qty-th cntr"> |
| 59 | 59 | <?php |
| 60 | 60 | /** |
| 61 | - * Filters the text printed for the header of the quantity column in the ticket selector table |
|
| 62 | - * |
|
| 63 | - * @since 4.7.2 |
|
| 64 | - * |
|
| 65 | - * @param string 'Qty' The translatable text to display in the table header for the Quantity of tickets |
|
| 66 | - * @param int $EVT_ID The Event ID |
|
| 67 | - */ |
|
| 61 | + * Filters the text printed for the header of the quantity column in the ticket selector table |
|
| 62 | + * |
|
| 63 | + * @since 4.7.2 |
|
| 64 | + * |
|
| 65 | + * @param string 'Qty' The translatable text to display in the table header for the Quantity of tickets |
|
| 66 | + * @param int $EVT_ID The Event ID |
|
| 67 | + */ |
|
| 68 | 68 | echo apply_filters( |
| 69 | - 'FHEE__ticket_selector_chart_template__table_header_qty', |
|
| 70 | - esc_html__( 'Qty', 'event_espresso' ), |
|
| 71 | - $EVT_ID |
|
| 72 | - ); |
|
| 69 | + 'FHEE__ticket_selector_chart_template__table_header_qty', |
|
| 70 | + esc_html__( 'Qty', 'event_espresso' ), |
|
| 71 | + $EVT_ID |
|
| 72 | + ); |
|
| 73 | 73 | ?> |
| 74 | 74 | </th> |
| 75 | 75 | </tr> |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | if ( $max_atndz > 0 ) { |
| 97 | 97 | echo apply_filters( |
| 98 | 98 | 'FHEE__ticket_selector_chart_template__maximum_tickets_purchased_footnote', |
| 99 | - esc_html('') |
|
| 99 | + esc_html('') |
|
| 100 | 100 | ); |
| 101 | 101 | } |
| 102 | 102 | if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | ?> |
| 22 | 22 | <div id="tkt-slctr-tbl-wrap-dv-<?php echo $EVT_ID; ?>" class="tkt-slctr-tbl-wrap-dv"> |
| 23 | 23 | |
| 24 | - <?php do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event ); ?> |
|
| 24 | + <?php do_action('AHEE__ticket_selector_chart__template__before_ticket_selector', $event); ?> |
|
| 25 | 25 | <?php echo $datetime_selector; ?> |
| 26 | 26 | |
| 27 | 27 | <table id="tkt-slctr-tbl-<?php echo $EVT_ID; ?>" class="tkt-slctr-tbl"> |
@@ -31,12 +31,12 @@ discard block |
||
| 31 | 31 | <?php |
| 32 | 32 | echo apply_filters( |
| 33 | 33 | 'FHEE__ticket_selector_chart_template__table_header_available_tickets', |
| 34 | - esc_html__( 'Details', 'event_espresso' ), |
|
| 34 | + esc_html__('Details', 'event_espresso'), |
|
| 35 | 35 | $EVT_ID |
| 36 | 36 | ); |
| 37 | 37 | ?> |
| 38 | 38 | </th> |
| 39 | - <?php if ( apply_filters( 'FHEE__ticket_selector_chart_template__display_ticket_price_details', TRUE ) ) { ?> |
|
| 39 | + <?php if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', TRUE)) { ?> |
|
| 40 | 40 | <th id="price-<?php echo $EVT_ID; ?>" scope="col" class="ee-ticket-selector-ticket-price-th cntr"> |
| 41 | 41 | <?php |
| 42 | 42 | /** |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | echo apply_filters( |
| 51 | 51 | 'FHEE__ticket_selector_chart_template__table_header_price', |
| 52 | - esc_html__( 'Price', 'event_espresso' ), |
|
| 52 | + esc_html__('Price', 'event_espresso'), |
|
| 53 | 53 | $EVT_ID |
| 54 | 54 | ); |
| 55 | 55 | ?> |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | echo apply_filters( |
| 69 | 69 | 'FHEE__ticket_selector_chart_template__table_header_qty', |
| 70 | - esc_html__( 'Qty', 'event_espresso' ), |
|
| 70 | + esc_html__('Qty', 'event_espresso'), |
|
| 71 | 71 | $EVT_ID |
| 72 | 72 | ); |
| 73 | 73 | ?> |
@@ -75,17 +75,17 @@ discard block |
||
| 75 | 75 | </tr> |
| 76 | 76 | </thead> |
| 77 | 77 | <tbody> |
| 78 | - <?php echo $ticket_row_html;?> |
|
| 78 | + <?php echo $ticket_row_html; ?> |
|
| 79 | 79 | </tbody> |
| 80 | 80 | </table> |
| 81 | 81 | <?php |
| 82 | - if ( $taxable_tickets && apply_filters( 'FHEE__ticket_selector_chart_template__display_ticket_price_details', true ) ) { |
|
| 83 | - if ( $prices_displayed_including_taxes ) { |
|
| 84 | - $ticket_price_includes_taxes = esc_html__( '* price includes taxes', 'event_espresso' ); |
|
| 82 | + if ($taxable_tickets && apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
| 83 | + if ($prices_displayed_including_taxes) { |
|
| 84 | + $ticket_price_includes_taxes = esc_html__('* price includes taxes', 'event_espresso'); |
|
| 85 | 85 | } else { |
| 86 | - $ticket_price_includes_taxes = esc_html__( '* price does not include taxes', 'event_espresso' ); |
|
| 86 | + $ticket_price_includes_taxes = esc_html__('* price does not include taxes', 'event_espresso'); |
|
| 87 | 87 | } |
| 88 | - echo '<p class="small-text lt-grey-text" style="text-align:right; margin: -1em 0 1em;">' . $ticket_price_includes_taxes . '</p>'; |
|
| 88 | + echo '<p class="small-text lt-grey-text" style="text-align:right; margin: -1em 0 1em;">'.$ticket_price_includes_taxes.'</p>'; |
|
| 89 | 89 | } |
| 90 | 90 | ?> |
| 91 | 91 | |
@@ -93,13 +93,13 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | |
| 95 | 95 | <?php |
| 96 | -if ( $max_atndz > 0 ) { |
|
| 96 | +if ($max_atndz > 0) { |
|
| 97 | 97 | echo apply_filters( |
| 98 | 98 | 'FHEE__ticket_selector_chart_template__maximum_tickets_purchased_footnote', |
| 99 | 99 | esc_html('') |
| 100 | 100 | ); |
| 101 | 101 | } |
| 102 | -if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
| 103 | - add_filter( 'FHEE__EE_Ticket_Selector__no_ticket_selector_submit', '__return_true' ); |
|
| 102 | +if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
| 103 | + add_filter('FHEE__EE_Ticket_Selector__no_ticket_selector_submit', '__return_true'); |
|
| 104 | 104 | } |
| 105 | -do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event ); |
|
| 106 | 105 | \ No newline at end of file |
| 106 | +do_action('AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event); |
|
| 107 | 107 | \ No newline at end of file |
@@ -20,55 +20,55 @@ |
||
| 20 | 20 | class AssetRegisterCollection extends Collection implements AssetRegisterInterface |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Collection constructor |
|
| 25 | - * |
|
| 26 | - * @throws InvalidInterfaceException |
|
| 27 | - */ |
|
| 28 | - public function __construct() |
|
| 29 | - { |
|
| 30 | - parent::__construct('EventEspresso\core\services\assets\AssetRegisterInterface'); |
|
| 31 | - } |
|
| 23 | + /** |
|
| 24 | + * Collection constructor |
|
| 25 | + * |
|
| 26 | + * @throws InvalidInterfaceException |
|
| 27 | + */ |
|
| 28 | + public function __construct() |
|
| 29 | + { |
|
| 30 | + parent::__construct('EventEspresso\core\services\assets\AssetRegisterInterface'); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @return void |
|
| 36 | - */ |
|
| 37 | - public function registerManifestFile() |
|
| 38 | - { |
|
| 39 | - $this->rewind(); |
|
| 40 | - while ($this->valid()) { |
|
| 41 | - $this->current()->registerManifestFile(); |
|
| 42 | - $this->next(); |
|
| 43 | - } |
|
| 44 | - $this->rewind(); |
|
| 45 | - } |
|
| 34 | + /** |
|
| 35 | + * @return void |
|
| 36 | + */ |
|
| 37 | + public function registerManifestFile() |
|
| 38 | + { |
|
| 39 | + $this->rewind(); |
|
| 40 | + while ($this->valid()) { |
|
| 41 | + $this->current()->registerManifestFile(); |
|
| 42 | + $this->next(); |
|
| 43 | + } |
|
| 44 | + $this->rewind(); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @return void |
|
| 50 | - */ |
|
| 51 | - public function registerScripts() |
|
| 52 | - { |
|
| 53 | - $this->rewind(); |
|
| 54 | - while ($this->valid()) { |
|
| 55 | - $this->current()->registerScripts(); |
|
| 56 | - $this->next(); |
|
| 57 | - } |
|
| 58 | - $this->rewind(); |
|
| 59 | - } |
|
| 48 | + /** |
|
| 49 | + * @return void |
|
| 50 | + */ |
|
| 51 | + public function registerScripts() |
|
| 52 | + { |
|
| 53 | + $this->rewind(); |
|
| 54 | + while ($this->valid()) { |
|
| 55 | + $this->current()->registerScripts(); |
|
| 56 | + $this->next(); |
|
| 57 | + } |
|
| 58 | + $this->rewind(); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @return void |
|
| 64 | - */ |
|
| 65 | - public function registerStyles() |
|
| 66 | - { |
|
| 67 | - $this->rewind(); |
|
| 68 | - while ($this->valid()) { |
|
| 69 | - $this->current()->registerStyles(); |
|
| 70 | - $this->next(); |
|
| 71 | - } |
|
| 72 | - $this->rewind(); |
|
| 73 | - } |
|
| 62 | + /** |
|
| 63 | + * @return void |
|
| 64 | + */ |
|
| 65 | + public function registerStyles() |
|
| 66 | + { |
|
| 67 | + $this->rewind(); |
|
| 68 | + while ($this->valid()) { |
|
| 69 | + $this->current()->registerStyles(); |
|
| 70 | + $this->next(); |
|
| 71 | + } |
|
| 72 | + $this->rewind(); |
|
| 73 | + } |
|
| 74 | 74 | } |
| 75 | 75 | \ No newline at end of file |
@@ -17,20 +17,20 @@ |
||
| 17 | 17 | interface AssetRegisterInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @return void |
|
| 22 | - */ |
|
| 23 | - public function registerManifestFile(); |
|
| 20 | + /** |
|
| 21 | + * @return void |
|
| 22 | + */ |
|
| 23 | + public function registerManifestFile(); |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @return void |
|
| 28 | - */ |
|
| 29 | - public function registerScripts(); |
|
| 26 | + /** |
|
| 27 | + * @return void |
|
| 28 | + */ |
|
| 29 | + public function registerScripts(); |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @return void |
|
| 34 | - */ |
|
| 35 | - public function registerStyles(); |
|
| 32 | + /** |
|
| 33 | + * @return void |
|
| 34 | + */ |
|
| 35 | + public function registerStyles(); |
|
| 36 | 36 | } |
| 37 | 37 | \ No newline at end of file |