Completed
Branch BUG/3575-event-deletion-previe... (bbeda1)
by
unknown
06:40 queued 04:49
created
core/db_models/strategies/EE_Restriction_Generator_Base.strategy.php 2 patches
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -27,182 +27,182 @@
 block discarded – undo
27 27
 abstract class EE_Restriction_Generator_Base
28 28
 {
29 29
 
30
-    /**
31
-     * The restrictions generated by this object. FALSE before any are made.
32
-     * @var EE_Default_Where_Conditions[]
33
-     */
34
-    protected $_cap_restrictions_generated = false;
30
+	/**
31
+	 * The restrictions generated by this object. FALSE before any are made.
32
+	 * @var EE_Default_Where_Conditions[]
33
+	 */
34
+	protected $_cap_restrictions_generated = false;
35 35
 
36
-    /**
37
-     * Model for which restrictions are generated
38
-     * @var EEM_Base
39
-     */
40
-    protected $_model;
36
+	/**
37
+	 * Model for which restrictions are generated
38
+	 * @var EEM_Base
39
+	 */
40
+	protected $_model;
41 41
 
42
-    /**
43
-     * One of EEM_Base::valid_cap_contexts()
44
-     * @var string
45
-     */
46
-    protected $_action;
47
-    /**
48
-     * Puts the last necessary info onto the restriction generator class. This is usually
49
-     * called by EEM_Base during its constructor, so child classes don't have to
50
-     * always provide this info.
51
-     * @param EEM_Base $model
52
-     * @param string $action
53
-     */
54
-    public function _construct_finalize(EEM_Base $model, $action)
55
-    {
56
-        $this->_model = $model;
57
-        $this->_action = $action;
58
-    }
42
+	/**
43
+	 * One of EEM_Base::valid_cap_contexts()
44
+	 * @var string
45
+	 */
46
+	protected $_action;
47
+	/**
48
+	 * Puts the last necessary info onto the restriction generator class. This is usually
49
+	 * called by EEM_Base during its constructor, so child classes don't have to
50
+	 * always provide this info.
51
+	 * @param EEM_Base $model
52
+	 * @param string $action
53
+	 */
54
+	public function _construct_finalize(EEM_Base $model, $action)
55
+	{
56
+		$this->_model = $model;
57
+		$this->_action = $action;
58
+	}
59 59
 
60
-    /**
61
-     * Returns the model set for this restriction generator
62
-     *
63
-     * @throws EE_Error
64
-     * @return EEM_Base | EEM_Soft_Delete_Base
65
-     */
66
-    public function model()
67
-    {
68
-        if (! $this->_model instanceof EEM_Base) {
69
-            throw new EE_Error(sprintf(esc_html__('Cannot generate capability restrictions because model has not yet been set on the %s. Please ensure _construct_finalize() was called', 'event_espresso'), get_class($this)));
70
-        }
71
-        return $this->_model;
72
-    }
60
+	/**
61
+	 * Returns the model set for this restriction generator
62
+	 *
63
+	 * @throws EE_Error
64
+	 * @return EEM_Base | EEM_Soft_Delete_Base
65
+	 */
66
+	public function model()
67
+	{
68
+		if (! $this->_model instanceof EEM_Base) {
69
+			throw new EE_Error(sprintf(esc_html__('Cannot generate capability restrictions because model has not yet been set on the %s. Please ensure _construct_finalize() was called', 'event_espresso'), get_class($this)));
70
+		}
71
+		return $this->_model;
72
+	}
73 73
 
74
-    /**
75
-     * Returns the action this restriction generator will generate restrictions for.
76
-     * It should be one of EEM_Base::valid_cap_contexts()
77
-     *
78
-     * @throws EE_Error
79
-     * @return string
80
-     */
81
-    public function action()
82
-    {
83
-        if (! $this->_action) {
84
-            throw new EE_Error(sprintf(esc_html__('Cannot generate capability restrictions because model has not yet been set on the %s. Please ensure _construct_finalize() was called', 'event_espresso'), get_class($this)));
85
-        }
86
-        return $this->_action;
87
-    }
74
+	/**
75
+	 * Returns the action this restriction generator will generate restrictions for.
76
+	 * It should be one of EEM_Base::valid_cap_contexts()
77
+	 *
78
+	 * @throws EE_Error
79
+	 * @return string
80
+	 */
81
+	public function action()
82
+	{
83
+		if (! $this->_action) {
84
+			throw new EE_Error(sprintf(esc_html__('Cannot generate capability restrictions because model has not yet been set on the %s. Please ensure _construct_finalize() was called', 'event_espresso'), get_class($this)));
85
+		}
86
+		return $this->_action;
87
+	}
88 88
 
89
-    /**
90
-     * Returns whether or not _construct_finalize() has been called on this restriction generator object
91
-     * @return boolean
92
-     */
93
-    public function construction_finalized()
94
-    {
95
-        if ($this->_model instanceof EEM_Base  && $this->_action) {
96
-            return true;
97
-        } else {
98
-            return false;
99
-        }
100
-    }
89
+	/**
90
+	 * Returns whether or not _construct_finalize() has been called on this restriction generator object
91
+	 * @return boolean
92
+	 */
93
+	public function construction_finalized()
94
+	{
95
+		if ($this->_model instanceof EEM_Base  && $this->_action) {
96
+			return true;
97
+		} else {
98
+			return false;
99
+		}
100
+	}
101 101
 
102
-    /**
103
-     * Gets the capability restrictions generated by this object. Caches them in
104
-     * case they are required for subsequent requests
105
-     * @return array @see EEM_Base::_cap_restrictions
106
-     */
107
-    public function generate_restrictions()
108
-    {
109
-        if ($this->_cap_restrictions_generated === false) {
110
-            $this->_cap_restrictions_generated = apply_filters('FHEE__EE_Restriction_Generator_Base__generate_restrictions__first_time', $this->_generate_restrictions(), $this);
111
-        }
112
-        return apply_filters('FHEE__EE_Restriction_Generator_Base__generate_restrictions__every_time', $this->_cap_restrictions_generated, $this);
113
-    }
102
+	/**
103
+	 * Gets the capability restrictions generated by this object. Caches them in
104
+	 * case they are required for subsequent requests
105
+	 * @return array @see EEM_Base::_cap_restrictions
106
+	 */
107
+	public function generate_restrictions()
108
+	{
109
+		if ($this->_cap_restrictions_generated === false) {
110
+			$this->_cap_restrictions_generated = apply_filters('FHEE__EE_Restriction_Generator_Base__generate_restrictions__first_time', $this->_generate_restrictions(), $this);
111
+		}
112
+		return apply_filters('FHEE__EE_Restriction_Generator_Base__generate_restrictions__every_time', $this->_cap_restrictions_generated, $this);
113
+	}
114 114
 
115
-    /**
116
-     * Provided with the model, and using global knowledge about what capabilities exist,
117
-     * generates an array for use in one of the sub-arrays in EEM_Base::_cap_restrictions,
118
-     * where keys are capability names, and values are children of EE_Default_Where_Conditions
119
-     * @return array @see EEM_Base::_cap_restrictions
120
-     */
121
-    abstract protected function _generate_restrictions();
115
+	/**
116
+	 * Provided with the model, and using global knowledge about what capabilities exist,
117
+	 * generates an array for use in one of the sub-arrays in EEM_Base::_cap_restrictions,
118
+	 * where keys are capability names, and values are children of EE_Default_Where_Conditions
119
+	 * @return array @see EEM_Base::_cap_restrictions
120
+	 */
121
+	abstract protected function _generate_restrictions();
122 122
 
123
-    /**
124
-     * Whether or not this restriction generator has already done its job of
125
-     * making restrictions and caching them on itself in case its asked later
126
-     * @return boolean
127
-     */
128
-    public function has_generated_cap_restrictions()
129
-    {
130
-        if ($this->_cap_restrictions_generated === false) {
131
-            return false;
132
-        } else {
133
-            return true;
134
-        }
135
-    }
123
+	/**
124
+	 * Whether or not this restriction generator has already done its job of
125
+	 * making restrictions and caching them on itself in case its asked later
126
+	 * @return boolean
127
+	 */
128
+	public function has_generated_cap_restrictions()
129
+	{
130
+		if ($this->_cap_restrictions_generated === false) {
131
+			return false;
132
+		} else {
133
+			return true;
134
+		}
135
+	}
136 136
 
137
-    /**
138
-     * Given an action like 'edit' generates the cap name based off
139
-     * the EEM_Base::_cap_slug, which for events would be 'events', to generate the
140
-     * cap name like 'ee_edit_events'.
141
-     * If a $qualifier is passed,
142
-     * @param EEM_Base $model
143
-     * @param string $action
144
-     * @return string
145
-     */
146
-    public static function get_cap_name($model, $action)
147
-    {
148
-        return apply_filters('FHEE__EE_Restriction_Generator__get_cap_name', ( $model->is_wp_core_model() ? '' : 'ee_' ) . $action . '_' . $model->cap_slug(), $model, $action);
149
-    }
137
+	/**
138
+	 * Given an action like 'edit' generates the cap name based off
139
+	 * the EEM_Base::_cap_slug, which for events would be 'events', to generate the
140
+	 * cap name like 'ee_edit_events'.
141
+	 * If a $qualifier is passed,
142
+	 * @param EEM_Base $model
143
+	 * @param string $action
144
+	 * @return string
145
+	 */
146
+	public static function get_cap_name($model, $action)
147
+	{
148
+		return apply_filters('FHEE__EE_Restriction_Generator__get_cap_name', ( $model->is_wp_core_model() ? '' : 'ee_' ) . $action . '_' . $model->cap_slug(), $model, $action);
149
+	}
150 150
 
151
-    /**
152
-     * Checks if there is a cap for this model and this action
153
-     * @param EEM_Base $model
154
-     * @param string $action
155
-     * @return boolean
156
-     */
157
-    public static function is_cap($model, $action)
158
-    {
159
-        $caps_for_admin = EE_Registry::instance()->CAP->get_ee_capabilities('administrator');
160
-        if (in_array(self::get_cap_name($model, $action), $caps_for_admin)) {
161
-            return true;
162
-        } else {
163
-            return false;
164
-        }
165
-    }
151
+	/**
152
+	 * Checks if there is a cap for this model and this action
153
+	 * @param EEM_Base $model
154
+	 * @param string $action
155
+	 * @return boolean
156
+	 */
157
+	public static function is_cap($model, $action)
158
+	{
159
+		$caps_for_admin = EE_Registry::instance()->CAP->get_ee_capabilities('administrator');
160
+		if (in_array(self::get_cap_name($model, $action), $caps_for_admin)) {
161
+			return true;
162
+		} else {
163
+			return false;
164
+		}
165
+	}
166 166
 
167
-    /**
168
-     * Returns the default capability used to determine if the current user can
169
-     * access something.
170
-     * @return string
171
-     */
172
-    public static function get_default_restrictions_cap()
173
-    {
174
-        return apply_filters('FHEE__EE_Restriction_Generator_Base__default_restrictions_cap', 'manage_options');
175
-    }
167
+	/**
168
+	 * Returns the default capability used to determine if the current user can
169
+	 * access something.
170
+	 * @return string
171
+	 */
172
+	public static function get_default_restrictions_cap()
173
+	{
174
+		return apply_filters('FHEE__EE_Restriction_Generator_Base__default_restrictions_cap', 'manage_options');
175
+	}
176 176
 
177 177
 
178
-    /**
179
-     * Gets WHERE conditions for the query that show the posty-y model is published,
180
-     * or that it's sold out and it was previously published
181
-     * @param array $where_conditions
182
-     * @param boolean $check_if_published if true, will add conditions like status=publish. If false, will add conditions
183
-     *                                    like status!=private
184
-     * @param string $path_to_event_model including the period at the end
185
-     * @return array
186
-     */
187
-    protected function addPublishedPostConditions($where_conditions = array(), $check_if_published = true, $path_to_event_model = '')
188
-    {
189
-        if ($check_if_published) {
190
-            $published_value = 'publish';
191
-        } else {
192
-            $published_value = array('!=','private');
193
-        }
194
-        // only add a check for the previous event status if the model is the event or it's related to the event model
195
-        if ($this->model() instanceof EEM_Event || strpos($path_to_event_model, 'Event') !== false) {
196
-            $where_conditions['OR*status'] = array(
197
-                $path_to_event_model . 'status' => $published_value,
198
-                'AND' => array(
199
-                    $path_to_event_model . 'Post_Meta.meta_key'   => '_previous_event_status',
200
-                    $path_to_event_model . 'Post_Meta.meta_value' => $published_value
201
-                )
202
-            );
203
-        } else {
204
-            $where_conditions[ $path_to_event_model . 'status' ] = $published_value;
205
-        }
206
-        return $where_conditions;
207
-    }
178
+	/**
179
+	 * Gets WHERE conditions for the query that show the posty-y model is published,
180
+	 * or that it's sold out and it was previously published
181
+	 * @param array $where_conditions
182
+	 * @param boolean $check_if_published if true, will add conditions like status=publish. If false, will add conditions
183
+	 *                                    like status!=private
184
+	 * @param string $path_to_event_model including the period at the end
185
+	 * @return array
186
+	 */
187
+	protected function addPublishedPostConditions($where_conditions = array(), $check_if_published = true, $path_to_event_model = '')
188
+	{
189
+		if ($check_if_published) {
190
+			$published_value = 'publish';
191
+		} else {
192
+			$published_value = array('!=','private');
193
+		}
194
+		// only add a check for the previous event status if the model is the event or it's related to the event model
195
+		if ($this->model() instanceof EEM_Event || strpos($path_to_event_model, 'Event') !== false) {
196
+			$where_conditions['OR*status'] = array(
197
+				$path_to_event_model . 'status' => $published_value,
198
+				'AND' => array(
199
+					$path_to_event_model . 'Post_Meta.meta_key'   => '_previous_event_status',
200
+					$path_to_event_model . 'Post_Meta.meta_value' => $published_value
201
+				)
202
+			);
203
+		} else {
204
+			$where_conditions[ $path_to_event_model . 'status' ] = $published_value;
205
+		}
206
+		return $where_conditions;
207
+	}
208 208
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      */
66 66
     public function model()
67 67
     {
68
-        if (! $this->_model instanceof EEM_Base) {
68
+        if ( ! $this->_model instanceof EEM_Base) {
69 69
             throw new EE_Error(sprintf(esc_html__('Cannot generate capability restrictions because model has not yet been set on the %s. Please ensure _construct_finalize() was called', 'event_espresso'), get_class($this)));
70 70
         }
71 71
         return $this->_model;
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public function action()
82 82
     {
83
-        if (! $this->_action) {
83
+        if ( ! $this->_action) {
84 84
             throw new EE_Error(sprintf(esc_html__('Cannot generate capability restrictions because model has not yet been set on the %s. Please ensure _construct_finalize() was called', 'event_espresso'), get_class($this)));
85 85
         }
86 86
         return $this->_action;
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
      */
93 93
     public function construction_finalized()
94 94
     {
95
-        if ($this->_model instanceof EEM_Base  && $this->_action) {
95
+        if ($this->_model instanceof EEM_Base && $this->_action) {
96 96
             return true;
97 97
         } else {
98 98
             return false;
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
      */
146 146
     public static function get_cap_name($model, $action)
147 147
     {
148
-        return apply_filters('FHEE__EE_Restriction_Generator__get_cap_name', ( $model->is_wp_core_model() ? '' : 'ee_' ) . $action . '_' . $model->cap_slug(), $model, $action);
148
+        return apply_filters('FHEE__EE_Restriction_Generator__get_cap_name', ($model->is_wp_core_model() ? '' : 'ee_').$action.'_'.$model->cap_slug(), $model, $action);
149 149
     }
150 150
 
151 151
     /**
@@ -189,19 +189,19 @@  discard block
 block discarded – undo
189 189
         if ($check_if_published) {
190 190
             $published_value = 'publish';
191 191
         } else {
192
-            $published_value = array('!=','private');
192
+            $published_value = array('!=', 'private');
193 193
         }
194 194
         // only add a check for the previous event status if the model is the event or it's related to the event model
195 195
         if ($this->model() instanceof EEM_Event || strpos($path_to_event_model, 'Event') !== false) {
196 196
             $where_conditions['OR*status'] = array(
197
-                $path_to_event_model . 'status' => $published_value,
197
+                $path_to_event_model.'status' => $published_value,
198 198
                 'AND' => array(
199
-                    $path_to_event_model . 'Post_Meta.meta_key'   => '_previous_event_status',
200
-                    $path_to_event_model . 'Post_Meta.meta_value' => $published_value
199
+                    $path_to_event_model.'Post_Meta.meta_key'   => '_previous_event_status',
200
+                    $path_to_event_model.'Post_Meta.meta_value' => $published_value
201 201
                 )
202 202
             );
203 203
         } else {
204
-            $where_conditions[ $path_to_event_model . 'status' ] = $published_value;
204
+            $where_conditions[$path_to_event_model.'status'] = $published_value;
205 205
         }
206 206
         return $where_conditions;
207 207
     }
Please login to merge, or discard this patch.
core/db_models/strategies/EE_Soft_Delete_Where_Conditions.strategy.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -13,41 +13,41 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Soft_Delete_Where_Conditions extends EE_Default_Where_Conditions
15 15
 {
16
-    /**
17
-     * Strategy for setting default soft delete where conditions. This strategy will find
18
-     * the field of type 'EE_Trashed_Flag_Field', and add a condition that it be FALSE on all queries involving
19
-     * the model.
20
-     * If you want to override these default where conditions, you may explicitly in the query you send to the model.
21
-     * Eg,
22
-     *
23
-     */
24
-    public function __construct()
25
-    {
26
-    }
27
-    /**
28
-     * Gets the where default where conditions for a custom post type model
29
-     * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
30
-     */
31
-    protected function _get_default_where_conditions()
32
-    {
33
-        $trashed_field_name = $this->deleted_field_name();
34
-        return array(
35
-            $trashed_field_name => false
36
-        );
37
-    }
38
-    /**
39
-     * Searches for field on the model of type 'deleted_flag'. if it is found,
40
-     * returns it's name.
41
-     * @return string
42
-     * @throws EE_Error
43
-     */
44
-    private function deleted_field_name()
45
-    {
46
-        $field = $this->_model->get_a_field_of_type('EE_Trashed_Flag_Field');
47
-        if ($field) {
48
-            return $field->get_name();
49
-        } else {
50
-            throw new EE_Error(sprintf(esc_html__('We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', 'event_espresso'), get_class($this), get_class($this)));
51
-        }
52
-    }
16
+	/**
17
+	 * Strategy for setting default soft delete where conditions. This strategy will find
18
+	 * the field of type 'EE_Trashed_Flag_Field', and add a condition that it be FALSE on all queries involving
19
+	 * the model.
20
+	 * If you want to override these default where conditions, you may explicitly in the query you send to the model.
21
+	 * Eg,
22
+	 *
23
+	 */
24
+	public function __construct()
25
+	{
26
+	}
27
+	/**
28
+	 * Gets the where default where conditions for a custom post type model
29
+	 * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
30
+	 */
31
+	protected function _get_default_where_conditions()
32
+	{
33
+		$trashed_field_name = $this->deleted_field_name();
34
+		return array(
35
+			$trashed_field_name => false
36
+		);
37
+	}
38
+	/**
39
+	 * Searches for field on the model of type 'deleted_flag'. if it is found,
40
+	 * returns it's name.
41
+	 * @return string
42
+	 * @throws EE_Error
43
+	 */
44
+	private function deleted_field_name()
45
+	{
46
+		$field = $this->_model->get_a_field_of_type('EE_Trashed_Flag_Field');
47
+		if ($field) {
48
+			return $field->get_name();
49
+		} else {
50
+			throw new EE_Error(sprintf(esc_html__('We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', 'event_espresso'), get_class($this), get_class($this)));
51
+		}
52
+	}
53 53
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Price_Type.model.php 2 patches
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -12,108 +12,108 @@  discard block
 block discarded – undo
12 12
 class EEM_Price_Type extends EEM_Soft_Delete_Base
13 13
 {
14 14
 
15
-    // private instance of the Price Type object
16
-    protected static $_instance = null;
17
-    // An array of the price type objects
18
-    public $type = null;
19
-
20
-    /**
21
-    *   Price Base types
22
-    *
23
-    *   @access private
24
-    *   @var int
25
-    */
26
-    public $base_types = null;
27
-
28
-    /**
29
-     * return an array of Base types. Keys are INTs which are used in the database,
30
-     * values are text-representations of the base type.
31
-     * @return array
32
-     */
33
-    public function get_base_types()
34
-    {
35
-        return $this->base_types;
36
-    }
37
-
38
-    /**
39
-     * Gets the name of the base
40
-     * @param type $base_type_int
41
-     * @return type
42
-     */
43
-    public function get_base_type_name($base_type_int)
44
-    {
45
-        return $this->base_types[ $base_type_int ];
46
-    }
47
-
48
-    /**
49
-     * constants for price base types. In the DB, we decided to store the price base type
50
-     * as an integer. So, to avoid just having magic numbers everwhere (eg, querying for
51
-     * all price types with PBT_ID = 2), we define these constants, to make code more understandable.
52
-     * So, as an example, to query for all price types that are a tax, we'd do
53
-     * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax)))
54
-     * instead of
55
-     * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2)))
56
-     * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever
57
-     * change, we can continue to use the constant, by simply change its value.
58
-     */
59
-    const base_type_base_price = 1;
60
-    const base_type_discount = 2;
61
-    const base_type_surcharge = 3;
62
-    const base_type_tax = 4;
63
-    /**
64
-     *      private constructor to prevent direct creation
65
-     *      @Constructor
66
-     *      @access protected
67
-     *      @return void
68
-     */
69
-    protected function __construct($timezone = null)
70
-    {
71
-        $this->base_types = array(
72
-            EEM_Price_Type::base_type_base_price => esc_html__('Price', 'event_espresso'),
73
-            EEM_Price_Type::base_type_discount => esc_html__('Discount', 'event_espresso'),
74
-            EEM_Price_Type::base_type_surcharge => esc_html__('Surcharge', 'event_espresso'),
75
-            EEM_Price_Type::base_type_tax => esc_html__('Tax', 'event_espresso') );
76
-        $this->singular_item = esc_html__('Price Type', 'event_espresso');
77
-        $this->plural_item = esc_html__('Price Types', 'event_espresso');
78
-
79
-        $this->_tables = array(
80
-            'Price_Type' => new EE_Primary_Table('esp_price_type', 'PRT_ID')
81
-        );
82
-        $this->_fields = array(
83
-            'Price_Type' => array(
84
-                'PRT_ID' => new EE_Primary_Key_Int_Field('PRT_ID', esc_html__('Price Type ID', 'event_espresso')),
85
-                'PRT_name' => new EE_Plain_Text_Field('PRT_name', esc_html__('Price Type Name', 'event_espresso'), false, ''),
86
-                'PBT_ID' => new EE_Enum_Integer_Field('PBT_ID', esc_html__('Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax', 'event_espresso'), false, EEM_Price_Type::base_type_base_price, $this->base_types),
87
-                'PRT_is_percent' => new EE_Boolean_Field('PRT_is_percent', esc_html__('Flag indicating price is a percentage', 'event_espresso'), false, false),
88
-                'PRT_order' => new EE_Integer_Field('PRT_order', esc_html__('Order in which price should be applied. ', 'event_espresso'), false, 0),
89
-                'PRT_deleted' => new EE_Trashed_Flag_Field('PRT_deleted', esc_html__('Flag indicating price type has been trashed', 'event_espresso'), false, false),
90
-                'PRT_wp_user' => new EE_WP_User_Field('PRT_wp_user', esc_html__('Price Type Creator ID', 'event_espresso'), false),
91
-            )
92
-        );
93
-        $this->_model_relations = array(
94
-            'Price' => new EE_Has_Many_Relation(),
95
-            'WP_User' => new EE_Belongs_To_Relation(),
96
-        );
97
-        // this model is generally available for reading
98
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
99
-        // all price types are "default" in terms of capability names
100
-        $this->_caps_slug = 'default_price_types';
101
-        parent::__construct($timezone);
102
-    }
103
-
104
-
105
-
106
-
107
-    /**
108
-     *      instantiate a new price type object with blank/empty properties
109
-     *
110
-     *      @access     public
111
-     *      @return     mixed       array on success, FALSE on fail
112
-     */
113
-    public function get_new_price_type()
114
-    {
115
-        return EE_Price_Type::new_instance();
116
-    }
15
+	// private instance of the Price Type object
16
+	protected static $_instance = null;
17
+	// An array of the price type objects
18
+	public $type = null;
19
+
20
+	/**
21
+	 *   Price Base types
22
+	 *
23
+	 *   @access private
24
+	 *   @var int
25
+	 */
26
+	public $base_types = null;
27
+
28
+	/**
29
+	 * return an array of Base types. Keys are INTs which are used in the database,
30
+	 * values are text-representations of the base type.
31
+	 * @return array
32
+	 */
33
+	public function get_base_types()
34
+	{
35
+		return $this->base_types;
36
+	}
37
+
38
+	/**
39
+	 * Gets the name of the base
40
+	 * @param type $base_type_int
41
+	 * @return type
42
+	 */
43
+	public function get_base_type_name($base_type_int)
44
+	{
45
+		return $this->base_types[ $base_type_int ];
46
+	}
47
+
48
+	/**
49
+	 * constants for price base types. In the DB, we decided to store the price base type
50
+	 * as an integer. So, to avoid just having magic numbers everwhere (eg, querying for
51
+	 * all price types with PBT_ID = 2), we define these constants, to make code more understandable.
52
+	 * So, as an example, to query for all price types that are a tax, we'd do
53
+	 * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax)))
54
+	 * instead of
55
+	 * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2)))
56
+	 * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever
57
+	 * change, we can continue to use the constant, by simply change its value.
58
+	 */
59
+	const base_type_base_price = 1;
60
+	const base_type_discount = 2;
61
+	const base_type_surcharge = 3;
62
+	const base_type_tax = 4;
63
+	/**
64
+	 *      private constructor to prevent direct creation
65
+	 *      @Constructor
66
+	 *      @access protected
67
+	 *      @return void
68
+	 */
69
+	protected function __construct($timezone = null)
70
+	{
71
+		$this->base_types = array(
72
+			EEM_Price_Type::base_type_base_price => esc_html__('Price', 'event_espresso'),
73
+			EEM_Price_Type::base_type_discount => esc_html__('Discount', 'event_espresso'),
74
+			EEM_Price_Type::base_type_surcharge => esc_html__('Surcharge', 'event_espresso'),
75
+			EEM_Price_Type::base_type_tax => esc_html__('Tax', 'event_espresso') );
76
+		$this->singular_item = esc_html__('Price Type', 'event_espresso');
77
+		$this->plural_item = esc_html__('Price Types', 'event_espresso');
78
+
79
+		$this->_tables = array(
80
+			'Price_Type' => new EE_Primary_Table('esp_price_type', 'PRT_ID')
81
+		);
82
+		$this->_fields = array(
83
+			'Price_Type' => array(
84
+				'PRT_ID' => new EE_Primary_Key_Int_Field('PRT_ID', esc_html__('Price Type ID', 'event_espresso')),
85
+				'PRT_name' => new EE_Plain_Text_Field('PRT_name', esc_html__('Price Type Name', 'event_espresso'), false, ''),
86
+				'PBT_ID' => new EE_Enum_Integer_Field('PBT_ID', esc_html__('Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax', 'event_espresso'), false, EEM_Price_Type::base_type_base_price, $this->base_types),
87
+				'PRT_is_percent' => new EE_Boolean_Field('PRT_is_percent', esc_html__('Flag indicating price is a percentage', 'event_espresso'), false, false),
88
+				'PRT_order' => new EE_Integer_Field('PRT_order', esc_html__('Order in which price should be applied. ', 'event_espresso'), false, 0),
89
+				'PRT_deleted' => new EE_Trashed_Flag_Field('PRT_deleted', esc_html__('Flag indicating price type has been trashed', 'event_espresso'), false, false),
90
+				'PRT_wp_user' => new EE_WP_User_Field('PRT_wp_user', esc_html__('Price Type Creator ID', 'event_espresso'), false),
91
+			)
92
+		);
93
+		$this->_model_relations = array(
94
+			'Price' => new EE_Has_Many_Relation(),
95
+			'WP_User' => new EE_Belongs_To_Relation(),
96
+		);
97
+		// this model is generally available for reading
98
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
99
+		// all price types are "default" in terms of capability names
100
+		$this->_caps_slug = 'default_price_types';
101
+		parent::__construct($timezone);
102
+	}
103
+
104
+
105
+
106
+
107
+	/**
108
+	 *      instantiate a new price type object with blank/empty properties
109
+	 *
110
+	 *      @access     public
111
+	 *      @return     mixed       array on success, FALSE on fail
112
+	 */
113
+	public function get_new_price_type()
114
+	{
115
+		return EE_Price_Type::new_instance();
116
+	}
117 117
 
118 118
 
119 119
 
@@ -132,33 +132,33 @@  discard block
 block discarded – undo
132 132
  *
133 133
  * @param type $query_params
134 134
  * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
135
-     * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects
136
-     * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
135
+ * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects
136
+ * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
137 137
  * @return boolean
138 138
  */
139
-    public function delete_permanently($query_params = array(), $allow_blocking = true)
140
-    {
139
+	public function delete_permanently($query_params = array(), $allow_blocking = true)
140
+	{
141 141
 
142
-        $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params);
143
-        $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types);
142
+		$would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params);
143
+		$would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types);
144 144
 
145
-        $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ];
145
+		$ID = $query_params[0][ $this->get_primary_key_field()->get_name() ];
146 146
 
147
-        // check if any prices use this price type
148
-        $prc_query_params = array(array('PRT_ID' => array('IN',$would_be_deleted_price_type_ids)));
149
-        if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) {
150
-            $prices_names_and_ids = array();
151
-            foreach ($prices as $price) {
152
-                /* @var $price EE_Price */
153
-                $prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")";
154
-            }
155
-            $msg = sprintf(esc_html__('The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type.  If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', 'event_espresso'), implode(",", $prices_names_and_ids));
156
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
157
-            return false;
158
-        }
147
+		// check if any prices use this price type
148
+		$prc_query_params = array(array('PRT_ID' => array('IN',$would_be_deleted_price_type_ids)));
149
+		if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) {
150
+			$prices_names_and_ids = array();
151
+			foreach ($prices as $price) {
152
+				/* @var $price EE_Price */
153
+				$prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")";
154
+			}
155
+			$msg = sprintf(esc_html__('The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type.  If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', 'event_espresso'), implode(",", $prices_names_and_ids));
156
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
157
+			return false;
158
+		}
159 159
 
160 160
 
161 161
 
162
-        return parent::delete_permanently($query_params);
163
-    }
162
+		return parent::delete_permanently($query_params);
163
+	}
164 164
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function get_base_type_name($base_type_int)
44 44
     {
45
-        return $this->base_types[ $base_type_int ];
45
+        return $this->base_types[$base_type_int];
46 46
     }
47 47
 
48 48
     /**
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
             'WP_User' => new EE_Belongs_To_Relation(),
96 96
         );
97 97
         // this model is generally available for reading
98
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
98
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
99 99
         // all price types are "default" in terms of capability names
100 100
         $this->_caps_slug = 'default_price_types';
101 101
         parent::__construct($timezone);
@@ -142,15 +142,15 @@  discard block
 block discarded – undo
142 142
         $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params);
143 143
         $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types);
144 144
 
145
-        $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ];
145
+        $ID = $query_params[0][$this->get_primary_key_field()->get_name()];
146 146
 
147 147
         // check if any prices use this price type
148
-        $prc_query_params = array(array('PRT_ID' => array('IN',$would_be_deleted_price_type_ids)));
148
+        $prc_query_params = array(array('PRT_ID' => array('IN', $would_be_deleted_price_type_ids)));
149 149
         if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) {
150 150
             $prices_names_and_ids = array();
151 151
             foreach ($prices as $price) {
152 152
                 /* @var $price EE_Price */
153
-                $prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")";
153
+                $prices_names_and_ids[] = $price->name()."(".$price->ID().")";
154 154
             }
155 155
             $msg = sprintf(esc_html__('The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type.  If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', 'event_espresso'), implode(",", $prices_names_and_ids));
156 156
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
Please login to merge, or discard this patch.
core/db_models/EEM_Status.model.php 2 patches
Indentation   +277 added lines, -277 removed lines patch added patch discarded remove patch
@@ -11,292 +11,292 @@
 block discarded – undo
11 11
 class EEM_Status extends EEM_Base
12 12
 {
13 13
 
14
-    // private instance of the Attendee object
15
-    protected static $_instance = null;
14
+	// private instance of the Attendee object
15
+	protected static $_instance = null;
16 16
 
17 17
 
18
-    /**
19
-     * @return EEM_Status
20
-     */
21
-    protected function __construct($timezone = null)
22
-    {
23
-        $this->singular_item    = esc_html__('Status', 'event_espresso');
24
-        $this->plural_item      = esc_html__('Stati', 'event_espresso');
25
-        $this->_tables          = array(
26
-            'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
27
-        );
28
-        $this->_fields          = array(
29
-            'StatusTable' => array(
30
-                'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso')),
31
-                'STS_code'     => new EE_Plain_Text_Field('STS_code', esc_html__('Status Code', 'event_espresso'), false, ''),
32
-                'STS_type'     => new EE_Enum_Text_Field(
33
-                    'STS_type',
34
-                    esc_html__("Type", "event_espresso"),
35
-                    false,
36
-                    'event',
37
-                    array(
38
-                        'event'        => esc_html__("Event", "event_espresso"),// deprecated
39
-                        'registration' => esc_html__("Registration", "event_espresso"),
40
-                        'transaction'  => esc_html__("Transaction", "event_espresso"),
41
-                        'payment'      => esc_html__("Payment", "event_espresso"),
42
-                        'email'        => esc_html__("Email", "event_espresso"),
43
-                        'message'      => esc_html__("Message", "event_espresso"),
44
-                    )
45
-                ),
46
-                'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', esc_html__('Editable?', 'event_espresso'), false, false),
47
-                'STS_desc'     => new EE_Simple_HTML_Field('STS_desc', esc_html__("Description", "event_espresso"), false, ''),
48
-                'STS_open'     => new EE_Boolean_Field('STS_open', esc_html__("Open?", "event_espresso"), false, false),
49
-            ),
50
-        );
51
-        $this->_model_relations = array(
52
-            'Registration' => new EE_Has_Many_Relation(),
53
-            'Transaction'  => new EE_Has_Many_Relation(),
54
-            'Payment'      => new EE_Has_Many_Relation(),
55
-        );
56
-        // this model is generally available for reading
57
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
18
+	/**
19
+	 * @return EEM_Status
20
+	 */
21
+	protected function __construct($timezone = null)
22
+	{
23
+		$this->singular_item    = esc_html__('Status', 'event_espresso');
24
+		$this->plural_item      = esc_html__('Stati', 'event_espresso');
25
+		$this->_tables          = array(
26
+			'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
27
+		);
28
+		$this->_fields          = array(
29
+			'StatusTable' => array(
30
+				'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso')),
31
+				'STS_code'     => new EE_Plain_Text_Field('STS_code', esc_html__('Status Code', 'event_espresso'), false, ''),
32
+				'STS_type'     => new EE_Enum_Text_Field(
33
+					'STS_type',
34
+					esc_html__("Type", "event_espresso"),
35
+					false,
36
+					'event',
37
+					array(
38
+						'event'        => esc_html__("Event", "event_espresso"),// deprecated
39
+						'registration' => esc_html__("Registration", "event_espresso"),
40
+						'transaction'  => esc_html__("Transaction", "event_espresso"),
41
+						'payment'      => esc_html__("Payment", "event_espresso"),
42
+						'email'        => esc_html__("Email", "event_espresso"),
43
+						'message'      => esc_html__("Message", "event_espresso"),
44
+					)
45
+				),
46
+				'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', esc_html__('Editable?', 'event_espresso'), false, false),
47
+				'STS_desc'     => new EE_Simple_HTML_Field('STS_desc', esc_html__("Description", "event_espresso"), false, ''),
48
+				'STS_open'     => new EE_Boolean_Field('STS_open', esc_html__("Open?", "event_espresso"), false, false),
49
+			),
50
+		);
51
+		$this->_model_relations = array(
52
+			'Registration' => new EE_Has_Many_Relation(),
53
+			'Transaction'  => new EE_Has_Many_Relation(),
54
+			'Payment'      => new EE_Has_Many_Relation(),
55
+		);
56
+		// this model is generally available for reading
57
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
58 58
 
