Completed
Branch dependabot/composer/wp-graphql... (0948c3)
by
unknown
16:03 queued 10:25
created
core/libraries/messages/EE_Message_Generated_From_Token.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
             return $this->_message;
94 94
         }
95 95
         $message = EEM_Message::instance()->get_one_by_token($this->token);
96
-        if (! $message instanceof EE_Message) {
96
+        if ( ! $message instanceof EE_Message) {
97 97
             throw new EE_Error(
98 98
                 sprintf(
99 99
                     esc_html__('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'),
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         }
104 104
         $message->set_STS_ID(EEM_Message::status_idle);
105 105
 
106
-        if (! $this->_sending_messenger instanceof EE_messenger) {
106
+        if ( ! $this->_sending_messenger instanceof EE_messenger) {
107 107
             $message->set_STS_ID(EEM_Message::status_failed);
108 108
             $message->set_error_message(
109 109
                 sprintf(
Please login to merge, or discard this patch.
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -11,111 +11,111 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Message_Generated_From_Token extends EE_Message_To_Generate implements EEI_Has_Sending_Messenger
13 13
 {
14
-    /**
15
-     * Sending messenger
16
-     *
17
-     * @type EE_messenger | string
18
-     */
19
-    protected $_sending_messenger = '';
20
-
21
-
22
-    /**
23
-     * Holds the incoming token;
24
-     * @type string
25
-     */
26
-    public $token = '';
27
-
28
-
29
-    /**
30
-     * Constructor
31
-     *
32
-     * @param   string    $sending_messenger_slug     This is used to set what messenger is used to "send"
33
-     *                                                the EE_Message retrieved from the DB via the given token.
34
-     * @param   string $token                         This is a token for a Message that should already exist int the db.
35
-     *                                                This is then used to populate the properties in here.
36
-     * @param   EE_Message_Resource_Manager $message_resource_manager
37
-     */
38
-    public function __construct($token, $sending_messenger_slug, EE_Message_Resource_Manager $message_resource_manager)
39
-    {
40
-        $this->token = $token;
41
-        $this->_sending_messenger = $this->_set_sending_messenger($sending_messenger_slug, $message_resource_manager);
42
-        $this->_message = $this->_generate_message();
43
-        // set params for parent from the message object
44
-        parent::__construct(
45
-            $this->_message->messenger(),
46
-            $this->_message->message_type(),
47
-            array(),
48
-            $this->_message->context(),
49
-            false
50
-        );
51
-    }
52
-
53
-
54
-
55
-    /**
56
-     * @param string                       $sending_messenger_slug
57
-     * @param \EE_Message_Resource_Manager $message_resource_manager
58
-     * @return \EE_messenger | string
59
-     */
60
-    protected function _set_sending_messenger(
61
-        $sending_messenger_slug,
62
-        EE_Message_Resource_Manager $message_resource_manager
63
-    ) {
64
-        $sending_messenger = $message_resource_manager->get_active_messenger($sending_messenger_slug);
65
-        return $sending_messenger instanceof EE_messenger ? $sending_messenger : $sending_messenger_slug;
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     * @return EE_messenger
72
-     */
73
-    public function sending_messenger()
74
-    {
75
-        return $this->_sending_messenger;
76
-    }
77
-
78
-
79
-
80
-    /**
81
-     * generates an EE_Message using the supplied arguments and some defaults
82
-     *
83
-     * @param array $properties
84
-     * @return EE_Message
85
-     * @throws \EE_Error
86
-     */
87
-    protected function _generate_message($properties = array())
88
-    {
89
-        // a message was generated immediately but the parent class will call this again
90
-        if ($this->_message instanceof EE_Message) {
91
-            return $this->_message;
92
-        }
93
-        $message = EEM_Message::instance()->get_one_by_token($this->token);
94
-        if (! $message instanceof EE_Message) {
95
-            throw new EE_Error(
96
-                sprintf(
97
-                    esc_html__('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'),
98
-                    $this->token
99
-                )
100
-            );
101
-        }
102
-        $message->set_STS_ID(EEM_Message::status_idle);
103
-
104
-        if (! $this->_sending_messenger instanceof EE_messenger) {
105
-            $message->set_STS_ID(EEM_Message::status_failed);
106
-            $message->set_error_message(
107
-                sprintf(
108
-                    esc_html__('Unable to send message because the "%1$s" messenger is not active or not installed', 'event_espresso'),
109
-                    $this->_sending_messenger
110
-                )
111
-            );
112
-        }
113
-
114
-        // set properties
115
-        $this->_valid = true;
116
-        $this->_messenger = $message->messenger_object();
117
-        $this->_message_type = $message->message_type_object();
118
-        $this->_send_now = $message->send_now();
119
-        return $message;
120
-    }
14
+	/**
15
+	 * Sending messenger
16
+	 *
17
+	 * @type EE_messenger | string
18
+	 */
19
+	protected $_sending_messenger = '';
20
+
21
+
22
+	/**
23
+	 * Holds the incoming token;
24
+	 * @type string
25
+	 */
26
+	public $token = '';
27
+
28
+
29
+	/**
30
+	 * Constructor
31
+	 *
32
+	 * @param   string    $sending_messenger_slug     This is used to set what messenger is used to "send"
33
+	 *                                                the EE_Message retrieved from the DB via the given token.
34
+	 * @param   string $token                         This is a token for a Message that should already exist int the db.
35
+	 *                                                This is then used to populate the properties in here.
36
+	 * @param   EE_Message_Resource_Manager $message_resource_manager
37
+	 */
38
+	public function __construct($token, $sending_messenger_slug, EE_Message_Resource_Manager $message_resource_manager)
39
+	{
40
+		$this->token = $token;
41
+		$this->_sending_messenger = $this->_set_sending_messenger($sending_messenger_slug, $message_resource_manager);
42
+		$this->_message = $this->_generate_message();
43
+		// set params for parent from the message object
44
+		parent::__construct(
45
+			$this->_message->messenger(),
46
+			$this->_message->message_type(),
47
+			array(),
48
+			$this->_message->context(),
49
+			false
50
+		);
51
+	}
52
+
53
+
54
+
55
+	/**
56
+	 * @param string                       $sending_messenger_slug
57
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
58
+	 * @return \EE_messenger | string
59
+	 */
60
+	protected function _set_sending_messenger(
61
+		$sending_messenger_slug,
62
+		EE_Message_Resource_Manager $message_resource_manager
63
+	) {
64
+		$sending_messenger = $message_resource_manager->get_active_messenger($sending_messenger_slug);
65
+		return $sending_messenger instanceof EE_messenger ? $sending_messenger : $sending_messenger_slug;
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 * @return EE_messenger
72
+	 */
73
+	public function sending_messenger()
74
+	{
75
+		return $this->_sending_messenger;
76
+	}
77
+
78
+
79
+
80
+	/**
81
+	 * generates an EE_Message using the supplied arguments and some defaults
82
+	 *
83
+	 * @param array $properties
84
+	 * @return EE_Message
85
+	 * @throws \EE_Error
86
+	 */
87
+	protected function _generate_message($properties = array())
88
+	{
89
+		// a message was generated immediately but the parent class will call this again
90
+		if ($this->_message instanceof EE_Message) {
91
+			return $this->_message;
92
+		}
93
+		$message = EEM_Message::instance()->get_one_by_token($this->token);
94
+		if (! $message instanceof EE_Message) {
95
+			throw new EE_Error(
96
+				sprintf(
97
+					esc_html__('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'),
98
+					$this->token
99
+				)
100
+			);
101
+		}
102
+		$message->set_STS_ID(EEM_Message::status_idle);
103
+
104
+		if (! $this->_sending_messenger instanceof EE_messenger) {
105
+			$message->set_STS_ID(EEM_Message::status_failed);
106
+			$message->set_error_message(
107
+				sprintf(
108
+					esc_html__('Unable to send message because the "%1$s" messenger is not active or not installed', 'event_espresso'),
109
+					$this->_sending_messenger
110
+				)
111
+			);
112
+		}
113
+
114
+		// set properties
115
+		$this->_valid = true;
116
+		$this->_messenger = $message->messenger_object();
117
+		$this->_message_type = $message->message_type_object();
118
+		$this->_send_now = $message->send_now();
119
+		return $message;
120
+	}
121 121
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Registration_Base_message_type.lib.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger)
37 37
     {
38 38
         // this is just a test
39
-        return $this->name . ' Message Type for ' . $messenger->name . ' Messenger ';
39
+        return $this->name.' Message Type for '.$messenger->name.' Messenger ';
40 40
     }
41 41
 
42 42
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
                     if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) {
56 56
                         $regs = $data_type;
57 57
                     } else {
58
-                        $regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg );
58
+                        $regs = is_array($data_type[0]) ? $data_type[0] : array($maybe_reg);
59 59
                     }
60 60
 
61 61
                     foreach ($regs as $reg) {
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
                             $this->_regs_for_sending[] = $reg->ID();
64 64
                         }
65 65
                     }
66
-                    $this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() );
66
+                    $this->_data = isset($this->_data[1]) ? array($maybe_reg->transaction(), null, $this->_data[1]) : array($maybe_reg->transaction());
67 67
                     $this->_data_handler = 'Gateways';
68 68
                 } else {
69 69
                     $this->_data_handler = 'Gateways';
@@ -82,17 +82,17 @@  discard block
 block discarded – undo
82 82
 
83 83
     protected function _get_data_for_context($context, EE_Registration $registration, $id)
84 84
     {
85
-        if ($context  == 'admin') {
85
+        if ($context == 'admin') {
86 86
             // use the registration to get the transaction.
87 87
             $transaction = $registration->transaction();
88 88
 
89 89
             // bail early if no transaction
90
-            if (! $transaction instanceof EE_Transaction) {
90
+            if ( ! $transaction instanceof EE_Transaction) {
91 91
                 throw new EE_Error(esc_html__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
92 92
             }
93 93
 
94
-            $payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0;
95
-            return array( $transaction, $payment );
94
+            $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array(array('PAY_ID' => $id, 'TXN_ID' => $transaction->ID()))) : 0;
95
+            return array($transaction, $payment);
96 96
         } else {
97 97
             return $registration;
98 98
         }
Please login to merge, or discard this patch.
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -12,126 +12,126 @@
 block discarded – undo
12 12
  */
13 13
 abstract class EE_Registration_Base_message_type extends EE_message_type
14 14
 {
15
-    /**
16
-     * @see parent::get_priority() for documentation.
17
-     * @return int
18
-     */
19
-    public function get_priority()
20
-    {
21
-        return EEM_Message::priority_medium;
22
-    }
23
-
24
-
25
-
26
-    protected function _set_admin_pages()
27
-    {
28
-        $this->admin_registered_pages = array(
29
-            'events_edit' => true
30
-            );
31
-    }
32
-
33
-
34
-    protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger)
35
-    {
36
-        // this is just a test
37
-        return $this->name . ' Message Type for ' . $messenger->name . ' Messenger ';
38
-    }
39
-
40
-
41
-
42
-
43
-    protected function _set_data_handler()
44
-    {
45
-        if (is_array($this->_data)) {
46
-            $data_type = reset($this->_data);
47
-
48
-            if (is_array($data_type)) {
49
-                // grab the first item and see if its a registration.
50
-                $maybe_reg = isset($data_type[0]) && is_array($data_type[0]) ? reset($data_type[0]) : reset($data_type);
51
-                if ($maybe_reg instanceof EE_Registration) {
52
-                    // is $data_type itself just an array of registrations?
53
-                    if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) {
54
-                        $regs = $data_type;
55
-                    } else {
56
-                        $regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg );
57
-                    }
58
-
59
-                    foreach ($regs as $reg) {
60
-                        if ($reg instanceof EE_Registration) {
61
-                            $this->_regs_for_sending[] = $reg->ID();
62
-                        }
63
-                    }
64
-                    $this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() );
65
-                    $this->_data_handler = 'Gateways';
66
-                } else {
67
-                    $this->_data_handler = 'Gateways';
68
-                }
69
-            } else {
70
-                $this->_data_handler = $data_type instanceof EE_Registration ? 'REG' : 'Gateways';
71
-            }
72
-        } else {
73
-            $this->_data_handler = $this->_data instanceof EE_Registration ? 'REG' : 'Gateways';
74
-        }
75
-
76
-        $this->_single_message = $this->_data_handler == 'REG' ? true : false;
77
-    }
78
-
79
-
80
-
81
-    protected function _get_data_for_context($context, EE_Registration $registration, $id)
82
-    {
83
-        if ($context  == 'admin') {
84
-            // use the registration to get the transaction.
85
-            $transaction = $registration->transaction();
86
-
87
-            // bail early if no transaction
88
-            if (! $transaction instanceof EE_Transaction) {
89
-                throw new EE_Error(esc_html__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
90
-            }
91
-
92
-            $payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0;
93
-            return array( $transaction, $payment );
94
-        } else {
95
-            return $registration;
96
-        }
97
-    }
98
-
99
-
100
-
101
-    /**
102
-     * Setup admin settings for this message type.
103
-     */
104
-    protected function _set_admin_settings_fields()
105
-    {
106
-        $this->_admin_settings_fields = array();
107
-    }
108
-
109
-
110
-
111
-
112
-
113
-    /**
114
-     * returns an array of addressee objects for event_admins
115
-     *
116
-     * @access protected
117
-     * @return array array of EE_Messages_Addressee objects
118
-     */
119
-    protected function _admin_addressees()
120
-    {
121
-        if ($this->_single_message) {
122
-            return array();
123
-        }
124
-        return parent::_admin_addressees();
125
-    }
126
-
127
-
128
-
129
-    protected function _primary_attendee_addressees()
130
-    {
131
-        if ($this->_single_message) {
132
-            return array();
133
-        }
134
-
135
-        return parent::_primary_attendee_addressees();
136
-    }
15
+	/**
16
+	 * @see parent::get_priority() for documentation.
17
+	 * @return int
18
+	 */
19
+	public function get_priority()
20
+	{
21
+		return EEM_Message::priority_medium;
22
+	}
23
+
24
+
25
+
26
+	protected function _set_admin_pages()
27
+	{
28
+		$this->admin_registered_pages = array(
29
+			'events_edit' => true
30
+			);
31
+	}
32
+
33
+
34
+	protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger)
35
+	{
36
+		// this is just a test
37
+		return $this->name . ' Message Type for ' . $messenger->name . ' Messenger ';
38
+	}
39
+
40
+
41
+
42
+
43
+	protected function _set_data_handler()
44
+	{
45
+		if (is_array($this->_data)) {
46
+			$data_type = reset($this->_data);
47
+
48
+			if (is_array($data_type)) {
49
+				// grab the first item and see if its a registration.
50
+				$maybe_reg = isset($data_type[0]) && is_array($data_type[0]) ? reset($data_type[0]) : reset($data_type);
51
+				if ($maybe_reg instanceof EE_Registration) {
52
+					// is $data_type itself just an array of registrations?
53
+					if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) {
54
+						$regs = $data_type;
55
+					} else {
56
+						$regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg );
57
+					}
58
+
59
+					foreach ($regs as $reg) {
60
+						if ($reg instanceof EE_Registration) {
61
+							$this->_regs_for_sending[] = $reg->ID();
62
+						}
63
+					}
64
+					$this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() );
65
+					$this->_data_handler = 'Gateways';
66
+				} else {
67
+					$this->_data_handler = 'Gateways';
68
+				}
69
+			} else {
70
+				$this->_data_handler = $data_type instanceof EE_Registration ? 'REG' : 'Gateways';
71
+			}
72
+		} else {
73
+			$this->_data_handler = $this->_data instanceof EE_Registration ? 'REG' : 'Gateways';
74
+		}
75
+
76
+		$this->_single_message = $this->_data_handler == 'REG' ? true : false;
77
+	}
78
+
79
+
80
+
81
+	protected function _get_data_for_context($context, EE_Registration $registration, $id)
82
+	{
83
+		if ($context  == 'admin') {
84
+			// use the registration to get the transaction.
85
+			$transaction = $registration->transaction();
86
+
87
+			// bail early if no transaction
88
+			if (! $transaction instanceof EE_Transaction) {
89
+				throw new EE_Error(esc_html__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso'));
90
+			}
91
+
92
+			$payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0;
93
+			return array( $transaction, $payment );
94
+		} else {
95
+			return $registration;
96
+		}
97
+	}
98
+
99
+
100
+
101
+	/**
102
+	 * Setup admin settings for this message type.
103
+	 */
104
+	protected function _set_admin_settings_fields()
105
+	{
106
+		$this->_admin_settings_fields = array();
107
+	}
108
+
109
+
110
+
111
+
112
+
113
+	/**
114
+	 * returns an array of addressee objects for event_admins
115
+	 *
116
+	 * @access protected
117
+	 * @return array array of EE_Messages_Addressee objects
118
+	 */
119
+	protected function _admin_addressees()
120
+	{
121
+		if ($this->_single_message) {
122
+			return array();
123
+		}
124
+		return parent::_admin_addressees();
125
+	}
126
+
127
+
128
+
129
+	protected function _primary_attendee_addressees()
130
+	{
131
+		if ($this->_single_message) {
132
+			return array();
133
+		}
134
+
135
+		return parent::_primary_attendee_addressees();
136
+	}
137 137
 }
Please login to merge, or discard this patch.
core/libraries/qtips/EE_Qtip_Config.lib.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -207,7 +207,7 @@
 block discarded – undo
207 207
     {
208 208
         foreach ($this->_qtipsa as $qt) {
209 209
             // make sure we have what we need.
210
-            if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) {
210
+            if ( ! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) {
211 211
                 throw new EE_Error(
212 212
                     sprintf(
213 213
                         esc_html__(
Please login to merge, or discard this patch.
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -14,235 +14,235 @@  discard block
 block discarded – undo
14 14
  */
15 15
 abstract class EE_Qtip_Config extends EE_Base
16 16
 {
17
-    /**
18
-     * This will hold the qtips setup array (setup by children)
19
-     *
20
-     * @access protected
21
-     * @var array
22
-     */
23
-    protected $_qtipsa;
17
+	/**
18
+	 * This will hold the qtips setup array (setup by children)
19
+	 *
20
+	 * @access protected
21
+	 * @var array
22
+	 */
23
+	protected $_qtipsa;
24 24
 
25 25
 
26
-    /**
27
-     * This holds the constructed EE_Qtip objects
28
-     *
29
-     * @access protected
30
-     * @var EE_Qtip
31
-     */
32
-    protected $_qtips;
26
+	/**
27
+	 * This holds the constructed EE_Qtip objects
28
+	 *
29
+	 * @access protected
30
+	 * @var EE_Qtip
31
+	 */
32
+	protected $_qtips;
33 33
 
34 34
 
35
-    /**
36
-     * an array of default options for instantiated qtip js objects
37
-     *
38
-     * @access protected
39
-     * @var array
40
-     */
41
-    protected $_default_options;
35
+	/**
36
+	 * an array of default options for instantiated qtip js objects
37
+	 *
38
+	 * @access protected
39
+	 * @var array
40
+	 */
41
+	protected $_default_options;
42 42
 
43 43
 
44
-    /**
45
-     * constructor
46
-     *
47
-     * @access public
48
-     */
49
-    public function __construct()
50
-    {
51
-        $this->_qtipsa = $this->_qtips = array();
52
-        $this->_set_default_options();
53
-        $this->_set_tips_array();
54
-        $this->_construct_tips();
55
-    }
44
+	/**
45
+	 * constructor
46
+	 *
47
+	 * @access public
48
+	 */
49
+	public function __construct()
50
+	{
51
+		$this->_qtipsa = $this->_qtips = array();
52
+		$this->_set_default_options();
53
+		$this->_set_tips_array();
54
+		$this->_construct_tips();
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * Children define this method and its purpose is to setup the $_qtipsa property.  The format of this property is:
60
-     *
61
-     * $qtipsa = array(
62
-     *        0 => array(
63
-     *            'content_id' => 'some_unique_id_for_referencing_content', //just the string
64
-     *            'content' => 'html/text content for the qtip',
65
-     *            'target' => '#target-element', //use the same schema as jQuery selectors.  This will match what the
66
-     *            target is for the qTip in the dom (i.e. if class then '.some-class').
67
-     *            'options' => array() //use this to override any of the default options for this specific qtip.
68
-     *        )
69
-     * );
70
-     *
71
-     * @abstract
72
-     * @access protected
73
-     * @return void
74
-     */
75
-    abstract protected function _set_tips_array();
58
+	/**
59
+	 * Children define this method and its purpose is to setup the $_qtipsa property.  The format of this property is:
60
+	 *
61
+	 * $qtipsa = array(
62
+	 *        0 => array(
63
+	 *            'content_id' => 'some_unique_id_for_referencing_content', //just the string
64
+	 *            'content' => 'html/text content for the qtip',
65
+	 *            'target' => '#target-element', //use the same schema as jQuery selectors.  This will match what the
66
+	 *            target is for the qTip in the dom (i.e. if class then '.some-class').
67
+	 *            'options' => array() //use this to override any of the default options for this specific qtip.
68
+	 *        )
69
+	 * );
70
+	 *
71
+	 * @abstract
72
+	 * @access protected
73
+	 * @return void
74
+	 */
75
+	abstract protected function _set_tips_array();
76 76
 
77 77
 
78
-    /**
79
-     * all the default options for the qtip js are defined here.  Children class can override the defaults for all the
80
-     * qtips defined in their config OR just leave it and have the parent default options apply.
81
-     *
82
-     * commented out options are there for reference so you know which can be defined by the child.
83
-     *
84
-     * Note: children do NOT have to define all these options.  Just define the ones to override.
85
-     *
86
-     * @link   http://qtip2.com/options
87
-     *
88
-     * @access protected
89
-     * @return void
90
-     */
91
-    protected function _set_default_options()
92
-    {
93
-        $this->_default_options = array(
94
-            // 'id' => 'unique_id_referncing_qtip_instance',
95
-            'prerender'      => false,
96
-            // increases page load if true,
97
-            'suppress'       => true,
98
-            // whether default browser tooltips are suppressed.
99
-            'content'        => array(
100
-                'button' => false,
101
-                // what you want for the close button text/link.
102
-                'title'  => true,
103
-                // Options: "string", true.  If TRUE then the title attribute of the target will be used (if available). If "string" then we'll use that as the title.
104
-                'clone'  => true,
105
-                // Options: true|false.  if true then the text will be cloned from the content instead of removed from the dom.
106
-            ),
107
-            'show_only_once' => false,
108
-            // this is NOT a qtip2 library option, but is something added for EE specific use.  If set to true, this means that this particular tooltip will only show ONCE for the user and then a cookie will be saved so that it doesn't show again (after exit).
109
-            'position'       => array(
110
-                'my'        => 'top left',
111
-                // top left || top center || top right || right top || right center || right bottom || bottom right || bottom center || bottom left || left bottom || left center || left top
112
-                'at'        => 'bottom right',
113
-                // same options as above.
114
-                'target'    => 'event',
115
-                // if u use jQuery::#selector, js will parse to a jQuery selector || 'mouse' (at mouse cursor position) || 'event' (position at target that triggered the tooltip), or an array containing an absolute x/y position on page.
116
-                'container' => false,
117
-                // what HTML element the tooltip is appended to (it's containing element). jquery object.  Use 'jQuery::#selector' and js will parse'
118
-                'viewport'  => true,
119
-                // @link http://qtip2.com/plugins#viewport
120
-                'adjust'    => array(
121
-                    'x'      => 0,
122
-                    // adjust position on x axis by 0 pixels.
123
-                    'y'      => 0,
124
-                    // adjust position on y axis by 0 pixels.
125
-                    'mouse'  => true,
126
-                    // when position['target'] is set to 'mouse', tooltip will follow mouse when hovering over the target.  False, stops following.
127
-                    'resize' => true,
128
-                    // adjust tooltip position when window is resized.
129
-                    'scroll' => true,
130
-                    // position of tooltip adjusted when window (or position.container) is scrolled.
131
-                    'method' => 'flipinvert',
132
-                    // @link http://qtip2.com/plugins#viewport
133
-                ),
134
-            ),
135
-            'show'           => array(
136
-                'event'  => 'mouseenter',
137
-                // what event triggers tooltip to be shown.  Any jQuery standard event or custom events can be used. space separated events provide multiple triggers.
138
-                'target' => false,
139
-                // options jQuery::#selector|false.  Used to indicate which html element will trigger show event.  When false, the element the qtip() method was called upon is used.
140
-                'delay'  => 90,
141
-                // time in millisecons by which to delay showing of tooltip.
142
-                'solo'   => false,
143
-                // determines whether tooltip will hid all others when triggered. Options: true (hide all) || false (ignore) || string (parent selector for which qtips get hidden)
144
-                'modal'  => array(
145
-                    'on'         => false, // does tooltip trigger modal?
146
-                    'blur'       => true, // does clicking on the dimmed background hide the tooltip and remove the dim?
147
-                    'escape'     => true, // hitting escape key hide the tooltip and cancel modal
148
-                    'stealfocus' => true, // can users focus on inputs and elelments outside of tooltip when modal on?
149
-                ),
150
-            ),
151
-            'hide'           => array(
152
-                'event'    => 'mouseleave',
153
-                // similar as what you do for show.event.
154
-                'target'   => false,
155
-                // Options jQuery::#selector. which html element will trigger hide event. When false, the element the .qtip() method was called upon is used.
156
-                'delay'    => 0,
157
-                // set time in milliseconds for delaying the hide of the tooltip
158
-                'inactive' => false,
159
-                // if integer, time in millisecons in which the tooltip should be hidden if remains inactive (not interacted with)
160
-                'fixed'    => false,
161
-                // when set to true, the tooltip will not hide if moused over.
162
-                'leave'    => 'window',
163
-                // specify whether the tooltip will hide when leaving the window it's conained within.
164
-                'distance' => false,
165
-                // if integer, distance in pixels that the tooltip hides when the mouse is moved from the point it triggered the tooltip.
166
-            ),
167
-            'style'          => array(
168
-                'classes' => 'qtip-tipsy',
169
-                // Options "string", false.  A space separated string containing all class names which should be added ot the main qTip element. See options for styles in comment block at end of this class.
170
-                'def'     => true,
171
-                // set to false and the default qtip class does not get applied
172
-                'widget'  => false,
173
-                // whether ui-widget classes of the themeroller UI styles are applied to tooltip.
174
-                'width'   => false,
175
-                // Options: "string", integer, false.  with this you can override all applied CSS width styles for tooltip.  Can be any valid width CSS value. (does not override min/max width styles)
176
-                'height'  => false,
177
-                // same as above except applies to height.
178
-                'tip'     => array(
179
-                    'corner' => true,
180
-                    // where in relation to the tooltip the speech bubble tip is applied. Options: true, "corner string" (see position), false.  true inherits
181
-                    'mimic'  => false,
182
-                    // see documentation @link http://qtip2.com/plugins#tips
183
-                    'border' => true,
184
-                    // Options: true, integer. determines the width of the border that surrounds the tip element.  True inherits from tooltip.
185
-                    'width'  => 6,
186
-                    // width of rendered tip in pixels in relation to the side of the tooltip the tip is on.
187
-                    'height' => 6,
188
-                    // works the same as tip.width
189
-                    'offset' => 0,
190
-                    // use to set the offset of the tip in relation to its corner position.
191
-                ),
192
-            ),
78
+	/**
79
+	 * all the default options for the qtip js are defined here.  Children class can override the defaults for all the
80
+	 * qtips defined in their config OR just leave it and have the parent default options apply.
81
+	 *
82
+	 * commented out options are there for reference so you know which can be defined by the child.
83
+	 *
84
+	 * Note: children do NOT have to define all these options.  Just define the ones to override.
85
+	 *
86
+	 * @link   http://qtip2.com/options
87
+	 *
88
+	 * @access protected
89
+	 * @return void
90
+	 */
91
+	protected function _set_default_options()
92
+	{
93
+		$this->_default_options = array(
94
+			// 'id' => 'unique_id_referncing_qtip_instance',
95
+			'prerender'      => false,
96
+			// increases page load if true,
97
+			'suppress'       => true,
98
+			// whether default browser tooltips are suppressed.
99
+			'content'        => array(
100
+				'button' => false,
101
+				// what you want for the close button text/link.
102
+				'title'  => true,
103
+				// Options: "string", true.  If TRUE then the title attribute of the target will be used (if available). If "string" then we'll use that as the title.
104
+				'clone'  => true,
105
+				// Options: true|false.  if true then the text will be cloned from the content instead of removed from the dom.
106
+			),
107
+			'show_only_once' => false,
108
+			// this is NOT a qtip2 library option, but is something added for EE specific use.  If set to true, this means that this particular tooltip will only show ONCE for the user and then a cookie will be saved so that it doesn't show again (after exit).
109
+			'position'       => array(
110
+				'my'        => 'top left',
111
+				// top left || top center || top right || right top || right center || right bottom || bottom right || bottom center || bottom left || left bottom || left center || left top
112
+				'at'        => 'bottom right',
113
+				// same options as above.
114
+				'target'    => 'event',
115
+				// if u use jQuery::#selector, js will parse to a jQuery selector || 'mouse' (at mouse cursor position) || 'event' (position at target that triggered the tooltip), or an array containing an absolute x/y position on page.
116
+				'container' => false,
117
+				// what HTML element the tooltip is appended to (it's containing element). jquery object.  Use 'jQuery::#selector' and js will parse'
118
+				'viewport'  => true,
119
+				// @link http://qtip2.com/plugins#viewport
120
+				'adjust'    => array(
121
+					'x'      => 0,
122
+					// adjust position on x axis by 0 pixels.
123
+					'y'      => 0,
124
+					// adjust position on y axis by 0 pixels.
125
+					'mouse'  => true,
126
+					// when position['target'] is set to 'mouse', tooltip will follow mouse when hovering over the target.  False, stops following.
127
+					'resize' => true,
128
+					// adjust tooltip position when window is resized.
129
+					'scroll' => true,
130
+					// position of tooltip adjusted when window (or position.container) is scrolled.
131
+					'method' => 'flipinvert',
132
+					// @link http://qtip2.com/plugins#viewport
133
+				),
134
+			),
135
+			'show'           => array(
136
+				'event'  => 'mouseenter',
137
+				// what event triggers tooltip to be shown.  Any jQuery standard event or custom events can be used. space separated events provide multiple triggers.
138
+				'target' => false,
139
+				// options jQuery::#selector|false.  Used to indicate which html element will trigger show event.  When false, the element the qtip() method was called upon is used.
140
+				'delay'  => 90,
141
+				// time in millisecons by which to delay showing of tooltip.
142
+				'solo'   => false,
143
+				// determines whether tooltip will hid all others when triggered. Options: true (hide all) || false (ignore) || string (parent selector for which qtips get hidden)
144
+				'modal'  => array(
145
+					'on'         => false, // does tooltip trigger modal?
146
+					'blur'       => true, // does clicking on the dimmed background hide the tooltip and remove the dim?
147
+					'escape'     => true, // hitting escape key hide the tooltip and cancel modal
148
+					'stealfocus' => true, // can users focus on inputs and elelments outside of tooltip when modal on?
149
+				),
150
+			),
151
+			'hide'           => array(
152
+				'event'    => 'mouseleave',
153
+				// similar as what you do for show.event.
154
+				'target'   => false,
155
+				// Options jQuery::#selector. which html element will trigger hide event. When false, the element the .qtip() method was called upon is used.
156
+				'delay'    => 0,
157
+				// set time in milliseconds for delaying the hide of the tooltip
158
+				'inactive' => false,
159
+				// if integer, time in millisecons in which the tooltip should be hidden if remains inactive (not interacted with)
160
+				'fixed'    => false,
161
+				// when set to true, the tooltip will not hide if moused over.
162
+				'leave'    => 'window',
163
+				// specify whether the tooltip will hide when leaving the window it's conained within.
164
+				'distance' => false,
165
+				// if integer, distance in pixels that the tooltip hides when the mouse is moved from the point it triggered the tooltip.
166
+			),
167
+			'style'          => array(
168
+				'classes' => 'qtip-tipsy',
169
+				// Options "string", false.  A space separated string containing all class names which should be added ot the main qTip element. See options for styles in comment block at end of this class.
170
+				'def'     => true,
171
+				// set to false and the default qtip class does not get applied
172
+				'widget'  => false,
173
+				// whether ui-widget classes of the themeroller UI styles are applied to tooltip.
174
+				'width'   => false,
175
+				// Options: "string", integer, false.  with this you can override all applied CSS width styles for tooltip.  Can be any valid width CSS value. (does not override min/max width styles)
176
+				'height'  => false,
177
+				// same as above except applies to height.
178
+				'tip'     => array(
179
+					'corner' => true,
180
+					// where in relation to the tooltip the speech bubble tip is applied. Options: true, "corner string" (see position), false.  true inherits
181
+					'mimic'  => false,
182
+					// see documentation @link http://qtip2.com/plugins#tips
183
+					'border' => true,
184
+					// Options: true, integer. determines the width of the border that surrounds the tip element.  True inherits from tooltip.
185
+					'width'  => 6,
186
+					// width of rendered tip in pixels in relation to the side of the tooltip the tip is on.
187
+					'height' => 6,
188
+					// works the same as tip.width
189
+					'offset' => 0,
190
+					// use to set the offset of the tip in relation to its corner position.
191
+				),
192
+			),
193 193
 
194
-        );
195
-    }
194
+		);
195
+	}
196 196
 
197 197
 
198
-    /**
199
-     * This takes the set $_qtipsa array property and loops through it to set the EE_Qtip objects and assign them to
200
-     * the $_qtips property
201
-     *
202
-     * @access protected
203
-     * @return void
204
-     */
205
-    protected function _construct_tips()
206
-    {
207
-        foreach ($this->_qtipsa as $qt) {
208
-            // make sure we have what we need.
209
-            if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) {
210
-                throw new EE_Error(
211
-                    sprintf(
212
-                        esc_html__(
213
-                            'There is something wrong with the _qtipsa property setup for the %s qtip config class.  The dump of the current array index is: %s.<br /><br />Please check that it is setup correctly.',
214
-                            'event_espresso'
215
-                        ),
216
-                        get_class($this),
217
-                        var_export($qt, true)
218
-                    )
219
-                );
220
-            }
198
+	/**
199
+	 * This takes the set $_qtipsa array property and loops through it to set the EE_Qtip objects and assign them to
200
+	 * the $_qtips property
201
+	 *
202
+	 * @access protected
203
+	 * @return void
204
+	 */
205
+	protected function _construct_tips()
206
+	{
207
+		foreach ($this->_qtipsa as $qt) {
208
+			// make sure we have what we need.
209
+			if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) {
210
+				throw new EE_Error(
211
+					sprintf(
212
+						esc_html__(
213
+							'There is something wrong with the _qtipsa property setup for the %s qtip config class.  The dump of the current array index is: %s.<br /><br />Please check that it is setup correctly.',
214
+							'event_espresso'
215
+						),
216
+						get_class($this),
217
+						var_export($qt, true)
218
+					)
219
+				);
220
+			}
221 221
 
222
-            // make sure the options include defaults and just override via set config.
223
-            $options_override = isset($qt['options']) ? (array) $qt['options'] : array();
224
-            $options = array_merge($this->_default_options, $options_override);
225
-            $setup = array(
226
-                'content_id' => $qt['content_id'],
227
-                'options'    => $options,
228
-                'target'     => $qt['target'],
229
-                'content'    => $qt['content'],
230
-            );
231
-            $this->_qtips[] = new EE_Qtip($setup);
232
-        }
233
-    }
222
+			// make sure the options include defaults and just override via set config.
223
+			$options_override = isset($qt['options']) ? (array) $qt['options'] : array();
224
+			$options = array_merge($this->_default_options, $options_override);
225
+			$setup = array(
226
+				'content_id' => $qt['content_id'],
227
+				'options'    => $options,
228
+				'target'     => $qt['target'],
229
+				'content'    => $qt['content'],
230
+			);
231
+			$this->_qtips[] = new EE_Qtip($setup);
232
+		}
233
+	}
234 234
 
235 235
 
236
-    /**
237
-     * return the _qtips property contents
238
-     *
239
-     * @access public
240
-     * @return EE_Qtip[]
241
-     */
242
-    public function get_tips()
243
-    {
244
-        return $this->_qtips;
245
-    }
236
+	/**
237
+	 * return the _qtips property contents
238
+	 *
239
+	 * @access public
240
+	 * @return EE_Qtip[]
241
+	 */
242
+	public function get_tips()
243
+	{
244
+		return $this->_qtips;
245
+	}
246 246
 }
247 247
 
248 248
 // class names you can use for tooltip styles
@@ -294,17 +294,17 @@  discard block
 block discarded – undo
294 294
  */
295 295
 class EE_Qtip extends EE_Base
296 296
 {
297
-    public $content_id;
298
-    public $options;
299
-    public $target;
300
-    public $content;
297
+	public $content_id;
298
+	public $options;
299
+	public $target;
300
+	public $content;
301 301
 
302
-    public function __construct($setup_array)
303
-    {
304
-        foreach ($setup_array as $prop => $value) {
305
-            if (EEH_Class_Tools::has_property($this, $prop)) {
306
-                $this->{$prop} = $value;
307
-            }
308
-        }
309
-    }
302
+	public function __construct($setup_array)
303
+	{
304
+		foreach ($setup_array as $prop => $value) {
305
+			if (EEH_Class_Tools::has_property($this, $prop)) {
306
+				$this->{$prop} = $value;
307
+			}
308
+		}
309
+	}
310 310
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/db/EEME_Base.lib.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function __construct()
73 73
     {
74
-        if (! $this->_model_name_extended) {
74
+        if ( ! $this->_model_name_extended) {
75 75
             throw new EE_Error(
76 76
                 esc_html__(
77 77
                     "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'",
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
                 )
80 80
             );
81 81
         }
82
-        $construct_end_action = 'AHEE__EEM_' . $this->_model_name_extended . '__construct__end';
82
+        $construct_end_action = 'AHEE__EEM_'.$this->_model_name_extended.'__construct__end';
83 83
         if (did_action($construct_end_action)) {
84 84
             throw new EE_Error(
85 85
                 sprintf(
@@ -94,15 +94,15 @@  discard block
 block discarded – undo
94 94
             );
95 95
         }
96 96
         add_filter(
97
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables',
97
+            'FHEE__EEM_'.$this->_model_name_extended.'__construct__tables',
98 98
             array($this, 'add_extra_tables_on_filter')
99 99
         );
100 100
         add_filter(
101
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields',
101
+            'FHEE__EEM_'.$this->_model_name_extended.'__construct__fields',
102 102
             array($this, 'add_extra_fields_on_filter')
103 103
         );
104 104
         add_filter(
105
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations',
105
+            'FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations',
106 106
             array($this, 'add_extra_relations_on_filter')
107 107
         );
108 108
         $this->_register_extending_methods();
@@ -127,12 +127,12 @@  discard block
 block discarded – undo
127 127
     {
128 128
         if ($this->_extra_fields) {
129 129
             foreach ($this->_extra_fields as $table_alias => $fields) {
130
-                if (! isset($existing_fields[ $table_alias ])) {
131
-                    $existing_fields[ $table_alias ] = array();
130
+                if ( ! isset($existing_fields[$table_alias])) {
131
+                    $existing_fields[$table_alias] = array();
132 132
                 }
133
-                $existing_fields[ $table_alias ] = array_merge(
134
-                    (array) $existing_fields[ $table_alias ],
135
-                    $this->_extra_fields[ $table_alias ]
133
+                $existing_fields[$table_alias] = array_merge(
134
+                    (array) $existing_fields[$table_alias],
135
+                    $this->_extra_fields[$table_alias]
136 136
                 );
137 137
             }
138 138
         }
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
                 $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model";
164 164
                 add_filter(
165 165
                     $callback_name,
166
-                    array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
166
+                    array($this, self::dynamic_callback_method_prefix.$method_name_on_model),
167 167
                     10,
168 168
                     10
169 169
                 );
@@ -178,15 +178,15 @@  discard block
 block discarded – undo
178 178
     public function deregister()
179 179
     {
180 180
         remove_filter(
181
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables',
181
+            'FHEE__EEM_'.$this->_model_name_extended.'__construct__tables',
182 182
             array($this, 'add_extra_tables_on_filter')
183 183
         );
184 184
         remove_filter(
185
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields',
185
+            'FHEE__EEM_'.$this->_model_name_extended.'__construct__fields',
186 186
             array($this, 'add_extra_fields_on_filter')
187 187
         );
188 188
         remove_filter(
189
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations',
189
+            'FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations',
190 190
             array($this, 'add_extra_relations_on_filter')
191 191
         );
192 192
         $all_methods = get_class_methods(get_class($this));
@@ -196,13 +196,13 @@  discard block
 block discarded – undo
196 196
                 $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model";
197 197
                 remove_filter(
198 198
                     $callback_name,
199
-                    array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
199
+                    array($this, self::dynamic_callback_method_prefix.$method_name_on_model),
200 200
                     10
201 201
                 );
202 202
             }
203 203
         }
204 204
         /** @var EEM_Base $model_to_reset */
205
-        $model_to_reset = 'EEM_' . $this->_model_name_extended;
205
+        $model_to_reset = 'EEM_'.$this->_model_name_extended;
206 206
         if (class_exists($model_to_reset)) {
207 207
             $model_to_reset::reset();
208 208
         }
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
             // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction
225 225
             $this->_ = $model_called;
226 226
             // phpcs:enable
227
-            $extending_method = self::extending_method_prefix . $method_called_on_model;
227
+            $extending_method = self::extending_method_prefix.$method_called_on_model;
228 228
             if (method_exists($this, $extending_method)) {
229 229
                 return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model);
230 230
             } else {
Please login to merge, or discard this patch.
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -43,211 +43,211 @@
 block discarded – undo
43 43
  */
44 44
 abstract class EEME_Base
45 45
 {
46
-    const extending_method_prefix = 'ext_';
47
-    const dynamic_callback_method_prefix = 'dynamic_callback_method_';
48
-
49
-    protected $_extra_tables = array();
50
-    protected $_extra_fields = array();
51
-    protected $_extra_relations = array();
52
-
53
-    /**
54
-     * The model name that is extended (not classname)
55
-     *
56
-     * @var string
57
-     */
58
-    protected $_model_name_extended = null;
59
-
60
-    /**
61
-     * The model this extends
62
-     *
63
-     * @var EEM_Base
64
-     */
65
-    protected $_ = null;
66
-
67
-
68
-    /**
69
-     * @throws \EE_Error
70
-     */
71
-    public function __construct()
72
-    {
73
-        if (! $this->_model_name_extended) {
74
-            throw new EE_Error(
75
-                esc_html__(
76
-                    "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'",
77
-                    "event_espresso"
78
-                )
79
-            );
80
-        }
81
-        $construct_end_action = 'AHEE__EEM_' . $this->_model_name_extended . '__construct__end';
82
-        if (did_action($construct_end_action)) {
83
-            throw new EE_Error(
84
-                sprintf(
85
-                    esc_html__(
86
-                        "Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired",
87
-                        "event_espresso"
88
-                    ),
89
-                    get_class($this),
90
-                    $this->_model_name_extended,
91
-                    $construct_end_action
92
-                )
93
-            );
94
-        }
95
-        add_filter(
96
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables',
97
-            array($this, 'add_extra_tables_on_filter')
98
-        );
99
-        add_filter(
100
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields',
101
-            array($this, 'add_extra_fields_on_filter')
102
-        );
103
-        add_filter(
104
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations',
105
-            array($this, 'add_extra_relations_on_filter')
106
-        );
107
-        $this->_register_extending_methods();
108
-    }
109
-
110
-
111
-    /**
112
-     * @param array $existing_tables
113
-     * @return array
114
-     */
115
-    public function add_extra_tables_on_filter($existing_tables)
116
-    {
117
-        return array_merge((array) $existing_tables, $this->_extra_tables);
118
-    }
119
-
120
-
121
-    /**
122
-     * @param array $existing_fields
123
-     * @return array
124
-     */
125
-    public function add_extra_fields_on_filter($existing_fields)
126
-    {
127
-        if ($this->_extra_fields) {
128
-            foreach ($this->_extra_fields as $table_alias => $fields) {
129
-                if (! isset($existing_fields[ $table_alias ])) {
130
-                    $existing_fields[ $table_alias ] = array();
131
-                }
132
-                $existing_fields[ $table_alias ] = array_merge(
133
-                    (array) $existing_fields[ $table_alias ],
134
-                    $this->_extra_fields[ $table_alias ]
135
-                );
136
-            }
137
-        }
138
-        return $existing_fields;
139
-    }
140
-
141
-
142
-    /**
143
-     * @param array $existing_relations
144
-     * @return array
145
-     */
146
-    public function add_extra_relations_on_filter($existing_relations)
147
-    {
148
-        return array_merge((array) $existing_relations, $this->_extra_relations);
149
-    }
150
-
151
-
152
-    /**
153
-     * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the
154
-     * model extended. (Internally uses filters, and the __call magic method)
155
-     */
156
-    protected function _register_extending_methods()
157
-    {
158
-        $all_methods = get_class_methods(get_class($this));
159
-        foreach ($all_methods as $method_name) {
160
-            if (strpos($method_name, self::extending_method_prefix) === 0) {
161
-                $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name);
162
-                $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model";
163
-                add_filter(
164
-                    $callback_name,
165
-                    array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
166
-                    10,
167
-                    10
168
-                );
169
-            }
170
-        }
171
-    }
172
-
173
-    /**
174
-     * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the
175
-     * model extended. (Internally uses filters, and the __call magic method)
176
-     */
177
-    public function deregister()
178
-    {
179
-        remove_filter(
180
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables',
181
-            array($this, 'add_extra_tables_on_filter')
182
-        );
183
-        remove_filter(
184
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields',
185
-            array($this, 'add_extra_fields_on_filter')
186
-        );
187
-        remove_filter(
188
-            'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations',
189
-            array($this, 'add_extra_relations_on_filter')
190
-        );
191
-        $all_methods = get_class_methods(get_class($this));
192
-        foreach ($all_methods as $method_name) {
193
-            if (strpos($method_name, self::extending_method_prefix) === 0) {
194
-                $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name);
195
-                $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model";
196
-                remove_filter(
197
-                    $callback_name,
198
-                    array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
199
-                    10
200
-                );
201
-            }
202
-        }
203
-        /** @var EEM_Base $model_to_reset */
204
-        $model_to_reset = 'EEM_' . $this->_model_name_extended;
205
-        if (class_exists($model_to_reset)) {
206
-            $model_to_reset::reset();
207
-        }
208
-    }
209
-
210
-
211
-    /**
212
-     * @param string $callback_method_name
213
-     * @param array  $args
214
-     * @return mixed
215
-     * @throws EE_Error
216
-     */
217
-    public function __call($callback_method_name, $args)
218
-    {
219
-        if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) {
220
-            // it's a dynamic callback for a method name
221
-            $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name);
222
-            list($original_return_val, $model_called, $args_provided_to_method_on_model) = (array) $args;
223
-            // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction
224
-            $this->_ = $model_called;
225
-            // phpcs:enable
226
-            $extending_method = self::extending_method_prefix . $method_called_on_model;
227
-            if (method_exists($this, $extending_method)) {
228
-                return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model);
229
-            } else {
230
-                throw new EE_Error(
231
-                    sprintf(
232
-                        esc_html__(
233
-                            "An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)",
234
-                            "event_espresso"
235
-                        ),
236
-                        $this->_model_name_extended,
237
-                        get_class($this),
238
-                        $extending_method,
239
-                        $extending_method
240
-                    )
241
-                );
242
-            }
243
-        } else {
244
-            throw new EE_Error(
245
-                sprintf(
246
-                    esc_html__("There is no method named '%s' on '%s'", "event_espresso"),
247
-                    $callback_method_name,
248
-                    get_class($this)
249
-                )
250
-            );
251
-        }
252
-    }
46
+	const extending_method_prefix = 'ext_';
47
+	const dynamic_callback_method_prefix = 'dynamic_callback_method_';
48
+
49
+	protected $_extra_tables = array();
50
+	protected $_extra_fields = array();
51
+	protected $_extra_relations = array();
52
+
53
+	/**
54
+	 * The model name that is extended (not classname)
55
+	 *
56
+	 * @var string
57
+	 */
58
+	protected $_model_name_extended = null;
59
+
60
+	/**
61
+	 * The model this extends
62
+	 *
63
+	 * @var EEM_Base
64
+	 */
65
+	protected $_ = null;
66
+
67
+
68
+	/**
69
+	 * @throws \EE_Error
70
+	 */
71
+	public function __construct()
72
+	{
73
+		if (! $this->_model_name_extended) {
74
+			throw new EE_Error(
75
+				esc_html__(
76
+					"When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'",
77
+					"event_espresso"
78
+				)
79
+			);
80
+		}
81
+		$construct_end_action = 'AHEE__EEM_' . $this->_model_name_extended . '__construct__end';
82
+		if (did_action($construct_end_action)) {
83
+			throw new EE_Error(
84
+				sprintf(
85
+					esc_html__(
86
+						"Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired",
87
+						"event_espresso"
88
+					),
89
+					get_class($this),
90
+					$this->_model_name_extended,
91
+					$construct_end_action
92
+				)
93
+			);
94
+		}
95
+		add_filter(
96
+			'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables',
97
+			array($this, 'add_extra_tables_on_filter')
98
+		);
99
+		add_filter(
100
+			'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields',
101
+			array($this, 'add_extra_fields_on_filter')
102
+		);
103
+		add_filter(
104
+			'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations',
105
+			array($this, 'add_extra_relations_on_filter')
106
+		);
107
+		$this->_register_extending_methods();
108
+	}
109
+
110
+
111
+	/**
112
+	 * @param array $existing_tables
113
+	 * @return array
114
+	 */
115
+	public function add_extra_tables_on_filter($existing_tables)
116
+	{
117
+		return array_merge((array) $existing_tables, $this->_extra_tables);
118
+	}
119
+
120
+
121
+	/**
122
+	 * @param array $existing_fields
123
+	 * @return array
124
+	 */
125
+	public function add_extra_fields_on_filter($existing_fields)
126
+	{
127
+		if ($this->_extra_fields) {
128
+			foreach ($this->_extra_fields as $table_alias => $fields) {
129
+				if (! isset($existing_fields[ $table_alias ])) {
130
+					$existing_fields[ $table_alias ] = array();
131
+				}
132
+				$existing_fields[ $table_alias ] = array_merge(
133
+					(array) $existing_fields[ $table_alias ],
134
+					$this->_extra_fields[ $table_alias ]
135
+				);
136
+			}
137
+		}
138
+		return $existing_fields;
139
+	}
140
+
141
+
142
+	/**
143
+	 * @param array $existing_relations
144
+	 * @return array
145
+	 */
146
+	public function add_extra_relations_on_filter($existing_relations)
147
+	{
148
+		return array_merge((array) $existing_relations, $this->_extra_relations);
149
+	}
150
+
151
+
152
+	/**
153
+	 * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the
154
+	 * model extended. (Internally uses filters, and the __call magic method)
155
+	 */
156
+	protected function _register_extending_methods()
157
+	{
158
+		$all_methods = get_class_methods(get_class($this));
159
+		foreach ($all_methods as $method_name) {
160
+			if (strpos($method_name, self::extending_method_prefix) === 0) {
161
+				$method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name);
162
+				$callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model";
163
+				add_filter(
164
+					$callback_name,
165
+					array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
166
+					10,
167
+					10
168
+				);
169
+			}
170
+		}
171
+	}
172
+
173
+	/**
174
+	 * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the
175
+	 * model extended. (Internally uses filters, and the __call magic method)
176
+	 */
177
+	public function deregister()
178
+	{
179
+		remove_filter(
180
+			'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables',
181
+			array($this, 'add_extra_tables_on_filter')
182
+		);
183
+		remove_filter(
184
+			'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields',
185
+			array($this, 'add_extra_fields_on_filter')
186
+		);
187
+		remove_filter(
188
+			'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations',
189
+			array($this, 'add_extra_relations_on_filter')
190
+		);
191
+		$all_methods = get_class_methods(get_class($this));
192
+		foreach ($all_methods as $method_name) {
193
+			if (strpos($method_name, self::extending_method_prefix) === 0) {
194
+				$method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name);
195
+				$callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model";
196
+				remove_filter(
197
+					$callback_name,
198
+					array($this, self::dynamic_callback_method_prefix . $method_name_on_model),
199
+					10
200
+				);
201
+			}
202
+		}
203
+		/** @var EEM_Base $model_to_reset */
204
+		$model_to_reset = 'EEM_' . $this->_model_name_extended;
205
+		if (class_exists($model_to_reset)) {
206
+			$model_to_reset::reset();
207
+		}
208
+	}
209
+
210
+
211
+	/**
212
+	 * @param string $callback_method_name
213
+	 * @param array  $args
214
+	 * @return mixed
215
+	 * @throws EE_Error
216
+	 */
217
+	public function __call($callback_method_name, $args)
218
+	{
219
+		if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) {
220
+			// it's a dynamic callback for a method name
221
+			$method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name);
222
+			list($original_return_val, $model_called, $args_provided_to_method_on_model) = (array) $args;
223
+			// phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction
224
+			$this->_ = $model_called;
225
+			// phpcs:enable
226
+			$extending_method = self::extending_method_prefix . $method_called_on_model;
227
+			if (method_exists($this, $extending_method)) {
228
+				return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model);
229
+			} else {
230
+				throw new EE_Error(
231
+					sprintf(
232
+						esc_html__(
233
+							"An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)",
234
+							"event_espresso"
235
+						),
236
+						$this->_model_name_extended,
237
+						get_class($this),
238
+						$extending_method,
239
+						$extending_method
240
+					)
241
+				);
242
+			}
243
+		} else {
244
+			throw new EE_Error(
245
+				sprintf(
246
+					esc_html__("There is no method named '%s' on '%s'", "event_espresso"),
247
+					$callback_method_name,
248
+					get_class($this)
249
+				)
250
+			);
251
+		}
252
+	}
253 253
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Payment_List_Shortcodes.lib.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,15 +29,15 @@  discard block
 block discarded – undo
29 29
                 'Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults.  Attributes that are available are:',
30 30
                 'event_espresso'
31 31
             )
32
-                                  . '<p><ul>' .
33
-                                  '<li><strong>no_payments</strong>:' . sprintf(
32
+                                  . '<p><ul>'.
33
+                                  '<li><strong>no_payments</strong>:'.sprintf(
34 34
                                       esc_html__(
35 35
                                           'Indicate with this attribute what will be used if there are no payments present.  Default is: "%sNo approved payments have been received.%s"',
36 36
                                           'event_espresso'
37 37
                                       ),
38 38
                                       htmlspecialchars('<td class="aln-cntr" colspan="6">'),
39 39
                                       htmlspecialchars('</td>')
40
-                                  ) . '</li>' .
40
+                                  ).'</li>'.
41 41
                                   '</ul></p>',
42 42
         );
43 43
     }
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         $this->_validate_list_requirements();
68 68
 
69 69
 
70
-        if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
70
+        if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) {
71 71
             return '';
72 72
         }
