Completed
Branch BUG-9042-ics-organizer-email (7b2e23)
by
unknown
29:24 queued 16:15
created

EED_Ticket_Selector   A

Complexity

Total Complexity 35

Size/Duplication

Total Lines 419
Duplicated Lines 4.3 %

Coupling/Cohesion

Components 3
Dependencies 10

Importance

Changes 0
Metric Value
dl 18
loc 419
rs 9
c 0
b 0
f 0
wmc 35
lcom 3
cbo 10

27 Methods

Rating   Name   Duplication   Size   Complexity  
A instance() 0 3 1
A set_config() 0 5 1
A ticketSelector() 0 7 2
A run() 0 1 1
A set_hooks() 0 11 1
A set_hooks_admin() 0 19 1
A set_definitions() 4 10 2
A getIframeEmbedButton() 0 6 2
A ticket_selector_iframe_embed_button() 0 4 1
A ticket_selector_iframe() 0 4 1
A display_ticket_selector() 0 3 1
A process_ticket_selections() 0 4 1
A cancel_ticket_selections() 0 5 1
A translate_js_strings() 0 5 1
A load_tckt_slctr_assets() 0 12 2
A loadIframeAssets() 0 21 1
A iframeCss() 0 5 1
A iframeJs() 0 5 1
A display_view_details_btn() 0 5 1
A display_ticket_selector_submit() 0 5 1
A iframe_code_button() 7 12 3
A ticket_selector_form_open() 0 5 1
A ticket_selector_form_close() 0 5 1
A no_tkt_slctr_end_dv() 0 5 1
A tkt_slctr_end_dv() 0 4 1
A clear_tkt_slctr() 0 4 1
A load_tckt_slctr_assets_admin() 7 11 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php use EventEspresso\modules\ticket_selector\DisplayTicketSelector;
2
use EventEspresso\modules\ticket_selector\ProcessTicketSelector;
3
use EventEspresso\modules\ticket_selector\TicketSelectorIframe;
4
use EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton;
5
6
if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
7
	exit( 'No direct script access allowed' );
8
}
9
10
11
12
/**
13
 * ------------------------------------------------------------------------
14
 *
15
 * Ticket Selector  class
16
 *
17
 * @package		Event Espresso
18
 * @subpackage	includes/classes/EE_Ticket_Selector.class.php
19
 * @author		Brent Christensen
20
 *
21
 * ------------------------------------------------------------------------
22
 */
23
class EED_Ticket_Selector extends  EED_Module {
24
25
    /**
26
     * @var EventEspresso\modules\ticket_selector\DisplayTicketSelector $ticket_selector
27
     */
28
    private static $ticket_selector;
29
30
    /**
31
     * @var EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton $iframe_embed_button
32
     */
33
    private static $iframe_embed_button;
34
35
36
37
	/**
38
	 * @return EED_Ticket_Selector
39
	 */
40
	public static function instance() {
41
		return parent::get_instance( __CLASS__ );
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (get_instance() instead of instance()). Are you sure this is correct? If so, you might want to change this to $this->get_instance().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
42
	}
43
44
45
46
	protected function set_config(){
47
		$this->set_config_section( 'template_settings' );
48
		$this->set_config_class( 'EE_Ticket_Selector_Config' );
49
		$this->set_config_name( 'EED_Ticket_Selector' );
50
	}
51
52
53
54
	/**
55
	 * 	set_hooks - for hooking into EE Core, other modules, etc
56
	 *
57
	 *  @access 	public
58
	 *  @return 	void
59
	 */
60
	public static function set_hooks() {
61
		// routing
62
		EE_Config::register_route( 'iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector' );
63
		EE_Config::register_route( 'process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections' );
64
        EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections');
65
        add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 );
66
		add_action( 'AHEE_event_details_header_bottom', array( 'EED_Ticket_Selector', 'display_ticket_selector' ), 10, 1 );
67
        add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'translate_js_strings' ), 0 );
68
        add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 );
69
        EED_Ticket_Selector::loadIframeAssets();
70
    }
71
72
73
74
	/**
75
	 * 	set_hooks_admin - for hooking into EE Admin Core, other modules, etc
76
	 *
77
	 *  @access 	public
78
	 *  @return 	void
79
	 */