59
-        parent::__construct($timezone);
60
-    }
59
+		parent::__construct($timezone);
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * This method provides the localized singular or plural string for a given status id
65
-     *
66
-     * @param  array   $statuses This should be an array of statuses in the format array( $status_id, $status_code ).
67
-     *                           That way if there isn't a translation in the index we'll return the default code.
68
-     * @param  boolean $plural   Whether to return plural string or not. Note, nearly all of the plural strings are the
69
-     *                           same as the singular (in English), however, this may NOT be the case with other
70
-     *                           languages
71
-     * @param  string  $schema   This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
72
-     *                           the status string returned ( UPPER, lower, Sentence)
73
-     * @throws EE_Error
74
-     * @return array             an array of translated strings for the incoming status id.
75
-     */
76
-    public function localized_status($statuses, $plural = false, $schema = 'upper')
77
-    {
78
-        // note these are all in lower case because ucwords() on upper case will NOT convert.
79
-        $translation_array = array(
80
-            EEM_Registration::status_id_pending_payment => array(
81
-                esc_html__('pending payment', 'event_espresso'), // singular
82
-                esc_html__('pending payments', 'event_espresso') // plural
83
-            ),
84
-            EEM_Registration::status_id_approved        => array(
85
-                esc_html__('approved', 'event_espresso'), // singular
86
-                esc_html__('approved', 'event_espresso') // plural
87
-            ),
88
-            EEM_Registration::status_id_not_approved    => array(
89
-                esc_html__('not approved', 'event_espresso'),
90
-                esc_html__('not approved', 'event_espresso'),
91
-            ),
92
-            EEM_Registration::status_id_cancelled       => array(
93
-                esc_html__('cancelled', 'event_espresso'),
94
-                esc_html__('cancelled', 'event_espresso'),
95
-            ),
96
-            EEM_Registration::status_id_incomplete      => array(
97
-                esc_html__('incomplete', 'event_espresso'),
98
-                esc_html__('incomplete', 'event_espresso'),
99
-            ),
100
-            EEM_Registration::status_id_declined        => array(
101
-                esc_html__('declined', 'event_espresso'),
102
-                esc_html__('declined', 'event_espresso'),
103
-            ),
104
-            EEM_Registration::status_id_wait_list       => array(
105
-                esc_html__('wait list', 'event_espresso'),
106
-                esc_html__('wait list', 'event_espresso'),
107
-            ),
108
-            EEM_Transaction::overpaid_status_code       => array(
109
-                esc_html__('overpaid', 'event_espresso'),
110
-                esc_html__('overpaid', 'event_espresso'),
111
-            ),
112
-            EEM_Transaction::complete_status_code       => array(
113
-                esc_html__('complete', 'event_espresso'),
114
-                esc_html__('complete', 'event_espresso'),
115
-            ),
116
-            EEM_Transaction::incomplete_status_code     => array(
117
-                esc_html__('incomplete', 'event_espresso'),
118
-                esc_html__('incomplete', 'event_espresso'),
119
-            ),
120
-            EEM_Transaction::failed_status_code         => array(
121
-                esc_html__('failed', 'event_espresso'),
122
-                esc_html__('failed', 'event_espresso'),
123
-            ),
124
-            EEM_Transaction::abandoned_status_code      => array(
125
-                esc_html__('abandoned', 'event_espresso'),
126
-                esc_html__('abandoned', 'event_espresso'),
127
-            ),
128
-            EEM_Payment::status_id_approved             => array(
129
-                esc_html__('accepted', 'event_espresso'),
130
-                esc_html__('accepted', 'event_espresso'),
131
-            ),
132
-            EEM_Payment::status_id_pending              => array(
133
-                esc_html__('pending', 'event_espresso'),
134
-                esc_html__('pending', 'event_espresso'),
135
-            ),
136
-            EEM_Payment::status_id_cancelled            => array(
137
-                esc_html__('cancelled', 'event_espresso'),
138
-                esc_html__('cancelled', 'event_espresso'),
139
-            ),
140
-            EEM_Payment::status_id_declined             => array(
141
-                esc_html__('declined', 'event_espresso'),
142
-                esc_html__('declined', 'event_espresso'),
143
-            ),
144
-            EEM_Payment::status_id_failed               => array(
145
-                esc_html__('failed', 'event_espresso'),
146
-                esc_html__('failed', 'event_espresso'),
147
-            ),
148
-            // following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
149
-            EEM_Event::sold_out                         => array(
150
-                esc_html__('sold out', 'event_espresso'),
151
-                esc_html__('sold out', 'event_espresso'),
152
-            ),
153
-            EEM_Event::postponed                        => array(
154
-                esc_html__('postponed', 'event_espresso'),
155
-                esc_html__('Postponed', 'event_espresso'),
156
-            ),
157
-            EEM_Event::cancelled                        => array(
158
-                esc_html__('cancelled', 'event_espresso'),
159
-                esc_html__('cancelled', 'event_espresso'),
160
-            ),
161
-            EE_Ticket::archived                         => array(
162
-                esc_html__('archived', 'event_espresso'),
163
-                esc_html__('archived', 'event_espresso'),
164
-            ),
165
-            EE_Ticket::expired                          => array(
166
-                esc_html__('expired', 'event_espresso'),
167
-                esc_html__('expired', 'event_espresso'),
168
-            ),
169
-            EE_Ticket::sold_out                         => array(
170
-                esc_html__('sold out', 'event_espresso'),
171
-                esc_html__('sold out', 'event_espresso'),
172
-            ),
173
-            EE_Ticket::pending                          => array(
174
-                esc_html__('upcoming', 'event_espresso'),
175
-                esc_html__('upcoming', 'event_espresso'),
176
-            ),
177
-            EE_Ticket::onsale                           => array(
178
-                esc_html__('on sale', 'event_espresso'),
179
-                esc_html__('on sale', 'event_espresso'),
180
-            ),
181
-            EE_Datetime::cancelled                      => array(
182
-                esc_html__('cancelled', 'event_espresso'),
183
-                esc_html__('cancelled', 'event_espresso'),
184
-            ),
185
-            EE_Datetime::sold_out                       => array(
186
-                esc_html__('sold out', 'event_espresso'),
187
-                esc_html__('sold out', 'event_espresso'),
188
-            ),
189
-            EE_Datetime::expired                        => array(
190
-                esc_html__('expired', 'event_espresso'),
191
-                esc_html__('expired', 'event_espresso'),
192
-            ),
193
-            EE_Datetime::inactive                       => array(
194
-                esc_html__('inactive', 'event_espresso'),
195
-                esc_html__('inactive', 'event_espresso'),
196
-            ),
197
-            EE_Datetime::upcoming                       => array(
198
-                esc_html__('upcoming', 'event_espresso'),
199
-                esc_html__('upcoming', 'event_espresso'),
200
-            ),
201
-            EE_Datetime::active                         => array(
202
-                esc_html__('active', 'event_espresso'),
203
-                esc_html__('active', 'event_espresso'),
204
-            ),
205
-            EE_Datetime::postponed                      => array(
206
-                esc_html__('postponed', 'event_espresso'),
207
-                esc_html__('postponed', 'event_espresso'),
208
-            ),
209
-            // messages related
210
-            EEM_Message::status_sent                    => array(
211
-                esc_html__('sent', 'event_espresso'),
212
-                esc_html__('sent', 'event_espresso'),
213
-            ),
214
-            EEM_Message::status_idle                    => array(
215
-                esc_html__('queued for sending', 'event_espresso'),
216
-                esc_html__('queued for sending', 'event_espresso'),
217
-            ),
218
-            EEM_Message::status_failed                  => array(
219
-                esc_html__('failed', 'event_espresso'),
220
-                esc_html__('failed', 'event_espresso'),
221
-            ),
222
-            EEM_Message::status_debug_only              => array(
223
-                esc_html__('debug only', 'event_espresso'),
224
-                esc_html__('debug only', 'event_espresso'),
225
-            ),
226
-            EEM_Message::status_messenger_executing     => array(
227
-                esc_html__('messenger is executing', 'event_espresso'),
228
-                esc_html__('messenger is executing', 'event_espresso'),
229
-            ),
230
-            EEM_Message::status_resend                  => array(
231
-                esc_html__('queued for resending', 'event_espresso'),
232
-                esc_html__('queued for resending', 'event_espresso'),
233
-            ),
234
-            EEM_Message::status_incomplete              => array(
235
-                esc_html__('queued for generating', 'event_espresso'),
236
-                esc_html__('queued for generating', 'event_espresso'),
237
-            ),
238
-            EEM_Message::status_retry                   => array(
239
-                esc_html__('failed sending, can be retried', 'event_espresso'),
240
-                esc_html__('failed sending, can be retried', 'event_espresso'),
241
-            ),
242
-            EEM_CPT_Base::post_status_publish           => array(
243
-                esc_html__('published', 'event_espresso'),
244
-                esc_html__('published', 'event_espresso'),
245
-            ),
246
-            EEM_CPT_Base::post_status_future            => array(
247
-                esc_html__('scheduled', 'event_espresso'),
248
-                esc_html__('scheduled', 'event_espresso'),
249
-            ),
250
-            EEM_CPT_Base::post_status_draft             => array(
251
-                esc_html__('draft', 'event_espresso'),
252
-                esc_html__('draft', 'event_espresso'),
253
-            ),
254
-            EEM_CPT_Base::post_status_pending           => array(
255
-                esc_html__('pending', 'event_espresso'),
256
-                esc_html__('pending', 'event_espresso'),
257
-            ),
258
-            EEM_CPT_Base::post_status_private           => array(
259
-                esc_html__('private', 'event_espresso'),
260
-                esc_html__('private', 'event_espresso'),
261
-            ),
262
-            EEM_CPT_Base::post_status_trashed           => array(
263
-                esc_html__('trashed', 'event_espresso'),
264
-                esc_html__('trashed', 'event_espresso'),
265
-            ),
266
-        );
63
+	/**
64
+	 * This method provides the localized singular or plural string for a given status id
65
+	 *
66
+	 * @param  array   $statuses This should be an array of statuses in the format array( $status_id, $status_code ).
67
+	 *                           That way if there isn't a translation in the index we'll return the default code.
68
+	 * @param  boolean $plural   Whether to return plural string or not. Note, nearly all of the plural strings are the
69
+	 *                           same as the singular (in English), however, this may NOT be the case with other
70
+	 *                           languages
71
+	 * @param  string  $schema   This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
72
+	 *                           the status string returned ( UPPER, lower, Sentence)
73
+	 * @throws EE_Error
74
+	 * @return array             an array of translated strings for the incoming status id.
75
+	 */
76
+	public function localized_status($statuses, $plural = false, $schema = 'upper')
77
+	{
78
+		// note these are all in lower case because ucwords() on upper case will NOT convert.
79
+		$translation_array = array(
80
+			EEM_Registration::status_id_pending_payment => array(
81
+				esc_html__('pending payment', 'event_espresso'), // singular
82
+				esc_html__('pending payments', 'event_espresso') // plural
83
+			),
84
+			EEM_Registration::status_id_approved        => array(
85
+				esc_html__('approved', 'event_espresso'), // singular
86
+				esc_html__('approved', 'event_espresso') // plural
87
+			),
88
+			EEM_Registration::status_id_not_approved    => array(
89
+				esc_html__('not approved', 'event_espresso'),
90
+				esc_html__('not approved', 'event_espresso'),
91
+			),
92
+			EEM_Registration::status_id_cancelled       => array(
93
+				esc_html__('cancelled', 'event_espresso'),
94
+				esc_html__('cancelled', 'event_espresso'),
95
+			),
96
+			EEM_Registration::status_id_incomplete      => array(
97
+				esc_html__('incomplete', 'event_espresso'),
98
+				esc_html__('incomplete', 'event_espresso'),
99
+			),
100
+			EEM_Registration::status_id_declined        => array(
101
+				esc_html__('declined', 'event_espresso'),
102
+				esc_html__('declined', 'event_espresso'),
103
+			),
104
+			EEM_Registration::status_id_wait_list       => array(
105
+				esc_html__('wait list', 'event_espresso'),
106
+				esc_html__('wait list', 'event_espresso'),
107
+			),
108
+			EEM_Transaction::overpaid_status_code       => array(
109
+				esc_html__('overpaid', 'event_espresso'),
110
+				esc_html__('overpaid', 'event_espresso'),
111
+			),
112
+			EEM_Transaction::complete_status_code       => array(
113
+				esc_html__('complete', 'event_espresso'),
114
+				esc_html__('complete', 'event_espresso'),
115
+			),
116
+			EEM_Transaction::incomplete_status_code     => array(
117
+				esc_html__('incomplete', 'event_espresso'),
118
+				esc_html__('incomplete', 'event_espresso'),
119
+			),
120
+			EEM_Transaction::failed_status_code         => array(
121
+				esc_html__('failed', 'event_espresso'),
122
+				esc_html__('failed', 'event_espresso'),
123
+			),
124
+			EEM_Transaction::abandoned_status_code      => array(
125
+				esc_html__('abandoned', 'event_espresso'),
126
+				esc_html__('abandoned', 'event_espresso'),
127
+			),
128
+			EEM_Payment::status_id_approved             => array(
129
+				esc_html__('accepted', 'event_espresso'),
130
+				esc_html__('accepted', 'event_espresso'),
131
+			),
132
+			EEM_Payment::status_id_pending              => array(
133
+				esc_html__('pending', 'event_espresso'),
134
+				esc_html__('pending', 'event_espresso'),
135
+			),
136
+			EEM_Payment::status_id_cancelled            => array(
137
+				esc_html__('cancelled', 'event_espresso'),
138
+				esc_html__('cancelled', 'event_espresso'),
139
+			),
140
+			EEM_Payment::status_id_declined             => array(
141
+				esc_html__('declined', 'event_espresso'),
142
+				esc_html__('declined', 'event_espresso'),
143
+			),
144
+			EEM_Payment::status_id_failed               => array(
145
+				esc_html__('failed', 'event_espresso'),
146
+				esc_html__('failed', 'event_espresso'),
147
+			),
148
+			// following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
149
+			EEM_Event::sold_out                         => array(
150
+				esc_html__('sold out', 'event_espresso'),
151
+				esc_html__('sold out', 'event_espresso'),
152
+			),
153
+			EEM_Event::postponed                        => array(
154
+				esc_html__('postponed', 'event_espresso'),
155
+				esc_html__('Postponed', 'event_espresso'),
156
+			),
157
+			EEM_Event::cancelled                        => array(
158
+				esc_html__('cancelled', 'event_espresso'),
159
+				esc_html__('cancelled', 'event_espresso'),
160
+			),
161
+			EE_Ticket::archived                         => array(
162
+				esc_html__('archived', 'event_espresso'),
163
+				esc_html__('archived', 'event_espresso'),
164
+			),
165
+			EE_Ticket::expired                          => array(
166
+				esc_html__('expired', 'event_espresso'),
167
+				esc_html__('expired', 'event_espresso'),
168
+			),
169
+			EE_Ticket::sold_out                         => array(
170
+				esc_html__('sold out', 'event_espresso'),
171
+				esc_html__('sold out', 'event_espresso'),
172
+			),
173
+			EE_Ticket::pending                          => array(
174
+				esc_html__('upcoming', 'event_espresso'),
175
+				esc_html__('upcoming', 'event_espresso'),
176
+			),
177
+			EE_Ticket::onsale                           => array(
178
+				esc_html__('on sale', 'event_espresso'),
179
+				esc_html__('on sale', 'event_espresso'),
180
+			),
181
+			EE_Datetime::cancelled                      => array(
182
+				esc_html__('cancelled', 'event_espresso'),
183
+				esc_html__('cancelled', 'event_espresso'),
184
+			),
185
+			EE_Datetime::sold_out                       => array(
186
+				esc_html__('sold out', 'event_espresso'),
187
+				esc_html__('sold out', 'event_espresso'),
188
+			),
189
+			EE_Datetime::expired                        => array(
190
+				esc_html__('expired', 'event_espresso'),
191
+				esc_html__('expired', 'event_espresso'),
192
+			),
193
+			EE_Datetime::inactive                       => array(
194
+				esc_html__('inactive', 'event_espresso'),
195
+				esc_html__('inactive', 'event_espresso'),
196
+			),
197
+			EE_Datetime::upcoming                       => array(
198
+				esc_html__('upcoming', 'event_espresso'),
199
+				esc_html__('upcoming', 'event_espresso'),
200
+			),
201
+			EE_Datetime::active                         => array(
202
+				esc_html__('active', 'event_espresso'),
203
+				esc_html__('active', 'event_espresso'),
204
+			),
205
+			EE_Datetime::postponed                      => array(
206
+				esc_html__('postponed', 'event_espresso'),
207
+				esc_html__('postponed', 'event_espresso'),
208
+			),
209
+			// messages related
210
+			EEM_Message::status_sent                    => array(
211
+				esc_html__('sent', 'event_espresso'),
212
+				esc_html__('sent', 'event_espresso'),
213
+			),
214
+			EEM_Message::status_idle                    => array(
215
+				esc_html__('queued for sending', 'event_espresso'),
216
+				esc_html__('queued for sending', 'event_espresso'),
217
+			),
218
+			EEM_Message::status_failed                  => array(
219
+				esc_html__('failed', 'event_espresso'),
220
+				esc_html__('failed', 'event_espresso'),
221
+			),
222
+			EEM_Message::status_debug_only              => array(
223
+				esc_html__('debug only', 'event_espresso'),
224
+				esc_html__('debug only', 'event_espresso'),
225
+			),
226
+			EEM_Message::status_messenger_executing     => array(
227
+				esc_html__('messenger is executing', 'event_espresso'),
228
+				esc_html__('messenger is executing', 'event_espresso'),
229
+			),
230
+			EEM_Message::status_resend                  => array(
231
+				esc_html__('queued for resending', 'event_espresso'),
232
+				esc_html__('queued for resending', 'event_espresso'),
233
+			),
234
+			EEM_Message::status_incomplete              => array(
235
+				esc_html__('queued for generating', 'event_espresso'),
236
+				esc_html__('queued for generating', 'event_espresso'),
237
+			),
238
+			EEM_Message::status_retry                   => array(
239
+				esc_html__('failed sending, can be retried', 'event_espresso'),
240
+				esc_html__('failed sending, can be retried', 'event_espresso'),
241
+			),
242
+			EEM_CPT_Base::post_status_publish           => array(
243
+				esc_html__('published', 'event_espresso'),
244
+				esc_html__('published', 'event_espresso'),
245
+			),
246
+			EEM_CPT_Base::post_status_future            => array(
247
+				esc_html__('scheduled', 'event_espresso'),
248
+				esc_html__('scheduled', 'event_espresso'),
249
+			),
250
+			EEM_CPT_Base::post_status_draft             => array(
251
+				esc_html__('draft', 'event_espresso'),
252
+				esc_html__('draft', 'event_espresso'),
253
+			),
254
+			EEM_CPT_Base::post_status_pending           => array(
255
+				esc_html__('pending', 'event_espresso'),
256
+				esc_html__('pending', 'event_espresso'),
257
+			),
258
+			EEM_CPT_Base::post_status_private           => array(
259
+				esc_html__('private', 'event_espresso'),
260
+				esc_html__('private', 'event_espresso'),
261
+			),
262
+			EEM_CPT_Base::post_status_trashed           => array(
263
+				esc_html__('trashed', 'event_espresso'),
264
+				esc_html__('trashed', 'event_espresso'),
265
+			),
266
+		);
267 267
 
268
-        $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
268
+		$translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
269 269
 
270
-        if (! is_array($statuses)) {
271
-            throw new EE_Error(esc_html__(
272
-                'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
273
-                'event_espresso'
274
-            ));
275
-        }
270
+		if (! is_array($statuses)) {
271
+			throw new EE_Error(esc_html__(
272
+				'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
273
+				'event_espresso'
274
+			));
275
+		}
276 276
 
277
-        $translation = array();
277
+		$translation = array();
278 278
 
279
-        foreach ($statuses as $id => $code) {
280
-            if (isset($translation_array[ $id ])) {
281
-                $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
282
-            } else {
283
-                $translation[ $id ] = $code;
284
-            }
279
+		foreach ($statuses as $id => $code) {
280
+			if (isset($translation_array[ $id ])) {
281
+				$translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
282
+			} else {
283
+				$translation[ $id ] = $code;
284
+			}
285 285
 
286
-            // schema
287
-            switch ($schema) {
288
-                case 'lower':
289
-                    $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter.
290
-                    break;
291
-                case 'sentence':
292
-                    $translation[ $id ] = ucwords($translation[ $id ]);
293
-                    break;
294
-                case 'upper':
295
-                    $translation[ $id ] = strtoupper($translation[ $id ]);
296
-                    break;
297
-            }
298
-        }
286
+			// schema
287
+			switch ($schema) {
288
+				case 'lower':
289
+					$translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter.
290
+					break;
291
+				case 'sentence':
292
+					$translation[ $id ] = ucwords($translation[ $id ]);
293
+					break;
294
+				case 'upper':
295
+					$translation[ $id ] = strtoupper($translation[ $id ]);
296
+					break;
297
+			}
298
+		}
299 299
 
300
-        return $translation;
301
-    }
300
+		return $translation;
301
+	}
302 302
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
                     false,
