@@ -66,8 +66,8 @@ |
||
66 | 66 | { |
67 | 67 | |
68 | 68 | $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
69 | - $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
70 | - $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
69 | + $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path.'invoice_body.template.php', null, false, false, true); |
|
70 | + $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path.'receipt_body.template.php', null, false, false, true); |
|
71 | 71 | if ($overridden_invoice_body || $overridden_receipt_body) { |
72 | 72 | new PersistentAdminNotice( |
73 | 73 | 'invoice_overriding_templates', |
@@ -27,59 +27,59 @@ |
||
27 | 27 | */ |
28 | 28 | class EE_DMS_4_6_0_invoice_settings extends EE_Data_Migration_Script_Stage |
29 | 29 | { |
30 | - /** |
|
31 | - * Just initializes the status of the migration |
|
32 | - */ |
|
33 | - public function __construct() |
|
34 | - { |
|
35 | - $this->_pretty_name = esc_html__('Update Invoice Settings', 'event_espresso'); |
|
36 | - parent::__construct(); |
|
37 | - } |
|
30 | + /** |
|
31 | + * Just initializes the status of the migration |
|
32 | + */ |
|
33 | + public function __construct() |
|
34 | + { |
|
35 | + $this->_pretty_name = esc_html__('Update Invoice Settings', 'event_espresso'); |
|
36 | + parent::__construct(); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * _count_records_to_migrate |
|
43 | - * Counts the records to migrate; the public version may cache it |
|
44 | - * |
|
45 | - * @access protected |
|
46 | - * @return int |
|
47 | - */ |
|
48 | - protected function _count_records_to_migrate() |
|
49 | - { |
|
50 | - return 1; |
|
51 | - } |
|
41 | + /** |
|
42 | + * _count_records_to_migrate |
|
43 | + * Counts the records to migrate; the public version may cache it |
|
44 | + * |
|
45 | + * @access protected |
|
46 | + * @return int |
|
47 | + */ |
|
48 | + protected function _count_records_to_migrate() |
|
49 | + { |
|
50 | + return 1; |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * _migration_step |
|
57 | - * |
|
58 | - * @access protected |
|
59 | - * @param int $num_items |
|
60 | - * @throws EE_Error |
|
61 | - * @return int number of items ACTUALLY migrated |
|
62 | - * @throws InvalidDataTypeException |
|
63 | - */ |
|
64 | - protected function _migration_step($num_items = 1) |
|
65 | - { |
|
55 | + /** |
|
56 | + * _migration_step |
|
57 | + * |
|
58 | + * @access protected |
|
59 | + * @param int $num_items |
|
60 | + * @throws EE_Error |
|
61 | + * @return int number of items ACTUALLY migrated |
|
62 | + * @throws InvalidDataTypeException |
|
63 | + */ |
|
64 | + protected function _migration_step($num_items = 1) |
|
65 | + { |
|
66 | 66 | |
67 | - $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
68 | - $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
69 | - $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
70 | - if ($overridden_invoice_body || $overridden_receipt_body) { |
|
71 | - new PersistentAdminNotice( |
|
72 | - 'invoice_overriding_templates', |
|
73 | - esc_html__( |
|
74 | - 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents (but this will be removed in an upcoming version). We recommend deleting your old Invoice/Receipt templates and using the new messages system. Then modify the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
75 | - 'event_espresso' |
|
76 | - ), |
|
77 | - true |
|
78 | - ); |
|
79 | - } |
|
67 | + $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
68 | + $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
69 | + $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
70 | + if ($overridden_invoice_body || $overridden_receipt_body) { |
|
71 | + new PersistentAdminNotice( |
|
72 | + 'invoice_overriding_templates', |
|
73 | + esc_html__( |
|
74 | + 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents (but this will be removed in an upcoming version). We recommend deleting your old Invoice/Receipt templates and using the new messages system. Then modify the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
75 | + 'event_espresso' |
|
76 | + ), |
|
77 | + true |
|
78 | + ); |
|
79 | + } |
|
80 | 80 | |
81 | - // regardless of whether it worked or not, we ought to continue the migration |
|
82 | - $this->set_completed(); |
|
83 | - return 1; |
|
84 | - } |
|
81 | + // regardless of whether it worked or not, we ought to continue the migration |
|
82 | + $this->set_completed(); |
|
83 | + return 1; |
|
84 | + } |
|
85 | 85 | } |
@@ -36,19 +36,19 @@ discard block |
||
36 | 36 | { |
37 | 37 | EE_Load_Textdomain::loadTranslationsForLocale(); |
38 | 38 | // now load the textdomain |
39 | - if (!empty(EE_Load_Textdomain::$locale)) { |
|
40 | - $github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo'; |
|
39 | + if ( ! empty(EE_Load_Textdomain::$locale)) { |
|
40 | + $github_mo_path = EE_LANGUAGES_SAFE_DIR.'event_espresso-'.EE_Load_Textdomain::$locale.'.mo'; |
|
41 | 41 | if (is_readable($github_mo_path)) { |
42 | 42 | load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC); |
43 | 43 | return; |
44 | 44 | } |
45 | - $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event-espresso-4-' . EE_Load_Textdomain::$locale . '.mo'; |
|
45 | + $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR.'event-espresso-4-'.EE_Load_Textdomain::$locale.'.mo'; |
|
46 | 46 | if (is_readable($glotpress_mo_path)) { |
47 | 47 | load_textdomain('event_espresso', $glotpress_mo_path); |
48 | 48 | return; |
49 | 49 | } |
50 | 50 | } |
51 | - load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/'); |
|
51 | + load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME).'/languages/'); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | if (empty(EE_Load_Textdomain::$locale)) { |
72 | 72 | return; |
73 | 73 | } |
74 | - $language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION; |
|
74 | + $language_check_option_name = 'ee_lang_check_'.EE_Load_Textdomain::$locale.'_'.EVENT_ESPRESSO_VERSION; |
|
75 | 75 | // check if language files has already been sideloaded |
76 | 76 | if (get_option($language_check_option_name)) { |
77 | 77 | return; |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | |
82 | 82 | // load sideloader and sideload the .POT file as this should always be included. |
83 | 83 | $sideloader_args = array( |
84 | - '_upload_to' => EE_PLUGIN_DIR_PATH . 'languages/', |
|
85 | - '_download_from' => $repo_base_URL . '.pot?raw=true', |
|
84 | + '_upload_to' => EE_PLUGIN_DIR_PATH.'languages/', |
|
85 | + '_download_from' => $repo_base_URL.'.pot?raw=true', |
|
86 | 86 | '_new_file_name' => 'event_espresso.pot', |
87 | 87 | ); |
88 | 88 | /** @var EEH_Sideloader $sideloader */ |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | update_option($language_check_option_name, 1); |
99 | 99 | return; |
100 | 100 | } |
101 | - $repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale; |
|
102 | - $file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale; |
|
101 | + $repo_locale_URL = $repo_base_URL.'-'.EE_Load_Textdomain::$locale; |
|
102 | + $file_name_base = 'event_espresso-'.EE_Load_Textdomain::$locale; |
|
103 | 103 | |
104 | 104 | // made it here so let's get the language files from the github repo, first the .mo file |
105 | 105 | $sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true"); |
@@ -12,105 +12,105 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Load_Textdomain extends EE_Base |
14 | 14 | { |
15 | - /** |
|
16 | - * holds the current lang in WP |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - private static $locale; |
|
15 | + /** |
|
16 | + * holds the current lang in WP |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + private static $locale; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * this takes care of retrieving a matching textdomain for event espresso for the current WPLANG from EE GitHub |
|
25 | - * repo (if necessary) and then loading it for translations. should only be called in wp plugins_loaded callback |
|
26 | - * |
|
27 | - * @return void |
|
28 | - * @throws EE_Error |
|
29 | - * @throws InvalidArgumentException |
|
30 | - * @throws ReflectionException |
|
31 | - * @throws InvalidDataTypeException |
|
32 | - * @throws InvalidInterfaceException |
|
33 | - */ |
|
34 | - public static function load_textdomain() |
|
35 | - { |
|
36 | - EE_Load_Textdomain::loadTranslationsForLocale(); |
|
37 | - // now load the textdomain |
|
38 | - if (!empty(EE_Load_Textdomain::$locale)) { |
|
39 | - $github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo'; |
|
40 | - if (is_readable($github_mo_path)) { |
|
41 | - load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC); |
|
42 | - return; |
|
43 | - } |
|
44 | - $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event-espresso-4-' . EE_Load_Textdomain::$locale . '.mo'; |
|
45 | - if (is_readable($glotpress_mo_path)) { |
|
46 | - load_textdomain('event_espresso', $glotpress_mo_path); |
|
47 | - return; |
|
48 | - } |
|
49 | - } |
|
50 | - load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/'); |
|
51 | - } |
|
23 | + /** |
|
24 | + * this takes care of retrieving a matching textdomain for event espresso for the current WPLANG from EE GitHub |
|
25 | + * repo (if necessary) and then loading it for translations. should only be called in wp plugins_loaded callback |
|
26 | + * |
|
27 | + * @return void |
|
28 | + * @throws EE_Error |
|
29 | + * @throws InvalidArgumentException |
|
30 | + * @throws ReflectionException |
|
31 | + * @throws InvalidDataTypeException |
|
32 | + * @throws InvalidInterfaceException |
|
33 | + */ |
|
34 | + public static function load_textdomain() |
|
35 | + { |
|
36 | + EE_Load_Textdomain::loadTranslationsForLocale(); |
|
37 | + // now load the textdomain |
|
38 | + if (!empty(EE_Load_Textdomain::$locale)) { |
|
39 | + $github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo'; |
|
40 | + if (is_readable($github_mo_path)) { |
|
41 | + load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC); |
|
42 | + return; |
|
43 | + } |
|
44 | + $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event-espresso-4-' . EE_Load_Textdomain::$locale . '.mo'; |
|
45 | + if (is_readable($glotpress_mo_path)) { |
|
46 | + load_textdomain('event_espresso', $glotpress_mo_path); |
|
47 | + return; |
|
48 | + } |
|
49 | + } |
|
50 | + load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/'); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * The purpose of this method is to sideload all of the lang files for EE, this includes the POT file and also the PO/MO files for the given WPLANG locale (if necessary). |
|
56 | - * |
|
57 | - * @access private |
|
58 | - * @static |
|
59 | - * @return void |
|
60 | - * @throws EE_Error |
|
61 | - * @throws InvalidArgumentException |
|
62 | - * @throws ReflectionException |
|
63 | - * @throws InvalidDataTypeException |
|
64 | - * @throws InvalidInterfaceException |
|
65 | - */ |
|
66 | - private static function loadTranslationsForLocale() |
|
67 | - { |
|
68 | - EE_Load_Textdomain::$locale = get_locale(); |
|
69 | - // can't download a language file if a language isn't set <taps temple> |
|
70 | - if (empty(EE_Load_Textdomain::$locale)) { |
|
71 | - return; |
|
72 | - } |
|
73 | - $language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION; |
|
74 | - // check if language files has already been sideloaded |
|
75 | - if (get_option($language_check_option_name)) { |
|
76 | - return; |
|
77 | - } |
|
54 | + /** |
|
55 | + * The purpose of this method is to sideload all of the lang files for EE, this includes the POT file and also the PO/MO files for the given WPLANG locale (if necessary). |
|
56 | + * |
|
57 | + * @access private |
|
58 | + * @static |
|
59 | + * @return void |
|
60 | + * @throws EE_Error |
|
61 | + * @throws InvalidArgumentException |
|
62 | + * @throws ReflectionException |
|
63 | + * @throws InvalidDataTypeException |
|
64 | + * @throws InvalidInterfaceException |
|
65 | + */ |
|
66 | + private static function loadTranslationsForLocale() |
|
67 | + { |
|
68 | + EE_Load_Textdomain::$locale = get_locale(); |
|
69 | + // can't download a language file if a language isn't set <taps temple> |
|
70 | + if (empty(EE_Load_Textdomain::$locale)) { |
|
71 | + return; |
|
72 | + } |
|
73 | + $language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION; |
|
74 | + // check if language files has already been sideloaded |
|
75 | + if (get_option($language_check_option_name)) { |
|
76 | + return; |
|
77 | + } |
|
78 | 78 | |
79 | - $repo_base_URL = 'https://github.com/eventespresso/languages-ee4/blob/master/event_espresso'; |
|
79 | + $repo_base_URL = 'https://github.com/eventespresso/languages-ee4/blob/master/event_espresso'; |
|
80 | 80 | |
81 | - // load sideloader and sideload the .POT file as this should always be included. |
|
82 | - $sideloader_args = array( |
|
83 | - '_upload_to' => EE_PLUGIN_DIR_PATH . 'languages/', |
|
84 | - '_download_from' => $repo_base_URL . '.pot?raw=true', |
|
85 | - '_new_file_name' => 'event_espresso.pot', |
|
86 | - ); |
|
87 | - /** @var EEH_Sideloader $sideloader */ |
|
88 | - $sideloader = EE_Registry::instance()->load_helper('Sideloader', $sideloader_args, false); |
|
89 | - // sideload the .POT file only for main site of the network, or if not running Multisite. |
|
90 | - if (is_main_site()) { |
|
91 | - $sideloader->sideload(); |
|
92 | - } |
|
81 | + // load sideloader and sideload the .POT file as this should always be included. |
|
82 | + $sideloader_args = array( |
|
83 | + '_upload_to' => EE_PLUGIN_DIR_PATH . 'languages/', |
|
84 | + '_download_from' => $repo_base_URL . '.pot?raw=true', |
|
85 | + '_new_file_name' => 'event_espresso.pot', |
|
86 | + ); |
|
87 | + /** @var EEH_Sideloader $sideloader */ |
|
88 | + $sideloader = EE_Registry::instance()->load_helper('Sideloader', $sideloader_args, false); |
|
89 | + // sideload the .POT file only for main site of the network, or if not running Multisite. |
|
90 | + if (is_main_site()) { |
|
91 | + $sideloader->sideload(); |
|
92 | + } |
|
93 | 93 | |
94 | - // if locale is "en_US" then lets just get out, since Event Espresso core is already "en_US" |
|
95 | - if (EE_Load_Textdomain::$locale === 'en_US') { |
|
96 | - // but set option first else we'll forever be downloading the pot file |
|
97 | - update_option($language_check_option_name, 1); |
|
98 | - return; |
|
99 | - } |
|
100 | - $repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale; |
|
101 | - $file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale; |
|
94 | + // if locale is "en_US" then lets just get out, since Event Espresso core is already "en_US" |
|
95 | + if (EE_Load_Textdomain::$locale === 'en_US') { |
|
96 | + // but set option first else we'll forever be downloading the pot file |
|
97 | + update_option($language_check_option_name, 1); |
|
98 | + return; |
|
99 | + } |
|
100 | + $repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale; |
|
101 | + $file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale; |
|
102 | 102 | |
103 | - // made it here so let's get the language files from the github repo, first the .mo file |
|
104 | - $sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true"); |
|
105 | - $sideloader->set_new_file_name("{$file_name_base}.mo"); |
|
106 | - $sideloader->sideload(); |
|
103 | + // made it here so let's get the language files from the github repo, first the .mo file |
|
104 | + $sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true"); |
|
105 | + $sideloader->set_new_file_name("{$file_name_base}.mo"); |
|
106 | + $sideloader->sideload(); |
|
107 | 107 | |
108 | - // now the .po file: |
|
109 | - $sideloader->set_download_from("{$repo_locale_URL}.po?raw=true"); |
|
110 | - $sideloader->set_new_file_name("{$file_name_base}.po"); |
|
111 | - $sideloader->sideload(); |
|
108 | + // now the .po file: |
|
109 | + $sideloader->set_download_from("{$repo_locale_URL}.po?raw=true"); |
|
110 | + $sideloader->set_new_file_name("{$file_name_base}.po"); |
|
111 | + $sideloader->sideload(); |
|
112 | 112 | |
113 | - // set option so the above only runs when EE updates. |
|
114 | - update_option($language_check_option_name, 1); |
|
115 | - } |
|
113 | + // set option so the above only runs when EE updates. |
|
114 | + update_option($language_check_option_name, 1); |
|
115 | + } |
|
116 | 116 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $class = parent::_get_row_class($item); |
115 | 115 | // add status class |
116 | 116 | $class .= $item instanceof EE_Event |
117 | - ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
117 | + ? ' ee-status-strip event-status-'.$item->get_active_status() |
|
118 | 118 | : ''; |
119 | 119 | if ($this->_has_checkbox_column) { |
120 | 120 | $class .= ' has-checkbox-column'; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function column_cb($item) |
145 | 145 | { |
146 | - if (! $item instanceof EE_Event) { |
|
146 | + if ( ! $item instanceof EE_Event) { |
|
147 | 147 | return ''; |
148 | 148 | } |
149 | 149 | $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | public function column_id(EE_Event $item) |
167 | 167 | { |
168 | 168 | $content = $item->ID(); |
169 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
169 | + $content .= ' <span class="show-on-mobile-view-only">'.$item->name().'</span>'; |
|
170 | 170 | return $content; |
171 | 171 | } |
172 | 172 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $actions = $this->_column_name_action_setup($item); |
190 | 190 | $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
191 | 191 | $content = '<strong><a class="row-title" href="' |
192 | - . $edit_link . '">' |
|
192 | + . $edit_link.'">' |
|
193 | 193 | . $item->name() |
194 | 194 | . '</a></strong>' |
195 | 195 | . $status; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | protected function _column_name_action_setup(EE_Event $item) |
219 | 219 | { |
220 | 220 | // todo: remove when attendees is active |
221 | - if (! defined('REG_ADMIN_URL')) { |
|
221 | + if ( ! defined('REG_ADMIN_URL')) { |
|
222 | 222 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
223 | 223 | } |
224 | 224 | $actions = array(); |
@@ -237,8 +237,8 @@ discard block |
||
237 | 237 | 'post' => $item->ID(), |
238 | 238 | ); |
239 | 239 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
240 | - $actions['edit'] = '<a href="' . $edit_link . '"' |
|
241 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
240 | + $actions['edit'] = '<a href="'.$edit_link.'"' |
|
241 | + . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
242 | 242 | . esc_html__('Edit', 'event_espresso') |
243 | 243 | . '</a>'; |
244 | 244 | } |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | 'event_id' => $item->ID(), |
259 | 259 | ); |
260 | 260 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
261 | - $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
262 | - . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
261 | + $actions['attendees'] = '<a href="'.$attendees_link.'"' |
|
262 | + . ' title="'.esc_attr__('View Registrations', 'event_espresso').'">' |
|
263 | 263 | . esc_html__('Registrations', 'event_espresso') |
264 | 264 | . '</a>'; |
265 | 265 | } |
@@ -312,8 +312,8 @@ discard block |
||
312 | 312 | ); |
313 | 313 | } |
314 | 314 | $view_link = get_permalink($item->ID()); |
315 | - $actions['view'] = '<a href="' . $view_link . '"' |
|
316 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
315 | + $actions['view'] = '<a href="'.$view_link.'"' |
|
316 | + . ' title="'.esc_attr__('View Event', 'event_espresso').'">' |
|
317 | 317 | . esc_html__('View', 'event_espresso') |
318 | 318 | . '</a>'; |
319 | 319 | if ($item->get('status') === 'trash') { |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | $item->ID() |
325 | 325 | ) |
326 | 326 | ) { |
327 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
328 | - . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
327 | + $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'"' |
|
328 | + . ' title="'.esc_attr__('Restore from Trash', 'event_espresso') |
|
329 | 329 | . '">' |
330 | 330 | . esc_html__('Restore from Trash', 'event_espresso') |
331 | 331 | . '</a>'; |
@@ -338,8 +338,8 @@ discard block |
||
338 | 338 | $item->ID() |
339 | 339 | ) |
340 | 340 | ) { |
341 | - $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
342 | - . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
341 | + $actions['delete'] = '<a href="'.$delete_event_link.'"' |
|
342 | + . ' title="'.esc_attr__('Delete Permanently', 'event_espresso').'">' |
|
343 | 343 | . esc_html__('Delete Permanently', 'event_espresso') |
344 | 344 | . '</a>'; |
345 | 345 | } |
@@ -351,8 +351,8 @@ discard block |
||
351 | 351 | $item->ID() |
352 | 352 | ) |
353 | 353 | ) { |
354 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
355 | - . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
354 | + $actions['move to trash'] = '<a href="'.$trash_event_link.'"' |
|
355 | + . ' title="'.esc_attr__('Trash Event', 'event_espresso').'">' |
|
356 | 356 | . esc_html__('Trash', 'event_espresso') |
357 | 357 | . '</a>'; |
358 | 358 | } |
@@ -377,8 +377,8 @@ discard block |
||
377 | 377 | 'EVT_wp_user' => $item->wp_user(), |
378 | 378 | ); |
379 | 379 | $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
380 | - return $gravatar . ' <a href="' . $filter_url . '"' |
|
381 | - . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
380 | + return $gravatar.' <a href="'.$filter_url.'"' |
|
381 | + . ' title="'.esc_attr__('Click to filter events by this author.', 'event_espresso').'">' |
|
382 | 382 | . $event_author->display_name |
383 | 383 | . '</a>'; |
384 | 384 | } |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | return implode( |
396 | 396 | ', ', |
397 | 397 | array_map( |
398 | - function (EE_Term $category) { |
|
398 | + function(EE_Term $category) { |
|
399 | 399 | return $category->name(); |
400 | 400 | }, |
401 | 401 | $event_categories |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | 'ee_read_registrations', |
471 | 471 | 'espresso_registrations_view_registration' |
472 | 472 | ) |
473 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
473 | + ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>' |
|
474 | 474 | : $registered_attendees; |
475 | 475 | } |
476 | 476 | |
@@ -500,13 +500,13 @@ discard block |
||
500 | 500 | public function column_actions(EE_Event $item) |
501 | 501 | { |
502 | 502 | // todo: remove when attendees is active |
503 | - if (! defined('REG_ADMIN_URL')) { |
|
503 | + if ( ! defined('REG_ADMIN_URL')) { |
|
504 | 504 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
505 | 505 | } |
506 | 506 | $action_links = array(); |
507 | 507 | $view_link = get_permalink($item->ID()); |
508 | - $action_links[] = '<a href="' . $view_link . '"' |
|
509 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
508 | + $action_links[] = '<a href="'.$view_link.'"' |
|
509 | + . ' title="'.esc_attr__('View Event', 'event_espresso').'" target="_blank">'; |
|
510 | 510 | $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
511 | 511 | if ( |
512 | 512 | EE_Registry::instance()->CAP->current_user_can( |
@@ -520,8 +520,8 @@ discard block |
||
520 | 520 | 'post' => $item->ID(), |
521 | 521 | ); |
522 | 522 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
523 | - $action_links[] = '<a href="' . $edit_link . '"' |
|
524 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
523 | + $action_links[] = '<a href="'.$edit_link.'"' |
|
524 | + . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
525 | 525 | . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
526 | 526 | . '</a>'; |
527 | 527 | } |
@@ -540,8 +540,8 @@ discard block |
||
540 | 540 | 'event_id' => $item->ID(), |
541 | 541 | ); |
542 | 542 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
543 | - $action_links[] = '<a href="' . $attendees_link . '"' |
|
544 | - . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
543 | + $action_links[] = '<a href="'.$attendees_link.'"' |
|
544 | + . ' title="'.esc_attr__('View Registrants', 'event_espresso').'">' |
|
545 | 545 | . '<div class="dashicons dashicons-groups"></div>' |
546 | 546 | . '</a>'; |
547 | 547 | } |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | } |
577 | 577 | $column_array = []; |
578 | 578 | foreach ($this->_columns as $column => $column_label) { |
579 | - $column_array[ $column ] = $column_label; |
|
579 | + $column_array[$column] = $column_label; |
|
580 | 580 | if ($column === 'venue') { |
581 | 581 | $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
582 | 582 | } |
@@ -14,567 +14,567 @@ |
||
14 | 14 | */ |
15 | 15 | class Events_Admin_List_Table extends EE_Admin_List_Table |
16 | 16 | { |
17 | - /** |
|
18 | - * @var EE_Datetime |
|
19 | - */ |
|
20 | - private $_dtt; |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * Initial setup of data properties for the list table. |
|
25 | - */ |
|
26 | - protected function _setup_data() |
|
27 | - { |
|
28 | - $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
29 | - $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
30 | - } |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * Set up of additional properties for the list table. |
|
35 | - */ |
|
36 | - protected function _set_properties() |
|
37 | - { |
|
38 | - $this->_wp_list_args = array( |
|
39 | - 'singular' => esc_html__('event', 'event_espresso'), |
|
40 | - 'plural' => esc_html__('events', 'event_espresso'), |
|
41 | - 'ajax' => true, // for now |
|
42 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
43 | - ); |
|
44 | - $this->_columns = array( |
|
45 | - 'cb' => '<input type="checkbox" />', |
|
46 | - 'id' => esc_html__('ID', 'event_espresso'), |
|
47 | - 'name' => esc_html__('Name', 'event_espresso'), |
|
48 | - 'author' => esc_html__('Author', 'event_espresso'), |
|
49 | - 'venue' => esc_html__('Venue', 'event_espresso'), |
|
50 | - 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
51 | - 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
52 | - 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
53 | - . '<span class="screen-reader-text">' |
|
54 | - . esc_html__('Approved Registrations', 'event_espresso') |
|
55 | - . '</span>' |
|
56 | - . '</span>', |
|
57 | - // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), |
|
58 | - 'actions' => esc_html__('Actions', 'event_espresso'), |
|
59 | - ); |
|
60 | - $this->addConditionalColumns(); |
|
61 | - $this->_sortable_columns = array( |
|
62 | - 'id' => array('EVT_ID' => true), |
|
63 | - 'name' => array('EVT_name' => false), |
|
64 | - 'author' => array('EVT_wp_user' => false), |
|
65 | - 'venue' => array('Venue.VNU_name' => false), |
|
66 | - 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
67 | - 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
68 | - ); |
|
69 | - |
|
70 | - $this->_primary_column = 'id'; |
|
71 | - $this->_hidden_columns = array('author', 'event_category'); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @return array |
|
77 | - */ |
|
78 | - protected function _get_table_filters() |
|
79 | - { |
|
80 | - return array(); // no filters with decaf |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Setup of views properties. |
|
86 | - * |
|
87 | - * @throws InvalidDataTypeException |
|
88 | - * @throws InvalidInterfaceException |
|
89 | - * @throws InvalidArgumentException |
|
90 | - */ |
|
91 | - protected function _add_view_counts() |
|
92 | - { |
|
93 | - $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
94 | - $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
95 | - if ( |
|
96 | - EE_Registry::instance()->CAP->current_user_can( |
|
97 | - 'ee_delete_events', |
|
98 | - 'espresso_events_trash_events' |
|
99 | - ) |
|
100 | - ) { |
|
101 | - $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @param EE_Event $item |
|
108 | - * @return string |
|
109 | - * @throws EE_Error |
|
110 | - */ |
|
111 | - protected function _get_row_class($item) |
|
112 | - { |
|
113 | - $class = parent::_get_row_class($item); |
|
114 | - // add status class |
|
115 | - $class .= $item instanceof EE_Event |
|
116 | - ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
117 | - : ''; |
|
118 | - if ($this->_has_checkbox_column) { |
|
119 | - $class .= ' has-checkbox-column'; |
|
120 | - } |
|
121 | - return $class; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @param EE_Event $item |
|
127 | - * @return string |
|
128 | - * @throws EE_Error |
|
129 | - */ |
|
130 | - public function column_status(EE_Event $item) |
|
131 | - { |
|
132 | - return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
133 | - . $item->get_active_status() |
|
134 | - . '"></span>'; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @param EE_Event $item |
|
140 | - * @return string |
|
141 | - * @throws EE_Error |
|
142 | - */ |
|
143 | - public function column_cb($item) |
|
144 | - { |
|
145 | - if (! $item instanceof EE_Event) { |
|
146 | - return ''; |
|
147 | - } |
|
148 | - $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
149 | - return sprintf( |
|
150 | - '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
151 | - $item->ID() |
|
152 | - ); |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * @param EE_Event $item |
|
158 | - * @return mixed|string |
|
159 | - * @throws EE_Error |
|
160 | - */ |
|
161 | - public function column_id(EE_Event $item) |
|
162 | - { |
|
163 | - $content = $item->ID(); |
|
164 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
165 | - return $content; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param EE_Event $item |
|
171 | - * @return string |
|
172 | - * @throws EE_Error |
|
173 | - * @throws InvalidArgumentException |
|
174 | - * @throws InvalidDataTypeException |
|
175 | - * @throws InvalidInterfaceException |
|
176 | - */ |
|
177 | - public function column_name(EE_Event $item) |
|
178 | - { |
|
179 | - $edit_query_args = array( |
|
180 | - 'action' => 'edit', |
|
181 | - 'post' => $item->ID(), |
|
182 | - ); |
|
183 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
184 | - $actions = $this->_column_name_action_setup($item); |
|
185 | - $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
186 | - $content = '<strong><a class="row-title" href="' |
|
187 | - . $edit_link . '">' |
|
188 | - . $item->name() |
|
189 | - . '</a></strong>' |
|
190 | - . $status; |
|
191 | - $content .= '<br><span class="ee-status-text-small">' |
|
192 | - . EEH_Template::pretty_status( |
|
193 | - $item->get_active_status(), |
|
194 | - false, |
|
195 | - 'sentence' |
|
196 | - ) |
|
197 | - . '</span>'; |
|
198 | - $content .= $this->row_actions($actions); |
|
199 | - return $content; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * Just a method for setting up the actions for the name column |
|
205 | - * |
|
206 | - * @param EE_Event $item |
|
207 | - * @return array array of actions |
|
208 | - * @throws EE_Error |
|
209 | - * @throws InvalidArgumentException |
|
210 | - * @throws InvalidDataTypeException |
|
211 | - * @throws InvalidInterfaceException |
|
212 | - */ |
|
213 | - protected function _column_name_action_setup(EE_Event $item) |
|
214 | - { |
|
215 | - // todo: remove when attendees is active |
|
216 | - if (! defined('REG_ADMIN_URL')) { |
|
217 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
218 | - } |
|
219 | - $actions = array(); |
|
220 | - $restore_event_link = ''; |
|
221 | - $delete_event_link = ''; |
|
222 | - $trash_event_link = ''; |
|
223 | - if ( |
|
224 | - EE_Registry::instance()->CAP->current_user_can( |
|
225 | - 'ee_edit_event', |
|
226 | - 'espresso_events_edit', |
|
227 | - $item->ID() |
|
228 | - ) |
|
229 | - ) { |
|
230 | - $edit_query_args = array( |
|
231 | - 'action' => 'edit', |
|
232 | - 'post' => $item->ID(), |
|
233 | - ); |
|
234 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
235 | - $actions['edit'] = '<a href="' . $edit_link . '"' |
|
236 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
237 | - . esc_html__('Edit', 'event_espresso') |
|
238 | - . '</a>'; |
|
239 | - } |
|
240 | - if ( |
|
241 | - EE_Registry::instance()->CAP->current_user_can( |
|
242 | - 'ee_read_registrations', |
|
243 | - 'espresso_registrations_view_registration' |
|
244 | - ) |
|
245 | - && EE_Registry::instance()->CAP->current_user_can( |
|
246 | - 'ee_read_event', |
|
247 | - 'espresso_registrations_view_registration', |
|
248 | - $item->ID() |
|
249 | - ) |
|
250 | - ) { |
|
251 | - $attendees_query_args = array( |
|
252 | - 'action' => 'default', |
|
253 | - 'event_id' => $item->ID(), |
|
254 | - ); |
|
255 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
256 | - $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
257 | - . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
258 | - . esc_html__('Registrations', 'event_espresso') |
|
259 | - . '</a>'; |
|
260 | - } |
|
261 | - if ( |
|
262 | - EE_Registry::instance()->CAP->current_user_can( |
|
263 | - 'ee_delete_event', |
|
264 | - 'espresso_events_trash_event', |
|
265 | - $item->ID() |
|
266 | - ) |
|
267 | - ) { |
|
268 | - $trash_event_query_args = array( |
|
269 | - 'action' => 'trash_event', |
|
270 | - 'EVT_ID' => $item->ID(), |
|
271 | - ); |
|
272 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
273 | - $trash_event_query_args, |
|
274 | - EVENTS_ADMIN_URL |
|
275 | - ); |
|
276 | - } |
|
277 | - if ( |
|
278 | - EE_Registry::instance()->CAP->current_user_can( |
|
279 | - 'ee_delete_event', |
|
280 | - 'espresso_events_restore_event', |
|
281 | - $item->ID() |
|
282 | - ) |
|
283 | - ) { |
|
284 | - $restore_event_query_args = array( |
|
285 | - 'action' => 'restore_event', |
|
286 | - 'EVT_ID' => $item->ID(), |
|
287 | - ); |
|
288 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
289 | - $restore_event_query_args, |
|
290 | - EVENTS_ADMIN_URL |
|
291 | - ); |
|
292 | - } |
|
293 | - if ( |
|
294 | - EE_Registry::instance()->CAP->current_user_can( |
|
295 | - 'ee_delete_event', |
|
296 | - 'espresso_events_delete_event', |
|
297 | - $item->ID() |
|
298 | - ) |
|
299 | - ) { |
|
300 | - $delete_event_query_args = array( |
|
301 | - 'action' => 'delete_event', |
|
302 | - 'EVT_ID' => $item->ID(), |
|
303 | - ); |
|
304 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
305 | - $delete_event_query_args, |
|
306 | - EVENTS_ADMIN_URL |
|
307 | - ); |
|
308 | - } |
|
309 | - $view_link = get_permalink($item->ID()); |
|
310 | - $actions['view'] = '<a href="' . $view_link . '"' |
|
311 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
312 | - . esc_html__('View', 'event_espresso') |
|
313 | - . '</a>'; |
|
314 | - if ($item->get('status') === 'trash') { |
|
315 | - if ( |
|
316 | - EE_Registry::instance()->CAP->current_user_can( |
|
317 | - 'ee_delete_event', |
|
318 | - 'espresso_events_restore_event', |
|
319 | - $item->ID() |
|
320 | - ) |
|
321 | - ) { |
|
322 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
323 | - . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
324 | - . '">' |
|
325 | - . esc_html__('Restore from Trash', 'event_espresso') |
|
326 | - . '</a>'; |
|
327 | - } |
|
328 | - if ( |
|
329 | - EE_Registry::instance()->CAP->current_user_can( |
|
330 | - 'ee_delete_event', |
|
331 | - 'espresso_events_delete_event', |
|
332 | - $item->ID() |
|
333 | - ) |
|
334 | - ) { |
|
335 | - $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
336 | - . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
337 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
338 | - . '</a>'; |
|
339 | - } |
|
340 | - } else { |
|
341 | - if ( |
|
342 | - EE_Registry::instance()->CAP->current_user_can( |
|
343 | - 'ee_delete_event', |
|
344 | - 'espresso_events_trash_event', |
|
345 | - $item->ID() |
|
346 | - ) |
|
347 | - ) { |
|
348 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
349 | - . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
350 | - . esc_html__('Trash', 'event_espresso') |
|
351 | - . '</a>'; |
|
352 | - } |
|
353 | - } |
|
354 | - return $actions; |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * @param EE_Event $item |
|
360 | - * @return string |
|
361 | - * @throws EE_Error |
|
362 | - */ |
|
363 | - public function column_author(EE_Event $item) |
|
364 | - { |
|
365 | - // user author info |
|
366 | - $event_author = get_userdata($item->wp_user()); |
|
367 | - $gravatar = get_avatar($item->wp_user(), '15'); |
|
368 | - // filter link |
|
369 | - $query_args = array( |
|
370 | - 'action' => 'default', |
|
371 | - 'EVT_wp_user' => $item->wp_user(), |
|
372 | - ); |
|
373 | - $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
374 | - return $gravatar . ' <a href="' . $filter_url . '"' |
|
375 | - . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
376 | - . $event_author->display_name |
|
377 | - . '</a>'; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * @param EE_Event $event |
|
383 | - * @return string |
|
384 | - * @throws EE_Error |
|
385 | - */ |
|
386 | - public function column_event_category(EE_Event $event) |
|
387 | - { |
|
388 | - $event_categories = $event->get_all_event_categories(); |
|
389 | - return implode( |
|
390 | - ', ', |
|
391 | - array_map( |
|
392 | - function (EE_Term $category) { |
|
393 | - return $category->name(); |
|
394 | - }, |
|
395 | - $event_categories |
|
396 | - ) |
|
397 | - ); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * @param EE_Event $item |
|
403 | - * @return string |
|
404 | - * @throws EE_Error |
|
405 | - */ |
|
406 | - public function column_venue(EE_Event $item) |
|
407 | - { |
|
408 | - $venue = $item->get_first_related('Venue'); |
|
409 | - return ! empty($venue) |
|
410 | - ? $venue->name() |
|
411 | - : ''; |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * @param EE_Event $item |
|
417 | - * @return string |
|
418 | - * @throws EE_Error |
|
419 | - */ |
|
420 | - public function column_start_date_time(EE_Event $item) |
|
421 | - { |
|
422 | - return $this->_dtt instanceof EE_Datetime |
|
423 | - ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
424 | - : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * @param EE_Event $item |
|
430 | - * @return string |
|
431 | - * @throws EE_Error |
|
432 | - */ |
|
433 | - public function column_reg_begins(EE_Event $item) |
|
434 | - { |
|
435 | - $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
436 | - return $reg_start instanceof EE_Ticket |
|
437 | - ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
438 | - : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * @param EE_Event $item |
|
444 | - * @return int|string |
|
445 | - * @throws EE_Error |
|
446 | - * @throws InvalidArgumentException |
|
447 | - * @throws InvalidDataTypeException |
|
448 | - * @throws InvalidInterfaceException |
|
449 | - */ |
|
450 | - public function column_attendees(EE_Event $item) |
|
451 | - { |
|
452 | - $attendees_query_args = array( |
|
453 | - 'action' => 'default', |
|
454 | - 'event_id' => $item->ID(), |
|
455 | - ); |
|
456 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
457 | - $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
458 | - return EE_Registry::instance()->CAP->current_user_can( |
|
459 | - 'ee_read_event', |
|
460 | - 'espresso_registrations_view_registration', |
|
461 | - $item->ID() |
|
462 | - ) |
|
463 | - && EE_Registry::instance()->CAP->current_user_can( |
|
464 | - 'ee_read_registrations', |
|
465 | - 'espresso_registrations_view_registration' |
|
466 | - ) |
|
467 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
468 | - : $registered_attendees; |
|
469 | - } |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * @param EE_Event $item |
|
474 | - * @return float |
|
475 | - * @throws EE_Error |
|
476 | - * @throws InvalidArgumentException |
|
477 | - * @throws InvalidDataTypeException |
|
478 | - * @throws InvalidInterfaceException |
|
479 | - */ |
|
480 | - public function column_tkts_sold(EE_Event $item) |
|
481 | - { |
|
482 | - return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
483 | - } |
|
484 | - |
|
485 | - |
|
486 | - /** |
|
487 | - * @param EE_Event $item |
|
488 | - * @return string |
|
489 | - * @throws EE_Error |
|
490 | - * @throws InvalidArgumentException |
|
491 | - * @throws InvalidDataTypeException |
|
492 | - * @throws InvalidInterfaceException |
|
493 | - */ |
|
494 | - public function column_actions(EE_Event $item) |
|
495 | - { |
|
496 | - // todo: remove when attendees is active |
|
497 | - if (! defined('REG_ADMIN_URL')) { |
|
498 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
499 | - } |
|
500 | - $action_links = array(); |
|
501 | - $view_link = get_permalink($item->ID()); |
|
502 | - $action_links[] = '<a href="' . $view_link . '"' |
|
503 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
504 | - $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
505 | - if ( |
|
506 | - EE_Registry::instance()->CAP->current_user_can( |
|
507 | - 'ee_edit_event', |
|
508 | - 'espresso_events_edit', |
|
509 | - $item->ID() |
|
510 | - ) |
|
511 | - ) { |
|
512 | - $edit_query_args = array( |
|
513 | - 'action' => 'edit', |
|
514 | - 'post' => $item->ID(), |
|
515 | - ); |
|
516 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
517 | - $action_links[] = '<a href="' . $edit_link . '"' |
|
518 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
519 | - . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
520 | - . '</a>'; |
|
521 | - } |
|
522 | - if ( |
|
523 | - EE_Registry::instance()->CAP->current_user_can( |
|
524 | - 'ee_read_registrations', |
|
525 | - 'espresso_registrations_view_registration' |
|
526 | - ) && EE_Registry::instance()->CAP->current_user_can( |
|
527 | - 'ee_read_event', |
|
528 | - 'espresso_registrations_view_registration', |
|
529 | - $item->ID() |
|
530 | - ) |
|
531 | - ) { |
|
532 | - $attendees_query_args = array( |
|
533 | - 'action' => 'default', |
|
534 | - 'event_id' => $item->ID(), |
|
535 | - ); |
|
536 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
537 | - $action_links[] = '<a href="' . $attendees_link . '"' |
|
538 | - . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
539 | - . '<div class="dashicons dashicons-groups"></div>' |
|
540 | - . '</a>'; |
|
541 | - } |
|
542 | - $action_links = apply_filters( |
|
543 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
544 | - $action_links, |
|
545 | - $item |
|
546 | - ); |
|
547 | - return $this->_action_string( |
|
548 | - implode("\n\t", $action_links), |
|
549 | - $item, |
|
550 | - 'div' |
|
551 | - ); |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - /** |
|
556 | - * Helper for adding columns conditionally |
|
557 | - * |
|
558 | - * @throws EE_Error |
|
559 | - * @throws InvalidArgumentException |
|
560 | - * @throws InvalidDataTypeException |
|
561 | - * @throws InvalidInterfaceException |
|
562 | - */ |
|
563 | - private function addConditionalColumns() |
|
564 | - { |
|
565 | - $event_category_count = EEM_Term::instance()->count( |
|
566 | - [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]] |
|
567 | - ); |
|
568 | - if ($event_category_count === 0) { |
|
569 | - return; |
|
570 | - } |
|
571 | - $column_array = []; |
|
572 | - foreach ($this->_columns as $column => $column_label) { |
|
573 | - $column_array[ $column ] = $column_label; |
|
574 | - if ($column === 'venue') { |
|
575 | - $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
|
576 | - } |
|
577 | - } |
|
578 | - $this->_columns = $column_array; |
|
579 | - } |
|
17 | + /** |
|
18 | + * @var EE_Datetime |
|
19 | + */ |
|
20 | + private $_dtt; |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * Initial setup of data properties for the list table. |
|
25 | + */ |
|
26 | + protected function _setup_data() |
|
27 | + { |
|
28 | + $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
29 | + $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
30 | + } |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * Set up of additional properties for the list table. |
|
35 | + */ |
|
36 | + protected function _set_properties() |
|
37 | + { |
|
38 | + $this->_wp_list_args = array( |
|
39 | + 'singular' => esc_html__('event', 'event_espresso'), |
|
40 | + 'plural' => esc_html__('events', 'event_espresso'), |
|
41 | + 'ajax' => true, // for now |
|
42 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
43 | + ); |
|
44 | + $this->_columns = array( |
|
45 | + 'cb' => '<input type="checkbox" />', |
|
46 | + 'id' => esc_html__('ID', 'event_espresso'), |
|
47 | + 'name' => esc_html__('Name', 'event_espresso'), |
|
48 | + 'author' => esc_html__('Author', 'event_espresso'), |
|
49 | + 'venue' => esc_html__('Venue', 'event_espresso'), |
|
50 | + 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
51 | + 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
52 | + 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
53 | + . '<span class="screen-reader-text">' |
|
54 | + . esc_html__('Approved Registrations', 'event_espresso') |
|
55 | + . '</span>' |
|
56 | + . '</span>', |
|
57 | + // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), |
|
58 | + 'actions' => esc_html__('Actions', 'event_espresso'), |
|
59 | + ); |
|
60 | + $this->addConditionalColumns(); |
|
61 | + $this->_sortable_columns = array( |
|
62 | + 'id' => array('EVT_ID' => true), |
|
63 | + 'name' => array('EVT_name' => false), |
|
64 | + 'author' => array('EVT_wp_user' => false), |
|
65 | + 'venue' => array('Venue.VNU_name' => false), |
|
66 | + 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
67 | + 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
68 | + ); |
|
69 | + |
|
70 | + $this->_primary_column = 'id'; |
|
71 | + $this->_hidden_columns = array('author', 'event_category'); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @return array |
|
77 | + */ |
|
78 | + protected function _get_table_filters() |
|
79 | + { |
|
80 | + return array(); // no filters with decaf |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Setup of views properties. |
|
86 | + * |
|
87 | + * @throws InvalidDataTypeException |
|
88 | + * @throws InvalidInterfaceException |
|
89 | + * @throws InvalidArgumentException |
|
90 | + */ |
|
91 | + protected function _add_view_counts() |
|
92 | + { |
|
93 | + $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
94 | + $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
95 | + if ( |
|
96 | + EE_Registry::instance()->CAP->current_user_can( |
|
97 | + 'ee_delete_events', |
|
98 | + 'espresso_events_trash_events' |
|
99 | + ) |
|
100 | + ) { |
|
101 | + $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @param EE_Event $item |
|
108 | + * @return string |
|
109 | + * @throws EE_Error |
|
110 | + */ |
|
111 | + protected function _get_row_class($item) |
|
112 | + { |
|
113 | + $class = parent::_get_row_class($item); |
|
114 | + // add status class |
|
115 | + $class .= $item instanceof EE_Event |
|
116 | + ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
117 | + : ''; |
|
118 | + if ($this->_has_checkbox_column) { |
|
119 | + $class .= ' has-checkbox-column'; |
|
120 | + } |
|
121 | + return $class; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @param EE_Event $item |
|
127 | + * @return string |
|
128 | + * @throws EE_Error |
|
129 | + */ |
|
130 | + public function column_status(EE_Event $item) |
|
131 | + { |
|
132 | + return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
133 | + . $item->get_active_status() |
|
134 | + . '"></span>'; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @param EE_Event $item |
|
140 | + * @return string |
|
141 | + * @throws EE_Error |
|
142 | + */ |
|
143 | + public function column_cb($item) |
|
144 | + { |
|
145 | + if (! $item instanceof EE_Event) { |
|
146 | + return ''; |
|
147 | + } |
|
148 | + $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
149 | + return sprintf( |
|
150 | + '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
151 | + $item->ID() |
|
152 | + ); |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * @param EE_Event $item |
|
158 | + * @return mixed|string |
|
159 | + * @throws EE_Error |
|
160 | + */ |
|
161 | + public function column_id(EE_Event $item) |
|
162 | + { |
|
163 | + $content = $item->ID(); |
|
164 | + $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
165 | + return $content; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param EE_Event $item |
|
171 | + * @return string |
|
172 | + * @throws EE_Error |
|
173 | + * @throws InvalidArgumentException |
|
174 | + * @throws InvalidDataTypeException |
|
175 | + * @throws InvalidInterfaceException |
|
176 | + */ |
|
177 | + public function column_name(EE_Event $item) |
|
178 | + { |
|
179 | + $edit_query_args = array( |
|
180 | + 'action' => 'edit', |
|
181 | + 'post' => $item->ID(), |
|
182 | + ); |
|
183 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
184 | + $actions = $this->_column_name_action_setup($item); |
|
185 | + $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
186 | + $content = '<strong><a class="row-title" href="' |
|
187 | + . $edit_link . '">' |
|
188 | + . $item->name() |
|
189 | + . '</a></strong>' |
|
190 | + . $status; |
|
191 | + $content .= '<br><span class="ee-status-text-small">' |
|
192 | + . EEH_Template::pretty_status( |
|
193 | + $item->get_active_status(), |
|
194 | + false, |
|
195 | + 'sentence' |
|
196 | + ) |
|
197 | + . '</span>'; |
|
198 | + $content .= $this->row_actions($actions); |
|
199 | + return $content; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * Just a method for setting up the actions for the name column |
|
205 | + * |
|
206 | + * @param EE_Event $item |
|
207 | + * @return array array of actions |
|
208 | + * @throws EE_Error |
|
209 | + * @throws InvalidArgumentException |
|
210 | + * @throws InvalidDataTypeException |
|
211 | + * @throws InvalidInterfaceException |
|
212 | + */ |
|
213 | + protected function _column_name_action_setup(EE_Event $item) |
|
214 | + { |
|
215 | + // todo: remove when attendees is active |
|
216 | + if (! defined('REG_ADMIN_URL')) { |
|
217 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
218 | + } |
|
219 | + $actions = array(); |
|
220 | + $restore_event_link = ''; |
|
221 | + $delete_event_link = ''; |
|
222 | + $trash_event_link = ''; |
|
223 | + if ( |
|
224 | + EE_Registry::instance()->CAP->current_user_can( |
|
225 | + 'ee_edit_event', |
|
226 | + 'espresso_events_edit', |
|
227 | + $item->ID() |
|
228 | + ) |
|
229 | + ) { |
|
230 | + $edit_query_args = array( |
|
231 | + 'action' => 'edit', |
|
232 | + 'post' => $item->ID(), |
|
233 | + ); |
|
234 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
235 | + $actions['edit'] = '<a href="' . $edit_link . '"' |
|
236 | + . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
237 | + . esc_html__('Edit', 'event_espresso') |
|
238 | + . '</a>'; |
|
239 | + } |
|
240 | + if ( |
|
241 | + EE_Registry::instance()->CAP->current_user_can( |
|
242 | + 'ee_read_registrations', |
|
243 | + 'espresso_registrations_view_registration' |
|
244 | + ) |
|
245 | + && EE_Registry::instance()->CAP->current_user_can( |
|
246 | + 'ee_read_event', |
|
247 | + 'espresso_registrations_view_registration', |
|
248 | + $item->ID() |
|
249 | + ) |
|
250 | + ) { |
|
251 | + $attendees_query_args = array( |
|
252 | + 'action' => 'default', |
|
253 | + 'event_id' => $item->ID(), |
|
254 | + ); |
|
255 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
256 | + $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
257 | + . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
258 | + . esc_html__('Registrations', 'event_espresso') |
|
259 | + . '</a>'; |
|
260 | + } |
|
261 | + if ( |
|
262 | + EE_Registry::instance()->CAP->current_user_can( |
|
263 | + 'ee_delete_event', |
|
264 | + 'espresso_events_trash_event', |
|
265 | + $item->ID() |
|
266 | + ) |
|
267 | + ) { |
|
268 | + $trash_event_query_args = array( |
|
269 | + 'action' => 'trash_event', |
|
270 | + 'EVT_ID' => $item->ID(), |
|
271 | + ); |
|
272 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
273 | + $trash_event_query_args, |
|
274 | + EVENTS_ADMIN_URL |
|
275 | + ); |
|
276 | + } |
|
277 | + if ( |
|
278 | + EE_Registry::instance()->CAP->current_user_can( |
|
279 | + 'ee_delete_event', |
|
280 | + 'espresso_events_restore_event', |
|
281 | + $item->ID() |
|
282 | + ) |
|
283 | + ) { |
|
284 | + $restore_event_query_args = array( |
|
285 | + 'action' => 'restore_event', |
|
286 | + 'EVT_ID' => $item->ID(), |
|
287 | + ); |
|
288 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
289 | + $restore_event_query_args, |
|
290 | + EVENTS_ADMIN_URL |
|
291 | + ); |
|
292 | + } |
|
293 | + if ( |
|
294 | + EE_Registry::instance()->CAP->current_user_can( |
|
295 | + 'ee_delete_event', |
|
296 | + 'espresso_events_delete_event', |
|
297 | + $item->ID() |
|
298 | + ) |
|
299 | + ) { |
|
300 | + $delete_event_query_args = array( |
|
301 | + 'action' => 'delete_event', |
|
302 | + 'EVT_ID' => $item->ID(), |
|
303 | + ); |
|
304 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
305 | + $delete_event_query_args, |
|
306 | + EVENTS_ADMIN_URL |
|
307 | + ); |
|
308 | + } |
|
309 | + $view_link = get_permalink($item->ID()); |
|
310 | + $actions['view'] = '<a href="' . $view_link . '"' |
|
311 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
312 | + . esc_html__('View', 'event_espresso') |
|
313 | + . '</a>'; |
|
314 | + if ($item->get('status') === 'trash') { |
|
315 | + if ( |
|
316 | + EE_Registry::instance()->CAP->current_user_can( |
|
317 | + 'ee_delete_event', |
|
318 | + 'espresso_events_restore_event', |
|
319 | + $item->ID() |
|
320 | + ) |
|
321 | + ) { |
|
322 | + $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
323 | + . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
324 | + . '">' |
|
325 | + . esc_html__('Restore from Trash', 'event_espresso') |
|
326 | + . '</a>'; |
|
327 | + } |
|
328 | + if ( |
|
329 | + EE_Registry::instance()->CAP->current_user_can( |
|
330 | + 'ee_delete_event', |
|
331 | + 'espresso_events_delete_event', |
|
332 | + $item->ID() |
|
333 | + ) |
|
334 | + ) { |
|
335 | + $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
336 | + . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
337 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
338 | + . '</a>'; |
|
339 | + } |
|
340 | + } else { |
|
341 | + if ( |
|
342 | + EE_Registry::instance()->CAP->current_user_can( |
|
343 | + 'ee_delete_event', |
|
344 | + 'espresso_events_trash_event', |
|
345 | + $item->ID() |
|
346 | + ) |
|
347 | + ) { |
|
348 | + $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
349 | + . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
350 | + . esc_html__('Trash', 'event_espresso') |
|
351 | + . '</a>'; |
|
352 | + } |
|
353 | + } |
|
354 | + return $actions; |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * @param EE_Event $item |
|
360 | + * @return string |
|
361 | + * @throws EE_Error |
|
362 | + */ |
|
363 | + public function column_author(EE_Event $item) |
|
364 | + { |
|
365 | + // user author info |
|
366 | + $event_author = get_userdata($item->wp_user()); |
|
367 | + $gravatar = get_avatar($item->wp_user(), '15'); |
|
368 | + // filter link |
|
369 | + $query_args = array( |
|
370 | + 'action' => 'default', |
|
371 | + 'EVT_wp_user' => $item->wp_user(), |
|
372 | + ); |
|
373 | + $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
374 | + return $gravatar . ' <a href="' . $filter_url . '"' |
|
375 | + . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
376 | + . $event_author->display_name |
|
377 | + . '</a>'; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * @param EE_Event $event |
|
383 | + * @return string |
|
384 | + * @throws EE_Error |
|
385 | + */ |
|
386 | + public function column_event_category(EE_Event $event) |
|
387 | + { |
|
388 | + $event_categories = $event->get_all_event_categories(); |
|
389 | + return implode( |
|
390 | + ', ', |
|
391 | + array_map( |
|
392 | + function (EE_Term $category) { |
|
393 | + return $category->name(); |
|
394 | + }, |
|
395 | + $event_categories |
|
396 | + ) |
|
397 | + ); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * @param EE_Event $item |
|
403 | + * @return string |
|
404 | + * @throws EE_Error |
|
405 | + */ |
|
406 | + public function column_venue(EE_Event $item) |
|
407 | + { |
|
408 | + $venue = $item->get_first_related('Venue'); |
|
409 | + return ! empty($venue) |
|
410 | + ? $venue->name() |
|
411 | + : ''; |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * @param EE_Event $item |
|
417 | + * @return string |
|
418 | + * @throws EE_Error |
|
419 | + */ |
|
420 | + public function column_start_date_time(EE_Event $item) |
|
421 | + { |
|
422 | + return $this->_dtt instanceof EE_Datetime |
|
423 | + ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
424 | + : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * @param EE_Event $item |
|
430 | + * @return string |
|
431 | + * @throws EE_Error |
|
432 | + */ |
|
433 | + public function column_reg_begins(EE_Event $item) |
|
434 | + { |
|
435 | + $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
436 | + return $reg_start instanceof EE_Ticket |
|
437 | + ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
438 | + : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * @param EE_Event $item |
|
444 | + * @return int|string |
|
445 | + * @throws EE_Error |
|
446 | + * @throws InvalidArgumentException |
|
447 | + * @throws InvalidDataTypeException |
|
448 | + * @throws InvalidInterfaceException |
|
449 | + */ |
|
450 | + public function column_attendees(EE_Event $item) |
|
451 | + { |
|
452 | + $attendees_query_args = array( |
|
453 | + 'action' => 'default', |
|
454 | + 'event_id' => $item->ID(), |
|
455 | + ); |
|
456 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
457 | + $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
458 | + return EE_Registry::instance()->CAP->current_user_can( |
|
459 | + 'ee_read_event', |
|
460 | + 'espresso_registrations_view_registration', |
|
461 | + $item->ID() |
|
462 | + ) |
|
463 | + && EE_Registry::instance()->CAP->current_user_can( |
|
464 | + 'ee_read_registrations', |
|
465 | + 'espresso_registrations_view_registration' |
|
466 | + ) |
|
467 | + ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
468 | + : $registered_attendees; |
|
469 | + } |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * @param EE_Event $item |
|
474 | + * @return float |
|
475 | + * @throws EE_Error |
|
476 | + * @throws InvalidArgumentException |
|
477 | + * @throws InvalidDataTypeException |
|
478 | + * @throws InvalidInterfaceException |
|
479 | + */ |
|
480 | + public function column_tkts_sold(EE_Event $item) |
|
481 | + { |
|
482 | + return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
483 | + } |
|
484 | + |
|
485 | + |
|
486 | + /** |
|
487 | + * @param EE_Event $item |
|
488 | + * @return string |
|
489 | + * @throws EE_Error |
|
490 | + * @throws InvalidArgumentException |
|
491 | + * @throws InvalidDataTypeException |
|
492 | + * @throws InvalidInterfaceException |
|
493 | + */ |
|
494 | + public function column_actions(EE_Event $item) |
|
495 | + { |
|
496 | + // todo: remove when attendees is active |
|
497 | + if (! defined('REG_ADMIN_URL')) { |
|
498 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
499 | + } |
|
500 | + $action_links = array(); |
|
501 | + $view_link = get_permalink($item->ID()); |
|
502 | + $action_links[] = '<a href="' . $view_link . '"' |
|
503 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
504 | + $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
505 | + if ( |
|
506 | + EE_Registry::instance()->CAP->current_user_can( |
|
507 | + 'ee_edit_event', |
|
508 | + 'espresso_events_edit', |
|
509 | + $item->ID() |
|
510 | + ) |
|
511 | + ) { |
|
512 | + $edit_query_args = array( |
|
513 | + 'action' => 'edit', |
|
514 | + 'post' => $item->ID(), |
|
515 | + ); |
|
516 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
517 | + $action_links[] = '<a href="' . $edit_link . '"' |
|
518 | + . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
519 | + . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
520 | + . '</a>'; |
|
521 | + } |
|
522 | + if ( |
|
523 | + EE_Registry::instance()->CAP->current_user_can( |
|
524 | + 'ee_read_registrations', |
|
525 | + 'espresso_registrations_view_registration' |
|
526 | + ) && EE_Registry::instance()->CAP->current_user_can( |
|
527 | + 'ee_read_event', |
|
528 | + 'espresso_registrations_view_registration', |
|
529 | + $item->ID() |
|
530 | + ) |
|
531 | + ) { |
|
532 | + $attendees_query_args = array( |
|
533 | + 'action' => 'default', |
|
534 | + 'event_id' => $item->ID(), |
|
535 | + ); |
|
536 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
537 | + $action_links[] = '<a href="' . $attendees_link . '"' |
|
538 | + . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
539 | + . '<div class="dashicons dashicons-groups"></div>' |
|
540 | + . '</a>'; |
|
541 | + } |
|
542 | + $action_links = apply_filters( |
|
543 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
544 | + $action_links, |
|
545 | + $item |
|
546 | + ); |
|
547 | + return $this->_action_string( |
|
548 | + implode("\n\t", $action_links), |
|
549 | + $item, |
|
550 | + 'div' |
|
551 | + ); |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + /** |
|
556 | + * Helper for adding columns conditionally |
|
557 | + * |
|
558 | + * @throws EE_Error |
|
559 | + * @throws InvalidArgumentException |
|
560 | + * @throws InvalidDataTypeException |
|
561 | + * @throws InvalidInterfaceException |
|
562 | + */ |
|
563 | + private function addConditionalColumns() |
|
564 | + { |
|
565 | + $event_category_count = EEM_Term::instance()->count( |
|
566 | + [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]] |
|
567 | + ); |
|
568 | + if ($event_category_count === 0) { |
|
569 | + return; |
|
570 | + } |
|
571 | + $column_array = []; |
|
572 | + foreach ($this->_columns as $column => $column_label) { |
|
573 | + $column_array[ $column ] = $column_label; |
|
574 | + if ($column === 'venue') { |
|
575 | + $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
|
576 | + } |
|
577 | + } |
|
578 | + $this->_columns = $column_array; |
|
579 | + } |
|
580 | 580 | } |
@@ -12,382 +12,382 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Attendee_Contact_List_Table extends EE_Admin_List_Table |
14 | 14 | { |
15 | - /** |
|
16 | - * Initial setup of data (called by parent). |
|
17 | - */ |
|
18 | - protected function _setup_data() |
|
19 | - { |
|
20 | - $this->_data = $this->_view !== 'trash' |
|
21 | - ? $this->_admin_page->get_attendees($this->_per_page) |
|
22 | - : $this->_admin_page->get_attendees($this->_per_page, false, true); |
|
23 | - $this->_all_data_count = $this->_view !== 'trash' |
|
24 | - ? $this->_admin_page->get_attendees($this->_per_page, true) |
|
25 | - : $this->_admin_page->get_attendees($this->_per_page, true, true); |
|
26 | - } |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * Initial setup of properties. |
|
31 | - */ |
|
32 | - protected function _set_properties() |
|
33 | - { |
|
34 | - $this->_wp_list_args = array( |
|
35 | - 'singular' => esc_html__('attendee', 'event_espresso'), |
|
36 | - 'plural' => esc_html__('attendees', 'event_espresso'), |
|
37 | - 'ajax' => true, |
|
38 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
39 | - ); |
|
40 | - |
|
41 | - $this->_columns = array( |
|
42 | - 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
43 | - 'ATT_ID' => esc_html__('ID', 'event_espresso'), |
|
44 | - 'ATT_fname' => esc_html__('First Name', 'event_espresso'), |
|
45 | - 'ATT_lname' => esc_html__('Last Name', 'event_espresso'), |
|
46 | - 'ATT_email' => esc_html__('Email Address', 'event_espresso'), |
|
47 | - 'Registration_Count' => esc_html__('# Registrations', 'event_espresso'), |
|
48 | - 'ATT_phone' => esc_html__('Phone', 'event_espresso'), |
|
49 | - 'ATT_address' => esc_html__('Address', 'event_espresso'), |
|
50 | - 'ATT_city' => esc_html__('City', 'event_espresso'), |
|
51 | - 'STA_ID' => esc_html__('State/Province', 'event_espresso'), |
|
52 | - 'CNT_ISO' => esc_html__('Country', 'event_espresso'), |
|
53 | - ); |
|
54 | - |
|
55 | - $this->_sortable_columns = array( |
|
56 | - 'ATT_ID' => array('ATT_ID' => false), |
|
57 | - 'ATT_lname' => array('ATT_lname' => true), // true means its already sorted |
|
58 | - 'ATT_fname' => array('ATT_fname' => false), |
|
59 | - 'ATT_email' => array('ATT_email' => false), |
|
60 | - 'Registration_Count' => array('Registration_Count' => false), |
|
61 | - 'ATT_city' => array('ATT_city' => false), |
|
62 | - 'STA_ID' => array('STA_ID' => false), |
|
63 | - 'CNT_ISO' => array('CNT_ISO' => false), |
|
64 | - ); |
|
65 | - |
|
66 | - $this->_hidden_columns = array( |
|
67 | - 'ATT_phone', |
|
68 | - 'ATT_address', |
|
69 | - 'ATT_city', |
|
70 | - 'STA_ID', |
|
71 | - 'CNT_ISO', |
|
72 | - ); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * Initial setup of filters |
|
78 | - * |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - protected function _get_table_filters() |
|
82 | - { |
|
83 | - return array(); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * Initial setup of counts for views |
|
89 | - * |
|
90 | - * @throws InvalidArgumentException |
|
91 | - * @throws InvalidDataTypeException |
|
92 | - * @throws InvalidInterfaceException |
|
93 | - */ |
|
94 | - protected function _add_view_counts() |
|
95 | - { |
|
96 | - $this->_views['in_use']['count'] = $this->_admin_page->get_attendees($this->_per_page, true); |
|
97 | - if ( |
|
98 | - EE_Registry::instance()->CAP->current_user_can( |
|
99 | - 'ee_delete_contacts', |
|
100 | - 'espresso_registrations_delete_registration' |
|
101 | - ) |
|
102 | - ) { |
|
103 | - $this->_views['trash']['count'] = $this->_admin_page->get_attendees($this->_per_page, true, true); |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Get count of attendees. |
|
110 | - * |
|
111 | - * @return int |
|
112 | - * @throws EE_Error |
|
113 | - * @throws InvalidArgumentException |
|
114 | - * @throws InvalidDataTypeException |
|
115 | - * @throws InvalidInterfaceException |
|
116 | - */ |
|
117 | - protected function _get_attendees_count() |
|
118 | - { |
|
119 | - return EEM_Attendee::instance()->count(); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * Checkbox column |
|
125 | - * |
|
126 | - * @param EE_Attendee $attendee Unable to typehint this method because overrides parent. |
|
127 | - * @return string |
|
128 | - * @throws EE_Error |
|
129 | - */ |
|
130 | - public function column_cb($attendee) |
|
131 | - { |
|
132 | - if (! $attendee instanceof EE_Attendee) { |
|
133 | - return ''; |
|
134 | - } |
|
135 | - return sprintf( |
|
136 | - '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', |
|
137 | - $attendee->ID() |
|
138 | - ); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * ATT_ID column |
|
144 | - * |
|
145 | - * @param EE_Attendee $attendee |
|
146 | - * @return string |
|
147 | - * @throws EE_Error |
|
148 | - */ |
|
149 | - public function column_ATT_ID(EE_Attendee $attendee) |
|
150 | - { |
|
151 | - $content = $attendee->ID(); |
|
152 | - $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
153 | - $content .= ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
154 | - return $content; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * ATT_lname column |
|
160 | - * |
|
161 | - * @param EE_Attendee $attendee |
|
162 | - * @return string |
|
163 | - * @throws InvalidArgumentException |
|
164 | - * @throws InvalidDataTypeException |
|
165 | - * @throws InvalidInterfaceException |
|
166 | - * @throws EE_Error |
|
167 | - */ |
|
168 | - public function column_ATT_lname(EE_Attendee $attendee) |
|
169 | - { |
|
170 | - // edit attendee link |
|
171 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
172 | - array( |
|
173 | - 'action' => 'edit_attendee', |
|
174 | - 'post' => $attendee->ID(), |
|
175 | - ), |
|
176 | - REG_ADMIN_URL |
|
177 | - ); |
|
178 | - $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
179 | - 'ee_edit_contacts', |
|
180 | - 'espresso_registrations_edit_attendee' |
|
181 | - ) |
|
182 | - ? '<a href="' . $edit_lnk_url . '" title="' |
|
183 | - . esc_attr__('Edit Contact', 'event_espresso') . '">' |
|
184 | - . $attendee->lname() . '</a>' |
|
185 | - : $attendee->lname(); |
|
186 | - return $name_link; |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * ATT_fname column |
|
192 | - * |
|
193 | - * @param EE_Attendee $attendee |
|
194 | - * @return string |
|
195 | - * @throws InvalidArgumentException |
|
196 | - * @throws InvalidDataTypeException |
|
197 | - * @throws InvalidInterfaceException |
|
198 | - * @throws EE_Error |
|
199 | - */ |
|
200 | - public function column_ATT_fname(EE_Attendee $attendee) |
|
201 | - { |
|
202 | - // Build row actions |
|
203 | - $actions = array(); |
|
204 | - // edit attendee link |
|
205 | - if ( |
|
206 | - EE_Registry::instance()->CAP->current_user_can( |
|
207 | - 'ee_edit_contacts', |
|
208 | - 'espresso_registrations_edit_attendee' |
|
209 | - ) |
|
210 | - ) { |
|
211 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
212 | - array( |
|
213 | - 'action' => 'edit_attendee', |
|
214 | - 'post' => $attendee->ID(), |
|
215 | - ), |
|
216 | - REG_ADMIN_URL |
|
217 | - ); |
|
218 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="' |
|
219 | - . esc_attr__('Edit Contact', 'event_espresso') . '">' |
|
220 | - . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
221 | - } |
|
222 | - |
|
223 | - if ($this->_view === 'in_use') { |
|
224 | - // trash attendee link |
|
225 | - if ( |
|
226 | - EE_Registry::instance()->CAP->current_user_can( |
|
227 | - 'ee_delete_contacts', |
|
228 | - 'espresso_registrations_trash_attendees' |
|
229 | - ) |
|
230 | - ) { |
|
231 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
232 | - array( |
|
233 | - 'action' => 'trash_attendee', |
|
234 | - 'ATT_ID' => $attendee->ID(), |
|
235 | - ), |
|
236 | - REG_ADMIN_URL |
|
237 | - ); |
|
238 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
239 | - . esc_attr__('Move Contact to Trash', 'event_espresso') |
|
240 | - . '">' . esc_html__('Trash', 'event_espresso') . '</a>'; |
|
241 | - } |
|
242 | - } else { |
|
243 | - if ( |
|
244 | - EE_Registry::instance()->CAP->current_user_can( |
|
245 | - 'ee_delete_contacts', |
|
246 | - 'espresso_registrations_restore_attendees' |
|
247 | - ) |
|
248 | - ) { |
|
249 | - // restore attendee link |
|
250 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
251 | - array( |
|
252 | - 'action' => 'restore_attendees', |
|
253 | - 'ATT_ID' => $attendee->ID(), |
|
254 | - ), |
|
255 | - REG_ADMIN_URL |
|
256 | - ); |
|
257 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
258 | - . esc_attr__('Restore Contact', 'event_espresso') . '">' |
|
259 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
260 | - } |
|
261 | - } |
|
262 | - |
|
263 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
264 | - array( |
|
265 | - 'action' => 'edit_attendee', |
|
266 | - 'post' => $attendee->ID(), |
|
267 | - ), |
|
268 | - REG_ADMIN_URL |
|
269 | - ); |
|
270 | - $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
271 | - 'ee_edit_contacts', |
|
272 | - 'espresso_registrations_edit_attendee' |
|
273 | - ) |
|
274 | - ? '<a href="' . $edit_lnk_url . '" title="' |
|
275 | - . esc_attr__('Edit Contact', 'event_espresso') . '">' . $attendee->fname() . '</a>' |
|
276 | - : $attendee->fname(); |
|
277 | - |
|
278 | - // Return the name contents |
|
279 | - return sprintf('%1$s %2$s', $name_link, $this->row_actions($actions)); |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * Email Column |
|
285 | - * |
|
286 | - * @param EE_Attendee $attendee |
|
287 | - * @return string |
|
288 | - * @throws EE_Error |
|
289 | - */ |
|
290 | - public function column_ATT_email(EE_Attendee $attendee) |
|
291 | - { |
|
292 | - return '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>'; |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * Column displaying count of registrations attached to Attendee. |
|
298 | - * |
|
299 | - * @param EE_Attendee $attendee |
|
300 | - * @return string |
|
301 | - * @throws EE_Error |
|
302 | - */ |
|
303 | - public function column_Registration_Count(EE_Attendee $attendee) |
|
304 | - { |
|
305 | - $link = EEH_URL::add_query_args_and_nonce( |
|
306 | - array( |
|
307 | - 'action' => 'default', |
|
308 | - 'ATT_ID' => $attendee->ID(), |
|
309 | - ), |
|
310 | - REG_ADMIN_URL |
|
311 | - ); |
|
312 | - return '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>'; |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * ATT_address column |
|
318 | - * |
|
319 | - * @param EE_Attendee $attendee |
|
320 | - * @return mixed |
|
321 | - * @throws EE_Error |
|
322 | - */ |
|
323 | - public function column_ATT_address(EE_Attendee $attendee) |
|
324 | - { |
|
325 | - return $attendee->address(); |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * ATT_city column |
|
331 | - * |
|
332 | - * @param EE_Attendee $attendee |
|
333 | - * @return mixed |
|
334 | - * @throws EE_Error |
|
335 | - */ |
|
336 | - public function column_ATT_city(EE_Attendee $attendee) |
|
337 | - { |
|
338 | - return $attendee->city(); |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * State Column |
|
344 | - * |
|
345 | - * @param EE_Attendee $attendee |
|
346 | - * @return string |
|
347 | - * @throws EE_Error |
|
348 | - * @throws InvalidArgumentException |
|
349 | - * @throws InvalidDataTypeException |
|
350 | - * @throws InvalidInterfaceException |
|
351 | - */ |
|
352 | - public function column_STA_ID(EE_Attendee $attendee) |
|
353 | - { |
|
354 | - $states = EEM_State::instance()->get_all_states(); |
|
355 | - $state = isset($states[ $attendee->state_ID() ]) |
|
356 | - ? $states[ $attendee->state_ID() ]->get('STA_name') |
|
357 | - : $attendee->state_ID(); |
|
358 | - return ! is_numeric($state) ? $state : ''; |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * Country Column |
|
364 | - * |
|
365 | - * @param EE_Attendee $attendee |
|
366 | - * @return string |
|
367 | - * @throws EE_Error |
|
368 | - * @throws InvalidArgumentException |
|
369 | - * @throws InvalidDataTypeException |
|
370 | - * @throws InvalidInterfaceException |
|
371 | - */ |
|
372 | - public function column_CNT_ISO(EE_Attendee $attendee) |
|
373 | - { |
|
374 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
375 | - $country = isset($countries[ $attendee->country_ID() ]) |
|
376 | - ? $countries[ $attendee->country_ID() ]->get('CNT_name') |
|
377 | - : $attendee->country_ID(); |
|
378 | - return ! is_numeric($country) ? $country : ''; |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * Phone Number column |
|
384 | - * |
|
385 | - * @param EE_Attendee $attendee |
|
386 | - * @return mixed |
|
387 | - * @throws EE_Error |
|
388 | - */ |
|
389 | - public function column_ATT_phone(EE_Attendee $attendee) |
|
390 | - { |
|
391 | - return $attendee->phone(); |
|
392 | - } |
|
15 | + /** |
|
16 | + * Initial setup of data (called by parent). |
|
17 | + */ |
|
18 | + protected function _setup_data() |
|
19 | + { |
|
20 | + $this->_data = $this->_view !== 'trash' |
|
21 | + ? $this->_admin_page->get_attendees($this->_per_page) |
|
22 | + : $this->_admin_page->get_attendees($this->_per_page, false, true); |
|
23 | + $this->_all_data_count = $this->_view !== 'trash' |
|
24 | + ? $this->_admin_page->get_attendees($this->_per_page, true) |
|
25 | + : $this->_admin_page->get_attendees($this->_per_page, true, true); |
|
26 | + } |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * Initial setup of properties. |
|
31 | + */ |
|
32 | + protected function _set_properties() |
|
33 | + { |
|
34 | + $this->_wp_list_args = array( |
|
35 | + 'singular' => esc_html__('attendee', 'event_espresso'), |
|
36 | + 'plural' => esc_html__('attendees', 'event_espresso'), |
|
37 | + 'ajax' => true, |
|
38 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
39 | + ); |
|
40 | + |
|
41 | + $this->_columns = array( |
|
42 | + 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
43 | + 'ATT_ID' => esc_html__('ID', 'event_espresso'), |
|
44 | + 'ATT_fname' => esc_html__('First Name', 'event_espresso'), |
|
45 | + 'ATT_lname' => esc_html__('Last Name', 'event_espresso'), |
|
46 | + 'ATT_email' => esc_html__('Email Address', 'event_espresso'), |
|
47 | + 'Registration_Count' => esc_html__('# Registrations', 'event_espresso'), |
|
48 | + 'ATT_phone' => esc_html__('Phone', 'event_espresso'), |
|
49 | + 'ATT_address' => esc_html__('Address', 'event_espresso'), |
|
50 | + 'ATT_city' => esc_html__('City', 'event_espresso'), |
|
51 | + 'STA_ID' => esc_html__('State/Province', 'event_espresso'), |
|
52 | + 'CNT_ISO' => esc_html__('Country', 'event_espresso'), |
|
53 | + ); |
|
54 | + |
|
55 | + $this->_sortable_columns = array( |
|
56 | + 'ATT_ID' => array('ATT_ID' => false), |
|
57 | + 'ATT_lname' => array('ATT_lname' => true), // true means its already sorted |
|
58 | + 'ATT_fname' => array('ATT_fname' => false), |
|
59 | + 'ATT_email' => array('ATT_email' => false), |
|
60 | + 'Registration_Count' => array('Registration_Count' => false), |
|
61 | + 'ATT_city' => array('ATT_city' => false), |
|
62 | + 'STA_ID' => array('STA_ID' => false), |
|
63 | + 'CNT_ISO' => array('CNT_ISO' => false), |
|
64 | + ); |
|
65 | + |
|
66 | + $this->_hidden_columns = array( |
|
67 | + 'ATT_phone', |
|
68 | + 'ATT_address', |
|
69 | + 'ATT_city', |
|
70 | + 'STA_ID', |
|
71 | + 'CNT_ISO', |
|
72 | + ); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * Initial setup of filters |
|
78 | + * |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + protected function _get_table_filters() |
|
82 | + { |
|
83 | + return array(); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * Initial setup of counts for views |
|
89 | + * |
|
90 | + * @throws InvalidArgumentException |
|
91 | + * @throws InvalidDataTypeException |
|
92 | + * @throws InvalidInterfaceException |
|
93 | + */ |
|
94 | + protected function _add_view_counts() |
|
95 | + { |
|
96 | + $this->_views['in_use']['count'] = $this->_admin_page->get_attendees($this->_per_page, true); |
|
97 | + if ( |
|
98 | + EE_Registry::instance()->CAP->current_user_can( |
|
99 | + 'ee_delete_contacts', |
|
100 | + 'espresso_registrations_delete_registration' |
|
101 | + ) |
|
102 | + ) { |
|
103 | + $this->_views['trash']['count'] = $this->_admin_page->get_attendees($this->_per_page, true, true); |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Get count of attendees. |
|
110 | + * |
|
111 | + * @return int |
|
112 | + * @throws EE_Error |
|
113 | + * @throws InvalidArgumentException |
|
114 | + * @throws InvalidDataTypeException |
|
115 | + * @throws InvalidInterfaceException |
|
116 | + */ |
|
117 | + protected function _get_attendees_count() |
|
118 | + { |
|
119 | + return EEM_Attendee::instance()->count(); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * Checkbox column |
|
125 | + * |
|
126 | + * @param EE_Attendee $attendee Unable to typehint this method because overrides parent. |
|
127 | + * @return string |
|
128 | + * @throws EE_Error |
|
129 | + */ |
|
130 | + public function column_cb($attendee) |
|
131 | + { |
|
132 | + if (! $attendee instanceof EE_Attendee) { |
|
133 | + return ''; |
|
134 | + } |
|
135 | + return sprintf( |
|
136 | + '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', |
|
137 | + $attendee->ID() |
|
138 | + ); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * ATT_ID column |
|
144 | + * |
|
145 | + * @param EE_Attendee $attendee |
|
146 | + * @return string |
|
147 | + * @throws EE_Error |
|
148 | + */ |
|
149 | + public function column_ATT_ID(EE_Attendee $attendee) |
|
150 | + { |
|
151 | + $content = $attendee->ID(); |
|
152 | + $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
153 | + $content .= ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
154 | + return $content; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * ATT_lname column |
|
160 | + * |
|
161 | + * @param EE_Attendee $attendee |
|
162 | + * @return string |
|
163 | + * @throws InvalidArgumentException |
|
164 | + * @throws InvalidDataTypeException |
|
165 | + * @throws InvalidInterfaceException |
|
166 | + * @throws EE_Error |
|
167 | + */ |
|
168 | + public function column_ATT_lname(EE_Attendee $attendee) |
|
169 | + { |
|
170 | + // edit attendee link |
|
171 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
172 | + array( |
|
173 | + 'action' => 'edit_attendee', |
|
174 | + 'post' => $attendee->ID(), |
|
175 | + ), |
|
176 | + REG_ADMIN_URL |
|
177 | + ); |
|
178 | + $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
179 | + 'ee_edit_contacts', |
|
180 | + 'espresso_registrations_edit_attendee' |
|
181 | + ) |
|
182 | + ? '<a href="' . $edit_lnk_url . '" title="' |
|
183 | + . esc_attr__('Edit Contact', 'event_espresso') . '">' |
|
184 | + . $attendee->lname() . '</a>' |
|
185 | + : $attendee->lname(); |
|
186 | + return $name_link; |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * ATT_fname column |
|
192 | + * |
|
193 | + * @param EE_Attendee $attendee |
|
194 | + * @return string |
|
195 | + * @throws InvalidArgumentException |
|
196 | + * @throws InvalidDataTypeException |
|
197 | + * @throws InvalidInterfaceException |
|
198 | + * @throws EE_Error |
|
199 | + */ |
|
200 | + public function column_ATT_fname(EE_Attendee $attendee) |
|
201 | + { |
|
202 | + // Build row actions |
|
203 | + $actions = array(); |
|
204 | + // edit attendee link |
|
205 | + if ( |
|
206 | + EE_Registry::instance()->CAP->current_user_can( |
|
207 | + 'ee_edit_contacts', |
|
208 | + 'espresso_registrations_edit_attendee' |
|
209 | + ) |
|
210 | + ) { |
|
211 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
212 | + array( |
|
213 | + 'action' => 'edit_attendee', |
|
214 | + 'post' => $attendee->ID(), |
|
215 | + ), |
|
216 | + REG_ADMIN_URL |
|
217 | + ); |
|
218 | + $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="' |
|
219 | + . esc_attr__('Edit Contact', 'event_espresso') . '">' |
|
220 | + . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
221 | + } |
|
222 | + |
|
223 | + if ($this->_view === 'in_use') { |
|
224 | + // trash attendee link |
|
225 | + if ( |
|
226 | + EE_Registry::instance()->CAP->current_user_can( |
|
227 | + 'ee_delete_contacts', |
|
228 | + 'espresso_registrations_trash_attendees' |
|
229 | + ) |
|
230 | + ) { |
|
231 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
232 | + array( |
|
233 | + 'action' => 'trash_attendee', |
|
234 | + 'ATT_ID' => $attendee->ID(), |
|
235 | + ), |
|
236 | + REG_ADMIN_URL |
|
237 | + ); |
|
238 | + $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
239 | + . esc_attr__('Move Contact to Trash', 'event_espresso') |
|
240 | + . '">' . esc_html__('Trash', 'event_espresso') . '</a>'; |
|
241 | + } |
|
242 | + } else { |
|
243 | + if ( |
|
244 | + EE_Registry::instance()->CAP->current_user_can( |
|
245 | + 'ee_delete_contacts', |
|
246 | + 'espresso_registrations_restore_attendees' |
|
247 | + ) |
|
248 | + ) { |
|
249 | + // restore attendee link |
|
250 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
251 | + array( |
|
252 | + 'action' => 'restore_attendees', |
|
253 | + 'ATT_ID' => $attendee->ID(), |
|
254 | + ), |
|
255 | + REG_ADMIN_URL |
|
256 | + ); |
|
257 | + $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
258 | + . esc_attr__('Restore Contact', 'event_espresso') . '">' |
|
259 | + . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
260 | + } |
|
261 | + } |
|
262 | + |
|
263 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
264 | + array( |
|
265 | + 'action' => 'edit_attendee', |
|
266 | + 'post' => $attendee->ID(), |
|
267 | + ), |
|
268 | + REG_ADMIN_URL |
|
269 | + ); |
|
270 | + $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
271 | + 'ee_edit_contacts', |
|
272 | + 'espresso_registrations_edit_attendee' |
|
273 | + ) |
|
274 | + ? '<a href="' . $edit_lnk_url . '" title="' |
|
275 | + . esc_attr__('Edit Contact', 'event_espresso') . '">' . $attendee->fname() . '</a>' |
|
276 | + : $attendee->fname(); |
|
277 | + |
|
278 | + // Return the name contents |
|
279 | + return sprintf('%1$s %2$s', $name_link, $this->row_actions($actions)); |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * Email Column |
|
285 | + * |
|
286 | + * @param EE_Attendee $attendee |
|
287 | + * @return string |
|
288 | + * @throws EE_Error |
|
289 | + */ |
|
290 | + public function column_ATT_email(EE_Attendee $attendee) |
|
291 | + { |
|
292 | + return '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>'; |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * Column displaying count of registrations attached to Attendee. |
|
298 | + * |
|
299 | + * @param EE_Attendee $attendee |
|
300 | + * @return string |
|
301 | + * @throws EE_Error |
|
302 | + */ |
|
303 | + public function column_Registration_Count(EE_Attendee $attendee) |
|
304 | + { |
|
305 | + $link = EEH_URL::add_query_args_and_nonce( |
|
306 | + array( |
|
307 | + 'action' => 'default', |
|
308 | + 'ATT_ID' => $attendee->ID(), |
|
309 | + ), |
|
310 | + REG_ADMIN_URL |
|
311 | + ); |
|
312 | + return '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>'; |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * ATT_address column |
|
318 | + * |
|
319 | + * @param EE_Attendee $attendee |
|
320 | + * @return mixed |
|
321 | + * @throws EE_Error |
|
322 | + */ |
|
323 | + public function column_ATT_address(EE_Attendee $attendee) |
|
324 | + { |
|
325 | + return $attendee->address(); |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * ATT_city column |
|
331 | + * |
|
332 | + * @param EE_Attendee $attendee |
|
333 | + * @return mixed |
|
334 | + * @throws EE_Error |
|
335 | + */ |
|
336 | + public function column_ATT_city(EE_Attendee $attendee) |
|
337 | + { |
|
338 | + return $attendee->city(); |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * State Column |
|
344 | + * |
|
345 | + * @param EE_Attendee $attendee |
|
346 | + * @return string |
|
347 | + * @throws EE_Error |
|
348 | + * @throws InvalidArgumentException |
|
349 | + * @throws InvalidDataTypeException |
|
350 | + * @throws InvalidInterfaceException |
|
351 | + */ |
|
352 | + public function column_STA_ID(EE_Attendee $attendee) |
|
353 | + { |
|
354 | + $states = EEM_State::instance()->get_all_states(); |
|
355 | + $state = isset($states[ $attendee->state_ID() ]) |
|
356 | + ? $states[ $attendee->state_ID() ]->get('STA_name') |
|
357 | + : $attendee->state_ID(); |
|
358 | + return ! is_numeric($state) ? $state : ''; |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * Country Column |
|
364 | + * |
|
365 | + * @param EE_Attendee $attendee |
|
366 | + * @return string |
|
367 | + * @throws EE_Error |
|
368 | + * @throws InvalidArgumentException |
|
369 | + * @throws InvalidDataTypeException |
|
370 | + * @throws InvalidInterfaceException |
|
371 | + */ |
|
372 | + public function column_CNT_ISO(EE_Attendee $attendee) |
|
373 | + { |
|
374 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
375 | + $country = isset($countries[ $attendee->country_ID() ]) |
|
376 | + ? $countries[ $attendee->country_ID() ]->get('CNT_name') |
|
377 | + : $attendee->country_ID(); |
|
378 | + return ! is_numeric($country) ? $country : ''; |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * Phone Number column |
|
384 | + * |
|
385 | + * @param EE_Attendee $attendee |
|
386 | + * @return mixed |
|
387 | + * @throws EE_Error |
|
388 | + */ |
|
389 | + public function column_ATT_phone(EE_Attendee $attendee) |
|
390 | + { |
|
391 | + return $attendee->phone(); |
|
392 | + } |
|
393 | 393 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function column_cb($attendee) |
131 | 131 | { |
132 | - if (! $attendee instanceof EE_Attendee) { |
|
132 | + if ( ! $attendee instanceof EE_Attendee) { |
|
133 | 133 | return ''; |
134 | 134 | } |
135 | 135 | return sprintf( |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | { |
151 | 151 | $content = $attendee->ID(); |
152 | 152 | $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
153 | - $content .= ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
153 | + $content .= ' <span class="show-on-mobile-view-only">'.$attendee_name.'</span>'; |
|
154 | 154 | return $content; |
155 | 155 | } |
156 | 156 | |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | 'ee_edit_contacts', |
180 | 180 | 'espresso_registrations_edit_attendee' |
181 | 181 | ) |
182 | - ? '<a href="' . $edit_lnk_url . '" title="' |
|
183 | - . esc_attr__('Edit Contact', 'event_espresso') . '">' |
|
184 | - . $attendee->lname() . '</a>' |
|
182 | + ? '<a href="'.$edit_lnk_url.'" title="' |
|
183 | + . esc_attr__('Edit Contact', 'event_espresso').'">' |
|
184 | + . $attendee->lname().'</a>' |
|
185 | 185 | : $attendee->lname(); |
186 | 186 | return $name_link; |
187 | 187 | } |
@@ -215,9 +215,9 @@ discard block |
||
215 | 215 | ), |
216 | 216 | REG_ADMIN_URL |
217 | 217 | ); |
218 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="' |
|
219 | - . esc_attr__('Edit Contact', 'event_espresso') . '">' |
|
220 | - . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
218 | + $actions['edit'] = '<a href="'.$edit_lnk_url.'" title="' |
|
219 | + . esc_attr__('Edit Contact', 'event_espresso').'">' |
|
220 | + . esc_html__('Edit', 'event_espresso').'</a>'; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | if ($this->_view === 'in_use') { |
@@ -235,9 +235,9 @@ discard block |
||
235 | 235 | ), |
236 | 236 | REG_ADMIN_URL |
237 | 237 | ); |
238 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
238 | + $actions['trash'] = '<a href="'.$trash_lnk_url.'" title="' |
|
239 | 239 | . esc_attr__('Move Contact to Trash', 'event_espresso') |
240 | - . '">' . esc_html__('Trash', 'event_espresso') . '</a>'; |
|
240 | + . '">'.esc_html__('Trash', 'event_espresso').'</a>'; |
|
241 | 241 | } |
242 | 242 | } else { |
243 | 243 | if ( |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | ), |
255 | 255 | REG_ADMIN_URL |
256 | 256 | ); |
257 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
258 | - . esc_attr__('Restore Contact', 'event_espresso') . '">' |
|
259 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
257 | + $actions['restore'] = '<a href="'.$restore_lnk_url.'" title="' |
|
258 | + . esc_attr__('Restore Contact', 'event_espresso').'">' |
|
259 | + . esc_html__('Restore', 'event_espresso').'</a>'; |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
@@ -271,8 +271,8 @@ discard block |
||
271 | 271 | 'ee_edit_contacts', |
272 | 272 | 'espresso_registrations_edit_attendee' |
273 | 273 | ) |
274 | - ? '<a href="' . $edit_lnk_url . '" title="' |
|
275 | - . esc_attr__('Edit Contact', 'event_espresso') . '">' . $attendee->fname() . '</a>' |
|
274 | + ? '<a href="'.$edit_lnk_url.'" title="' |
|
275 | + . esc_attr__('Edit Contact', 'event_espresso').'">'.$attendee->fname().'</a>' |
|
276 | 276 | : $attendee->fname(); |
277 | 277 | |
278 | 278 | // Return the name contents |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | */ |
290 | 290 | public function column_ATT_email(EE_Attendee $attendee) |
291 | 291 | { |
292 | - return '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>'; |
|
292 | + return '<a href="mailto:'.$attendee->email().'">'.$attendee->email().'</a>'; |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | ), |
310 | 310 | REG_ADMIN_URL |
311 | 311 | ); |
312 | - return '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>'; |
|
312 | + return '<a href="'.$link.'">'.$attendee->getCustomSelect('Registration_Count').'</a>'; |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | |
@@ -352,8 +352,8 @@ discard block |
||
352 | 352 | public function column_STA_ID(EE_Attendee $attendee) |
353 | 353 | { |
354 | 354 | $states = EEM_State::instance()->get_all_states(); |
355 | - $state = isset($states[ $attendee->state_ID() ]) |
|
356 | - ? $states[ $attendee->state_ID() ]->get('STA_name') |
|
355 | + $state = isset($states[$attendee->state_ID()]) |
|
356 | + ? $states[$attendee->state_ID()]->get('STA_name') |
|
357 | 357 | : $attendee->state_ID(); |
358 | 358 | return ! is_numeric($state) ? $state : ''; |
359 | 359 | } |
@@ -372,8 +372,8 @@ discard block |
||
372 | 372 | public function column_CNT_ISO(EE_Attendee $attendee) |
373 | 373 | { |
374 | 374 | $countries = EEM_Country::instance()->get_all_countries(); |
375 | - $country = isset($countries[ $attendee->country_ID() ]) |
|
376 | - ? $countries[ $attendee->country_ID() ]->get('CNT_name') |
|
375 | + $country = isset($countries[$attendee->country_ID()]) |
|
376 | + ? $countries[$attendee->country_ID()]->get('CNT_name') |
|
377 | 377 | : $attendee->country_ID(); |
378 | 378 | return ! is_numeric($country) ? $country : ''; |
379 | 379 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | public static function new_instance($props_n_values = [], $timezone = null, $date_formats = []) |
22 | 22 | { |
23 | 23 | $price = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
24 | - if (! $price instanceof EE_Price) { |
|
24 | + if ( ! $price instanceof EE_Price) { |
|
25 | 25 | $price = new EE_Price($props_n_values, false, $timezone, $date_formats); |
26 | 26 | } |
27 | 27 | return $price; |
@@ -9,346 +9,346 @@ |
||
9 | 9 | */ |
10 | 10 | class EE_Price extends EE_Soft_Delete_Base_Class |
11 | 11 | { |
12 | - /** |
|
13 | - * @param array $props_n_values incoming values |
|
14 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be used.) |
|
15 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
16 | - * date_format and the second value is the time format |
|
17 | - * @return EE_Price |
|
18 | - * @throws EE_Error|ReflectionException |
|
19 | - */ |
|
20 | - public static function new_instance($props_n_values = [], $timezone = null, $date_formats = []) |
|
21 | - { |
|
22 | - $price = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
23 | - if (! $price instanceof EE_Price) { |
|
24 | - $price = new EE_Price($props_n_values, false, $timezone, $date_formats); |
|
25 | - } |
|
26 | - return $price; |
|
27 | - } |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @param array $props_n_values incoming values from the database |
|
32 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
33 | - * the website will be used. |
|
34 | - * @return EE_Price |
|
35 | - * @throws EE_Error|ReflectionException |
|
36 | - */ |
|
37 | - public static function new_instance_from_db($props_n_values = [], $timezone = null) |
|
38 | - { |
|
39 | - return new self($props_n_values, true, $timezone); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * Adds some defaults if they're not specified |
|
45 | - * |
|
46 | - * @param array $props_n_values |
|
47 | - * @param bool $bydb |
|
48 | - * @param string $timezone |
|
49 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
50 | - * date_format and the second value is the time format |
|
51 | - * @throws EE_Error |
|
52 | - * @throws ReflectionException |
|
53 | - */ |
|
54 | - protected function __construct($props_n_values = [], $bydb = false, $timezone = '', $date_formats = []) |
|
55 | - { |
|
56 | - parent::__construct($props_n_values, $bydb, $timezone, $date_formats); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Set Price type ID |
|
62 | - * |
|
63 | - * @param int $PRT_ID |
|
64 | - * @throws EE_Error |
|
65 | - * @throws ReflectionException |
|
66 | - */ |
|
67 | - public function set_type($PRT_ID = 0) |
|
68 | - { |
|
69 | - $this->set('PRT_ID', $PRT_ID); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Set Price Amount |
|
75 | - * |
|
76 | - * @param float $amount |
|
77 | - * @throws EE_Error |
|
78 | - * @throws ReflectionException |
|
79 | - */ |
|
80 | - public function set_amount($amount = 0.00) |
|
81 | - { |
|
82 | - $this->set('PRC_amount', $amount); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Set Price Name |
|
88 | - * |
|
89 | - * @param string $PRC_name |
|
90 | - * @throws EE_Error |
|
91 | - * @throws ReflectionException |
|
92 | - */ |
|
93 | - public function set_name($PRC_name = '') |
|
94 | - { |
|
95 | - $this->set('PRC_name', $PRC_name); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Set Price Description |
|
101 | - * |
|
102 | - * @param string $PRC_desc |
|
103 | - * @throws EE_Error |
|
104 | - * @throws ReflectionException |
|
105 | - */ |
|
106 | - public function set_description($PRC_desc = '') |
|
107 | - { |
|
108 | - $this->Set('PRC_desc', $PRC_desc); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * set is_default |
|
114 | - * |
|
115 | - * @param bool $PRC_is_default |
|
116 | - * @throws EE_Error |
|
117 | - * @throws ReflectionException |
|
118 | - */ |
|
119 | - public function set_is_default($PRC_is_default = false) |
|
120 | - { |
|
121 | - $this->set('PRC_is_default', $PRC_is_default); |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * set deleted |
|
127 | - * |
|
128 | - * @param bool $PRC_deleted |
|
129 | - * @throws EE_Error |
|
130 | - * @throws ReflectionException |
|
131 | - */ |
|
132 | - public function set_deleted($PRC_deleted = null) |
|
133 | - { |
|
134 | - $this->set('PRC_deleted', $PRC_deleted); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * get Price type |
|
140 | - * |
|
141 | - * @return int |
|
142 | - * @throws EE_Error |
|
143 | - * @throws ReflectionException |
|
144 | - */ |
|
145 | - public function type() |
|
146 | - { |
|
147 | - return $this->get('PRT_ID'); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * get Price Amount |
|
153 | - * |
|
154 | - * @return float |
|
155 | - * @throws EE_Error |
|
156 | - * @throws ReflectionException |
|
157 | - */ |
|
158 | - public function amount() |
|
159 | - { |
|
160 | - return $this->get('PRC_amount'); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * get Price Name |
|
166 | - * |
|
167 | - * @return string |
|
168 | - * @throws EE_Error |
|
169 | - * @throws ReflectionException |
|
170 | - */ |
|
171 | - public function name() |
|
172 | - { |
|
173 | - return $this->get('PRC_name'); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * get Price description |
|
179 | - * |
|
180 | - * @return string |
|
181 | - * @throws EE_Error |
|
182 | - * @throws ReflectionException |
|
183 | - */ |
|
184 | - public function desc() |
|
185 | - { |
|
186 | - return $this->get('PRC_desc'); |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * get overrides |
|
192 | - * |
|
193 | - * @return int |
|
194 | - * @throws EE_Error |
|
195 | - * @throws ReflectionException |
|
196 | - */ |
|
197 | - public function overrides() |
|
198 | - { |
|
199 | - return $this->get('PRC_overrides'); |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * get order |
|
205 | - * |
|
206 | - * @return int |
|
207 | - * @throws EE_Error |
|
208 | - * @throws ReflectionException |
|
209 | - */ |
|
210 | - public function order() |
|
211 | - { |
|
212 | - return $this->get('PRC_order'); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * get the author of the price |
|
218 | - * |
|
219 | - * @return int |
|
220 | - * @throws EE_Error |
|
221 | - * @throws ReflectionException |
|
222 | - * @since 4.5.0 |
|
223 | - * |
|
224 | - */ |
|
225 | - public function wp_user() |
|
226 | - { |
|
227 | - return $this->get('PRC_wp_user'); |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * get is_default |
|
233 | - * |
|
234 | - * @return bool |
|
235 | - * @throws EE_Error |
|
236 | - * @throws ReflectionException |
|
237 | - */ |
|
238 | - public function is_default() |
|
239 | - { |
|
240 | - return $this->get('PRC_is_default'); |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * get deleted |
|
246 | - * |
|
247 | - * @return bool |
|
248 | - * @throws EE_Error |
|
249 | - * @throws ReflectionException |
|
250 | - */ |
|
251 | - public function deleted() |
|
252 | - { |
|
253 | - return $this->get('PRC_deleted'); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * @return bool |
|
259 | - * @throws EE_Error |
|
260 | - * @throws ReflectionException |
|
261 | - */ |
|
262 | - public function parent() |
|
263 | - { |
|
264 | - return $this->get('PRC_parent'); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - // some helper methods for getting info on the price_type for this price |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * return whether the price is a base price or not |
|
273 | - * |
|
274 | - * @return boolean |
|
275 | - * @throws EE_Error |
|
276 | - * @throws ReflectionException |
|
277 | - */ |
|
278 | - public function is_base_price() |
|
279 | - { |
|
280 | - $price_type = $this->type_obj(); |
|
281 | - return $price_type->base_type() === 1; |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * |
|
287 | - * @return EE_Base_Class|EE_Price_Type |
|
288 | - * @throws EE_Error |
|
289 | - * @throws ReflectionException |
|
290 | - */ |
|
291 | - public function type_obj() |
|
292 | - { |
|
293 | - return $this->get_first_related('Price_Type'); |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * Simply indicates whether this price increases or decreases the total |
|
299 | - * |
|
300 | - * @return boolean true = discount, otherwise adds to the total |
|
301 | - * @throws EE_Error |
|
302 | - * @throws ReflectionException |
|
303 | - */ |
|
304 | - public function is_discount() |
|
305 | - { |
|
306 | - $price_type = $this->type_obj(); |
|
307 | - return $price_type->is_discount(); |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * whether the price is a percentage or not |
|
313 | - * |
|
314 | - * @return boolean |
|
315 | - * @throws EE_Error |
|
316 | - * @throws ReflectionException |
|
317 | - */ |
|
318 | - public function is_percent() |
|
319 | - { |
|
320 | - $price_type = $this->type_obj(); |
|
321 | - return $price_type->get('PRT_is_percent'); |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * return pretty price dependant on whether its a dollar or percent. |
|
327 | - * |
|
328 | - * @return string |
|
329 | - * @throws EE_Error |
|
330 | - * @throws ReflectionException |
|
331 | - * @since 4.4.0 |
|
332 | - * |
|
333 | - */ |
|
334 | - public function pretty_price() |
|
335 | - { |
|
336 | - return $this->is_percent() |
|
337 | - ? apply_filters( |
|
338 | - 'FHEE__format_percentage_value', |
|
339 | - $this->get_pretty('PRC_amount', 'localized_float') |
|
340 | - ) |
|
341 | - : $this->get_pretty('PRC_amount', 'localized_currency'); |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * @return mixed |
|
347 | - * @throws EE_Error |
|
348 | - * @throws ReflectionException |
|
349 | - */ |
|
350 | - public function get_price_without_currency_symbol() |
|
351 | - { |
|
352 | - return $this->get_pretty('PRC_amount', 'localized_float'); |
|
353 | - } |
|
12 | + /** |
|
13 | + * @param array $props_n_values incoming values |
|
14 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be used.) |
|
15 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
16 | + * date_format and the second value is the time format |
|
17 | + * @return EE_Price |
|
18 | + * @throws EE_Error|ReflectionException |
|
19 | + */ |
|
20 | + public static function new_instance($props_n_values = [], $timezone = null, $date_formats = []) |
|
21 | + { |
|
22 | + $price = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
23 | + if (! $price instanceof EE_Price) { |
|
24 | + $price = new EE_Price($props_n_values, false, $timezone, $date_formats); |
|
25 | + } |
|
26 | + return $price; |
|
27 | + } |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @param array $props_n_values incoming values from the database |
|
32 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
33 | + * the website will be used. |
|
34 | + * @return EE_Price |
|
35 | + * @throws EE_Error|ReflectionException |
|
36 | + */ |
|
37 | + public static function new_instance_from_db($props_n_values = [], $timezone = null) |
|
38 | + { |
|
39 | + return new self($props_n_values, true, $timezone); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * Adds some defaults if they're not specified |
|
45 | + * |
|
46 | + * @param array $props_n_values |
|
47 | + * @param bool $bydb |
|
48 | + * @param string $timezone |
|
49 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
50 | + * date_format and the second value is the time format |
|
51 | + * @throws EE_Error |
|
52 | + * @throws ReflectionException |
|
53 | + */ |
|
54 | + protected function __construct($props_n_values = [], $bydb = false, $timezone = '', $date_formats = []) |
|
55 | + { |
|
56 | + parent::__construct($props_n_values, $bydb, $timezone, $date_formats); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Set Price type ID |
|
62 | + * |
|
63 | + * @param int $PRT_ID |
|
64 | + * @throws EE_Error |
|
65 | + * @throws ReflectionException |
|
66 | + */ |
|
67 | + public function set_type($PRT_ID = 0) |
|
68 | + { |
|
69 | + $this->set('PRT_ID', $PRT_ID); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Set Price Amount |
|
75 | + * |
|
76 | + * @param float $amount |
|
77 | + * @throws EE_Error |
|
78 | + * @throws ReflectionException |
|
79 | + */ |
|
80 | + public function set_amount($amount = 0.00) |
|
81 | + { |
|
82 | + $this->set('PRC_amount', $amount); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Set Price Name |
|
88 | + * |
|
89 | + * @param string $PRC_name |
|
90 | + * @throws EE_Error |
|
91 | + * @throws ReflectionException |
|
92 | + */ |
|
93 | + public function set_name($PRC_name = '') |
|
94 | + { |
|
95 | + $this->set('PRC_name', $PRC_name); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Set Price Description |
|
101 | + * |
|
102 | + * @param string $PRC_desc |
|
103 | + * @throws EE_Error |
|
104 | + * @throws ReflectionException |
|
105 | + */ |
|
106 | + public function set_description($PRC_desc = '') |
|
107 | + { |
|
108 | + $this->Set('PRC_desc', $PRC_desc); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * set is_default |
|
114 | + * |
|
115 | + * @param bool $PRC_is_default |
|
116 | + * @throws EE_Error |
|
117 | + * @throws ReflectionException |
|
118 | + */ |
|
119 | + public function set_is_default($PRC_is_default = false) |
|
120 | + { |
|
121 | + $this->set('PRC_is_default', $PRC_is_default); |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * set deleted |
|
127 | + * |
|
128 | + * @param bool $PRC_deleted |
|
129 | + * @throws EE_Error |
|
130 | + * @throws ReflectionException |
|
131 | + */ |
|
132 | + public function set_deleted($PRC_deleted = null) |
|
133 | + { |
|
134 | + $this->set('PRC_deleted', $PRC_deleted); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * get Price type |
|
140 | + * |
|
141 | + * @return int |
|
142 | + * @throws EE_Error |
|
143 | + * @throws ReflectionException |
|
144 | + */ |
|
145 | + public function type() |
|
146 | + { |
|
147 | + return $this->get('PRT_ID'); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * get Price Amount |
|
153 | + * |
|
154 | + * @return float |
|
155 | + * @throws EE_Error |
|
156 | + * @throws ReflectionException |
|
157 | + */ |
|
158 | + public function amount() |
|
159 | + { |
|
160 | + return $this->get('PRC_amount'); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * get Price Name |
|
166 | + * |
|
167 | + * @return string |
|
168 | + * @throws EE_Error |
|
169 | + * @throws ReflectionException |
|
170 | + */ |
|
171 | + public function name() |
|
172 | + { |
|
173 | + return $this->get('PRC_name'); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * get Price description |
|
179 | + * |
|
180 | + * @return string |
|
181 | + * @throws EE_Error |
|
182 | + * @throws ReflectionException |
|
183 | + */ |
|
184 | + public function desc() |
|
185 | + { |
|
186 | + return $this->get('PRC_desc'); |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * get overrides |
|
192 | + * |
|
193 | + * @return int |
|
194 | + * @throws EE_Error |
|
195 | + * @throws ReflectionException |
|
196 | + */ |
|
197 | + public function overrides() |
|
198 | + { |
|
199 | + return $this->get('PRC_overrides'); |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * get order |
|
205 | + * |
|
206 | + * @return int |
|
207 | + * @throws EE_Error |
|
208 | + * @throws ReflectionException |
|
209 | + */ |
|
210 | + public function order() |
|
211 | + { |
|
212 | + return $this->get('PRC_order'); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * get the author of the price |
|
218 | + * |
|
219 | + * @return int |
|
220 | + * @throws EE_Error |
|
221 | + * @throws ReflectionException |
|
222 | + * @since 4.5.0 |
|
223 | + * |
|
224 | + */ |
|
225 | + public function wp_user() |
|
226 | + { |
|
227 | + return $this->get('PRC_wp_user'); |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * get is_default |
|
233 | + * |
|
234 | + * @return bool |
|
235 | + * @throws EE_Error |
|
236 | + * @throws ReflectionException |
|
237 | + */ |
|
238 | + public function is_default() |
|
239 | + { |
|
240 | + return $this->get('PRC_is_default'); |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * get deleted |
|
246 | + * |
|
247 | + * @return bool |
|
248 | + * @throws EE_Error |
|
249 | + * @throws ReflectionException |
|
250 | + */ |
|
251 | + public function deleted() |
|
252 | + { |
|
253 | + return $this->get('PRC_deleted'); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * @return bool |
|
259 | + * @throws EE_Error |
|
260 | + * @throws ReflectionException |
|
261 | + */ |
|
262 | + public function parent() |
|
263 | + { |
|
264 | + return $this->get('PRC_parent'); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + // some helper methods for getting info on the price_type for this price |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * return whether the price is a base price or not |
|
273 | + * |
|
274 | + * @return boolean |
|
275 | + * @throws EE_Error |
|
276 | + * @throws ReflectionException |
|
277 | + */ |
|
278 | + public function is_base_price() |
|
279 | + { |
|
280 | + $price_type = $this->type_obj(); |
|
281 | + return $price_type->base_type() === 1; |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * |
|
287 | + * @return EE_Base_Class|EE_Price_Type |
|
288 | + * @throws EE_Error |
|
289 | + * @throws ReflectionException |
|
290 | + */ |
|
291 | + public function type_obj() |
|
292 | + { |
|
293 | + return $this->get_first_related('Price_Type'); |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * Simply indicates whether this price increases or decreases the total |
|
299 | + * |
|
300 | + * @return boolean true = discount, otherwise adds to the total |
|
301 | + * @throws EE_Error |
|
302 | + * @throws ReflectionException |
|
303 | + */ |
|
304 | + public function is_discount() |
|
305 | + { |
|
306 | + $price_type = $this->type_obj(); |
|
307 | + return $price_type->is_discount(); |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * whether the price is a percentage or not |
|
313 | + * |
|
314 | + * @return boolean |
|
315 | + * @throws EE_Error |
|
316 | + * @throws ReflectionException |
|
317 | + */ |
|
318 | + public function is_percent() |
|
319 | + { |
|
320 | + $price_type = $this->type_obj(); |
|
321 | + return $price_type->get('PRT_is_percent'); |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * return pretty price dependant on whether its a dollar or percent. |
|
327 | + * |
|
328 | + * @return string |
|
329 | + * @throws EE_Error |
|
330 | + * @throws ReflectionException |
|
331 | + * @since 4.4.0 |
|
332 | + * |
|
333 | + */ |
|
334 | + public function pretty_price() |
|
335 | + { |
|
336 | + return $this->is_percent() |
|
337 | + ? apply_filters( |
|
338 | + 'FHEE__format_percentage_value', |
|
339 | + $this->get_pretty('PRC_amount', 'localized_float') |
|
340 | + ) |
|
341 | + : $this->get_pretty('PRC_amount', 'localized_currency'); |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * @return mixed |
|
347 | + * @throws EE_Error |
|
348 | + * @throws ReflectionException |
|
349 | + */ |
|
350 | + public function get_price_without_currency_symbol() |
|
351 | + { |
|
352 | + return $this->get_pretty('PRC_amount', 'localized_float'); |
|
353 | + } |
|
354 | 354 | } |
@@ -25,7 +25,7 @@ |
||
25 | 25 | public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
26 | 26 | { |
27 | 27 | $reg_payment = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
28 | - if (! $reg_payment instanceof EE_Registration_Payment) { |
|
28 | + if ( ! $reg_payment instanceof EE_Registration_Payment) { |
|
29 | 29 | $reg_payment = new EE_Registration_Payment($props_n_values, false, $timezone, $date_formats); |
30 | 30 | } |
31 | 31 | return $reg_payment; |
@@ -11,142 +11,142 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Registration_Payment extends EE_Base_Class |
13 | 13 | { |
14 | - /** |
|
15 | - * |
|
16 | - * @param array $props_n_values incoming values |
|
17 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
18 | - * used.) |
|
19 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
20 | - * date_format and the second value is the time format |
|
21 | - * @return EE_Registration_Payment |
|
22 | - * @throws EE_Error|ReflectionException |
|
23 | - */ |
|
24 | - public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
25 | - { |
|
26 | - $reg_payment = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
27 | - if (! $reg_payment instanceof EE_Registration_Payment) { |
|
28 | - $reg_payment = new EE_Registration_Payment($props_n_values, false, $timezone, $date_formats); |
|
29 | - } |
|
30 | - return $reg_payment; |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @param array $props_n_values |
|
36 | - * @param string $timezone |
|
37 | - * @return EE_Registration_Payment |
|
38 | - * @throws EE_Error|ReflectionException |
|
39 | - */ |
|
40 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
41 | - { |
|
42 | - return new self($props_n_values, true, $timezone); |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * Adds some defaults if they're not specified |
|
48 | - * |
|
49 | - * @param array $props_n_values |
|
50 | - * @param bool $bydb |
|
51 | - * @param string $timezone |
|
52 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
53 | - * date_format and the second value is the time format |
|
54 | - * @throws EE_Error |
|
55 | - * @throws ReflectionException |
|
56 | - */ |
|
57 | - protected function __construct($props_n_values = [], $bydb = false, $timezone = '', $date_formats = []) |
|
58 | - { |
|
59 | - parent::__construct($props_n_values, $bydb, $timezone, $date_formats); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * registration_ID |
|
65 | - * |
|
66 | - * @return int |
|
67 | - * @throws EE_Error |
|
68 | - * @throws ReflectionException |
|
69 | - */ |
|
70 | - public function registration_ID() |
|
71 | - { |
|
72 | - return $this->get('REG_ID'); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * payment_ID |
|
78 | - * |
|
79 | - * @return int |
|
80 | - * @throws EE_Error |
|
81 | - * @throws ReflectionException |
|
82 | - */ |
|
83 | - public function payment_ID() |
|
84 | - { |
|
85 | - return $this->get('PAY_ID'); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * amount |
|
91 | - * |
|
92 | - * @return float |
|
93 | - * @throws EE_Error |
|
94 | - * @throws ReflectionException |
|
95 | - */ |
|
96 | - public function amount() |
|
97 | - { |
|
98 | - return $this->get('RPY_amount'); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * formatted amount |
|
104 | - * |
|
105 | - * @param string|null $schema |
|
106 | - * @return string |
|
107 | - * @throws EE_Error |
|
108 | - * @throws ReflectionException |
|
109 | - */ |
|
110 | - public function prettyAmount($schema = 'localized_currency') |
|
111 | - { |
|
112 | - return $this->get_pretty('RPY_amount', $schema); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * amount |
|
118 | - * |
|
119 | - * @param float $amount |
|
120 | - * @throws EE_Error|ReflectionException |
|
121 | - */ |
|
122 | - public function set_amount($amount = 0) |
|
123 | - { |
|
124 | - $this->set('RPY_amount', $amount); |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * registration |
|
130 | - * |
|
131 | - * @return EE_Base_Class|EE_Registration |
|
132 | - * @throws EE_Error |
|
133 | - * @throws ReflectionException |
|
134 | - */ |
|
135 | - public function registration() |
|
136 | - { |
|
137 | - return $this->get_first_related('Registration'); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * payment |
|
143 | - * |
|
144 | - * @return EE_Base_Class|EE_Payment |
|
145 | - * @throws EE_Error |
|
146 | - * @throws ReflectionException |
|
147 | - */ |
|
148 | - public function payment() |
|
149 | - { |
|
150 | - return $this->get_first_related('Payment'); |
|
151 | - } |
|
14 | + /** |
|
15 | + * |
|
16 | + * @param array $props_n_values incoming values |
|
17 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
18 | + * used.) |
|
19 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
20 | + * date_format and the second value is the time format |
|
21 | + * @return EE_Registration_Payment |
|
22 | + * @throws EE_Error|ReflectionException |
|
23 | + */ |
|
24 | + public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
25 | + { |
|
26 | + $reg_payment = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
27 | + if (! $reg_payment instanceof EE_Registration_Payment) { |
|
28 | + $reg_payment = new EE_Registration_Payment($props_n_values, false, $timezone, $date_formats); |
|
29 | + } |
|
30 | + return $reg_payment; |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @param array $props_n_values |
|
36 | + * @param string $timezone |
|
37 | + * @return EE_Registration_Payment |
|
38 | + * @throws EE_Error|ReflectionException |
|
39 | + */ |
|
40 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
41 | + { |
|
42 | + return new self($props_n_values, true, $timezone); |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * Adds some defaults if they're not specified |
|
48 | + * |
|
49 | + * @param array $props_n_values |
|
50 | + * @param bool $bydb |
|
51 | + * @param string $timezone |
|
52 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
53 | + * date_format and the second value is the time format |
|
54 | + * @throws EE_Error |
|
55 | + * @throws ReflectionException |
|
56 | + */ |
|
57 | + protected function __construct($props_n_values = [], $bydb = false, $timezone = '', $date_formats = []) |
|
58 | + { |
|
59 | + parent::__construct($props_n_values, $bydb, $timezone, $date_formats); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * registration_ID |
|
65 | + * |
|
66 | + * @return int |
|
67 | + * @throws EE_Error |
|
68 | + * @throws ReflectionException |
|
69 | + */ |
|
70 | + public function registration_ID() |
|
71 | + { |
|
72 | + return $this->get('REG_ID'); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * payment_ID |
|
78 | + * |
|
79 | + * @return int |
|
80 | + * @throws EE_Error |
|
81 | + * @throws ReflectionException |
|
82 | + */ |
|
83 | + public function payment_ID() |
|
84 | + { |
|
85 | + return $this->get('PAY_ID'); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * amount |
|
91 | + * |
|
92 | + * @return float |
|
93 | + * @throws EE_Error |
|
94 | + * @throws ReflectionException |
|
95 | + */ |
|
96 | + public function amount() |
|
97 | + { |
|
98 | + return $this->get('RPY_amount'); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * formatted amount |
|
104 | + * |
|
105 | + * @param string|null $schema |
|
106 | + * @return string |
|
107 | + * @throws EE_Error |
|
108 | + * @throws ReflectionException |
|
109 | + */ |
|
110 | + public function prettyAmount($schema = 'localized_currency') |
|
111 | + { |
|
112 | + return $this->get_pretty('RPY_amount', $schema); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * amount |
|
118 | + * |
|
119 | + * @param float $amount |
|
120 | + * @throws EE_Error|ReflectionException |
|
121 | + */ |
|
122 | + public function set_amount($amount = 0) |
|
123 | + { |
|
124 | + $this->set('RPY_amount', $amount); |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * registration |
|
130 | + * |
|
131 | + * @return EE_Base_Class|EE_Registration |
|
132 | + * @throws EE_Error |
|
133 | + * @throws ReflectionException |
|
134 | + */ |
|
135 | + public function registration() |
|
136 | + { |
|
137 | + return $this->get_first_related('Registration'); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * payment |
|
143 | + * |
|
144 | + * @return EE_Base_Class|EE_Payment |
|
145 | + * @throws EE_Error |
|
146 | + * @throws ReflectionException |
|
147 | + */ |
|
148 | + public function payment() |
|
149 | + { |
|
150 | + return $this->get_first_related('Payment'); |
|
151 | + } |
|
152 | 152 | } |
@@ -116,15 +116,15 @@ discard block |
||
116 | 116 | */ |
117 | 117 | protected function __construct($fieldValues = [], $bydb = false, $timezone = '', $date_formats = []) |
118 | 118 | { |
119 | - if (! $this->calculator instanceof LineItemCalculator) { |
|
119 | + if ( ! $this->calculator instanceof LineItemCalculator) { |
|
120 | 120 | $this->calculator = LoaderFactory::getLoader()->getShared(LineItemCalculator::class); |
121 | 121 | } |
122 | 122 | parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
123 | - if (! $this->get('LIN_code')) { |
|
123 | + if ( ! $this->get('LIN_code')) { |
|
124 | 124 | $this->set_code($this->generate_code()); |
125 | 125 | } |
126 | 126 | // in a better world this would have been injected upon construction |
127 | - if (! $this->currency_formatter instanceof CurrencyFormatter) { |
|
127 | + if ( ! $this->currency_formatter instanceof CurrencyFormatter) { |
|
128 | 128 | $this->currency_formatter = LoaderFactory::getLoader()->getShared(CurrencyFormatter::class); |
129 | 129 | } |
130 | 130 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | public function name() |
201 | 201 | { |
202 | 202 | $name = $this->get('LIN_name'); |
203 | - if (! $name) { |
|
203 | + if ( ! $name) { |
|
204 | 204 | $name = ucwords(str_replace('-', ' ', $this->type())); |
205 | 205 | } |
206 | 206 | return $name; |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | ] |
711 | 711 | ); |
712 | 712 | } |
713 | - if (! is_array($this->_children)) { |
|
713 | + if ( ! is_array($this->_children)) { |
|
714 | 714 | $this->_children = []; |
715 | 715 | } |
716 | 716 | return $this->_children; |
@@ -951,7 +951,7 @@ discard block |
||
951 | 951 | } |
952 | 952 | return $line_item->save(); |
953 | 953 | } |
954 | - $this->_children[ $line_item->code() ] = $line_item; |
|
954 | + $this->_children[$line_item->code()] = $line_item; |
|
955 | 955 | if ($line_item->parent() !== $this) { |
956 | 956 | $line_item->set_parent($this); |
957 | 957 | } |
@@ -975,7 +975,7 @@ discard block |
||
975 | 975 | public function set_parent($line_item) |
976 | 976 | { |
977 | 977 | if ($this->ID()) { |
978 | - if (! $line_item->ID()) { |
|
978 | + if ( ! $line_item->ID()) { |
|
979 | 979 | $line_item->save(); |
980 | 980 | } |
981 | 981 | $this->set_parent_ID($line_item->ID()); |
@@ -1007,8 +1007,8 @@ discard block |
||
1007 | 1007 | [['LIN_parent' => $this->ID(), 'LIN_code' => $code]] |
1008 | 1008 | ); |
1009 | 1009 | } |
1010 | - return isset($this->_children[ $code ]) |
|
1011 | - ? $this->_children[ $code ] |
|
1010 | + return isset($this->_children[$code]) |
|
1011 | + ? $this->_children[$code] |
|
1012 | 1012 | : null; |
1013 | 1013 | } |
1014 | 1014 | |
@@ -1068,8 +1068,8 @@ discard block |
||
1068 | 1068 | } |
1069 | 1069 | return $items_deleted; |
1070 | 1070 | } |
1071 | - if (isset($this->_children[ $code ])) { |
|
1072 | - unset($this->_children[ $code ]); |
|
1071 | + if (isset($this->_children[$code])) { |
|
1072 | + unset($this->_children[$code]); |
|
1073 | 1073 | return 1; |
1074 | 1074 | } |
1075 | 1075 | return 0; |
@@ -1111,7 +1111,7 @@ discard block |
||
1111 | 1111 | { |
1112 | 1112 | // each line item in the cart requires a unique identifier |
1113 | 1113 | // return md5($this->get('OBJ_type') . $this->get('OBJ_ID') . microtime()); |
1114 | - return $this->get('OBJ_type') . '-' . $this->get('OBJ_ID') . '-' . microtime(); |
|
1114 | + return $this->get('OBJ_type').'-'.$this->get('OBJ_ID').'-'.microtime(); |
|
1115 | 1115 | } |
1116 | 1116 | |
1117 | 1117 | |
@@ -1424,12 +1424,12 @@ discard block |
||
1424 | 1424 | public function save_this_and_descendants_to_txn($txn_id = null) |
1425 | 1425 | { |
1426 | 1426 | $count = 0; |
1427 | - if (! $txn_id) { |
|
1427 | + if ( ! $txn_id) { |
|
1428 | 1428 | $txn_id = $this->TXN_ID(); |
1429 | 1429 | } |
1430 | 1430 | $this->set_TXN_ID($txn_id); |
1431 | 1431 | $children = $this->children(); |
1432 | - $count += $this->save() |
|
1432 | + $count += $this->save() |
|
1433 | 1433 | ? 1 |
1434 | 1434 | : 0; |
1435 | 1435 | foreach ($children as $child_line_item) { |
@@ -1456,7 +1456,7 @@ discard block |
||
1456 | 1456 | { |
1457 | 1457 | $count = 0; |
1458 | 1458 | $children = $this->children(); |
1459 | - $count += $this->save() |
|
1459 | + $count += $this->save() |
|
1460 | 1460 | ? 1 |
1461 | 1461 | : 0; |
1462 | 1462 | foreach ($children as $child_line_item) { |
@@ -16,1568 +16,1568 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Line_Item extends EE_Base_Class implements EEI_Line_Item |
18 | 18 | { |
19 | - /** |
|
20 | - * @var CurrencyFormatter |
|
21 | - * @since $VID:$ |
|
22 | - */ |
|
23 | - protected $currency_formatter; |
|
24 | - |
|
25 | - /** |
|
26 | - * for children line items (currently not a normal relation) |
|
27 | - * |
|
28 | - * @type EE_Line_Item[] |
|
29 | - */ |
|
30 | - protected $_children = []; |
|
31 | - |
|
32 | - /** |
|
33 | - * for the parent line item |
|
34 | - * |
|
35 | - * @var EE_Line_Item |
|
36 | - */ |
|
37 | - protected $_parent; |
|
38 | - |
|
39 | - /** |
|
40 | - * number of decimal places to round numbers to when performing calculations |
|
41 | - * |
|
42 | - * @var integer $decimal_precision |
|
43 | - */ |
|
44 | - protected $decimal_precision = 6; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var LineItemCalculator |
|
48 | - */ |
|
49 | - private $calculator; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var bool |
|
53 | - */ |
|
54 | - private $is_percent; |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @param array $props_n_values incoming values |
|
61 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
62 | - * used.) |
|
63 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
64 | - * date_format and the second value is the time format |
|
65 | - * @return EE_Line_Item |
|
66 | - * @throws EE_Error |
|
67 | - * @throws InvalidArgumentException |
|
68 | - * @throws InvalidDataTypeException |
|
69 | - * @throws InvalidInterfaceException |
|
70 | - * @throws ReflectionException |
|
71 | - */ |
|
72 | - public static function new_instance($props_n_values = [], $timezone = null, $date_formats = []) |
|
73 | - { |
|
74 | - $has_object = parent::_check_for_object( |
|
75 | - $props_n_values, |
|
76 | - EE_Line_Item::class, |
|
77 | - $timezone, |
|
78 | - $date_formats |
|
79 | - ); |
|
80 | - return $has_object |
|
81 | - ? $has_object |
|
82 | - : new EE_Line_Item($props_n_values, false, $timezone, $date_formats); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @param array $props_n_values incoming values from the database |
|
88 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
89 | - * the website will be used. |
|
90 | - * @return EE_Line_Item |
|
91 | - * @throws EE_Error |
|
92 | - * @throws InvalidArgumentException |
|
93 | - * @throws InvalidDataTypeException |
|
94 | - * @throws InvalidInterfaceException |
|
95 | - * @throws ReflectionException |
|
96 | - */ |
|
97 | - public static function new_instance_from_db($props_n_values = [], $timezone = null) |
|
98 | - { |
|
99 | - return new EE_Line_Item($props_n_values, true, $timezone); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Adds some defaults if they're not specified |
|
105 | - * |
|
106 | - * @param array $fieldValues |
|
107 | - * @param bool $bydb |
|
108 | - * @param string $timezone |
|
109 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
110 | - * date_format and the second value is the time format |
|
111 | - * @throws EE_Error |
|
112 | - * @throws InvalidArgumentException |
|
113 | - * @throws InvalidDataTypeException |
|
114 | - * @throws InvalidInterfaceException |
|
115 | - * @throws ReflectionException |
|
116 | - */ |
|
117 | - protected function __construct($fieldValues = [], $bydb = false, $timezone = '', $date_formats = []) |
|
118 | - { |
|
119 | - if (! $this->calculator instanceof LineItemCalculator) { |
|
120 | - $this->calculator = LoaderFactory::getLoader()->getShared(LineItemCalculator::class); |
|
121 | - } |
|
122 | - parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
123 | - if (! $this->get('LIN_code')) { |
|
124 | - $this->set_code($this->generate_code()); |
|
125 | - } |
|
126 | - // in a better world this would have been injected upon construction |
|
127 | - if (! $this->currency_formatter instanceof CurrencyFormatter) { |
|
128 | - $this->currency_formatter = LoaderFactory::getLoader()->getShared(CurrencyFormatter::class); |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @param int $decimal_precision |
|
135 | - */ |
|
136 | - public function setDecimalPrecision($decimal_precision = 6) |
|
137 | - { |
|
138 | - $this->decimal_precision = absint($decimal_precision); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * Gets ID |
|
144 | - * |
|
145 | - * @return int |
|
146 | - * @throws EE_Error |
|
147 | - * @throws InvalidArgumentException |
|
148 | - * @throws InvalidDataTypeException |
|
149 | - * @throws InvalidInterfaceException |
|
150 | - * @throws ReflectionException |
|
151 | - */ |
|
152 | - public function ID() |
|
153 | - { |
|
154 | - return $this->get('LIN_ID'); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * Gets TXN_ID |
|
160 | - * |
|
161 | - * @return int |
|
162 | - * @throws EE_Error |
|
163 | - * @throws InvalidArgumentException |
|
164 | - * @throws InvalidDataTypeException |
|
165 | - * @throws InvalidInterfaceException |
|
166 | - * @throws ReflectionException |
|
167 | - */ |
|
168 | - public function TXN_ID() |
|
169 | - { |
|
170 | - return $this->get('TXN_ID'); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Sets TXN_ID |
|
176 | - * |
|
177 | - * @param int $TXN_ID |
|
178 | - * @throws EE_Error |
|
179 | - * @throws InvalidArgumentException |
|
180 | - * @throws InvalidDataTypeException |
|
181 | - * @throws InvalidInterfaceException |
|
182 | - * @throws ReflectionException |
|
183 | - */ |
|
184 | - public function set_TXN_ID($TXN_ID) |
|
185 | - { |
|
186 | - $this->set('TXN_ID', $TXN_ID); |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * Gets name |
|
192 | - * |
|
193 | - * @return string |
|
194 | - * @throws EE_Error |
|
195 | - * @throws InvalidArgumentException |
|
196 | - * @throws InvalidDataTypeException |
|
197 | - * @throws InvalidInterfaceException |
|
198 | - * @throws ReflectionException |
|
199 | - */ |
|
200 | - public function name() |
|
201 | - { |
|
202 | - $name = $this->get('LIN_name'); |
|
203 | - if (! $name) { |
|
204 | - $name = ucwords(str_replace('-', ' ', $this->type())); |
|
205 | - } |
|
206 | - return $name; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Sets name |
|
212 | - * |
|
213 | - * @param string $name |
|
214 | - * @throws EE_Error |
|
215 | - * @throws InvalidArgumentException |
|
216 | - * @throws InvalidDataTypeException |
|
217 | - * @throws InvalidInterfaceException |
|
218 | - * @throws ReflectionException |
|
219 | - */ |
|
220 | - public function set_name($name) |
|
221 | - { |
|
222 | - $this->set('LIN_name', $name); |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * Gets desc |
|
228 | - * |
|
229 | - * @return string |
|
230 | - * @throws EE_Error |
|
231 | - * @throws InvalidArgumentException |
|
232 | - * @throws InvalidDataTypeException |
|
233 | - * @throws InvalidInterfaceException |
|
234 | - * @throws ReflectionException |
|
235 | - */ |
|
236 | - public function desc() |
|
237 | - { |
|
238 | - return $this->get('LIN_desc'); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * Sets desc |
|
244 | - * |
|
245 | - * @param string $desc |
|
246 | - * @throws EE_Error |
|
247 | - * @throws InvalidArgumentException |
|
248 | - * @throws InvalidDataTypeException |
|
249 | - * @throws InvalidInterfaceException |
|
250 | - * @throws ReflectionException |
|
251 | - */ |
|
252 | - public function set_desc($desc) |
|
253 | - { |
|
254 | - $this->set('LIN_desc', $desc); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Gets quantity |
|
260 | - * |
|
261 | - * @return int |
|
262 | - * @throws EE_Error |
|
263 | - * @throws InvalidArgumentException |
|
264 | - * @throws InvalidDataTypeException |
|
265 | - * @throws InvalidInterfaceException |
|
266 | - * @throws ReflectionException |
|
267 | - */ |
|
268 | - public function quantity() |
|
269 | - { |
|
270 | - return $this->get('LIN_quantity'); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * Sets quantity |
|
276 | - * |
|
277 | - * @param int $quantity |
|
278 | - * @throws EE_Error |
|
279 | - * @throws InvalidArgumentException |
|
280 | - * @throws InvalidDataTypeException |
|
281 | - * @throws InvalidInterfaceException |
|
282 | - * @throws ReflectionException |
|
283 | - */ |
|
284 | - public function set_quantity($quantity) |
|
285 | - { |
|
286 | - $this->set('LIN_quantity', max($quantity, 0)); |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * Gets item_id |
|
292 | - * |
|
293 | - * @return int|string |
|
294 | - * @throws EE_Error |
|
295 | - * @throws InvalidArgumentException |
|
296 | - * @throws InvalidDataTypeException |
|
297 | - * @throws InvalidInterfaceException |
|
298 | - * @throws ReflectionException |
|
299 | - */ |
|
300 | - public function OBJ_ID() |
|
301 | - { |
|
302 | - return $this->get('OBJ_ID'); |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * Sets item_id |
|
308 | - * |
|
309 | - * @param int|string $item_id |
|
310 | - * @throws EE_Error |
|
311 | - * @throws InvalidArgumentException |
|
312 | - * @throws InvalidDataTypeException |
|
313 | - * @throws InvalidInterfaceException |
|
314 | - * @throws ReflectionException |
|
315 | - */ |
|
316 | - public function set_OBJ_ID($item_id) |
|
317 | - { |
|
318 | - $this->set('OBJ_ID', $item_id); |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Gets item_type |
|
324 | - * |
|
325 | - * @return string |
|
326 | - * @throws EE_Error |
|
327 | - * @throws InvalidArgumentException |
|
328 | - * @throws InvalidDataTypeException |
|
329 | - * @throws InvalidInterfaceException |
|
330 | - * @throws ReflectionException |
|
331 | - */ |
|
332 | - public function OBJ_type() |
|
333 | - { |
|
334 | - return $this->get('OBJ_type'); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * Gets item_type |
|
340 | - * |
|
341 | - * @return string |
|
342 | - * @throws EE_Error |
|
343 | - * @throws InvalidArgumentException |
|
344 | - * @throws InvalidDataTypeException |
|
345 | - * @throws InvalidInterfaceException |
|
346 | - * @throws ReflectionException |
|
347 | - */ |
|
348 | - public function OBJ_type_i18n() |
|
349 | - { |
|
350 | - $obj_type = $this->OBJ_type(); |
|
351 | - switch ($obj_type) { |
|
352 | - case EEM_Line_Item::OBJ_TYPE_EVENT: |
|
353 | - $obj_type = esc_html__('Event', 'event_espresso'); |
|
354 | - break; |
|
355 | - case EEM_Line_Item::OBJ_TYPE_PRICE: |
|
356 | - $obj_type = esc_html__('Price', 'event_espresso'); |
|
357 | - break; |
|
358 | - case EEM_Line_Item::OBJ_TYPE_PROMOTION: |
|
359 | - $obj_type = esc_html__('Promotion', 'event_espresso'); |
|
360 | - break; |
|
361 | - case EEM_Line_Item::OBJ_TYPE_TICKET: |
|
362 | - $obj_type = esc_html__('Ticket', 'event_espresso'); |
|
363 | - break; |
|
364 | - case EEM_Line_Item::OBJ_TYPE_TRANSACTION: |
|
365 | - $obj_type = esc_html__('Transaction', 'event_espresso'); |
|
366 | - break; |
|
367 | - } |
|
368 | - return apply_filters('FHEE__EE_Line_Item__OBJ_type_i18n', $obj_type, $this); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Sets item_type |
|
374 | - * |
|
375 | - * @param string $OBJ_type |
|
376 | - * @throws EE_Error |
|
377 | - * @throws InvalidArgumentException |
|
378 | - * @throws InvalidDataTypeException |
|
379 | - * @throws InvalidInterfaceException |
|
380 | - * @throws ReflectionException |
|
381 | - */ |
|
382 | - public function set_OBJ_type($OBJ_type) |
|
383 | - { |
|
384 | - $this->set('OBJ_type', $OBJ_type); |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * Gets unit_price for flat rate items. Percent items should set this to 0. |
|
390 | - * You may alternatively want to use prettyUnitPrice(), which works for flat and percent items. |
|
391 | - * |
|
392 | - * @param string $schema |
|
393 | - * @return float |
|
394 | - * @throws EE_Error |
|
395 | - * @throws ReflectionException |
|
396 | - */ |
|
397 | - public function unit_price($schema = 'localized_float') |
|
398 | - { |
|
399 | - return $this->get('LIN_unit_price', $schema); |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * @param string $schema |
|
405 | - * @return mixed|string |
|
406 | - * @throws EE_Error |
|
407 | - * @throws ReflectionException |
|
408 | - * @since $VID:$ |
|
409 | - */ |
|
410 | - public function prettyUnitPrice($schema = 'localized_currency') |
|
411 | - { |
|
412 | - if ($this->is_percent()) { |
|
413 | - $quantity = $this->parent() instanceof EE_Line_Item |
|
414 | - && $this->parent()->type() === EEM_Line_Item::type_line_item |
|
415 | - ? $this->parent()->quantity() |
|
416 | - : $this->quantity(); |
|
417 | - if ($quantity !== 0) { |
|
418 | - $percent = $this->total() / $quantity; |
|
419 | - $percent = $this->currency_formatter->roundForLocale($percent); |
|
420 | - return apply_filters('FHEE__format_percentage_value', $percent); |
|
421 | - } |
|
422 | - } |
|
423 | - return $this->get_pretty('LIN_unit_price', $schema); |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * Sets unit_price |
|
429 | - * |
|
430 | - * @param float $unit_price |
|
431 | - * @throws EE_Error |
|
432 | - * @throws ReflectionException |
|
433 | - */ |
|
434 | - public function set_unit_price($unit_price) |
|
435 | - { |
|
436 | - $this->set('LIN_unit_price', $unit_price); |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * Checks if this item is a percentage modifier or not |
|
442 | - * |
|
443 | - * @return boolean |
|
444 | - * @throws EE_Error |
|
445 | - * @throws InvalidArgumentException |
|
446 | - * @throws InvalidDataTypeException |
|
447 | - * @throws InvalidInterfaceException |
|
448 | - * @throws ReflectionException |
|
449 | - */ |
|
450 | - public function is_percent() |
|
451 | - { |
|
452 | - if ($this->is_percent !== null) { |
|
453 | - return $this->is_percent; |
|
454 | - } |
|
455 | - if ($this->is_tax_sub_total()) { |
|
456 | - // tax subtotals HAVE a percent on them, that percentage only applies |
|
457 | - // to taxable items, so its' an exception. Treat it like a flat line item |
|
458 | - $this->is_percent = false; |
|
459 | - return $this->is_percent; |
|
460 | - } |
|
461 | - $unit_price = abs($this->get('LIN_unit_price')); |
|
462 | - $percent = abs($this->get('LIN_percent')); |
|
463 | - if ($unit_price < .001 && $percent) { |
|
464 | - $this->is_percent = true; |
|
465 | - return $this->is_percent; |
|
466 | - } |
|
467 | - if ($unit_price >= .001 && ! $percent) { |
|
468 | - $this->is_percent = false; |
|
469 | - return $this->is_percent; |
|
470 | - } |
|
471 | - if ($unit_price >= .001 && $percent) { |
|
472 | - throw new EE_Error( |
|
473 | - sprintf( |
|
474 | - esc_html__( |
|
475 | - 'A Line Item can not have a unit price of (%s) AND a percent (%s)!', |
|
476 | - 'event_espresso' |
|
477 | - ), |
|
478 | - $unit_price, |
|
479 | - $percent |
|
480 | - ) |
|
481 | - ); |
|
482 | - } |
|
483 | - // if they're both 0, assume its not a percent item |
|
484 | - $this->is_percent = false; |
|
485 | - return $this->is_percent; |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * Gets percent (between 100-.001) |
|
491 | - * |
|
492 | - * @param bool $as_decimal if true will divide value by 100 |
|
493 | - * @return float |
|
494 | - * @throws EE_Error |
|
495 | - * @throws ReflectionException |
|
496 | - */ |
|
497 | - public function percent($as_decimal = false) |
|
498 | - { |
|
499 | - $percent = $this->get('LIN_percent'); |
|
500 | - $percent = $as_decimal ? $percent / 100 : $percent; |
|
501 | - return $this->currency_formatter->precisionRound($percent); |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - /** |
|
506 | - * Gets percent (between 100-.001) |
|
507 | - * |
|
508 | - * @return float |
|
509 | - * @throws EE_Error |
|
510 | - * @throws ReflectionException |
|
511 | - */ |
|
512 | - public function prettyPercent() |
|
513 | - { |
|
514 | - return apply_filters('FHEE__format_percentage_value', $this->get_pretty('LIN_percent')); |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * Sets percent (between 100-0.01) |
|
520 | - * |
|
521 | - * @param float $percent |
|
522 | - * @throws EE_Error |
|
523 | - * @throws InvalidArgumentException |
|
524 | - * @throws InvalidDataTypeException |
|
525 | - * @throws InvalidInterfaceException |
|
526 | - * @throws ReflectionException |
|
527 | - */ |
|
528 | - public function set_percent($percent) |
|
529 | - { |
|
530 | - $this->set('LIN_percent', $percent); |
|
531 | - } |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * Gets total |
|
536 | - * |
|
537 | - * @param string $schema |
|
538 | - * @return float |
|
539 | - * @throws EE_Error |
|
540 | - * @throws ReflectionException |
|
541 | - */ |
|
542 | - public function total($schema = 'localized_float') |
|
543 | - { |
|
544 | - return $this->get('LIN_total', $schema); |
|
545 | - } |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * @param string $schema |
|
550 | - * @return string |
|
551 | - * @throws EE_Error |
|
552 | - * @throws InvalidArgumentException |
|
553 | - * @throws InvalidDataTypeException |
|
554 | - * @throws InvalidInterfaceException |
|
555 | - * @throws ReflectionException |
|
556 | - */ |
|
557 | - public function prettyTotal($schema = 'localized_currency') |
|
558 | - { |
|
559 | - return $this->get_pretty('LIN_total', $schema); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * Sets total |
|
565 | - * |
|
566 | - * @param float $total |
|
567 | - * @throws EE_Error |
|
568 | - * @throws ReflectionException |
|
569 | - */ |
|
570 | - public function set_total($total) |
|
571 | - { |
|
572 | - $this->set('LIN_total', $total); |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - /** |
|
577 | - * Gets order |
|
578 | - * |
|
579 | - * @return int |
|
580 | - * @throws EE_Error |
|
581 | - * @throws InvalidArgumentException |
|
582 | - * @throws InvalidDataTypeException |
|
583 | - * @throws InvalidInterfaceException |
|
584 | - * @throws ReflectionException |
|
585 | - */ |
|
586 | - public function order() |
|
587 | - { |
|
588 | - return $this->get('LIN_order'); |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - /** |
|
593 | - * Sets order |
|
594 | - * |
|
595 | - * @param int $order |
|
596 | - * @throws EE_Error |
|
597 | - * @throws InvalidArgumentException |
|
598 | - * @throws InvalidDataTypeException |
|
599 | - * @throws InvalidInterfaceException |
|
600 | - * @throws ReflectionException |
|
601 | - */ |
|
602 | - public function set_order($order) |
|
603 | - { |
|
604 | - $this->set('LIN_order', $order); |
|
605 | - } |
|
606 | - |
|
607 | - |
|
608 | - /** |
|
609 | - * Gets parent |
|
610 | - * |
|
611 | - * @return int |
|
612 | - * @throws EE_Error |
|
613 | - * @throws InvalidArgumentException |
|
614 | - * @throws InvalidDataTypeException |
|
615 | - * @throws InvalidInterfaceException |
|
616 | - * @throws ReflectionException |
|
617 | - */ |
|
618 | - public function parent_ID() |
|
619 | - { |
|
620 | - return $this->get('LIN_parent'); |
|
621 | - } |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * Sets parent |
|
626 | - * |
|
627 | - * @param int $parent |
|
628 | - * @throws EE_Error |
|
629 | - * @throws InvalidArgumentException |
|
630 | - * @throws InvalidDataTypeException |
|
631 | - * @throws InvalidInterfaceException |
|
632 | - * @throws ReflectionException |
|
633 | - */ |
|
634 | - public function set_parent_ID($parent) |
|
635 | - { |
|
636 | - $this->set('LIN_parent', $parent); |
|
637 | - } |
|
638 | - |
|
639 | - |
|
640 | - /** |
|
641 | - * Gets type |
|
642 | - * |
|
643 | - * @return string |
|
644 | - * @throws EE_Error |
|
645 | - * @throws InvalidArgumentException |
|
646 | - * @throws InvalidDataTypeException |
|
647 | - * @throws InvalidInterfaceException |
|
648 | - * @throws ReflectionException |
|
649 | - */ |
|
650 | - public function type() |
|
651 | - { |
|
652 | - return $this->get('LIN_type'); |
|
653 | - } |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * Sets type |
|
658 | - * |
|
659 | - * @param string $type |
|
660 | - * @throws EE_Error |
|
661 | - * @throws InvalidArgumentException |
|
662 | - * @throws InvalidDataTypeException |
|
663 | - * @throws InvalidInterfaceException |
|
664 | - * @throws ReflectionException |
|
665 | - */ |
|
666 | - public function set_type($type) |
|
667 | - { |
|
668 | - $this->set('LIN_type', $type); |
|
669 | - } |
|
670 | - |
|
671 | - |
|
672 | - /** |
|
673 | - * Gets the line item of which this item is a composite. Eg, if this is a subtotal, the parent might be a total\ |
|
674 | - * If this line item is saved to the DB, fetches the parent from the DB. However, if this line item isn't in the DB |
|
675 | - * it uses its cached reference to its parent line item (which would have been set by `EE_Line_Item::set_parent()` |
|
676 | - * or indirectly by `EE_Line_item::add_child_line_item()`) |
|
677 | - * |
|
678 | - * @return EE_Base_Class|EE_Line_Item |
|
679 | - * @throws EE_Error |
|
680 | - * @throws InvalidArgumentException |
|
681 | - * @throws InvalidDataTypeException |
|
682 | - * @throws InvalidInterfaceException |
|
683 | - * @throws ReflectionException |
|
684 | - */ |
|
685 | - public function parent() |
|
686 | - { |
|
687 | - return $this->ID() |
|
688 | - ? $this->get_model()->get_one_by_ID($this->parent_ID()) |
|
689 | - : $this->_parent; |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * Gets ALL the children of this line item (ie, all the parts that contribute towards this total). |
|
695 | - * |
|
696 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
697 | - * @throws EE_Error |
|
698 | - * @throws InvalidArgumentException |
|
699 | - * @throws InvalidDataTypeException |
|
700 | - * @throws InvalidInterfaceException |
|
701 | - * @throws ReflectionException |
|
702 | - */ |
|
703 | - public function children() |
|
704 | - { |
|
705 | - if ($this->ID()) { |
|
706 | - return $this->get_model()->get_all( |
|
707 | - [ |
|
708 | - ['LIN_parent' => $this->ID()], |
|
709 | - 'order_by' => ['LIN_order' => 'ASC'], |
|
710 | - ] |
|
711 | - ); |
|
712 | - } |
|
713 | - if (! is_array($this->_children)) { |
|
714 | - $this->_children = []; |
|
715 | - } |
|
716 | - return $this->_children; |
|
717 | - } |
|
718 | - |
|
719 | - |
|
720 | - /** |
|
721 | - * Gets code |
|
722 | - * |
|
723 | - * @return string |
|
724 | - * @throws EE_Error |
|
725 | - * @throws InvalidArgumentException |
|
726 | - * @throws InvalidDataTypeException |
|
727 | - * @throws InvalidInterfaceException |
|
728 | - * @throws ReflectionException |
|
729 | - */ |
|
730 | - public function code() |
|
731 | - { |
|
732 | - return $this->get('LIN_code'); |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * Sets code |
|
738 | - * |
|
739 | - * @param string $code |
|
740 | - * @throws EE_Error |
|
741 | - * @throws InvalidArgumentException |
|
742 | - * @throws InvalidDataTypeException |
|
743 | - * @throws InvalidInterfaceException |
|
744 | - * @throws ReflectionException |
|
745 | - */ |
|
746 | - public function set_code($code) |
|
747 | - { |
|
748 | - $this->set('LIN_code', $code); |
|
749 | - } |
|
750 | - |
|
751 | - |
|
752 | - /** |
|
753 | - * Gets is_taxable |
|
754 | - * |
|
755 | - * @return boolean |
|
756 | - * @throws EE_Error |
|
757 | - * @throws InvalidArgumentException |
|
758 | - * @throws InvalidDataTypeException |
|
759 | - * @throws InvalidInterfaceException |
|
760 | - * @throws ReflectionException |
|
761 | - */ |
|
762 | - public function is_taxable() |
|
763 | - { |
|
764 | - return $this->get('LIN_is_taxable'); |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * Sets is_taxable |
|
770 | - * |
|
771 | - * @param boolean $is_taxable |
|
772 | - * @throws EE_Error |
|
773 | - * @throws InvalidArgumentException |
|
774 | - * @throws InvalidDataTypeException |
|
775 | - * @throws InvalidInterfaceException |
|
776 | - * @throws ReflectionException |
|
777 | - */ |
|
778 | - public function set_is_taxable($is_taxable) |
|
779 | - { |
|
780 | - $this->set('LIN_is_taxable', $is_taxable); |
|
781 | - } |
|
782 | - |
|
783 | - |
|
784 | - /** |
|
785 | - * Gets the object that this model-joins-to. |
|
786 | - * returns one of the model objects that the field OBJ_ID can point to... see the 'OBJ_ID' field on |
|
787 | - * EEM_Promotion_Object |
|
788 | - * Eg, if this line item join model object is for a ticket, this will return the EE_Ticket object |
|
789 | - * |
|
790 | - * @return EE_Base_Class | NULL |
|
791 | - * @throws EE_Error |
|
792 | - * @throws InvalidArgumentException |
|
793 | - * @throws InvalidDataTypeException |
|
794 | - * @throws InvalidInterfaceException |
|
795 | - * @throws ReflectionException |
|
796 | - */ |
|
797 | - public function get_object() |
|
798 | - { |
|
799 | - $model_name_of_related_obj = $this->OBJ_type(); |
|
800 | - return $this->get_model()->has_relation($model_name_of_related_obj) |
|
801 | - ? $this->get_first_related($model_name_of_related_obj) |
|
802 | - : null; |
|
803 | - } |
|
804 | - |
|
805 | - |
|
806 | - /** |
|
807 | - * Like EE_Line_Item::get_object(), but can only ever actually return an EE_Ticket. |
|
808 | - * (IE, if this line item is for a price or something else, will return NULL) |
|
809 | - * |
|
810 | - * @param array $query_params |
|
811 | - * @return EE_Base_Class|EE_Ticket |
|
812 | - * @throws EE_Error |
|
813 | - * @throws InvalidArgumentException |
|
814 | - * @throws InvalidDataTypeException |
|
815 | - * @throws InvalidInterfaceException |
|
816 | - * @throws ReflectionException |
|
817 | - */ |
|
818 | - public function ticket($query_params = []) |
|
819 | - { |
|
820 | - // we're going to assume that when this method is called |
|
821 | - // we always want to receive the attached ticket EVEN if that ticket is archived. |
|
822 | - // This can be overridden via the incoming $query_params argument |
|
823 | - $remove_defaults = ['default_where_conditions' => 'none']; |
|
824 | - $query_params = array_merge($remove_defaults, $query_params); |
|
825 | - return $this->get_first_related(EEM_Line_Item::OBJ_TYPE_TICKET, $query_params); |
|
826 | - } |
|
827 | - |
|
828 | - |
|
829 | - /** |
|
830 | - * Gets the EE_Datetime that's related to the ticket, IF this is for a ticket |
|
831 | - * |
|
832 | - * @return EE_Datetime | NULL |
|
833 | - * @throws EE_Error |
|
834 | - * @throws InvalidArgumentException |
|
835 | - * @throws InvalidDataTypeException |
|
836 | - * @throws InvalidInterfaceException |
|
837 | - * @throws ReflectionException |
|
838 | - */ |
|
839 | - public function get_ticket_datetime() |
|
840 | - { |
|
841 | - if ($this->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
842 | - $ticket = $this->ticket(); |
|
843 | - if ($ticket instanceof EE_Ticket) { |
|
844 | - $datetime = $ticket->first_datetime(); |
|
845 | - if ($datetime instanceof EE_Datetime) { |
|
846 | - return $datetime; |
|
847 | - } |
|
848 | - } |
|
849 | - } |
|
850 | - return null; |
|
851 | - } |
|
852 | - |
|
853 | - |
|
854 | - /** |
|
855 | - * Gets the event's name that's related to the ticket, if this is for |
|
856 | - * a ticket |
|
857 | - * |
|
858 | - * @return string |
|
859 | - * @throws EE_Error |
|
860 | - * @throws InvalidArgumentException |
|
861 | - * @throws InvalidDataTypeException |
|
862 | - * @throws InvalidInterfaceException |
|
863 | - * @throws ReflectionException |
|
864 | - */ |
|
865 | - public function ticket_event_name() |
|
866 | - { |
|
867 | - $event_name = esc_html__('Unknown', 'event_espresso'); |
|
868 | - $event = $this->ticket_event(); |
|
869 | - if ($event instanceof EE_Event) { |
|
870 | - $event_name = $event->name(); |
|
871 | - } |
|
872 | - return $event_name; |
|
873 | - } |
|
874 | - |
|
875 | - |
|
876 | - /** |
|
877 | - * Gets the event that's related to the ticket, if this line item represents a ticket. |
|
878 | - * |
|
879 | - * @return EE_Event|null |
|
880 | - * @throws EE_Error |
|
881 | - * @throws InvalidArgumentException |
|
882 | - * @throws InvalidDataTypeException |
|
883 | - * @throws InvalidInterfaceException |
|
884 | - * @throws ReflectionException |
|
885 | - */ |
|
886 | - public function ticket_event() |
|
887 | - { |
|
888 | - $event = null; |
|
889 | - $ticket = $this->ticket(); |
|
890 | - if ($ticket instanceof EE_Ticket) { |
|
891 | - $datetime = $ticket->first_datetime(); |
|
892 | - if ($datetime instanceof EE_Datetime) { |
|
893 | - $event = $datetime->event(); |
|
894 | - } |
|
895 | - } |
|
896 | - return $event; |
|
897 | - } |
|
898 | - |
|
899 | - |
|
900 | - /** |
|
901 | - * Gets the first datetime for this lien item, assuming it's for a ticket |
|
902 | - * |
|
903 | - * @param string $date_format |
|
904 | - * @param string $time_format |
|
905 | - * @return string |
|
906 | - * @throws EE_Error |
|
907 | - * @throws InvalidArgumentException |
|
908 | - * @throws InvalidDataTypeException |
|
909 | - * @throws InvalidInterfaceException |
|
910 | - * @throws ReflectionException |
|
911 | - */ |
|
912 | - public function ticket_datetime_start($date_format = '', $time_format = '') |
|
913 | - { |
|
914 | - $first_datetime_string = esc_html__('Unknown', 'event_espresso'); |
|
915 | - $datetime = $this->get_ticket_datetime(); |
|
916 | - if ($datetime) { |
|
917 | - $first_datetime_string = $datetime->start_date_and_time($date_format, $time_format); |
|
918 | - } |
|
919 | - return $first_datetime_string; |
|
920 | - } |
|
921 | - |
|
922 | - |
|
923 | - /** |
|
924 | - * Adds the line item as a child to this line item. If there is another child line |
|
925 | - * item with the same LIN_code, it is overwritten by this new one |
|
926 | - * |
|
927 | - * @param EEI_Line_Item|EE_Line_Item $line_item |
|
928 | - * @param bool $set_order |
|
929 | - * @return bool success |
|
930 | - * @throws EE_Error |
|
931 | - * @throws InvalidArgumentException |
|
932 | - * @throws InvalidDataTypeException |
|
933 | - * @throws InvalidInterfaceException |
|
934 | - * @throws ReflectionException |
|
935 | - */ |
|
936 | - public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true) |
|
937 | - { |
|
938 | - // should we calculate the LIN_order for this line item ? |
|
939 | - if ($set_order || $line_item->order() === null) { |
|
940 | - $line_item->set_order(count($this->children())); |
|
941 | - } |
|
942 | - if ($this->ID()) { |
|
943 | - // check for any duplicate line items (with the same code), if so, this replaces it |
|
944 | - $line_item_with_same_code = $this->get_child_line_item($line_item->code()); |
|
945 | - if (($line_item_with_same_code instanceof EE_Line_Item) && $line_item_with_same_code !== $line_item) { |
|
946 | - $this->delete_child_line_item($line_item_with_same_code->code()); |
|
947 | - } |
|
948 | - $line_item->set_parent_ID($this->ID()); |
|
949 | - if ($this->TXN_ID()) { |
|
950 | - $line_item->set_TXN_ID($this->TXN_ID()); |
|
951 | - } |
|
952 | - return $line_item->save(); |
|
953 | - } |
|
954 | - $this->_children[ $line_item->code() ] = $line_item; |
|
955 | - if ($line_item->parent() !== $this) { |
|
956 | - $line_item->set_parent($this); |
|
957 | - } |
|
958 | - return true; |
|
959 | - } |
|
960 | - |
|
961 | - |
|
962 | - /** |
|
963 | - * Similar to EE_Base_Class::_add_relation_to, except this isn't a normal relation. |
|
964 | - * If this line item is saved to the DB, this is just a wrapper for set_parent_ID() and save() |
|
965 | - * However, if this line item is NOT saved to the DB, this just caches the parent on |
|
966 | - * the EE_Line_Item::_parent property. |
|
967 | - * |
|
968 | - * @param EE_Line_Item $line_item |
|
969 | - * @throws EE_Error |
|
970 | - * @throws InvalidArgumentException |
|
971 | - * @throws InvalidDataTypeException |
|
972 | - * @throws InvalidInterfaceException |
|
973 | - * @throws ReflectionException |
|
974 | - */ |
|
975 | - public function set_parent($line_item) |
|
976 | - { |
|
977 | - if ($this->ID()) { |
|
978 | - if (! $line_item->ID()) { |
|
979 | - $line_item->save(); |
|
980 | - } |
|
981 | - $this->set_parent_ID($line_item->ID()); |
|
982 | - $this->save(); |
|
983 | - } else { |
|
984 | - $this->_parent = $line_item; |
|
985 | - $this->set_parent_ID($line_item->ID()); |
|
986 | - } |
|
987 | - } |
|
988 | - |
|
989 | - |
|
990 | - /** |
|
991 | - * Gets the child line item as specified by its code. Because this returns an object (by reference) |
|
992 | - * you can modify this child line item and the parent (this object) can know about them |
|
993 | - * because it also has a reference to that line item |
|
994 | - * |
|
995 | - * @param string $code |
|
996 | - * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
997 | - * @throws EE_Error |
|
998 | - * @throws InvalidArgumentException |
|
999 | - * @throws InvalidDataTypeException |
|
1000 | - * @throws InvalidInterfaceException |
|
1001 | - * @throws ReflectionException |
|
1002 | - */ |
|
1003 | - public function get_child_line_item($code) |
|
1004 | - { |
|
1005 | - if ($this->ID()) { |
|
1006 | - return $this->get_model()->get_one( |
|
1007 | - [['LIN_parent' => $this->ID(), 'LIN_code' => $code]] |
|
1008 | - ); |
|
1009 | - } |
|
1010 | - return isset($this->_children[ $code ]) |
|
1011 | - ? $this->_children[ $code ] |
|
1012 | - : null; |
|
1013 | - } |
|
1014 | - |
|
1015 | - |
|
1016 | - /** |
|
1017 | - * Returns how many items are deleted (or, if this item has not been saved ot the DB yet, just how many it HAD |
|
1018 | - * cached on it) |
|
1019 | - * |
|
1020 | - * @return int |
|
1021 | - * @throws EE_Error |
|
1022 | - * @throws InvalidArgumentException |
|
1023 | - * @throws InvalidDataTypeException |
|
1024 | - * @throws InvalidInterfaceException |
|
1025 | - * @throws ReflectionException |
|
1026 | - */ |
|
1027 | - public function delete_children_line_items() |
|
1028 | - { |
|
1029 | - if ($this->ID()) { |
|
1030 | - return $this->get_model()->delete([['LIN_parent' => $this->ID()]]); |
|
1031 | - } |
|
1032 | - $count = count($this->_children); |
|
1033 | - $this->_children = []; |
|
1034 | - return $count; |
|
1035 | - } |
|
1036 | - |
|
1037 | - |
|
1038 | - /** |
|
1039 | - * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line |
|
1040 | - * HAS NOT been saved to the DB, removes the child line item with index $code. |
|
1041 | - * Also searches through the child's children for a matching line item. However, once a line item has been found |
|
1042 | - * and deleted, stops searching (so if there are line items with duplicate codes, only the first one found will be |
|
1043 | - * deleted) |
|
1044 | - * |
|
1045 | - * @param string $code |
|
1046 | - * @param bool $stop_search_once_found |
|
1047 | - * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to |
|
1048 | - * the DB yet) |
|
1049 | - * @throws EE_Error |
|
1050 | - * @throws InvalidArgumentException |
|
1051 | - * @throws InvalidDataTypeException |
|
1052 | - * @throws InvalidInterfaceException |
|
1053 | - * @throws ReflectionException |
|
1054 | - */ |
|
1055 | - public function delete_child_line_item($code, $stop_search_once_found = true) |
|
1056 | - { |
|
1057 | - if ($this->ID()) { |
|
1058 | - $items_deleted = 0; |
|
1059 | - if ($this->code() === $code) { |
|
1060 | - $items_deleted += EEH_Line_Item::delete_all_child_items($this); |
|
1061 | - $items_deleted += (int) $this->delete(); |
|
1062 | - if ($stop_search_once_found) { |
|
1063 | - return $items_deleted; |
|
1064 | - } |
|
1065 | - } |
|
1066 | - foreach ($this->children() as $child_line_item) { |
|
1067 | - $items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found); |
|
1068 | - } |
|
1069 | - return $items_deleted; |
|
1070 | - } |
|
1071 | - if (isset($this->_children[ $code ])) { |
|
1072 | - unset($this->_children[ $code ]); |
|
1073 | - return 1; |
|
1074 | - } |
|
1075 | - return 0; |
|
1076 | - } |
|
1077 | - |
|
1078 | - |
|
1079 | - /** |
|
1080 | - * If this line item is in the database, is of the type subtotal, and |
|
1081 | - * has no children, why do we have it? It should be deleted so this function |
|
1082 | - * does that |
|
1083 | - * |
|
1084 | - * @return boolean |
|
1085 | - * @throws EE_Error |
|
1086 | - * @throws InvalidArgumentException |
|
1087 | - * @throws InvalidDataTypeException |
|
1088 | - * @throws InvalidInterfaceException |
|
1089 | - * @throws ReflectionException |
|
1090 | - */ |
|
1091 | - public function delete_if_childless_subtotal() |
|
1092 | - { |
|
1093 | - if ($this->ID() && $this->type() === EEM_Line_Item::type_sub_total && ! $this->children()) { |
|
1094 | - return $this->delete(); |
|
1095 | - } |
|
1096 | - return false; |
|
1097 | - } |
|
1098 | - |
|
1099 | - |
|
1100 | - /** |
|
1101 | - * Creates a code and returns a string. doesn't assign the code to this model object |
|
1102 | - * |
|
1103 | - * @return string |
|
1104 | - * @throws EE_Error |
|
1105 | - * @throws InvalidArgumentException |
|
1106 | - * @throws InvalidDataTypeException |
|
1107 | - * @throws InvalidInterfaceException |
|
1108 | - * @throws ReflectionException |
|
1109 | - */ |
|
1110 | - public function generate_code() |
|
1111 | - { |
|
1112 | - // each line item in the cart requires a unique identifier |
|
1113 | - // return md5($this->get('OBJ_type') . $this->get('OBJ_ID') . microtime()); |
|
1114 | - return $this->get('OBJ_type') . '-' . $this->get('OBJ_ID') . '-' . microtime(); |
|
1115 | - } |
|
1116 | - |
|
1117 | - |
|
1118 | - /** |
|
1119 | - * @return bool |
|
1120 | - * @throws EE_Error |
|
1121 | - * @throws InvalidArgumentException |
|
1122 | - * @throws InvalidDataTypeException |
|
1123 | - * @throws InvalidInterfaceException |
|
1124 | - * @throws ReflectionException |
|
1125 | - */ |
|
1126 | - public function is_tax() |
|
1127 | - { |
|
1128 | - return $this->type() === EEM_Line_Item::type_tax; |
|
1129 | - } |
|
1130 | - |
|
1131 | - |
|
1132 | - /** |
|
1133 | - * @return bool |
|
1134 | - * @throws EE_Error |
|
1135 | - * @throws InvalidArgumentException |
|
1136 | - * @throws InvalidDataTypeException |
|
1137 | - * @throws InvalidInterfaceException |
|
1138 | - * @throws ReflectionException |
|
1139 | - */ |
|
1140 | - public function is_tax_sub_total() |
|
1141 | - { |
|
1142 | - return $this->type() === EEM_Line_Item::type_tax_sub_total; |
|
1143 | - } |
|
1144 | - |
|
1145 | - |
|
1146 | - /** |
|
1147 | - * @return bool |
|
1148 | - * @throws EE_Error |
|
1149 | - * @throws InvalidArgumentException |
|
1150 | - * @throws InvalidDataTypeException |
|
1151 | - * @throws InvalidInterfaceException |
|
1152 | - * @throws ReflectionException |
|
1153 | - */ |
|
1154 | - public function is_line_item() |
|
1155 | - { |
|
1156 | - return $this->type() === EEM_Line_Item::type_line_item; |
|
1157 | - } |
|
1158 | - |
|
1159 | - |
|
1160 | - /** |
|
1161 | - * @return bool |
|
1162 | - * @throws EE_Error |
|
1163 | - * @throws InvalidArgumentException |
|
1164 | - * @throws InvalidDataTypeException |
|
1165 | - * @throws InvalidInterfaceException |
|
1166 | - * @throws ReflectionException |
|
1167 | - */ |
|
1168 | - public function is_sub_line_item() |
|
1169 | - { |
|
1170 | - return $this->type() === EEM_Line_Item::type_sub_line_item; |
|
1171 | - } |
|
1172 | - |
|
1173 | - |
|
1174 | - /** |
|
1175 | - * @return bool |
|
1176 | - * @throws EE_Error |
|
1177 | - * @throws InvalidArgumentException |
|
1178 | - * @throws InvalidDataTypeException |
|
1179 | - * @throws InvalidInterfaceException |
|
1180 | - * @throws ReflectionException |
|
1181 | - */ |
|
1182 | - public function is_sub_total() |
|
1183 | - { |
|
1184 | - return $this->type() === EEM_Line_Item::type_sub_total; |
|
1185 | - } |
|
1186 | - |
|
1187 | - |
|
1188 | - /** |
|
1189 | - * Whether or not this line item is a cancellation line item |
|
1190 | - * |
|
1191 | - * @return boolean |
|
1192 | - * @throws EE_Error |
|
1193 | - * @throws InvalidArgumentException |
|
1194 | - * @throws InvalidDataTypeException |
|
1195 | - * @throws InvalidInterfaceException |
|
1196 | - * @throws ReflectionException |
|
1197 | - */ |
|
1198 | - public function is_cancellation() |
|
1199 | - { |
|
1200 | - return EEM_Line_Item::type_cancellation === $this->type(); |
|
1201 | - } |
|
1202 | - |
|
1203 | - |
|
1204 | - /** |
|
1205 | - * @return bool |
|
1206 | - * @throws EE_Error |
|
1207 | - * @throws InvalidArgumentException |
|
1208 | - * @throws InvalidDataTypeException |
|
1209 | - * @throws InvalidInterfaceException |
|
1210 | - * @throws ReflectionException |
|
1211 | - */ |
|
1212 | - public function is_total() |
|
1213 | - { |
|
1214 | - return $this->type() === EEM_Line_Item::type_total; |
|
1215 | - } |
|
1216 | - |
|
1217 | - |
|
1218 | - /** |
|
1219 | - * @return bool |
|
1220 | - * @throws EE_Error |
|
1221 | - * @throws InvalidArgumentException |
|
1222 | - * @throws InvalidDataTypeException |
|
1223 | - * @throws InvalidInterfaceException |
|
1224 | - * @throws ReflectionException |
|
1225 | - */ |
|
1226 | - public function is_cancelled() |
|
1227 | - { |
|
1228 | - return $this->type() === EEM_Line_Item::type_cancellation; |
|
1229 | - } |
|
1230 | - |
|
1231 | - |
|
1232 | - /** |
|
1233 | - * @param string $schema |
|
1234 | - * @return string like '2, 004.00', formatted according to the localized currency |
|
1235 | - * @throws EE_Error |
|
1236 | - * @throws ReflectionException |
|
1237 | - */ |
|
1238 | - public function unit_price_no_code($schema = 'localized_float') |
|
1239 | - { |
|
1240 | - return $this->get_pretty('LIN_unit_price', $schema); |
|
1241 | - } |
|
1242 | - |
|
1243 | - |
|
1244 | - /** |
|
1245 | - * @param string $schema |
|
1246 | - * @return string like '2, 004.00', formatted according to the localized currency |
|
1247 | - * @throws EE_Error |
|
1248 | - * @throws ReflectionException |
|
1249 | - */ |
|
1250 | - public function total_no_code($schema = 'localized_float') |
|
1251 | - { |
|
1252 | - return $this->get_pretty('LIN_total', $schema); |
|
1253 | - } |
|
1254 | - |
|
1255 | - |
|
1256 | - /** |
|
1257 | - * Gets the final total on this item, taking taxes into account. |
|
1258 | - * Has the side-effect of setting the sub-total as it was just calculated. |
|
1259 | - * If this is used on a grand-total line item, also updates the transaction's |
|
1260 | - * TXN_total (provided this line item is allowed to persist, otherwise we don't |
|
1261 | - * want to change a persistable transaction with info from a non-persistent line item) |
|
1262 | - * |
|
1263 | - * @param bool $update_txn_status |
|
1264 | - * @return float |
|
1265 | - * @throws EE_Error |
|
1266 | - * @throws InvalidArgumentException |
|
1267 | - * @throws InvalidDataTypeException |
|
1268 | - * @throws InvalidInterfaceException |
|
1269 | - * @throws ReflectionException |
|
1270 | - * @throws RuntimeException |
|
1271 | - */ |
|
1272 | - public function recalculate_total_including_taxes($update_txn_status = false) |
|
1273 | - { |
|
1274 | - return $this->calculator->recalculateTotalIncludingTaxes($this, $update_txn_status); |
|
1275 | - } |
|
1276 | - |
|
1277 | - |
|
1278 | - /** |
|
1279 | - * Recursively goes through all the children and recalculates sub-totals EXCEPT for |
|
1280 | - * tax-sub-totals (they're a an odd beast). Updates the 'total' on each line item according to either its |
|
1281 | - * unit price * quantity or the total of all its children EXCEPT when we're only calculating the taxable total and |
|
1282 | - * when this is called on the grand total |
|
1283 | - * |
|
1284 | - * @return float |
|
1285 | - * @throws EE_Error |
|
1286 | - * @throws InvalidArgumentException |
|
1287 | - * @throws InvalidDataTypeException |
|
1288 | - * @throws InvalidInterfaceException |
|
1289 | - * @throws ReflectionException |
|
1290 | - */ |
|
1291 | - public function recalculate_pre_tax_total() |
|
1292 | - { |
|
1293 | - return $this->calculator->recalculatePreTaxTotal($this); |
|
1294 | - } |
|
1295 | - |
|
1296 | - |
|
1297 | - /** |
|
1298 | - * Recalculates the total on each individual tax (based on a recalculation of the pre-tax total), sets |
|
1299 | - * the totals on each tax calculated, and returns the final tax total. Re-saves tax line items |
|
1300 | - * and tax sub-total if already in the DB |
|
1301 | - * |
|
1302 | - * @return float |
|
1303 | - * @throws EE_Error |
|
1304 | - * @throws InvalidArgumentException |
|
1305 | - * @throws InvalidDataTypeException |
|
1306 | - * @throws InvalidInterfaceException |
|
1307 | - * @throws ReflectionException |
|
1308 | - */ |
|
1309 | - public function recalculate_taxes_and_tax_total() |
|
1310 | - { |
|
1311 | - return $this->calculator->recalculateTaxesAndTaxTotal($this); |
|
1312 | - } |
|
1313 | - |
|
1314 | - |
|
1315 | - /** |
|
1316 | - * Gets the total tax on this line item. Assumes taxes have already been calculated using |
|
1317 | - * recalculate_taxes_and_total |
|
1318 | - * |
|
1319 | - * @return float |
|
1320 | - * @throws EE_Error |
|
1321 | - * @throws InvalidArgumentException |
|
1322 | - * @throws InvalidDataTypeException |
|
1323 | - * @throws InvalidInterfaceException |
|
1324 | - * @throws ReflectionException |
|
1325 | - */ |
|
1326 | - public function get_total_tax() |
|
1327 | - { |
|
1328 | - return $this->calculator->getTotalTax($this); |
|
1329 | - } |
|
1330 | - |
|
1331 | - |
|
1332 | - /** |
|
1333 | - * Gets the total for all the items purchased only |
|
1334 | - * |
|
1335 | - * @return float |
|
1336 | - * @throws EE_Error |
|
1337 | - * @throws InvalidArgumentException |
|
1338 | - * @throws InvalidDataTypeException |
|
1339 | - * @throws InvalidInterfaceException |
|
1340 | - * @throws ReflectionException |
|
1341 | - */ |
|
1342 | - public function get_items_total() |
|
1343 | - { |
|
1344 | - return $this->calculator->getItemsTotal($this); |
|
1345 | - } |
|
1346 | - |
|
1347 | - |
|
1348 | - /** |
|
1349 | - * Returns the amount taxable among this line item's children (or if it has no children, |
|
1350 | - * how much of it is taxable). Does not recalculate totals or subtotals. |
|
1351 | - * If the taxable total is negative, (eg, if none of the tickets were taxable, |
|
1352 | - * but there is a "Taxable" discount), returns 0. |
|
1353 | - * |
|
1354 | - * @return float |
|
1355 | - * @throws EE_Error |
|
1356 | - * @throws InvalidArgumentException |
|
1357 | - * @throws InvalidDataTypeException |
|
1358 | - * @throws InvalidInterfaceException |
|
1359 | - * @throws ReflectionException |
|
1360 | - */ |
|
1361 | - public function taxable_total() |
|
1362 | - { |
|
1363 | - return $this->calculator->amountTaxable($this); |
|
1364 | - } |
|
1365 | - |
|
1366 | - |
|
1367 | - /** |
|
1368 | - * Gets all the descendants (ie, children or children of children etc) that |
|
1369 | - * are of the type 'tax' |
|
1370 | - * |
|
1371 | - * @return EE_Line_Item[] |
|
1372 | - * @throws EE_Error |
|
1373 | - * @throws ReflectionException |
|
1374 | - */ |
|
1375 | - public function tax_descendants() |
|
1376 | - { |
|
1377 | - return EEH_Line_Item::get_tax_descendants($this); |
|
1378 | - } |
|
1379 | - |
|
1380 | - |
|
1381 | - /** |
|
1382 | - * Gets all the real items purchased which are children of this item |
|
1383 | - * |
|
1384 | - * @return EE_Line_Item[] |
|
1385 | - * @throws EE_Error |
|
1386 | - * @throws ReflectionException |
|
1387 | - */ |
|
1388 | - public function get_items() |
|
1389 | - { |
|
1390 | - return EEH_Line_Item::get_line_item_descendants($this); |
|
1391 | - } |
|
1392 | - |
|
1393 | - |
|
1394 | - /** |
|
1395 | - * Gets the transaction for this line item |
|
1396 | - * |
|
1397 | - * @return EE_Base_Class|EE_Transaction |
|
1398 | - * @throws EE_Error |
|
1399 | - * @throws InvalidArgumentException |
|
1400 | - * @throws InvalidDataTypeException |
|
1401 | - * @throws InvalidInterfaceException |
|
1402 | - * @throws ReflectionException |
|
1403 | - */ |
|
1404 | - public function transaction() |
|
1405 | - { |
|
1406 | - return $this->get_first_related(EEM_Line_Item::OBJ_TYPE_TRANSACTION); |
|
1407 | - } |
|
1408 | - |
|
1409 | - |
|
1410 | - /** |
|
1411 | - * Saves this line item to the DB, and recursively saves its descendants. |
|
1412 | - * Because there currently is no proper parent-child relation on the model, |
|
1413 | - * save_this_and_cached() will NOT save the descendants. |
|
1414 | - * Also sets the transaction on this line item and all its descendants before saving |
|
1415 | - * |
|
1416 | - * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
|
1417 | - * @return int count of items saved |
|
1418 | - * @throws EE_Error |
|
1419 | - * @throws InvalidArgumentException |
|
1420 | - * @throws InvalidDataTypeException |
|
1421 | - * @throws InvalidInterfaceException |
|
1422 | - * @throws ReflectionException |
|
1423 | - */ |
|
1424 | - public function save_this_and_descendants_to_txn($txn_id = null) |
|
1425 | - { |
|
1426 | - $count = 0; |
|
1427 | - if (! $txn_id) { |
|
1428 | - $txn_id = $this->TXN_ID(); |
|
1429 | - } |
|
1430 | - $this->set_TXN_ID($txn_id); |
|
1431 | - $children = $this->children(); |
|
1432 | - $count += $this->save() |
|
1433 | - ? 1 |
|
1434 | - : 0; |
|
1435 | - foreach ($children as $child_line_item) { |
|
1436 | - if ($child_line_item instanceof EE_Line_Item) { |
|
1437 | - $child_line_item->set_parent_ID($this->ID()); |
|
1438 | - $count += $child_line_item->save_this_and_descendants_to_txn($txn_id); |
|
1439 | - } |
|
1440 | - } |
|
1441 | - return $count; |
|
1442 | - } |
|
1443 | - |
|
1444 | - |
|
1445 | - /** |
|
1446 | - * Saves this line item to the DB, and recursively saves its descendants. |
|
1447 | - * |
|
1448 | - * @return int count of items saved |
|
1449 | - * @throws EE_Error |
|
1450 | - * @throws InvalidArgumentException |
|
1451 | - * @throws InvalidDataTypeException |
|
1452 | - * @throws InvalidInterfaceException |
|
1453 | - * @throws ReflectionException |
|
1454 | - */ |
|
1455 | - public function save_this_and_descendants() |
|
1456 | - { |
|
1457 | - $count = 0; |
|
1458 | - $children = $this->children(); |
|
1459 | - $count += $this->save() |
|
1460 | - ? 1 |
|
1461 | - : 0; |
|
1462 | - foreach ($children as $child_line_item) { |
|
1463 | - if ($child_line_item instanceof EE_Line_Item) { |
|
1464 | - $child_line_item->set_parent_ID($this->ID()); |
|
1465 | - $count += $child_line_item->save_this_and_descendants(); |
|
1466 | - } |
|
1467 | - } |
|
1468 | - return $count; |
|
1469 | - } |
|
1470 | - |
|
1471 | - |
|
1472 | - /** |
|
1473 | - * returns the cancellation line item if this item was cancelled |
|
1474 | - * |
|
1475 | - * @return EE_Line_Item[] |
|
1476 | - * @throws InvalidArgumentException |
|
1477 | - * @throws InvalidInterfaceException |
|
1478 | - * @throws InvalidDataTypeException |
|
1479 | - * @throws ReflectionException |
|
1480 | - * @throws EE_Error |
|
1481 | - */ |
|
1482 | - public function get_cancellations() |
|
1483 | - { |
|
1484 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
1485 | - return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation); |
|
1486 | - } |
|
1487 | - |
|
1488 | - |
|
1489 | - /** |
|
1490 | - * If this item has an ID, then this saves it again to update the db |
|
1491 | - * |
|
1492 | - * @return int count of items saved |
|
1493 | - * @throws EE_Error |
|
1494 | - * @throws InvalidArgumentException |
|
1495 | - * @throws InvalidDataTypeException |
|
1496 | - * @throws InvalidInterfaceException |
|
1497 | - * @throws ReflectionException |
|
1498 | - */ |
|
1499 | - public function maybe_save() |
|
1500 | - { |
|
1501 | - if ($this->ID()) { |
|
1502 | - return $this->save(); |
|
1503 | - } |
|
1504 | - return false; |
|
1505 | - } |
|
1506 | - |
|
1507 | - |
|
1508 | - /** |
|
1509 | - * clears the cached children and parent from the line item |
|
1510 | - * |
|
1511 | - * @return void |
|
1512 | - */ |
|
1513 | - public function clear_related_line_item_cache() |
|
1514 | - { |
|
1515 | - $this->_children = []; |
|
1516 | - $this->_parent = null; |
|
1517 | - } |
|
1518 | - |
|
1519 | - |
|
1520 | - /** |
|
1521 | - * @param bool $raw |
|
1522 | - * @return int |
|
1523 | - * @throws EE_Error |
|
1524 | - * @throws InvalidArgumentException |
|
1525 | - * @throws InvalidDataTypeException |
|
1526 | - * @throws InvalidInterfaceException |
|
1527 | - * @throws ReflectionException |
|
1528 | - */ |
|
1529 | - public function timestamp($raw = false) |
|
1530 | - { |
|
1531 | - return $raw |
|
1532 | - ? $this->get_raw('LIN_timestamp') |
|
1533 | - : $this->get('LIN_timestamp'); |
|
1534 | - } |
|
1535 | - |
|
1536 | - |
|
1537 | - |
|
1538 | - |
|
1539 | - /************************* DEPRECATED *************************/ |
|
1540 | - /** |
|
1541 | - * @param string $type one of the constants on EEM_Line_Item |
|
1542 | - * @return EE_Line_Item[] |
|
1543 | - * @throws EE_Error |
|
1544 | - * @throws ReflectionException |
|
1545 | - * @deprecated 4.6.0 |
|
1546 | - */ |
|
1547 | - protected function _get_descendants_of_type($type) |
|
1548 | - { |
|
1549 | - EE_Error::doing_it_wrong( |
|
1550 | - 'EE_Line_Item::_get_descendants_of_type()', |
|
1551 | - sprintf( |
|
1552 | - esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
1553 | - 'EEH_Line_Item::get_descendants_of_type()' |
|
1554 | - ), |
|
1555 | - '4.6.0' |
|
1556 | - ); |
|
1557 | - return EEH_Line_Item::get_descendants_of_type($this, $type); |
|
1558 | - } |
|
1559 | - |
|
1560 | - |
|
1561 | - /** |
|
1562 | - * @param string $type like one of the EEM_Line_Item::type_* |
|
1563 | - * @return EE_Line_Item |
|
1564 | - * @throws EE_Error |
|
1565 | - * @throws InvalidArgumentException |
|
1566 | - * @throws InvalidDataTypeException |
|
1567 | - * @throws InvalidInterfaceException |
|
1568 | - * @throws ReflectionException |
|
1569 | - * @deprecated 4.6.0 |
|
1570 | - */ |
|
1571 | - public function get_nearest_descendant_of_type($type) |
|
1572 | - { |
|
1573 | - EE_Error::doing_it_wrong( |
|
1574 | - 'EE_Line_Item::get_nearest_descendant_of_type()', |
|
1575 | - sprintf( |
|
1576 | - esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
1577 | - 'EEH_Line_Item::get_nearest_descendant_of_type()' |
|
1578 | - ), |
|
1579 | - '4.6.0' |
|
1580 | - ); |
|
1581 | - return EEH_Line_Item::get_nearest_descendant_of_type($this, $type); |
|
1582 | - } |
|
19 | + /** |
|
20 | + * @var CurrencyFormatter |
|
21 | + * @since $VID:$ |
|
22 | + */ |
|
23 | + protected $currency_formatter; |
|
24 | + |
|
25 | + /** |
|
26 | + * for children line items (currently not a normal relation) |
|
27 | + * |
|
28 | + * @type EE_Line_Item[] |
|
29 | + */ |
|
30 | + protected $_children = []; |
|
31 | + |
|
32 | + /** |
|
33 | + * for the parent line item |
|
34 | + * |
|
35 | + * @var EE_Line_Item |
|
36 | + */ |
|
37 | + protected $_parent; |
|
38 | + |
|
39 | + /** |
|
40 | + * number of decimal places to round numbers to when performing calculations |
|
41 | + * |
|
42 | + * @var integer $decimal_precision |
|
43 | + */ |
|
44 | + protected $decimal_precision = 6; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var LineItemCalculator |
|
48 | + */ |
|
49 | + private $calculator; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var bool |
|
53 | + */ |
|
54 | + private $is_percent; |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @param array $props_n_values incoming values |
|
61 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
62 | + * used.) |
|
63 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
64 | + * date_format and the second value is the time format |
|
65 | + * @return EE_Line_Item |
|
66 | + * @throws EE_Error |
|
67 | + * @throws InvalidArgumentException |
|
68 | + * @throws InvalidDataTypeException |
|
69 | + * @throws InvalidInterfaceException |
|
70 | + * @throws ReflectionException |
|
71 | + */ |
|
72 | + public static function new_instance($props_n_values = [], $timezone = null, $date_formats = []) |
|
73 | + { |
|
74 | + $has_object = parent::_check_for_object( |
|
75 | + $props_n_values, |
|
76 | + EE_Line_Item::class, |
|
77 | + $timezone, |
|
78 | + $date_formats |
|
79 | + ); |
|
80 | + return $has_object |
|
81 | + ? $has_object |
|
82 | + : new EE_Line_Item($props_n_values, false, $timezone, $date_formats); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @param array $props_n_values incoming values from the database |
|
88 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
89 | + * the website will be used. |
|
90 | + * @return EE_Line_Item |
|
91 | + * @throws EE_Error |
|
92 | + * @throws InvalidArgumentException |
|
93 | + * @throws InvalidDataTypeException |
|
94 | + * @throws InvalidInterfaceException |
|
95 | + * @throws ReflectionException |
|
96 | + */ |
|
97 | + public static function new_instance_from_db($props_n_values = [], $timezone = null) |
|
98 | + { |
|
99 | + return new EE_Line_Item($props_n_values, true, $timezone); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Adds some defaults if they're not specified |
|
105 | + * |
|
106 | + * @param array $fieldValues |
|
107 | + * @param bool $bydb |
|
108 | + * @param string $timezone |
|
109 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
110 | + * date_format and the second value is the time format |
|
111 | + * @throws EE_Error |
|
112 | + * @throws InvalidArgumentException |
|
113 | + * @throws InvalidDataTypeException |
|
114 | + * @throws InvalidInterfaceException |
|
115 | + * @throws ReflectionException |
|
116 | + */ |
|
117 | + protected function __construct($fieldValues = [], $bydb = false, $timezone = '', $date_formats = []) |
|
118 | + { |
|
119 | + if (! $this->calculator instanceof LineItemCalculator) { |
|
120 | + $this->calculator = LoaderFactory::getLoader()->getShared(LineItemCalculator::class); |
|
121 | + } |
|
122 | + parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
123 | + if (! $this->get('LIN_code')) { |
|
124 | + $this->set_code($this->generate_code()); |
|
125 | + } |
|
126 | + // in a better world this would have been injected upon construction |
|
127 | + if (! $this->currency_formatter instanceof CurrencyFormatter) { |
|
128 | + $this->currency_formatter = LoaderFactory::getLoader()->getShared(CurrencyFormatter::class); |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @param int $decimal_precision |
|
135 | + */ |
|
136 | + public function setDecimalPrecision($decimal_precision = 6) |
|
137 | + { |
|
138 | + $this->decimal_precision = absint($decimal_precision); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * Gets ID |
|
144 | + * |
|
145 | + * @return int |
|
146 | + * @throws EE_Error |
|
147 | + * @throws InvalidArgumentException |
|
148 | + * @throws InvalidDataTypeException |
|
149 | + * @throws InvalidInterfaceException |
|
150 | + * @throws ReflectionException |
|
151 | + */ |
|
152 | + public function ID() |
|
153 | + { |
|
154 | + return $this->get('LIN_ID'); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * Gets TXN_ID |
|
160 | + * |
|
161 | + * @return int |
|
162 | + * @throws EE_Error |
|
163 | + * @throws InvalidArgumentException |
|
164 | + * @throws InvalidDataTypeException |
|
165 | + * @throws InvalidInterfaceException |
|
166 | + * @throws ReflectionException |
|
167 | + */ |
|
168 | + public function TXN_ID() |
|
169 | + { |
|
170 | + return $this->get('TXN_ID'); |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Sets TXN_ID |
|
176 | + * |
|
177 | + * @param int $TXN_ID |
|
178 | + * @throws EE_Error |
|
179 | + * @throws InvalidArgumentException |
|
180 | + * @throws InvalidDataTypeException |
|
181 | + * @throws InvalidInterfaceException |
|
182 | + * @throws ReflectionException |
|
183 | + */ |
|
184 | + public function set_TXN_ID($TXN_ID) |
|
185 | + { |
|
186 | + $this->set('TXN_ID', $TXN_ID); |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * Gets name |
|
192 | + * |
|
193 | + * @return string |
|
194 | + * @throws EE_Error |
|
195 | + * @throws InvalidArgumentException |
|
196 | + * @throws InvalidDataTypeException |
|
197 | + * @throws InvalidInterfaceException |
|
198 | + * @throws ReflectionException |
|
199 | + */ |
|
200 | + public function name() |
|
201 | + { |
|
202 | + $name = $this->get('LIN_name'); |
|
203 | + if (! $name) { |
|
204 | + $name = ucwords(str_replace('-', ' ', $this->type())); |
|
205 | + } |
|
206 | + return $name; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Sets name |
|
212 | + * |
|
213 | + * @param string $name |
|
214 | + * @throws EE_Error |
|
215 | + * @throws InvalidArgumentException |
|
216 | + * @throws InvalidDataTypeException |
|
217 | + * @throws InvalidInterfaceException |
|
218 | + * @throws ReflectionException |
|
219 | + */ |
|
220 | + public function set_name($name) |
|
221 | + { |
|
222 | + $this->set('LIN_name', $name); |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * Gets desc |
|
228 | + * |
|
229 | + * @return string |
|
230 | + * @throws EE_Error |
|
231 | + * @throws InvalidArgumentException |
|
232 | + * @throws InvalidDataTypeException |
|
233 | + * @throws InvalidInterfaceException |
|
234 | + * @throws ReflectionException |
|
235 | + */ |
|
236 | + public function desc() |
|
237 | + { |
|
238 | + return $this->get('LIN_desc'); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * Sets desc |
|
244 | + * |
|
245 | + * @param string $desc |
|
246 | + * @throws EE_Error |
|
247 | + * @throws InvalidArgumentException |
|
248 | + * @throws InvalidDataTypeException |
|
249 | + * @throws InvalidInterfaceException |
|
250 | + * @throws ReflectionException |
|
251 | + */ |
|
252 | + public function set_desc($desc) |
|
253 | + { |
|
254 | + $this->set('LIN_desc', $desc); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Gets quantity |
|
260 | + * |
|
261 | + * @return int |
|
262 | + * @throws EE_Error |
|
263 | + * @throws InvalidArgumentException |
|
264 | + * @throws InvalidDataTypeException |
|
265 | + * @throws InvalidInterfaceException |
|
266 | + * @throws ReflectionException |
|
267 | + */ |
|
268 | + public function quantity() |
|
269 | + { |
|
270 | + return $this->get('LIN_quantity'); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * Sets quantity |
|
276 | + * |
|
277 | + * @param int $quantity |
|
278 | + * @throws EE_Error |
|
279 | + * @throws InvalidArgumentException |
|
280 | + * @throws InvalidDataTypeException |
|
281 | + * @throws InvalidInterfaceException |
|
282 | + * @throws ReflectionException |
|
283 | + */ |
|
284 | + public function set_quantity($quantity) |
|
285 | + { |
|
286 | + $this->set('LIN_quantity', max($quantity, 0)); |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * Gets item_id |
|
292 | + * |
|
293 | + * @return int|string |
|
294 | + * @throws EE_Error |
|
295 | + * @throws InvalidArgumentException |
|
296 | + * @throws InvalidDataTypeException |
|
297 | + * @throws InvalidInterfaceException |
|
298 | + * @throws ReflectionException |
|
299 | + */ |
|
300 | + public function OBJ_ID() |
|
301 | + { |
|
302 | + return $this->get('OBJ_ID'); |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * Sets item_id |
|
308 | + * |
|
309 | + * @param int|string $item_id |
|
310 | + * @throws EE_Error |
|
311 | + * @throws InvalidArgumentException |
|
312 | + * @throws InvalidDataTypeException |
|
313 | + * @throws InvalidInterfaceException |
|
314 | + * @throws ReflectionException |
|
315 | + */ |
|
316 | + public function set_OBJ_ID($item_id) |
|
317 | + { |
|
318 | + $this->set('OBJ_ID', $item_id); |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Gets item_type |
|
324 | + * |
|
325 | + * @return string |
|
326 | + * @throws EE_Error |
|
327 | + * @throws InvalidArgumentException |
|
328 | + * @throws InvalidDataTypeException |
|
329 | + * @throws InvalidInterfaceException |
|
330 | + * @throws ReflectionException |
|
331 | + */ |
|
332 | + public function OBJ_type() |
|
333 | + { |
|
334 | + return $this->get('OBJ_type'); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * Gets item_type |
|
340 | + * |
|
341 | + * @return string |
|
342 | + * @throws EE_Error |
|
343 | + * @throws InvalidArgumentException |
|
344 | + * @throws InvalidDataTypeException |
|
345 | + * @throws InvalidInterfaceException |
|
346 | + * @throws ReflectionException |
|
347 | + */ |
|
348 | + public function OBJ_type_i18n() |
|
349 | + { |
|
350 | + $obj_type = $this->OBJ_type(); |
|
351 | + switch ($obj_type) { |
|
352 | + case EEM_Line_Item::OBJ_TYPE_EVENT: |
|
353 | + $obj_type = esc_html__('Event', 'event_espresso'); |
|
354 | + break; |
|
355 | + case EEM_Line_Item::OBJ_TYPE_PRICE: |
|
356 | + $obj_type = esc_html__('Price', 'event_espresso'); |
|
357 | + break; |
|
358 | + case EEM_Line_Item::OBJ_TYPE_PROMOTION: |
|
359 | + $obj_type = esc_html__('Promotion', 'event_espresso'); |
|
360 | + break; |
|
361 | + case EEM_Line_Item::OBJ_TYPE_TICKET: |
|
362 | + $obj_type = esc_html__('Ticket', 'event_espresso'); |
|
363 | + break; |
|
364 | + case EEM_Line_Item::OBJ_TYPE_TRANSACTION: |
|
365 | + $obj_type = esc_html__('Transaction', 'event_espresso'); |
|
366 | + break; |
|
367 | + } |
|
368 | + return apply_filters('FHEE__EE_Line_Item__OBJ_type_i18n', $obj_type, $this); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Sets item_type |
|
374 | + * |
|
375 | + * @param string $OBJ_type |
|
376 | + * @throws EE_Error |
|
377 | + * @throws InvalidArgumentException |
|
378 | + * @throws InvalidDataTypeException |
|
379 | + * @throws InvalidInterfaceException |
|
380 | + * @throws ReflectionException |
|
381 | + */ |
|
382 | + public function set_OBJ_type($OBJ_type) |
|
383 | + { |
|
384 | + $this->set('OBJ_type', $OBJ_type); |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * Gets unit_price for flat rate items. Percent items should set this to 0. |
|
390 | + * You may alternatively want to use prettyUnitPrice(), which works for flat and percent items. |
|
391 | + * |
|
392 | + * @param string $schema |
|
393 | + * @return float |
|
394 | + * @throws EE_Error |
|
395 | + * @throws ReflectionException |
|
396 | + */ |
|
397 | + public function unit_price($schema = 'localized_float') |
|
398 | + { |
|
399 | + return $this->get('LIN_unit_price', $schema); |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * @param string $schema |
|
405 | + * @return mixed|string |
|
406 | + * @throws EE_Error |
|
407 | + * @throws ReflectionException |
|
408 | + * @since $VID:$ |
|
409 | + */ |
|
410 | + public function prettyUnitPrice($schema = 'localized_currency') |
|
411 | + { |
|
412 | + if ($this->is_percent()) { |
|
413 | + $quantity = $this->parent() instanceof EE_Line_Item |
|
414 | + && $this->parent()->type() === EEM_Line_Item::type_line_item |
|
415 | + ? $this->parent()->quantity() |
|
416 | + : $this->quantity(); |
|
417 | + if ($quantity !== 0) { |
|
418 | + $percent = $this->total() / $quantity; |
|
419 | + $percent = $this->currency_formatter->roundForLocale($percent); |
|
420 | + return apply_filters('FHEE__format_percentage_value', $percent); |
|
421 | + } |
|
422 | + } |
|
423 | + return $this->get_pretty('LIN_unit_price', $schema); |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * Sets unit_price |
|
429 | + * |
|
430 | + * @param float $unit_price |
|
431 | + * @throws EE_Error |
|
432 | + * @throws ReflectionException |
|
433 | + */ |
|
434 | + public function set_unit_price($unit_price) |
|
435 | + { |
|
436 | + $this->set('LIN_unit_price', $unit_price); |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * Checks if this item is a percentage modifier or not |
|
442 | + * |
|
443 | + * @return boolean |
|
444 | + * @throws EE_Error |
|
445 | + * @throws InvalidArgumentException |
|
446 | + * @throws InvalidDataTypeException |
|
447 | + * @throws InvalidInterfaceException |
|
448 | + * @throws ReflectionException |
|
449 | + */ |
|
450 | + public function is_percent() |
|
451 | + { |
|
452 | + if ($this->is_percent !== null) { |
|
453 | + return $this->is_percent; |
|
454 | + } |
|
455 | + if ($this->is_tax_sub_total()) { |
|
456 | + // tax subtotals HAVE a percent on them, that percentage only applies |
|
457 | + // to taxable items, so its' an exception. Treat it like a flat line item |
|
458 | + $this->is_percent = false; |
|
459 | + return $this->is_percent; |
|
460 | + } |
|
461 | + $unit_price = abs($this->get('LIN_unit_price')); |
|
462 | + $percent = abs($this->get('LIN_percent')); |
|
463 | + if ($unit_price < .001 && $percent) { |
|
464 | + $this->is_percent = true; |
|
465 | + return $this->is_percent; |
|
466 | + } |
|
467 | + if ($unit_price >= .001 && ! $percent) { |
|
468 | + $this->is_percent = false; |
|
469 | + return $this->is_percent; |
|
470 | + } |
|
471 | + if ($unit_price >= .001 && $percent) { |
|
472 | + throw new EE_Error( |
|
473 | + sprintf( |
|
474 | + esc_html__( |
|
475 | + 'A Line Item can not have a unit price of (%s) AND a percent (%s)!', |
|
476 | + 'event_espresso' |
|
477 | + ), |
|
478 | + $unit_price, |
|
479 | + $percent |
|
480 | + ) |
|
481 | + ); |
|
482 | + } |
|
483 | + // if they're both 0, assume its not a percent item |
|
484 | + $this->is_percent = false; |
|
485 | + return $this->is_percent; |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * Gets percent (between 100-.001) |
|
491 | + * |
|
492 | + * @param bool $as_decimal if true will divide value by 100 |
|
493 | + * @return float |
|
494 | + * @throws EE_Error |
|
495 | + * @throws ReflectionException |
|
496 | + */ |
|
497 | + public function percent($as_decimal = false) |
|
498 | + { |
|
499 | + $percent = $this->get('LIN_percent'); |
|
500 | + $percent = $as_decimal ? $percent / 100 : $percent; |
|
501 | + return $this->currency_formatter->precisionRound($percent); |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + /** |
|
506 | + * Gets percent (between 100-.001) |
|
507 | + * |
|
508 | + * @return float |
|
509 | + * @throws EE_Error |
|
510 | + * @throws ReflectionException |
|
511 | + */ |
|
512 | + public function prettyPercent() |
|
513 | + { |
|
514 | + return apply_filters('FHEE__format_percentage_value', $this->get_pretty('LIN_percent')); |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * Sets percent (between 100-0.01) |
|
520 | + * |
|
521 | + * @param float $percent |
|
522 | + * @throws EE_Error |
|
523 | + * @throws InvalidArgumentException |
|
524 | + * @throws InvalidDataTypeException |
|
525 | + * @throws InvalidInterfaceException |
|
526 | + * @throws ReflectionException |
|
527 | + */ |
|
528 | + public function set_percent($percent) |
|
529 | + { |
|
530 | + $this->set('LIN_percent', $percent); |
|
531 | + } |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * Gets total |
|
536 | + * |
|
537 | + * @param string $schema |
|
538 | + * @return float |
|
539 | + * @throws EE_Error |
|
540 | + * @throws ReflectionException |
|
541 | + */ |
|
542 | + public function total($schema = 'localized_float') |
|
543 | + { |
|
544 | + return $this->get('LIN_total', $schema); |
|
545 | + } |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * @param string $schema |
|
550 | + * @return string |
|
551 | + * @throws EE_Error |
|
552 | + * @throws InvalidArgumentException |
|
553 | + * @throws InvalidDataTypeException |
|
554 | + * @throws InvalidInterfaceException |
|
555 | + * @throws ReflectionException |
|
556 | + */ |
|
557 | + public function prettyTotal($schema = 'localized_currency') |
|
558 | + { |
|
559 | + return $this->get_pretty('LIN_total', $schema); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * Sets total |
|
565 | + * |
|
566 | + * @param float $total |
|
567 | + * @throws EE_Error |
|
568 | + * @throws ReflectionException |
|
569 | + */ |
|
570 | + public function set_total($total) |
|
571 | + { |
|
572 | + $this->set('LIN_total', $total); |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + /** |
|
577 | + * Gets order |
|
578 | + * |
|
579 | + * @return int |
|
580 | + * @throws EE_Error |
|
581 | + * @throws InvalidArgumentException |
|
582 | + * @throws InvalidDataTypeException |
|
583 | + * @throws InvalidInterfaceException |
|
584 | + * @throws ReflectionException |
|
585 | + */ |
|
586 | + public function order() |
|
587 | + { |
|
588 | + return $this->get('LIN_order'); |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + /** |
|
593 | + * Sets order |
|
594 | + * |
|
595 | + * @param int $order |
|
596 | + * @throws EE_Error |
|
597 | + * @throws InvalidArgumentException |
|
598 | + * @throws InvalidDataTypeException |
|
599 | + * @throws InvalidInterfaceException |
|
600 | + * @throws ReflectionException |
|
601 | + */ |
|
602 | + public function set_order($order) |
|
603 | + { |
|
604 | + $this->set('LIN_order', $order); |
|
605 | + } |
|
606 | + |
|
607 | + |
|
608 | + /** |
|
609 | + * Gets parent |
|
610 | + * |
|
611 | + * @return int |
|
612 | + * @throws EE_Error |
|
613 | + * @throws InvalidArgumentException |
|
614 | + * @throws InvalidDataTypeException |
|
615 | + * @throws InvalidInterfaceException |
|
616 | + * @throws ReflectionException |
|
617 | + */ |
|
618 | + public function parent_ID() |
|
619 | + { |
|
620 | + return $this->get('LIN_parent'); |
|
621 | + } |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * Sets parent |
|
626 | + * |
|
627 | + * @param int $parent |
|
628 | + * @throws EE_Error |
|
629 | + * @throws InvalidArgumentException |
|
630 | + * @throws InvalidDataTypeException |
|
631 | + * @throws InvalidInterfaceException |
|
632 | + * @throws ReflectionException |
|
633 | + */ |
|
634 | + public function set_parent_ID($parent) |
|
635 | + { |
|
636 | + $this->set('LIN_parent', $parent); |
|
637 | + } |
|
638 | + |
|
639 | + |
|
640 | + /** |
|
641 | + * Gets type |
|
642 | + * |
|
643 | + * @return string |
|
644 | + * @throws EE_Error |
|
645 | + * @throws InvalidArgumentException |
|
646 | + * @throws InvalidDataTypeException |
|
647 | + * @throws InvalidInterfaceException |
|
648 | + * @throws ReflectionException |
|
649 | + */ |
|
650 | + public function type() |
|
651 | + { |
|
652 | + return $this->get('LIN_type'); |
|
653 | + } |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * Sets type |
|
658 | + * |
|
659 | + * @param string $type |
|
660 | + * @throws EE_Error |
|
661 | + * @throws InvalidArgumentException |
|
662 | + * @throws InvalidDataTypeException |
|
663 | + * @throws InvalidInterfaceException |
|
664 | + * @throws ReflectionException |
|
665 | + */ |
|
666 | + public function set_type($type) |
|
667 | + { |
|
668 | + $this->set('LIN_type', $type); |
|
669 | + } |
|
670 | + |
|
671 | + |
|
672 | + /** |
|
673 | + * Gets the line item of which this item is a composite. Eg, if this is a subtotal, the parent might be a total\ |
|
674 | + * If this line item is saved to the DB, fetches the parent from the DB. However, if this line item isn't in the DB |
|
675 | + * it uses its cached reference to its parent line item (which would have been set by `EE_Line_Item::set_parent()` |
|
676 | + * or indirectly by `EE_Line_item::add_child_line_item()`) |
|
677 | + * |
|
678 | + * @return EE_Base_Class|EE_Line_Item |
|
679 | + * @throws EE_Error |
|
680 | + * @throws InvalidArgumentException |
|
681 | + * @throws InvalidDataTypeException |
|
682 | + * @throws InvalidInterfaceException |
|
683 | + * @throws ReflectionException |
|
684 | + */ |
|
685 | + public function parent() |
|
686 | + { |
|
687 | + return $this->ID() |
|
688 | + ? $this->get_model()->get_one_by_ID($this->parent_ID()) |
|
689 | + : $this->_parent; |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * Gets ALL the children of this line item (ie, all the parts that contribute towards this total). |
|
695 | + * |
|
696 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
697 | + * @throws EE_Error |
|
698 | + * @throws InvalidArgumentException |
|
699 | + * @throws InvalidDataTypeException |
|
700 | + * @throws InvalidInterfaceException |
|
701 | + * @throws ReflectionException |
|
702 | + */ |
|
703 | + public function children() |
|
704 | + { |
|
705 | + if ($this->ID()) { |
|
706 | + return $this->get_model()->get_all( |
|
707 | + [ |
|
708 | + ['LIN_parent' => $this->ID()], |
|
709 | + 'order_by' => ['LIN_order' => 'ASC'], |
|
710 | + ] |
|
711 | + ); |
|
712 | + } |
|
713 | + if (! is_array($this->_children)) { |
|
714 | + $this->_children = []; |
|
715 | + } |
|
716 | + return $this->_children; |
|
717 | + } |
|
718 | + |
|
719 | + |
|
720 | + /** |
|
721 | + * Gets code |
|
722 | + * |
|
723 | + * @return string |
|
724 | + * @throws EE_Error |
|
725 | + * @throws InvalidArgumentException |
|
726 | + * @throws InvalidDataTypeException |
|
727 | + * @throws InvalidInterfaceException |
|
728 | + * @throws ReflectionException |
|
729 | + */ |
|
730 | + public function code() |
|
731 | + { |
|
732 | + return $this->get('LIN_code'); |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * Sets code |
|
738 | + * |
|
739 | + * @param string $code |
|
740 | + * @throws EE_Error |
|
741 | + * @throws InvalidArgumentException |
|
742 | + * @throws InvalidDataTypeException |
|
743 | + * @throws InvalidInterfaceException |
|
744 | + * @throws ReflectionException |
|
745 | + */ |
|
746 | + public function set_code($code) |
|
747 | + { |
|
748 | + $this->set('LIN_code', $code); |
|
749 | + } |
|
750 | + |
|
751 | + |
|
752 | + /** |
|
753 | + * Gets is_taxable |
|
754 | + * |
|
755 | + * @return boolean |
|
756 | + * @throws EE_Error |
|
757 | + * @throws InvalidArgumentException |
|
758 | + * @throws InvalidDataTypeException |
|
759 | + * @throws InvalidInterfaceException |
|
760 | + * @throws ReflectionException |
|
761 | + */ |
|
762 | + public function is_taxable() |
|
763 | + { |
|
764 | + return $this->get('LIN_is_taxable'); |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * Sets is_taxable |
|
770 | + * |
|
771 | + * @param boolean $is_taxable |
|
772 | + * @throws EE_Error |
|
773 | + * @throws InvalidArgumentException |
|
774 | + * @throws InvalidDataTypeException |
|
775 | + * @throws InvalidInterfaceException |
|
776 | + * @throws ReflectionException |
|
777 | + */ |
|
778 | + public function set_is_taxable($is_taxable) |
|
779 | + { |
|
780 | + $this->set('LIN_is_taxable', $is_taxable); |
|
781 | + } |
|
782 | + |
|
783 | + |
|
784 | + /** |
|
785 | + * Gets the object that this model-joins-to. |
|
786 | + * returns one of the model objects that the field OBJ_ID can point to... see the 'OBJ_ID' field on |
|
787 | + * EEM_Promotion_Object |
|
788 | + * Eg, if this line item join model object is for a ticket, this will return the EE_Ticket object |
|
789 | + * |
|
790 | + * @return EE_Base_Class | NULL |
|
791 | + * @throws EE_Error |
|
792 | + * @throws InvalidArgumentException |
|
793 | + * @throws InvalidDataTypeException |
|
794 | + * @throws InvalidInterfaceException |
|
795 | + * @throws ReflectionException |
|
796 | + */ |
|
797 | + public function get_object() |
|
798 | + { |
|
799 | + $model_name_of_related_obj = $this->OBJ_type(); |
|
800 | + return $this->get_model()->has_relation($model_name_of_related_obj) |
|
801 | + ? $this->get_first_related($model_name_of_related_obj) |
|
802 | + : null; |
|
803 | + } |
|
804 | + |
|
805 | + |
|
806 | + /** |
|
807 | + * Like EE_Line_Item::get_object(), but can only ever actually return an EE_Ticket. |
|
808 | + * (IE, if this line item is for a price or something else, will return NULL) |
|
809 | + * |
|
810 | + * @param array $query_params |
|
811 | + * @return EE_Base_Class|EE_Ticket |
|
812 | + * @throws EE_Error |
|
813 | + * @throws InvalidArgumentException |
|
814 | + * @throws InvalidDataTypeException |
|
815 | + * @throws InvalidInterfaceException |
|
816 | + * @throws ReflectionException |
|
817 | + */ |
|
818 | + public function ticket($query_params = []) |
|
819 | + { |
|
820 | + // we're going to assume that when this method is called |
|
821 | + // we always want to receive the attached ticket EVEN if that ticket is archived. |
|
822 | + // This can be overridden via the incoming $query_params argument |
|
823 | + $remove_defaults = ['default_where_conditions' => 'none']; |
|
824 | + $query_params = array_merge($remove_defaults, $query_params); |
|
825 | + return $this->get_first_related(EEM_Line_Item::OBJ_TYPE_TICKET, $query_params); |
|
826 | + } |
|
827 | + |
|
828 | + |
|
829 | + /** |
|
830 | + * Gets the EE_Datetime that's related to the ticket, IF this is for a ticket |
|
831 | + * |
|
832 | + * @return EE_Datetime | NULL |
|
833 | + * @throws EE_Error |
|
834 | + * @throws InvalidArgumentException |
|
835 | + * @throws InvalidDataTypeException |
|
836 | + * @throws InvalidInterfaceException |
|
837 | + * @throws ReflectionException |
|
838 | + */ |
|
839 | + public function get_ticket_datetime() |
|
840 | + { |
|
841 | + if ($this->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
842 | + $ticket = $this->ticket(); |
|
843 | + if ($ticket instanceof EE_Ticket) { |
|
844 | + $datetime = $ticket->first_datetime(); |
|
845 | + if ($datetime instanceof EE_Datetime) { |
|
846 | + return $datetime; |
|
847 | + } |
|
848 | + } |
|
849 | + } |
|
850 | + return null; |
|
851 | + } |
|
852 | + |
|
853 | + |
|
854 | + /** |
|
855 | + * Gets the event's name that's related to the ticket, if this is for |
|
856 | + * a ticket |
|
857 | + * |
|
858 | + * @return string |
|
859 | + * @throws EE_Error |
|
860 | + * @throws InvalidArgumentException |
|
861 | + * @throws InvalidDataTypeException |
|
862 | + * @throws InvalidInterfaceException |
|
863 | + * @throws ReflectionException |
|
864 | + */ |
|
865 | + public function ticket_event_name() |
|
866 | + { |
|
867 | + $event_name = esc_html__('Unknown', 'event_espresso'); |
|
868 | + $event = $this->ticket_event(); |
|
869 | + if ($event instanceof EE_Event) { |
|
870 | + $event_name = $event->name(); |
|
871 | + } |
|
872 | + return $event_name; |
|
873 | + } |
|
874 | + |
|
875 | + |
|
876 | + /** |
|
877 | + * Gets the event that's related to the ticket, if this line item represents a ticket. |
|
878 | + * |
|
879 | + * @return EE_Event|null |
|
880 | + * @throws EE_Error |
|
881 | + * @throws InvalidArgumentException |
|
882 | + * @throws InvalidDataTypeException |
|
883 | + * @throws InvalidInterfaceException |
|
884 | + * @throws ReflectionException |
|
885 | + */ |
|
886 | + public function ticket_event() |
|
887 | + { |
|
888 | + $event = null; |
|
889 | + $ticket = $this->ticket(); |
|
890 | + if ($ticket instanceof EE_Ticket) { |
|
891 | + $datetime = $ticket->first_datetime(); |
|
892 | + if ($datetime instanceof EE_Datetime) { |
|
893 | + $event = $datetime->event(); |
|
894 | + } |
|
895 | + } |
|
896 | + return $event; |
|
897 | + } |
|
898 | + |
|
899 | + |
|
900 | + /** |
|
901 | + * Gets the first datetime for this lien item, assuming it's for a ticket |
|
902 | + * |
|
903 | + * @param string $date_format |
|
904 | + * @param string $time_format |
|
905 | + * @return string |
|
906 | + * @throws EE_Error |
|
907 | + * @throws InvalidArgumentException |
|
908 | + * @throws InvalidDataTypeException |
|
909 | + * @throws InvalidInterfaceException |
|
910 | + * @throws ReflectionException |
|
911 | + */ |
|
912 | + public function ticket_datetime_start($date_format = '', $time_format = '') |
|
913 | + { |
|
914 | + $first_datetime_string = esc_html__('Unknown', 'event_espresso'); |
|
915 | + $datetime = $this->get_ticket_datetime(); |
|
916 | + if ($datetime) { |
|
917 | + $first_datetime_string = $datetime->start_date_and_time($date_format, $time_format); |
|
918 | + } |
|
919 | + return $first_datetime_string; |
|
920 | + } |
|
921 | + |
|
922 | + |
|
923 | + /** |
|
924 | + * Adds the line item as a child to this line item. If there is another child line |
|
925 | + * item with the same LIN_code, it is overwritten by this new one |
|
926 | + * |
|
927 | + * @param EEI_Line_Item|EE_Line_Item $line_item |
|
928 | + * @param bool $set_order |
|
929 | + * @return bool success |
|
930 | + * @throws EE_Error |
|
931 | + * @throws InvalidArgumentException |
|
932 | + * @throws InvalidDataTypeException |
|
933 | + * @throws InvalidInterfaceException |
|
934 | + * @throws ReflectionException |
|
935 | + */ |
|
936 | + public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true) |
|
937 | + { |
|
938 | + // should we calculate the LIN_order for this line item ? |
|
939 | + if ($set_order || $line_item->order() === null) { |
|
940 | + $line_item->set_order(count($this->children())); |
|
941 | + } |
|
942 | + if ($this->ID()) { |
|
943 | + // check for any duplicate line items (with the same code), if so, this replaces it |
|
944 | + $line_item_with_same_code = $this->get_child_line_item($line_item->code()); |
|
945 | + if (($line_item_with_same_code instanceof EE_Line_Item) && $line_item_with_same_code !== $line_item) { |
|
946 | + $this->delete_child_line_item($line_item_with_same_code->code()); |
|
947 | + } |
|
948 | + $line_item->set_parent_ID($this->ID()); |
|
949 | + if ($this->TXN_ID()) { |
|
950 | + $line_item->set_TXN_ID($this->TXN_ID()); |
|
951 | + } |
|
952 | + return $line_item->save(); |
|
953 | + } |
|
954 | + $this->_children[ $line_item->code() ] = $line_item; |
|
955 | + if ($line_item->parent() !== $this) { |
|
956 | + $line_item->set_parent($this); |
|
957 | + } |
|
958 | + return true; |
|
959 | + } |
|
960 | + |
|
961 | + |
|
962 | + /** |
|
963 | + * Similar to EE_Base_Class::_add_relation_to, except this isn't a normal relation. |
|
964 | + * If this line item is saved to the DB, this is just a wrapper for set_parent_ID() and save() |
|
965 | + * However, if this line item is NOT saved to the DB, this just caches the parent on |
|
966 | + * the EE_Line_Item::_parent property. |
|
967 | + * |
|
968 | + * @param EE_Line_Item $line_item |
|
969 | + * @throws EE_Error |
|
970 | + * @throws InvalidArgumentException |
|
971 | + * @throws InvalidDataTypeException |
|
972 | + * @throws InvalidInterfaceException |
|
973 | + * @throws ReflectionException |
|
974 | + */ |
|
975 | + public function set_parent($line_item) |
|
976 | + { |
|
977 | + if ($this->ID()) { |
|
978 | + if (! $line_item->ID()) { |
|
979 | + $line_item->save(); |
|
980 | + } |
|
981 | + $this->set_parent_ID($line_item->ID()); |
|
982 | + $this->save(); |
|
983 | + } else { |
|
984 | + $this->_parent = $line_item; |
|
985 | + $this->set_parent_ID($line_item->ID()); |
|
986 | + } |
|
987 | + } |
|
988 | + |
|
989 | + |
|
990 | + /** |
|
991 | + * Gets the child line item as specified by its code. Because this returns an object (by reference) |
|
992 | + * you can modify this child line item and the parent (this object) can know about them |
|
993 | + * because it also has a reference to that line item |
|
994 | + * |
|
995 | + * @param string $code |
|
996 | + * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
997 | + * @throws EE_Error |
|
998 | + * @throws InvalidArgumentException |
|
999 | + * @throws InvalidDataTypeException |
|
1000 | + * @throws InvalidInterfaceException |
|
1001 | + * @throws ReflectionException |
|
1002 | + */ |
|
1003 | + public function get_child_line_item($code) |
|
1004 | + { |
|
1005 | + if ($this->ID()) { |
|
1006 | + return $this->get_model()->get_one( |
|
1007 | + [['LIN_parent' => $this->ID(), 'LIN_code' => $code]] |
|
1008 | + ); |
|
1009 | + } |
|
1010 | + return isset($this->_children[ $code ]) |
|
1011 | + ? $this->_children[ $code ] |
|
1012 | + : null; |
|
1013 | + } |
|
1014 | + |
|
1015 | + |
|
1016 | + /** |
|
1017 | + * Returns how many items are deleted (or, if this item has not been saved ot the DB yet, just how many it HAD |
|
1018 | + * cached on it) |
|
1019 | + * |
|
1020 | + * @return int |
|
1021 | + * @throws EE_Error |
|
1022 | + * @throws InvalidArgumentException |
|
1023 | + * @throws InvalidDataTypeException |
|
1024 | + * @throws InvalidInterfaceException |
|
1025 | + * @throws ReflectionException |
|
1026 | + */ |
|
1027 | + public function delete_children_line_items() |
|
1028 | + { |
|
1029 | + if ($this->ID()) { |
|
1030 | + return $this->get_model()->delete([['LIN_parent' => $this->ID()]]); |
|
1031 | + } |
|
1032 | + $count = count($this->_children); |
|
1033 | + $this->_children = []; |
|
1034 | + return $count; |
|
1035 | + } |
|
1036 | + |
|
1037 | + |
|
1038 | + /** |
|
1039 | + * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line |
|
1040 | + * HAS NOT been saved to the DB, removes the child line item with index $code. |
|
1041 | + * Also searches through the child's children for a matching line item. However, once a line item has been found |
|
1042 | + * and deleted, stops searching (so if there are line items with duplicate codes, only the first one found will be |
|
1043 | + * deleted) |
|
1044 | + * |
|
1045 | + * @param string $code |
|
1046 | + * @param bool $stop_search_once_found |
|
1047 | + * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to |
|
1048 | + * the DB yet) |
|
1049 | + * @throws EE_Error |
|
1050 | + * @throws InvalidArgumentException |
|
1051 | + * @throws InvalidDataTypeException |
|
1052 | + * @throws InvalidInterfaceException |
|
1053 | + * @throws ReflectionException |
|
1054 | + */ |
|
1055 | + public function delete_child_line_item($code, $stop_search_once_found = true) |
|
1056 | + { |
|
1057 | + if ($this->ID()) { |
|
1058 | + $items_deleted = 0; |
|
1059 | + if ($this->code() === $code) { |
|
1060 | + $items_deleted += EEH_Line_Item::delete_all_child_items($this); |
|
1061 | + $items_deleted += (int) $this->delete(); |
|
1062 | + if ($stop_search_once_found) { |
|
1063 | + return $items_deleted; |
|
1064 | + } |
|
1065 | + } |
|
1066 | + foreach ($this->children() as $child_line_item) { |
|
1067 | + $items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found); |
|
1068 | + } |
|
1069 | + return $items_deleted; |
|
1070 | + } |
|
1071 | + if (isset($this->_children[ $code ])) { |
|
1072 | + unset($this->_children[ $code ]); |
|
1073 | + return 1; |
|
1074 | + } |
|
1075 | + return 0; |
|
1076 | + } |
|
1077 | + |
|
1078 | + |
|
1079 | + /** |
|
1080 | + * If this line item is in the database, is of the type subtotal, and |
|
1081 | + * has no children, why do we have it? It should be deleted so this function |
|
1082 | + * does that |
|
1083 | + * |
|
1084 | + * @return boolean |
|
1085 | + * @throws EE_Error |
|
1086 | + * @throws InvalidArgumentException |
|
1087 | + * @throws InvalidDataTypeException |
|
1088 | + * @throws InvalidInterfaceException |
|
1089 | + * @throws ReflectionException |
|
1090 | + */ |
|
1091 | + public function delete_if_childless_subtotal() |
|
1092 | + { |
|
1093 | + if ($this->ID() && $this->type() === EEM_Line_Item::type_sub_total && ! $this->children()) { |
|
1094 | + return $this->delete(); |
|
1095 | + } |
|
1096 | + return false; |
|
1097 | + } |
|
1098 | + |
|
1099 | + |
|
1100 | + /** |
|
1101 | + * Creates a code and returns a string. doesn't assign the code to this model object |
|
1102 | + * |
|
1103 | + * @return string |
|
1104 | + * @throws EE_Error |
|
1105 | + * @throws InvalidArgumentException |
|
1106 | + * @throws InvalidDataTypeException |
|
1107 | + * @throws InvalidInterfaceException |
|
1108 | + * @throws ReflectionException |
|
1109 | + */ |
|
1110 | + public function generate_code() |
|
1111 | + { |
|
1112 | + // each line item in the cart requires a unique identifier |
|
1113 | + // return md5($this->get('OBJ_type') . $this->get('OBJ_ID') . microtime()); |
|
1114 | + return $this->get('OBJ_type') . '-' . $this->get('OBJ_ID') . '-' . microtime(); |
|
1115 | + } |
|
1116 | + |
|
1117 | + |
|
1118 | + /** |
|
1119 | + * @return bool |
|
1120 | + * @throws EE_Error |
|
1121 | + * @throws InvalidArgumentException |
|
1122 | + * @throws InvalidDataTypeException |
|
1123 | + * @throws InvalidInterfaceException |
|
1124 | + * @throws ReflectionException |
|
1125 | + */ |
|
1126 | + public function is_tax() |
|
1127 | + { |
|
1128 | + return $this->type() === EEM_Line_Item::type_tax; |
|
1129 | + } |
|
1130 | + |
|
1131 | + |
|
1132 | + /** |
|
1133 | + * @return bool |
|
1134 | + * @throws EE_Error |
|
1135 | + * @throws InvalidArgumentException |
|
1136 | + * @throws InvalidDataTypeException |
|
1137 | + * @throws InvalidInterfaceException |
|
1138 | + * @throws ReflectionException |
|
1139 | + */ |
|
1140 | + public function is_tax_sub_total() |
|
1141 | + { |
|
1142 | + return $this->type() === EEM_Line_Item::type_tax_sub_total; |
|
1143 | + } |
|
1144 | + |
|
1145 | + |
|
1146 | + /** |
|
1147 | + * @return bool |
|
1148 | + * @throws EE_Error |
|
1149 | + * @throws InvalidArgumentException |
|
1150 | + * @throws InvalidDataTypeException |
|
1151 | + * @throws InvalidInterfaceException |
|
1152 | + * @throws ReflectionException |
|
1153 | + */ |
|
1154 | + public function is_line_item() |
|
1155 | + { |
|
1156 | + return $this->type() === EEM_Line_Item::type_line_item; |
|
1157 | + } |
|
1158 | + |
|
1159 | + |
|
1160 | + /** |
|
1161 | + * @return bool |
|
1162 | + * @throws EE_Error |
|
1163 | + * @throws InvalidArgumentException |
|
1164 | + * @throws InvalidDataTypeException |
|
1165 | + * @throws InvalidInterfaceException |
|
1166 | + * @throws ReflectionException |
|
1167 | + */ |
|
1168 | + public function is_sub_line_item() |
|
1169 | + { |
|
1170 | + return $this->type() === EEM_Line_Item::type_sub_line_item; |
|
1171 | + } |
|
1172 | + |
|
1173 | + |
|
1174 | + /** |
|
1175 | + * @return bool |
|
1176 | + * @throws EE_Error |
|
1177 | + * @throws InvalidArgumentException |
|
1178 | + * @throws InvalidDataTypeException |
|
1179 | + * @throws InvalidInterfaceException |
|
1180 | + * @throws ReflectionException |
|
1181 | + */ |
|
1182 | + public function is_sub_total() |
|
1183 | + { |
|
1184 | + return $this->type() === EEM_Line_Item::type_sub_total; |
|
1185 | + } |
|
1186 | + |
|
1187 | + |
|
1188 | + /** |
|
1189 | + * Whether or not this line item is a cancellation line item |
|
1190 | + * |
|
1191 | + * @return boolean |
|
1192 | + * @throws EE_Error |
|
1193 | + * @throws InvalidArgumentException |
|
1194 | + * @throws InvalidDataTypeException |
|
1195 | + * @throws InvalidInterfaceException |
|
1196 | + * @throws ReflectionException |
|
1197 | + */ |
|
1198 | + public function is_cancellation() |
|
1199 | + { |
|
1200 | + return EEM_Line_Item::type_cancellation === $this->type(); |
|
1201 | + } |
|
1202 | + |
|
1203 | + |
|
1204 | + /** |
|
1205 | + * @return bool |
|
1206 | + * @throws EE_Error |
|
1207 | + * @throws InvalidArgumentException |
|
1208 | + * @throws InvalidDataTypeException |
|
1209 | + * @throws InvalidInterfaceException |
|
1210 | + * @throws ReflectionException |
|
1211 | + */ |
|
1212 | + public function is_total() |
|
1213 | + { |
|
1214 | + return $this->type() === EEM_Line_Item::type_total; |
|
1215 | + } |
|
1216 | + |
|
1217 | + |
|
1218 | + /** |
|
1219 | + * @return bool |
|
1220 | + * @throws EE_Error |
|
1221 | + * @throws InvalidArgumentException |
|
1222 | + * @throws InvalidDataTypeException |
|
1223 | + * @throws InvalidInterfaceException |
|
1224 | + * @throws ReflectionException |
|
1225 | + */ |
|
1226 | + public function is_cancelled() |
|
1227 | + { |
|
1228 | + return $this->type() === EEM_Line_Item::type_cancellation; |
|
1229 | + } |
|
1230 | + |
|
1231 | + |
|
1232 | + /** |
|
1233 | + * @param string $schema |
|
1234 | + * @return string like '2, 004.00', formatted according to the localized currency |
|
1235 | + * @throws EE_Error |
|
1236 | + * @throws ReflectionException |
|
1237 | + */ |
|
1238 | + public function unit_price_no_code($schema = 'localized_float') |
|
1239 | + { |
|
1240 | + return $this->get_pretty('LIN_unit_price', $schema); |
|
1241 | + } |
|
1242 | + |
|
1243 | + |
|
1244 | + /** |
|
1245 | + * @param string $schema |
|
1246 | + * @return string like '2, 004.00', formatted according to the localized currency |
|
1247 | + * @throws EE_Error |
|
1248 | + * @throws ReflectionException |
|
1249 | + */ |
|
1250 | + public function total_no_code($schema = 'localized_float') |
|
1251 | + { |
|
1252 | + return $this->get_pretty('LIN_total', $schema); |
|
1253 | + } |
|
1254 | + |
|
1255 | + |
|
1256 | + /** |
|
1257 | + * Gets the final total on this item, taking taxes into account. |
|
1258 | + * Has the side-effect of setting the sub-total as it was just calculated. |
|
1259 | + * If this is used on a grand-total line item, also updates the transaction's |
|
1260 | + * TXN_total (provided this line item is allowed to persist, otherwise we don't |
|
1261 | + * want to change a persistable transaction with info from a non-persistent line item) |
|
1262 | + * |
|
1263 | + * @param bool $update_txn_status |
|
1264 | + * @return float |
|
1265 | + * @throws EE_Error |
|
1266 | + * @throws InvalidArgumentException |
|
1267 | + * @throws InvalidDataTypeException |
|
1268 | + * @throws InvalidInterfaceException |
|
1269 | + * @throws ReflectionException |
|
1270 | + * @throws RuntimeException |
|
1271 | + */ |
|
1272 | + public function recalculate_total_including_taxes($update_txn_status = false) |
|
1273 | + { |
|
1274 | + return $this->calculator->recalculateTotalIncludingTaxes($this, $update_txn_status); |
|
1275 | + } |
|
1276 | + |
|
1277 | + |
|
1278 | + /** |
|
1279 | + * Recursively goes through all the children and recalculates sub-totals EXCEPT for |
|
1280 | + * tax-sub-totals (they're a an odd beast). Updates the 'total' on each line item according to either its |
|
1281 | + * unit price * quantity or the total of all its children EXCEPT when we're only calculating the taxable total and |
|
1282 | + * when this is called on the grand total |
|
1283 | + * |
|
1284 | + * @return float |
|
1285 | + * @throws EE_Error |
|
1286 | + * @throws InvalidArgumentException |
|
1287 | + * @throws InvalidDataTypeException |
|
1288 | + * @throws InvalidInterfaceException |
|
1289 | + * @throws ReflectionException |
|
1290 | + */ |
|
1291 | + public function recalculate_pre_tax_total() |
|
1292 | + { |
|
1293 | + return $this->calculator->recalculatePreTaxTotal($this); |
|
1294 | + } |
|
1295 | + |
|
1296 | + |
|
1297 | + /** |
|
1298 | + * Recalculates the total on each individual tax (based on a recalculation of the pre-tax total), sets |
|
1299 | + * the totals on each tax calculated, and returns the final tax total. Re-saves tax line items |
|
1300 | + * and tax sub-total if already in the DB |
|
1301 | + * |
|
1302 | + * @return float |
|
1303 | + * @throws EE_Error |
|
1304 | + * @throws InvalidArgumentException |
|
1305 | + * @throws InvalidDataTypeException |
|
1306 | + * @throws InvalidInterfaceException |
|
1307 | + * @throws ReflectionException |
|
1308 | + */ |
|
1309 | + public function recalculate_taxes_and_tax_total() |
|
1310 | + { |
|
1311 | + return $this->calculator->recalculateTaxesAndTaxTotal($this); |
|
1312 | + } |
|
1313 | + |
|
1314 | + |
|
1315 | + /** |
|
1316 | + * Gets the total tax on this line item. Assumes taxes have already been calculated using |
|
1317 | + * recalculate_taxes_and_total |
|
1318 | + * |
|
1319 | + * @return float |
|
1320 | + * @throws EE_Error |
|
1321 | + * @throws InvalidArgumentException |
|
1322 | + * @throws InvalidDataTypeException |
|
1323 | + * @throws InvalidInterfaceException |
|
1324 | + * @throws ReflectionException |
|
1325 | + */ |
|
1326 | + public function get_total_tax() |
|
1327 | + { |
|
1328 | + return $this->calculator->getTotalTax($this); |
|
1329 | + } |
|
1330 | + |
|
1331 | + |
|
1332 | + /** |
|
1333 | + * Gets the total for all the items purchased only |
|
1334 | + * |
|
1335 | + * @return float |
|
1336 | + * @throws EE_Error |
|
1337 | + * @throws InvalidArgumentException |
|
1338 | + * @throws InvalidDataTypeException |
|
1339 | + * @throws InvalidInterfaceException |
|
1340 | + * @throws ReflectionException |
|
1341 | + */ |
|
1342 | + public function get_items_total() |
|
1343 | + { |
|
1344 | + return $this->calculator->getItemsTotal($this); |
|
1345 | + } |
|
1346 | + |
|
1347 | + |
|
1348 | + /** |
|
1349 | + * Returns the amount taxable among this line item's children (or if it has no children, |
|
1350 | + * how much of it is taxable). Does not recalculate totals or subtotals. |
|
1351 | + * If the taxable total is negative, (eg, if none of the tickets were taxable, |
|
1352 | + * but there is a "Taxable" discount), returns 0. |
|
1353 | + * |
|
1354 | + * @return float |
|
1355 | + * @throws EE_Error |
|
1356 | + * @throws InvalidArgumentException |
|
1357 | + * @throws InvalidDataTypeException |
|
1358 | + * @throws InvalidInterfaceException |
|
1359 | + * @throws ReflectionException |
|
1360 | + */ |
|
1361 | + public function taxable_total() |
|
1362 | + { |
|
1363 | + return $this->calculator->amountTaxable($this); |
|
1364 | + } |
|
1365 | + |
|
1366 | + |
|
1367 | + /** |
|
1368 | + * Gets all the descendants (ie, children or children of children etc) that |
|
1369 | + * are of the type 'tax' |
|
1370 | + * |
|
1371 | + * @return EE_Line_Item[] |
|
1372 | + * @throws EE_Error |
|
1373 | + * @throws ReflectionException |
|
1374 | + */ |
|
1375 | + public function tax_descendants() |
|
1376 | + { |
|
1377 | + return EEH_Line_Item::get_tax_descendants($this); |
|
1378 | + } |
|
1379 | + |
|
1380 | + |
|
1381 | + /** |
|
1382 | + * Gets all the real items purchased which are children of this item |
|
1383 | + * |
|
1384 | + * @return EE_Line_Item[] |
|
1385 | + * @throws EE_Error |
|
1386 | + * @throws ReflectionException |
|
1387 | + */ |
|
1388 | + public function get_items() |
|
1389 | + { |
|
1390 | + return EEH_Line_Item::get_line_item_descendants($this); |
|
1391 | + } |
|
1392 | + |
|
1393 | + |
|
1394 | + /** |
|
1395 | + * Gets the transaction for this line item |
|
1396 | + * |
|
1397 | + * @return EE_Base_Class|EE_Transaction |
|
1398 | + * @throws EE_Error |
|
1399 | + * @throws InvalidArgumentException |
|
1400 | + * @throws InvalidDataTypeException |
|
1401 | + * @throws InvalidInterfaceException |
|
1402 | + * @throws ReflectionException |
|
1403 | + */ |
|
1404 | + public function transaction() |
|
1405 | + { |
|
1406 | + return $this->get_first_related(EEM_Line_Item::OBJ_TYPE_TRANSACTION); |
|
1407 | + } |
|
1408 | + |
|
1409 | + |
|
1410 | + /** |
|
1411 | + * Saves this line item to the DB, and recursively saves its descendants. |
|
1412 | + * Because there currently is no proper parent-child relation on the model, |
|
1413 | + * save_this_and_cached() will NOT save the descendants. |
|
1414 | + * Also sets the transaction on this line item and all its descendants before saving |
|
1415 | + * |
|
1416 | + * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
|
1417 | + * @return int count of items saved |
|
1418 | + * @throws EE_Error |
|
1419 | + * @throws InvalidArgumentException |
|
1420 | + * @throws InvalidDataTypeException |
|
1421 | + * @throws InvalidInterfaceException |
|
1422 | + * @throws ReflectionException |
|
1423 | + */ |
|
1424 | + public function save_this_and_descendants_to_txn($txn_id = null) |
|
1425 | + { |
|
1426 | + $count = 0; |
|
1427 | + if (! $txn_id) { |
|
1428 | + $txn_id = $this->TXN_ID(); |
|
1429 | + } |
|
1430 | + $this->set_TXN_ID($txn_id); |
|
1431 | + $children = $this->children(); |
|
1432 | + $count += $this->save() |
|
1433 | + ? 1 |
|
1434 | + : 0; |
|
1435 | + foreach ($children as $child_line_item) { |
|
1436 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1437 | + $child_line_item->set_parent_ID($this->ID()); |
|
1438 | + $count += $child_line_item->save_this_and_descendants_to_txn($txn_id); |
|
1439 | + } |
|
1440 | + } |
|
1441 | + return $count; |
|
1442 | + } |
|
1443 | + |
|
1444 | + |
|
1445 | + /** |
|
1446 | + * Saves this line item to the DB, and recursively saves its descendants. |
|
1447 | + * |
|
1448 | + * @return int count of items saved |
|
1449 | + * @throws EE_Error |
|
1450 | + * @throws InvalidArgumentException |
|
1451 | + * @throws InvalidDataTypeException |
|
1452 | + * @throws InvalidInterfaceException |
|
1453 | + * @throws ReflectionException |
|
1454 | + */ |
|
1455 | + public function save_this_and_descendants() |
|
1456 | + { |
|
1457 | + $count = 0; |
|
1458 | + $children = $this->children(); |
|
1459 | + $count += $this->save() |
|
1460 | + ? 1 |
|
1461 | + : 0; |
|
1462 | + foreach ($children as $child_line_item) { |
|
1463 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1464 | + $child_line_item->set_parent_ID($this->ID()); |
|
1465 | + $count += $child_line_item->save_this_and_descendants(); |
|
1466 | + } |
|
1467 | + } |
|
1468 | + return $count; |
|
1469 | + } |
|
1470 | + |
|
1471 | + |
|
1472 | + /** |
|
1473 | + * returns the cancellation line item if this item was cancelled |
|
1474 | + * |
|
1475 | + * @return EE_Line_Item[] |
|
1476 | + * @throws InvalidArgumentException |
|
1477 | + * @throws InvalidInterfaceException |
|
1478 | + * @throws InvalidDataTypeException |
|
1479 | + * @throws ReflectionException |
|
1480 | + * @throws EE_Error |
|
1481 | + */ |
|
1482 | + public function get_cancellations() |
|
1483 | + { |
|
1484 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
1485 | + return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation); |
|
1486 | + } |
|
1487 | + |
|
1488 | + |
|
1489 | + /** |
|
1490 | + * If this item has an ID, then this saves it again to update the db |
|
1491 | + * |
|
1492 | + * @return int count of items saved |
|
1493 | + * @throws EE_Error |
|
1494 | + * @throws InvalidArgumentException |
|
1495 | + * @throws InvalidDataTypeException |
|
1496 | + * @throws InvalidInterfaceException |
|
1497 | + * @throws ReflectionException |
|
1498 | + */ |
|
1499 | + public function maybe_save() |
|
1500 | + { |
|
1501 | + if ($this->ID()) { |
|
1502 | + return $this->save(); |
|
1503 | + } |
|
1504 | + return false; |
|
1505 | + } |
|
1506 | + |
|
1507 | + |
|
1508 | + /** |
|
1509 | + * clears the cached children and parent from the line item |
|
1510 | + * |
|
1511 | + * @return void |
|
1512 | + */ |
|
1513 | + public function clear_related_line_item_cache() |
|
1514 | + { |
|
1515 | + $this->_children = []; |
|
1516 | + $this->_parent = null; |
|
1517 | + } |
|
1518 | + |
|
1519 | + |
|
1520 | + /** |
|
1521 | + * @param bool $raw |
|
1522 | + * @return int |
|
1523 | + * @throws EE_Error |
|
1524 | + * @throws InvalidArgumentException |
|
1525 | + * @throws InvalidDataTypeException |
|
1526 | + * @throws InvalidInterfaceException |
|
1527 | + * @throws ReflectionException |
|
1528 | + */ |
|
1529 | + public function timestamp($raw = false) |
|
1530 | + { |
|
1531 | + return $raw |
|
1532 | + ? $this->get_raw('LIN_timestamp') |
|
1533 | + : $this->get('LIN_timestamp'); |
|
1534 | + } |
|
1535 | + |
|
1536 | + |
|
1537 | + |
|
1538 | + |
|
1539 | + /************************* DEPRECATED *************************/ |
|
1540 | + /** |
|
1541 | + * @param string $type one of the constants on EEM_Line_Item |
|
1542 | + * @return EE_Line_Item[] |
|
1543 | + * @throws EE_Error |
|
1544 | + * @throws ReflectionException |
|
1545 | + * @deprecated 4.6.0 |
|
1546 | + */ |
|
1547 | + protected function _get_descendants_of_type($type) |
|
1548 | + { |
|
1549 | + EE_Error::doing_it_wrong( |
|
1550 | + 'EE_Line_Item::_get_descendants_of_type()', |
|
1551 | + sprintf( |
|
1552 | + esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
1553 | + 'EEH_Line_Item::get_descendants_of_type()' |
|
1554 | + ), |
|
1555 | + '4.6.0' |
|
1556 | + ); |
|
1557 | + return EEH_Line_Item::get_descendants_of_type($this, $type); |
|
1558 | + } |
|
1559 | + |
|
1560 | + |
|
1561 | + /** |
|
1562 | + * @param string $type like one of the EEM_Line_Item::type_* |
|
1563 | + * @return EE_Line_Item |
|
1564 | + * @throws EE_Error |
|
1565 | + * @throws InvalidArgumentException |
|
1566 | + * @throws InvalidDataTypeException |
|
1567 | + * @throws InvalidInterfaceException |
|
1568 | + * @throws ReflectionException |
|
1569 | + * @deprecated 4.6.0 |
|
1570 | + */ |
|
1571 | + public function get_nearest_descendant_of_type($type) |
|
1572 | + { |
|
1573 | + EE_Error::doing_it_wrong( |
|
1574 | + 'EE_Line_Item::get_nearest_descendant_of_type()', |
|
1575 | + sprintf( |
|
1576 | + esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
1577 | + 'EEH_Line_Item::get_nearest_descendant_of_type()' |
|
1578 | + ), |
|
1579 | + '4.6.0' |
|
1580 | + ); |
|
1581 | + return EEH_Line_Item::get_nearest_descendant_of_type($this, $type); |
|
1582 | + } |
|
1583 | 1583 | } |
@@ -445,11 +445,11 @@ discard block |
||
445 | 445 | */ |
446 | 446 | public function type_obj() |
447 | 447 | { |
448 | - if (! $this->_type_obj) { |
|
448 | + if ( ! $this->_type_obj) { |
|
449 | 449 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
450 | 450 | if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
451 | 451 | $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
452 | - if (! class_exists($class_name)) { |
|
452 | + if ( ! class_exists($class_name)) { |
|
453 | 453 | throw new EE_Error( |
454 | 454 | sprintf( |
455 | 455 | esc_html__( |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | ), |
459 | 459 | $class_name, |
460 | 460 | '<br />', |
461 | - '<a href="' . admin_url('plugins.php') . '">', |
|
461 | + '<a href="'.admin_url('plugins.php').'">', |
|
462 | 462 | '</a>' |
463 | 463 | ) |
464 | 464 | ); |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | foreach ($fields as $key => $value) { |
500 | 500 | if (strpos($key, 'PMD_') === 0) { |
501 | 501 | $key_sans_model_prefix = str_replace('PMD_', '', $key); |
502 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
502 | + $combined_settings_array [$key_sans_model_prefix] = $value; |
|
503 | 503 | } |
504 | 504 | } |
505 | 505 | $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
@@ -522,14 +522,14 @@ discard block |
||
522 | 522 | <div id="' |
523 | 523 | . $this->slug() |
524 | 524 | . '-payment-option-dv" class="' |
525 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
525 | + . $payment_occurs.'-payment-gateway reg-page-payment-option-dv'.$css_class.'"> |
|
526 | 526 | <a id="payment-gateway-button-' . $this->slug() |
527 | 527 | . '" class="reg-page-payment-option-lnk" rel="' |
528 | - . $this->slug() . '" href="' . $url . '" > |
|
529 | - <img src="' . $this->button_url() . '" alt="' . sprintf( |
|
528 | + . $this->slug().'" href="'.$url.'" > |
|
529 | + <img src="' . $this->button_url().'" alt="'.sprintf( |
|
530 | 530 | esc_attr__('Pay using %s', 'event_espresso'), |
531 | 531 | $this->get_pretty('PMD_name', 'form_input') |
532 | - ) . '" /> |
|
532 | + ).'" /> |
|
533 | 533 | </a> |
534 | 534 | </div> |
535 | 535 | '; |
@@ -13,644 +13,644 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Payment_Method extends EE_Base_Class |
15 | 15 | { |
16 | - /** |
|
17 | - * Payment Method type object, which has all the info about this type of payment method, |
|
18 | - * including functions for processing payments, to get settings forms, etc. |
|
19 | - * |
|
20 | - * @var EE_PMT_Base |
|
21 | - */ |
|
22 | - protected $_type_obj; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * @param array $props_n_values |
|
27 | - * @return EE_Payment_Method |
|
28 | - * @throws EE_Error|ReflectionException |
|
29 | - */ |
|
30 | - public static function new_instance($props_n_values = array()) |
|
31 | - { |
|
32 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
33 | - return $has_object ? $has_object : new self($props_n_values, false); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @param array $props_n_values |
|
39 | - * @return EE_Payment_Method |
|
40 | - * @throws EE_Error|ReflectionException |
|
41 | - */ |
|
42 | - public static function new_instance_from_db($props_n_values = array()) |
|
43 | - { |
|
44 | - return new self($props_n_values, true); |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
51 | - * Otherwise returns a normal EE_Payment_Method |
|
52 | - * |
|
53 | - * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
54 | - * the classname minus 'EEPM_') |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - // private static function _payment_method_type($props_n_values) |
|
58 | - // { |
|
59 | - // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
60 | - // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
61 | - // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
62 | - // return 'EEPM_' . $type_string; |
|
63 | - // } else { |
|
64 | - // return __CLASS__; |
|
65 | - // } |
|
66 | - // } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
71 | - * |
|
72 | - * @return array |
|
73 | - * @throws EE_Error|ReflectionException |
|
74 | - */ |
|
75 | - public function active() |
|
76 | - { |
|
77 | - return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
83 | - * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
84 | - * |
|
85 | - * @throws EE_Error |
|
86 | - * @throws ReflectionException |
|
87 | - */ |
|
88 | - public function set_active() |
|
89 | - { |
|
90 | - $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
91 | - if ( |
|
92 | - $this->type_obj() && |
|
93 | - $this->type_obj()->payment_occurs() === EE_PMT_Base::offline |
|
94 | - ) { |
|
95 | - $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
96 | - } |
|
97 | - $this->set_scope($default_scopes); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
103 | - * |
|
104 | - * @throws EE_Error|ReflectionException |
|
105 | - */ |
|
106 | - public function deactivate() |
|
107 | - { |
|
108 | - $this->set_scope(array()); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Gets button_url |
|
114 | - * |
|
115 | - * @return string |
|
116 | - * @throws EE_Error |
|
117 | - * @throws ReflectionException |
|
118 | - */ |
|
119 | - public function button_url() |
|
120 | - { |
|
121 | - return $this->get('PMD_button_url'); |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * Sets button_url |
|
127 | - * |
|
128 | - * @param string $button_url |
|
129 | - * @throws EE_Error |
|
130 | - * @throws ReflectionException |
|
131 | - */ |
|
132 | - public function set_button_url($button_url) |
|
133 | - { |
|
134 | - $this->set('PMD_button_url', $button_url); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * Gets debug_mode |
|
140 | - * |
|
141 | - * @return boolean |
|
142 | - * @throws EE_Error |
|
143 | - * @throws ReflectionException |
|
144 | - */ |
|
145 | - public function debug_mode() |
|
146 | - { |
|
147 | - return $this->get('PMD_debug_mode'); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * Sets debug_mode |
|
153 | - * |
|
154 | - * @param boolean $debug_mode |
|
155 | - * @throws EE_Error |
|
156 | - * @throws ReflectionException |
|
157 | - */ |
|
158 | - public function set_debug_mode($debug_mode) |
|
159 | - { |
|
160 | - $this->set('PMD_debug_mode', $debug_mode); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * Gets description |
|
166 | - * |
|
167 | - * @return string |
|
168 | - * @throws EE_Error |
|
169 | - * @throws ReflectionException |
|
170 | - */ |
|
171 | - public function description() |
|
172 | - { |
|
173 | - return $this->get('PMD_desc'); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * Sets description |
|
179 | - * |
|
180 | - * @param string $description |
|
181 | - * @throws EE_Error |
|
182 | - * @throws ReflectionException |
|
183 | - */ |
|
184 | - public function set_description($description) |
|
185 | - { |
|
186 | - $this->set('PMD_desc', $description); |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * Gets name |
|
192 | - * |
|
193 | - * @return string |
|
194 | - * @throws EE_Error |
|
195 | - * @throws ReflectionException |
|
196 | - */ |
|
197 | - public function name() |
|
198 | - { |
|
199 | - return $this->get('PMD_name'); |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * Sets name |
|
205 | - * |
|
206 | - * @param string $name |
|
207 | - * @throws EE_Error |
|
208 | - * @throws ReflectionException |
|
209 | - */ |
|
210 | - public function set_name($name) |
|
211 | - { |
|
212 | - $this->set('PMD_name', $name); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * Gets open_by_default |
|
218 | - * |
|
219 | - * @return boolean |
|
220 | - * @throws EE_Error |
|
221 | - * @throws ReflectionException |
|
222 | - */ |
|
223 | - public function open_by_default() |
|
224 | - { |
|
225 | - return $this->get('PMD_open_by_default'); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * Sets open_by_default |
|
231 | - * |
|
232 | - * @param boolean $open_by_default |
|
233 | - * @throws EE_Error |
|
234 | - * @throws ReflectionException |
|
235 | - */ |
|
236 | - public function set_open_by_default($open_by_default) |
|
237 | - { |
|
238 | - $this->set('PMD_open_by_default', $open_by_default); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * Gets order |
|
244 | - * |
|
245 | - * @return int |
|
246 | - * @throws EE_Error |
|
247 | - * @throws ReflectionException |
|
248 | - */ |
|
249 | - public function order() |
|
250 | - { |
|
251 | - return $this->get('PMD_order'); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * Sets order |
|
257 | - * |
|
258 | - * @param int $order |
|
259 | - * @throws EE_Error |
|
260 | - * @throws ReflectionException |
|
261 | - */ |
|
262 | - public function set_order($order) |
|
263 | - { |
|
264 | - $this->set('PMD_order', $order); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * Gets slug |
|
270 | - * |
|
271 | - * @return string |
|
272 | - * @throws EE_Error |
|
273 | - * @throws ReflectionException |
|
274 | - */ |
|
275 | - public function slug() |
|
276 | - { |
|
277 | - return $this->get('PMD_slug'); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Sets slug |
|
283 | - * |
|
284 | - * @param string $slug |
|
285 | - * @throws EE_Error |
|
286 | - * @throws ReflectionException |
|
287 | - */ |
|
288 | - public function set_slug($slug) |
|
289 | - { |
|
290 | - $this->set('PMD_slug', $slug); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * Gets type |
|
296 | - * |
|
297 | - * @return string |
|
298 | - * @throws EE_Error |
|
299 | - * @throws ReflectionException |
|
300 | - */ |
|
301 | - public function type() |
|
302 | - { |
|
303 | - return $this->get('PMD_type'); |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * Sets type |
|
309 | - * |
|
310 | - * @param string $type |
|
311 | - * @throws EE_Error |
|
312 | - * @throws ReflectionException |
|
313 | - */ |
|
314 | - public function set_type($type) |
|
315 | - { |
|
316 | - $this->set('PMD_type', $type); |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * Gets wp_user |
|
322 | - * |
|
323 | - * @return int |
|
324 | - * @throws EE_Error |
|
325 | - * @throws ReflectionException |
|
326 | - */ |
|
327 | - public function wp_user() |
|
328 | - { |
|
329 | - return $this->get('PMD_wp_user'); |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * Sets wp_user |
|
335 | - * |
|
336 | - * @param int $wp_user_id |
|
337 | - * @throws EE_Error |
|
338 | - * @throws ReflectionException |
|
339 | - */ |
|
340 | - public function set_wp_user($wp_user_id) |
|
341 | - { |
|
342 | - $this->set('PMD_wp_user', $wp_user_id); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
348 | - * |
|
349 | - * @param string $field_name |
|
350 | - * @param mixed $field_value |
|
351 | - * @param boolean $use_default |
|
352 | - * @param string $schema |
|
353 | - * @throws EE_Error |
|
354 | - * @throws ReflectionException |
|
355 | - */ |
|
356 | - public function set($field_name, $field_value, $use_default = false, $schema = '') |
|
357 | - { |
|
358 | - if ($field_name === 'PMD_type') { |
|
359 | - // the type has probably changed, so forget about its old type object |
|
360 | - $this->_type_obj = null; |
|
361 | - } |
|
362 | - parent::set($field_name, $field_value, $use_default); |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - /** |
|
367 | - * Gets admin_name |
|
368 | - * |
|
369 | - * @return string |
|
370 | - * @throws EE_Error |
|
371 | - * @throws ReflectionException |
|
372 | - */ |
|
373 | - public function admin_name() |
|
374 | - { |
|
375 | - return $this->get('PMD_admin_name'); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * Sets admin_name |
|
381 | - * |
|
382 | - * @param string $admin_name |
|
383 | - * @throws EE_Error |
|
384 | - * @throws ReflectionException |
|
385 | - */ |
|
386 | - public function set_admin_name($admin_name) |
|
387 | - { |
|
388 | - $this->set('PMD_admin_name', $admin_name); |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * Gets admin_desc |
|
394 | - * |
|
395 | - * @return string |
|
396 | - * @throws EE_Error |
|
397 | - * @throws ReflectionException |
|
398 | - */ |
|
399 | - public function admin_desc() |
|
400 | - { |
|
401 | - return $this->get('PMD_admin_desc'); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * Sets admin_desc |
|
407 | - * |
|
408 | - * @param string $admin_desc |
|
409 | - * @throws EE_Error |
|
410 | - * @throws ReflectionException |
|
411 | - */ |
|
412 | - public function set_admin_desc($admin_desc) |
|
413 | - { |
|
414 | - $this->set('PMD_admin_desc', $admin_desc); |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * Gets scope |
|
420 | - * |
|
421 | - * @return array |
|
422 | - * @throws EE_Error |
|
423 | - * @throws ReflectionException |
|
424 | - */ |
|
425 | - public function scope() |
|
426 | - { |
|
427 | - return $this->get('PMD_scope'); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Sets scope |
|
433 | - * |
|
434 | - * @param array $scope |
|
435 | - * @throws EE_Error |
|
436 | - * @throws ReflectionException |
|
437 | - */ |
|
438 | - public function set_scope($scope) |
|
439 | - { |
|
440 | - $this->set('PMD_scope', $scope); |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * Gets the payment method type for this payment method instance |
|
446 | - * |
|
447 | - * @return EE_PMT_Base |
|
448 | - * @throws EE_Error|ReflectionException |
|
449 | - */ |
|
450 | - public function type_obj() |
|
451 | - { |
|
452 | - if (! $this->_type_obj) { |
|
453 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
454 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
455 | - $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
456 | - if (! class_exists($class_name)) { |
|
457 | - throw new EE_Error( |
|
458 | - sprintf( |
|
459 | - esc_html__( |
|
460 | - 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
461 | - 'event_espresso' |
|
462 | - ), |
|
463 | - $class_name, |
|
464 | - '<br />', |
|
465 | - '<a href="' . admin_url('plugins.php') . '">', |
|
466 | - '</a>' |
|
467 | - ) |
|
468 | - ); |
|
469 | - } |
|
470 | - $r = new ReflectionClass($class_name); |
|
471 | - $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
472 | - } else { |
|
473 | - throw new EE_Error( |
|
474 | - sprintf( |
|
475 | - esc_html__( |
|
476 | - 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
477 | - 'event_espresso' |
|
478 | - ), |
|
479 | - $this->type(), |
|
480 | - implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
481 | - ) |
|
482 | - ); |
|
483 | - } |
|
484 | - } |
|
485 | - return $this->_type_obj; |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
491 | - * and the extra meta. Mostly used for passing off ot gateways. * |
|
492 | - * |
|
493 | - * @return array |
|
494 | - * @throws EE_Error |
|
495 | - * @throws ReflectionException |
|
496 | - */ |
|
497 | - public function settings_array() |
|
498 | - { |
|
499 | - $fields = $this->model_field_array(); |
|
500 | - $extra_meta = $this->all_extra_meta_array(); |
|
501 | - // remove the model's prefix from the fields |
|
502 | - $combined_settings_array = array(); |
|
503 | - foreach ($fields as $key => $value) { |
|
504 | - if (strpos($key, 'PMD_') === 0) { |
|
505 | - $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
506 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
507 | - } |
|
508 | - } |
|
509 | - $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
510 | - return $combined_settings_array; |
|
511 | - } |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * Gets the HTML for displaying the payment method on a page. |
|
516 | - * |
|
517 | - * @param string $url |
|
518 | - * @param string $css_class |
|
519 | - * @return string of HTML for displaying the button |
|
520 | - * @throws EE_Error|ReflectionException |
|
521 | - */ |
|
522 | - public function button_html($url = '', $css_class = '') |
|
523 | - { |
|
524 | - $payment_occurs = $this->type_obj()->payment_occurs(); |
|
525 | - return ' |
|
16 | + /** |
|
17 | + * Payment Method type object, which has all the info about this type of payment method, |
|
18 | + * including functions for processing payments, to get settings forms, etc. |
|
19 | + * |
|
20 | + * @var EE_PMT_Base |
|
21 | + */ |
|
22 | + protected $_type_obj; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * @param array $props_n_values |
|
27 | + * @return EE_Payment_Method |
|
28 | + * @throws EE_Error|ReflectionException |
|
29 | + */ |
|
30 | + public static function new_instance($props_n_values = array()) |
|
31 | + { |
|
32 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
33 | + return $has_object ? $has_object : new self($props_n_values, false); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @param array $props_n_values |
|
39 | + * @return EE_Payment_Method |
|
40 | + * @throws EE_Error|ReflectionException |
|
41 | + */ |
|
42 | + public static function new_instance_from_db($props_n_values = array()) |
|
43 | + { |
|
44 | + return new self($props_n_values, true); |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
51 | + * Otherwise returns a normal EE_Payment_Method |
|
52 | + * |
|
53 | + * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
54 | + * the classname minus 'EEPM_') |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + // private static function _payment_method_type($props_n_values) |
|
58 | + // { |
|
59 | + // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
60 | + // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
61 | + // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
62 | + // return 'EEPM_' . $type_string; |
|
63 | + // } else { |
|
64 | + // return __CLASS__; |
|
65 | + // } |
|
66 | + // } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
71 | + * |
|
72 | + * @return array |
|
73 | + * @throws EE_Error|ReflectionException |
|
74 | + */ |
|
75 | + public function active() |
|
76 | + { |
|
77 | + return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
83 | + * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
84 | + * |
|
85 | + * @throws EE_Error |
|
86 | + * @throws ReflectionException |
|
87 | + */ |
|
88 | + public function set_active() |
|
89 | + { |
|
90 | + $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
91 | + if ( |
|
92 | + $this->type_obj() && |
|
93 | + $this->type_obj()->payment_occurs() === EE_PMT_Base::offline |
|
94 | + ) { |
|
95 | + $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
96 | + } |
|
97 | + $this->set_scope($default_scopes); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
103 | + * |
|
104 | + * @throws EE_Error|ReflectionException |
|
105 | + */ |
|
106 | + public function deactivate() |
|
107 | + { |
|
108 | + $this->set_scope(array()); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Gets button_url |
|
114 | + * |
|
115 | + * @return string |
|
116 | + * @throws EE_Error |
|
117 | + * @throws ReflectionException |
|
118 | + */ |
|
119 | + public function button_url() |
|
120 | + { |
|
121 | + return $this->get('PMD_button_url'); |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * Sets button_url |
|
127 | + * |
|
128 | + * @param string $button_url |
|
129 | + * @throws EE_Error |
|
130 | + * @throws ReflectionException |
|
131 | + */ |
|
132 | + public function set_button_url($button_url) |
|
133 | + { |
|
134 | + $this->set('PMD_button_url', $button_url); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * Gets debug_mode |
|
140 | + * |
|
141 | + * @return boolean |
|
142 | + * @throws EE_Error |
|
143 | + * @throws ReflectionException |
|
144 | + */ |
|
145 | + public function debug_mode() |
|
146 | + { |
|
147 | + return $this->get('PMD_debug_mode'); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * Sets debug_mode |
|
153 | + * |
|
154 | + * @param boolean $debug_mode |
|
155 | + * @throws EE_Error |
|
156 | + * @throws ReflectionException |
|
157 | + */ |
|
158 | + public function set_debug_mode($debug_mode) |
|
159 | + { |
|
160 | + $this->set('PMD_debug_mode', $debug_mode); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * Gets description |
|
166 | + * |
|
167 | + * @return string |
|
168 | + * @throws EE_Error |
|
169 | + * @throws ReflectionException |
|
170 | + */ |
|
171 | + public function description() |
|
172 | + { |
|
173 | + return $this->get('PMD_desc'); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * Sets description |
|
179 | + * |
|
180 | + * @param string $description |
|
181 | + * @throws EE_Error |
|
182 | + * @throws ReflectionException |
|
183 | + */ |
|
184 | + public function set_description($description) |
|
185 | + { |
|
186 | + $this->set('PMD_desc', $description); |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * Gets name |
|
192 | + * |
|
193 | + * @return string |
|
194 | + * @throws EE_Error |
|
195 | + * @throws ReflectionException |
|
196 | + */ |
|
197 | + public function name() |
|
198 | + { |
|
199 | + return $this->get('PMD_name'); |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * Sets name |
|
205 | + * |
|
206 | + * @param string $name |
|
207 | + * @throws EE_Error |
|
208 | + * @throws ReflectionException |
|
209 | + */ |
|
210 | + public function set_name($name) |
|
211 | + { |
|
212 | + $this->set('PMD_name', $name); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * Gets open_by_default |
|
218 | + * |
|
219 | + * @return boolean |
|
220 | + * @throws EE_Error |
|
221 | + * @throws ReflectionException |
|
222 | + */ |
|
223 | + public function open_by_default() |
|
224 | + { |
|
225 | + return $this->get('PMD_open_by_default'); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * Sets open_by_default |
|
231 | + * |
|
232 | + * @param boolean $open_by_default |
|
233 | + * @throws EE_Error |
|
234 | + * @throws ReflectionException |
|
235 | + */ |
|
236 | + public function set_open_by_default($open_by_default) |
|
237 | + { |
|
238 | + $this->set('PMD_open_by_default', $open_by_default); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * Gets order |
|
244 | + * |
|
245 | + * @return int |
|
246 | + * @throws EE_Error |
|
247 | + * @throws ReflectionException |
|
248 | + */ |
|
249 | + public function order() |
|
250 | + { |
|
251 | + return $this->get('PMD_order'); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * Sets order |
|
257 | + * |
|
258 | + * @param int $order |
|
259 | + * @throws EE_Error |
|
260 | + * @throws ReflectionException |
|
261 | + */ |
|
262 | + public function set_order($order) |
|
263 | + { |
|
264 | + $this->set('PMD_order', $order); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * Gets slug |
|
270 | + * |
|
271 | + * @return string |
|
272 | + * @throws EE_Error |
|
273 | + * @throws ReflectionException |
|
274 | + */ |
|
275 | + public function slug() |
|
276 | + { |
|
277 | + return $this->get('PMD_slug'); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Sets slug |
|
283 | + * |
|
284 | + * @param string $slug |
|
285 | + * @throws EE_Error |
|
286 | + * @throws ReflectionException |
|
287 | + */ |
|
288 | + public function set_slug($slug) |
|
289 | + { |
|
290 | + $this->set('PMD_slug', $slug); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * Gets type |
|
296 | + * |
|
297 | + * @return string |
|
298 | + * @throws EE_Error |
|
299 | + * @throws ReflectionException |
|
300 | + */ |
|
301 | + public function type() |
|
302 | + { |
|
303 | + return $this->get('PMD_type'); |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * Sets type |
|
309 | + * |
|
310 | + * @param string $type |
|
311 | + * @throws EE_Error |
|
312 | + * @throws ReflectionException |
|
313 | + */ |
|
314 | + public function set_type($type) |
|
315 | + { |
|
316 | + $this->set('PMD_type', $type); |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * Gets wp_user |
|
322 | + * |
|
323 | + * @return int |
|
324 | + * @throws EE_Error |
|
325 | + * @throws ReflectionException |
|
326 | + */ |
|
327 | + public function wp_user() |
|
328 | + { |
|
329 | + return $this->get('PMD_wp_user'); |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * Sets wp_user |
|
335 | + * |
|
336 | + * @param int $wp_user_id |
|
337 | + * @throws EE_Error |
|
338 | + * @throws ReflectionException |
|
339 | + */ |
|
340 | + public function set_wp_user($wp_user_id) |
|
341 | + { |
|
342 | + $this->set('PMD_wp_user', $wp_user_id); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
348 | + * |
|
349 | + * @param string $field_name |
|
350 | + * @param mixed $field_value |
|
351 | + * @param boolean $use_default |
|
352 | + * @param string $schema |
|
353 | + * @throws EE_Error |
|
354 | + * @throws ReflectionException |
|
355 | + */ |
|
356 | + public function set($field_name, $field_value, $use_default = false, $schema = '') |
|
357 | + { |
|
358 | + if ($field_name === 'PMD_type') { |
|
359 | + // the type has probably changed, so forget about its old type object |
|
360 | + $this->_type_obj = null; |
|
361 | + } |
|
362 | + parent::set($field_name, $field_value, $use_default); |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + /** |
|
367 | + * Gets admin_name |
|
368 | + * |
|
369 | + * @return string |
|
370 | + * @throws EE_Error |
|
371 | + * @throws ReflectionException |
|
372 | + */ |
|
373 | + public function admin_name() |
|
374 | + { |
|
375 | + return $this->get('PMD_admin_name'); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * Sets admin_name |
|
381 | + * |
|
382 | + * @param string $admin_name |
|
383 | + * @throws EE_Error |
|
384 | + * @throws ReflectionException |
|
385 | + */ |
|
386 | + public function set_admin_name($admin_name) |
|
387 | + { |
|
388 | + $this->set('PMD_admin_name', $admin_name); |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * Gets admin_desc |
|
394 | + * |
|
395 | + * @return string |
|
396 | + * @throws EE_Error |
|
397 | + * @throws ReflectionException |
|
398 | + */ |
|
399 | + public function admin_desc() |
|
400 | + { |
|
401 | + return $this->get('PMD_admin_desc'); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * Sets admin_desc |
|
407 | + * |
|
408 | + * @param string $admin_desc |
|
409 | + * @throws EE_Error |
|
410 | + * @throws ReflectionException |
|
411 | + */ |
|
412 | + public function set_admin_desc($admin_desc) |
|
413 | + { |
|
414 | + $this->set('PMD_admin_desc', $admin_desc); |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * Gets scope |
|
420 | + * |
|
421 | + * @return array |
|
422 | + * @throws EE_Error |
|
423 | + * @throws ReflectionException |
|
424 | + */ |
|
425 | + public function scope() |
|
426 | + { |
|
427 | + return $this->get('PMD_scope'); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Sets scope |
|
433 | + * |
|
434 | + * @param array $scope |
|
435 | + * @throws EE_Error |
|
436 | + * @throws ReflectionException |
|
437 | + */ |
|
438 | + public function set_scope($scope) |
|
439 | + { |
|
440 | + $this->set('PMD_scope', $scope); |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * Gets the payment method type for this payment method instance |
|
446 | + * |
|
447 | + * @return EE_PMT_Base |
|
448 | + * @throws EE_Error|ReflectionException |
|
449 | + */ |
|
450 | + public function type_obj() |
|
451 | + { |
|
452 | + if (! $this->_type_obj) { |
|
453 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
454 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
455 | + $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
456 | + if (! class_exists($class_name)) { |
|
457 | + throw new EE_Error( |
|
458 | + sprintf( |
|
459 | + esc_html__( |
|
460 | + 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
461 | + 'event_espresso' |
|
462 | + ), |
|
463 | + $class_name, |
|
464 | + '<br />', |
|
465 | + '<a href="' . admin_url('plugins.php') . '">', |
|
466 | + '</a>' |
|
467 | + ) |
|
468 | + ); |
|
469 | + } |
|
470 | + $r = new ReflectionClass($class_name); |
|
471 | + $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
472 | + } else { |
|
473 | + throw new EE_Error( |
|
474 | + sprintf( |
|
475 | + esc_html__( |
|
476 | + 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
477 | + 'event_espresso' |
|
478 | + ), |
|
479 | + $this->type(), |
|
480 | + implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
481 | + ) |
|
482 | + ); |
|
483 | + } |
|
484 | + } |
|
485 | + return $this->_type_obj; |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
491 | + * and the extra meta. Mostly used for passing off ot gateways. * |
|
492 | + * |
|
493 | + * @return array |
|
494 | + * @throws EE_Error |
|
495 | + * @throws ReflectionException |
|
496 | + */ |
|
497 | + public function settings_array() |
|
498 | + { |
|
499 | + $fields = $this->model_field_array(); |
|
500 | + $extra_meta = $this->all_extra_meta_array(); |
|
501 | + // remove the model's prefix from the fields |
|
502 | + $combined_settings_array = array(); |
|
503 | + foreach ($fields as $key => $value) { |
|
504 | + if (strpos($key, 'PMD_') === 0) { |
|
505 | + $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
506 | + $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
507 | + } |
|
508 | + } |
|
509 | + $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
510 | + return $combined_settings_array; |
|
511 | + } |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * Gets the HTML for displaying the payment method on a page. |
|
516 | + * |
|
517 | + * @param string $url |
|
518 | + * @param string $css_class |
|
519 | + * @return string of HTML for displaying the button |
|
520 | + * @throws EE_Error|ReflectionException |
|
521 | + */ |
|
522 | + public function button_html($url = '', $css_class = '') |
|
523 | + { |
|
524 | + $payment_occurs = $this->type_obj()->payment_occurs(); |
|
525 | + return ' |
|
526 | 526 | <div id="' |
527 | - . $this->slug() |
|
528 | - . '-payment-option-dv" class="' |
|
529 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
527 | + . $this->slug() |
|
528 | + . '-payment-option-dv" class="' |
|
529 | + . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
530 | 530 | <a id="payment-gateway-button-' . $this->slug() |
531 | - . '" class="reg-page-payment-option-lnk" rel="' |
|
532 | - . $this->slug() . '" href="' . $url . '" > |
|
531 | + . '" class="reg-page-payment-option-lnk" rel="' |
|
532 | + . $this->slug() . '" href="' . $url . '" > |
|
533 | 533 | <img src="' . $this->button_url() . '" alt="' . sprintf( |
534 | - esc_attr__('Pay using %s', 'event_espresso'), |
|
535 | - $this->get_pretty('PMD_name', 'form_input') |
|
536 | - ) . '" /> |
|
534 | + esc_attr__('Pay using %s', 'event_espresso'), |
|
535 | + $this->get_pretty('PMD_name', 'form_input') |
|
536 | + ) . '" /> |
|
537 | 537 | </a> |
538 | 538 | </div> |
539 | 539 | '; |
540 | - } |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * Gets all the currencies which are an option for this payment method |
|
545 | - * (as defined by the gateway and the currently active currencies) |
|
546 | - * |
|
547 | - * @return EE_Currency[] |
|
548 | - * @throws EE_Error |
|
549 | - * @throws ReflectionException |
|
550 | - */ |
|
551 | - public function get_all_usable_currencies() |
|
552 | - { |
|
553 | - return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * Reports whether or not this payment method can be used for this payment method |
|
559 | - * |
|
560 | - * @param string $currency_code currency ID (code) |
|
561 | - * @return boolean |
|
562 | - * @throws EE_Error|ReflectionException |
|
563 | - */ |
|
564 | - public function usable_for_currency($currency_code) |
|
565 | - { |
|
566 | - foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
567 | - if ($currency_obj->ID() === $currency_code) { |
|
568 | - return true; |
|
569 | - } |
|
570 | - } |
|
571 | - return false; |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - /** |
|
576 | - * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
577 | - * |
|
578 | - * @return bool |
|
579 | - * @throws EE_Error |
|
580 | - * @throws ReflectionException |
|
581 | - */ |
|
582 | - public function is_on_site() |
|
583 | - { |
|
584 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
585 | - } |
|
586 | - |
|
587 | - |
|
588 | - /** |
|
589 | - * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
590 | - * |
|
591 | - * @return bool |
|
592 | - * @throws EE_Error |
|
593 | - * @throws ReflectionException |
|
594 | - */ |
|
595 | - public function is_off_site() |
|
596 | - { |
|
597 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - /** |
|
602 | - * Returns TRUE if this payment method does not utilize a gateway |
|
603 | - * |
|
604 | - * @return bool |
|
605 | - * @throws EE_Error |
|
606 | - * @throws ReflectionException |
|
607 | - */ |
|
608 | - public function is_off_line() |
|
609 | - { |
|
610 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * Overrides default __sleep so the object type is NOT cached. |
|
615 | - * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
616 | - * to load the required classes, and don't need them at the time of unserialization |
|
617 | - * |
|
618 | - * @return array |
|
619 | - */ |
|
620 | - public function __sleep() |
|
621 | - { |
|
622 | - $properties = get_object_vars($this); |
|
623 | - unset($properties['_type_obj']); |
|
624 | - return array_keys($properties); |
|
625 | - } |
|
626 | - |
|
627 | - |
|
628 | - /** |
|
629 | - * Overrides parent to add some logging for when payment methods get deactivated |
|
630 | - * |
|
631 | - * @param array $set_cols_n_values |
|
632 | - * @return int @see EE_Base_Class::save() |
|
633 | - * @throws EE_Error|ReflectionException |
|
634 | - */ |
|
635 | - public function save($set_cols_n_values = array()) |
|
636 | - { |
|
637 | - $results = parent::save($set_cols_n_values); |
|
638 | - if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
639 | - /** @var CurrentPage $current_page */ |
|
640 | - $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
641 | - EE_Log::instance()->log( |
|
642 | - __FILE__, |
|
643 | - __FUNCTION__, |
|
644 | - sprintf( |
|
645 | - esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
646 | - $this->name(), |
|
647 | - serialize($this->get_original('PMD_scope')), |
|
648 | - serialize($this->get('PMD_scope')), |
|
649 | - $current_page->getPermalink() |
|
650 | - ), |
|
651 | - 'payment_method_change' |
|
652 | - ); |
|
653 | - } |
|
654 | - return $results; |
|
655 | - } |
|
540 | + } |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * Gets all the currencies which are an option for this payment method |
|
545 | + * (as defined by the gateway and the currently active currencies) |
|
546 | + * |
|
547 | + * @return EE_Currency[] |
|
548 | + * @throws EE_Error |
|
549 | + * @throws ReflectionException |
|
550 | + */ |
|
551 | + public function get_all_usable_currencies() |
|
552 | + { |
|
553 | + return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * Reports whether or not this payment method can be used for this payment method |
|
559 | + * |
|
560 | + * @param string $currency_code currency ID (code) |
|
561 | + * @return boolean |
|
562 | + * @throws EE_Error|ReflectionException |
|
563 | + */ |
|
564 | + public function usable_for_currency($currency_code) |
|
565 | + { |
|
566 | + foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
567 | + if ($currency_obj->ID() === $currency_code) { |
|
568 | + return true; |
|
569 | + } |
|
570 | + } |
|
571 | + return false; |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + /** |
|
576 | + * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
577 | + * |
|
578 | + * @return bool |
|
579 | + * @throws EE_Error |
|
580 | + * @throws ReflectionException |
|
581 | + */ |
|
582 | + public function is_on_site() |
|
583 | + { |
|
584 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
585 | + } |
|
586 | + |
|
587 | + |
|
588 | + /** |
|
589 | + * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
590 | + * |
|
591 | + * @return bool |
|
592 | + * @throws EE_Error |
|
593 | + * @throws ReflectionException |
|
594 | + */ |
|
595 | + public function is_off_site() |
|
596 | + { |
|
597 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + /** |
|
602 | + * Returns TRUE if this payment method does not utilize a gateway |
|
603 | + * |
|
604 | + * @return bool |
|
605 | + * @throws EE_Error |
|
606 | + * @throws ReflectionException |
|
607 | + */ |
|
608 | + public function is_off_line() |
|
609 | + { |
|
610 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
611 | + } |
|
612 | + |
|
613 | + /** |
|
614 | + * Overrides default __sleep so the object type is NOT cached. |
|
615 | + * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
616 | + * to load the required classes, and don't need them at the time of unserialization |
|
617 | + * |
|
618 | + * @return array |
|
619 | + */ |
|
620 | + public function __sleep() |
|
621 | + { |
|
622 | + $properties = get_object_vars($this); |
|
623 | + unset($properties['_type_obj']); |
|
624 | + return array_keys($properties); |
|
625 | + } |
|
626 | + |
|
627 | + |
|
628 | + /** |
|
629 | + * Overrides parent to add some logging for when payment methods get deactivated |
|
630 | + * |
|
631 | + * @param array $set_cols_n_values |
|
632 | + * @return int @see EE_Base_Class::save() |
|
633 | + * @throws EE_Error|ReflectionException |
|
634 | + */ |
|
635 | + public function save($set_cols_n_values = array()) |
|
636 | + { |
|
637 | + $results = parent::save($set_cols_n_values); |
|
638 | + if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
639 | + /** @var CurrentPage $current_page */ |
|
640 | + $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
641 | + EE_Log::instance()->log( |
|
642 | + __FILE__, |
|
643 | + __FUNCTION__, |
|
644 | + sprintf( |
|
645 | + esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
646 | + $this->name(), |
|
647 | + serialize($this->get_original('PMD_scope')), |
|
648 | + serialize($this->get('PMD_scope')), |
|
649 | + $current_page->getPermalink() |
|
650 | + ), |
|
651 | + 'payment_method_change' |
|
652 | + ); |
|
653 | + } |
|
654 | + return $results; |
|
655 | + } |
|
656 | 656 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | public function __construct($table_column, $nicename, $nullable, $default_value = null) |
33 | 33 | { |
34 | 34 | parent::__construct($table_column, $nicename, $nullable, $default_value); |
35 | - if (! $this->number_formatter instanceof NumberFormatter) { |
|
35 | + if ( ! $this->number_formatter instanceof NumberFormatter) { |
|
36 | 36 | $this->number_formatter = LoaderFactory::getLoader()->getShared(NumberFormatter::class); |
37 | 37 | } |
38 | 38 | $this->setSchemaType('number'); |
@@ -9,79 +9,79 @@ |
||
9 | 9 | */ |
10 | 10 | class EE_Float_Field extends EE_Model_Field_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * @var EE_Currency_Config |
|
14 | - * @deprecatd $VID:$ |
|
15 | - */ |
|
16 | - public $currency; |
|
12 | + /** |
|
13 | + * @var EE_Currency_Config |
|
14 | + * @deprecatd $VID:$ |
|
15 | + */ |
|
16 | + public $currency; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @var NumberFormatter |
|
20 | - * @since $VID:$ |
|
21 | - */ |
|
22 | - protected $number_formatter; |
|
18 | + /** |
|
19 | + * @var NumberFormatter |
|
20 | + * @since $VID:$ |
|
21 | + */ |
|
22 | + protected $number_formatter; |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * @param string $table_column |
|
27 | - * @param string $nicename |
|
28 | - * @param bool $nullable |
|
29 | - * @param null $default_value |
|
30 | - */ |
|
31 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
32 | - { |
|
33 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
34 | - if (! $this->number_formatter instanceof NumberFormatter) { |
|
35 | - $this->number_formatter = LoaderFactory::getLoader()->getShared(NumberFormatter::class); |
|
36 | - } |
|
37 | - $this->setSchemaType('number'); |
|
38 | - } |
|
25 | + /** |
|
26 | + * @param string $table_column |
|
27 | + * @param string $nicename |
|
28 | + * @param bool $nullable |
|
29 | + * @param null $default_value |
|
30 | + */ |
|
31 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
32 | + { |
|
33 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
34 | + if (! $this->number_formatter instanceof NumberFormatter) { |
|
35 | + $this->number_formatter = LoaderFactory::getLoader()->getShared(NumberFormatter::class); |
|
36 | + } |
|
37 | + $this->setSchemaType('number'); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param float|int|string $amount |
|
43 | - * @return float |
|
44 | - * @since $VID:$ |
|
45 | - */ |
|
46 | - public function prepare_for_get($amount) |
|
47 | - { |
|
48 | - return $this->number_formatter->filterNumericValue($amount); |
|
49 | - } |
|
41 | + /** |
|
42 | + * @param float|int|string $amount |
|
43 | + * @return float |
|
44 | + * @since $VID:$ |
|
45 | + */ |
|
46 | + public function prepare_for_get($amount) |
|
47 | + { |
|
48 | + return $this->number_formatter->filterNumericValue($amount); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * Returns the number formatted according to local custom (set by the country of the blog). |
|
54 | - * |
|
55 | - * @param float $value |
|
56 | - * @param string|null $schema |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public function prepare_for_pretty_echoing($value, ?string $schema = null) |
|
60 | - { |
|
61 | - return $this->number_formatter->formatForLocale($value); |
|
62 | - } |
|
52 | + /** |
|
53 | + * Returns the number formatted according to local custom (set by the country of the blog). |
|
54 | + * |
|
55 | + * @param float $value |
|
56 | + * @param string|null $schema |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public function prepare_for_pretty_echoing($value, ?string $schema = null) |
|
60 | + { |
|
61 | + return $this->number_formatter->formatForLocale($value); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
67 | - * However, treats commas and periods as thousand-separators or decimal marks, as per the currency's config. |
|
68 | - * |
|
69 | - * @param float|int|string $value |
|
70 | - * @return float |
|
71 | - */ |
|
72 | - public function prepare_for_set($value) |
|
73 | - { |
|
74 | - $value = $this->number_formatter->parseForLocale($value); |
|
75 | - return $this->prepare_for_set_from_db($value); |
|
76 | - } |
|
65 | + /** |
|
66 | + * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
67 | + * However, treats commas and periods as thousand-separators or decimal marks, as per the currency's config. |
|
68 | + * |
|
69 | + * @param float|int|string $value |
|
70 | + * @return float |
|
71 | + */ |
|
72 | + public function prepare_for_set($value) |
|
73 | + { |
|
74 | + $value = $this->number_formatter->parseForLocale($value); |
|
75 | + return $this->prepare_for_set_from_db($value); |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @param float $value |
|
81 | - * @return float |
|
82 | - */ |
|
83 | - public function prepare_for_set_from_db($value) |
|
84 | - { |
|
85 | - return $this->number_formatter->precisionRound($value); |
|
86 | - } |
|
79 | + /** |
|
80 | + * @param float $value |
|
81 | + * @return float |
|
82 | + */ |
|
83 | + public function prepare_for_set_from_db($value) |
|
84 | + { |
|
85 | + return $this->number_formatter->precisionRound($value); |
|
86 | + } |
|
87 | 87 | } |