73 73
 
Please login to merge, or discard this patch.
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -18,87 +18,87 @@
 block discarded – undo
18 18
  */
19 19
 class EE_Payment_List_Shortcodes extends EE_Shortcodes
20 20
 {
21
-    protected function _init_props()
22
-    {
23
-        $this->label = esc_html__('Payment List Shortcodes', 'event_espresso');
24
-        $this->description = esc_html__('All shortcodes specific to payment lists', 'event_espresso');
25
-        $this->_shortcodes = array(
26
-            '[PAYMENT_LIST_*]' => esc_html__(
27
-                'Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults.  Attributes that are available are:',
28
-                'event_espresso'
29
-            )
30
-                                  . '<p><ul>' .
31
-                                  '<li><strong>no_payments</strong>:' . sprintf(
32
-                                      esc_html__(
33
-                                          'Indicate with this attribute what will be used if there are no payments present.  Default is: "%sNo approved payments have been received.%s"',
34
-                                          'event_espresso'
35
-                                      ),
36
-                                      htmlspecialchars('<td class="aln-cntr" colspan="6">'),
37
-                                      htmlspecialchars('</td>')
38
-                                  ) . '</li>' .
39
-                                  '</ul></p>',
40
-        );
41
-    }
21
+	protected function _init_props()
22
+	{
23
+		$this->label = esc_html__('Payment List Shortcodes', 'event_espresso');
24
+		$this->description = esc_html__('All shortcodes specific to payment lists', 'event_espresso');
25
+		$this->_shortcodes = array(
26
+			'[PAYMENT_LIST_*]' => esc_html__(
27
+				'Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults.  Attributes that are available are:',
28
+				'event_espresso'
29
+			)
30
+								  . '<p><ul>' .
31
+								  '<li><strong>no_payments</strong>:' . sprintf(
32
+									  esc_html__(
33
+										  'Indicate with this attribute what will be used if there are no payments present.  Default is: "%sNo approved payments have been received.%s"',
34
+										  'event_espresso'
35
+									  ),
36
+									  htmlspecialchars('<td class="aln-cntr" colspan="6">'),
37
+									  htmlspecialchars('</td>')
38
+								  ) . '</li>' .
39
+								  '</ul></p>',
40
+		);
41
+	}
42 42
 
43 43
 
44
-    protected function _parser($shortcode)
45
-    {
46
-        if (strpos($shortcode, '[PAYMENT_LIST_*') !== false) {
47
-            return $this->_get_payment_list($shortcode);
48
-        }
49
-        return '';
50
-    }
44
+	protected function _parser($shortcode)
45
+	{
46
+		if (strpos($shortcode, '[PAYMENT_LIST_*') !== false) {
47
+			return $this->_get_payment_list($shortcode);
48
+		}
49
+		return '';
50
+	}
51 51
 
52 52
 
53
-    /**
54
-     * verify incoming data contains what is needed for retrieving and parsing each payment for transaction.
55
-     *
56
-     * @since 4.5.0
57
-     *
58
-     * @param string $shortcode The incoming shortcode.
59
-     *
60
-     * @return string parsed ticket line item list.
61
-     */
62
-    private function _get_payment_list($shortcode)
63
-    {
64
-        $this->_validate_list_requirements();
53
+	/**
54
+	 * verify incoming data contains what is needed for retrieving and parsing each payment for transaction.
55
+	 *
56
+	 * @since 4.5.0
57
+	 *
58
+	 * @param string $shortcode The incoming shortcode.
59
+	 *
60
+	 * @return string parsed ticket line item list.
61
+	 */
62
+	private function _get_payment_list($shortcode)
63
+	{
64
+		$this->_validate_list_requirements();
65 65
 
66 66
 
67
-        if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
68
-            return '';
69
-        }
67
+		if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
68
+			return '';
69
+		}
70 70
 
71
-        $valid_shortcodes = array('payment');
71
+		$valid_shortcodes = array('payment');
72 72
 
73
-        $addressee_obj = $this->_data['data'];
74
-        $templates = $this->_extra_data['template'];
75
-        $payments = apply_filters(
76
-            'FHEE__Payment_List_Shortcodes___get_payments_list__payments',
77
-            $addressee_obj->payments
78
-        );
73
+		$addressee_obj = $this->_data['data'];
74
+		$templates = $this->_extra_data['template'];
75
+		$payments = apply_filters(
76
+			'FHEE__Payment_List_Shortcodes___get_payments_list__payments',
77
+			$addressee_obj->payments
78
+		);
79 79
 
80
-        // let's get any attributes that may be present and set the defaults.
81
-        $atts = $this->_get_shortcode_attrs($shortcode);
80
+		// let's get any attributes that may be present and set the defaults.
81
+		$atts = $this->_get_shortcode_attrs($shortcode);
82 82
 
83
-        $no_payments_msg = empty($atts['no_payments']) ? esc_html__(
84
-            'No approved payments have been received.',
85
-            'event_espresso'
86
-        ) : $atts['no_payments'];
83
+		$no_payments_msg = empty($atts['no_payments']) ? esc_html__(
84
+			'No approved payments have been received.',
85
+			'event_espresso'
86
+		) : $atts['no_payments'];
87 87
 
88
-        // made it here so we have an array of paymnets, so we should have what we need.
89
-        $payment_content = empty($payments) ? $no_payments_msg : '';
88
+		// made it here so we have an array of paymnets, so we should have what we need.
89
+		$payment_content = empty($payments) ? $no_payments_msg : '';
90 90
 
91
-        $payments = (array) $payments;
91
+		$payments = (array) $payments;
92 92
 
93
-        foreach ($payments as $payment) {
94
-            $payment_content .= $this->_shortcode_helper->parse_payment_list_template(
95
-                $templates['payment_list'],
96
-                $payment,
97
-                $valid_shortcodes,
98
-                $this->_extra_data
99
-            );
100
-        }
93
+		foreach ($payments as $payment) {
94
+			$payment_content .= $this->_shortcode_helper->parse_payment_list_template(
95
+				$templates['payment_list'],
96
+				$payment,
97
+				$valid_shortcodes,
98
+				$this->_extra_data
99
+			);
100
+		}
101 101
 
102
-        return $payment_content;
103
-    }
102
+		return $payment_content;
103
+	}
104 104
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/model/Base.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
      */