36 36
                     'event',
37 37
                     array(
38
-                        'event'        => esc_html__("Event", "event_espresso"),// deprecated
38
+                        'event'        => esc_html__("Event", "event_espresso"), // deprecated
39 39
                         'registration' => esc_html__("Registration", "event_espresso"),
40 40
                         'transaction'  => esc_html__("Transaction", "event_espresso"),
41 41
                         'payment'      => esc_html__("Payment", "event_espresso"),
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
             'Payment'      => new EE_Has_Many_Relation(),
55 55
         );
56 56
         // this model is generally available for reading
57
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
57
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
58 58
 
59 59
         parent::__construct($timezone);
60 60
     }
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 
268 268
         $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
269 269
 
270
-        if (! is_array($statuses)) {
270
+        if ( ! is_array($statuses)) {
271 271
             throw new EE_Error(esc_html__(
272 272
                 'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
273 273
                 'event_espresso'
@@ -277,22 +277,22 @@  discard block
 block discarded – undo
277 277
         $translation = array();
278 278
 
279 279
         foreach ($statuses as $id => $code) {
280
-            if (isset($translation_array[ $id ])) {
281
-                $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
280
+            if (isset($translation_array[$id])) {
281
+                $translation[$id] = $plural ? $translation_array[$id][1] : $translation_array[$id][0];
282 282
             } else {
283
-                $translation[ $id ] = $code;
283
+                $translation[$id] = $code;
284 284
             }
285 285
 
286 286
             // schema
287 287
             switch ($schema) {
288 288
                 case 'lower':
289
-                    $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter.
289
+                    $translation[$id] = strtolower($translation[$id]); // even though these start in lower case, this will catch any statuses added via filter.
290 290
                     break;
291 291
                 case 'sentence':
292
-                    $translation[ $id ] = ucwords($translation[ $id ]);
292
+                    $translation[$id] = ucwords($translation[$id]);
293 293
                     break;
294 294
                 case 'upper':
295
-                    $translation[ $id ] = strtoupper($translation[ $id ]);
295
+                    $translation[$id] = strtoupper($translation[$id]);
296 296
                     break;
297 297
             }
298 298
         }
Please login to merge, or discard this patch.
core/db_models/EEM_Checkin.model.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -14,40 +14,40 @@
 block discarded – undo
14 14
 class EEM_Checkin extends EEM_Base
15 15
 {
16 16
 
17
-    // private instance of the EEM_Checkin object
18
-    protected static $_instance = null;
17
+	// private instance of the EEM_Checkin object
18
+	protected static $_instance = null;
19 19
 
20 20
 
21 21
 
22
-    /**
23
-     *      private constructor to prevent direct creation
24
-     *      @Constructor
25
-     *      @access protected
26
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
27
-     *      @return void
28
-     */
29
-    protected function __construct($timezone = null)
30
-    {
31
-        $this->singular_item = esc_html__('Check-In', 'event_espresso');
32
-        $this->plural_item = esc_html__('Check-Ins', 'event_espresso');
22
+	/**
23
+	 *      private constructor to prevent direct creation
24
+	 *      @Constructor
25
+	 *      @access protected
26
+	 *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
27
+	 *      @return void
28
+	 */
29
+	protected function __construct($timezone = null)
30
+	{
31
+		$this->singular_item = esc_html__('Check-In', 'event_espresso');
32
+		$this->plural_item = esc_html__('Check-Ins', 'event_espresso');
33 33
 
34
-        $this->_tables = array(
35
-            'Checkin' => new EE_Primary_Table('esp_checkin', 'CHK_ID')
36
-        );
37
-        $this->_fields = array(
38
-            'Checkin' => array(
39
-                'CHK_ID' => new EE_Primary_Key_Int_Field('CHK_ID', 'Check-in ID'),
40
-                'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', 'Registration Id', false, 0, 'Registration'),
41
-                'DTT_ID' => new EE_Foreign_Key_Int_Field('DTT_ID', 'Datetime Id', false, 0, 'Datetime'),
42
-                'CHK_in' => new EE_Boolean_Field('CHK_in', 'Whether a person has checked in or checked out', false, true),
43
-                'CHK_timestamp' => new EE_Datetime_Field('CHK_timestamp', esc_html__('When the row was modified', 'event_espresso'), false, EE_Datetime_Field::now, $timezone)
44
-            )
45
-        );
46
-        $this->_model_relations = array(
47
-            'Registration' => new EE_Belongs_To_Relation(),
48
-            'Datetime' => new EE_Belongs_To_Relation()
49
-        );
50
-        $this->_model_chain_to_wp_user = 'Registration.Event';
51
-        parent::__construct($timezone);
52
-    }
34
+		$this->_tables = array(
35
+			'Checkin' => new EE_Primary_Table('esp_checkin', 'CHK_ID')
36
+		);
37
+		$this->_fields = array(
38
+			'Checkin' => array(
39
+				'CHK_ID' => new EE_Primary_Key_Int_Field('CHK_ID', 'Check-in ID'),
40
+				'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', 'Registration Id', false, 0, 'Registration'),
41
+				'DTT_ID' => new EE_Foreign_Key_Int_Field('DTT_ID', 'Datetime Id', false, 0, 'Datetime'),
42
+				'CHK_in' => new EE_Boolean_Field('CHK_in', 'Whether a person has checked in or checked out', false, true),
43
+				'CHK_timestamp' => new EE_Datetime_Field('CHK_timestamp', esc_html__('When the row was modified', 'event_espresso'), false, EE_Datetime_Field::now, $timezone)
44
+			)
45
+		);
46
+		$this->_model_relations = array(
47
+			'Registration' => new EE_Belongs_To_Relation(),
48
+			'Datetime' => new EE_Belongs_To_Relation()
49
+		);
50
+		$this->_model_chain_to_wp_user = 'Registration.Event';
51
+		parent::__construct($timezone);
52
+	}
53 53
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Message_Template_Group.model.php 2 patches
Indentation   +423 added lines, -423 removed lines patch added patch discarded remove patch
@@ -15,427 +15,427 @@
 block discarded – undo
15 15
 class EEM_Message_Template_Group extends EEM_Soft_Delete_Base
16 16
 {
17 17
 
18
-    // private instance of the EEM_Message_Template_Group object
19
-    protected static $_instance = null;
20
-
21
-
22
-
23
-    protected function __construct($timezone = null)
24
-    {
25
-        $this->singular_item = esc_html__('Message Template Group', 'event_espresso');
26
-        $this->plural_item = esc_html__('Message Template Groups', 'event_espresso');
27
-        $this->_tables = array(
28
-            'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID')
29
-        );
30
-        $this->_fields = array(
31
-            'Message_Template_Group' => array(
32
-                'GRP_ID' => new EE_Primary_Key_Int_Field('GRP_ID', esc_html__('Message Template Group ID', 'event_espresso')),
33
-                'MTP_name' => new EE_Plain_Text_Field('MTP_name', esc_html__('The name of the template group', 'event_espresso'), false, ''),
34
-                'MTP_description' => new EE_Simple_HTML_Field('MTP_description', esc_html__('A brief description about this template.', 'event_espresso'), false, ''),
35
-                'MTP_user_id' => new EE_WP_User_Field('MTP_user_id', esc_html__('Template Creator ID', 'event_espresso'), false, get_current_user_id()),
36
-                'MTP_messenger' => new EE_Plain_Text_Field('MTP_messenger', esc_html__('Messenger Used for Template', 'event_espresso'), false, 'email'),
37
-                'MTP_message_type' => new EE_Plain_Text_Field('MTP_message_type', esc_html__('Message Type', 'event_espresso'), false, 'registration'),
38
-                'MTP_is_global' => new EE_Boolean_Field('MTP_is_global', esc_html__('Flag indicating if Template Group is Global', 'event_espresso'), false, true),
39
-                'MTP_is_override' => new EE_Boolean_Field('MTP_is_override', esc_html__('Flag indicating if Template Group overrides any other Templates for the messenger/messagetype combination', 'event_espresso'), false, false),
40
-                'MTP_deleted' => new EE_Trashed_Flag_Field('MTP_deleted', esc_html__('Flag indicating whether this has been trashed', 'event_espresso'), false, false),
41
-                'MTP_is_active' => new EE_Boolean_Field('MTP_is_active', esc_html__('Flag indicating whether template group is active', 'event_espresso'), false, true)
42
-            )
43
-        );
44
-        $this->_model_relations = array(
45
-            'Message_Template' => new EE_Has_Many_Relation(),
46
-            'Message' => new EE_Has_Many_Relation(),
47
-            'Event' => new EE_HABTM_Relation('Event_Message_Template'),
48
-            'WP_User' => new EE_Belongs_To_Relation()
49
-        );
50
-        foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
51
-            $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global');
52
-        }
53
-        $this->_caps_slug = 'messages';
54
-
55
-        parent::__construct($timezone);
56
-    }
57
-
58
-
59
-
60
-    /**
61
-     * get_all_trashed_message_templates_by_event
62
-     *
63
-     * @access public
64
-     * @param int    $EVT_ID specific event id
65
-     * @param string $orderby
66
-     * @param string $order
67
-     * @param null   $limit
68
-     * @param bool   $count
69
-     * @return array message template objects that are attached to a specific event.
70
-     */
71
-    public function get_all_trashed_message_templates_by_event(
72
-        $EVT_ID,
73
-        $orderby = 'GRP_ID',
74
-        $order = 'ASC',
75
-        $limit = null,
76
-        $count = false
77
-    ) {
78
-        $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit );
79
-        return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
80
-    }
81
-
82
-
83
-
84
-    /**
85
-     * get_all_message_templates_by_messenger
86
-     *
87
-     * @access public
88
-     * @param        $messenger
89
-     * @param string $orderby
90
-     * @param string $order
91
-     * @return array all (including trashed or inactive) message template group objects for the given messenger
92
-     */
93
-    public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC')
94
-    {
95
-        return $this->get_all_deleted_and_undeleted(
96
-            array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) )
97
-        );
98
-    }
99
-
100
-
101
-    /**
102
-     * This simply adds on any messenger/message type filters that may be present in the request
103
-     *
104
-     * @param array $_where any existing where conditions to append these to.
105
-     * @return array          original where conditions or original with additional filters.
106
-     */
107
-    protected function _maybe_mtp_filters($_where = array())
108
-    {
109
-        /** @var RequestInterface $request */
110
-        $request   = LoaderFactory::getLoader()->getShared(RequestInterface::class);
111
-        $messenger = $request->getRequestParam('ee_messenger_filter_by');
112
-        // account for messenger or message type filters
113
-        if ($messenger !== '' && $messenger !== 'none_selected' && $messenger !== 'all') {
114
-            $_where['MTP_messenger'] = $messenger;
115
-        }
116
-        $message_type = $request->getRequestParam('ee_message_type_filter_by');
117
-        if (
118
-            $message_type !== '' && $message_type !== 'none_selected'
119
-        ) {
120
-            $_where['MTP_message_type'] = $message_type;
121
-        }
122
-
123
-        return $_where;
124
-    }
125
-
126
-
127
-
128
-    /**
129
-     * get_all_active_message_templates groups
130
-     *
131
-     * @access public
132
-     * @param string $orderby
133
-     * @param string $order
134
-     * @param null   $limit
135
-     * @param bool   $count
136
-     * @param bool   $global
137
-     * @param bool   $user_check
138
-     * @return array all active (non_trashed, active) message template objects
139
-     */
140
-    public function get_all_active_message_templates(
141
-        $orderby = 'GRP_ID',
142
-        $order = 'ASC',
143
-        $limit = null,
144
-        $count = false,
145
-        $global = true,
146
-        $user_check = false
147
-    ) {
148
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
149
-        $_where['MTP_is_active'] = true;
150
-        $_where = $this->_maybe_mtp_filters($_where);
151
-
152
-        if (
153
-            $user_check
154
-            && ! $global
155
-            && ! EE_Registry::instance()->CAP->current_user_can(
156
-                'ee_read_others_messages',
157
-                'get_all_active_message_templates'
158
-            )
159
-        ) {
160
-            $_where['MTP_user_id'] = get_current_user_id();
161
-        }
162
-
163
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
164
-
165
-        return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     *    retrieve ALL message_template groups from db regardless of wht
172
-     *
173
-     * @access    public
174
-     * @param string $orderby
175
-     * @param string $order
176
-     * @param null   $limit
177
-     * @param bool   $count
178
-     * @return mixed array on success, FALSE on fail
179
-     */
180
-    public function get_all_message_templates($orderby = 'GRP_ID', $order = 'ASC', $limit = null, $count = false)
181
-    {
182
-        $_where = $this->_maybe_mtp_filters();
183
-
184
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
185
-
186
-        $r_templates = $count
187
-            ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true)
188
-            : $this->get_all_deleted_and_undeleted($query_params);
189
-
190
-        return $r_templates;
191
-    }
192
-
193
-
194
-
195
-
196
-    /**
197
-     * This gets all the custom templates attached to a specific event
198
-     * @param  int      $EVT_ID         event id
199
-     * @param  array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
200
-     * @return  EE_Message_Template_Group[]
201
-     */
202
-    public function get_all_custom_templates_by_event($EVT_ID, $query_params = array())
203
-    {
204
-        $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID ));
205
-        return $this->get_all(
206
-            array( $where )
207
-        );
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     * get_all_trashed_grouped_message_templates
214
-     * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed
215
-     *
216
-     * @access public
217
-     * @param string $orderby
218
-     * @param string $order
219
-     * @param null   $limit
220
-     * @param bool   $count
221
-     * @param bool   $global
222
-     * @return \EE_Message_Template_Group[] message template groups.
223
-     */
224
-    public function get_all_trashed_grouped_message_templates(
225
-        $orderby = 'GRP_ID',
226
-        $order = 'ASC',
227
-        $limit = null,
228
-        $count = false,
229
-        $global = true
230
-    ) {
231
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
232
-        $_where['MTP_is_active'] = true;
233
-        $_where = $this->_maybe_mtp_filters($_where);
234
-
235
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
236
-
237
-        return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
238
-    }
239
-
240
-
241
-
242
-    /**
243
-     * this returns the message template group(s) for a given event, messenger, and message template
244
-     *
245
-     * @param  string             $messenger
246
-     * @param  string             $message_type
247
-     * @param                     $evt_id
248
-     * @param  string             $orderby pointless at this point but still included
249
-     * @param  string             $order
250
-     * @param  mixed (array|null) $limit   array($offset, $num)
251
-     * @param  bool               $count   true = just return count, false = objects
252
-     * @param  bool               $active  ignore "active" or not. (default only return active)
253
-     * @return \mixed[]) depending on $count.
254
-     */
255
-    public function get_event_message_templates_by_m_and_mt_and_evt(
256
-        $messenger,
257
-        $message_type,
258
-        $evt_id,
259
-        $orderby = 'GRP_ID',
260
-        $order = 'ASC',
261
-        $limit = null,
262
-        $count = false,
263
-        $active = true
264
-    ) {
265
-        $_where = array(
266
-            'MTP_messenger' => $messenger,
267
-            'MTP_message_type' => $message_type,
268
-            'Event.EVT_ID' => $evt_id,
269
-            'MTP_is_global' => true,
270
-            'MTP_is_active' => $active
271
-        );
272
-
273
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
274
-
275
-        return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
276
-    }
277
-
278
-
279
-
280
-
281
-    /**
282
-     * get all GLOBAL message template groups for the given messenger and message type
283
-     *
284
-     * @param  string $messenger    slug for messenger
285
-     * @param  string $message_type slug for message type
286
-     * @param  string $orderby      what column to orderby
287
-     * @param  string $order        ASC or DESC
288
-     * @param  mixed (array|null) $limit array($offset, $num)
289
-     * @param  bool   $count        true = just return count, false = objects
290
-     * @param  bool   $active       ignore "active" or not. (default only return active) -
291
-     *                              'all' means return both inactive AND inactive.
292
-     * @return array               message template objects that are global (i.e. non-event)
293
-     */
294
-    public function get_global_message_template_by_m_and_mt(
295
-        $messenger,
296
-        $message_type,
297
-        $orderby = 'GRP_ID',
298
-        $order = 'ASC',
299
-        $limit = null,
300
-        $count = false,
301
-        $active = true
302
-    ) {
303
-        $_where = array(
304
-            'MTP_messenger' => $messenger,
305
-            'MTP_message_type' => $message_type,
306
-            'MTP_is_global' => true,
307
-        );
308
-
309
-        if ($active != 'all') {
310
-            $_where['MTP_is_active'] = $active;
311
-        }
312
-
313
-        $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
314
-
315
-        return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
316
-    }
317
-
318
-
319
-
320
-
321
-    /**
322
-     * get all custom message template groups for the given messenger and message type
323
-     * @param  string $messenger    messenger
324
-     * @param  string $message_type messagetype
325
-     * @param  array  $query_params same as EEM_Base->get_all()
326
-     * @return EE_Message_Template_Group[]
327
-     */
328
-    public function get_custom_message_template_by_m_and_mt($messenger, $message_type, $query_params = array())
329
-    {
330
-        return $this->get_all(
331
-            array_merge(
332
-                $query_params,
333
-                array(
334
-                    array(
335
-                        'MTP_is_global'    => false,
336
-                        'MTP_messenger'    => $messenger,
337
-                        'MTP_message_type' => $message_type
338
-                    )
339
-                )
340
-            )
341
-        );
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * This sends things to the validator for the given messenger and message type.
348
-     *
349
-     * @param  array $fields the incoming fields to check.
350
-     *                       Note this array is in the formatted fields from the form fields setup.
351
-     *                       So we need to reformat this into an array of expected field refs by the validator.
352
-     *                       Note also that this is not only the fields for the Message Template Group
353
-     *                       but ALSO for Message Template.
354
-     * @param string $context      The context the fields were obtained from.
355
-     * @param string $messenger    The messenger we are validating
356
-     * @param string $message_type The message type we are validating.
357
-     * @return mixed If the fields all check out then we return true otherwise error messages are returned
358
-     *                       (indexed by field name);
359
-     * @throws \EE_Error
360
-     */
361
-    public function validate($fields, $context, $messenger, $message_type)
362
-    {
363
-
364
-        $assembled_fields = array();
365
-
366
-        // let's loop through all the fields and set them up in the right format
367
-        foreach ($fields as $index => $value) {
368
-            // first let's figure out if the value['content'] in the current index is an array.
369
-            //  If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list').
370
-            if (is_array($value['content'])) {
371
-                $assembled_fields[ $value['name'] ] = $value['content']['main'];
372
-                // loop through the content and get the other fields.
373
-                foreach ($value['content'] as $name => $val) {
374
-                    if ($name == 'main') {
375
-                        continue;
376
-                    }
377
-                    $assembled_fields[ $name ] = $val;
378
-                }
379
-                continue;
380
-            }
381
-
382
-            // okay if we're here then this is just a straight field=>$value arrangement
383
-            $assembled_fields[ $value['name'] ] = $value['content'];
384
-        }
385
-
386
-        // now we've got the assembled_fields.
387
-        // We need to setup the string for the appropriate validator class and call that.
388
-        $m_ref = ucwords(str_replace('_', ' ', $messenger));
389
-        $m_ref = str_replace(' ', '_', $m_ref);
390
-        $mt_ref = ucwords(str_replace('_', ' ', $message_type));
391
-        $mt_ref = str_replace(' ', '_', $mt_ref);
392
-
393
-        $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator';
394
-
395
-        if (!class_exists($classname)) {
396
-            $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
397
-            $msg[] = sprintf(
398
-                esc_html__(
399
-                    'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class',
400
-                    'event_espresso'
401
-                ),
402
-                $classname
403
-            );
404
-            throw new EE_Error(implode('||', $msg));
405
-        }
406
-
407
-        $a = new ReflectionClass($classname);
408
-        $_VLD = $a->newInstance($assembled_fields, $context);
409
-        $result = $_VLD->validate();
410
-        return $result;
411
-    }
412
-
413
-
414
-
415
-    /**
416
-     * Updates all message template groups matching the incoming arguments to inactive status.
417
-     *
418
-     * @param array $messenger_names    The messenger slugs.
419
-     *                              If empty then all templates matching the message types are marked inactive.
420
-     *                              Otherwise only templates matching the messengers and message types.
421
-     * @param array $message_type_names     The message type slugs.
422
-     *                              If empty then all templates matching the messengers are marked inactive.
423
-     *                              Otherwise only templates matching the messengers and message types.
424
-     *
425
-     * @return int  count of updated records.
426
-     */
427
-    public function deactivate_message_template_groups_for($messenger_names = array(), $message_type_names = array())
428
-    {
429
-        $query_args = array();
430
-        if (empty($messenger_names) && empty($message_type_names)) {
431
-            return 0;
432
-        }
433
-        if (! empty($messenger_names)) {
434
-            $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names );
435
-        }
436
-        if (! empty($message_type_names)) {
437
-            $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names );
438
-        }
439
-        return $this->update(array( 'MTP_is_active' => false ), $query_args);
440
-    }
18
+	// private instance of the EEM_Message_Template_Group object
19
+	protected static $_instance = null;
20
+
21
+
22
+
23
+	protected function __construct($timezone = null)
24
+	{
25
+		$this->singular_item = esc_html__('Message Template Group', 'event_espresso');
26
+		$this->plural_item = esc_html__('Message Template Groups', 'event_espresso');
27
+		$this->_tables = array(
28
+			'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID')
29
+		);
30
+		$this->_fields = array(
31
+			'Message_Template_Group' => array(
32
+				'GRP_ID' => new EE_Primary_Key_Int_Field('GRP_ID', esc_html__('Message Template Group ID', 'event_espresso')),
33
+				'MTP_name' => new EE_Plain_Text_Field('MTP_name', esc_html__('The name of the template group', 'event_espresso'), false, ''),
34
+				'MTP_description' => new EE_Simple_HTML_Field('MTP_description', esc_html__('A brief description about this template.', 'event_espresso'), false, ''),
35
+				'MTP_user_id' => new EE_WP_User_Field('MTP_user_id', esc_html__('Template Creator ID', 'event_espresso'), false, get_current_user_id()),
36
+				'MTP_messenger' => new EE_Plain_Text_Field('MTP_messenger', esc_html__('Messenger Used for Template', 'event_espresso'), false, 'email'),
37
+				'MTP_message_type' => new EE_Plain_Text_Field('MTP_message_type', esc_html__('Message Type', 'event_espresso'), false, 'registration'),
38
+				'MTP_is_global' => new EE_Boolean_Field('MTP_is_global', esc_html__('Flag indicating if Template Group is Global', 'event_espresso'), false, true),
39
+				'MTP_is_override' => new EE_Boolean_Field('MTP_is_override', esc_html__('Flag indicating if Template Group overrides any other Templates for the messenger/messagetype combination', 'event_espresso'), false, false),
40
+				'MTP_deleted' => new EE_Trashed_Flag_Field('MTP_deleted', esc_html__('Flag indicating whether this has been trashed', 'event_espresso'), false, false),
41
+				'MTP_is_active' => new EE_Boolean_Field('MTP_is_active', esc_html__('Flag indicating whether template group is active', 'event_espresso'), false, true)
42
+			)
43
+		);
44
+		$this->_model_relations = array(
45
+			'Message_Template' => new EE_Has_Many_Relation(),
46
+			'Message' => new EE_Has_Many_Relation(),
47
+			'Event' => new EE_HABTM_Relation('Event_Message_Template'),
48
+			'WP_User' => new EE_Belongs_To_Relation()
49
+		);
50
+		foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
51
+			$this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global');
52
+		}
53
+		$this->_caps_slug = 'messages';
54
+
55
+		parent::__construct($timezone);
56
+	}
57
+
58
+
59
+
60
+	/**
61
+	 * get_all_trashed_message_templates_by_event
62
+	 *
63
+	 * @access public
64
+	 * @param int    $EVT_ID specific event id
65
+	 * @param string $orderby
66
+	 * @param string $order
67
+	 * @param null   $limit
68
+	 * @param bool   $count
69
+	 * @return array message template objects that are attached to a specific event.
70
+	 */
71
+	public function get_all_trashed_message_templates_by_event(
72
+		$EVT_ID,
73
+		$orderby = 'GRP_ID',
74
+		$order = 'ASC',
75
+		$limit = null,
76
+		$count = false
77
+	) {
78
+		$query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit );
79
+		return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
80
+	}
81
+
82
+
83
+
84
+	/**
85
+	 * get_all_message_templates_by_messenger
86
+	 *
87
+	 * @access public
88
+	 * @param        $messenger
89
+	 * @param string $orderby
90
+	 * @param string $order
91
+	 * @return array all (including trashed or inactive) message template group objects for the given messenger
92
+	 */
93
+	public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC')
94
+	{
95
+		return $this->get_all_deleted_and_undeleted(
96
+			array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) )
97
+		);
98
+	}
99
+
100
+
101
+	/**
102
+	 * This simply adds on any messenger/message type filters that may be present in the request
103
+	 *
104
+	 * @param array $_where any existing where conditions to append these to.
105
+	 * @return array          original where conditions or original with additional filters.
106
+	 */
107
+	protected function _maybe_mtp_filters($_where = array())
108
+	{
109
+		/** @var RequestInterface $request */
110
+		$request   = LoaderFactory::getLoader()->getShared(RequestInterface::class);
111
+		$messenger = $request->getRequestParam('ee_messenger_filter_by');
112
+		// account for messenger or message type filters
113
+		if ($messenger !== '' && $messenger !== 'none_selected' && $messenger !== 'all') {
114
+			$_where['MTP_messenger'] = $messenger;
115
+		}
116
+		$message_type = $request->getRequestParam('ee_message_type_filter_by');
117
+		if (
118
+			$message_type !== '' && $message_type !== 'none_selected'
119
+		) {
120
+			$_where['MTP_message_type'] = $message_type;
121
+		}
122
+
123
+		return $_where;
124
+	}
125
+
126
+
127
+
128
+	/**
129
+	 * get_all_active_message_templates groups
130
+	 *
131
+	 * @access public
132
+	 * @param string $orderby
133
+	 * @param string $order
134
+	 * @param null   $limit
135
+	 * @param bool   $count
136
+	 * @param bool   $global
137
+	 * @param bool   $user_check
138
+	 * @return array all active (non_trashed, active) message template objects
139
+	 */
140
+	public function get_all_active_message_templates(
141
+		$orderby = 'GRP_ID',
142
+		$order = 'ASC',
143
+		$limit = null,
144
+		$count = false,
145
+		$global = true,
146
+		$user_check = false
147
+	) {
148
+		$_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
149
+		$_where['MTP_is_active'] = true;
150
+		$_where = $this->_maybe_mtp_filters($_where);
151
+
152
+		if (
153
+			$user_check
154
+			&& ! $global
155
+			&& ! EE_Registry::instance()->CAP->current_user_can(
156
+				'ee_read_others_messages',
157
+				'get_all_active_message_templates'
158
+			)
159
+		) {
160
+			$_where['MTP_user_id'] = get_current_user_id();
161
+		}
162
+
163
+		$query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
164
+
165
+		return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 *    retrieve ALL message_template groups from db regardless of wht
172
+	 *
173
+	 * @access    public
174
+	 * @param string $orderby
175
+	 * @param string $order
176
+	 * @param null   $limit
177
+	 * @param bool   $count
178
+	 * @return mixed array on success, FALSE on fail
179
+	 */
180
+	public function get_all_message_templates($orderby = 'GRP_ID', $order = 'ASC', $limit = null, $count = false)
181
+	{
182
+		$_where = $this->_maybe_mtp_filters();
183
+
184
+		$query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
185
+
186
+		$r_templates = $count
187
+			? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true)
188
+			: $this->get_all_deleted_and_undeleted($query_params);
189
+
190
+		return $r_templates;
191
+	}
192
+
193
+
194
+
195
+
196
+	/**
197
+	 * This gets all the custom templates attached to a specific event
198
+	 * @param  int      $EVT_ID         event id
199
+	 * @param  array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
200
+	 * @return  EE_Message_Template_Group[]
201
+	 */
202
+	public function get_all_custom_templates_by_event($EVT_ID, $query_params = array())
203
+	{
204
+		$where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID ));
205
+		return $this->get_all(
206
+			array( $where )
207
+		);
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 * get_all_trashed_grouped_message_templates
214
+	 * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed
215
+	 *
216
+	 * @access public
217
+	 * @param string $orderby
218
+	 * @param string $order
219
+	 * @param null   $limit
220
+	 * @param bool   $count
221
+	 * @param bool   $global
222
+	 * @return \EE_Message_Template_Group[] message template groups.
223
+	 */
224
+	public function get_all_trashed_grouped_message_templates(
225
+		$orderby = 'GRP_ID',
226
+		$order = 'ASC',
227
+		$limit = null,
228
+		$count = false,
229
+		$global = true
230
+	) {
231
+		$_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
232
+		$_where['MTP_is_active'] = true;
233
+		$_where = $this->_maybe_mtp_filters($_where);
234
+
235
+		$query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
236
+
237
+		return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
238
+	}
239
+
240
+
241
+
242
+	/**
243
+	 * this returns the message template group(s) for a given event, messenger, and message template
244
+	 *
245
+	 * @param  string             $messenger
246
+	 * @param  string             $message_type
247
+	 * @param                     $evt_id
248
+	 * @param  string             $orderby pointless at this point but still included
249
+	 * @param  string             $order
250
+	 * @param  mixed (array|null) $limit   array($offset, $num)
251
+	 * @param  bool               $count   true = just return count, false = objects
252
+	 * @param  bool               $active  ignore "active" or not. (default only return active)
253
+	 * @return \mixed[]) depending on $count.
254
+	 */
255
+	public function get_event_message_templates_by_m_and_mt_and_evt(
256
+		$messenger,
257
+		$message_type,
258
+		$evt_id,
259
+		$orderby = 'GRP_ID',
260
+		$order = 'ASC',
261
+		$limit = null,
262
+		$count = false,
263
+		$active = true
264
+	) {
265
+		$_where = array(
266
+			'MTP_messenger' => $messenger,
267
+			'MTP_message_type' => $message_type,
268
+			'Event.EVT_ID' => $evt_id,
269
+			'MTP_is_global' => true,
270
+			'MTP_is_active' => $active
271
+		);
272
+
273
+		$query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
274
+
275
+		return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
276
+	}
277
+
278
+
279
+
280
+
281
+	/**
282
+	 * get all GLOBAL message template groups for the given messenger and message type
283
+	 *
284
+	 * @param  string $messenger    slug for messenger
285
+	 * @param  string $message_type slug for message type
286
+	 * @param  string $orderby      what column to orderby
287
+	 * @param  string $order        ASC or DESC
288
+	 * @param  mixed (array|null) $limit array($offset, $num)
289
+	 * @param  bool   $count        true = just return count, false = objects
290
+	 * @param  bool   $active       ignore "active" or not. (default only return active) -
291
+	 *                              'all' means return both inactive AND inactive.
292
+	 * @return array               message template objects that are global (i.e. non-event)
293
+	 */
294
+	public function get_global_message_template_by_m_and_mt(
295
+		$messenger,
296
+		$message_type,
297
+		$orderby = 'GRP_ID',
298
+		$order = 'ASC',
299
+		$limit = null,
300
+		$count = false,
301
+		$active = true
302
+	) {
303
+		$_where = array(
304
+			'MTP_messenger' => $messenger,
305
+			'MTP_message_type' => $message_type,
306
+			'MTP_is_global' => true,
307
+		);
308
+
309
+		if ($active != 'all') {
310
+			$_where['MTP_is_active'] = $active;
311
+		}
312
+
313
+		$query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
314
+
315
+		return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
316
+	}
317
+
318
+
319
+
320
+
321
+	/**
322
+	 * get all custom message template groups for the given messenger and message type
323
+	 * @param  string $messenger    messenger
324
+	 * @param  string $message_type messagetype
325
+	 * @param  array  $query_params same as EEM_Base->get_all()
326
+	 * @return EE_Message_Template_Group[]
327
+	 */
328
+	public function get_custom_message_template_by_m_and_mt($messenger, $message_type, $query_params = array())
329
+	{
330
+		return $this->get_all(
331
+			array_merge(
332
+				$query_params,
333
+				array(
334
+					array(
335
+						'MTP_is_global'    => false,
336
+						'MTP_messenger'    => $messenger,
337
+						'MTP_message_type' => $message_type
338
+					)
339
+				)
340
+			)
341
+		);
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * This sends things to the validator for the given messenger and message type.
348
+	 *
349
+	 * @param  array $fields the incoming fields to check.
350
+	 *                       Note this array is in the formatted fields from the form fields setup.
351
+	 *                       So we need to reformat this into an array of expected field refs by the validator.
352
+	 *                       Note also that this is not only the fields for the Message Template Group
353
+	 *                       but ALSO for Message Template.
354
+	 * @param string $context      The context the fields were obtained from.
355
+	 * @param string $messenger    The messenger we are validating
356
+	 * @param string $message_type The message type we are validating.
357
+	 * @return mixed If the fields all check out then we return true otherwise error messages are returned
358
+	 *                       (indexed by field name);
359
+	 * @throws \EE_Error
360
+	 */
361
+	public function validate($fields, $context, $messenger, $message_type)
362
+	{
363
+
364
+		$assembled_fields = array();
365
+
366
+		// let's loop through all the fields and set them up in the right format
367
+		foreach ($fields as $index => $value) {
368
+			// first let's figure out if the value['content'] in the current index is an array.
369
+			//  If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list').
370
+			if (is_array($value['content'])) {
371
+				$assembled_fields[ $value['name'] ] = $value['content']['main'];
372
+				// loop through the content and get the other fields.
373
+				foreach ($value['content'] as $name => $val) {
374
+					if ($name == 'main') {
375
+						continue;
376
+					}
377
+					$assembled_fields[ $name ] = $val;
378
+				}
379
+				continue;
380
+			}
381
+
382
+			// okay if we're here then this is just a straight field=>$value arrangement
383
+			$assembled_fields[ $value['name'] ] = $value['content'];
384
+		}
385
+
386
+		// now we've got the assembled_fields.
387
+		// We need to setup the string for the appropriate validator class and call that.
388
+		$m_ref = ucwords(str_replace('_', ' ', $messenger));
389
+		$m_ref = str_replace(' ', '_', $m_ref);
390
+		$mt_ref = ucwords(str_replace('_', ' ', $message_type));
391
+		$mt_ref = str_replace(' ', '_', $mt_ref);
392
+
393
+		$classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator';
394
+
395
+		if (!class_exists($classname)) {
396
+			$msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
397
+			$msg[] = sprintf(
398
+				esc_html__(
399
+					'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class',
400
+					'event_espresso'
401
+				),
402
+				$classname
403
+			);
404
+			throw new EE_Error(implode('||', $msg));
405
+		}
406
+
407
+		$a = new ReflectionClass($classname);
408
+		$_VLD = $a->newInstance($assembled_fields, $context);
409
+		$result = $_VLD->validate();
410
+		return $result;
411
+	}
412
+
413
+
414
+
415
+	/**
416
+	 * Updates all message template groups matching the incoming arguments to inactive status.
417
+	 *
418
+	 * @param array $messenger_names    The messenger slugs.
419
+	 *                              If empty then all templates matching the message types are marked inactive.
420
+	 *                              Otherwise only templates matching the messengers and message types.
421
+	 * @param array $message_type_names     The message type slugs.
422
+	 *                              If empty then all templates matching the messengers are marked inactive.
423
+	 *                              Otherwise only templates matching the messengers and message types.
424
+	 *
425
+	 * @return int  count of updated records.
426
+	 */
427
+	public function deactivate_message_template_groups_for($messenger_names = array(), $message_type_names = array())
428
+	{
429
+		$query_args = array();
430
+		if (empty($messenger_names) && empty($message_type_names)) {
431
+			return 0;
432
+		}
433
+		if (! empty($messenger_names)) {
434
+			$query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names );
435
+		}
436
+		if (! empty($message_type_names)) {
437
+			$query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names );
438
+		}
439
+		return $this->update(array( 'MTP_is_active' => false ), $query_args);
440
+	}
441 441
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
             'WP_User' => new EE_Belongs_To_Relation()
