Completed
Branch BETA-4.9-messages-queue-fixed (941081)
by
unknown
17:38 queued 10s
created

EED_Events_Archive_Caff   B

Complexity

Total Complexity 42

Size/Duplication

Total Lines 164
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8
Metric Value
wmc 42
lcom 0
cbo 8
dl 0
loc 164
rs 8.295

7 Methods

Rating   Name   Duplication   Size   Complexity  
A instance() 0 3 1
A set_hooks() 0 2 1
A run() 0 2 1
A set_hooks_admin() 0 9 1
F template_settings_form() 0 30 15
C update_template_settings() 0 20 18
B update_event_archive_order() 0 28 5

How to fix   Complexity   

Complex Class

Complex classes like EED_Events_Archive_Caff often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use EED_Events_Archive_Caff, and based on these observations, apply Extract Interface, too.

1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
/**
3
 * Event Espresso
4
 *
5
 * Event Registration and Management Plugin for WordPress
6
 *
7
 * @ package			Event Espresso
8
 * @ author			Seth Shoultes
9
 * @ copyright		(c) 2008-2011 Event Espresso  All Rights Reserved.
10
 * @ license			http://eventespresso.com/support/terms-conditions/   * see Plugin Licensing *
11
 * @ link					http://www.eventespresso.com
12
 * @ version		 	4.0
13
 *
14
 * ------------------------------------------------------------------------
15
 *
16
 * EED_Events_Archive_Caff
17
 *
18
 * @package		Event Espresso
19
 * @subpackage	/modules/events_archive_caff/
20
 * @author		Brent Christensen
21
 *
22
 * ------------------------------------------------------------------------
23
 */
