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