49 49
         );
50 50
         foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
51
-            $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global');
51
+            $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_Global('MTP_is_global');
52 52
         }
53 53
         $this->_caps_slug = 'messages';
54 54
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
         $limit = null,
76 76
         $count = false
77 77
     ) {
78
-        $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit );
78
+        $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit);
79 79
         return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
80 80
     }
81 81
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
     public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC')
94 94
     {
95 95
         return $this->get_all_deleted_and_undeleted(
96
-            array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) )
96
+            array(array('MTP_messenger' => $messenger), 'order_by' => array($orderby => $order))
97 97
         );
98 98
     }
99 99
 
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
         $global = true,
146 146
         $user_check = false
147 147
     ) {
148
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
148
+        $_where = $global ? array('MTP_is_global' => true) : array('MTP_is_global' => false);
149 149
         $_where['MTP_is_active'] = true;
150 150
         $_where = $this->_maybe_mtp_filters($_where);
151 151
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
             $_where['MTP_user_id'] = get_current_user_id();
161 161
         }
162 162
 
163
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
163
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
164 164
 
165 165
         return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
166 166
     }
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
     {
182 182
         $_where = $this->_maybe_mtp_filters();
183 183
 
184
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
184
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
185 185
 
186 186
         $r_templates = $count
187 187
             ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true)