51 51
     public function getModelVersionInfo()
52 52
     {
53
-        if (! $this->model_version_info) {
53
+        if ( ! $this->model_version_info) {
54 54
             throw new EE_Error(
55 55
                 sprintf(
56 56
                     esc_html__(
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      */
96 96
     protected function validateModel($model_name)
97 97
     {
98
-        if (! $this->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
98
+        if ( ! $this->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
99 99
             throw new RestException(
100 100
                 'endpoint_parsing_error',
101 101
                 sprintf(
Please login to merge, or discard this patch.
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -18,95 +18,95 @@
 block discarded – undo
18 18
  */
19 19
 class Base extends Controller_Base
20 20
 {
21
-    /**
22
-     * Holds reference to the model version info, which knows the requested version
23
-     *
24
-     * @var ModelVersionInfo
25
-     */
26
-    protected $model_version_info;
21
+	/**
22
+	 * Holds reference to the model version info, which knows the requested version
23
+	 *
24
+	 * @var ModelVersionInfo
25
+	 */
26
+	protected $model_version_info;
27 27
 
28 28
 
29 29
 
30
-    /**
31
-     * Sets the version the user requested
32
-     *
33
-     * @param string $version eg '4.8'
34
-     */
35
-    public function setRequestedVersion(string $version)
36
-    {
37
-        parent::setRequestedVersion($version);
38
-        $this->model_version_info = new ModelVersionInfo($version);
39
-    }
30
+	/**
31
+	 * Sets the version the user requested
32
+	 *
33
+	 * @param string $version eg '4.8'
34
+	 */
35
+	public function setRequestedVersion(string $version)
36
+	{
37
+		parent::setRequestedVersion($version);
38
+		$this->model_version_info = new ModelVersionInfo($version);
39
+	}
40 40
 
41 41
 
42 42
 
43
-    /**
44
-     * Gets the object that should be used for getting any info from the models,
45
-     * because it's takes the requested and current core version into account
46
-     *
47
-     * @return ModelVersionInfo
48
-     * @throws EE_Error
49
-     */
50
-    public function getModelVersionInfo()
51
-    {
52
-        if (! $this->model_version_info) {
53
-            throw new EE_Error(
54
-                sprintf(
55
-                    esc_html__(
56
-                        'Cannot use model version info before setting the requested version in the controller',
57
-                        'event_espresso'
58
-                    )
59
-                )
60
-            );
61
-        }
62
-        return $this->model_version_info;
63
-    }
43
+	/**
44
+	 * Gets the object that should be used for getting any info from the models,
45
+	 * because it's takes the requested and current core version into account
46
+	 *
47
+	 * @return ModelVersionInfo
48
+	 * @throws EE_Error
49
+	 */
50
+	public function getModelVersionInfo()
51
+	{
52
+		if (! $this->model_version_info) {
53
+			throw new EE_Error(
54
+				sprintf(
55
+					esc_html__(
56
+						'Cannot use model version info before setting the requested version in the controller',
57
+						'event_espresso'
58
+					)
59
+				)
60
+			);
61
+		}
62
+		return $this->model_version_info;
63
+	}
64 64
 
65 65
 
66 66
 
67
-    /**
68
-     * Determines if $object is of one of the classes of $classes. Similar to
69
-     * in_array(), except this checks if $object is a subclass of the classnames provided
70
-     * in $classnames
71
-     *
72
-     * @param object $object
73
-     * @param array  $classnames
74
-     * @return boolean
75
-     */
76
-    public function isSubclassOfOne($object, $classnames)
77
-    {
78
-        foreach ($classnames as $classname) {
79
-            if (is_a($object, $classname)) {
80
-                return true;
81
-            }
82
-        }
83
-        return false;
84
-    }
67
+	/**
68
+	 * Determines if $object is of one of the classes of $classes. Similar to
69
+	 * in_array(), except this checks if $object is a subclass of the classnames provided
70
+	 * in $classnames
71
+	 *
72
+	 * @param object $object
73
+	 * @param array  $classnames
74
+	 * @return boolean
75
+	 */
76
+	public function isSubclassOfOne($object, $classnames)
77
+	{
78
+		foreach ($classnames as $classname) {
79
+			if (is_a($object, $classname)) {
80
+				return true;
81
+			}
82
+		}
83
+		return false;
84
+	}
85 85
 
86
-    /**
87
-     * Verifies the model name provided was valid. If so, returns the model (as an object). Otherwise, throws an
88
-     * exception. Must be called after `setRequestedVersion()`.
89
-     * @since 4.9.76.p
90
-     * @param $model_name
91
-     * @return EEM_Base
92
-     * @throws EE_Error
93
-     * @throws RestException
94
-     */
95
-    protected function validateModel($model_name)
96
-    {
97
-        if (! $this->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
98
-            throw new RestException(
99
-                'endpoint_parsing_error',
100
-                sprintf(
101
-                    esc_html__(
102
-                        'There is no model for endpoint %s. Please contact event espresso support',
103
-                        'event_espresso'
104
-                    ),
105
-                    $model_name
106
-                )
107
-            );
108
-        }
109
-        return $this->getModelVersionInfo()->loadModel($model_name);
110
-    }
86
+	/**
87
+	 * Verifies the model name provided was valid. If so, returns the model (as an object). Otherwise, throws an
88
+	 * exception. Must be called after `setRequestedVersion()`.
89
+	 * @since 4.9.76.p
90
+	 * @param $model_name
91
+	 * @return EEM_Base
92
+	 * @throws EE_Error
93
+	 * @throws RestException
94
+	 */
95
+	protected function validateModel($model_name)
96
+	{
97
+		if (! $this->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
98
+			throw new RestException(
99
+				'endpoint_parsing_error',
100
+				sprintf(
101
+					esc_html__(
102
+						'There is no model for endpoint %s. Please contact event espresso support',
103
+						'event_espresso'
104
+					),
105
+					$model_name
106
+				)
107
+			);
108
+		}
109
+		return $this->getModelVersionInfo()->loadModel($model_name);
110
+	}
111 111
 }
112 112
 // End of file Base.php
Please login to merge, or discard this patch.
core/libraries/rest_api/changes/ChangesInBase.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -37,74 +37,74 @@
 block discarded – undo
37 37
 abstract class ChangesInBase
38 38
 {
39 39
 
40
-    /**
41
-     * The version that these changes happened
42
-     *
43
-     * @var string
44
-     */
45
-    protected $version = null;
40
+	/**
41
+	 * The version that these changes happened
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $version = null;
46 46
 
47 47
 
48
-    /**
49
-     * Called when an EE4 REST API request is made to an earlier version than
50
-     * what is indicated in this class' name.
51
-     * Uses WordPress' add_filter and add_action to modify the EE4 REST API's response
52
-     * so that regardless of what version of EE4 core is running, API clients
53
-     * will have a consistent response
54
-     *
55
-     * @return void
56
-     */
57
-    abstract public function setHooks();
48
+	/**
49
+	 * Called when an EE4 REST API request is made to an earlier version than
50
+	 * what is indicated in this class' name.
51
+	 * Uses WordPress' add_filter and add_action to modify the EE4 REST API's response
52
+	 * so that regardless of what version of EE4 core is running, API clients
53
+	 * will have a consistent response
54
+	 *
55
+	 * @return void
56
+	 */
57
+	abstract public function setHooks();
58 58
 
59 59
 
60
-    /**
61
-     * Returns whether or not this class' name indicates its hooks should
62
-     * apply when a request comes in for $requested_version. A class can use
63
-     * other conditions when determining whether to perform their callbacks or not,
64
-     * but this will typically be enough
65
-     *
66
-     * @param string $requested_version eg "4.8.33"
67
-     * @return boolean true: this class' name indicates its filters and actions
68
-     *                                  should take effect. False: this class' name indicates it shouldn't do anything
69
-     */
70
-    public function appliesToVersion($requested_version)
71
-    {
72
-        if ($this->version() > $requested_version) {
73
-            return true;
74
-        }
75
-        return false;
76
-    }
60
+	/**
61
+	 * Returns whether or not this class' name indicates its hooks should
62
+	 * apply when a request comes in for $requested_version. A class can use
63
+	 * other conditions when determining whether to perform their callbacks or not,
64
+	 * but this will typically be enough
65
+	 *
66
+	 * @param string $requested_version eg "4.8.33"
67
+	 * @return boolean true: this class' name indicates its filters and actions
68
+	 *                                  should take effect. False: this class' name indicates it shouldn't do anything
69
+	 */
70
+	public function appliesToVersion($requested_version)
71
+	{
72
+		if ($this->version() > $requested_version) {
73
+			return true;
74
+		}
75
+		return false;
76
+	}
77 77
 
78 78
 
79
-    /**
80
-     * Gets the EE core version when this changes were made to the rest api.
81
-     * Any requests to earlier versions should have modifications made to them
82
-     * by the callbacks of this class.
83
-     *
84
-     * @return string eg "4.8.33"
85
-     * @throws EE_Error
86
-     */
87
-    public function version()
88
-    {
89
-        if ($this->version === null) {
90
-            $matches = array();
91
-            $regex = '~ChangesIn(\d)(\d\d)(\d\d)$~';
92
-            $success = preg_match(
93
-                $regex,
94
-                get_class($this),
95
-                $matches
96
-            );
97
-            if (! $success) {
98
-                throw new EE_Error(
99
-                    sprintf(
100
-                        esc_html__('The class %1$s was misnamed. It name should match the regex "%2$s"', 'event_espresso'),
101
-                        get_class($this),
102
-                        $regex
103
-                    )
104
-                );
105
-            }
106
-            $this->version = (int) $matches[1] . '.' . (int) $matches[2] . '.' . (int) $matches[3];
107
-        }
108
-        return $this->version;
109
-    }
79
+	/**
80
+	 * Gets the EE core version when this changes were made to the rest api.
81
+	 * Any requests to earlier versions should have modifications made to them
82
+	 * by the callbacks of this class.
83
+	 *
84
+	 * @return string eg "4.8.33"
85
+	 * @throws EE_Error
86
+	 */
87
+	public function version()
88
+	{
89
+		if ($this->version === null) {
90
+			$matches = array();
91
+			$regex = '~ChangesIn(\d)(\d\d)(\d\d)$~';
92
+			$success = preg_match(
93
+				$regex,
94
+				get_class($this),
95
+				$matches
96
+			);
97
+			if (! $success) {
98
+				throw new EE_Error(
99
+					sprintf(
100
+						esc_html__('The class %1$s was misnamed. It name should match the regex "%2$s"', 'event_espresso'),
101
+						get_class($this),
102
+						$regex
103
+					)
104
+				);
105
+			}
106
+			$this->version = (int) $matches[1] . '.' . (int) $matches[2] . '.' . (int) $matches[3];
107
+		}
108
+		return $this->version;
109
+	}
110 110
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
                 get_class($this),
95 95
                 $matches
96 96
             );
97
-            if (! $success) {
97
+            if ( ! $success) {
98 98
                 throw new EE_Error(
99 99
                     sprintf(
100 100
                         esc_html__('The class %1$s was misnamed. It name should match the regex "%2$s"', 'event_espresso'),
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
                     )
104 104
                 );
105 105
             }
106
-            $this->version = (int) $matches[1] . '.' . (int) $matches[2] . '.' . (int) $matches[3];
106
+            $this->version = (int) $matches[1].'.'.(int) $matches[2].'.'.(int) $matches[3];
107 107
         }
108 108
         return $this->version;
109 109
     }
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Datetime.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      */
88 88
     public function registrationsCheckedInCount($wpdb_row, $request, $controller)
89 89
     {
90
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
90
+        if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
91 91
             throw new EE_Error(
92 92
                 sprintf(
93 93
                     esc_html__(
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      */
122 122
     public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
123 123
     {
124
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
124
+        if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
125 125
             throw new EE_Error(
126 126
                 sprintf(
127 127
                     esc_html__(
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      */
157 157
     public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
158 158
     {
159
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
159
+        if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
160 160
             throw new EE_Error(
161 161
                 sprintf(
162 162
                     esc_html__(
Please login to merge, or discard this patch.
Indentation   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -18,214 +18,214 @@
 block discarded – undo
18 18
 
19 19
 class Datetime extends DatetimeCalculationBase
20 20
 {
21
-    /**
22
-     * @var EEM_Datetime
23
-     */
24
-    protected $datetime_model;
21
+	/**
22
+	 * @var EEM_Datetime
23
+	 */
24
+	protected $datetime_model;
25 25
 
26
-    /**
27
-     * @var EEM_Registration
28
-     */
29
-    protected $registration_model;
30
-    public function __construct(EEM_Datetime $datetime_model, EEM_Registration $registration_model)
31
-    {
32
-        $this->datetime_model = $datetime_model;
33
-        $this->registration_model = $registration_model;
34
-    }
26
+	/**
27
+	 * @var EEM_Registration
28
+	 */
29
+	protected $registration_model;
30
+	public function __construct(EEM_Datetime $datetime_model, EEM_Registration $registration_model)
31
+	{
32
+		$this->datetime_model = $datetime_model;
33
+		$this->registration_model = $registration_model;
34
+	}
35 35
 
36
-    /**
37
-     * Calculates the total spaces available on the datetime, taking into account
38
-     * ticket limits too.
39
-     *
40
-     * @see EE_Datetime::spaces_remaining( true )
41
-     * @param array            $wpdb_row
42
-     * @param WP_REST_Request $request
43
-     * @param DatetimeControllerBase  $controller
44
-     * @return int
45
-     * @throws EE_Error
46
-     * @throws InvalidDataTypeException
47
-     * @throws InvalidInterfaceException
48
-     * @throws InvalidArgumentException
49
-     * @throws ReflectionException
50
-     */
51
-    public function spacesRemainingConsideringTickets($wpdb_row, $request, $controller)
52
-    {
53
-        if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) {
54
-            $dtt_obj = $this->datetime_model->get_one_by_ID($wpdb_row['Datetime.DTT_ID']);
55
-        } else {
56
-            $dtt_obj = null;
57
-        }
58
-        if ($dtt_obj instanceof EE_Datetime) {
59
-            return $dtt_obj->spaces_remaining(true);
60
-        }
61
-        throw new EE_Error(
62
-            sprintf(
63
-                esc_html__(
64
-                // @codingStandardsIgnoreStart
65
-                    'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found',
66
-                    // @codingStandardsIgnoreEnd
67
-                    'event_espresso'
68
-                ),
69
-                $wpdb_row['Datetime.DTT_ID'],
70
-                print_r($wpdb_row, true)
71
-            )
72
-        );
73
-    }
36
+	/**
37
+	 * Calculates the total spaces available on the datetime, taking into account
38
+	 * ticket limits too.
39
+	 *
40
+	 * @see EE_Datetime::spaces_remaining( true )
41
+	 * @param array            $wpdb_row
42
+	 * @param WP_REST_Request $request
43
+	 * @param DatetimeControllerBase  $controller
44
+	 * @return int
45
+	 * @throws EE_Error
46
+	 * @throws InvalidDataTypeException
47
+	 * @throws InvalidInterfaceException
48
+	 * @throws InvalidArgumentException
49
+	 * @throws ReflectionException
50
+	 */
51
+	public function spacesRemainingConsideringTickets($wpdb_row, $request, $controller)
52
+	{
53
+		if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) {
54
+			$dtt_obj = $this->datetime_model->get_one_by_ID($wpdb_row['Datetime.DTT_ID']);
55
+		} else {
56
+			$dtt_obj = null;
57
+		}
58
+		if ($dtt_obj instanceof EE_Datetime) {
59
+			return $dtt_obj->spaces_remaining(true);
60
+		}
61
+		throw new EE_Error(
62
+			sprintf(
63
+				esc_html__(
64
+				// @codingStandardsIgnoreStart
65
+					'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found',
66
+					// @codingStandardsIgnoreEnd
67
+					'event_espresso'
68
+				),
69
+				$wpdb_row['Datetime.DTT_ID'],
70
+				print_r($wpdb_row, true)
71
+			)
72
+		);
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * Counts registrations who have checked into this datetime
78
-     *
79
-     * @param array           $wpdb_row
80
-     * @param WP_REST_Request $request
81
-     * @param DatetimeControllerBase $controller
82
-     * @return int
83
-     * @throws EE_Error
84
-     * @throws InvalidArgumentException
85
-     * @throws InvalidDataTypeException
86
-     * @throws InvalidInterfaceException
87
-     * @throws RestException
88
-     */
89
-    public function registrationsCheckedInCount($wpdb_row, $request, $controller)
90
-    {
91
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
92
-            throw new EE_Error(
93
-                sprintf(
94
-                    esc_html__(
95
-                    // @codingStandardsIgnoreStart
96
-                        'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
97
-                        // @codingStandardsIgnoreEnd
98
-                        'event_espresso'
99
-                    ),
100
-                    print_r($wpdb_row, true)
101
-                )
102
-            );
103
-        }
104
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
105
-        return $this->registration_model
106
-                               ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true);
107
-    }
76
+	/**
77
+	 * Counts registrations who have checked into this datetime
78
+	 *
79
+	 * @param array           $wpdb_row
80
+	 * @param WP_REST_Request $request
81
+	 * @param DatetimeControllerBase $controller
82
+	 * @return int
83
+	 * @throws EE_Error
84
+	 * @throws InvalidArgumentException
85
+	 * @throws InvalidDataTypeException
86
+	 * @throws InvalidInterfaceException
87
+	 * @throws RestException
88
+	 */
89
+	public function registrationsCheckedInCount($wpdb_row, $request, $controller)
90
+	{
91
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
92
+			throw new EE_Error(
93
+				sprintf(
94
+					esc_html__(
95
+					// @codingStandardsIgnoreStart
96
+						'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
97
+						// @codingStandardsIgnoreEnd
98
+						'event_espresso'
99
+					),
100
+					print_r($wpdb_row, true)
101
+				)
102
+			);
103
+		}
104
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
105
+		return $this->registration_model
106
+							   ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true);
107
+	}
108 108
 
109 109
 
110
-    /**
111
-     * Counts registrations who have checked out of this datetime
112
-     *
113
-     * @param array           $wpdb_row
114
-     * @param WP_REST_Request $request
115
-     * @param DatetimeControllerBase $controller
116
-     * @return int
117
-     * @throws EE_Error
118
-     * @throws InvalidArgumentException
119
-     * @throws InvalidDataTypeException
120
-     * @throws InvalidInterfaceException
121
-     * @throws RestException
122
-     */
123
-    public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
124
-    {
125
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
126
-            throw new EE_Error(
127
-                sprintf(
128
-                    esc_html__(
129
-                    // @codingStandardsIgnoreStart
130
-                        'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
131
-                        // @codingStandardsIgnoreEnd
132
-                        'event_espresso'
133
-                    ),
134
-                    print_r($wpdb_row, true)
135
-                )
136
-            );
137
-        }
138
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
139
-        return $this->registration_model
140
-                               ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false);
141
-    }
110
+	/**
111
+	 * Counts registrations who have checked out of this datetime
112
+	 *
113
+	 * @param array           $wpdb_row
114
+	 * @param WP_REST_Request $request
115
+	 * @param DatetimeControllerBase $controller
116
+	 * @return int
117
+	 * @throws EE_Error
118
+	 * @throws InvalidArgumentException
119
+	 * @throws InvalidDataTypeException
120
+	 * @throws InvalidInterfaceException
121
+	 * @throws RestException
122
+	 */
123
+	public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
124
+	{
125
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
126
+			throw new EE_Error(
127
+				sprintf(
128
+					esc_html__(
129
+					// @codingStandardsIgnoreStart
130
+						'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
131
+						// @codingStandardsIgnoreEnd
132
+						'event_espresso'
133
+					),
134
+					print_r($wpdb_row, true)
135
+				)
136
+			);
137
+		}
138
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
139
+		return $this->registration_model
140
+							   ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false);
141
+	}
142 142
 
143 143
 
144
-    /**
145
-     * Counts the number of pending-payment registrations for this event (regardless
146
-     * of how many datetimes each registrations' ticket purchase is for)
147
-     *
148
-     * @param array           $wpdb_row
149
-     * @param WP_REST_Request $request
150
-     * @param DatetimeControllerBase $controller
151
-     * @return int
152
-     * @throws EE_Error
153
-     * @throws InvalidArgumentException
154
-     * @throws InvalidDataTypeException
155
-     * @throws InvalidInterfaceException
156
-     * @throws RestException
157
-     */
158
-    public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
159
-    {
160
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
161
-            throw new EE_Error(
162
-                sprintf(
163
-                    esc_html__(
164
-                    // @codingStandardsIgnoreStart
165
-                        'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
166
-                        // @codingStandardsIgnoreEnd
167
-                        'event_espresso'
168
-                    ),
169
-                    print_r($wpdb_row, true)
170
-                )
171
-            );
172
-        }
173
-        $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
174
-        return $this->registration_model->count(
175
-            array(
176
-                array(
177
-                    'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'],
178
-                    'STS_ID'                 => RegStatus::PENDING_PAYMENT,
179
-                ),
180
-            ),
181
-            'REG_ID',
182
-            true
183
-        );
184
-    }
144
+	/**
145
+	 * Counts the number of pending-payment registrations for this event (regardless
146
+	 * of how many datetimes each registrations' ticket purchase is for)
147
+	 *
148
+	 * @param array           $wpdb_row
149
+	 * @param WP_REST_Request $request
150
+	 * @param DatetimeControllerBase $controller
151
+	 * @return int
152
+	 * @throws EE_Error
153
+	 * @throws InvalidArgumentException
154
+	 * @throws InvalidDataTypeException
155
+	 * @throws InvalidInterfaceException
156
+	 * @throws RestException
157
+	 */
158
+	public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
159
+	{
160
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
161
+			throw new EE_Error(
162
+				sprintf(
163
+					esc_html__(
164
+					// @codingStandardsIgnoreStart
165
+						'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
166
+						// @codingStandardsIgnoreEnd
167
+						'event_espresso'
168
+					),
169
+					print_r($wpdb_row, true)
170
+				)
171
+			);
172
+		}
173
+		$this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
174
+		return $this->registration_model->count(
175
+			array(
176
+				array(
177
+					'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'],
178
+					'STS_ID'                 => RegStatus::PENDING_PAYMENT,
179
+				),
180
+			),
181
+			'REG_ID',
182
+			true
183
+		);
184
+	}
185 185
 
186 186
 
187
-    /**
188
-     * Provides an array for all the calculations possible that outlines a json schema for those calculations.
189
-     * Array is indexed by calculation (snake case) and value is the schema for that calculation.
190
-     *
191
-     * @since 4.9.68.p
192
-     * @return array
193
-     */
194
-    public function schemaForCalculations()
195
-    {
196
-        return array(
197
-            'spaces_remaining_considering_tickets' => array(
198
-                'description' => esc_html__(
199
-                    'Calculates the total spaces available on the datetime, taking into account ticket limits too.',
200
-                    'event_espresso'
201
-                ),
202
-                'type' => 'number',
203
-                'protected' => true,
204
-            ),
205
-            'registrations_checked_in_count' => array(
206
-                'description' => esc_html__(
207
-                    'Counts registrations who have checked into this datetime.',
208
-                    'event_espresso'
209
-                ),
210
-                'type' => 'number',
211
-                'protected' => true,
212
-            ),
213
-            'registrations_checked_out_count' => array(
214
-                'description' => esc_html__(
215
-                    'Counts registrations who have checked out of this datetime.',
216
-                    'event_espresso'
217
-                ),
218
-                'type' => 'number',
219
-                'protected' => true,
220
-            ),
221
-            'spots_taken_pending_payment' => array(
222
-                'description' => esc_html__(
223
-                    'The count of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for',
224
-                    'event_espresso'
225
-                ),
226
-                'type' => 'number',
227
-                'protected' => true,
228
-            ),
229
-        );
230
-    }
187
+	/**
188
+	 * Provides an array for all the calculations possible that outlines a json schema for those calculations.
189
+	 * Array is indexed by calculation (snake case) and value is the schema for that calculation.
190
+	 *
191
+	 * @since 4.9.68.p
192
+	 * @return array
193
+	 */
194
+	public function schemaForCalculations()
195
+	{
196
+		return array(
197
+			'spaces_remaining_considering_tickets' => array(
198
+				'description' => esc_html__(
199
+					'Calculates the total spaces available on the datetime, taking into account ticket limits too.',
200
+					'event_espresso'
201
+				),
202
+				'type' => 'number',
203
+				'protected' => true,
204
+			),
205
+			'registrations_checked_in_count' => array(
206
+				'description' => esc_html__(
207
+					'Counts registrations who have checked into this datetime.',
208
+					'event_espresso'
209
+				),
210
+				'type' => 'number',
211
+				'protected' => true,
212
+			),
213
+			'registrations_checked_out_count' => array(
214
+				'description' => esc_html__(
215
+					'Counts registrations who have checked out of this datetime.',
216
+					'event_espresso'
217
+				),
218
+				'type' => 'number',
219
+				'protected' => true,
220
+			),
221
+			'spots_taken_pending_payment' => array(
222
+				'description' => esc_html__(
223
+					'The count of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for',
224
+					'event_espresso'
225
+				),
226
+				'type' => 'number',
227
+				'protected' => true,
228
+			),
229
+		);
230
+	}
231 231
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Event.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
      */
176 176
     public function spotsTaken($wpdb_row, $request, $controller)
177 177
     {
178
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
178
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
179 179
             throw new EE_Error(
180 180
                 sprintf(
181 181
                     esc_html__(
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
      */
218 218
     public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
219 219
     {
220
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
220
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
221 221
             throw new EE_Error(
222 222
                 sprintf(
223 223
                     esc_html__(
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
      */
261 261
     public function registrationsCheckedInCount($wpdb_row, $request, $controller)
262 262
     {
263
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
263
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
264 264
             throw new EE_Error(
265 265
                 sprintf(
266 266
                     esc_html__(
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
      */
295 295
     public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
296 296
     {
297
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
297
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
298 298
             throw new EE_Error(
299 299
                 sprintf(
300 300
                     esc_html__(
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
      */
414 414
     protected function calculateImageData($wpdb_row, $image_size)
415 415
     {
416
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
416
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
417 417
             throw new EE_Error(
418 418
                 sprintf(
419 419
                     esc_html__(
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
         $EVT_ID = $wpdb_row['Event_CPT.ID'];
430 430
         $attachment_id = get_post_thumbnail_id($EVT_ID);
431 431
         $data = wp_get_attachment_image_src($attachment_id, $image_size);
432
-        if (! $data) {
432
+        if ( ! $data) {
433 433
             return null;
434 434
         }
435 435
         $generated = true;
Please login to merge, or discard this patch.
Indentation   +567 added lines, -567 removed lines patch added patch discarded remove patch
@@ -27,571 +27,571 @@
 block discarded – undo
27 27
  */
28 28
 class Event extends EventCalculationBase
29 29
 {
30
-    /**
31
-     * @var EEM_Event
32
-     */
33
-    protected $event_model;
34
-
35
-    /**
36
-     * @var EEM_Registration
37
-     */
38
-    protected $registration_model;
39
-    public function __construct(EEM_Event $event_model, EEM_Registration $registration_model)
40
-    {
41
-        $this->event_model = $event_model;
42
-        $this->registration_model = $registration_model;
43
-    }
44
-
45
-    /**
46
-     * Calculates the total spaces on the event (not subtracting sales, but taking
47
-     * sales into account; so this is the optimum sales that CAN still be achieved)
48
-     * See EE_Event::total_available_spaces( true );
49
-     *
50
-     * @param array               $wpdb_row
51
-     * @param WP_REST_Request     $request
52
-     * @param EventControllerBase $controller
53
-     * @return int
54
-     * @throws EE_Error
55
-     * @throws DomainException
56
-     * @throws InvalidDataTypeException
57
-     * @throws InvalidInterfaceException
58
-     * @throws UnexpectedEntityException
59
-     * @throws InvalidArgumentException
60
-     */
61
-    public function optimumSalesAtStart($wpdb_row, $request, $controller)
62
-    {
63
-        $event_obj = null;
64
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
65
-            $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
66
-        }
67
-        if ($event_obj instanceof EE_Event) {
68
-            return $event_obj->total_available_spaces();
69
-        }
70
-        throw new EE_Error(
71
-            sprintf(
72
-                esc_html__(
73
-                // @codingStandardsIgnoreStart
74
-                    'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found',
75
-                    // @codingStandardsIgnoreEnd
76
-                    'event_espresso'
77
-                ),
78
-                $wpdb_row['Event_CPT.ID'],
79
-                print_r($wpdb_row, true)
80
-            )
81
-        );
82
-    }
83
-
84
-
85
-    /**
86
-     * Calculates the total spaces on the event (ignoring all sales; so this is the optimum
87
-     * sales that COULD have been achieved)
88
-     * See EE_Event::total_available_spaces( true );
89
-     *
90
-     * @param array               $wpdb_row
91
-     * @param WP_REST_Request     $request
92
-     * @param EventControllerBase $controller
93
-     * @return int
94
-     * @throws DomainException
95
-     * @throws EE_Error
96
-     * @throws InvalidArgumentException
97
-     * @throws InvalidDataTypeException
98
-     * @throws InvalidInterfaceException
99
-     * @throws UnexpectedEntityException
100
-     */
101
-    public function optimumSalesNow($wpdb_row, $request, $controller)
102
-    {
103
-        $event_obj = null;
104
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
105
-            $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
106
-        }
107
-        if ($event_obj instanceof EE_Event) {
108
-            return $event_obj->total_available_spaces(true);
109
-        }
110
-        throw new EE_Error(
111
-            sprintf(
112
-                esc_html__(
113
-                // @codingStandardsIgnoreStart
114
-                    'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found',
115
-                    // @codingStandardsIgnoreEnd
116
-                    'event_espresso'
117
-                ),
118
-                $wpdb_row['Event_CPT.ID'],
119
-                print_r($wpdb_row, true)
120
-            )
121
-        );
122
-    }
123
-
124
-
125
-    /**
126
-     * Like optimum_sales_now, but minus total sales so far.
127
-     * See EE_Event::spaces_remaining_for_sale( true );
128
-     *
129
-     * @param array               $wpdb_row
130
-     * @param WP_REST_Request     $request
131
-     * @param EventControllerBase $controller
132
-     * @return int
133
-     * @throws DomainException
134
-     * @throws EE_Error
135
-     * @throws InvalidArgumentException
136
-     * @throws InvalidDataTypeException
137
-     * @throws InvalidInterfaceException
138
-     * @throws UnexpectedEntityException
139
-     */
140
-    public function spacesRemaining($wpdb_row, $request, $controller)
141
-    {
142
-        $event_obj = null;
143
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
144
-            $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
145
-        }
146
-        if ($event_obj instanceof EE_Event) {
147
-            return $event_obj->spaces_remaining_for_sale();
148
-        }
149
-        throw new EE_Error(
150
-            sprintf(
151
-                esc_html__(
152
-                // @codingStandardsIgnoreStart
153
-                    'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found',
154
-                    // @codingStandardsIgnoreEnd
155
-                    'event_espresso'
156
-                ),
157
-                $wpdb_row['Event_CPT.ID'],
158
-                print_r($wpdb_row, true)
159
-            )
160
-        );
161
-    }
162
-
163
-
164
-    /**
165
-     * Counts the number of approved registrations for this event (regardless
166
-     * of how many datetimes each registrations' ticket purchase is for)
167
-     *
168
-     * @param array               $wpdb_row
169
-     * @param WP_REST_Request     $request
170
-     * @param EventControllerBase $controller
171
-     * @return int
172
-     * @throws EE_Error
173
-     * @throws InvalidArgumentException
174
-     * @throws InvalidDataTypeException
175
-     * @throws InvalidInterfaceException
176
-     */
177
-    public function spotsTaken($wpdb_row, $request, $controller)
178
-    {
179
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
180
-            throw new EE_Error(
181
-                sprintf(
182
-                    esc_html__(
183
-                    // @codingStandardsIgnoreStart
184
-                        'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"',
185
-                        // @codingStandardsIgnoreEnd
186
-                        'event_espresso'
187
-                    ),
188
-                    print_r($wpdb_row, true)
189
-                )
190
-            );
191
-        }
192
-        return $this->registration_model->count(
193
-            array(
194
-                array(
195
-                    'EVT_ID' => $wpdb_row['Event_CPT.ID'],
196
-                    'STS_ID' => RegStatus::APPROVED,
197
-                ),
198
-            ),
199
-            'REG_ID',
200
-            true
201
-        );
202
-    }
203
-
204
-
205
-    /**
206
-     * Counts the number of pending-payment registrations for this event (regardless
207
-     * of how many datetimes each registrations' ticket purchase is for)
208
-     *
209
-     * @param array               $wpdb_row
210
-     * @param WP_REST_Request     $request
211
-     * @param EventControllerBase $controller
212
-     * @return int
213
-     * @throws EE_Error
214
-     * @throws InvalidArgumentException
215
-     * @throws InvalidDataTypeException
216
-     * @throws InvalidInterfaceException
217
-     * @throws RestException
218
-     */
219
-    public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
220
-    {
221
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
222
-            throw new EE_Error(
223
-                sprintf(
224
-                    esc_html__(
225
-                    // @codingStandardsIgnoreStart
226
-                        'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"',
227
-                        // @codingStandardsIgnoreEnd
228
-                        'event_espresso'
229
-                    ),
230
-                    print_r($wpdb_row, true)
231
-                )
232
-            );
233
-        }
234
-        $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
235
-        return $this->registration_model->count(
236
-            array(
237
-                array(
238
-                    'EVT_ID' => $wpdb_row['Event_CPT.ID'],
239
-                    'STS_ID' => RegStatus::PENDING_PAYMENT,
240
-                ),
241
-            ),
242
-            'REG_ID',
243
-            true
244
-        );
245
-    }
246
-
247
-
248
-    /**
249
-     * Counts all the registrations who have checked into one of this events' datetimes
250
-     * See EE_Event::total_available_spaces( false );
251
-     *
252
-     * @param array               $wpdb_row
253
-     * @param WP_REST_Request     $request
254
-     * @param EventControllerBase $controller
255
-     * @return int|null if permission denied
256
-     * @throws EE_Error
257
-     * @throws InvalidArgumentException
258
-     * @throws InvalidDataTypeException
259
-     * @throws InvalidInterfaceException
260
-     * @throws RestException
261
-     */
262
-    public function registrationsCheckedInCount($wpdb_row, $request, $controller)
263
-    {
264
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
265
-            throw new EE_Error(
266
-                sprintf(
267
-                    esc_html__(
268
-                    // @codingStandardsIgnoreStart
269
-                        'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
270
-                        // @codingStandardsIgnoreEnd
271
-                        'event_espresso'
272
-                    ),
273
-                    print_r($wpdb_row, true)
274
-                )
275
-            );
276
-        }
277
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
278
-        return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true);
279
-    }
280
-
281
-
282
-    /**
283
-     * Counts all the registrations who have checked out of one of this events' datetimes
284
-     * See EE_Event::total_available_spaces( false );
285
-     *
286
-     * @param array               $wpdb_row
287
-     * @param WP_REST_Request     $request
288
-     * @param EventControllerBase $controller
289
-     * @return int
290
-     * @throws EE_Error
291
-     * @throws InvalidArgumentException
292
-     * @throws InvalidDataTypeException
293
-     * @throws InvalidInterfaceException
294
-     * @throws RestException
295
-     */
296
-    public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
297
-    {
298
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
299
-            throw new EE_Error(
300
-                sprintf(
301
-                    esc_html__(
302
-                    // @codingStandardsIgnoreStart
303
-                        'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
304
-                        // @codingStandardsIgnoreEnd
305
-                        'event_espresso'
306
-                    ),
307
-                    print_r($wpdb_row, true)
308
-                )
309
-            );
310
-        }
311
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
312
-        return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false);
313
-    }
314
-
315
-
316
-    /**
317
-     * Gets the thumbnail image
318
-     *
319
-     * @param array               $wpdb_row
320
-     * @param WP_REST_Request     $request
321
-     * @param EventControllerBase $controller
322
-     * @return array
323
-     * @throws EE_Error
324
-     */
325
-    public function imageThumbnail($wpdb_row, $request, $controller)
326
-    {
327
-        return self::calculateImageData($wpdb_row, 'thumbnail');
328
-    }
329
-
330
-
331
-    /**
332
-     * Gets the medium image
333
-     *
334
-     * @param array               $wpdb_row
335
-     * @param WP_REST_Request     $request
336
-     * @param EventControllerBase $controller
337
-     * @return array
338
-     * @throws EE_Error
339
-     */
340
-    public function imageMedium($wpdb_row, $request, $controller)
341
-    {
342
-        return self::calculateImageData($wpdb_row, 'medium');
343
-    }
344
-
345
-
346
-    /**
347
-     * Gets the medium-large image
348
-     *
349
-     * @param array               $wpdb_row
350
-     * @param WP_REST_Request     $request
351
-     * @param EventControllerBase $controller
352
-     * @return array
353
-     * @throws EE_Error
354
-     */
355
-    public function imageMediumLarge($wpdb_row, $request, $controller)
356
-    {
357
-        return self::calculateImageData($wpdb_row, 'medium_large');
358
-    }
359
-
360
-
361
-    /**
362
-     * Gets the large image
363
-     *
364
-     * @param array               $wpdb_row
365
-     * @param WP_REST_Request     $request
366
-     * @param EventControllerBase $controller
367
-     * @return array
368
-     * @throws EE_Error
369
-     */
370
-    public function imageLarge($wpdb_row, $request, $controller)
371
-    {
372
-        return self::calculateImageData($wpdb_row, 'large');
373
-    }
374
-
375
-
376
-    /**
377
-     * Gets the post-thumbnail image
378
-     *
379
-     * @param array               $wpdb_row
380
-     * @param WP_REST_Request     $request
381
-     * @param EventControllerBase $controller
382
-     * @return array
383
-     * @throws EE_Error
384
-     */
385
-    public function imagePostThumbnail($wpdb_row, $request, $controller)
386
-    {
387
-        return self::calculateImageData($wpdb_row, 'post-thumbnail');
388
-    }
389
-
390
-
391
-    /**
392
-     * Gets the full size image
393
-     *
394
-     * @param array               $wpdb_row
395
-     * @param WP_REST_Request     $request
396
-     * @param EventControllerBase $controller
397
-     * @return array
398
-     * @throws EE_Error
399
-     */
400
-    public function imageFull($wpdb_row, $request, $controller)
401
-    {
402
-        return self::calculateImageData($wpdb_row, 'full');
403
-    }
404
-
405
-
406
-    /**
407
-     * Gets image specs and formats them for the display in the API,
408
-     * according to the image size requested
409
-     *
410
-     * @param array  $wpdb_row
411
-     * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full
412
-     * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original'
413
-     * @throws EE_Error
414
-     */
415
-    protected function calculateImageData($wpdb_row, $image_size)
416
-    {
417
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
418
-            throw new EE_Error(
419
-                sprintf(
420
-                    esc_html__(
421
-                    // @codingStandardsIgnoreStart
422
-                        'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"',
423
-                        // @codingStandardsIgnoreEnd
424
-                        'event_espresso'
425
-                    ),
426
-                    print_r($wpdb_row, true)
427
-                )
428
-            );
429
-        }
430
-        $EVT_ID = $wpdb_row['Event_CPT.ID'];
431
-        $attachment_id = get_post_thumbnail_id($EVT_ID);
432
-        $data = wp_get_attachment_image_src($attachment_id, $image_size);
433
-        if (! $data) {
434
-            return null;
435
-        }
436
-        $generated = true;
437
-        if (isset($data[3])) {
438
-            $generated = $data[3];
439
-        }
440
-        return array(
441
-            'url'       => $data[0],
442
-            'width'     => $data[1],
443
-            'height'    => $data[2],
444
-            'generated' => $generated,
445
-        );
446
-    }
447
-
448
-
449
-    /**
450
-     * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise
451
-     *
452
-     * @param array $wpdb_row
453
-     * @return bool
454
-     */
455
-    protected function wpdbRowHasEventId($wpdb_row)
456
-    {
457
-        return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']));
458
-    }
459
-
460
-
461
-    /**
462
-     * Provides an array for all the calculations possible that outlines a json schema for those calculations.
463
-     * Array is indexed by calculation (snake case) and value is the schema for that calculation.
464
-     *
465
-     * @since 4.9.68.p
466
-     * @return array
467
-     */
468
-    public function schemaForCalculations()
469
-    {
470
-        $image_object_properties = array(
471
-            'url'       => array(
472
-                'type' => 'string',
473
-            ),
474
-            'width'     => array(
475
-                'type' => 'number',
476
-            ),
477
-            'height'    => array(
478
-                'type' => 'number',
479
-            ),
480
-            'generated' => array(
481
-                'type' => 'boolean',
482
-            ),
483
-        );
484
-        return array(
485
-            'optimum_sales_at_start'          => array(
486
-                'description' => esc_html__(
487
-                    'The total spaces on the event (not subtracting sales, but taking sales into account; so this is the optimum sales that CAN still be achieved.',
488
-                    'event_espresso'
489
-                ),
490
-                'type'        => 'number',
491
-                'protected' => true,
492
-            ),
493
-            'optimum_sales_now'               => array(
494
-                'description' => esc_html__(
495
-                    'The total spaces on the event (ignoring all sales; so this is the optimum sales that could have been achieved.',
496
-                    'event_espresso'
497
-                ),
498
-                'type'        => 'number',
499
-                'protected' => true,
500
-            ),
501
-            'spaces_remaining'                => array(
502
-                'description' => esc_html__(
503
-                    'The optimum_sales_number result, minus total sales so far.',
504
-                    'event_espresso'
505
-                ),
506
-                'type'        => 'number',
507
-                'protected' => true,
508
-            ),
509
-            'spots_taken'                     => array(
510
-                'description' => esc_html__(
511
-                    'The number of approved registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
512
-                    'event_espresso'
513
-                ),
514
-                'type'        => 'number',
515
-                'protected' => true,
516
-            ),
517
-            'spots_taken_pending_payment'     => array(
518
-                'description' => esc_html__(
519
-                    'The number of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
520
-                    'event_espresso'
521
-                ),
522
-                'type'        => 'number',
523
-                'protected' => true,
524
-            ),
525
-            'registrations_checked_in_count'  => array(
526
-                'description' => esc_html__(
527
-                    'The count of all the registrations who have checked into one of this event\'s datetimes.',
528
-                    'event_espresso'
529
-                ),
530
-                'type'        => 'number',
531
-                'protected' => true,
532
-            ),
533
-            'registrations_checked_out_count' => array(
534
-                'description' => esc_html__(
535
-                    'The count of all registrations who have checked out of one of this event\'s datetimes.',
536
-                    'event_espresso'
537
-                ),
538
-                'type'        => 'number',
539
-                'protected' => true,
540
-            ),
541
-            'image_thumbnail'                 => array(
542
-                'description'          => esc_html__(
543
-                    'The thumbnail image data.',
544
-                    'event_espresso'
545
-                ),
546
-                'type'                 => 'object',
547
-                'properties'           => $image_object_properties,
548
-                'additionalProperties' => false,
549
-            ),
550
-            'image_medium'                    => array(
551
-                'description'          => esc_html__(
552
-                    'The medium image data.',
553
-                    'event_espresso'
554
-                ),
555
-                'type'                 => 'object',
556
-                'properties'           => $image_object_properties,
557
-                'additionalProperties' => false,
558
-            ),
559
-            'image_medium_large'              => array(
560
-                'description'          => esc_html__(
561
-                    'The medium-large image data.',
562
-                    'event_espresso'
563
-                ),
564
-                'type'                 => 'object',
565
-                'properties'           => $image_object_properties,
566
-                'additionalProperties' => false,
567
-            ),
568
-            'image_large'                     => array(
569
-                'description'          => esc_html__(
570
-                    'The large image data.',
571
-                    'event_espresso'
572
-                ),
573
-                'type'                 => 'object',
574
-                'properties'           => $image_object_properties,
575
-                'additionalProperties' => false,
576
-            ),
577
-            'image_post_thumbnail'            => array(
578
-                'description'          => esc_html__(
579
-                    'The post-thumbnail image data.',
580
-                    'event_espresso'
581
-                ),
582
-                'type'                 => 'object',
583
-                'properties'           => $image_object_properties,
584
-                'additionalProperties' => false,
585
-            ),
586
-            'image_full'                      => array(
587
-                'description'          => esc_html__(
588
-                    'The full size image data',
589
-                    'event_espresso'
590
-                ),
591
-                'type'                 => 'object',
592
-                'properties'           => $image_object_properties,
593
-                'additionalProperties' => false,
594
-            ),
595
-        );
596
-    }
30
+	/**
31
+	 * @var EEM_Event
32
+	 */
33
+	protected $event_model;
34
+
35
+	/**
36
+	 * @var EEM_Registration
37
+	 */
38
+	protected $registration_model;
39
+	public function __construct(EEM_Event $event_model, EEM_Registration $registration_model)
40
+	{
41
+		$this->event_model = $event_model;
42
+		$this->registration_model = $registration_model;
43
+	}
44
+
45
+	/**
46
+	 * Calculates the total spaces on the event (not subtracting sales, but taking
47
+	 * sales into account; so this is the optimum sales that CAN still be achieved)
48
+	 * See EE_Event::total_available_spaces( true );
49
+	 *
50
+	 * @param array               $wpdb_row
51
+	 * @param WP_REST_Request     $request
52
+	 * @param EventControllerBase $controller
53
+	 * @return int
54
+	 * @throws EE_Error
55
+	 * @throws DomainException
56
+	 * @throws InvalidDataTypeException
57
+	 * @throws InvalidInterfaceException
58
+	 * @throws UnexpectedEntityException
59
+	 * @throws InvalidArgumentException
60
+	 */
61
+	public function optimumSalesAtStart($wpdb_row, $request, $controller)
62
+	{
63
+		$event_obj = null;
64
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
65
+			$event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
66
+		}
67
+		if ($event_obj instanceof EE_Event) {
68
+			return $event_obj->total_available_spaces();
69
+		}
70
+		throw new EE_Error(
71
+			sprintf(
72
+				esc_html__(
73
+				// @codingStandardsIgnoreStart
74
+					'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found',
75
+					// @codingStandardsIgnoreEnd
76
+					'event_espresso'
77
+				),
78
+				$wpdb_row['Event_CPT.ID'],
79
+				print_r($wpdb_row, true)
80
+			)
81
+		);
82
+	}
83
+
84
+
85
+	/**
86
+	 * Calculates the total spaces on the event (ignoring all sales; so this is the optimum
87
+	 * sales that COULD have been achieved)
88
+	 * See EE_Event::total_available_spaces( true );
89
+	 *
90
+	 * @param array               $wpdb_row
91
+	 * @param WP_REST_Request     $request
92
+	 * @param EventControllerBase $controller
93
+	 * @return int
94
+	 * @throws DomainException
95
+	 * @throws EE_Error
96
+	 * @throws InvalidArgumentException
97
+	 * @throws InvalidDataTypeException
98
+	 * @throws InvalidInterfaceException
99
+	 * @throws UnexpectedEntityException
100
+	 */
101
+	public function optimumSalesNow($wpdb_row, $request, $controller)
102
+	{
103
+		$event_obj = null;
104
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
105
+			$event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
106
+		}
107
+		if ($event_obj instanceof EE_Event) {
108
+			return $event_obj->total_available_spaces(true);
109
+		}
110
+		throw new EE_Error(
111
+			sprintf(
112
+				esc_html__(
113
+				// @codingStandardsIgnoreStart
114
+					'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found',
115
+					// @codingStandardsIgnoreEnd
116
+					'event_espresso'
117
+				),
118
+				$wpdb_row['Event_CPT.ID'],
119
+				print_r($wpdb_row, true)
120
+			)
121
+		);
122
+	}
123
+
124
+
125
+	/**
126
+	 * Like optimum_sales_now, but minus total sales so far.
127
+	 * See EE_Event::spaces_remaining_for_sale( true );
128
+	 *
129
+	 * @param array               $wpdb_row
130
+	 * @param WP_REST_Request     $request
131
+	 * @param EventControllerBase $controller
132
+	 * @return int
133
+	 * @throws DomainException
134
+	 * @throws EE_Error
135
+	 * @throws InvalidArgumentException
136
+	 * @throws InvalidDataTypeException
137
+	 * @throws InvalidInterfaceException
138
+	 * @throws UnexpectedEntityException
139
+	 */
140
+	public function spacesRemaining($wpdb_row, $request, $controller)
141
+	{
142
+		$event_obj = null;
143
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
144
+			$event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
145
+		}
146
+		if ($event_obj instanceof EE_Event) {
147
+			return $event_obj->spaces_remaining_for_sale();
148
+		}
149
+		throw new EE_Error(
150
+			sprintf(
151
+				esc_html__(
152
+				// @codingStandardsIgnoreStart
153
+					'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found',
154
+					// @codingStandardsIgnoreEnd
155
+					'event_espresso'
156
+				),
157
+				$wpdb_row['Event_CPT.ID'],
158
+				print_r($wpdb_row, true)
159
+			)
160
+		);
161
+	}
162
+
163
+
164
+	/**
165
+	 * Counts the number of approved registrations for this event (regardless
166
+	 * of how many datetimes each registrations' ticket purchase is for)
167
+	 *
168
+	 * @param array               $wpdb_row
169
+	 * @param WP_REST_Request     $request
170
+	 * @param EventControllerBase $controller
171
+	 * @return int
172
+	 * @throws EE_Error
173
+	 * @throws InvalidArgumentException
174
+	 * @throws InvalidDataTypeException
175
+	 * @throws InvalidInterfaceException
176
+	 */
177
+	public function spotsTaken($wpdb_row, $request, $controller)
178
+	{
179
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
180
+			throw new EE_Error(
181
+				sprintf(
182
+					esc_html__(
183
+					// @codingStandardsIgnoreStart
184
+						'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"',
185
+						// @codingStandardsIgnoreEnd
186
+						'event_espresso'
187
+					),
188
+					print_r($wpdb_row, true)
189
+				)
190
+			);
191
+		}
192
+		return $this->registration_model->count(
193
+			array(
194
+				array(
195
+					'EVT_ID' => $wpdb_row['Event_CPT.ID'],
196
+					'STS_ID' => RegStatus::APPROVED,
197
+				),
198
+			),
199
+			'REG_ID',
200
+			true
201
+		);
202
+	}
203
+
204
+
205
+	/**
206
+	 * Counts the number of pending-payment registrations for this event (regardless
207
+	 * of how many datetimes each registrations' ticket purchase is for)
208
+	 *
209
+	 * @param array               $wpdb_row
210
+	 * @param WP_REST_Request     $request
211
+	 * @param EventControllerBase $controller
212
+	 * @return int
213
+	 * @throws EE_Error
214
+	 * @throws InvalidArgumentException
215
+	 * @throws InvalidDataTypeException
216
+	 * @throws InvalidInterfaceException
217
+	 * @throws RestException
218
+	 */
219
+	public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
220
+	{
221
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
222
+			throw new EE_Error(
223
+				sprintf(
224
+					esc_html__(
225
+					// @codingStandardsIgnoreStart
226
+						'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"',
227
+						// @codingStandardsIgnoreEnd
228
+						'event_espresso'
229
+					),
230
+					print_r($wpdb_row, true)
231
+				)
232
+			);
233
+		}
234
+		$this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
235
+		return $this->registration_model->count(
236
+			array(
237
+				array(
238
+					'EVT_ID' => $wpdb_row['Event_CPT.ID'],
239
+					'STS_ID' => RegStatus::PENDING_PAYMENT,
240
+				),
241
+			),
242
+			'REG_ID',
243
+			true
244
+		);
245
+	}
246
+
247
+
248
+	/**
249
+	 * Counts all the registrations who have checked into one of this events' datetimes
250
+	 * See EE_Event::total_available_spaces( false );
251
+	 *
252
+	 * @param array               $wpdb_row
253
+	 * @param WP_REST_Request     $request
254
+	 * @param EventControllerBase $controller
255
+	 * @return int|null if permission denied
256
+	 * @throws EE_Error
257
+	 * @throws InvalidArgumentException
258
+	 * @throws InvalidDataTypeException
259
+	 * @throws InvalidInterfaceException
260
+	 * @throws RestException
261
+	 */
262
+	public function registrationsCheckedInCount($wpdb_row, $request, $controller)
263
+	{
264
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
265
+			throw new EE_Error(
266
+				sprintf(
267
+					esc_html__(
268
+					// @codingStandardsIgnoreStart
269
+						'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
270
+						// @codingStandardsIgnoreEnd
271
+						'event_espresso'
272
+					),
273
+					print_r($wpdb_row, true)
274
+				)
275
+			);
276
+		}
277
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
278
+		return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true);
279
+	}
280
+
281
+
282
+	/**
283
+	 * Counts all the registrations who have checked out of one of this events' datetimes
284
+	 * See EE_Event::total_available_spaces( false );
285
+	 *
286
+	 * @param array               $wpdb_row
287
+	 * @param WP_REST_Request     $request
288
+	 * @param EventControllerBase $controller
289
+	 * @return int
290
+	 * @throws EE_Error
291
+	 * @throws InvalidArgumentException
292
+	 * @throws InvalidDataTypeException
293
+	 * @throws InvalidInterfaceException
294
+	 * @throws RestException
295
+	 */
296
+	public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
297
+	{
298
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
299
+			throw new EE_Error(
300
+				sprintf(
301
+					esc_html__(
302
+					// @codingStandardsIgnoreStart
303
+						'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
304
+						// @codingStandardsIgnoreEnd
305
+						'event_espresso'
306
+					),
307
+					print_r($wpdb_row, true)
308
+				)
309
+			);
310
+		}
311
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
312
+		return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false);
313
+	}
314
+
315
+
316
+	/**
317
+	 * Gets the thumbnail image
318
+	 *
319
+	 * @param array               $wpdb_row
320
+	 * @param WP_REST_Request     $request
321
+	 * @param EventControllerBase $controller
322
+	 * @return array
323
+	 * @throws EE_Error
324
+	 */
325
+	public function imageThumbnail($wpdb_row, $request, $controller)
326
+	{
327
+		return self::calculateImageData($wpdb_row, 'thumbnail');
328
+	}
329
+
330
+
331
+	/**
332
+	 * Gets the medium image
333
+	 *
334
+	 * @param array               $wpdb_row
335
+	 * @param WP_REST_Request     $request
336
+	 * @param EventControllerBase $controller
337
+	 * @return array
338
+	 * @throws EE_Error
339
+	 */
340
+	public function imageMedium($wpdb_row, $request, $controller)
341
+	{
342
+		return self::calculateImageData($wpdb_row, 'medium');
343
+	}
344
+
345
+
346
+	/**
347
+	 * Gets the medium-large image
348
+	 *
349
+	 * @param array               $wpdb_row
350
+	 * @param WP_REST_Request     $request
351
+	 * @param EventControllerBase $controller
352
+	 * @return array
353
+	 * @throws EE_Error
354
+	 */
355
+	public function imageMediumLarge($wpdb_row, $request, $controller)
356
+	{
357
+		return self::calculateImageData($wpdb_row, 'medium_large');
358
+	}
359
+
360
+
361
+	/**
362
+	 * Gets the large image
363
+	 *
364
+	 * @param array               $wpdb_row
365
+	 * @param WP_REST_Request     $request
366
+	 * @param EventControllerBase $controller
367
+	 * @return array
368
+	 * @throws EE_Error
369
+	 */
370
+	public function imageLarge($wpdb_row, $request, $controller)
371
+	{
372
+		return self::calculateImageData($wpdb_row, 'large');
373
+	}
374
+
375
+
376
+	/**
377
+	 * Gets the post-thumbnail image
378
+	 *
379
+	 * @param array               $wpdb_row
380
+	 * @param WP_REST_Request     $request
381
+	 * @param EventControllerBase $controller
382
+	 * @return array
383
+	 * @throws EE_Error
384
+	 */
385
+	public function imagePostThumbnail($wpdb_row, $request, $controller)
386
+	{
387
+		return self::calculateImageData($wpdb_row, 'post-thumbnail');
388
+	}
389
+
390
+
391
+	/**
392
+	 * Gets the full size image
393
+	 *
394
+	 * @param array               $wpdb_row
395
+	 * @param WP_REST_Request     $request
396
+	 * @param EventControllerBase $controller
397
+	 * @return array
398
+	 * @throws EE_Error
399
+	 */
400
+	public function imageFull($wpdb_row, $request, $controller)
401
+	{
402
+		return self::calculateImageData($wpdb_row, 'full');
403
+	}
404
+
405
+
406
+	/**
407
+	 * Gets image specs and formats them for the display in the API,
408
+	 * according to the image size requested
409
+	 *
410
+	 * @param array  $wpdb_row
411
+	 * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full
412
+	 * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original'
413
+	 * @throws EE_Error
414
+	 */
415
+	protected function calculateImageData($wpdb_row, $image_size)
416
+	{
417
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
418
+			throw new EE_Error(
419
+				sprintf(
420
+					esc_html__(
421
+					// @codingStandardsIgnoreStart
422
+						'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"',
423
+						// @codingStandardsIgnoreEnd
424
+						'event_espresso'
425
+					),
426
+					print_r($wpdb_row, true)
427
+				)
428
+			);
429
+		}
430
+		$EVT_ID = $wpdb_row['Event_CPT.ID'];
431
+		$attachment_id = get_post_thumbnail_id($EVT_ID);
432
+		$data = wp_get_attachment_image_src($attachment_id, $image_size);
433
+		if (! $data) {
434
+			return null;
435
+		}
436
+		$generated = true;
437
+		if (isset($data[3])) {
438
+			$generated = $data[3];
439
+		}
440
+		return array(
441
+			'url'       => $data[0],
442
+			'width'     => $data[1],
443
+			'height'    => $data[2],
444
+			'generated' => $generated,
445
+		);
446
+	}
447
+
448
+
449
+	/**
450
+	 * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise
451
+	 *
452
+	 * @param array $wpdb_row
453
+	 * @return bool
454
+	 */
455
+	protected function wpdbRowHasEventId($wpdb_row)
456
+	{
457
+		return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']));
458
+	}
459
+
460
+
461
+	/**
462
+	 * Provides an array for all the calculations possible that outlines a json schema for those calculations.
463
+	 * Array is indexed by calculation (snake case) and value is the schema for that calculation.
464
+	 *
465
+	 * @since 4.9.68.p
466
+	 * @return array
467
+	 */
468
+	public function schemaForCalculations()
469
+	{
470
+		$image_object_properties = array(
471
+			'url'       => array(
472
+				'type' => 'string',
473
+			),
474
+			'width'     => array(
475
+				'type' => 'number',
476
+			),
477
+			'height'    => array(
478
+				'type' => 'number',
479
+			),
480
+			'generated' => array(
481
+				'type' => 'boolean',
482
+			),
483
+		);
484
+		return array(
485
+			'optimum_sales_at_start'          => array(
486
+				'description' => esc_html__(
487
+					'The total spaces on the event (not subtracting sales, but taking sales into account; so this is the optimum sales that CAN still be achieved.',
488
+					'event_espresso'
489
+				),
490
+				'type'        => 'number',
491
+				'protected' => true,
492
+			),
493
+			'optimum_sales_now'               => array(
494
+				'description' => esc_html__(
495
+					'The total spaces on the event (ignoring all sales; so this is the optimum sales that could have been achieved.',
496
+					'event_espresso'
497
+				),
498
+				'type'        => 'number',
499
+				'protected' => true,
500
+			),
501
+			'spaces_remaining'                => array(
502
+				'description' => esc_html__(
503
+					'The optimum_sales_number result, minus total sales so far.',
504
+					'event_espresso'
505
+				),
506
+				'type'        => 'number',
507
+				'protected' => true,
508
+			),
509
+			'spots_taken'                     => array(
510
+				'description' => esc_html__(
511
+					'The number of approved registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
512
+					'event_espresso'
513
+				),
514
+				'type'        => 'number',
515
+				'protected' => true,
516
+			),
517
+			'spots_taken_pending_payment'     => array(
518
+				'description' => esc_html__(
519
+					'The number of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
520
+					'event_espresso'
521
+				),
522
+				'type'        => 'number',
523
+				'protected' => true,
524
+			),
525
+			'registrations_checked_in_count'  => array(
526
+				'description' => esc_html__(
527
+					'The count of all the registrations who have checked into one of this event\'s datetimes.',
528
+					'event_espresso'
529
+				),
530
+				'type'        => 'number',
531
+				'protected' => true,
532
+			),
533
+			'registrations_checked_out_count' => array(
534
+				'description' => esc_html__(
535
+					'The count of all registrations who have checked out of one of this event\'s datetimes.',
536
+					'event_espresso'
537
+				),
538
+				'type'        => 'number',
539
+				'protected' => true,
540
+			),
541
+			'image_thumbnail'                 => array(
542
+				'description'          => esc_html__(
543
+					'The thumbnail image data.',
544
+					'event_espresso'
545
+				),
546
+				'type'                 => 'object',
547
+				'properties'           => $image_object_properties,
548
+				'additionalProperties' => false,
549
+			),
550
+			'image_medium'                    => array(
551
+				'description'          => esc_html__(
552
+					'The medium image data.',
553
+					'event_espresso'
554
+				),
555
+				'type'                 => 'object',
556
+				'properties'           => $image_object_properties,
557
+				'additionalProperties' => false,
558
+			),
559
+			'image_medium_large'              => array(
560
+				'description'          => esc_html__(
561
+					'The medium-large image data.',
562
+					'event_espresso'
563
+				),
564
+				'type'                 => 'object',
565
+				'properties'           => $image_object_properties,
566
+				'additionalProperties' => false,
567
+			),
568
+			'image_large'                     => array(
569
+				'description'          => esc_html__(
570
+					'The large image data.',
571
+					'event_espresso'
572
+				),
573
+				'type'                 => 'object',
574
+				'properties'           => $image_object_properties,
575
+				'additionalProperties' => false,
576
+			),
577
+			'image_post_thumbnail'            => array(
578
+				'description'          => esc_html__(
579
+					'The post-thumbnail image data.',
580
+					'event_espresso'
581
+				),
582
+				'type'                 => 'object',
583
+				'properties'           => $image_object_properties,
584
+				'additionalProperties' => false,
585
+			),
586
+			'image_full'                      => array(
587
+				'description'          => esc_html__(
588
+					'The full size image data',
589
+					'event_espresso'
590
+				),
591
+				'type'                 => 'object',
592
+				'properties'           => $image_object_properties,
593
+				'additionalProperties' => false,
594
+			),
595
+		);
596
+	}
597 597
 }
Please login to merge, or discard this patch.