Completed
Branch master (87a62b)
by
unknown
18:29 queued 13:45
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($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($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/controllers/model/Write.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
     {
135 135
         Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'create');
136 136
         $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap();
137
-        if (! current_user_can($default_cap_to_check_for)) {
137
+        if ( ! current_user_can($default_cap_to_check_for)) {
138 138
             throw new RestException(
139
-                'rest_cannot_create_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
139
+                'rest_cannot_create_'.EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
140 140
                 sprintf(
141 141
                     esc_html__(
142 142
                     // @codingStandardsIgnoreStart
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         );
165 165
         $model_obj->save();
166 166
         $new_id = $model_obj->ID();
167
-        if (! $new_id) {
167
+        if ( ! $new_id) {
168 168
             throw new RestException(
169 169
                 'rest_insertion_failed',
170 170
                 sprintf(esc_html__('Could not insert new %1$s', 'event_espresso'), $model->get_this_model_name())
@@ -186,9 +186,9 @@  discard block
 block discarded – undo
186 186
     {
187 187
         Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit');
188 188
         $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap();
189
-        if (! current_user_can($default_cap_to_check_for)) {
189
+        if ( ! current_user_can($default_cap_to_check_for)) {
190 190
             throw new RestException(
191
-                'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
191
+                'rest_cannot_edit_'.EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
192 192
                 sprintf(
193 193
                     esc_html__(
194 194
                     // @codingStandardsIgnoreStart
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
             );
203 203
         }
204 204
         $obj_id = $request->get_param('id');
205
-        if (! $obj_id) {
205
+        if ( ! $obj_id) {
206 206
             throw new RestException(
207 207
                 'rest_edit_failed',
208 208
                 sprintf(esc_html__('Could not edit %1$s', 'event_espresso'), $model->get_this_model_name())
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
             true
216 216
         );
217 217
         $model_obj = $model->get_one_by_ID($obj_id);
218
-        if (! $model_obj instanceof EE_Base_Class) {
218
+        if ( ! $model_obj instanceof EE_Base_Class) {
219 219
             $lowercase_model_name = strtolower($model->get_this_model_name());
220 220
             throw new RestException(
221 221
                 sprintf('rest_%s_invalid_id', $lowercase_model_name),
@@ -240,9 +240,9 @@  discard block
 block discarded – undo
240 240
     {
241 241
         Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_delete, 'delete');
242 242
         $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap();
243
-        if (! current_user_can($default_cap_to_check_for)) {
243
+        if ( ! current_user_can($default_cap_to_check_for)) {
244 244
             throw new RestException(
245
-                'rest_cannot_delete_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
245
+                'rest_cannot_delete_'.EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
246 246
                 sprintf(
247 247
                     esc_html__(
248 248
                     // @codingStandardsIgnoreStart
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
         $obj_id = $request->get_param('id');
259 259
         // this is where we would apply more fine-grained caps
260 260
         $model_obj = $model->get_one_by_ID($obj_id);
261
-        if (! $model_obj instanceof EE_Base_Class) {
261
+        if ( ! $model_obj instanceof EE_Base_Class) {
262 262
             $lowercase_model_name = strtolower($model->get_this_model_name());
263 263
             throw new RestException(
264 264
                 sprintf('rest_%s_invalid_id', $lowercase_model_name),
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
             } else {
317 317
                 $raw_value = $model_obj->get_raw($field_name);
318 318
             }
319
-            $simulated_db_row[ $field_obj->get_qualified_column() ] = $field_obj->prepare_for_use_in_db($raw_value);
319
+            $simulated_db_row[$field_obj->get_qualified_column()] = $field_obj->prepare_for_use_in_db($raw_value);
320 320
         }
321 321
         $read_controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read');
322 322
         $read_controller->setRequestedVersion($this->getRequestedVersion());
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
                     )
448 448
                 )
449 449
             );
450
-            $response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = $this->returnModelObjAsJsonResponse($join_model_obj, $request);
450
+            $response['join'][strtolower($relation->get_join_model()->get_this_model_name())] = $this->returnModelObjAsJsonResponse($join_model_obj, $request);
451 451
         }
452 452
         return $response;
453 453
     }
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
     {
496 496
         // This endpoint doesn't accept body parameters (it's understandable to think it might, so let developers know
497 497
         // up-front that it doesn't.)
498
-        if (!empty($request->get_body_params())) {
498
+        if ( ! empty($request->get_body_params())) {
499 499
             $body_params = $request->get_body_params();
500 500
             throw new RestException(
501 501
                 'invalid_field',
@@ -537,9 +537,9 @@  discard block
 block discarded – undo
537 537
                 )
538 538
             );
539 539
             if ($join_model_obj instanceof EE_Base_Class) {
540
-                $response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = $this->returnModelObjAsJsonResponse($join_model_obj, $request);
540
+                $response['join'][strtolower($relation->get_join_model()->get_this_model_name())] = $this->returnModelObjAsJsonResponse($join_model_obj, $request);
541 541
             } else {
542
-                $response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = null;
542
+                $response['join'][strtolower($relation->get_join_model()->get_this_model_name())] = null;
543 543
             }
544 544
         }
545 545
         return $response;
@@ -564,9 +564,9 @@  discard block
 block discarded – undo
564 564
         // Check generic caps. For now, we're only allowing access to this endpoint to full admins.
565 565
         Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit');
566 566
         $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap();
567
-        if (! current_user_can($default_cap_to_check_for)) {
567
+        if ( ! current_user_can($default_cap_to_check_for)) {
568 568
             throw new RestException(
569
-                'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
569
+                'rest_cannot_edit_'.EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
570 570
                 sprintf(
571 571
                     esc_html__(
572 572
                         // @codingStandardsIgnoreStart
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
         $model_obj = $this->getOneOrThrowException($model, $request->get_param('id'));
584 584
         // For now, we require the other model object to exist too. This might be relaxed later.
585 585
         $other_obj = $this->getOneOrThrowException($relation->get_other_model(), $request->get_param('related_id'));
586
-        return array($model_obj,$other_obj);
586
+        return array($model_obj, $other_obj);
587 587
     }
588 588
 
589 589
     /**
Please login to merge, or discard this patch.
Indentation   +546 added lines, -546 removed lines patch added patch discarded remove patch
@@ -37,573 +37,573 @@
 block discarded – undo
37 37
  */
38 38
 class Write extends Base
39 39
 {
40
-    public function __construct()
41
-    {
42
-        parent::__construct();
43
-        EE_Registry::instance()->load_helper('Inflector');
44
-    }
40
+	public function __construct()
41
+	{
42
+		parent::__construct();
43
+		EE_Registry::instance()->load_helper('Inflector');
44
+	}
45 45
 
46 46
 
47
-    /**
48
-     * Handles requests to get all (or a filtered subset) of entities for a particular model
49
-     *
50
-     * @param WP_REST_Request $request
51
-     * @param string          $version
52
-     * @param string          $model_name
53
-     * @return WP_REST_Response|\WP_Error
54
-     */
55
-    public static function handleRequestInsert(WP_REST_Request $request, $version, $model_name)
56
-    {
57
-        $controller = new Write();
58
-        try {
59
-            $controller->setRequestedVersion($version);
60
-            return $controller->sendResponse(
61
-                $controller->insert(
62
-                    $controller->getModelVersionInfo()->loadModel($model_name),
63
-                    $request
64
-                )
65
-            );
66
-        } catch (Exception $e) {
67
-            return $controller->sendResponse($e);
68
-        }
69
-    }
47
+	/**
48
+	 * Handles requests to get all (or a filtered subset) of entities for a particular model
49
+	 *
50
+	 * @param WP_REST_Request $request
51
+	 * @param string          $version
52
+	 * @param string          $model_name
53
+	 * @return WP_REST_Response|\WP_Error
54
+	 */
55
+	public static function handleRequestInsert(WP_REST_Request $request, $version, $model_name)
56
+	{
57
+		$controller = new Write();
58
+		try {
59
+			$controller->setRequestedVersion($version);
60
+			return $controller->sendResponse(
61
+				$controller->insert(
62
+					$controller->getModelVersionInfo()->loadModel($model_name),
63
+					$request
64
+				)
65
+			);
66
+		} catch (Exception $e) {
67
+			return $controller->sendResponse($e);
68
+		}
69
+	}
70 70
 
71 71
 
72
-    /**
73
-     * Handles a request from \WP_REST_Server to update an EE model
74
-     *
75
-     * @param WP_REST_Request $request
76
-     * @param string          $version
77
-     * @param string          $model_name
78
-     * @return WP_REST_Response|\WP_Error
79
-     */
80
-    public static function handleRequestUpdate(WP_REST_Request $request, $version, $model_name)
81
-    {
82
-        $controller = new Write();
83
-        try {
84
-            $controller->setRequestedVersion($version);
85
-            return $controller->sendResponse(
86
-                $controller->update(
87
-                    $controller->getModelVersionInfo()->loadModel($model_name),
88
-                    $request
89
-                )
90
-            );
91
-        } catch (Exception $e) {
92
-            return $controller->sendResponse($e);
93
-        }
94
-    }
72
+	/**
73
+	 * Handles a request from \WP_REST_Server to update an EE model
74
+	 *
75
+	 * @param WP_REST_Request $request
76
+	 * @param string          $version
77
+	 * @param string          $model_name
78
+	 * @return WP_REST_Response|\WP_Error
79
+	 */
80
+	public static function handleRequestUpdate(WP_REST_Request $request, $version, $model_name)
81
+	{
82
+		$controller = new Write();
83
+		try {
84
+			$controller->setRequestedVersion($version);
85
+			return $controller->sendResponse(
86
+				$controller->update(
87
+					$controller->getModelVersionInfo()->loadModel($model_name),
88
+					$request
89
+				)
90
+			);
91
+		} catch (Exception $e) {
92
+			return $controller->sendResponse($e);
93
+		}
94
+	}
95 95
 
96 96
 
97
-    /**
98
-     * Deletes a single model object and returns it. Unless
99
-     *
100
-     * @param WP_REST_Request $request
101
-     * @param string          $version
102
-     * @param string          $model_name
103
-     * @return WP_REST_Response|\WP_Error
104
-     */
105
-    public static function handleRequestDelete(WP_REST_Request $request, $version, $model_name)
106
-    {
107
-        $controller = new Write();
108
-        try {
109
-            $controller->setRequestedVersion($version);
110
-            return $controller->sendResponse(
111
-                $controller->delete(
112
-                    $controller->getModelVersionInfo()->loadModel($model_name),
113
-                    $request
114
-                )
115
-            );
116
-        } catch (Exception $e) {
117
-            return $controller->sendResponse($e);
118
-        }
119
-    }
97
+	/**
98
+	 * Deletes a single model object and returns it. Unless
99
+	 *
100
+	 * @param WP_REST_Request $request
101
+	 * @param string          $version
102
+	 * @param string          $model_name
103
+	 * @return WP_REST_Response|\WP_Error
104
+	 */
105
+	public static function handleRequestDelete(WP_REST_Request $request, $version, $model_name)
106
+	{
107
+		$controller = new Write();
108
+		try {
109
+			$controller->setRequestedVersion($version);
110
+			return $controller->sendResponse(
111
+				$controller->delete(
112
+					$controller->getModelVersionInfo()->loadModel($model_name),
113
+					$request
114
+				)
115
+			);
116
+		} catch (Exception $e) {
117
+			return $controller->sendResponse($e);
118
+		}
119
+	}
120 120
 
121 121
 
122
-    /**
123
-     * Inserts a new model object according to the $request
124
-     *
125
-     * @param EEM_Base        $model
126
-     * @param WP_REST_Request $request
127
-     * @return array
128
-     * @throws EE_Error
129
-     * @throws RestException
130
-     */
131
-    public function insert(EEM_Base $model, WP_REST_Request $request)
132
-    {
133
-        Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'create');
134
-        $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap();
135
-        if (! current_user_can($default_cap_to_check_for)) {
136
-            throw new RestException(
137
-                'rest_cannot_create_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
138
-                sprintf(
139
-                    esc_html__(
140
-                    // @codingStandardsIgnoreStart
141
-                        'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to insert data into Event Espresso.',
142
-                        // @codingStandardsIgnoreEnd
143
-                        'event_espresso'
144
-                    ),
145
-                    $default_cap_to_check_for
146
-                ),
147
-                array('status' => 403)
148
-            );
149
-        }
150
-        $submitted_json_data = array_merge((array) $request->get_body_params(), (array) $request->get_json_params());
151
-        $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels(
152
-            $submitted_json_data,
153
-            $model,
154
-            $this->getModelVersionInfo()->requestedVersion(),
155
-            true
156
-        );
157
-        $model_obj = EE_Registry::instance()->load_class(
158
-            $model->get_this_model_name(),
159
-            array($model_data, $model->get_timezone()),
160
-            false,
161
-            false
162
-        );
163
-        $model_obj->save();
164
-        $new_id = $model_obj->ID();
165
-        if (! $new_id) {
166
-            throw new RestException(
167
-                'rest_insertion_failed',
168
-                sprintf(esc_html__('Could not insert new %1$s', 'event_espresso'), $model->get_this_model_name())
169
-            );
170
-        }
171
-        return $this->returnModelObjAsJsonResponse($model_obj, $request);
172
-    }
122
+	/**
123
+	 * Inserts a new model object according to the $request
124
+	 *
125
+	 * @param EEM_Base        $model
126
+	 * @param WP_REST_Request $request
127
+	 * @return array
128
+	 * @throws EE_Error
129
+	 * @throws RestException
130
+	 */
131
+	public function insert(EEM_Base $model, WP_REST_Request $request)
132
+	{
133
+		Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'create');
134
+		$default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap();
135
+		if (! current_user_can($default_cap_to_check_for)) {
136
+			throw new RestException(
137
+				'rest_cannot_create_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
138
+				sprintf(
139
+					esc_html__(
140
+					// @codingStandardsIgnoreStart
141
+						'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to insert data into Event Espresso.',
142
+						// @codingStandardsIgnoreEnd
143
+						'event_espresso'
144
+					),
145
+					$default_cap_to_check_for
146
+				),
147
+				array('status' => 403)
148
+			);
149
+		}
150
+		$submitted_json_data = array_merge((array) $request->get_body_params(), (array) $request->get_json_params());
151
+		$model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels(
152
+			$submitted_json_data,
153
+			$model,
154
+			$this->getModelVersionInfo()->requestedVersion(),
155
+			true
156
+		);
157
+		$model_obj = EE_Registry::instance()->load_class(
158
+			$model->get_this_model_name(),
159
+			array($model_data, $model->get_timezone()),
160
+			false,
161
+			false
162
+		);
163
+		$model_obj->save();
164
+		$new_id = $model_obj->ID();
165
+		if (! $new_id) {
166
+			throw new RestException(
167
+				'rest_insertion_failed',
168
+				sprintf(esc_html__('Could not insert new %1$s', 'event_espresso'), $model->get_this_model_name())
169
+			);
170
+		}
171
+		return $this->returnModelObjAsJsonResponse($model_obj, $request);
172
+	}
173 173
 
174 174
 
175
-    /**
176
-     * Updates an existing model object according to the $request
177
-     *
178
-     * @param EEM_Base        $model
179
-     * @param WP_REST_Request $request
180
-     * @return array
181
-     * @throws EE_Error
182
-     */
183
-    public function update(EEM_Base $model, WP_REST_Request $request)
184
-    {
185
-        Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit');
186
-        $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap();
187
-        if (! current_user_can($default_cap_to_check_for)) {
188
-            throw new RestException(
189
-                'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
190
-                sprintf(
191
-                    esc_html__(
192
-                    // @codingStandardsIgnoreStart
193
-                        'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to update data into Event Espresso.',
194
-                        // @codingStandardsIgnoreEnd
195
-                        'event_espresso'
196
-                    ),
197
-                    $default_cap_to_check_for
198
-                ),
199
-                array('status' => 403)
200
-            );
201
-        }
202
-        $obj_id = $request->get_param('id');
203
-        if (! $obj_id) {
204
-            throw new RestException(
205
-                'rest_edit_failed',
206
-                sprintf(esc_html__('Could not edit %1$s', 'event_espresso'), $model->get_this_model_name())
207
-            );
208
-        }
209
-        $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels(
210
-            $this->getBodyParams($request),
211
-            $model,
212
-            $this->getModelVersionInfo()->requestedVersion(),
213
-            true
214
-        );
215
-        $model_obj = $model->get_one_by_ID($obj_id);
216
-        if (! $model_obj instanceof EE_Base_Class) {
217
-            $lowercase_model_name = strtolower($model->get_this_model_name());
218
-            throw new RestException(
219
-                sprintf('rest_%s_invalid_id', $lowercase_model_name),
220
-                sprintf(esc_html__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name),
221
-                array('status' => 404)
222
-            );
223
-        }
224
-        $model_obj->save($model_data);
225
-        return $this->returnModelObjAsJsonResponse($model_obj, $request);
226
-    }
175
+	/**
176
+	 * Updates an existing model object according to the $request
177
+	 *
178
+	 * @param EEM_Base        $model
179
+	 * @param WP_REST_Request $request
180
+	 * @return array
181
+	 * @throws EE_Error
182
+	 */
183
+	public function update(EEM_Base $model, WP_REST_Request $request)
184
+	{
185
+		Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit');
186
+		$default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap();
187
+		if (! current_user_can($default_cap_to_check_for)) {
188
+			throw new RestException(
189
+				'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
190
+				sprintf(
191
+					esc_html__(
192
+					// @codingStandardsIgnoreStart
193
+						'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to update data into Event Espresso.',
194
+						// @codingStandardsIgnoreEnd
195
+						'event_espresso'
196
+					),
197
+					$default_cap_to_check_for
198
+				),
199
+				array('status' => 403)
200
+			);
201
+		}
202
+		$obj_id = $request->get_param('id');
203
+		if (! $obj_id) {
204
+			throw new RestException(
205
+				'rest_edit_failed',
206
+				sprintf(esc_html__('Could not edit %1$s', 'event_espresso'), $model->get_this_model_name())
207
+			);
208
+		}
209
+		$model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels(
210
+			$this->getBodyParams($request),
211
+			$model,
212
+			$this->getModelVersionInfo()->requestedVersion(),
213
+			true
214
+		);
215
+		$model_obj = $model->get_one_by_ID($obj_id);
216
+		if (! $model_obj instanceof EE_Base_Class) {
217
+			$lowercase_model_name = strtolower($model->get_this_model_name());
218
+			throw new RestException(
219
+				sprintf('rest_%s_invalid_id', $lowercase_model_name),
220
+				sprintf(esc_html__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name),
221
+				array('status' => 404)
222
+			);
223
+		}
224
+		$model_obj->save($model_data);
225
+		return $this->returnModelObjAsJsonResponse($model_obj, $request);
226
+	}
227 227
 
228 228
 
229
-    /**
230
-     * Updates an existing model object according to the $request
231
-     *
232
-     * @param EEM_Base        $model
233
-     * @param WP_REST_Request $request
234
-     * @return array of either the soft-deleted item, or
235
-     * @throws EE_Error
236
-     */
237
-    public function delete(EEM_Base $model, WP_REST_Request $request)
238
-    {
239
-        Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_delete, 'delete');
240
-        $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap();
241
-        if (! current_user_can($default_cap_to_check_for)) {
242
-            throw new RestException(
243
-                'rest_cannot_delete_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
244
-                sprintf(
245
-                    esc_html__(
246
-                    // @codingStandardsIgnoreStart
247
-                        'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to delete data into Event Espresso.',
248
-                        // @codingStandardsIgnoreEnd
249
-                        'event_espresso'
250
-                    ),
251
-                    $default_cap_to_check_for
252
-                ),
253
-                array('status' => 403)
254
-            );
255
-        }
256
-        $obj_id = $request->get_param('id');
257
-        // this is where we would apply more fine-grained caps
258
-        $model_obj = $model->get_one_by_ID($obj_id);
259
-        if (! $model_obj instanceof EE_Base_Class) {
260
-            $lowercase_model_name = strtolower($model->get_this_model_name());
261
-            throw new RestException(
262
-                sprintf('rest_%s_invalid_id', $lowercase_model_name),
263
-                sprintf(esc_html__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name),
264
-                array('status' => 404)
265
-            );
266
-        }
267
-        $requested_permanent_delete = filter_var($request->get_param('force'), FILTER_VALIDATE_BOOLEAN);
268
-        $requested_allow_blocking = filter_var($request->get_param('allow_blocking'), FILTER_VALIDATE_BOOLEAN);
269
-        if ($requested_permanent_delete) {
270
-            $previous = $this->returnModelObjAsJsonResponse($model_obj, $request);
271
-            $deleted = (bool) $model->delete_permanently_by_ID($obj_id, $requested_allow_blocking);
272
-            return array(
273
-                'deleted'  => $deleted,
274
-                'previous' => $previous,
275
-            );
276
-        } else {
277
-            if ($model instanceof EEM_Soft_Delete_Base) {
278
-                $model->delete_by_ID($obj_id, $requested_allow_blocking);
279
-                return $this->returnModelObjAsJsonResponse($model_obj, $request);
280
-            } else {
281
-                throw new RestException(
282
-                    'rest_trash_not_supported',
283
-                    501,
284
-                    sprintf(
285
-                        esc_html__('%1$s do not support trashing. Set force=1 to delete.', 'event_espresso'),
286
-                        EEH_Inflector::pluralize($model->get_this_model_name())
287
-                    )
288
-                );
289
-            }
290
-        }
291
-    }
229
+	/**
230
+	 * Updates an existing model object according to the $request
231
+	 *
232
+	 * @param EEM_Base        $model
233
+	 * @param WP_REST_Request $request
234
+	 * @return array of either the soft-deleted item, or
235
+	 * @throws EE_Error
236
+	 */
237
+	public function delete(EEM_Base $model, WP_REST_Request $request)
238
+	{
239
+		Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_delete, 'delete');
240
+		$default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap();
241
+		if (! current_user_can($default_cap_to_check_for)) {
242
+			throw new RestException(
243
+				'rest_cannot_delete_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
244
+				sprintf(
245
+					esc_html__(
246
+					// @codingStandardsIgnoreStart
247
+						'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to delete data into Event Espresso.',
248
+						// @codingStandardsIgnoreEnd
249
+						'event_espresso'
250
+					),
251
+					$default_cap_to_check_for
252
+				),
253
+				array('status' => 403)
254
+			);
255
+		}
256
+		$obj_id = $request->get_param('id');
257
+		// this is where we would apply more fine-grained caps
258
+		$model_obj = $model->get_one_by_ID($obj_id);
259
+		if (! $model_obj instanceof EE_Base_Class) {
260
+			$lowercase_model_name = strtolower($model->get_this_model_name());
261
+			throw new RestException(
262
+				sprintf('rest_%s_invalid_id', $lowercase_model_name),
263
+				sprintf(esc_html__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name),
264
+				array('status' => 404)
265
+			);
266
+		}
267
+		$requested_permanent_delete = filter_var($request->get_param('force'), FILTER_VALIDATE_BOOLEAN);
268
+		$requested_allow_blocking = filter_var($request->get_param('allow_blocking'), FILTER_VALIDATE_BOOLEAN);
269
+		if ($requested_permanent_delete) {
270
+			$previous = $this->returnModelObjAsJsonResponse($model_obj, $request);
271
+			$deleted = (bool) $model->delete_permanently_by_ID($obj_id, $requested_allow_blocking);
272
+			return array(
273
+				'deleted'  => $deleted,
274
+				'previous' => $previous,
275
+			);
276
+		} else {
277
+			if ($model instanceof EEM_Soft_Delete_Base) {
278
+				$model->delete_by_ID($obj_id, $requested_allow_blocking);
279
+				return $this->returnModelObjAsJsonResponse($model_obj, $request);
280
+			} else {
281
+				throw new RestException(
282
+					'rest_trash_not_supported',
283
+					501,
284
+					sprintf(
285
+						esc_html__('%1$s do not support trashing. Set force=1 to delete.', 'event_espresso'),
286
+						EEH_Inflector::pluralize($model->get_this_model_name())
287
+					)
288
+				);
289
+			}
290
+		}
291
+	}
292 292
 
293 293
 
294
-    /**
295
-     * Returns an array ready to be converted into a JSON response, based solely on the model object
296
-     *
297
-     * @param EE_Base_Class   $model_obj
298
-     * @param WP_REST_Request $request
299
-     * @return array ready for a response
300
-     */
301
-    protected function returnModelObjAsJsonResponse(EE_Base_Class $model_obj, WP_REST_Request $request)
302
-    {
303
-        $model = $model_obj->get_model();
304
-        // create an array exactly like the wpdb results row,
305
-        // so we can pass it to controllers/model/Read::create_entity_from_wpdb_result()
306
-        $simulated_db_row = array();
307
-        foreach ($model->field_settings(true) as $field_name => $field_obj) {
308
-            // we need to reconstruct the normal wpdb results, including the db-only fields
309
-            // like a secondary table's primary key. The models expect those (but don't care what value they have)
310
-            if ($field_obj instanceof EE_DB_Only_Field_Base) {
311
-                $raw_value = true;
312
-            } elseif ($field_obj instanceof EE_Datetime_Field) {
313
-                $raw_value = $model_obj->get_DateTime_object($field_name);
314
-            } else {
315
-                $raw_value = $model_obj->get_raw($field_name);
316
-            }
317
-            $simulated_db_row[ $field_obj->get_qualified_column() ] = $field_obj->prepare_for_use_in_db($raw_value);
318
-        }
319
-        $read_controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read');
320
-        $read_controller->setRequestedVersion($this->getRequestedVersion());
321
-        // the simulates request really doesn't need any info downstream
322
-        $simulated_request = new WP_REST_Request('GET');
323
-        // set the caps context on the simulated according to the original request.
324
-        switch ($request->get_method()) {
325
-            case 'POST':
326
-            case 'PUT':
327
-                $caps_context = EEM_Base::caps_edit;
328
-                break;
329
-            case 'DELETE':
330
-                $caps_context = EEM_Base::caps_delete;
331
-                break;
332
-            default:
333
-                $caps_context = EEM_Base::caps_read_admin;
334
-        }
335
-        $simulated_request->set_param('caps', $caps_context);
336
-        return $read_controller->createEntityFromWpdbResult(
337
-            $model_obj->get_model(),
338
-            $simulated_db_row,
339
-            $simulated_request
340
-        );
341
-    }
294
+	/**
295
+	 * Returns an array ready to be converted into a JSON response, based solely on the model object
296
+	 *
297
+	 * @param EE_Base_Class   $model_obj
298
+	 * @param WP_REST_Request $request
299
+	 * @return array ready for a response
300
+	 */
301
+	protected function returnModelObjAsJsonResponse(EE_Base_Class $model_obj, WP_REST_Request $request)
302
+	{
303
+		$model = $model_obj->get_model();
304
+		// create an array exactly like the wpdb results row,
305
+		// so we can pass it to controllers/model/Read::create_entity_from_wpdb_result()
306
+		$simulated_db_row = array();
307
+		foreach ($model->field_settings(true) as $field_name => $field_obj) {
308
+			// we need to reconstruct the normal wpdb results, including the db-only fields
309
+			// like a secondary table's primary key. The models expect those (but don't care what value they have)
310
+			if ($field_obj instanceof EE_DB_Only_Field_Base) {
311
+				$raw_value = true;
312
+			} elseif ($field_obj instanceof EE_Datetime_Field) {
313
+				$raw_value = $model_obj->get_DateTime_object($field_name);
314
+			} else {
315
+				$raw_value = $model_obj->get_raw($field_name);
316
+			}
317
+			$simulated_db_row[ $field_obj->get_qualified_column() ] = $field_obj->prepare_for_use_in_db($raw_value);
318
+		}
319
+		$read_controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read');
320
+		$read_controller->setRequestedVersion($this->getRequestedVersion());
321
+		// the simulates request really doesn't need any info downstream
322
+		$simulated_request = new WP_REST_Request('GET');
323
+		// set the caps context on the simulated according to the original request.
324
+		switch ($request->get_method()) {
325
+			case 'POST':
326
+			case 'PUT':
327
+				$caps_context = EEM_Base::caps_edit;
328
+				break;
329
+			case 'DELETE':
330
+				$caps_context = EEM_Base::caps_delete;
331
+				break;
332
+			default:
333
+				$caps_context = EEM_Base::caps_read_admin;
334
+		}
335
+		$simulated_request->set_param('caps', $caps_context);
336
+		return $read_controller->createEntityFromWpdbResult(
337
+			$model_obj->get_model(),
338
+			$simulated_db_row,
339
+			$simulated_request
340
+		);
341
+	}
342 342
 
343 343
 
344
-    /**
345
-     * Gets the item affected by this request
346
-     *
347
-     * @param EEM_Base        $model
348
-     * @param WP_REST_Request $request
349
-     * @param  int|string     $obj_id
350
-     * @return \WP_Error|array
351
-     */
352
-    protected function getOneBasedOnRequest(EEM_Base $model, WP_REST_Request $request, $obj_id)
353
-    {
354
-        $requested_version = $this->getRequestedVersion($request->get_route());
355
-        $get_request = new WP_REST_Request(
356
-            'GET',
357
-            EED_Core_Rest_Api::ee_api_namespace
358
-            . $requested_version
359
-            . '/'
360
-            . EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
361
-            . '/'
362
-            . $obj_id
363
-        );
364
-        $get_request->set_url_params(
365
-            array(
366
-                'id'      => $obj_id,
367
-                'include' => $request->get_param('include'),
368
-            )
369
-        );
370
-        $read_controller = new Read();
371
-        $read_controller->setRequestedVersion($this->getRequestedVersion());
372
-        return $read_controller->getEntityFromModel($model, $get_request);
373
-    }
344
+	/**
345
+	 * Gets the item affected by this request
346
+	 *
347
+	 * @param EEM_Base        $model
348
+	 * @param WP_REST_Request $request
349
+	 * @param  int|string     $obj_id
350
+	 * @return \WP_Error|array
351
+	 */
352
+	protected function getOneBasedOnRequest(EEM_Base $model, WP_REST_Request $request, $obj_id)
353
+	{
354
+		$requested_version = $this->getRequestedVersion($request->get_route());
355
+		$get_request = new WP_REST_Request(
356
+			'GET',
357
+			EED_Core_Rest_Api::ee_api_namespace
358
+			. $requested_version
359
+			. '/'
360
+			. EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
361
+			. '/'
362
+			. $obj_id
363
+		);
364
+		$get_request->set_url_params(
365
+			array(
366
+				'id'      => $obj_id,
367
+				'include' => $request->get_param('include'),
368
+			)
369
+		);
370
+		$read_controller = new Read();
371
+		$read_controller->setRequestedVersion($this->getRequestedVersion());
372
+		return $read_controller->getEntityFromModel($model, $get_request);
373
+	}
374 374
 
375
-    /**
376
-     * Adds a relation between the specified models (if it doesn't already exist.)
377
-     * @since 4.9.76.p
378
-     * @param WP_REST_Request $request
379
-     * @return WP_REST_Response
380
-     */
381
-    public static function handleRequestAddRelation(WP_REST_Request $request, $version, $model_name, $related_model_name)
382
-    {
383
-        $controller = new Write();
384
-        try {
385
-            $controller->setRequestedVersion($version);
386
-            $main_model = $controller->validateModel($model_name);
387
-            $controller->validateModel($related_model_name);
388
-            return $controller->sendResponse(
389
-                $controller->addRelation(
390
-                    $main_model,
391
-                    $main_model->related_settings_for($related_model_name),
392
-                    $request
393
-                )
394
-            );
395
-        } catch (Exception $e) {
396
-            return $controller->sendResponse($e);
397
-        }
398
-    }
375
+	/**
376
+	 * Adds a relation between the specified models (if it doesn't already exist.)
377
+	 * @since 4.9.76.p
378
+	 * @param WP_REST_Request $request
379
+	 * @return WP_REST_Response
380
+	 */
381
+	public static function handleRequestAddRelation(WP_REST_Request $request, $version, $model_name, $related_model_name)
382
+	{
383
+		$controller = new Write();
384
+		try {
385
+			$controller->setRequestedVersion($version);
386
+			$main_model = $controller->validateModel($model_name);
387
+			$controller->validateModel($related_model_name);
388
+			return $controller->sendResponse(
389
+				$controller->addRelation(
390
+					$main_model,
391
+					$main_model->related_settings_for($related_model_name),
392
+					$request
393
+				)
394
+			);
395
+		} catch (Exception $e) {
396
+			return $controller->sendResponse($e);
397
+		}
398
+	}
399 399
 
400
-    /**
401
-     * Adds a relation between the two model specified model objects.
402
-     * @since 4.9.76.p
403
-     * @param EEM_Base $model
404
-     * @param EE_Model_Relation_Base $relation
405
-     * @param WP_REST_Request $request
406
-     * @return array
407
-     * @throws EE_Error
408
-     * @throws InvalidArgumentException
409
-     * @throws InvalidDataTypeException
410
-     * @throws InvalidInterfaceException
411
-     * @throws RestException
412
-     * @throws DomainException
413
-     */
414
-    public function addRelation(EEM_Base $model, EE_Model_Relation_Base $relation, WP_REST_Request $request)
415
-    {
416
-        list($model_obj, $other_obj) = $this->getBothModelObjects($model, $relation, $request);
417
-        $extra_params = array();
418
-        if ($relation instanceof EE_HABTM_Relation) {
419
-            $extra_params = array_intersect_key(
420
-                ModelDataTranslator::prepareConditionsQueryParamsForModels(
421
-                    $request->get_body_params(),
422
-                    $relation->get_join_model(),
423
-                    $this->getModelVersionInfo()->requestedVersion(),
424
-                    true
425
-                ),
426
-                $relation->getNonKeyFields()
427
-            );
428
-        }
429
-        // Add a relation.
430
-        $related_obj = $model_obj->_add_relation_to(
431
-            $other_obj,
432
-            $relation->get_other_model()->get_this_model_name(),
433
-            $extra_params
434
-        );
435
-        $response = array(
436
-            strtolower($model->get_this_model_name()) => $this->returnModelObjAsJsonResponse($model_obj, $request),
437
-            strtolower($relation->get_other_model()->get_this_model_name()) => $this->returnModelObjAsJsonResponse($related_obj, $request),
438
-        );
439
-        if ($relation instanceof EE_HABTM_Relation) {
440
-            $join_model_obj = $relation->get_join_model()->get_one(
441
-                array(
442
-                    array(
443
-                        $relation->get_join_model()->get_foreign_key_to($model->get_this_model_name())->get_name() => $model_obj->ID(),
444
-                        $relation->get_join_model()->get_foreign_key_to($relation->get_other_model()->get_this_model_name())->get_name() => $related_obj->ID()
445
-                    )
446
-                )
447
-            );
448
-            $response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = $this->returnModelObjAsJsonResponse($join_model_obj, $request);
449
-        }
450
-        return $response;
451
-    }
400
+	/**
401
+	 * Adds a relation between the two model specified model objects.
402
+	 * @since 4.9.76.p
403
+	 * @param EEM_Base $model
404
+	 * @param EE_Model_Relation_Base $relation
405
+	 * @param WP_REST_Request $request
406
+	 * @return array
407
+	 * @throws EE_Error
408
+	 * @throws InvalidArgumentException
409
+	 * @throws InvalidDataTypeException
410
+	 * @throws InvalidInterfaceException
411
+	 * @throws RestException
412
+	 * @throws DomainException
413
+	 */
414
+	public function addRelation(EEM_Base $model, EE_Model_Relation_Base $relation, WP_REST_Request $request)
415
+	{
416
+		list($model_obj, $other_obj) = $this->getBothModelObjects($model, $relation, $request);
417
+		$extra_params = array();
418
+		if ($relation instanceof EE_HABTM_Relation) {
419
+			$extra_params = array_intersect_key(
420
+				ModelDataTranslator::prepareConditionsQueryParamsForModels(
421
+					$request->get_body_params(),
422
+					$relation->get_join_model(),
423
+					$this->getModelVersionInfo()->requestedVersion(),
424
+					true
425
+				),
426
+				$relation->getNonKeyFields()
427
+			);
428
+		}
429
+		// Add a relation.
430
+		$related_obj = $model_obj->_add_relation_to(
431
+			$other_obj,
432
+			$relation->get_other_model()->get_this_model_name(),
433
+			$extra_params
434
+		);
435
+		$response = array(
436
+			strtolower($model->get_this_model_name()) => $this->returnModelObjAsJsonResponse($model_obj, $request),
437
+			strtolower($relation->get_other_model()->get_this_model_name()) => $this->returnModelObjAsJsonResponse($related_obj, $request),
438
+		);
439
+		if ($relation instanceof EE_HABTM_Relation) {
440
+			$join_model_obj = $relation->get_join_model()->get_one(
441
+				array(
442
+					array(
443
+						$relation->get_join_model()->get_foreign_key_to($model->get_this_model_name())->get_name() => $model_obj->ID(),
444
+						$relation->get_join_model()->get_foreign_key_to($relation->get_other_model()->get_this_model_name())->get_name() => $related_obj->ID()
445
+					)
446
+				)
447
+			);
448
+			$response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = $this->returnModelObjAsJsonResponse($join_model_obj, $request);
449
+		}
450
+		return $response;
451
+	}
452 452
 
453 453
 
454
-    /**
455
-     * Removes the relation between the specified models (if it exists).
456
-     * @since 4.9.76.p
457
-     * @param WP_REST_Request $request
458
-     * @return WP_REST_Response
459
-     */
460
-    public static function handleRequestRemoveRelation(WP_REST_Request $request, $version, $model_name, $related_model_name)
461
-    {
462
-        $controller = new Write();
463
-        try {
464
-            $controller->setRequestedVersion($version);
465
-            $main_model = $controller->getModelVersionInfo()->loadModel($model_name);
466
-            return $controller->sendResponse(
467
-                $controller->removeRelation(
468
-                    $main_model,
469
-                    $main_model->related_settings_for($related_model_name),
470
-                    $request
471
-                )
472
-            );
473
-        } catch (Exception $e) {
474
-            return $controller->sendResponse($e);
475
-        }
476
-    }
454
+	/**
455
+	 * Removes the relation between the specified models (if it exists).
456
+	 * @since 4.9.76.p
457
+	 * @param WP_REST_Request $request
458
+	 * @return WP_REST_Response
459
+	 */
460
+	public static function handleRequestRemoveRelation(WP_REST_Request $request, $version, $model_name, $related_model_name)
461
+	{
462
+		$controller = new Write();
463
+		try {
464
+			$controller->setRequestedVersion($version);
465
+			$main_model = $controller->getModelVersionInfo()->loadModel($model_name);
466
+			return $controller->sendResponse(
467
+				$controller->removeRelation(
468
+					$main_model,
469
+					$main_model->related_settings_for($related_model_name),
470
+					$request
471
+				)
472
+			);
473
+		} catch (Exception $e) {
474
+			return $controller->sendResponse($e);
475
+		}
476
+	}
477 477
 
478
-    /**
479
-     * Adds a relation between the two model specified model objects.
480
-     * @since 4.9.76.p
481
-     * @param EEM_Base $model
482
-     * @param EE_Model_Relation_Base $relation
483
-     * @param WP_REST_Request $request
484
-     * @return array
485
-     * @throws DomainException
486
-     * @throws EE_Error
487
-     * @throws InvalidArgumentException
488
-     * @throws InvalidDataTypeException
489
-     * @throws InvalidInterfaceException
490
-     * @throws RestException
491
-     */
492
-    public function removeRelation(EEM_Base $model, EE_Model_Relation_Base $relation, WP_REST_Request $request)
493
-    {
494
-        // This endpoint doesn't accept body parameters (it's understandable to think it might, so let developers know
495
-        // up-front that it doesn't.)
496
-        if (!empty($request->get_body_params())) {
497
-            $body_params = $request->get_body_params();
498
-            throw new RestException(
499
-                'invalid_field',
500
-                sprintf(
501
-                    esc_html__('This endpoint doesn\'t accept post body arguments, you sent in %1$s', 'event_espresso'),
502
-                    implode(array_keys($body_params))
503
-                )
504
-            );
505
-        }
506
-        list($model_obj, $other_obj) = $this->getBothModelObjects($model, $relation, $request);
507
-        // Remember the old relation, if it used a join entry.
508
-        $join_model_obj = null;
509
-        if ($relation instanceof EE_HABTM_Relation) {
510
-            $join_model_obj = $relation->get_join_model()->get_one(
511
-                array(
512
-                    array(
513
-                        $model->primary_key_name() => $model_obj->ID(),
514
-                        $relation->get_other_model()->primary_key_name() => $other_obj->ID()
515
-                    )
516
-                )
517
-            );
518
-        }
519
-        // Remove the relation.
520
-        $related_obj = $model_obj->_remove_relation_to(
521
-            $other_obj,
522
-            $relation->get_other_model()->get_this_model_name()
523
-        );
524
-        $response = array(
525
-            strtolower($model->get_this_model_name()) => $this->returnModelObjAsJsonResponse($model_obj, $request),
526
-            strtolower($relation->get_other_model()->get_this_model_name()) => $this->returnModelObjAsJsonResponse($related_obj, $request),
527
-        );
528
-        if ($relation instanceof EE_HABTM_Relation) {
529
-            $join_model_obj_after_removal = $relation->get_join_model()->get_one(
530
-                array(
531
-                    array(
532
-                        $model->primary_key_name() => $model_obj->ID(),
533
-                        $relation->get_other_model()->primary_key_name() => $other_obj->ID()
534
-                    )
535
-                )
536
-            );
537
-            if ($join_model_obj instanceof EE_Base_Class) {
538
-                $response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = $this->returnModelObjAsJsonResponse($join_model_obj, $request);
539
-            } else {
540
-                $response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = null;
541
-            }
542
-        }
543
-        return $response;
544
-    }
478
+	/**
479
+	 * Adds a relation between the two model specified model objects.
480
+	 * @since 4.9.76.p
481
+	 * @param EEM_Base $model
482
+	 * @param EE_Model_Relation_Base $relation
483
+	 * @param WP_REST_Request $request
484
+	 * @return array
485
+	 * @throws DomainException
486
+	 * @throws EE_Error
487
+	 * @throws InvalidArgumentException
488
+	 * @throws InvalidDataTypeException
489
+	 * @throws InvalidInterfaceException
490
+	 * @throws RestException
491
+	 */
492
+	public function removeRelation(EEM_Base $model, EE_Model_Relation_Base $relation, WP_REST_Request $request)
493
+	{
494
+		// This endpoint doesn't accept body parameters (it's understandable to think it might, so let developers know
495
+		// up-front that it doesn't.)
496
+		if (!empty($request->get_body_params())) {
497
+			$body_params = $request->get_body_params();
498
+			throw new RestException(
499
+				'invalid_field',
500
+				sprintf(
501
+					esc_html__('This endpoint doesn\'t accept post body arguments, you sent in %1$s', 'event_espresso'),
502
+					implode(array_keys($body_params))
503
+				)
504
+			);
505
+		}
506
+		list($model_obj, $other_obj) = $this->getBothModelObjects($model, $relation, $request);
507
+		// Remember the old relation, if it used a join entry.
508
+		$join_model_obj = null;
509
+		if ($relation instanceof EE_HABTM_Relation) {
510
+			$join_model_obj = $relation->get_join_model()->get_one(
511
+				array(
512
+					array(
513
+						$model->primary_key_name() => $model_obj->ID(),
514
+						$relation->get_other_model()->primary_key_name() => $other_obj->ID()
515
+					)
516
+				)
517
+			);
518
+		}
519
+		// Remove the relation.
520
+		$related_obj = $model_obj->_remove_relation_to(
521
+			$other_obj,
522
+			$relation->get_other_model()->get_this_model_name()
523
+		);
524
+		$response = array(
525
+			strtolower($model->get_this_model_name()) => $this->returnModelObjAsJsonResponse($model_obj, $request),
526
+			strtolower($relation->get_other_model()->get_this_model_name()) => $this->returnModelObjAsJsonResponse($related_obj, $request),
527
+		);
528
+		if ($relation instanceof EE_HABTM_Relation) {
529
+			$join_model_obj_after_removal = $relation->get_join_model()->get_one(
530
+				array(
531
+					array(
532
+						$model->primary_key_name() => $model_obj->ID(),
533
+						$relation->get_other_model()->primary_key_name() => $other_obj->ID()
534
+					)
535
+				)
536
+			);
537
+			if ($join_model_obj instanceof EE_Base_Class) {
538
+				$response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = $this->returnModelObjAsJsonResponse($join_model_obj, $request);
539
+			} else {
540
+				$response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = null;
541
+			}
542
+		}
543
+		return $response;
544
+	}
545 545
 
546
-    /**
547
-     * Gets the model objects indicated by the model, relation object, and request.
548
-     * Throws an exception if the first object doesn't exist, and currently if the related object also doesn't exist.
549
-     * However, this behaviour may change, as we may add support for simultaneously creating and relating data.
550
-     * @since 4.9.76.p
551
-     * @param EEM_Base $model
552
-     * @param EE_Model_Relation_Base $relation
553
-     * @param WP_REST_Request $request
554
-     * @return array {
555
-     * @type EE_Base_Class $model_obj
556
-     * @type EE_Base_Class|null $other_model_obj
557
-     * }
558
-     * @throws RestException
559
-     */
560
-    protected function getBothModelObjects(EEM_Base $model, EE_Model_Relation_Base $relation, WP_REST_Request $request)
561
-    {
562
-        // Check generic caps. For now, we're only allowing access to this endpoint to full admins.
563
-        Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit');
564
-        $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap();
565
-        if (! current_user_can($default_cap_to_check_for)) {
566
-            throw new RestException(
567
-                'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
568
-                sprintf(
569
-                    esc_html__(
570
-                        // @codingStandardsIgnoreStart
571
-                        'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to add relations in Event Espresso.',
572
-                        // @codingStandardsIgnoreEnd
573
-                        'event_espresso'
574
-                    ),
575
-                    $default_cap_to_check_for
576
-                ),
577
-                array('status' => 403)
578
-            );
579
-        }
580
-        // Get the main model object.
581
-        $model_obj = $this->getOneOrThrowException($model, $request->get_param('id'));
582
-        // For now, we require the other model object to exist too. This might be relaxed later.
583
-        $other_obj = $this->getOneOrThrowException($relation->get_other_model(), $request->get_param('related_id'));
584
-        return array($model_obj,$other_obj);
585
-    }
546
+	/**
547
+	 * Gets the model objects indicated by the model, relation object, and request.
548
+	 * Throws an exception if the first object doesn't exist, and currently if the related object also doesn't exist.
549
+	 * However, this behaviour may change, as we may add support for simultaneously creating and relating data.
550
+	 * @since 4.9.76.p
551
+	 * @param EEM_Base $model
552
+	 * @param EE_Model_Relation_Base $relation
553
+	 * @param WP_REST_Request $request
554
+	 * @return array {
555
+	 * @type EE_Base_Class $model_obj
556
+	 * @type EE_Base_Class|null $other_model_obj
557
+	 * }
558
+	 * @throws RestException
559
+	 */
560
+	protected function getBothModelObjects(EEM_Base $model, EE_Model_Relation_Base $relation, WP_REST_Request $request)
561
+	{
562
+		// Check generic caps. For now, we're only allowing access to this endpoint to full admins.
563
+		Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit');
564
+		$default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap();
565
+		if (! current_user_can($default_cap_to_check_for)) {
566
+			throw new RestException(
567
+				'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())),
568
+				sprintf(
569
+					esc_html__(
570
+						// @codingStandardsIgnoreStart
571
+						'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to add relations in Event Espresso.',
572
+						// @codingStandardsIgnoreEnd
573
+						'event_espresso'
574
+					),
575
+					$default_cap_to_check_for
576
+				),
577
+				array('status' => 403)
578
+			);
579
+		}
580
+		// Get the main model object.
581
+		$model_obj = $this->getOneOrThrowException($model, $request->get_param('id'));
582
+		// For now, we require the other model object to exist too. This might be relaxed later.
583
+		$other_obj = $this->getOneOrThrowException($relation->get_other_model(), $request->get_param('related_id'));
584
+		return array($model_obj,$other_obj);
585
+	}
586 586
 
587
-    /**
588
-     * Gets the model with that ID or throws a REST exception.
589
-     * @since 4.9.76.p
590
-     * @param EEM_Base $model
591
-     * @param $id
592
-     * @return EE_Base_Class
593
-     * @throws RestException
594
-     */
595
-    protected function getOneOrThrowException(EEM_Base $model, $id)
596
-    {
597
-        $model_obj = $model->get_one_by_ID($id);
598
-        // @todo: check they can permission for it. For now unnecessary because only full admins can use this endpoint.
599
-        if ($model_obj instanceof EE_Base_Class) {
600
-            return $model_obj;
601
-        }
602
-        $lowercase_model_name = strtolower($model->get_this_model_name());
603
-        throw new RestException(
604
-            sprintf('rest_%s_invalid_id', $lowercase_model_name),
605
-            sprintf(esc_html__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name),
606
-            array('status' => 404)
607
-        );
608
-    }
587
+	/**
588
+	 * Gets the model with that ID or throws a REST exception.
589
+	 * @since 4.9.76.p
590
+	 * @param EEM_Base $model
591
+	 * @param $id
592
+	 * @return EE_Base_Class
593
+	 * @throws RestException
594
+	 */
595
+	protected function getOneOrThrowException(EEM_Base $model, $id)
596
+	{
597
+		$model_obj = $model->get_one_by_ID($id);
598
+		// @todo: check they can permission for it. For now unnecessary because only full admins can use this endpoint.
599
+		if ($model_obj instanceof EE_Base_Class) {
600
+			return $model_obj;
601
+		}
602
+		$lowercase_model_name = strtolower($model->get_this_model_name());
603
+		throw new RestException(
604
+			sprintf('rest_%s_invalid_id', $lowercase_model_name),
605
+			sprintf(esc_html__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name),
606
+			array('status' => 404)
607
+		);
608
+	}
609 609
 }
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.