@@ -201,9 +201,9 @@  discard block
 block discarded – undo
201 201
      */
202 202
     public function get_all_custom_templates_by_event($EVT_ID, $query_params = array())
203 203
     {
204
-        $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID ));
204
+        $where = array_merge($query_params, array('Event.EVT_ID' => $EVT_ID));
205 205
         return $this->get_all(
206
-            array( $where )
206
+            array($where)
207 207
         );
208 208
     }
209 209
 
@@ -228,11 +228,11 @@  discard block
 block discarded – undo
228 228
         $count = false,
229 229
         $global = true
230 230
     ) {
231
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
231
+        $_where = $global ? array('MTP_is_global' => true) : array('MTP_is_global' => false);
232 232
         $_where['MTP_is_active'] = true;
233 233
         $_where = $this->_maybe_mtp_filters($_where);
234 234
 
235
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
235
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
236 236
 
237 237
         return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
238 238
     }
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
             'MTP_is_active' => $active
271 271
         );
272 272
 
273
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
273
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
274 274
 
275 275
         return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
276 276
     }
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
             $_where['MTP_is_active'] = $active;
311 311
         }
312 312
 
313
-        $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
313
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
314 314
 
315 315
         return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
316 316
     }
@@ -368,19 +368,19 @@  discard block
 block discarded – undo