80
	public static function set_hooks_admin() {
81
		// hook into the end of the \EE_Admin_Page::_load_page_dependencies()
82
		// to load assets for "espresso_events" page on the "edit" route (action)
83
		add_action(
84
			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit',
85
			array( 'EED_Ticket_Selector', 'ticket_selector_iframe_embed_button' ),
86
			10
87
		);
88
89
        /**
90
         * Make sure assets for the ticket selector are loaded on the espresso registrations route so  admin side
91
         * registrations work.
92
         */
93
		add_action(
94
		    'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration',
95
            array('EED_Ticket_Selector', 'set_definitions'),
96
            10
97
        );
98
    }
99
100
101
102
	/**
103
	 * 	set_definitions
104
	 *
105
	 *  @access 	public
106
	 *  @return 	void
107
	 */
108
	public static function set_definitions() {
109
		define( 'TICKET_SELECTOR_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
110
		define( 'TICKET_SELECTOR_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS );
111
112
		//if config is not set, initialize
113 View Code Duplication
		if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config ) {
114
            \EED_Ticket_Selector::instance()->set_config();
115
            \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config();
116
		}
117
	}
118
119
120
121
	/**
122
     * @return \EventEspresso\modules\ticket_selector\DisplayTicketSelector
123
     */
124
    public static function ticketSelector()
125
    {
126
        if ( ! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) {
127
            EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector();
128
        }
129
        return EED_Ticket_Selector::$ticket_selector;
130
    }
131
132
133
	/**
134
	 * 	gets the ball rolling
135
	 *
136
	 *	@access public
137
	 * 	@param	WP $WP
138
	 * 	@return void
139
	 */
140
	public function run( $WP ) {}
141
142
143
144
	/**
145
	 * @return \EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton
146
	 */
147
	public static function getIframeEmbedButton() {
148
		if ( ! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton ) {
149
			self::$iframe_embed_button = new TicketSelectorIframeEmbedButton();
150
		}
151
		return self::$iframe_embed_button;
152
	}
153
154
155
156
	/**
157
	 * ticket_selector_iframe_embed_button
158
	 *
159
	 * @return    void
160
	 * @throws \EE_Error
161
	 */
162
	public static function ticket_selector_iframe_embed_button() {
163
		$iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
164
		$iframe_embed_button->addEventEditorIframeEmbedButton();
165
	}
166
167
168
169
	/**
170
	 * ticket_selector_iframe
171
	 *
172
	 * @return    void
173
	 * @throws \DomainException
174
	 * @throws \EE_Error
175
	 */
176
	public function ticket_selector_iframe() {
177
		$ticket_selector_iframe = new TicketSelectorIframe();
178
		$ticket_selector_iframe->display();
179
	}
180
181
182
183
    /**
184
     *    creates buttons for selecting number of attendees for an event
185
     *
186
     * @access    public
187
     * @param    WP_Post|int $event
188
     * @param    bool        $view_details
189
     * @return    string
190
     * @throws \EE_Error
191
     */
192
	public static function display_ticket_selector( $event = NULL, $view_details = FALSE ) {
193
		return EED_Ticket_Selector::ticketSelector()->display( $event, $view_details );
194
	}
195
196
197
198
	/**
199
	 * process_ticket_selections
200
	 *
201
	 * @access        public
202
	 * @return        array  or FALSE
203
	 * @throws \EE_Error
204
	 */
205
	public function process_ticket_selections() {
206
		$form = new ProcessTicketSelector();
207
		return $form->processTicketSelections();
208
	}
209
210
211
212
    /**
213
     * cancel_ticket_selections
214
     *
215
     * @access        public
216
     * @return        string
217
     */
218
    public static function cancel_ticket_selections()
219
    {
220
        $form = new ProcessTicketSelector();
221
        return $form->cancelTicketSelections();
222
    }
223
224
225
226
	/**
227
	* @return void
228
	*/
229
	public static function translate_js_strings() {
230
        EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__(
231
            'please select a datetime', 'event_espresso'
232
        );
233
    }
234
235
236
237
	/**
238
	* 	load js
239
	*
240
	* 	@access 		public
241
	* 	@return 		void
242
	*/
243
	public static function load_tckt_slctr_assets() {
244
		if ( apply_filters( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE ) ) {
245
            // add some style
246
			wp_register_style('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css');
247
			wp_enqueue_style('ticket_selector');
248
			// make it dance
249
			wp_register_script('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', array('espresso_core'), '', TRUE);
250
			wp_enqueue_script('ticket_selector');
251
            require_once( EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php');
252
            \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
253
        }
254
	}
255
256
257
258
    /**
259
     * @return void
260
     */
261
    public static function loadIframeAssets()
262
    {
263
        // for event lists
264
        add_filter(
265
            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
266
            array('EED_Ticket_Selector', 'iframeCss')
267
        );
268
        add_filter(
269
            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
270
            array('EED_Ticket_Selector', 'iframeJs')
271
        );
272
        // for ticket selectors
273
        add_filter(
274
            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
275
            array('EED_Ticket_Selector', 'iframeCss')
276
        );
277
        add_filter(
278
            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
279
            array('EED_Ticket_Selector', 'iframeJs')
280
        );
281
    }
282
283
284
285
    /**
286
     * Informs the rest of the forms system what CSS and JS is needed to display the input
287
     *
288
     * @param array $iframe_css
289
     * @return array
290
     */
291
    public static function iframeCss(array $iframe_css)
292
    {
293
        $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css';
294
        return $iframe_css;
295
    }
296
297
298
299
    /**
300
     * Informs the rest of the forms system what CSS and JS is needed to display the input
301
     *
302
     * @param array $iframe_js
303
     * @return array
304
     */
305
    public static function iframeJs(array $iframe_js)
306
    {
307
        $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js';
308
        return $iframe_js;
309
    }
310
311
312
	/****************************** DEPRECATED ******************************/
313
314
315
316
    /**
317
     * @deprecated
318
     * @return string
319
     * @throws \EE_Error
320
     */
321
    public static function display_view_details_btn()
322
    {
323
        // todo add doing_it_wrong() notice during next major version
324
        return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton();
325
    }
326
327
328
329
    /**
330
     * @deprecated
331
     * @return string
332
     * @throws \EE_Error
333
     */
334
    public static function display_ticket_selector_submit()
335
    {
336
        // todo add doing_it_wrong() notice during next major version
337
        return EED_Ticket_Selector::ticketSelector()->displaySubmitButton();
338
    }
339
340
341
342
    /**
343
     * @deprecated
344
     * @param string $permalink_string
345
     * @param int    $id
346
     * @param string $new_title
347
     * @param string $new_slug
348
     * @return string
349
     */
350
    public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '')
0 ignored issues
show
Unused Code introduced by
The parameter $permalink_string is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $new_title is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $new_slug is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
351
    {
352
        // todo add doing_it_wrong() notice during next major version
353 View Code Duplication
        if (
354
        	\EE_Registry::instance()->REQ->get('page') === 'espresso_events'
355
        	&& \EE_Registry::instance()->REQ->get('action') === 'edit'
356
        ) {
357
            $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
358
            $iframe_embed_button->addEventEditorIframeEmbedButton();
359
        }
360
        return '';
361
    }
362
363
364
365
    /**
366
     * @deprecated
367
     * @param int    $ID
368
     * @param string $external_url
369
     * @return string
370
     */
371
    public static function ticket_selector_form_open($ID = 0, $external_url = '')
372
    {
373
        // todo add doing_it_wrong() notice during next major version
374
        return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url);
375
    }