24
class EED_Events_Archive_Caff  extends EED_Events_Archive {
25
26
27
	/**
28
	 * @return EED_Events_Archive_Caff
29
	 */
30
	public static function instance() {
31
		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...
32
	}
33
34
35
36
	/**
37
	 * 	set_hooks - for hooking into EE Core, other modules, etc
38
	 *
39
	 *  @access 	public
40
	 *  @return 	void
41
	 */
42
	public static function set_hooks() {
43
	}
44
45
	/**
46
	 * 	set_hooks_admin - for hooking into EE Admin Core, other modules, etc
47
	 *
48
	 *  @access 	public
49
	 *  @return 	void
50
	 */
51
	public static function set_hooks_admin() {
52
		define( 'EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS );
53
		define( 'EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
54
		add_action( 'AHEE__template_settings__template__before_settings_form', array( 'EED_Events_Archive_Caff', 'template_settings_form' ), 10 );
55
		add_filter( 'FHEE__General_Settings_Admin_Page__update_template_settings__data', array( 'EED_Events_Archive_Caff', 'update_template_settings' ), 10, 2 );
56
		// AJAX
57
		add_action( 'wp_ajax_espresso_update_event_archive_order', array( 'EED_Events_Archive_Caff', 'update_event_archive_order' ) );
58
		add_action( 'wp_ajax_nopriv_espresso_update_event_archive_order', array( 'EED_Events_Archive_Caff', 'update_event_archive_order' ) );
59
	}
60
61
62
63
64
	/**
65
	 *    run - initial module setup
66
	 *
67
	 * @access    public
68
	 * @param    WP $WP
69
	 * @return    void
70
	 */
71
	public function run( $WP ) {
72
	}
73
74
75
76
77
	/**
78
	 * 	template_settings_form
79
	 *
80
	 *  @access 	public
81
	 *  @static
82
	 *  @return 	void
83
	 */
84
	public static function template_settings_form() {
85
		// grab general settings admin page and remove the existing hook callback
86
		$gen_set_admin = EE_Registry::instance()->LIB->EE_Admin_Page_Loader->get_admin_page_object( 'general_settings' );
87
		if ( $gen_set_admin instanceof General_Settings_Admin_Page ) {
88
			remove_action( 'AHEE__template_settings__template__before_settings_form', array( $gen_set_admin, 'template_settings_caff_features' ), 100 );
89
		}
90
		// first just grab the template settings
91
		$config = EE_Registry::instance()->CFG->template_settings;
92
		// then if the Event Archive config is valid, use that, else create a new one
93
		$config = isset( $config->EED_Events_Archive ) && $config->EED_Events_Archive instanceof EE_Events_Archive_Config ? $config->EED_Events_Archive : new EE_Events_Archive_Config();
94
		$config = apply_filters( 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', $config );
95
		$config->display_status_banner = isset( $config->display_status_banner ) ? $config->display_status_banner : 0;
96
		$config->display_description = isset( $config->display_description ) ? $config->display_description : 1;
97
		$config->display_ticket_selector = isset( $config->display_ticket_selector ) ? $config->display_ticket_selector : 0;
98
		$config->display_datetimes = isset( $config->display_datetimes ) ? $config->display_datetimes : 1;
99
		$config->display_venue = isset( $config->display_venue ) ? $config->display_venue : 0;
100
		$config->display_expired_events = isset( $config->display_expired_events ) ? $config->display_expired_events : 0;
101
		// display order options
102
		$config->use_sortable_display_order = isset( $config->use_sortable_display_order  )? $config->use_sortable_display_order : false;
103
		$config->display_order_tickets = isset( $config->display_order_tickets  )? $config->display_order_tickets : 100;
104
		$config->display_order_datetimes = isset( $config->display_order_datetimes  )? $config->display_order_datetimes : 110;
105
		$config->display_order_event = isset( $config->display_order_event  )? $config->display_order_event : 120;
106
		$config->display_order_venue = isset( $config->display_order_venue  )? $config->display_order_venue : 130;
107
		// get template parts
108
		$template_parts = EED_Events_Archive::instance()->initialize_template_parts( $config );
109
		// convert to array so that we can add more properties
110
		$config = get_object_vars( $config );
111
		$config[ 'event_archive_display_order' ] = $template_parts->generate_sortable_list_of_template_parts( 'event-archive-sortable-js', '', 'archive-sortable-li archive-sortable-js' );
112
		EEH_Template::display_template( EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $config );
113
	}
114
115
116
117
118
119
120
	/**
121
	 * 	update_template_settings
122
	 *
123
	 *  @access 	public
124
	 *  @param    EE_Template_Config $CFG
125
	 *  @param 	array $REQ
126
	 *  @return    EE_Events_Archive_Config
127
	 */
128
	public static function update_template_settings( $CFG, $REQ ) {
129
		$config = new EE_Events_Archive_Config();
130
		// unless we are resetting the config...
131
		if ( ! isset( $REQ['EED_Events_Archive_reset_event_list_settings'] ) || absint( $REQ['EED_Events_Archive_reset_event_list_settings'] ) !== 1 ) {
132
			$config->display_status_banner = isset( $REQ['EED_Events_Archive_display_status_banner'] ) ? absint( $REQ['EED_Events_Archive_display_status_banner'] ) : 0;
133
			$config->display_description = isset( $REQ['EED_Events_Archive_display_description'] ) ? absint( $REQ['EED_Events_Archive_display_description'] ) : 1;
134
			$config->display_ticket_selector = isset( $REQ['EED_Events_Archive_display_ticket_selector'] ) ? absint( $REQ['EED_Events_Archive_display_ticket_selector'] ) : 0;
135
			$config->display_datetimes = isset( $REQ['EED_Events_Archive_display_datetimes'] ) ? absint( $REQ['EED_Events_Archive_display_datetimes'] ) : 1;
136
			$config->display_venue = isset( $REQ['EED_Events_Archive_display_venue'] ) ? absint( $REQ['EED_Events_Archive_display_venue'] ) : 0;
137
			$config->display_expired_events = isset( $REQ['EED_Events_Archive_display_expired_events'] ) ? absint( $REQ['EED_Events_Archive_display_expired_events'] ) : 0;
138
			$config->use_sortable_display_order = isset( $REQ['EED_Events_Archive_use_sortable_display_order'] ) ? absint( $REQ['EED_Events_Archive_use_sortable_display_order'] ) : 0;
139
			$config->display_order_tickets = isset( $CFG->EED_Events_Archive->display_order_tickets ) && $config->use_sortable_display_order ? $CFG->EED_Events_Archive->display_order_tickets : 100;
140
			$config->display_order_datetimes = isset( $CFG->EED_Events_Archive->display_order_datetimes ) && $config->use_sortable_display_order ? $CFG->EED_Events_Archive->display_order_datetimes : 110;
141
			$config->display_order_event = isset( $CFG->EED_Events_Archive->display_order_event ) && $config->use_sortable_display_order ? $CFG->EED_Events_Archive->display_order_event : 120;
142
			$config->display_order_venue = isset( $CFG->EED_Events_Archive->display_order_venue ) && $config->use_sortable_display_order ? $CFG->EED_Events_Archive->display_order_venue : 130;
143
		}
144
		$CFG->EED_Events_Archive = $config;
145
		do_action( 'AHEE__EED_Events_Archive__update_template_settings__after_update', $CFG, $REQ );
146
		return $CFG;
147
	}
148
149
150
151
	/**
152
	 * update_event_single_order
153
	 *
154
	 * @access    public
155
	 * @return    void
156
	 */
157
	public static function update_event_archive_order() {
158
		$config_saved = false;
159
		$template_parts = sanitize_text_field( $_POST[ 'elements' ] );
160
		if ( ! empty( $template_parts ) ) {
161
			$template_parts = explode( ',', trim( $template_parts, ',' ) );
162
			foreach ( $template_parts as $key => $template_part ) {
163
				$template_part = "display_order_$template_part";
164
				$priority = ( $key * 10 ) + 100;
165
				if (
166
					property_exists(
167
						EE_Registry::instance()->CFG->template_settings->EED_Events_Archive,
168
						$template_part
169
					)
170
				) {
171
					EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->$template_part = $priority;
172
				}
173
				do_action( "AHEE__EED_Events_Archive__update_event_archive_order__$template_part", $priority );
174
			}
175
			$config_saved = EE_Registry::instance()->CFG->update_espresso_config( false, false );
176
		}
177
		if ( $config_saved ) {
178
			EE_Error::add_success( __( 'Display Order has been successfully updated.', 'event_espresso' ) );
179
		} else {
180
			EE_Error::add_error( __( 'Display Order was not updated.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
181
		}
182
		echo wp_json_encode( EE_Error::get_notices( false ) );
183
		exit();
184
	}
185
186
187
}
188
189
190
191
192
193
// End of file EED_Events_Archive.module.php
194
// Location: /modules/events_archive_caff/EED_Events_Archive.module.php