368 368
             // first let's figure out if the value['content'] in the current index is an array.
369 369
             //  If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list').
370 370
             if (is_array($value['content'])) {
371
-                $assembled_fields[ $value['name'] ] = $value['content']['main'];
371
+                $assembled_fields[$value['name']] = $value['content']['main'];
372 372
                 // loop through the content and get the other fields.
373 373
                 foreach ($value['content'] as $name => $val) {
374 374
                     if ($name == 'main') {
375 375
                         continue;
376 376
                     }
377
-                    $assembled_fields[ $name ] = $val;
377
+                    $assembled_fields[$name] = $val;
378 378
                 }
379 379
                 continue;
380 380
             }
381 381
 
382 382
             // okay if we're here then this is just a straight field=>$value arrangement
383
-            $assembled_fields[ $value['name'] ] = $value['content'];
383
+            $assembled_fields[$value['name']] = $value['content'];
384 384
         }
385 385
 
386 386
         // now we've got the assembled_fields.
@@ -390,9 +390,9 @@  discard block
 block discarded – undo
390 390
         $mt_ref = ucwords(str_replace('_', ' ', $message_type));
391 391
         $mt_ref = str_replace(' ', '_', $mt_ref);
392 392
 
393
-        $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator';
393
+        $classname = 'EE_Messages_'.$m_ref.'_'.$mt_ref.'_Validator';
394 394
 