376
377
378
379
    /**
380
     * @deprecated
381
     * @return string
382
     */
383
    public static function ticket_selector_form_close()
384
    {
385
        // todo add doing_it_wrong() notice during next major version
386
        return EED_Ticket_Selector::ticketSelector()->formClose();
387
    }
388
389
390
391
    /**
392
     * @deprecated
393
     * @return string
394
     */
395
    public static function no_tkt_slctr_end_dv()
396
    {
397
        // todo add doing_it_wrong() notice during next major version
398
        return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv();
399
    }
400
401
402
403
    /**
404
     * @deprecated 4.9.13
405
     * @return string
406
     */
407
    public static function tkt_slctr_end_dv()
408
    {
409
        return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
410
    }
411
412
413
414
    /**
415
     * @deprecated
416
     * @return string
417
     */
418
    public static function clear_tkt_slctr()
419
    {
420
        return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
421
    }
422
423
424
425
    /**
426
     * @deprecated
427
     */
428
    public static function load_tckt_slctr_assets_admin()
429
    {
430
        // todo add doing_it_wrong() notice during next major version
431 View Code Duplication
	    if (
432
		    \EE_Registry::instance()->REQ->get( 'page' ) === 'espresso_events'
433
		    && \EE_Registry::instance()->REQ->get( 'action' ) === 'edit'
434
	    ) {
435
		    $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
436
            $iframe_embed_button->embedButtonAssets();
437
        }
438
    }
439
440
441
}
442
// End of file EED_Ticket_Selector.module.php
443
// Location: modules/ticket_selector/EED_Ticket_Selector.module.php
444