395
-        if (!class_exists($classname)) {
395
+        if ( ! class_exists($classname)) {
396 396
             $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
397 397
             $msg[] = sprintf(
398 398
                 esc_html__(
@@ -430,12 +430,12 @@  discard block
 block discarded – undo
430 430
         if (empty($messenger_names) && empty($message_type_names)) {
431 431
             return 0;
432 432
         }
433
-        if (! empty($messenger_names)) {
434
-            $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names );
433
+        if ( ! empty($messenger_names)) {
434
+            $query_args[0]['MTP_messenger'] = array('IN', (array) $messenger_names);
435 435
         }
436
-        if (! empty($message_type_names)) {
437
-            $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names );
436
+        if ( ! empty($message_type_names)) {
437
+            $query_args[0]['MTP_message_type'] = array('IN', (array) $message_type_names);
438 438
         }
439
-        return $this->update(array( 'MTP_is_active' => false ), $query_args);
439
+        return $this->update(array('MTP_is_active' => false), $query_args);
440 440
     }
441 441
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Datetime_Field.php 2 patches
Indentation   +752 added lines, -752 removed lines patch added patch discarded remove patch
@@ -16,757 +16,757 @@
 block discarded – undo
16 16
 class EE_Datetime_Field extends EE_Model_Field_Base
17 17
 {
18 18
 
19
-    /**
20
-     * The pattern we're looking for is if only the characters 0-9 are found and there are only
21
-     * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
22
-     *
23
-     * @type string unix_timestamp_regex
24
-     */
25
-    const unix_timestamp_regex = '/[0-9]{10,}/';
26
-
27
-    /**
28
-     * @type string mysql_timestamp_format
29
-     */
30
-    const mysql_timestamp_format = 'Y-m-d H:i:s';
31
-
32
-    /**
33
-     * @type string mysql_date_format
34
-     */
35
-    const mysql_date_format = 'Y-m-d';
36
-
37
-    /**
38
-     * @type string mysql_time_format
39
-     */
40
-    const mysql_time_format = 'H:i:s';
41
-
42
-    /**
43
-     * Const for using in the default value. If the field's default is set to this,
44
-     * then we will return the time of calling `get_default_value()`, not
45
-     * just the current time at construction
46
-     */
47
-    const now = 'now';
48
-
49
-    /**
50
-     * The following properties hold the default formats for date and time.
51
-     * Defaults are set via the constructor and can be overridden on class instantiation.
52
-     * However they can also be overridden later by the set_format() method
53
-     * (and corresponding set_date_format, set_time_format methods);
54
-     */
55
-    /**
56
-     * @type string $_date_format
57
-     */
58
-    protected $_date_format = '';
59
-
60
-    /**
61
-     * @type string $_time_format
62
-     */
63
-    protected $_time_format = '';
64
-
65
-    /**
66
-     * @type string $_pretty_date_format
67
-     */
68
-    protected $_pretty_date_format = '';
69
-
70
-    /**
71
-     * @type string $_pretty_time_format
72
-     */
73
-    protected $_pretty_time_format = '';
74
-
75
-    /**
76
-     * @type DateTimeZone $_DateTimeZone
77
-     */
78
-    protected $_DateTimeZone;
79
-
80
-    /**
81
-     * @type DateTimeZone $_UTC_DateTimeZone
82
-     */
83
-    protected $_UTC_DateTimeZone;
84
-
85
-    /**
86
-     * @type DateTimeZone $_blog_DateTimeZone
87
-     */
88
-    protected $_blog_DateTimeZone;
89
-
90
-
91
-    /**
92
-     * This property holds how we want the output returned when getting a datetime string.  It is set for the
93
-     * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
94
-     * and time returned via getters.
95
-     *
96
-     * @var mixed (null|string)
97
-     */
98
-    protected $_date_time_output;
99
-
100
-
101
-    /**
102
-     * timezone string
103
-     * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
104
-     * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
105
-     * coming out of the object to be in.  Default timezone is the current WP timezone option setting
106
-     *
107
-     * @var string
108
-     */
109
-    protected $_timezone_string;
110
-
111
-
112
-    /**
113
-     * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
114
-     * offsets for comparison purposes).
115
-     *
116
-     * @var int
117
-     */
118
-    protected $_blog_offset;
119
-
120
-
121
-
122
-    /**
123
-     * @param string $table_column
124
-     * @param string $nice_name
125
-     * @param bool   $nullable
126
-     * @param string $default_value
127
-     * @param string $timezone_string
128
-     * @param string $date_format
129
-     * @param string $time_format
130
-     * @param string $pretty_date_format
131
-     * @param string $pretty_time_format
132
-     * @throws EE_Error
133
-     * @throws InvalidArgumentException
134
-     */
135
-    public function __construct(
136
-        $table_column,
137
-        $nice_name,
138
-        $nullable,
139
-        $default_value,
140
-        $timezone_string = '',
141
-        $date_format = '',
142
-        $time_format = '',
143
-        $pretty_date_format = '',
144
-        $pretty_time_format = ''
145
-    ) {
146
-
147
-        $this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
148
-        $this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
149
-        $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
150
-        $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
151
-
152
-        parent::__construct($table_column, $nice_name, $nullable, $default_value);
153
-        $this->set_timezone($timezone_string);
154
-        $this->setSchemaFormat('date-time');
155
-    }
156
-
157
-
158
-    /**
159
-     * @return DateTimeZone
160
-     * @throws \EE_Error
161
-     */
162
-    public function get_UTC_DateTimeZone()
163
-    {
164
-        return $this->_UTC_DateTimeZone instanceof DateTimeZone
165
-            ? $this->_UTC_DateTimeZone
166
-            : $this->_create_timezone_object_from_timezone_string('UTC');
167
-    }
168
-
169
-
170
-    /**
171
-     * @return DateTimeZone
172
-     * @throws \EE_Error
173
-     */
174
-    public function get_blog_DateTimeZone()
175
-    {
176
-        return $this->_blog_DateTimeZone instanceof DateTimeZone
177
-            ? $this->_blog_DateTimeZone
178
-            : $this->_create_timezone_object_from_timezone_string('');
179
-    }
180
-
181
-
182
-    /**
183
-     * this prepares any incoming date data and make sure its converted to a utc unix timestamp
184
-     *
185
-     * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
186
-     *                                                              timestamp
187
-     * @return DateTime
188
-     */
189
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
190
-    {
191
-        return $this->_get_date_object($value_inputted_for_field_on_model_object);
192
-    }
193
-
194
-
195
-    /**
196
-     * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
197
-     * getters need to know whether we're just returning the date or the time or both.  By default we return both.
198
-     *
199
-     * @param bool $pretty If we're returning the pretty formats or standard format string.
200
-     * @return string    The final assembled format string.
201
-     */
202
-    protected function _get_date_time_output($pretty = false)
203
-    {
204
-
205
-        switch ($this->_date_time_output) {
206
-            case 'time':
207
-                return $pretty ? $this->_pretty_time_format : $this->_time_format;
208
-                break;
209
-
210
-            case 'date':
211
-                return $pretty ? $this->_pretty_date_format : $this->_date_format;
212
-                break;
213
-
214
-            default:
215
-                return $pretty
216
-                    ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
217
-                    : $this->_date_format . ' ' . $this->_time_format;
218
-        }
219
-    }
220
-
221
-
222
-    /**
223
-     * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
224
-     * returned (using the format properties)
225
-     *
226
-     * @param string $what acceptable values are 'time' or 'date'.
227
-     *                     Any other value will be set but will always result
228
-     *                     in both 'date' and 'time' being returned.
229
-     * @return void
230
-     */
231
-    public function set_date_time_output($what = null)
232
-    {
233
-        $this->_date_time_output = $what;
234
-    }
235
-
236
-
237
-    /**
238
-     * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
239
-     * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
240
-     * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
241
-     * We also set some other properties in this method.
242
-     *
243
-     * @param string $timezone_string A valid timezone string as described by @link
244
-     *                                http://www.php.net/manual/en/timezones.php
245
-     * @return void
246
-     * @throws InvalidArgumentException
247
-     * @throws InvalidDataTypeException
248
-     * @throws InvalidInterfaceException
249
-     */
250
-    public function set_timezone($timezone_string)
251
-    {
252
-        if (empty($timezone_string) && $this->_timezone_string !== null) {
253
-            // leave the timezone AS-IS if we already have one and
254
-            // the function arg didn't provide one
255
-            return;
256
-        }
257
-        $timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
258
-        $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
259
-        $this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
260
-    }
261
-
262
-
263
-    /**
264
-     * _create_timezone_object_from_timezone_name
265
-     *
266
-     * @access protected
267
-     * @param string $timezone_string
268
-     * @return \DateTimeZone
269
-     * @throws InvalidArgumentException
270
-     * @throws InvalidDataTypeException
271
-     * @throws InvalidInterfaceException
272
-     */
273
-    protected function _create_timezone_object_from_timezone_string($timezone_string = '')
274
-    {
275
-        return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
276
-    }
277
-
278
-
279
-    /**
280
-     * This just returns whatever is set for the current timezone.
281
-     *
282
-     * @access public
283
-     * @return string timezone string
284
-     */
285
-    public function get_timezone()
286
-    {
287
-        return $this->_timezone_string;
288
-    }
289
-
290
-
291
-    /**
292
-     * set the $_date_format property
293
-     *
294
-     * @access public
295
-     * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
296
-     * @param bool   $pretty Whether to set pretty format or not.
297
-     * @return void
298
-     */
299
-    public function set_date_format($format, $pretty = false)
300
-    {
301
-        if ($pretty) {
302
-            $this->_pretty_date_format = $format;
303
-        } else {
304
-            $this->_date_format = $format;
305
-        }
306
-    }
307
-
308
-
309
-    /**
310
-     * return the $_date_format property value.
311
-     *
312
-     * @param bool $pretty Whether to get pretty format or not.
313
-     * @return string
314
-     */
315
-    public function get_date_format($pretty = false)
316
-    {
317
-        return $pretty ? $this->_pretty_date_format : $this->_date_format;
318
-    }
319
-
320
-
321
-    /**
322
-     * set the $_time_format property
323
-     *
324
-     * @access public
325
-     * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
326
-     * @param bool   $pretty Whether to set pretty format or not.
327
-     * @return void
328
-     */
329
-    public function set_time_format($format, $pretty = false)
330
-    {
331
-        if ($pretty) {
332
-            $this->_pretty_time_format = $format;
333
-        } else {
334
-            $this->_time_format = $format;
335
-        }
336
-    }
337
-
338
-
339
-    /**
340
-     * return the $_time_format property value.
341
-     *
342
-     * @param bool $pretty Whether to get pretty format or not.
343
-     * @return string
344
-     */
345
-    public function get_time_format($pretty = false)
346
-    {
347
-        return $pretty ? $this->_pretty_time_format : $this->_time_format;
348
-    }
349
-
350
-
351
-    /**
352
-     * set the $_pretty_date_format property
353
-     *
354
-     * @access public
355
-     * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
356
-     * @return void
357
-     */
358
-    public function set_pretty_date_format($format)
359
-    {
360
-        $this->_pretty_date_format = $format;
361
-    }
362
-
363
-
364
-    /**
365
-     * set the $_pretty_time_format property
366
-     *
367
-     * @access public
368
-     * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
369
-     * @return void
370
-     */
371
-    public function set_pretty_time_format($format)
372
-    {
373
-        $this->_pretty_time_format = $format;
374
-    }
375
-
376
-
377
-    /**
378
-     * Only sets the time portion of the datetime.
379
-     *
380
-     * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
381
-     * @param DateTime        $current            current DateTime object for the datetime field
382
-     * @return DateTime
383
-     */
384
-    public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
385
-    {
386
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
387
-        // Otherwise parse the string.
388
-        if ($time_to_set_string instanceof DateTime) {
389
-            $parsed = array(
390
-                'hour'   => $time_to_set_string->format('H'),
391
-                'minute' => $time_to_set_string->format('i'),
392
-                'second' => $time_to_set_string->format('s'),
393
-            );
394
-        } else {
395
-            // parse incoming string
396
-            $parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
397
-        }
398
-        EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone);
399
-        return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
400
-    }
401
-
402
-
403
-    /**
404
-     * Only sets the date portion of the datetime.
405
-     *
406
-     * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
407
-     * @param DateTime        $current            current DateTime object for the datetime field
408
-     * @return DateTime
409
-     */
410
-    public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
411
-    {
412
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
413
-        // Otherwise parse the string.
414
-        if ($date_to_set_string instanceof DateTime) {
415
-            $parsed = array(
416
-                'year'  => $date_to_set_string->format('Y'),
417
-                'month' => $date_to_set_string->format('m'),
418
-                'day'   => $date_to_set_string->format('d'),
419
-            );
420
-        } else {
421
-            // parse incoming string
422
-            $parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
423
-        }
424
-        EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone);
425
-        return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
426
-    }
427
-
428
-
429
-    /**
430
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
431
-     * datetime gets to this stage it should ALREADY be in UTC time
432
-     *
433
-     * @param  DateTime $DateTime
434
-     * @return string formatted date time for given timezone
435
-     * @throws \EE_Error
436
-     */
437
-    public function prepare_for_get($DateTime)
438
-    {
439
-        return $this->_prepare_for_display($DateTime);
440
-    }
441
-
442
-
443
-    /**
444
-     * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
445
-     * from the set wp timezone.  If so, then it returns the datetime string formatted via
446
-     * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
447
-     * abbreviation to the date_string.
448
-     *
449
-     * @param mixed $DateTime
450
-     * @param null  $schema
451
-     * @return string
452
-     * @throws \EE_Error
453
-     */
454
-    public function prepare_for_pretty_echoing($DateTime, $schema = null)
455
-    {
456
-        return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
457
-    }
458
-
459
-
460
-    /**
461
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
462
-     * timezone).
463
-     *
464
-     * @param DateTime    $DateTime
465
-     * @param bool|string $schema
466
-     * @return string
467
-     * @throws \EE_Error
468
-     */
469
-    protected function _prepare_for_display($DateTime, $schema = false)
470
-    {
471
-        if (! $DateTime instanceof DateTime) {
472
-            if ($this->_nullable) {
473
-                return '';
474
-            } else {
475
-                if (WP_DEBUG) {
476
-                    throw new EE_Error(
477
-                        sprintf(
478
-                            esc_html__(
479
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
480
-                                'event_espresso'
481
-                            ),
482
-                            $this->_nicename
483
-                        )
484
-                    );
485
-                } else {
486
-                    $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
487
-                    EE_Error::add_error(
488
-                        sprintf(
489
-                            esc_html__(
490
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
491
-                                'event_espresso'
492
-                            ),
493
-                            $this->_nicename
494
-                        )
495
-                    );
496
-                }
497
-            }
498
-        }
499
-        $format_string = $this->_get_date_time_output($schema);
500
-        EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone);
501
-        if ($schema) {
502
-            if ($this->_display_timezone()) {
503
-                // must be explicit because schema could equal true.
504
-                if ($schema === 'no_html') {
505
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
506
-                } else {
507
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
508
-                }
509
-            } else {
510
-                $timezone_string = '';
511
-            }
512
-
513
-            return $DateTime->format($format_string) . $timezone_string;
514
-        }
515
-        return $DateTime->format($format_string);
516
-    }
517
-
518
-
519
-    /**
520
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
521
-     * timezone).
522
-     *
523
-     * @param  mixed $datetime_value u
524
-     * @return string mysql timestamp in UTC
525
-     * @throws \EE_Error
526
-     */
527
-    public function prepare_for_use_in_db($datetime_value)
528
-    {
529
-        // we allow an empty value or DateTime object, but nothing else.
530
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
531
-            throw new EE_Error(
532
-                sprintf(
533
-                    esc_html__(
534
-                        'The incoming value being prepared for setting in the database must either be empty or a php 
19
+	/**
20
+	 * The pattern we're looking for is if only the characters 0-9 are found and there are only
21
+	 * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
22
+	 *
23
+	 * @type string unix_timestamp_regex
24
+	 */
25
+	const unix_timestamp_regex = '/[0-9]{10,}/';
26
+
27
+	/**
28
+	 * @type string mysql_timestamp_format
29
+	 */
30
+	const mysql_timestamp_format = 'Y-m-d H:i:s';
31
+
32
+	/**
33
+	 * @type string mysql_date_format
34
+	 */
35
+	const mysql_date_format = 'Y-m-d';
36
+
37
+	/**
38
+	 * @type string mysql_time_format
39
+	 */
40
+	const mysql_time_format = 'H:i:s';
41
+
42
+	/**
43
+	 * Const for using in the default value. If the field's default is set to this,
44
+	 * then we will return the time of calling `get_default_value()`, not
45
+	 * just the current time at construction
46
+	 */
47
+	const now = 'now';
48
+
49
+	/**
50
+	 * The following properties hold the default formats for date and time.
51
+	 * Defaults are set via the constructor and can be overridden on class instantiation.
52
+	 * However they can also be overridden later by the set_format() method
53
+	 * (and corresponding set_date_format, set_time_format methods);
54
+	 */
55
+	/**
56
+	 * @type string $_date_format
57
+	 */
58
+	protected $_date_format = '';
59
+
60
+	/**
61
+	 * @type string $_time_format
62
+	 */
63
+	protected $_time_format = '';
64
+
65
+	/**
66
+	 * @type string $_pretty_date_format
67
+	 */
68
+	protected $_pretty_date_format = '';
69
+
70
+	/**
71
+	 * @type string $_pretty_time_format
72
+	 */
73
+	protected $_pretty_time_format = '';
74
+
75
+	/**
76
+	 * @type DateTimeZone $_DateTimeZone
77
+	 */
78
+	protected $_DateTimeZone;
79
+
80
+	/**
81
+	 * @type DateTimeZone $_UTC_DateTimeZone
82
+	 */
83
+	protected $_UTC_DateTimeZone;
84
+
85
+	/**
86
+	 * @type DateTimeZone $_blog_DateTimeZone
87
+	 */
88
+	protected $_blog_DateTimeZone;
89
+
90
+
91
+	/**
92
+	 * This property holds how we want the output returned when getting a datetime string.  It is set for the
93
+	 * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
94
+	 * and time returned via getters.
95
+	 *
96
+	 * @var mixed (null|string)
97
+	 */
98
+	protected $_date_time_output;
99
+
100
+
101
+	/**
102
+	 * timezone string
103
+	 * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
104
+	 * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
105
+	 * coming out of the object to be in.  Default timezone is the current WP timezone option setting
106
+	 *
107
+	 * @var string
108
+	 */
109
+	protected $_timezone_string;
110
+
111
+
112
+	/**
113
+	 * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
114
+	 * offsets for comparison purposes).
115
+	 *
116
+	 * @var int
117
+	 */
118
+	protected $_blog_offset;
119
+
120
+
121
+
122
+	/**
123
+	 * @param string $table_column
124
+	 * @param string $nice_name
125
+	 * @param bool   $nullable
126
+	 * @param string $default_value
127
+	 * @param string $timezone_string
128
+	 * @param string $date_format
129
+	 * @param string $time_format
130
+	 * @param string $pretty_date_format
131
+	 * @param string $pretty_time_format
132
+	 * @throws EE_Error
133
+	 * @throws InvalidArgumentException
134
+	 */
135
+	public function __construct(
136
+		$table_column,
137
+		$nice_name,
138
+		$nullable,
139
+		$default_value,
140
+		$timezone_string = '',
141
+		$date_format = '',
142
+		$time_format = '',
143
+		$pretty_date_format = '',
144
+		$pretty_time_format = ''
145
+	) {
146
+
147
+		$this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
148
+		$this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
149
+		$this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
150
+		$this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
151
+
152
+		parent::__construct($table_column, $nice_name, $nullable, $default_value);
153
+		$this->set_timezone($timezone_string);
154
+		$this->setSchemaFormat('date-time');
155
+	}
156
+
157
+
158
+	/**
159
+	 * @return DateTimeZone
160
+	 * @throws \EE_Error
161
+	 */
162
+	public function get_UTC_DateTimeZone()
163
+	{
164
+		return $this->_UTC_DateTimeZone instanceof DateTimeZone
165
+			? $this->_UTC_DateTimeZone
166
+			: $this->_create_timezone_object_from_timezone_string('UTC');
167
+	}
168
+
169
+
170
+	/**
171
+	 * @return DateTimeZone
172
+	 * @throws \EE_Error
173
+	 */
174
+	public function get_blog_DateTimeZone()
175
+	{
176
+		return $this->_blog_DateTimeZone instanceof DateTimeZone
177
+			? $this->_blog_DateTimeZone
178
+			: $this->_create_timezone_object_from_timezone_string('');
179
+	}
180
+
181
+
182
+	/**
183
+	 * this prepares any incoming date data and make sure its converted to a utc unix timestamp
184
+	 *
185
+	 * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
186
+	 *                                                              timestamp
187
+	 * @return DateTime
188
+	 */
189
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
190
+	{
191
+		return $this->_get_date_object($value_inputted_for_field_on_model_object);
192
+	}
193
+
194
+
195
+	/**
196
+	 * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
197
+	 * getters need to know whether we're just returning the date or the time or both.  By default we return both.
198
+	 *
199
+	 * @param bool $pretty If we're returning the pretty formats or standard format string.
200
+	 * @return string    The final assembled format string.
201
+	 */
202
+	protected function _get_date_time_output($pretty = false)
203
+	{
204
+
205
+		switch ($this->_date_time_output) {
206
+			case 'time':
207
+				return $pretty ? $this->_pretty_time_format : $this->_time_format;
208
+				break;
209
+
210
+			case 'date':
211
+				return $pretty ? $this->_pretty_date_format : $this->_date_format;
212
+				break;
213
+
214
+			default:
215
+				return $pretty
216
+					? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
217
+					: $this->_date_format . ' ' . $this->_time_format;
218
+		}
219
+	}
220
+
221
+
222
+	/**
223
+	 * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
224
+	 * returned (using the format properties)
225
+	 *
226
+	 * @param string $what acceptable values are 'time' or 'date'.
227
+	 *                     Any other value will be set but will always result
228
+	 *                     in both 'date' and 'time' being returned.
229
+	 * @return void
230
+	 */
231
+	public function set_date_time_output($what = null)
232
+	{
233
+		$this->_date_time_output = $what;
234
+	}
235
+
236
+
237
+	/**
238
+	 * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
239
+	 * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
240
+	 * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
241
+	 * We also set some other properties in this method.
242
+	 *
243
+	 * @param string $timezone_string A valid timezone string as described by @link
244
+	 *                                http://www.php.net/manual/en/timezones.php
245
+	 * @return void
246
+	 * @throws InvalidArgumentException
247
+	 * @throws InvalidDataTypeException
248
+	 * @throws InvalidInterfaceException
249
+	 */
250
+	public function set_timezone($timezone_string)
251
+	{
252
+		if (empty($timezone_string) && $this->_timezone_string !== null) {
253
+			// leave the timezone AS-IS if we already have one and
254
+			// the function arg didn't provide one
255
+			return;
256
+		}
257
+		$timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
258
+		$this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
259
+		$this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
260
+	}
261
+
262
+
263
+	/**
264
+	 * _create_timezone_object_from_timezone_name
265
+	 *
266
+	 * @access protected
267
+	 * @param string $timezone_string
268
+	 * @return \DateTimeZone
269
+	 * @throws InvalidArgumentException
270
+	 * @throws InvalidDataTypeException
271
+	 * @throws InvalidInterfaceException
272
+	 */
273
+	protected function _create_timezone_object_from_timezone_string($timezone_string = '')
274
+	{
275
+		return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
276
+	}
277
+
278
+
279
+	/**
280
+	 * This just returns whatever is set for the current timezone.
281
+	 *
282
+	 * @access public
283
+	 * @return string timezone string
284
+	 */
285
+	public function get_timezone()
286
+	{
287
+		return $this->_timezone_string;
288
+	}
289
+
290
+
291
+	/**
292
+	 * set the $_date_format property
293
+	 *
294
+	 * @access public
295
+	 * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
296
+	 * @param bool   $pretty Whether to set pretty format or not.
297
+	 * @return void
298
+	 */
299
+	public function set_date_format($format, $pretty = false)
300
+	{
301
+		if ($pretty) {
302
+			$this->_pretty_date_format = $format;
303
+		} else {
304
+			$this->_date_format = $format;
305
+		}
306
+	}
307
+
308
+
309
+	/**
310
+	 * return the $_date_format property value.
311
+	 *
312
+	 * @param bool $pretty Whether to get pretty format or not.
313
+	 * @return string
314
+	 */
315
+	public function get_date_format($pretty = false)
316
+	{
317
+		return $pretty ? $this->_pretty_date_format : $this->_date_format;
318
+	}
319
+
320
+
321
+	/**
322
+	 * set the $_time_format property
323
+	 *
324
+	 * @access public
325
+	 * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
326
+	 * @param bool   $pretty Whether to set pretty format or not.
327
+	 * @return void
328
+	 */
329
+	public function set_time_format($format, $pretty = false)
330
+	{
331
+		if ($pretty) {
332
+			$this->_pretty_time_format = $format;
333
+		} else {
334
+			$this->_time_format = $format;
335
+		}
336
+	}
337
+
338
+
339
+	/**
340
+	 * return the $_time_format property value.
341
+	 *
342
+	 * @param bool $pretty Whether to get pretty format or not.
343
+	 * @return string
344
+	 */
345
+	public function get_time_format($pretty = false)
346
+	{
347
+		return $pretty ? $this->_pretty_time_format : $this->_time_format;
348
+	}
349
+
350
+
351
+	/**
352
+	 * set the $_pretty_date_format property
353
+	 *
354
+	 * @access public
355
+	 * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
356
+	 * @return void
357
+	 */
358
+	public function set_pretty_date_format($format)
359
+	{
360
+		$this->_pretty_date_format = $format;
361
+	}
362
+
363
+
364
+	/**
365
+	 * set the $_pretty_time_format property
366
+	 *
367
+	 * @access public
368
+	 * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
369
+	 * @return void
370
+	 */
371
+	public function set_pretty_time_format($format)
372
+	{
373
+		$this->_pretty_time_format = $format;
374
+	}
375
+
376
+
377
+	/**
378
+	 * Only sets the time portion of the datetime.
379
+	 *
380
+	 * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
381
+	 * @param DateTime        $current            current DateTime object for the datetime field
382
+	 * @return DateTime
383
+	 */
384
+	public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
385
+	{
386
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
387
+		// Otherwise parse the string.
388
+		if ($time_to_set_string instanceof DateTime) {
389
+			$parsed = array(
390
+				'hour'   => $time_to_set_string->format('H'),
391
+				'minute' => $time_to_set_string->format('i'),
392
+				'second' => $time_to_set_string->format('s'),
393
+			);
394
+		} else {
395
+			// parse incoming string
396
+			$parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
397
+		}
398
+		EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone);
399
+		return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
400
+	}
401
+
402
+
403
+	/**
404
+	 * Only sets the date portion of the datetime.
405
+	 *
406
+	 * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
407
+	 * @param DateTime        $current            current DateTime object for the datetime field
408
+	 * @return DateTime
409
+	 */
410
+	public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
411
+	{
412
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
413
+		// Otherwise parse the string.
414
+		if ($date_to_set_string instanceof DateTime) {
415
+			$parsed = array(
416
+				'year'  => $date_to_set_string->format('Y'),
417
+				'month' => $date_to_set_string->format('m'),
418
+				'day'   => $date_to_set_string->format('d'),
419
+			);
420
+		} else {
421
+			// parse incoming string
422
+			$parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
423
+		}
424
+		EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone);
425
+		return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
426
+	}
427
+
428
+
429
+	/**
430
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
431
+	 * datetime gets to this stage it should ALREADY be in UTC time
432
+	 *
433
+	 * @param  DateTime $DateTime
434
+	 * @return string formatted date time for given timezone
435
+	 * @throws \EE_Error
436
+	 */
437
+	public function prepare_for_get($DateTime)
438
+	{
439
+		return $this->_prepare_for_display($DateTime);
440
+	}
441
+
442
+
443
+	/**
444
+	 * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
445
+	 * from the set wp timezone.  If so, then it returns the datetime string formatted via
446
+	 * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
447
+	 * abbreviation to the date_string.
448
+	 *
449
+	 * @param mixed $DateTime
450
+	 * @param null  $schema
451
+	 * @return string
452
+	 * @throws \EE_Error
453
+	 */
454
+	public function prepare_for_pretty_echoing($DateTime, $schema = null)
455
+	{
456
+		return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
457
+	}
458
+
459
+
460
+	/**
461
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
462
+	 * timezone).
463
+	 *
464
+	 * @param DateTime    $DateTime
465
+	 * @param bool|string $schema
466
+	 * @return string
467
+	 * @throws \EE_Error
468
+	 */
469
+	protected function _prepare_for_display($DateTime, $schema = false)
470
+	{
471
+		if (! $DateTime instanceof DateTime) {
472
+			if ($this->_nullable) {
473
+				return '';
474
+			} else {
475
+				if (WP_DEBUG) {
476
+					throw new EE_Error(
477
+						sprintf(
478
+							esc_html__(
479
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
480
+								'event_espresso'
481
+							),
482
+							$this->_nicename
483
+						)
484
+					);
485
+				} else {
486
+					$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
487
+					EE_Error::add_error(
488
+						sprintf(
489
+							esc_html__(
490
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
491
+								'event_espresso'
492
+							),
493
+							$this->_nicename
494
+						)
495
+					);
496
+				}
497
+			}
498
+		}
499
+		$format_string = $this->_get_date_time_output($schema);
500
+		EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone);
501
+		if ($schema) {
502
+			if ($this->_display_timezone()) {
503
+				// must be explicit because schema could equal true.
504
+				if ($schema === 'no_html') {
505
+					$timezone_string = ' (' . $DateTime->format('T') . ')';
506
+				} else {
507
+					$timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
508
+				}
509
+			} else {
510
+				$timezone_string = '';
511
+			}
512
+
513
+			return $DateTime->format($format_string) . $timezone_string;
514
+		}
515
+		return $DateTime->format($format_string);
516
+	}
517
+
518
+
519
+	/**
520
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
521
+	 * timezone).
522
+	 *
523
+	 * @param  mixed $datetime_value u
524
+	 * @return string mysql timestamp in UTC
525
+	 * @throws \EE_Error
526
+	 */
527
+	public function prepare_for_use_in_db($datetime_value)
528
+	{
529
+		// we allow an empty value or DateTime object, but nothing else.
530
+		if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
531
+			throw new EE_Error(
532
+				sprintf(
533
+					esc_html__(
534
+						'The incoming value being prepared for setting in the database must either be empty or a php 
535 535
             		    DateTime object, instead of: %1$s %2$s',
536
-                        'event_espresso'
537
-                    ),
538
-                    '<br />',
539
-                    print_r($datetime_value, true)
540
-                )
541
-            );
542
-        }
543
-
544
-        if ($datetime_value instanceof DateTime) {
545
-            if (! $datetime_value instanceof DbSafeDateTime) {
546
-                $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
547
-            }
548
-            EEH_DTT_Helper::setTimezone($datetime_value, $this->get_UTC_DateTimeZone());
549
-            return $datetime_value->format(
550
-                EE_Datetime_Field::mysql_timestamp_format
551
-            );
552
-        }
553
-
554
-        // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
555
-        return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
556
-    }
557
-
558
-
559
-    /**
560
-     * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
561
-     * allowed)
562
-     *
563
-     * @param string $datetime_string mysql timestamp in UTC
564
-     * @return  mixed null | DateTime
565
-     * @throws \EE_Error
566
-     */
567
-    public function prepare_for_set_from_db($datetime_string)
568
-    {
569
-        // if $datetime_value is empty, and ! $this->_nullable, just use time()
570
-        if (empty($datetime_string) && $this->_nullable) {
571
-            return null;
572
-        }
573
-        // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
574
-        if (empty($datetime_string)) {
575
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
576
-        } else {
577
-            $DateTime = DbSafeDateTime::createFromFormat(
578
-                EE_Datetime_Field::mysql_timestamp_format,
579
-                $datetime_string,
580
-                $this->get_UTC_DateTimeZone()
581
-            );
582
-        }
583
-
584
-        if (! $DateTime instanceof DbSafeDateTime) {
585
-            // if still no datetime object, then let's just use now
586
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
587
-        }
588
-        // THEN apply the field's set DateTimeZone
589
-        EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone);
590
-        return $DateTime;
591
-    }
592
-
593
-
594
-    /**
595
-     * All this method does is determine if we're going to display the timezone string or not on any output.
596
-     * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
597
-     * If so, then true.
598
-     *
599
-     * @return bool true for yes false for no
600
-     * @throws \EE_Error
601
-     */
602
-    protected function _display_timezone()
603
-    {
604
-
605
-        // first let's do a comparison of timezone strings.
606
-        // If they match then we can get out without any further calculations
607
-        $blog_string = get_option('timezone_string');
608
-        if ($blog_string === $this->_timezone_string) {
609
-            return false;
610
-        }
611
-        // now we need to calc the offset for the timezone string so we can compare with the blog offset.
612
-        $this_offset = $this->get_timezone_offset($this->_DateTimeZone);
613
-        $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
614
-        // now compare
615
-        return $blog_offset !== $this_offset;
616
-    }
617
-
618
-
619
-    /**
620
-     * This method returns a php DateTime object for setting on the EE_Base_Class model.
621
-     * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
622
-     * with.
623
-     *
624
-     * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
625
-     *                                                    in the format that is set on the date_field (or DateTime
626
-     *                                                    object)!
627
-     * @return DateTime
628
-     */
629
-    protected function _get_date_object($date_string)
630
-    {
631
-        // first if this is an empty date_string and nullable is allowed, just return null.
632
-        if ($this->_nullable && empty($date_string)) {
633
-            return null;
634
-        }
635
-
636
-        // if incoming date
637
-        if ($date_string instanceof DateTime) {
638
-            EEH_DTT_Helper::setTimezone($date_string, $this->_DateTimeZone);
639
-            return $date_string;
640
-        }
641
-        // if empty date_string and made it here.
642
-        // Return a datetime object for now in the given timezone.
643
-        if (empty($date_string)) {
644
-            return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
645
-        }
646
-        // if $date_string is matches something that looks like a Unix timestamp let's just use it.
647
-        if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
648
-            try {
649
-                // This is operating under the assumption that the incoming Unix timestamp
650
-                // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
651
-                $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
652
-                $DateTime->setTimestamp($date_string);
653
-
654
-                return $DateTime;
655
-            } catch (Exception $e) {
656
-                // should be rare, but if things got fooled then let's just continue
657
-            }
658
-        }
659
-        // not a unix timestamp.  So we will use the set format on this object and set timezone to
660
-        // create the DateTime object.
661
-        $format = $this->_date_format . ' ' . $this->_time_format;
662
-        try {
663
-            $DateTime = DbSafeDateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
664
-            if (! $DateTime instanceof DbSafeDateTime) {
665
-                throw new EE_Error(
666
-                    sprintf(
667
-                        esc_html__('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
668
-                        $date_string,
669
-                        $format
670
-                    )
671
-                );
672
-            }
673
-        } catch (Exception $e) {
674
-            // if we made it here then likely then something went really wrong.
675
-            // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
676
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
677
-        }
678
-
679
-        return $DateTime;
680
-    }
681
-
682
-
683
-
684
-    /**
685
-     * get_timezone_transitions
686
-     *
687
-     * @param \DateTimeZone $DateTimeZone
688
-     * @param int           $time
689
-     * @param bool          $first_only
690
-     * @return mixed
691
-     */
692
-    public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
693
-    {
694
-        return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only);
695
-    }
696
-
697
-
698
-
699
-    /**
700
-     * get_timezone_offset
701
-     *
702
-     * @param \DateTimeZone $DateTimeZone
703
-     * @param int           $time
704
-     * @return mixed
705
-     * @throws \DomainException
706
-     */
707
-    public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
708
-    {
709
-        return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time);
710
-    }
711
-
712
-
713
-    /**
714
-     * This will take an incoming timezone string and return the abbreviation for that timezone
715
-     *
716
-     * @param  string $timezone_string
717
-     * @return string           abbreviation
718
-     * @throws \EE_Error
719
-     */
720
-    public function get_timezone_abbrev($timezone_string)
721
-    {
722
-        $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
723
-        $dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
724
-
725
-        return $dateTime->format('T');
726
-    }
727
-
728
-    /**
729
-     * Overrides the parent to allow for having a dynamic "now" value
730
-     *
731
-     * @return mixed
732
-     */
733
-    public function get_default_value()
734
-    {
735
-        if ($this->_default_value === EE_Datetime_Field::now) {
736
-            return time();
737
-        } else {
738
-            return parent::get_default_value();
739
-        }
740
-    }
741
-
742
-    /**
743
-     * Gets the default datetime object from the field's default time
744
-     * @since 4.9.66.p
745
-     * @return DbSafeDateTime|null
746
-     * @throws InvalidArgumentException
747
-     * @throws InvalidDataTypeException
748
-     * @throws InvalidInterfaceException
749
-     */
750
-    public function getDefaultDateTimeObj()
751
-    {
752
-        $default_raw = $this->get_default_value();
753
-        if ($default_raw instanceof DateTime) {
754
-            return $default_raw;
755
-        } elseif (is_null($default_raw)) {
756
-            return $default_raw;
757
-        } else {
758
-            return new DbSafeDateTime(
759
-                $this->get_default_value(),
760
-                EEH_DTT_Helper::get_valid_timezone_string($this->get_timezone())
761
-            );
762
-        }
763
-    }
764
-
765
-    public function getSchemaDescription()
766
-    {
767
-        return sprintf(
768
-            esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
769
-            $this->get_nicename()
770
-        );
771
-    }
536
+						'event_espresso'
537
+					),
538
+					'<br />',
539
+					print_r($datetime_value, true)
540
+				)
541
+			);
542
+		}
543
+
544
+		if ($datetime_value instanceof DateTime) {
545
+			if (! $datetime_value instanceof DbSafeDateTime) {
546
+				$datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
547
+			}
548
+			EEH_DTT_Helper::setTimezone($datetime_value, $this->get_UTC_DateTimeZone());
549
+			return $datetime_value->format(
550
+				EE_Datetime_Field::mysql_timestamp_format
551
+			);
552
+		}
553
+
554
+		// if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
555
+		return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
556
+	}
557
+
558
+
559
+	/**
560
+	 * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
561
+	 * allowed)
562
+	 *
563
+	 * @param string $datetime_string mysql timestamp in UTC
564
+	 * @return  mixed null | DateTime
565
+	 * @throws \EE_Error
566
+	 */
567
+	public function prepare_for_set_from_db($datetime_string)
568
+	{
569
+		// if $datetime_value is empty, and ! $this->_nullable, just use time()
570
+		if (empty($datetime_string) && $this->_nullable) {
571
+			return null;
572
+		}
573
+		// datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
574
+		if (empty($datetime_string)) {
575
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
576
+		} else {
577
+			$DateTime = DbSafeDateTime::createFromFormat(
578
+				EE_Datetime_Field::mysql_timestamp_format,
579
+				$datetime_string,
580
+				$this->get_UTC_DateTimeZone()
581
+			);
582
+		}
583
+
584
+		if (! $DateTime instanceof DbSafeDateTime) {
585
+			// if still no datetime object, then let's just use now
586
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
587
+		}
588
+		// THEN apply the field's set DateTimeZone
589
+		EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone);
590
+		return $DateTime;
591
+	}
592
+
593
+
594
+	/**
595
+	 * All this method does is determine if we're going to display the timezone string or not on any output.
596
+	 * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
597
+	 * If so, then true.
598
+	 *
599
+	 * @return bool true for yes false for no
600
+	 * @throws \EE_Error
601
+	 */
602
+	protected function _display_timezone()
603
+	{
604
+
605
+		// first let's do a comparison of timezone strings.
606
+		// If they match then we can get out without any further calculations
607
+		$blog_string = get_option('timezone_string');
608
+		if ($blog_string === $this->_timezone_string) {
609
+			return false;
610
+		}
611
+		// now we need to calc the offset for the timezone string so we can compare with the blog offset.
612
+		$this_offset = $this->get_timezone_offset($this->_DateTimeZone);
613
+		$blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
614
+		// now compare
615
+		return $blog_offset !== $this_offset;
616
+	}
617
+
618
+
619
+	/**
620
+	 * This method returns a php DateTime object for setting on the EE_Base_Class model.
621
+	 * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
622
+	 * with.
623
+	 *
624
+	 * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
625
+	 *                                                    in the format that is set on the date_field (or DateTime
626
+	 *                                                    object)!
627
+	 * @return DateTime
628
+	 */
629
+	protected function _get_date_object($date_string)
630
+	{
631
+		// first if this is an empty date_string and nullable is allowed, just return null.
632
+		if ($this->_nullable && empty($date_string)) {
633
+			return null;
634
+		}
635
+
636
+		// if incoming date
637
+		if ($date_string instanceof DateTime) {
638
+			EEH_DTT_Helper::setTimezone($date_string, $this->_DateTimeZone);
639
+			return $date_string;
640
+		}
641
+		// if empty date_string and made it here.
642
+		// Return a datetime object for now in the given timezone.
643
+		if (empty($date_string)) {
644
+			return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
645
+		}
646
+		// if $date_string is matches something that looks like a Unix timestamp let's just use it.
647
+		if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
648
+			try {
649
+				// This is operating under the assumption that the incoming Unix timestamp
650
+				// is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
651
+				$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
652
+				$DateTime->setTimestamp($date_string);
653
+
654
+				return $DateTime;
655
+			} catch (Exception $e) {
656
+				// should be rare, but if things got fooled then let's just continue
657
+			}
658
+		}
659
+		// not a unix timestamp.  So we will use the set format on this object and set timezone to
660
+		// create the DateTime object.
661
+		$format = $this->_date_format . ' ' . $this->_time_format;
662
+		try {
663
+			$DateTime = DbSafeDateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
664
+			if (! $DateTime instanceof DbSafeDateTime) {
665
+				throw new EE_Error(
666
+					sprintf(
667
+						esc_html__('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
668
+						$date_string,
669
+						$format
670
+					)
671
+				);
672
+			}
673
+		} catch (Exception $e) {
674
+			// if we made it here then likely then something went really wrong.
675
+			// Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
676
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
677
+		}
678
+
679
+		return $DateTime;
680
+	}
681
+
682
+
683
+
684
+	/**
685
+	 * get_timezone_transitions
686
+	 *
687
+	 * @param \DateTimeZone $DateTimeZone
688
+	 * @param int           $time
689
+	 * @param bool          $first_only
690
+	 * @return mixed
691
+	 */
692
+	public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
693
+	{
694
+		return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only);
695
+	}
696
+
697
+
698
+
699
+	/**
700
+	 * get_timezone_offset
701
+	 *
702
+	 * @param \DateTimeZone $DateTimeZone
703
+	 * @param int           $time
704
+	 * @return mixed
705
+	 * @throws \DomainException
706
+	 */
707
+	public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
708
+	{
709
+		return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time);
710
+	}
711
+
712
+
713
+	/**
714
+	 * This will take an incoming timezone string and return the abbreviation for that timezone
715
+	 *
716
+	 * @param  string $timezone_string
717
+	 * @return string           abbreviation
718
+	 * @throws \EE_Error
719
+	 */
720
+	public function get_timezone_abbrev($timezone_string)
721
+	{
722
+		$timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
723
+		$dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
724
+
725
+		return $dateTime->format('T');
726
+	}
727
+
728
+	/**
729
+	 * Overrides the parent to allow for having a dynamic "now" value
730
+	 *
731
+	 * @return mixed
732
+	 */
733
+	public function get_default_value()
734
+	{
735
+		if ($this->_default_value === EE_Datetime_Field::now) {
736
+			return time();
737
+		} else {
738
+			return parent::get_default_value();
739
+		}
740
+	}
741
+
742
+	/**
743
+	 * Gets the default datetime object from the field's default time
744
+	 * @since 4.9.66.p
745
+	 * @return DbSafeDateTime|null
746
+	 * @throws InvalidArgumentException
747
+	 * @throws InvalidDataTypeException
748
+	 * @throws InvalidInterfaceException
749
+	 */
750
+	public function getDefaultDateTimeObj()
751
+	{
752
+		$default_raw = $this->get_default_value();
753
+		if ($default_raw instanceof DateTime) {
754
+			return $default_raw;
755
+		} elseif (is_null($default_raw)) {
756
+			return $default_raw;
757
+		} else {
758
+			return new DbSafeDateTime(
759
+				$this->get_default_value(),
760
+				EEH_DTT_Helper::get_valid_timezone_string($this->get_timezone())
761
+			);
762
+		}
763
+	}
764
+
765
+	public function getSchemaDescription()
766
+	{
767
+		return sprintf(
768
+			esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
769
+			$this->get_nicename()
770
+		);
771
+	}
772 772
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -213,8 +213,8 @@  discard block
 block discarded – undo
213 213
 
214 214
             default:
215 215
                 return $pretty
216
-                    ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
217
-                    : $this->_date_format . ' ' . $this->_time_format;
216
+                    ? $this->_pretty_date_format.' '.$this->_pretty_time_format
217
+                    : $this->_date_format.' '.$this->_time_format;
218 218
         }
219 219
     }
220 220
 
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
      */
469 469
     protected function _prepare_for_display($DateTime, $schema = false)
470 470
     {
471
-        if (! $DateTime instanceof DateTime) {
471
+        if ( ! $DateTime instanceof DateTime) {
472 472
             if ($this->_nullable) {
473 473
                 return '';
474 474
             } else {
@@ -502,15 +502,15 @@  discard block
 block discarded – undo
502 502
             if ($this->_display_timezone()) {
503 503
                 // must be explicit because schema could equal true.
504 504
                 if ($schema === 'no_html') {
505
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
505
+                    $timezone_string = ' ('.$DateTime->format('T').')';
506 506
                 } else {
507
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
507
+                    $timezone_string = ' <span class="ee_dtt_timezone_string">('.$DateTime->format('T').')</span>';
508 508
                 }
509 509
             } else {
510 510
                 $timezone_string = '';
511 511
             }
512 512
 
513
-            return $DateTime->format($format_string) . $timezone_string;
513
+            return $DateTime->format($format_string).$timezone_string;
514 514
         }
515 515
         return $DateTime->format($format_string);
516 516
     }
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
     public function prepare_for_use_in_db($datetime_value)
528 528
     {
529 529
         // we allow an empty value or DateTime object, but nothing else.
530
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
530
+        if ( ! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
531 531
             throw new EE_Error(
532 532
                 sprintf(
533 533
                     esc_html__(
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
         }
543 543
 
544 544
         if ($datetime_value instanceof DateTime) {
545
-            if (! $datetime_value instanceof DbSafeDateTime) {
545
+            if ( ! $datetime_value instanceof DbSafeDateTime) {
546 546
                 $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
547 547
             }
548 548
             EEH_DTT_Helper::setTimezone($datetime_value, $this->get_UTC_DateTimeZone());
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
             );
582 582
         }
583 583
 
584
-        if (! $DateTime instanceof DbSafeDateTime) {
584
+        if ( ! $DateTime instanceof DbSafeDateTime) {
585 585
             // if still no datetime object, then let's just use now
586 586
             $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
587 587
         }
@@ -658,10 +658,10 @@  discard block
 block discarded – undo
658 658
         }
659 659
         // not a unix timestamp.  So we will use the set format on this object and set timezone to
660 660
         // create the DateTime object.
661
-        $format = $this->_date_format . ' ' . $this->_time_format;
661
+        $format = $this->_date_format.' '.$this->_time_format;
662 662
         try {
663 663
             $DateTime = DbSafeDateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
664
-            if (! $DateTime instanceof DbSafeDateTime) {
664
+            if ( ! $DateTime instanceof DbSafeDateTime) {
665 665
                 throw new EE_Error(
666 666
                     sprintf(
667 667
                         esc_html__('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
Please login to merge, or discard this patch.
core/db_models/fields/EE_Foreign_Key_Int_Field.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -3,36 +3,36 @@
 block discarded – undo
3 3
 class EE_Foreign_Key_Int_Field extends EE_Foreign_Key_Field_Base
4 4
 {
5 5
 
6
-    /**
7
-     * @param string  $table_column  name fo column for field
8
-     * @param string  $nicename      should eb internationalized with esc_html__('blah','event_espresso')
9
-     * @param boolean $nullable
10
-     * @param mixed   $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul
11
-     *                               dbe a string
12
-     * @param string|string[]  $model_name    eg 'Event','Answer','Term', etc. Basically its the model class's name without the
13
-     *                               "EEM_"
14
-     */
15
-    public function __construct($table_column, $nicename, $nullable, $default_value, $model_name)
16
-    {
17
-        parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name);
18
-        $this->setSchemaType('integer');
19
-    }
6
+	/**
7
+	 * @param string  $table_column  name fo column for field
8
+	 * @param string  $nicename      should eb internationalized with esc_html__('blah','event_espresso')
9
+	 * @param boolean $nullable
10
+	 * @param mixed   $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul
11
+	 *                               dbe a string
12
+	 * @param string|string[]  $model_name    eg 'Event','Answer','Term', etc. Basically its the model class's name without the
13
+	 *                               "EEM_"
14
+	 */
15
+	public function __construct($table_column, $nicename, $nullable, $default_value, $model_name)
16
+	{
17
+		parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name);
18
+		$this->setSchemaType('integer');
19
+	}
20 20
 
21 21
 
22
-    /**
23
-     * @param int|EE_Base_Class $value_inputted_for_field_on_model_object
24
-     * @return int
25
-     */
26
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
27
-    {
28
-        if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
29
-            $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
30
-        }
31
-        return absint($value_inputted_for_field_on_model_object);
32
-    }
22
+	/**
23
+	 * @param int|EE_Base_Class $value_inputted_for_field_on_model_object
24
+	 * @return int
25
+	 */
26
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
27
+	{
28
+		if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
29
+			$value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
30
+		}
31
+		return absint($value_inputted_for_field_on_model_object);
32
+	}
33 33
 
34
-    public function prepare_for_set_from_db($value_found_in_db_for_model_object)
35
-    {
36
-        return intval($value_found_in_db_for_model_object);
37
-    }
34
+	public function prepare_for_set_from_db($value_found_in_db_for_model_object)
35
+	{
36
+		return intval($value_found_in_db_for_model_object);
37
+	}
38 38
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Boolean_Field.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -2,66 +2,66 @@
 block discarded – undo
2 2
 
3 3
 class EE_Boolean_Field extends EE_Integer_Field
4 4
 {
5
-    /**
6
-     * @param string $table_column
7
-     * @param string $nicename
8
-     * @param bool   $nullable
9
-     * @param null   $default_value
10
-     */
11
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
12
-    {
13
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
14
-        $this->setSchemaType('boolean');
15
-    }
5
+	/**
6
+	 * @param string $table_column
7
+	 * @param string $nicename
8
+	 * @param bool   $nullable
9
+	 * @param null   $default_value
10
+	 */
11
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
12
+	{
13
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
14
+		$this->setSchemaType('boolean');
15
+	}
16 16
 
17
-    /**
18
-     * Double-checks the value being returned is an boolean.
19
-     * @since 4.9.74.p
20
-     * @param mixed $value_of_field_on_model_object
21
-     * @return boolean
22
-     */
23
-    public function prepare_for_get($value_of_field_on_model_object)
24
-    {
25
-        return (bool) parent::prepare_for_get($value_of_field_on_model_object);
26
-    }
17
+	/**
18
+	 * Double-checks the value being returned is an boolean.
19
+	 * @since 4.9.74.p
20
+	 * @param mixed $value_of_field_on_model_object
21
+	 * @return boolean
22
+	 */
23
+	public function prepare_for_get($value_of_field_on_model_object)
24
+	{
25
+		return (bool) parent::prepare_for_get($value_of_field_on_model_object);
26
+	}
27 27
 
28
-    /**
29
-     * @since 4.9.74.p
30
-     * @param $value_inputted_for_field_on_model_object
31
-     * @return boolean
32
-     */
33
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
34
-    {
35
-        if ($value_inputted_for_field_on_model_object) {
36
-            return true;
37
-        } else {
38
-            return false;
39
-        }
40
-    }
28
+	/**
29
+	 * @since 4.9.74.p
30
+	 * @param $value_inputted_for_field_on_model_object
31
+	 * @return boolean
32
+	 */
33
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
34
+	{
35
+		if ($value_inputted_for_field_on_model_object) {
36
+			return true;
37
+		} else {
38
+			return false;
39
+		}
40
+	}
41 41
 
42
-    /**
43
-     * Make sure we're returning booleans
44
-     *
45
-     * @param string $value_inputted_for_field_on_model_object
46
-     * @return boolean
47
-     */
48
-    public function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
49
-    {
50
-        return intval($value_inputted_for_field_on_model_object) ? true : false;
51
-    }
42
+	/**
43
+	 * Make sure we're returning booleans
44
+	 *
45
+	 * @param string $value_inputted_for_field_on_model_object
46
+	 * @return boolean
47
+	 */
48
+	public function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
49
+	{
50
+		return intval($value_inputted_for_field_on_model_object) ? true : false;
51
+	}
52 52
 
53
-    /**
54
-     * Gets a nice Yes/No value for this field
55
-     *
56
-     * @param boolean $value_on_field_to_be_outputted
57
-     * @return string Yes or No
58
-     */
59
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
60
-    {
61
-        return apply_filters(
62
-            'FHEE__EE_Boolean_Field__prepare_for_pretty_echoing__return',
63
-            $value_on_field_to_be_outputted ? esc_html__('Yes', 'event_espresso') : esc_html__('No', 'event_espresso'),
64
-            $value_on_field_to_be_outputted
65
-        );
66
-    }
53
+	/**
54
+	 * Gets a nice Yes/No value for this field
55
+	 *
56
+	 * @param boolean $value_on_field_to_be_outputted
57
+	 * @return string Yes or No
58
+	 */
59
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
60
+	{
61
+		return apply_filters(
62
+			'FHEE__EE_Boolean_Field__prepare_for_pretty_echoing__return',
63
+			$value_on_field_to_be_outputted ? esc_html__('Yes', 'event_espresso') : esc_html__('No', 'event_espresso'),
64
+			$value_on_field_to_be_outputted
65
+		);
66
+	}
67 67
 }
Please login to merge, or discard this patch.