Completed
Branch FET/rest-relation-endpoints (02db8d)
by
unknown
27:05 queued 18:22
created
core/db_models/EEM_Datetime_Ticket.model.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -12,41 +12,41 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    // private instance of the EEM_Datetime_Ticket object
16
-    protected static $_instance = null;
15
+	// private instance of the EEM_Datetime_Ticket object
16
+	protected static $_instance = null;
17 17
 
18
-    /**
19
-     *      private constructor to prevent direct creation
20
-     *      @Constructor
21
-     *      @access private
22
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
23
-     *      @return void
24
-     */
25
-    protected function __construct($timezone)
26
-    {
27
-        $this->singular_item = __('Datetime Ticket', 'event_espresso');
28
-        $this->plural_item = __('Datetime Tickets', 'event_espresso');
18
+	/**
19
+	 *      private constructor to prevent direct creation
20
+	 *      @Constructor
21
+	 *      @access private
22
+	 *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
23
+	 *      @return void
24
+	 */
25
+	protected function __construct($timezone)
26
+	{
27
+		$this->singular_item = __('Datetime Ticket', 'event_espresso');
28
+		$this->plural_item = __('Datetime Tickets', 'event_espresso');
29 29
 
30
-        $this->_tables = array(
31
-            'Datetime_Ticket'=> new EE_Primary_Table('esp_datetime_ticket', 'DTK_ID')
32
-        );
33
-        $this->_fields = array(
34
-            'Datetime_Ticket'=>array(
35
-                'DTK_ID'=>new EE_Primary_Key_Int_Field('DTK_ID', __('Datetime Ticket ID', 'event_espresso')),
36
-                'DTT_ID'=>new EE_Foreign_Key_Int_Field('DTT_ID', __('The ID to the Datetime', 'event_espresso'), false, 0, 'Datetime'),
37
-                'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('The ID to the Ticket', 'event_espresso'), false, 0, 'Ticket')
38
-            ));
39
-        $this->_model_relations = array(
40
-            'Ticket'=>new EE_Belongs_To_Relation(),
41
-            'Datetime'=>new EE_Belongs_To_Relation()
42
-        );
43
-        // this model is generally available for reading
44
-        $path_to_event = 'Datetime.Event';
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
49
-        $this->model_chain_to_password = $path_to_event;
50
-        parent::__construct($timezone);
51
-    }
30
+		$this->_tables = array(
31
+			'Datetime_Ticket'=> new EE_Primary_Table('esp_datetime_ticket', 'DTK_ID')
32
+		);
33
+		$this->_fields = array(
34
+			'Datetime_Ticket'=>array(
35
+				'DTK_ID'=>new EE_Primary_Key_Int_Field('DTK_ID', __('Datetime Ticket ID', 'event_espresso')),
36
+				'DTT_ID'=>new EE_Foreign_Key_Int_Field('DTT_ID', __('The ID to the Datetime', 'event_espresso'), false, 0, 'Datetime'),
37
+				'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('The ID to the Ticket', 'event_espresso'), false, 0, 'Ticket')
38
+			));
39
+		$this->_model_relations = array(
40
+			'Ticket'=>new EE_Belongs_To_Relation(),
41
+			'Datetime'=>new EE_Belongs_To_Relation()
42
+		);
43
+		// this model is generally available for reading
44
+		$path_to_event = 'Datetime.Event';
45
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
49
+		$this->model_chain_to_password = $path_to_event;
50
+		parent::__construct($timezone);
51
+	}
52 52
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -42,10 +42,10 @@
 block discarded – undo
42 42
         );
43 43
         // this model is generally available for reading
44 44
         $path_to_event = 'Datetime.Event';
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
45
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
49 49
         $this->model_chain_to_password = $path_to_event;
50 50
         parent::__construct($timezone);
51 51
     }
Please login to merge, or discard this patch.
core/db_models/EEM_Term_Relationship.model.php 2 patches
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -9,233 +9,233 @@
 block discarded – undo
9 9
 class EEM_Term_Relationship extends EEM_Base
10 10
 {
11 11
 
12
-    // private instance of the Attendee object
13
-    protected static $_instance = null;
14
-
15
-
16
-
17
-    /**
18
-     * EEM_Term_Relationship constructor.
19
-     *
20
-     * @param string $timezone
21
-     */
22
-    protected function __construct($timezone = null)
23
-    {
24
-        $this->singular_item = __('Term Relationship', 'event_espresso');
25
-        $this->plural_item = __('Term Relationships', 'event_espresso');
26
-        $this->_tables = array(
27
-            'Term_Relationship' => new EE_Primary_Table('term_relationships'),
28
-        );
29
-        $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
30
-        $this->_fields = array(
31
-            'Term_Relationship' => array(
32
-                'object_id'        => new EE_Foreign_Key_Int_Field(
33
-                    'object_id',
34
-                    __('Object(Post) ID', 'event_espresso'),
35
-                    false,
36
-                    0,
37
-                    $models_this_can_attach_to
38
-                ),
39
-                'term_taxonomy_id' => new EE_Foreign_Key_Int_Field(
40
-                    'term_taxonomy_id',
41
-                    __(
42
-                        'Term (in context of a taxonomy) ID',
43
-                        'event_espresso'
44
-                    ),
45
-                    false,
46
-                    0,
47
-                    'Term_Taxonomy'
48
-                ),
49
-                'term_order'       => new EE_Integer_Field(
50
-                    'term_order',
51
-                    __('Term Order', 'event_espresso'),
52
-                    false,
53
-                    0
54
-                ),
55
-            ),
56
-        );
57
-        $this->_model_relations = array(
58
-            'Term_Taxonomy' => new EE_Belongs_To_Relation(),
59
-        );
60
-        foreach ($models_this_can_attach_to as $model_name) {
61
-            $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation();
62
-        }
63
-        $this->_wp_core_model = true;
64
-        $this->_indexes = array(
65
-            'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')),
66
-        );
67
-        $path_to_event_model = 'Event';
68
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public(
69
-            $path_to_event_model
70
-        );
71
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
72
-            new EE_Restriction_Generator_Event_Related_Protected(
73
-                $path_to_event_model
74
-            );
75
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected(
76
-            $path_to_event_model
77
-        );
78
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] =
79
-            new EE_Restriction_Generator_Event_Related_Protected(
80
-                $path_to_event_model,
81
-                EEM_Base::caps_edit
82
-            );
83
-        $path_to_tax_model = 'Term_Taxonomy.';
84
-        // add cap restrictions for editing term relations to the "ee_assign_*"
85
-        // and for deleting term relations too
86
-        $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete);
87
-        foreach ($cap_contexts_affected as $cap_context_affected) {
88
-            $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] =
89
-                new EE_Default_Where_Conditions(
90
-                    array(
91
-                        $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array(
92
-                            '!=',
93
-                            'espresso_event_categories',
94
-                        ),
95
-                    )
96
-                );
97
-            $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] =
98
-                new EE_Default_Where_Conditions(
99
-                    array(
100
-                        $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array(
101
-                            '!=',
102
-                            'espresso_venue_categories',
103
-                        ),
104
-                    )
105
-                );
106
-            $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions(
107
-                array(
108
-                    $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'),
109
-                )
110
-            );
111
-        }
112
-        parent::__construct($timezone);
113
-        add_filter(
114
-            'FHEE__Read__create_model_query_params',
115
-            array('EEM_Term_Relationship', 'rest_api_query_params'),
116
-            10,
117
-            3
118
-        );
119
-    }
120
-
121
-
122
-    /**
123
-     * Makes sure all term-taxonomy counts are correct
124
-     *
125
-     * @param int   $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL
126
-     * @global wpdb $wpdb
127
-     * @return int the number of rows affected
128
-     * @throws EE_Error
129
-     */
130
-    public function update_term_taxonomy_counts($term_taxonomy_id = null)
131
-    {
132
-        // because this uses a subquery and sometimes assigning to column to be another column's
133
-        // value, we just write the SQL directly.
134
-        global $wpdb;
135
-
136
-        $query = "
12
+	// private instance of the Attendee object
13
+	protected static $_instance = null;
14
+
15
+
16
+
17
+	/**
18
+	 * EEM_Term_Relationship constructor.
19
+	 *
20
+	 * @param string $timezone
21
+	 */
22
+	protected function __construct($timezone = null)
23
+	{
24
+		$this->singular_item = __('Term Relationship', 'event_espresso');
25
+		$this->plural_item = __('Term Relationships', 'event_espresso');
26
+		$this->_tables = array(
27
+			'Term_Relationship' => new EE_Primary_Table('term_relationships'),
28
+		);
29
+		$models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
30
+		$this->_fields = array(
31
+			'Term_Relationship' => array(
32
+				'object_id'        => new EE_Foreign_Key_Int_Field(
33
+					'object_id',
34
+					__('Object(Post) ID', 'event_espresso'),
35
+					false,
36
+					0,
37
+					$models_this_can_attach_to
38
+				),
39
+				'term_taxonomy_id' => new EE_Foreign_Key_Int_Field(
40
+					'term_taxonomy_id',
41
+					__(
42
+						'Term (in context of a taxonomy) ID',
43
+						'event_espresso'
44
+					),
45
+					false,
46
+					0,
47
+					'Term_Taxonomy'
48
+				),
49
+				'term_order'       => new EE_Integer_Field(
50
+					'term_order',
51
+					__('Term Order', 'event_espresso'),
52
+					false,
53
+					0
54
+				),
55
+			),
56
+		);
57
+		$this->_model_relations = array(
58
+			'Term_Taxonomy' => new EE_Belongs_To_Relation(),
59
+		);
60
+		foreach ($models_this_can_attach_to as $model_name) {
61
+			$this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation();
62
+		}
63
+		$this->_wp_core_model = true;
64
+		$this->_indexes = array(
65
+			'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')),
66
+		);
67
+		$path_to_event_model = 'Event';
68
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public(
69
+			$path_to_event_model
70
+		);
71
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
72
+			new EE_Restriction_Generator_Event_Related_Protected(
73
+				$path_to_event_model
74
+			);
75
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected(
76
+			$path_to_event_model
77
+		);
78
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] =
79
+			new EE_Restriction_Generator_Event_Related_Protected(
80
+				$path_to_event_model,
81
+				EEM_Base::caps_edit
82
+			);
83
+		$path_to_tax_model = 'Term_Taxonomy.';
84
+		// add cap restrictions for editing term relations to the "ee_assign_*"
85
+		// and for deleting term relations too
86
+		$cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete);
87
+		foreach ($cap_contexts_affected as $cap_context_affected) {
88
+			$this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] =
89
+				new EE_Default_Where_Conditions(
90
+					array(
91
+						$path_to_tax_model . 'taxonomy*ee_assign_event_category' => array(
92
+							'!=',
93
+							'espresso_event_categories',
94
+						),
95
+					)
96
+				);
97
+			$this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] =
98
+				new EE_Default_Where_Conditions(
99
+					array(
100
+						$path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array(
101
+							'!=',
102
+							'espresso_venue_categories',
103
+						),
104
+					)
105
+				);
106
+			$this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions(
107
+				array(
108
+					$path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'),
109
+				)
110
+			);
111
+		}
112
+		parent::__construct($timezone);
113
+		add_filter(
114
+			'FHEE__Read__create_model_query_params',
115
+			array('EEM_Term_Relationship', 'rest_api_query_params'),
116
+			10,
117
+			3
118
+		);
119
+	}
120
+
121
+
122
+	/**
123
+	 * Makes sure all term-taxonomy counts are correct
124
+	 *
125
+	 * @param int   $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL
126
+	 * @global wpdb $wpdb
127
+	 * @return int the number of rows affected
128
+	 * @throws EE_Error
129
+	 */
130
+	public function update_term_taxonomy_counts($term_taxonomy_id = null)
131
+	{
132
+		// because this uses a subquery and sometimes assigning to column to be another column's
133
+		// value, we just write the SQL directly.
134
+		global $wpdb;
135
+
136
+		$query = "
137 137
                 UPDATE {$wpdb->term_taxonomy} AS tt 
138 138
                 SET count = (
139 139
                     select count(*) as proper_count from {$wpdb->term_relationships} AS tr 
140 140
                     WHERE tt.term_taxonomy_id = tr.term_taxonomy_id
141 141
                 )";
142 142
 
143
-        if ($term_taxonomy_id) {
144
-            $query .= ' WHERE tt.term_taxonomy_id = %d';
145
-            $query = $wpdb->prepare(
146
-                $query,
147
-                $term_taxonomy_id
148
-            );
149
-        }
150
-        $rows_affected = $this->_do_wpdb_query(
151
-            'query',
152
-            array(
153
-                $query,
154
-            )
155
-        );
156
-        return $rows_affected;
157
-    }
158
-
159
-
160
-
161
-    /**
162
-     * Overrides the parent to also make sure term-taxonomy counts are up-to-date after
163
-     * inserting
164
-     *
165
-     * @param array $field_n_values @see EEM_Base::insert
166
-     * @return boolean
167
-     */
168
-    public function insert($field_n_values)
169
-    {
170
-        $return = parent::insert($field_n_values);
171
-        if (isset($field_n_values['term_taxonomy_id'])) {
172
-            $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']);
173
-        }
174
-        return $return;
175
-    }
176
-
177
-
178
-
179
-    /**
180
-     * Overrides parent so that after an update, we also check the term_taxonomy_counts are
181
-     * all ok
182
-     *
183
-     * @param array   $fields_n_values         see EEM_Base::update
184
-     * @param array   $query_params            @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
185
-     * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
186
-     *                                         in this model's entity map according to $fields_n_values that match
187
-     *                                         $query_params. This obviously has some overhead, so you can disable it
188
-     *                                         by setting this to FALSE, but be aware that model objects being used
189
-     *                                         could get out-of-sync with the database
190
-     * @return int
191
-     */
192
-    public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
193
-    {
194
-        $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync);
195
-        if ($count) {
196
-            $this->update_term_taxonomy_counts();
197
-        }
198
-        return $count;
199
-    }
200
-
201
-
202
-
203
-    /**
204
-     * Overrides parent so that after running this, we also double-check
205
-     * the term taxonomy counts are up-to-date
206
-     *
207
-     * @param array   $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
208
-     * @param boolean $allow_blocking
209
-     * @return int @see EEM_Base::delete
210
-     */
211
-    public function delete($query_params, $allow_blocking = true)
212
-    {
213
-        $count = parent::delete($query_params, $allow_blocking);
214
-        if ($count) {
215
-            $this->update_term_taxonomy_counts();
216
-        }
217
-        return $count;
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * Makes sure that during REST API queries, we only return term relationships
224
-     * for term taxonomies which should be shown in the rest api
225
-     *
226
-     * @param array    $model_query_params
227
-     * @param array    $querystring_query_params
228
-     * @param EEM_Base $model
229
-     * @return array
230
-     */
231
-    public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
232
-    {
233
-        if ($model === EEM_Term_Relationship::instance()) {
234
-            $taxonomies = get_taxonomies(array('show_in_rest' => true));
235
-            if (! empty($taxonomies)) {
236
-                $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies);
237
-            }
238
-        }
239
-        return $model_query_params;
240
-    }
143
+		if ($term_taxonomy_id) {
144
+			$query .= ' WHERE tt.term_taxonomy_id = %d';
145
+			$query = $wpdb->prepare(
146
+				$query,
147
+				$term_taxonomy_id
148
+			);
149
+		}
150
+		$rows_affected = $this->_do_wpdb_query(
151
+			'query',
152
+			array(
153
+				$query,
154
+			)
155
+		);
156
+		return $rows_affected;
157
+	}
158
+
159
+
160
+
161
+	/**
162
+	 * Overrides the parent to also make sure term-taxonomy counts are up-to-date after
163
+	 * inserting
164
+	 *
165
+	 * @param array $field_n_values @see EEM_Base::insert
166
+	 * @return boolean
167
+	 */
168
+	public function insert($field_n_values)
169
+	{
170
+		$return = parent::insert($field_n_values);
171
+		if (isset($field_n_values['term_taxonomy_id'])) {
172
+			$this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']);
173
+		}
174
+		return $return;
175
+	}
176
+
177
+
178
+
179
+	/**
180
+	 * Overrides parent so that after an update, we also check the term_taxonomy_counts are
181
+	 * all ok
182
+	 *
183
+	 * @param array   $fields_n_values         see EEM_Base::update
184
+	 * @param array   $query_params            @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
185
+	 * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
186
+	 *                                         in this model's entity map according to $fields_n_values that match
187
+	 *                                         $query_params. This obviously has some overhead, so you can disable it
188
+	 *                                         by setting this to FALSE, but be aware that model objects being used
189
+	 *                                         could get out-of-sync with the database
190
+	 * @return int
191
+	 */
192
+	public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
193
+	{
194
+		$count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync);
195
+		if ($count) {
196
+			$this->update_term_taxonomy_counts();
197
+		}
198
+		return $count;
199
+	}
200
+
201
+
202
+
203
+	/**
204
+	 * Overrides parent so that after running this, we also double-check
205
+	 * the term taxonomy counts are up-to-date
206
+	 *
207
+	 * @param array   $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
208
+	 * @param boolean $allow_blocking
209
+	 * @return int @see EEM_Base::delete
210
+	 */
211
+	public function delete($query_params, $allow_blocking = true)
212
+	{
213
+		$count = parent::delete($query_params, $allow_blocking);
214
+		if ($count) {
215
+			$this->update_term_taxonomy_counts();
216
+		}
217
+		return $count;
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * Makes sure that during REST API queries, we only return term relationships
224
+	 * for term taxonomies which should be shown in the rest api
225
+	 *
226
+	 * @param array    $model_query_params
227
+	 * @param array    $querystring_query_params
228
+	 * @param EEM_Base $model
229
+	 * @return array
230
+	 */
231
+	public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
232
+	{
233
+		if ($model === EEM_Term_Relationship::instance()) {
234
+			$taxonomies = get_taxonomies(array('show_in_rest' => true));
235
+			if (! empty($taxonomies)) {
236
+				$model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies);
237
+			}
238
+		}
239
+		return $model_query_params;
240
+	}
241 241
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -58,24 +58,24 @@  discard block
 block discarded – undo
58 58
             'Term_Taxonomy' => new EE_Belongs_To_Relation(),
59 59
         );
60 60
         foreach ($models_this_can_attach_to as $model_name) {
61
-            $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation();
61
+            $this->_model_relations[$model_name] = new EE_Belongs_To_Relation();
62 62
         }
63 63
         $this->_wp_core_model = true;
64 64
         $this->_indexes = array(
65 65
             'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')),
66 66
         );
67 67
         $path_to_event_model = 'Event';
68
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public(
68
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public(
69 69
             $path_to_event_model
70 70
         );
71
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
71
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] =
72 72
             new EE_Restriction_Generator_Event_Related_Protected(
73 73
                 $path_to_event_model
74 74
             );
75
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected(
75
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected(
76 76
             $path_to_event_model
77 77
         );
78
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] =
78
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] =
79 79
             new EE_Restriction_Generator_Event_Related_Protected(
80 80
                 $path_to_event_model,
81 81
                 EEM_Base::caps_edit
@@ -85,27 +85,27 @@  discard block
 block discarded – undo
85 85
         // and for deleting term relations too
86 86
         $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete);
87 87
         foreach ($cap_contexts_affected as $cap_context_affected) {
88
-            $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] =
88
+            $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_category'] =
89 89
                 new EE_Default_Where_Conditions(
90 90
                     array(
91
-                        $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array(
91
+                        $path_to_tax_model.'taxonomy*ee_assign_event_category' => array(
92 92
                             '!=',
93 93
                             'espresso_event_categories',
94 94
                         ),
95 95
                     )
96 96
                 );
97
-            $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] =
97
+            $this->_cap_restrictions[$cap_context_affected]['ee_assign_venue_category'] =
98 98
                 new EE_Default_Where_Conditions(
99 99
                     array(
100
-                        $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array(
100
+                        $path_to_tax_model.'taxonomy*ee_assign_venue_category' => array(
101 101
                             '!=',
102 102
                             'espresso_venue_categories',
103 103
                         ),
104 104
                     )
105 105
                 );
106
-            $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions(
106
+            $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_type'] = new EE_Default_Where_Conditions(
107 107
                 array(
108
-                    $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'),
108
+                    $path_to_tax_model.'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'),
109 109
                 )
110 110
             );
111 111
         }
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
     {
233 233
         if ($model === EEM_Term_Relationship::instance()) {
234 234
             $taxonomies = get_taxonomies(array('show_in_rest' => true));
235
-            if (! empty($taxonomies)) {
235
+            if ( ! empty($taxonomies)) {
236 236
                 $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies);
237 237
             }
238 238
         }
Please login to merge, or discard this patch.
core/db_models/EEM_Ticket.model.php 2 patches
Indentation   +304 added lines, -304 removed lines patch added patch discarded remove patch
@@ -10,322 +10,322 @@
 block discarded – undo
10 10
 class EEM_Ticket extends EEM_Soft_Delete_Base
11 11
 {
12 12
 
13
-    /**
14
-     * private instance of the EEM_Ticket object
15
-     *
16
-     * @var EEM_Ticket $_instance
17
-     */
18
-    protected static $_instance;
13
+	/**
14
+	 * private instance of the EEM_Ticket object
15
+	 *
16
+	 * @var EEM_Ticket $_instance
17
+	 */
18
+	protected static $_instance;
19 19
 
20 20
 
21
-    /**
22
-     * private constructor to prevent direct creation
23
-     *
24
-     * @Constructor
25
-     * @access private
26
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings
27
-     *                         (and any incoming timezone data that gets saved).
28
-     *                         Note this just sends the timezone info to the date time model field objects.
29
-     *                         Default is NULL
30
-     *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
31
-     * @throws EE_Error
32
-     */
33
-    protected function __construct($timezone)
34
-    {
35
-        $this->singular_item = esc_html__('Ticket', 'event_espresso');
36
-        $this->plural_item = esc_html__('Tickets', 'event_espresso');
37
-        $this->_tables = array(
38
-            'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'),
39
-        );
40
-        $this->_fields = array(
41
-            'Ticket' => array(
42
-                'TKT_ID'          => new EE_Primary_Key_Int_Field(
43
-                    'TKT_ID',
44
-                    esc_html__('Ticket ID', 'event_espresso')
45
-                ),
46
-                'TTM_ID'          => new EE_Foreign_Key_Int_Field(
47
-                    'TTM_ID',
48
-                    esc_html__('Ticket Template ID', 'event_espresso'),
49
-                    false,
50
-                    0,
51
-                    'Ticket_Template'
52
-                ),
53
-                'TKT_name'        => new EE_Plain_Text_Field(
54
-                    'TKT_name',
55
-                    esc_html__('Ticket Name', 'event_espresso'),
56
-                    false,
57
-                    ''
58
-                ),
59
-                'TKT_description' => new EE_Post_Content_Field(
60
-                    'TKT_description',
61
-                    esc_html__('Description of Ticket', 'event_espresso'),
62
-                    false,
63
-                    ''
64
-                ),
65
-                'TKT_start_date'  => new EE_Datetime_Field(
66
-                    'TKT_start_date',
67
-                    esc_html__('Start time/date of Ticket', 'event_espresso'),
68
-                    false,
69
-                    EE_Datetime_Field::now,
70
-                    $timezone
71
-                ),
72
-                'TKT_end_date'    => new EE_Datetime_Field(
73
-                    'TKT_end_date',
74
-                    esc_html__('End time/date of Ticket', 'event_espresso'),
75
-                    false,
76
-                    EE_Datetime_Field::now,
77
-                    $timezone
78
-                ),
79
-                'TKT_min'         => new EE_Integer_Field(
80
-                    'TKT_min',
81
-                    esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'),
82
-                    false,
83
-                    0
84
-                ),
85
-                'TKT_max'         => new EE_Infinite_Integer_Field(
86
-                    'TKT_max',
87
-                    esc_html__(
88
-                        'Maximum quantity of this ticket that can be purchased in one transaction',
89
-                        'event_espresso'
90
-                    ),
91
-                    false,
92
-                    EE_INF
93
-                ),
94
-                'TKT_price'       => new EE_Money_Field(
95
-                    'TKT_price',
96
-                    esc_html__('Final calculated price for ticket', 'event_espresso'),
97
-                    false,
98
-                    0
99
-                ),
100
-                'TKT_sold'        => new EE_Integer_Field(
101
-                    'TKT_sold',
102
-                    esc_html__('Number of this ticket sold', 'event_espresso'),
103
-                    false,
104
-                    0
105
-                ),
106
-                'TKT_qty'         => new EE_Infinite_Integer_Field(
107
-                    'TKT_qty',
108
-                    esc_html__('Quantity of this ticket that is available', 'event_espresso'),
109
-                    false,
110
-                    EE_INF
111
-                ),
112
-                'TKT_reserved'    => new EE_Integer_Field(
113
-                    'TKT_reserved',
114
-                    esc_html__(
115
-                        'Quantity of this ticket that is reserved, but not yet fully purchased',
116
-                        'event_espresso'
117
-                    ),
118
-                    false,
119
-                    0
120
-                ),
121
-                'TKT_uses'        => new EE_Infinite_Integer_Field(
122
-                    'TKT_uses',
123
-                    esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'),
124
-                    false,
125
-                    EE_INF
126
-                ),
127
-                'TKT_required'    => new EE_Boolean_Field(
128
-                    'TKT_required',
129
-                    esc_html__(
130
-                        'Flag indicating whether this ticket must be purchased with a transaction',
131
-                        'event_espresso'
132
-                    ),
133
-                    false,
134
-                    false
135
-                ),
136
-                'TKT_taxable'     => new EE_Boolean_Field(
137
-                    'TKT_taxable',
138
-                    esc_html__(
139
-                        'Flag indicating whether there is tax applied on this ticket',
140
-                        'event_espresso'
141
-                    ),
142
-                    false,
143
-                    false
144
-                ),
145
-                'TKT_is_default'  => new EE_Boolean_Field(
146
-                    'TKT_is_default',
147
-                    esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'),
148
-                    false,
149
-                    false
150
-                ),
151
-                'TKT_order'       => new EE_Integer_Field(
152
-                    'TKT_order',
153
-                    esc_html__(
154
-                        'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)',
155
-                        'event_espresso'
156
-                    ),
157
-                    false,
158
-                    0
159
-                ),
160
-                'TKT_row'         => new EE_Integer_Field(
161
-                    'TKT_row',
162
-                    esc_html__('How tickets are displayed in the ui', 'event_espresso'),
163
-                    false,
164
-                    0
165
-                ),
166
-                'TKT_deleted'     => new EE_Trashed_Flag_Field(
167
-                    'TKT_deleted',
168
-                    esc_html__('Flag indicating if this has been archived or not', 'event_espresso'),
169
-                    false,
170
-                    false
171
-                ),
172
-                'TKT_wp_user'     => new EE_WP_User_Field(
173
-                    'TKT_wp_user',
174
-                    esc_html__('Ticket Creator ID', 'event_espresso'),
175
-                    false
176
-                ),
177
-                'TKT_parent'      => new EE_Integer_Field(
178
-                    'TKT_parent',
179
-                    esc_html__(
180
-                        'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)',
181
-                        'event_espresso'
182
-                    ),
183
-                    true,
184
-                    0
185
-                ),
186
-            ),
187
-        );
188
-        $this->_model_relations = array(
189
-            'Datetime'        => new EE_HABTM_Relation('Datetime_Ticket'),
190
-            'Datetime_Ticket' => new EE_Has_Many_Relation(),
191
-            'Price'           => new EE_HABTM_Relation('Ticket_Price'),
192
-            'Ticket_Template' => new EE_Belongs_To_Relation(),
193
-            'Registration'    => new EE_Has_Many_Relation(),
194
-            'WP_User'         => new EE_Belongs_To_Relation(),
195
-        );
196
-        // this model is generally available for reading
197
-        $path_to_event = 'Datetime.Event';
198
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public(
199
-            'TKT_is_default',
200
-            $path_to_event
201
-        );
202
-        // account for default tickets in the caps
203
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected(
204
-            'TKT_is_default',
205
-            $path_to_event
206
-        );
207
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected(
208
-            'TKT_is_default',
209
-            $path_to_event
210
-        );
211
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected(
212
-            'TKT_is_default',
213
-            $path_to_event
214
-        );
215
-        $this->model_chain_to_password = $path_to_event;
216
-        parent::__construct($timezone);
217
-    }
21
+	/**
22
+	 * private constructor to prevent direct creation
23
+	 *
24
+	 * @Constructor
25
+	 * @access private
26
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings
27
+	 *                         (and any incoming timezone data that gets saved).
28
+	 *                         Note this just sends the timezone info to the date time model field objects.
29
+	 *                         Default is NULL
30
+	 *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
31
+	 * @throws EE_Error
32
+	 */
33
+	protected function __construct($timezone)
34
+	{
35
+		$this->singular_item = esc_html__('Ticket', 'event_espresso');
36
+		$this->plural_item = esc_html__('Tickets', 'event_espresso');
37
+		$this->_tables = array(
38
+			'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'),
39
+		);
40
+		$this->_fields = array(
41
+			'Ticket' => array(
42
+				'TKT_ID'          => new EE_Primary_Key_Int_Field(
43
+					'TKT_ID',
44
+					esc_html__('Ticket ID', 'event_espresso')
45
+				),
46
+				'TTM_ID'          => new EE_Foreign_Key_Int_Field(
47
+					'TTM_ID',
48
+					esc_html__('Ticket Template ID', 'event_espresso'),
49
+					false,
50
+					0,
51
+					'Ticket_Template'
52
+				),
53
+				'TKT_name'        => new EE_Plain_Text_Field(
54
+					'TKT_name',
55
+					esc_html__('Ticket Name', 'event_espresso'),
56
+					false,
57
+					''
58
+				),
59
+				'TKT_description' => new EE_Post_Content_Field(
60
+					'TKT_description',
61
+					esc_html__('Description of Ticket', 'event_espresso'),
62
+					false,
63
+					''
64
+				),
65
+				'TKT_start_date'  => new EE_Datetime_Field(
66
+					'TKT_start_date',
67
+					esc_html__('Start time/date of Ticket', 'event_espresso'),
68
+					false,
69
+					EE_Datetime_Field::now,
70
+					$timezone
71
+				),
72
+				'TKT_end_date'    => new EE_Datetime_Field(
73
+					'TKT_end_date',
74
+					esc_html__('End time/date of Ticket', 'event_espresso'),
75
+					false,
76
+					EE_Datetime_Field::now,
77
+					$timezone
78
+				),
79
+				'TKT_min'         => new EE_Integer_Field(
80
+					'TKT_min',
81
+					esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'),
82
+					false,
83
+					0
84
+				),
85
+				'TKT_max'         => new EE_Infinite_Integer_Field(
86
+					'TKT_max',
87
+					esc_html__(
88
+						'Maximum quantity of this ticket that can be purchased in one transaction',
89
+						'event_espresso'
90
+					),
91
+					false,
92
+					EE_INF
93
+				),
94
+				'TKT_price'       => new EE_Money_Field(
95
+					'TKT_price',
96
+					esc_html__('Final calculated price for ticket', 'event_espresso'),
97
+					false,
98
+					0
99
+				),
100
+				'TKT_sold'        => new EE_Integer_Field(
101
+					'TKT_sold',
102
+					esc_html__('Number of this ticket sold', 'event_espresso'),
103
+					false,
104
+					0
105
+				),
106
+				'TKT_qty'         => new EE_Infinite_Integer_Field(
107
+					'TKT_qty',
108
+					esc_html__('Quantity of this ticket that is available', 'event_espresso'),
109
+					false,
110
+					EE_INF
111
+				),
112
+				'TKT_reserved'    => new EE_Integer_Field(
113
+					'TKT_reserved',
114
+					esc_html__(
115
+						'Quantity of this ticket that is reserved, but not yet fully purchased',
116
+						'event_espresso'
117
+					),
118
+					false,
119
+					0
120
+				),
121
+				'TKT_uses'        => new EE_Infinite_Integer_Field(
122
+					'TKT_uses',
123
+					esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'),
124
+					false,
125
+					EE_INF
126
+				),
127
+				'TKT_required'    => new EE_Boolean_Field(
128
+					'TKT_required',
129
+					esc_html__(
130
+						'Flag indicating whether this ticket must be purchased with a transaction',
131
+						'event_espresso'
132
+					),
133
+					false,
134
+					false
135
+				),
136
+				'TKT_taxable'     => new EE_Boolean_Field(
137
+					'TKT_taxable',
138
+					esc_html__(
139
+						'Flag indicating whether there is tax applied on this ticket',
140
+						'event_espresso'
141
+					),
142
+					false,
143
+					false
144
+				),
145
+				'TKT_is_default'  => new EE_Boolean_Field(
146
+					'TKT_is_default',
147
+					esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'),
148
+					false,
149
+					false
150
+				),
151
+				'TKT_order'       => new EE_Integer_Field(
152
+					'TKT_order',
153
+					esc_html__(
154
+						'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)',
155
+						'event_espresso'
156
+					),
157
+					false,
158
+					0
159
+				),
160
+				'TKT_row'         => new EE_Integer_Field(
161
+					'TKT_row',
162
+					esc_html__('How tickets are displayed in the ui', 'event_espresso'),
163
+					false,
164
+					0
165
+				),
166
+				'TKT_deleted'     => new EE_Trashed_Flag_Field(
167
+					'TKT_deleted',
168
+					esc_html__('Flag indicating if this has been archived or not', 'event_espresso'),
169
+					false,
170
+					false
171
+				),
172
+				'TKT_wp_user'     => new EE_WP_User_Field(
173
+					'TKT_wp_user',
174
+					esc_html__('Ticket Creator ID', 'event_espresso'),
175
+					false
176
+				),
177
+				'TKT_parent'      => new EE_Integer_Field(
178
+					'TKT_parent',
179
+					esc_html__(
180
+						'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)',
181
+						'event_espresso'
182
+					),
183
+					true,
184
+					0
185
+				),
186
+			),
187
+		);
188
+		$this->_model_relations = array(
189
+			'Datetime'        => new EE_HABTM_Relation('Datetime_Ticket'),
190
+			'Datetime_Ticket' => new EE_Has_Many_Relation(),
191
+			'Price'           => new EE_HABTM_Relation('Ticket_Price'),
192
+			'Ticket_Template' => new EE_Belongs_To_Relation(),
193
+			'Registration'    => new EE_Has_Many_Relation(),
194
+			'WP_User'         => new EE_Belongs_To_Relation(),
195
+		);
196
+		// this model is generally available for reading
197
+		$path_to_event = 'Datetime.Event';
198
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public(
199
+			'TKT_is_default',
200
+			$path_to_event
201
+		);
202
+		// account for default tickets in the caps
203
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected(
204
+			'TKT_is_default',
205
+			$path_to_event
206
+		);
207
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected(
208
+			'TKT_is_default',
209
+			$path_to_event
210
+		);
211
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected(
212
+			'TKT_is_default',
213
+			$path_to_event
214
+		);
215
+		$this->model_chain_to_password = $path_to_event;
216
+		parent::__construct($timezone);
217
+	}
218 218
 
219 219
 
220
-    /**
221
-     * This returns all tickets that are defaults from the db
222
-     *
223
-     * @return EE_Ticket[]
224
-     * @throws EE_Error
225
-     */
226
-    public function get_all_default_tickets()
227
-    {
228
-        /** @type EE_Ticket[] $tickets */
229
-        $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC')));
230
-        // we need to set the start date and end date to today's date and the start of the default dtt
231
-        return $this->_set_default_dates($tickets);
232
-    }
220
+	/**
221
+	 * This returns all tickets that are defaults from the db
222
+	 *
223
+	 * @return EE_Ticket[]
224
+	 * @throws EE_Error
225
+	 */
226
+	public function get_all_default_tickets()
227
+	{
228
+		/** @type EE_Ticket[] $tickets */
229
+		$tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC')));
230
+		// we need to set the start date and end date to today's date and the start of the default dtt
231
+		return $this->_set_default_dates($tickets);
232
+	}
233 233
 
234 234
 
235
-    /**
236
-     * sets up relevant start and end date for EE_Ticket (s)
237
-     *
238
-     * @param EE_Ticket[] $tickets
239
-     * @return EE_Ticket[]
240
-     * @throws EE_Error
241
-     */
242
-    private function _set_default_dates($tickets)
243
-    {
244
-        foreach ($tickets as $ticket) {
245
-            $ticket->set(
246
-                'TKT_start_date',
247
-                (int) $this->current_time_for_query('TKT_start_date', true)
248
-            );
249
-            $ticket->set(
250
-                'TKT_end_date',
251
-                (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS
252
-            );
253
-            $ticket->set_end_time(
254
-                $this->convert_datetime_for_query(
255
-                    'TKT_end_date',
256
-                    '11:59 pm',
257
-                    'g:i a',
258
-                    $this->_timezone
259
-                )
260
-            );
261
-        }
262
-        return $tickets;
263
-    }
235
+	/**
236
+	 * sets up relevant start and end date for EE_Ticket (s)
237
+	 *
238
+	 * @param EE_Ticket[] $tickets
239
+	 * @return EE_Ticket[]
240
+	 * @throws EE_Error
241
+	 */
242
+	private function _set_default_dates($tickets)
243
+	{
244
+		foreach ($tickets as $ticket) {
245
+			$ticket->set(
246
+				'TKT_start_date',
247
+				(int) $this->current_time_for_query('TKT_start_date', true)
248
+			);
249
+			$ticket->set(
250
+				'TKT_end_date',
251
+				(int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS
252
+			);
253
+			$ticket->set_end_time(
254
+				$this->convert_datetime_for_query(
255
+					'TKT_end_date',
256
+					'11:59 pm',
257
+					'g:i a',
258
+					$this->_timezone
259
+				)
260
+			);
261
+		}
262
+		return $tickets;
263
+	}
264 264
 
265 265
 
266
-    /**
267
-     * Gets the total number of tickets available at a particular datetime (does
268
-     * NOT take int account the datetime's spaces available)
269
-     *
270
-     * @param int   $DTT_ID
271
-     * @param array $query_params
272
-     * @return int
273
-     */
274
-    public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array())
275
-    {
276
-        return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params);
277
-    }
266
+	/**
267
+	 * Gets the total number of tickets available at a particular datetime (does
268
+	 * NOT take int account the datetime's spaces available)
269
+	 *
270
+	 * @param int   $DTT_ID
271
+	 * @param array $query_params
272
+	 * @return int
273
+	 */
274
+	public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array())
275
+	{
276
+		return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params);
277
+	}
278 278
 
279 279
 
280
-    /**
281
-     * Updates the TKT_sold quantity on all the tickets matching $query_params
282
-     *
283
-     * @param EE_Ticket[] $tickets
284
-     * @return void
285
-     * @throws EE_Error
286
-     */
287
-    public function update_tickets_sold($tickets)
288
-    {
289
-        foreach ($tickets as $ticket) {
290
-            /* @var  $ticket EE_Ticket */
291
-            $ticket->update_tickets_sold();
292
-        }
293
-    }
280
+	/**
281
+	 * Updates the TKT_sold quantity on all the tickets matching $query_params
282
+	 *
283
+	 * @param EE_Ticket[] $tickets
284
+	 * @return void
285
+	 * @throws EE_Error
286
+	 */
287
+	public function update_tickets_sold($tickets)
288
+	{
289
+		foreach ($tickets as $ticket) {
290
+			/* @var  $ticket EE_Ticket */
291
+			$ticket->update_tickets_sold();
292
+		}
293
+	}
294 294
 
295 295
 
296
-    /**
297
-     * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved
298
-     *
299
-     * @return EE_Base_Class[]|EE_Ticket[]
300
-     * @throws EE_Error
301
-     */
302
-    public function get_tickets_with_reservations()
303
-    {
304
-        return $this->get_all(
305
-            array(
306
-                array(
307
-                    'TKT_reserved' => array('>', 0),
308
-                ),
309
-            )
310
-        );
311
-    }
296
+	/**
297
+	 * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved
298
+	 *
299
+	 * @return EE_Base_Class[]|EE_Ticket[]
300
+	 * @throws EE_Error
301
+	 */
302
+	public function get_tickets_with_reservations()
303
+	{
304
+		return $this->get_all(
305
+			array(
306
+				array(
307
+					'TKT_reserved' => array('>', 0),
308
+				),
309
+			)
310
+		);
311
+	}
312 312
 
313 313
 
314
-    /**
315
-     * returns an array of EE_Ticket objects matching the supplied list of IDs
316
-     *
317
-     * @param array $ticket_IDs
318
-     * @return EE_Base_Class[]|EE_Ticket[]
319
-     * @throws EE_Error
320
-     */
321
-    public function get_tickets_with_IDs(array $ticket_IDs)
322
-    {
323
-        return $this->get_all(
324
-            array(
325
-                array(
326
-                    'TKT_ID' => array('IN', $ticket_IDs),
327
-                ),
328
-            )
329
-        );
330
-    }
314
+	/**
315
+	 * returns an array of EE_Ticket objects matching the supplied list of IDs
316
+	 *
317
+	 * @param array $ticket_IDs
318
+	 * @return EE_Base_Class[]|EE_Ticket[]
319
+	 * @throws EE_Error
320
+	 */
321
+	public function get_tickets_with_IDs(array $ticket_IDs)
322
+	{
323
+		return $this->get_all(
324
+			array(
325
+				array(
326
+					'TKT_ID' => array('IN', $ticket_IDs),
327
+				),
328
+			)
329
+		);
330
+	}
331 331
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -195,20 +195,20 @@
 block discarded – undo
195 195
         );
196 196
         // this model is generally available for reading
197 197
         $path_to_event = 'Datetime.Event';
198
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public(
198
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public(
199 199
             'TKT_is_default',
200 200
             $path_to_event
201 201
         );
202 202
         // account for default tickets in the caps
203
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected(
203
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected(
204 204
             'TKT_is_default',
205 205
             $path_to_event
206 206
         );
207
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected(
207
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected(
208 208
             'TKT_is_default',
209 209
             $path_to_event
210 210
         );
211
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected(
211
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected(
212 212
             'TKT_is_default',
213 213
             $path_to_event
214 214
         );
Please login to merge, or discard this patch.
core/db_models/EEM_Event.model.php 2 patches
Indentation   +895 added lines, -895 removed lines patch added patch discarded remove patch
@@ -13,899 +13,899 @@
 block discarded – undo
13 13
 class EEM_Event extends EEM_CPT_Base
14 14
 {
15 15
 
16
-    /**
17
-     * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
18
-     * event
19
-     */
20
-    const sold_out = 'sold_out';
21
-
22
-    /**
23
-     * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
24
-     * date)
25
-     */
26
-    const postponed = 'postponed';
27
-
28
-    /**
29
-     * constant used by status(), indicating that the event will no longer occur
30
-     */
31
-    const cancelled = 'cancelled';
32
-
33
-
34
-    /**
35
-     * @var string
36
-     */
37
-    protected static $_default_reg_status;
38
-
39
-
40
-    /**
41
-     * This is the default for the additional limit field.
42
-     * @var int
43
-     */
44
-    protected static $_default_additional_limit = 10;
45
-
46
-
47
-    /**
48
-     * private instance of the Event object
49
-     *
50
-     * @var EEM_Event
51
-     */
52
-    protected static $_instance;
53
-
54
-
55
-
56
-
57
-    /**
58
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
59
-     *
60
-     * @param string $timezone
61
-     * @throws \EE_Error
62
-     */
63
-    protected function __construct($timezone = null)
64
-    {
65
-        EE_Registry::instance()->load_model('Registration');
66
-        $this->singular_item = esc_html__('Event', 'event_espresso');
67
-        $this->plural_item = esc_html__('Events', 'event_espresso');
68
-        // to remove Cancelled events from the frontend, copy the following filter to your functions.php file
69
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
70
-        // to remove Postponed events from the frontend, copy the following filter to your functions.php file
71
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
72
-        // to remove Sold Out events from the frontend, copy the following filter to your functions.php file
73
-        //  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
74
-        $this->_custom_stati = apply_filters(
75
-            'AFEE__EEM_Event__construct___custom_stati',
76
-            array(
77
-                EEM_Event::cancelled => array(
78
-                    'label'  => esc_html__('Cancelled', 'event_espresso'),
79
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
80
-                ),
81
-                EEM_Event::postponed => array(
82
-                    'label'  => esc_html__('Postponed', 'event_espresso'),
83
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
84
-                ),
85
-                EEM_Event::sold_out  => array(
86
-                    'label'  => esc_html__('Sold Out', 'event_espresso'),
87
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
88
-                ),
89
-            )
90
-        );
91
-        self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
92
-            : self::$_default_reg_status;
93
-        $this->_tables = array(
94
-            'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
95
-            'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
96
-        );
97
-        $this->_fields = array(
98
-            'Event_CPT'  => array(
99
-                'EVT_ID'         => new EE_Primary_Key_Int_Field(
100
-                    'ID',
101
-                    esc_html__('Post ID for Event', 'event_espresso')
102
-                ),
103
-                'EVT_name'       => new EE_Plain_Text_Field(
104
-                    'post_title',
105
-                    esc_html__('Event Name', 'event_espresso'),
106
-                    false,
107
-                    ''
108
-                ),
109
-                'EVT_desc'       => new EE_Post_Content_Field(
110
-                    'post_content',
111
-                    esc_html__('Event Description', 'event_espresso'),
112
-                    false,
113
-                    ''
114
-                ),
115
-                'EVT_slug'       => new EE_Slug_Field(
116
-                    'post_name',
117
-                    esc_html__('Event Slug', 'event_espresso'),
118
-                    false,
119
-                    ''
120
-                ),
121
-                'EVT_created'    => new EE_Datetime_Field(
122
-                    'post_date',
123
-                    esc_html__('Date/Time Event Created', 'event_espresso'),
124
-                    false,
125
-                    EE_Datetime_Field::now
126
-                ),
127
-                'EVT_short_desc' => new EE_Simple_HTML_Field(
128
-                    'post_excerpt',
129
-                    esc_html__('Event Short Description', 'event_espresso'),
130
-                    false,
131
-                    ''
132
-                ),
133
-                'EVT_modified'   => new EE_Datetime_Field(
134
-                    'post_modified',
135
-                    esc_html__('Date/Time Event Modified', 'event_espresso'),
136
-                    false,
137
-                    EE_Datetime_Field::now
138
-                ),
139
-                'EVT_wp_user'    => new EE_WP_User_Field(
140
-                    'post_author',
141
-                    esc_html__('Event Creator ID', 'event_espresso'),
142
-                    false
143
-                ),
144
-                'parent'         => new EE_Integer_Field(
145
-                    'post_parent',
146
-                    esc_html__('Event Parent ID', 'event_espresso'),
147
-                    false,
148
-                    0
149
-                ),
150
-                'EVT_order'      => new EE_Integer_Field(
151
-                    'menu_order',
152
-                    esc_html__('Event Menu Order', 'event_espresso'),
153
-                    false,
154
-                    1
155
-                ),
156
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
157
-                // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
158
-                'status'         => new EE_WP_Post_Status_Field(
159
-                    'post_status',
160
-                    esc_html__('Event Status', 'event_espresso'),
161
-                    false,
162
-                    'draft',
163
-                    $this->_custom_stati
164
-                ),
165
-                'password' => new EE_Password_Field(
166
-                    'post_password',
167
-                    __('Password', 'event_espresso'),
168
-                    false,
169
-                    '',
170
-                    array(
171
-                        'EVT_desc',
172
-                        'EVT_short_desc',
173
-                        'EVT_display_desc',
174
-                        'EVT_display_ticket_selector',
175
-                        'EVT_visible_on',
176
-                        'EVT_additional_limit',
177
-                        'EVT_default_registration_status',
178
-                        'EVT_member_only',
179
-                        'EVT_phone',
180
-                        'EVT_allow_overflow',
181
-                        'EVT_timezone_string',
182
-                        'EVT_external_URL',
183
-                        'EVT_donations'
184
-                    )
185
-                )
186
-            ),
187
-            'Event_Meta' => array(
188
-                'EVTM_ID'                         => new EE_DB_Only_Float_Field(
189
-                    'EVTM_ID',
190
-                    esc_html__('Event Meta Row ID', 'event_espresso'),
191
-                    false
192
-                ),
193
-                'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
194
-                    'EVT_ID',
195
-                    esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
196
-                    false
197
-                ),
198
-                'EVT_display_desc'                => new EE_Boolean_Field(
199
-                    'EVT_display_desc',
200
-                    esc_html__('Display Description Flag', 'event_espresso'),
201
-                    false,
202
-                    true
203
-                ),
204
-                'EVT_display_ticket_selector'     => new EE_Boolean_Field(
205
-                    'EVT_display_ticket_selector',
206
-                    esc_html__('Display Ticket Selector Flag', 'event_espresso'),
207
-                    false,
208
-                    true
209
-                ),
210
-                'EVT_visible_on'                  => new EE_Datetime_Field(
211
-                    'EVT_visible_on',
212
-                    esc_html__('Event Visible Date', 'event_espresso'),
213
-                    true,
214
-                    EE_Datetime_Field::now
215
-                ),
216
-                'EVT_additional_limit'            => new EE_Integer_Field(
217
-                    'EVT_additional_limit',
218
-                    esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
219
-                    true,
220
-                    self::$_default_additional_limit
221
-                ),
222
-                'EVT_default_registration_status' => new EE_Enum_Text_Field(
223
-                    'EVT_default_registration_status',
224
-                    esc_html__('Default Registration Status on this Event', 'event_espresso'),
225
-                    false,
226
-                    EEM_Event::$_default_reg_status,
227
-                    EEM_Registration::reg_status_array()
228
-                ),
229
-                'EVT_member_only'                 => new EE_Boolean_Field(
230
-                    'EVT_member_only',
231
-                    esc_html__('Member-Only Event Flag', 'event_espresso'),
232
-                    false,
233
-                    false
234
-                ),
235
-                'EVT_phone'                       => new EE_Plain_Text_Field(
236
-                    'EVT_phone',
237
-                    esc_html__('Event Phone Number', 'event_espresso'),
238
-                    false,
239
-                    ''
240
-                ),
241
-                'EVT_allow_overflow'              => new EE_Boolean_Field(
242
-                    'EVT_allow_overflow',
243
-                    esc_html__('Allow Overflow on Event', 'event_espresso'),
244
-                    false,
245
-                    false
246
-                ),
247
-                'EVT_timezone_string'             => new EE_Plain_Text_Field(
248
-                    'EVT_timezone_string',
249
-                    esc_html__('Timezone (name) for Event times', 'event_espresso'),
250
-                    false,
251
-                    ''
252
-                ),
253
-                'EVT_external_URL'                => new EE_Plain_Text_Field(
254
-                    'EVT_external_URL',
255
-                    esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
256
-                    true
257
-                ),
258
-                'EVT_donations'                   => new EE_Boolean_Field(
259
-                    'EVT_donations',
260
-                    esc_html__('Accept Donations?', 'event_espresso'),
261
-                    false,
262
-                    false
263
-                ),
264
-            ),
265
-        );
266
-        $this->_model_relations = array(
267
-            'Registration'           => new EE_Has_Many_Relation(),
268
-            'Datetime'               => new EE_Has_Many_Relation(),
269
-            'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
270
-            'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
271
-            'Term_Relationship'      => new EE_Has_Many_Relation(),
272
-            'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
273
-            'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
274
-            'Attendee'               => new EE_HABTM_Relation('Registration'),
275
-            'WP_User'                => new EE_Belongs_To_Relation(),
276
-        );
277
-        // this model is generally available for reading
278
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
279
-        $this->model_chain_to_password = '';
280
-        parent::__construct($timezone);
281
-    }
282
-
283
-
284
-
285
-    /**
286
-     * @param string $default_reg_status
287
-     */
288
-    public static function set_default_reg_status($default_reg_status)
289
-    {
290
-        self::$_default_reg_status = $default_reg_status;
291
-        // if EEM_Event has already been instantiated,
292
-        // then we need to reset the `EVT_default_reg_status` field to use the new default.
293
-        if (self::$_instance instanceof EEM_Event) {
294
-            $default_reg_status = new EE_Enum_Text_Field(
295
-                'EVT_default_registration_status',
296
-                esc_html__('Default Registration Status on this Event', 'event_espresso'),
297
-                false,
298
-                $default_reg_status,
299
-                EEM_Registration::reg_status_array()
300
-            );
301
-            $default_reg_status->_construct_finalize(
302
-                'Event_Meta',
303
-                'EVT_default_registration_status',
304
-                'EEM_Event'
305
-            );
306
-            self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
307
-        }
308
-    }
309
-
310
-
311
-    /**
312
-     * Used to override the default for the additional limit field.
313
-     * @param $additional_limit
314
-     */
315
-    public static function set_default_additional_limit($additional_limit)
316
-    {
317
-        self::$_default_additional_limit = (int) $additional_limit;
318
-        if (self::$_instance instanceof EEM_Event) {
319
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
320
-                'EVT_additional_limit',
321
-                __('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
322
-                true,
323
-                self::$_default_additional_limit
324
-            );
325
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
326
-                'Event_Meta',
327
-                'EVT_additional_limit',
328
-                'EEM_Event'
329
-            );
330
-        }
331
-    }
332
-
333
-
334
-    /**
335
-     * Return what is currently set as the default additional limit for the event.
336
-     * @return int
337
-     */
338
-    public static function get_default_additional_limit()
339
-    {
340
-        return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
341
-    }
342
-
343
-
344
-    /**
345
-     * get_question_groups
346
-     *
347
-     * @return array
348
-     * @throws \EE_Error
349
-     */
350
-    public function get_all_question_groups()
351
-    {
352
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
353
-            array(
354
-                array('QSG_deleted' => false),
355
-                'order_by' => array('QSG_order' => 'ASC'),
356
-            )
357
-        );
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     * get_question_groups
364
-     *
365
-     * @param int $EVT_ID
366
-     * @return array|bool
367
-     * @throws \EE_Error
368
-     */
369
-    public function get_all_event_question_groups($EVT_ID = 0)
370
-    {
371
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
372
-            EE_Error::add_error(
373
-                esc_html__(
374
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
375
-                    'event_espresso'
376
-                ),
377
-                __FILE__,
378
-                __FUNCTION__,
379
-                __LINE__
380
-            );
381
-            return false;
382
-        }
383
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
384
-            array(
385
-                array('EVT_ID' => $EVT_ID),
386
-            )
387
-        );
388
-    }
389
-
390
-
391
-
392
-    /**
393
-     * get_question_groups
394
-     *
395
-     * @param int     $EVT_ID
396
-     * @param boolean $for_primary_attendee
397
-     * @return array|bool
398
-     * @throws \EE_Error
399
-     */
400
-    public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
401
-    {
402
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
403
-            EE_Error::add_error(
404
-                esc_html__(
405
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
406
-                    'event_espresso'
407
-                ),
408
-                __FILE__,
409
-                __FUNCTION__,
410
-                __LINE__
411
-            );
412
-            return false;
413
-        }
414
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
415
-            array(
416
-                array(
417
-                    'EVT_ID'      => $EVT_ID,
418
-                    'EQG_primary' => $for_primary_attendee,
419
-                ),
420
-            )
421
-        );
422
-    }
423
-
424
-
425
-
426
-    /**
427
-     * get_question_groups
428
-     *
429
-     * @param int             $EVT_ID
430
-     * @param EE_Registration $registration
431
-     * @return array|bool
432
-     * @throws \EE_Error
433
-     */
434
-    public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
435
-    {
436
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
437
-            EE_Error::add_error(
438
-                esc_html__(
439
-                    'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
440
-                    'event_espresso'
441
-                ),
442
-                __FILE__,
443
-                __FUNCTION__,
444
-                __LINE__
445
-            );
446
-            return false;
447
-        }
448
-        $where_params = array(
449
-            'Event_Question_Group.EVT_ID'      => $EVT_ID,
450
-            'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
451
-            'QSG_deleted'                      => false,
452
-        );
453
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
454
-            array(
455
-                $where_params,
456
-                'order_by' => array('QSG_order' => 'ASC'),
457
-            )
458
-        );
459
-    }
460
-
461
-
462
-
463
-    /**
464
-     * get_question_target_db_column
465
-     *
466
-     * @param string $QSG_IDs csv list of $QSG IDs
467
-     * @return array|bool
468
-     * @throws \EE_Error
469
-     */
470
-    public function get_questions_in_groups($QSG_IDs = '')
471
-    {
472
-        if (empty($QSG_IDs)) {
473
-            EE_Error::add_error(
474
-                esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
475
-                __FILE__,
476
-                __FUNCTION__,
477
-                __LINE__
478
-            );
479
-            return false;
480
-        }
481
-        return EE_Registry::instance()->load_model('Question')->get_all(
482
-            array(
483
-                array(
484
-                    'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
485
-                    'QST_deleted'           => false,
486
-                    'QST_admin_only'        => is_admin(),
487
-                ),
488
-                'order_by' => 'QST_order',
489
-            )
490
-        );
491
-    }
492
-
493
-
494
-
495
-    /**
496
-     * get_options_for_question
497
-     *
498
-     * @param string $QST_IDs csv list of $QST IDs
499
-     * @return array|bool
500
-     * @throws \EE_Error
501
-     */
502
-    public function get_options_for_question($QST_IDs)
503
-    {
504
-        if (empty($QST_IDs)) {
505
-            EE_Error::add_error(
506
-                esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
507
-                __FILE__,
508
-                __FUNCTION__,
509
-                __LINE__
510
-            );
511
-            return false;
512
-        }
513
-        return EE_Registry::instance()->load_model('Question_Option')->get_all(
514
-            array(
515
-                array(
516
-                    'Question.QST_ID' => array('IN', $QST_IDs),
517
-                    'QSO_deleted'     => false,
518
-                ),
519
-                'order_by' => 'QSO_ID',
520
-            )
521
-        );
522
-    }
523
-
524
-
525
-
526
-
527
-
528
-
529
-
530
-    /**
531
-     * Gets all events that are published
532
-     * and have event start time earlier than now and an event end time later than now
533
-     *
534
-     * @param  array $query_params An array of query params to further filter on
535
-     *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
536
-     * @param bool   $count        whether to return the count or not (default FALSE)
537
-     * @return EE_Event[]|int
538
-     * @throws \EE_Error
539
-     */
540
-    public function get_active_events($query_params, $count = false)
541
-    {
542
-        if (array_key_exists(0, $query_params)) {
543
-            $where_params = $query_params[0];
544
-            unset($query_params[0]);
545
-        } else {
546
-            $where_params = array();
547
-        }
548
-        // if we have count make sure we don't include group by
549
-        if ($count && isset($query_params['group_by'])) {
550
-            unset($query_params['group_by']);
551
-        }
552
-        // let's add specific query_params for active_events
553
-        // keep in mind this will override any sent status in the query AND any date queries.
554
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
555
-        // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
556
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
557
-            $where_params['Datetime.DTT_EVT_start******'] = array(
558
-                '<',
559
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
560
-            );
561
-        } else {
562
-            $where_params['Datetime.DTT_EVT_start'] = array(
563
-                '<',
564
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
565
-            );
566
-        }
567
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
568
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
569
-                '>',
570
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
571
-            );
572
-        } else {
573
-            $where_params['Datetime.DTT_EVT_end'] = array(
574
-                '>',
575
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
576
-            );
577
-        }
578
-        $query_params[0] = $where_params;
579
-        // don't use $query_params with count()
580
-        // because we don't want to include additional query clauses like "GROUP BY"
581
-        return $count
582
-            ? $this->count(array($where_params), 'EVT_ID', true)
583
-            : $this->get_all($query_params);
584
-    }
585
-
586
-
587
-
588
-    /**
589
-     * get all events that are published and have an event start time later than now
590
-     *
591
-     * @param  array $query_params An array of query params to further filter on
592
-     *                             (Note that status and DTT_EVT_start will be overridden)
593
-     * @param bool   $count        whether to return the count or not (default FALSE)
594
-     * @return EE_Event[]|int
595
-     * @throws \EE_Error
596
-     */
597
-    public function get_upcoming_events($query_params, $count = false)
598
-    {
599
-        if (array_key_exists(0, $query_params)) {
600
-            $where_params = $query_params[0];
601
-            unset($query_params[0]);
602
-        } else {
603
-            $where_params = array();
604
-        }
605
-        // if we have count make sure we don't include group by
606
-        if ($count && isset($query_params['group_by'])) {
607
-            unset($query_params['group_by']);
608
-        }
609
-        // let's add specific query_params for active_events
610
-        // keep in mind this will override any sent status in the query AND any date queries.
611
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
612
-        // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
613
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
614
-            $where_params['Datetime.DTT_EVT_start*****'] = array(
615
-                '>',
616
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
617
-            );
618
-        } else {
619
-            $where_params['Datetime.DTT_EVT_start'] = array(
620
-                '>',
621
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
622
-            );
623
-        }
624
-        $query_params[0] = $where_params;
625
-        // don't use $query_params with count()
626
-        // because we don't want to include additional query clauses like "GROUP BY"
627
-        return $count
628
-            ? $this->count(array($where_params), 'EVT_ID', true)
629
-            : $this->get_all($query_params);
630
-    }
631
-
632
-
633
-
634
-    /**
635
-     * Gets all events that are published
636
-     * and have an event end time later than now
637
-     *
638
-     * @param  array $query_params An array of query params to further filter on
639
-     *                             (note that status and DTT_EVT_end will be overridden)
640
-     * @param bool   $count        whether to return the count or not (default FALSE)
641
-     * @return EE_Event[]|int
642
-     * @throws \EE_Error
643
-     */
644
-    public function get_active_and_upcoming_events($query_params, $count = false)
645
-    {
646
-        if (array_key_exists(0, $query_params)) {
647
-            $where_params = $query_params[0];
648
-            unset($query_params[0]);
649
-        } else {
650
-            $where_params = array();
651
-        }
652
-        // if we have count make sure we don't include group by
653
-        if ($count && isset($query_params['group_by'])) {
654
-            unset($query_params['group_by']);
655
-        }
656
-        // let's add specific query_params for active_events
657
-        // keep in mind this will override any sent status in the query AND any date queries.
658
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
659
-        // add where params for DTT_EVT_end
660
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
661
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
662
-                '>',
663
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
664
-            );
665
-        } else {
666
-            $where_params['Datetime.DTT_EVT_end'] = array(
667
-                '>',
668
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
669
-            );
670
-        }
671
-        $query_params[0] = $where_params;
672
-        // don't use $query_params with count()
673
-        // because we don't want to include additional query clauses like "GROUP BY"
674
-        return $count
675
-            ? $this->count(array($where_params), 'EVT_ID', true)
676
-            : $this->get_all($query_params);
677
-    }
678
-
679
-
680
-
681
-    /**
682
-     * This only returns events that are expired.
683
-     * They may still be published but all their datetimes have expired.
684
-     *
685
-     * @param  array $query_params An array of query params to further filter on
686
-     *                             (note that status and DTT_EVT_end will be overridden)
687
-     * @param bool   $count        whether to return the count or not (default FALSE)
688
-     * @return EE_Event[]|int
689
-     * @throws \EE_Error
690
-     */
691
-    public function get_expired_events($query_params, $count = false)
692
-    {
693
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
694
-        // if we have count make sure we don't include group by
695
-        if ($count && isset($query_params['group_by'])) {
696
-            unset($query_params['group_by']);
697
-        }
698
-        // let's add specific query_params for active_events
699
-        // keep in mind this will override any sent status in the query AND any date queries.
700
-        if (isset($where_params['status'])) {
701
-            unset($where_params['status']);
702
-        }
703
-        $exclude_query = $query_params;
704
-        if (isset($exclude_query[0])) {
705
-            unset($exclude_query[0]);
706
-        }
707
-        $exclude_query[0] = array(
708
-            'Datetime.DTT_EVT_end' => array(
709
-                '>',
710
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
711
-            ),
712
-        );
713
-        // first get all events that have datetimes where its not expired.
714
-        $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
715
-        $event_ids = array_keys($event_ids);
716
-        // if we have any additional query_params, let's add them to the 'AND' condition
717
-        $and_condition = array(
718
-            'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
719
-            'EVT_ID'               => array('NOT IN', $event_ids),
720
-        );
721
-        if (isset($where_params['OR'])) {
722
-            $and_condition['OR'] = $where_params['OR'];
723
-            unset($where_params['OR']);
724
-        }
725
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
726
-            $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
727
-            unset($where_params['Datetime.DTT_EVT_end']);
728
-        }
729
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
730
-            $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
731
-            unset($where_params['Datetime.DTT_EVT_start']);
732
-        }
733
-        // merge remaining $where params with the and conditions.
734
-        $where_params['AND'] = array_merge($and_condition, $where_params);
735
-        $query_params[0] = $where_params;
736
-        // don't use $query_params with count()
737
-        // because we don't want to include additional query clauses like "GROUP BY"
738
-        return $count
739
-            ? $this->count(array($where_params), 'EVT_ID', true)
740
-            : $this->get_all($query_params);
741
-    }
742
-
743
-
744
-
745
-    /**
746
-     * This basically just returns the events that do not have the publish status.
747
-     *
748
-     * @param  array   $query_params An array of query params to further filter on
749
-     *                               (note that status will be overwritten)
750
-     * @param  boolean $count        whether to return the count or not (default FALSE)
751
-     * @return EE_Event[]|int
752
-     * @throws \EE_Error
753
-     */
754
-    public function get_inactive_events($query_params, $count = false)
755
-    {
756
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
757
-        // let's add in specific query_params for inactive events.
758
-        if (isset($where_params['status'])) {
759
-            unset($where_params['status']);
760
-        }
761
-        // if we have count make sure we don't include group by
762
-        if ($count && isset($query_params['group_by'])) {
763
-            unset($query_params['group_by']);
764
-        }
765
-        // if we have any additional query_params, let's add them to the 'AND' condition
766
-        $where_params['AND']['status'] = array('!=', 'publish');
767
-        if (isset($where_params['OR'])) {
768
-            $where_params['AND']['OR'] = $where_params['OR'];
769
-            unset($where_params['OR']);
770
-        }
771
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
772
-            $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
773
-            unset($where_params['Datetime.DTT_EVT_end']);
774
-        }
775
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
776
-            $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
777
-            unset($where_params['Datetime.DTT_EVT_start']);
778
-        }
779
-        $query_params[0] = $where_params;
780
-        // don't use $query_params with count()
781
-        // because we don't want to include additional query clauses like "GROUP BY"
782
-        return $count
783
-            ? $this->count(array($where_params), 'EVT_ID', true)
784
-            : $this->get_all($query_params);
785
-    }
786
-
787
-
788
-
789
-    /**
790
-     * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
791
-     * because we don't want to override any existing global default prices but instead insert NEW prices that get
792
-     * attached to the event. See parent for param descriptions
793
-     *
794
-     * @param        $id_or_obj
795
-     * @param        $other_model_id_or_obj
796
-     * @param string $relationName
797
-     * @param array  $where_query
798
-     * @return EE_Base_Class
799
-     * @throws EE_Error
800
-     */
801
-    public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
802
-    {
803
-        if ($relationName === 'Price') {
804
-            // let's get the PRC object for the given ID to make sure that we aren't dealing with a default
805
-            $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
806
-            // if EVT_ID = 0, then this is a default
807
-            if ((int) $prc_chk->get('EVT_ID') === 0) {
808
-                // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
809
-                $prc_chk->set('PRC_ID', 0);
810
-            }
811
-            // run parent
812
-            return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
813
-        }
814
-        // otherwise carry on as normal
815
-        return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
816
-    }
817
-
818
-
819
-
820
-    /******************** DEPRECATED METHODS ********************/
821
-
822
-
823
-
824
-    /**
825
-     * _get_question_target_db_column
826
-     *
827
-     * @deprecated as of 4.8.32.rc.001. Instead consider using
828
-     *             EE_Registration_Custom_Questions_Form located in
829
-     *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
830
-     * @access     public
831
-     * @param    EE_Registration $registration (so existing answers for registration are included)
832
-     * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
833
-     *                                         registration).
834
-     * @throws EE_Error
835
-     * @return    array
836
-     */
837
-    public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
838
-    {
839
-        if (empty($EVT_ID)) {
840
-            throw new EE_Error(__(
841
-                'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
842
-                'event_espresso'
843
-            ));
844
-        }
845
-        $questions = array();
846
-        // get all question groups for event
847
-        $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
848
-        if (! empty($qgs)) {
849
-            foreach ($qgs as $qg) {
850
-                $qsts = $qg->questions();
851
-                $questions[ $qg->ID() ] = $qg->model_field_array();
852
-                $questions[ $qg->ID() ]['QSG_questions'] = array();
853
-                foreach ($qsts as $qst) {
854
-                    if ($qst->is_system_question()) {
855
-                        continue;
856
-                    }
857
-                    $answer = EEM_Answer::instance()->get_one(array(
858
-                        array(
859
-                            'QST_ID' => $qst->ID(),
860
-                            'REG_ID' => $registration->ID(),
861
-                        ),
862
-                    ));
863
-                    $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
864
-                    $qst_name = $qstn_id = $qst->ID();
865
-                    $ans_id = $answer->ID();
866
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
867
-                    $input_name = '';
868
-                    $input_id = sanitize_key($qst->display_text());
869
-                    $input_class = '';
870
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
871
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
872
-                                                                                           . $input_name
873
-                                                                                           . $qst_name;
874
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
875
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
876
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
877
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
878
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
879
-                    // leave responses as-is, don't convert stuff into html entities please!
880
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
881
-                    if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
882
-                        $QSOs = $qst->options(true, $answer->value());
883
-                        if (is_array($QSOs)) {
884
-                            foreach ($QSOs as $QSO_ID => $QSO) {
885
-                                $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
886
-                            }
887
-                        }
888
-                    }
889
-                }
890
-            }
891
-        }
892
-        return $questions;
893
-    }
894
-
895
-
896
-    /**
897
-     * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
898
-     *                             or an stdClass where each property is the name of a column,
899
-     * @return EE_Base_Class
900
-     * @throws \EE_Error
901
-     */
902
-    public function instantiate_class_from_array_or_object($cols_n_values)
903
-    {
904
-        $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
905
-        if ($classInstance instanceof EE_Event) {
906
-            // events have their timezone defined in the DB, so use it immediately
907
-            $this->set_timezone($classInstance->get_timezone());
908
-        }
909
-        return $classInstance;
910
-    }
16
+	/**
17
+	 * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
18
+	 * event
19
+	 */
20
+	const sold_out = 'sold_out';
21
+
22
+	/**
23
+	 * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
24
+	 * date)
25
+	 */
26
+	const postponed = 'postponed';
27
+
28
+	/**
29
+	 * constant used by status(), indicating that the event will no longer occur
30
+	 */
31
+	const cancelled = 'cancelled';
32
+
33
+
34
+	/**
35
+	 * @var string
36
+	 */
37
+	protected static $_default_reg_status;
38
+
39
+
40
+	/**
41
+	 * This is the default for the additional limit field.
42
+	 * @var int
43
+	 */
44
+	protected static $_default_additional_limit = 10;
45
+
46
+
47
+	/**
48
+	 * private instance of the Event object
49
+	 *
50
+	 * @var EEM_Event
51
+	 */
52
+	protected static $_instance;
53
+
54
+
55
+
56
+
57
+	/**
58
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
59
+	 *
60
+	 * @param string $timezone
61
+	 * @throws \EE_Error
62
+	 */
63
+	protected function __construct($timezone = null)
64
+	{
65
+		EE_Registry::instance()->load_model('Registration');
66
+		$this->singular_item = esc_html__('Event', 'event_espresso');
67
+		$this->plural_item = esc_html__('Events', 'event_espresso');
68
+		// to remove Cancelled events from the frontend, copy the following filter to your functions.php file
69
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
70
+		// to remove Postponed events from the frontend, copy the following filter to your functions.php file
71
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
72
+		// to remove Sold Out events from the frontend, copy the following filter to your functions.php file
73
+		//  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
74
+		$this->_custom_stati = apply_filters(
75
+			'AFEE__EEM_Event__construct___custom_stati',
76
+			array(
77
+				EEM_Event::cancelled => array(
78
+					'label'  => esc_html__('Cancelled', 'event_espresso'),
79
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
80
+				),
81
+				EEM_Event::postponed => array(
82
+					'label'  => esc_html__('Postponed', 'event_espresso'),
83
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
84
+				),
85
+				EEM_Event::sold_out  => array(
86
+					'label'  => esc_html__('Sold Out', 'event_espresso'),
87
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
88
+				),
89
+			)
90
+		);
91
+		self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
92
+			: self::$_default_reg_status;
93
+		$this->_tables = array(
94
+			'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
95
+			'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
96
+		);
97
+		$this->_fields = array(
98
+			'Event_CPT'  => array(
99
+				'EVT_ID'         => new EE_Primary_Key_Int_Field(
100
+					'ID',
101
+					esc_html__('Post ID for Event', 'event_espresso')
102
+				),
103
+				'EVT_name'       => new EE_Plain_Text_Field(
104
+					'post_title',
105
+					esc_html__('Event Name', 'event_espresso'),
106
+					false,
107
+					''
108
+				),
109
+				'EVT_desc'       => new EE_Post_Content_Field(
110
+					'post_content',
111
+					esc_html__('Event Description', 'event_espresso'),
112
+					false,
113
+					''
114
+				),
115
+				'EVT_slug'       => new EE_Slug_Field(
116
+					'post_name',
117
+					esc_html__('Event Slug', 'event_espresso'),
118
+					false,
119
+					''
120
+				),
121
+				'EVT_created'    => new EE_Datetime_Field(
122
+					'post_date',
123
+					esc_html__('Date/Time Event Created', 'event_espresso'),
124
+					false,
125
+					EE_Datetime_Field::now
126
+				),
127
+				'EVT_short_desc' => new EE_Simple_HTML_Field(
128
+					'post_excerpt',
129
+					esc_html__('Event Short Description', 'event_espresso'),
130
+					false,
131
+					''
132
+				),
133
+				'EVT_modified'   => new EE_Datetime_Field(
134
+					'post_modified',
135
+					esc_html__('Date/Time Event Modified', 'event_espresso'),
136
+					false,
137
+					EE_Datetime_Field::now
138
+				),
139
+				'EVT_wp_user'    => new EE_WP_User_Field(
140
+					'post_author',
141
+					esc_html__('Event Creator ID', 'event_espresso'),
142
+					false
143
+				),
144
+				'parent'         => new EE_Integer_Field(
145
+					'post_parent',
146
+					esc_html__('Event Parent ID', 'event_espresso'),
147
+					false,
148
+					0
149
+				),
150
+				'EVT_order'      => new EE_Integer_Field(
151
+					'menu_order',
152
+					esc_html__('Event Menu Order', 'event_espresso'),
153
+					false,
154
+					1
155
+				),
156
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
157
+				// EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
158
+				'status'         => new EE_WP_Post_Status_Field(
159
+					'post_status',
160
+					esc_html__('Event Status', 'event_espresso'),
161
+					false,
162
+					'draft',
163
+					$this->_custom_stati
164
+				),
165
+				'password' => new EE_Password_Field(
166
+					'post_password',
167
+					__('Password', 'event_espresso'),
168
+					false,
169
+					'',
170
+					array(
171
+						'EVT_desc',
172
+						'EVT_short_desc',
173
+						'EVT_display_desc',
174
+						'EVT_display_ticket_selector',
175
+						'EVT_visible_on',
176
+						'EVT_additional_limit',
177
+						'EVT_default_registration_status',
178
+						'EVT_member_only',
179
+						'EVT_phone',
180
+						'EVT_allow_overflow',
181
+						'EVT_timezone_string',
182
+						'EVT_external_URL',
183
+						'EVT_donations'
184
+					)
185
+				)
186
+			),
187
+			'Event_Meta' => array(
188
+				'EVTM_ID'                         => new EE_DB_Only_Float_Field(
189
+					'EVTM_ID',
190
+					esc_html__('Event Meta Row ID', 'event_espresso'),
191
+					false
192
+				),
193
+				'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
194
+					'EVT_ID',
195
+					esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
196
+					false
197
+				),
198
+				'EVT_display_desc'                => new EE_Boolean_Field(
199
+					'EVT_display_desc',
200
+					esc_html__('Display Description Flag', 'event_espresso'),
201
+					false,
202
+					true
203
+				),
204
+				'EVT_display_ticket_selector'     => new EE_Boolean_Field(
205
+					'EVT_display_ticket_selector',
206
+					esc_html__('Display Ticket Selector Flag', 'event_espresso'),
207
+					false,
208
+					true
209
+				),
210
+				'EVT_visible_on'                  => new EE_Datetime_Field(
211
+					'EVT_visible_on',
212
+					esc_html__('Event Visible Date', 'event_espresso'),
213
+					true,
214
+					EE_Datetime_Field::now
215
+				),
216
+				'EVT_additional_limit'            => new EE_Integer_Field(
217
+					'EVT_additional_limit',
218
+					esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
219
+					true,
220
+					self::$_default_additional_limit
221
+				),
222
+				'EVT_default_registration_status' => new EE_Enum_Text_Field(
223
+					'EVT_default_registration_status',
224
+					esc_html__('Default Registration Status on this Event', 'event_espresso'),
225
+					false,
226
+					EEM_Event::$_default_reg_status,
227
+					EEM_Registration::reg_status_array()
228
+				),
229
+				'EVT_member_only'                 => new EE_Boolean_Field(
230
+					'EVT_member_only',
231
+					esc_html__('Member-Only Event Flag', 'event_espresso'),
232
+					false,
233
+					false
234
+				),
235
+				'EVT_phone'                       => new EE_Plain_Text_Field(
236
+					'EVT_phone',
237
+					esc_html__('Event Phone Number', 'event_espresso'),
238
+					false,
239
+					''
240
+				),
241
+				'EVT_allow_overflow'              => new EE_Boolean_Field(
242
+					'EVT_allow_overflow',
243
+					esc_html__('Allow Overflow on Event', 'event_espresso'),
244
+					false,
245
+					false
246
+				),
247
+				'EVT_timezone_string'             => new EE_Plain_Text_Field(
248
+					'EVT_timezone_string',
249
+					esc_html__('Timezone (name) for Event times', 'event_espresso'),
250
+					false,
251
+					''
252
+				),
253
+				'EVT_external_URL'                => new EE_Plain_Text_Field(
254
+					'EVT_external_URL',
255
+					esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
256
+					true
257
+				),
258
+				'EVT_donations'                   => new EE_Boolean_Field(
259
+					'EVT_donations',
260
+					esc_html__('Accept Donations?', 'event_espresso'),
261
+					false,
262
+					false
263
+				),
264
+			),
265
+		);
266
+		$this->_model_relations = array(
267
+			'Registration'           => new EE_Has_Many_Relation(),
268
+			'Datetime'               => new EE_Has_Many_Relation(),
269
+			'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
270
+			'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
271
+			'Term_Relationship'      => new EE_Has_Many_Relation(),
272
+			'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
273
+			'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
274
+			'Attendee'               => new EE_HABTM_Relation('Registration'),
275
+			'WP_User'                => new EE_Belongs_To_Relation(),
276
+		);
277
+		// this model is generally available for reading
278
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
279
+		$this->model_chain_to_password = '';
280
+		parent::__construct($timezone);
281
+	}
282
+
283
+
284
+
285
+	/**
286
+	 * @param string $default_reg_status
287
+	 */
288
+	public static function set_default_reg_status($default_reg_status)
289
+	{
290
+		self::$_default_reg_status = $default_reg_status;
291
+		// if EEM_Event has already been instantiated,
292
+		// then we need to reset the `EVT_default_reg_status` field to use the new default.
293
+		if (self::$_instance instanceof EEM_Event) {
294
+			$default_reg_status = new EE_Enum_Text_Field(
295
+				'EVT_default_registration_status',
296
+				esc_html__('Default Registration Status on this Event', 'event_espresso'),
297
+				false,
298
+				$default_reg_status,
299
+				EEM_Registration::reg_status_array()
300
+			);
301
+			$default_reg_status->_construct_finalize(
302
+				'Event_Meta',
303
+				'EVT_default_registration_status',
304
+				'EEM_Event'
305
+			);
306
+			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
307
+		}
308
+	}
309
+
310
+
311
+	/**
312
+	 * Used to override the default for the additional limit field.
313
+	 * @param $additional_limit
314
+	 */
315
+	public static function set_default_additional_limit($additional_limit)
316
+	{
317
+		self::$_default_additional_limit = (int) $additional_limit;
318
+		if (self::$_instance instanceof EEM_Event) {
319
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
320
+				'EVT_additional_limit',
321
+				__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
322
+				true,
323
+				self::$_default_additional_limit
324
+			);
325
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
326
+				'Event_Meta',
327
+				'EVT_additional_limit',
328
+				'EEM_Event'
329
+			);
330
+		}
331
+	}
332
+
333
+
334
+	/**
335
+	 * Return what is currently set as the default additional limit for the event.
336
+	 * @return int
337
+	 */
338
+	public static function get_default_additional_limit()
339
+	{
340
+		return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
341
+	}
342
+
343
+
344
+	/**
345
+	 * get_question_groups
346
+	 *
347
+	 * @return array
348
+	 * @throws \EE_Error
349
+	 */
350
+	public function get_all_question_groups()
351
+	{
352
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
353
+			array(
354
+				array('QSG_deleted' => false),
355
+				'order_by' => array('QSG_order' => 'ASC'),
356
+			)
357
+		);
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 * get_question_groups
364
+	 *
365
+	 * @param int $EVT_ID
366
+	 * @return array|bool
367
+	 * @throws \EE_Error
368
+	 */
369
+	public function get_all_event_question_groups($EVT_ID = 0)
370
+	{
371
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
372
+			EE_Error::add_error(
373
+				esc_html__(
374
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
375
+					'event_espresso'
376
+				),
377
+				__FILE__,
378
+				__FUNCTION__,
379
+				__LINE__
380
+			);
381
+			return false;
382
+		}
383
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
384
+			array(
385
+				array('EVT_ID' => $EVT_ID),
386
+			)
387
+		);
388
+	}
389
+
390
+
391
+
392
+	/**
393
+	 * get_question_groups
394
+	 *
395
+	 * @param int     $EVT_ID
396
+	 * @param boolean $for_primary_attendee
397
+	 * @return array|bool
398
+	 * @throws \EE_Error
399
+	 */
400
+	public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
401
+	{
402
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
403
+			EE_Error::add_error(
404
+				esc_html__(
405
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
406
+					'event_espresso'
407
+				),
408
+				__FILE__,
409
+				__FUNCTION__,
410
+				__LINE__
411
+			);
412
+			return false;
413
+		}
414
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
415
+			array(
416
+				array(
417
+					'EVT_ID'      => $EVT_ID,
418
+					'EQG_primary' => $for_primary_attendee,
419
+				),
420
+			)
421
+		);
422
+	}
423
+
424
+
425
+
426
+	/**
427
+	 * get_question_groups
428
+	 *
429
+	 * @param int             $EVT_ID
430
+	 * @param EE_Registration $registration
431
+	 * @return array|bool
432
+	 * @throws \EE_Error
433
+	 */
434
+	public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
435
+	{
436
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
437
+			EE_Error::add_error(
438
+				esc_html__(
439
+					'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
440
+					'event_espresso'
441
+				),
442
+				__FILE__,
443
+				__FUNCTION__,
444
+				__LINE__
445
+			);
446
+			return false;
447
+		}
448
+		$where_params = array(
449
+			'Event_Question_Group.EVT_ID'      => $EVT_ID,
450
+			'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
451
+			'QSG_deleted'                      => false,
452
+		);
453
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
454
+			array(
455
+				$where_params,
456
+				'order_by' => array('QSG_order' => 'ASC'),
457
+			)
458
+		);
459
+	}
460
+
461
+
462
+
463
+	/**
464
+	 * get_question_target_db_column
465
+	 *
466
+	 * @param string $QSG_IDs csv list of $QSG IDs
467
+	 * @return array|bool
468
+	 * @throws \EE_Error
469
+	 */
470
+	public function get_questions_in_groups($QSG_IDs = '')
471
+	{
472
+		if (empty($QSG_IDs)) {
473
+			EE_Error::add_error(
474
+				esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
475
+				__FILE__,
476
+				__FUNCTION__,
477
+				__LINE__
478
+			);
479
+			return false;
480
+		}
481
+		return EE_Registry::instance()->load_model('Question')->get_all(
482
+			array(
483
+				array(
484
+					'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
485
+					'QST_deleted'           => false,
486
+					'QST_admin_only'        => is_admin(),
487
+				),
488
+				'order_by' => 'QST_order',
489
+			)
490
+		);
491
+	}
492
+
493
+
494
+
495
+	/**
496
+	 * get_options_for_question
497
+	 *
498
+	 * @param string $QST_IDs csv list of $QST IDs
499
+	 * @return array|bool
500
+	 * @throws \EE_Error
501
+	 */
502
+	public function get_options_for_question($QST_IDs)
503
+	{
504
+		if (empty($QST_IDs)) {
505
+			EE_Error::add_error(
506
+				esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
507
+				__FILE__,
508
+				__FUNCTION__,
509
+				__LINE__
510
+			);
511
+			return false;
512
+		}
513
+		return EE_Registry::instance()->load_model('Question_Option')->get_all(
514
+			array(
515
+				array(
516
+					'Question.QST_ID' => array('IN', $QST_IDs),
517
+					'QSO_deleted'     => false,
518
+				),
519
+				'order_by' => 'QSO_ID',
520
+			)
521
+		);
522
+	}
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+	/**
531
+	 * Gets all events that are published
532
+	 * and have event start time earlier than now and an event end time later than now
533
+	 *
534
+	 * @param  array $query_params An array of query params to further filter on
535
+	 *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
536
+	 * @param bool   $count        whether to return the count or not (default FALSE)
537
+	 * @return EE_Event[]|int
538
+	 * @throws \EE_Error
539
+	 */
540
+	public function get_active_events($query_params, $count = false)
541
+	{
542
+		if (array_key_exists(0, $query_params)) {
543
+			$where_params = $query_params[0];
544
+			unset($query_params[0]);
545
+		} else {
546
+			$where_params = array();
547
+		}
548
+		// if we have count make sure we don't include group by
549
+		if ($count && isset($query_params['group_by'])) {
550
+			unset($query_params['group_by']);
551
+		}
552
+		// let's add specific query_params for active_events
553
+		// keep in mind this will override any sent status in the query AND any date queries.
554
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
555
+		// if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
556
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
557
+			$where_params['Datetime.DTT_EVT_start******'] = array(
558
+				'<',
559
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
560
+			);
561
+		} else {
562
+			$where_params['Datetime.DTT_EVT_start'] = array(
563
+				'<',
564
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
565
+			);
566
+		}
567
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
568
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
569
+				'>',
570
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
571
+			);
572
+		} else {
573
+			$where_params['Datetime.DTT_EVT_end'] = array(
574
+				'>',
575
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
576
+			);
577
+		}
578
+		$query_params[0] = $where_params;
579
+		// don't use $query_params with count()
580
+		// because we don't want to include additional query clauses like "GROUP BY"
581
+		return $count
582
+			? $this->count(array($where_params), 'EVT_ID', true)
583
+			: $this->get_all($query_params);
584
+	}
585
+
586
+
587
+
588
+	/**
589
+	 * get all events that are published and have an event start time later than now
590
+	 *
591
+	 * @param  array $query_params An array of query params to further filter on
592
+	 *                             (Note that status and DTT_EVT_start will be overridden)
593
+	 * @param bool   $count        whether to return the count or not (default FALSE)
594
+	 * @return EE_Event[]|int
595
+	 * @throws \EE_Error
596
+	 */
597
+	public function get_upcoming_events($query_params, $count = false)
598
+	{
599
+		if (array_key_exists(0, $query_params)) {
600
+			$where_params = $query_params[0];
601
+			unset($query_params[0]);
602
+		} else {
603
+			$where_params = array();
604
+		}
605
+		// if we have count make sure we don't include group by
606
+		if ($count && isset($query_params['group_by'])) {
607
+			unset($query_params['group_by']);
608
+		}
609
+		// let's add specific query_params for active_events
610
+		// keep in mind this will override any sent status in the query AND any date queries.
611
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
612
+		// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
613
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
614
+			$where_params['Datetime.DTT_EVT_start*****'] = array(
615
+				'>',
616
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
617
+			);
618
+		} else {
619
+			$where_params['Datetime.DTT_EVT_start'] = array(
620
+				'>',
621
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
622
+			);
623
+		}
624
+		$query_params[0] = $where_params;
625
+		// don't use $query_params with count()
626
+		// because we don't want to include additional query clauses like "GROUP BY"
627
+		return $count
628
+			? $this->count(array($where_params), 'EVT_ID', true)
629
+			: $this->get_all($query_params);
630
+	}
631
+
632
+
633
+
634
+	/**
635
+	 * Gets all events that are published
636
+	 * and have an event end time later than now
637
+	 *
638
+	 * @param  array $query_params An array of query params to further filter on
639
+	 *                             (note that status and DTT_EVT_end will be overridden)
640
+	 * @param bool   $count        whether to return the count or not (default FALSE)
641
+	 * @return EE_Event[]|int
642
+	 * @throws \EE_Error
643
+	 */
644
+	public function get_active_and_upcoming_events($query_params, $count = false)
645
+	{
646
+		if (array_key_exists(0, $query_params)) {
647
+			$where_params = $query_params[0];
648
+			unset($query_params[0]);
649
+		} else {
650
+			$where_params = array();
651
+		}
652
+		// if we have count make sure we don't include group by
653
+		if ($count && isset($query_params['group_by'])) {
654
+			unset($query_params['group_by']);
655
+		}
656
+		// let's add specific query_params for active_events
657
+		// keep in mind this will override any sent status in the query AND any date queries.
658
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
659
+		// add where params for DTT_EVT_end
660
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
661
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
662
+				'>',
663
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
664
+			);
665
+		} else {
666
+			$where_params['Datetime.DTT_EVT_end'] = array(
667
+				'>',
668
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
669
+			);
670
+		}
671
+		$query_params[0] = $where_params;
672
+		// don't use $query_params with count()
673
+		// because we don't want to include additional query clauses like "GROUP BY"
674
+		return $count
675
+			? $this->count(array($where_params), 'EVT_ID', true)
676
+			: $this->get_all($query_params);
677
+	}
678
+
679
+
680
+
681
+	/**
682
+	 * This only returns events that are expired.
683
+	 * They may still be published but all their datetimes have expired.
684
+	 *
685
+	 * @param  array $query_params An array of query params to further filter on
686
+	 *                             (note that status and DTT_EVT_end will be overridden)
687
+	 * @param bool   $count        whether to return the count or not (default FALSE)
688
+	 * @return EE_Event[]|int
689
+	 * @throws \EE_Error
690
+	 */
691
+	public function get_expired_events($query_params, $count = false)
692
+	{
693
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
694
+		// if we have count make sure we don't include group by
695
+		if ($count && isset($query_params['group_by'])) {
696
+			unset($query_params['group_by']);
697
+		}
698
+		// let's add specific query_params for active_events
699
+		// keep in mind this will override any sent status in the query AND any date queries.
700
+		if (isset($where_params['status'])) {
701
+			unset($where_params['status']);
702
+		}
703
+		$exclude_query = $query_params;
704
+		if (isset($exclude_query[0])) {
705
+			unset($exclude_query[0]);
706
+		}
707
+		$exclude_query[0] = array(
708
+			'Datetime.DTT_EVT_end' => array(
709
+				'>',
710
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
711
+			),
712
+		);
713
+		// first get all events that have datetimes where its not expired.
714
+		$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
715
+		$event_ids = array_keys($event_ids);
716
+		// if we have any additional query_params, let's add them to the 'AND' condition
717
+		$and_condition = array(
718
+			'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
719
+			'EVT_ID'               => array('NOT IN', $event_ids),
720
+		);
721
+		if (isset($where_params['OR'])) {
722
+			$and_condition['OR'] = $where_params['OR'];
723
+			unset($where_params['OR']);
724
+		}
725
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
726
+			$and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
727
+			unset($where_params['Datetime.DTT_EVT_end']);
728
+		}
729
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
730
+			$and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
731
+			unset($where_params['Datetime.DTT_EVT_start']);
732
+		}
733
+		// merge remaining $where params with the and conditions.
734
+		$where_params['AND'] = array_merge($and_condition, $where_params);
735
+		$query_params[0] = $where_params;
736
+		// don't use $query_params with count()
737
+		// because we don't want to include additional query clauses like "GROUP BY"
738
+		return $count
739
+			? $this->count(array($where_params), 'EVT_ID', true)
740
+			: $this->get_all($query_params);
741
+	}
742
+
743
+
744
+
745
+	/**
746
+	 * This basically just returns the events that do not have the publish status.
747
+	 *
748
+	 * @param  array   $query_params An array of query params to further filter on
749
+	 *                               (note that status will be overwritten)
750
+	 * @param  boolean $count        whether to return the count or not (default FALSE)
751
+	 * @return EE_Event[]|int
752
+	 * @throws \EE_Error
753
+	 */
754
+	public function get_inactive_events($query_params, $count = false)
755
+	{
756
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
757
+		// let's add in specific query_params for inactive events.
758
+		if (isset($where_params['status'])) {
759
+			unset($where_params['status']);
760
+		}
761
+		// if we have count make sure we don't include group by
762
+		if ($count && isset($query_params['group_by'])) {
763
+			unset($query_params['group_by']);
764
+		}
765
+		// if we have any additional query_params, let's add them to the 'AND' condition
766
+		$where_params['AND']['status'] = array('!=', 'publish');
767
+		if (isset($where_params['OR'])) {
768
+			$where_params['AND']['OR'] = $where_params['OR'];
769
+			unset($where_params['OR']);
770
+		}
771
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
772
+			$where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
773
+			unset($where_params['Datetime.DTT_EVT_end']);
774
+		}
775
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
776
+			$where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
777
+			unset($where_params['Datetime.DTT_EVT_start']);
778
+		}
779
+		$query_params[0] = $where_params;
780
+		// don't use $query_params with count()
781
+		// because we don't want to include additional query clauses like "GROUP BY"
782
+		return $count
783
+			? $this->count(array($where_params), 'EVT_ID', true)
784
+			: $this->get_all($query_params);
785
+	}
786
+
787
+
788
+
789
+	/**
790
+	 * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
791
+	 * because we don't want to override any existing global default prices but instead insert NEW prices that get
792
+	 * attached to the event. See parent for param descriptions
793
+	 *
794
+	 * @param        $id_or_obj
795
+	 * @param        $other_model_id_or_obj
796
+	 * @param string $relationName
797
+	 * @param array  $where_query
798
+	 * @return EE_Base_Class
799
+	 * @throws EE_Error
800
+	 */
801
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
802
+	{
803
+		if ($relationName === 'Price') {
804
+			// let's get the PRC object for the given ID to make sure that we aren't dealing with a default
805
+			$prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
806
+			// if EVT_ID = 0, then this is a default
807
+			if ((int) $prc_chk->get('EVT_ID') === 0) {
808
+				// let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
809
+				$prc_chk->set('PRC_ID', 0);
810
+			}
811
+			// run parent
812
+			return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
813
+		}
814
+		// otherwise carry on as normal
815
+		return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
816
+	}
817
+
818
+
819
+
820
+	/******************** DEPRECATED METHODS ********************/
821
+
822
+
823
+
824
+	/**
825
+	 * _get_question_target_db_column
826
+	 *
827
+	 * @deprecated as of 4.8.32.rc.001. Instead consider using
828
+	 *             EE_Registration_Custom_Questions_Form located in
829
+	 *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
830
+	 * @access     public
831
+	 * @param    EE_Registration $registration (so existing answers for registration are included)
832
+	 * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
833
+	 *                                         registration).
834
+	 * @throws EE_Error
835
+	 * @return    array
836
+	 */
837
+	public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
838
+	{
839
+		if (empty($EVT_ID)) {
840
+			throw new EE_Error(__(
841
+				'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
842
+				'event_espresso'
843
+			));
844
+		}
845
+		$questions = array();
846
+		// get all question groups for event
847
+		$qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
848
+		if (! empty($qgs)) {
849
+			foreach ($qgs as $qg) {
850
+				$qsts = $qg->questions();
851
+				$questions[ $qg->ID() ] = $qg->model_field_array();
852
+				$questions[ $qg->ID() ]['QSG_questions'] = array();
853
+				foreach ($qsts as $qst) {
854
+					if ($qst->is_system_question()) {
855
+						continue;
856
+					}
857
+					$answer = EEM_Answer::instance()->get_one(array(
858
+						array(
859
+							'QST_ID' => $qst->ID(),
860
+							'REG_ID' => $registration->ID(),
861
+						),
862
+					));
863
+					$answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
864
+					$qst_name = $qstn_id = $qst->ID();
865
+					$ans_id = $answer->ID();
866
+					$qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
867
+					$input_name = '';
868
+					$input_id = sanitize_key($qst->display_text());
869
+					$input_class = '';
870
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
871
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
872
+																						   . $input_name
873
+																						   . $qst_name;
874
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
875
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
876
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
877
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
878
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
879
+					// leave responses as-is, don't convert stuff into html entities please!
880
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
881
+					if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
882
+						$QSOs = $qst->options(true, $answer->value());
883
+						if (is_array($QSOs)) {
884
+							foreach ($QSOs as $QSO_ID => $QSO) {
885
+								$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
886
+							}
887
+						}
888
+					}
889
+				}
890
+			}
891
+		}
892
+		return $questions;
893
+	}
894
+
895
+
896
+	/**
897
+	 * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
898
+	 *                             or an stdClass where each property is the name of a column,
899
+	 * @return EE_Base_Class
900
+	 * @throws \EE_Error
901
+	 */
902
+	public function instantiate_class_from_array_or_object($cols_n_values)
903
+	{
904
+		$classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
905
+		if ($classInstance instanceof EE_Event) {
906
+			// events have their timezone defined in the DB, so use it immediately
907
+			$this->set_timezone($classInstance->get_timezone());
908
+		}
909
+		return $classInstance;
910
+	}
911 911
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
             'WP_User'                => new EE_Belongs_To_Relation(),
276 276
         );
277 277
         // this model is generally available for reading
278
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
278
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
279 279
         $this->model_chain_to_password = '';
280 280
         parent::__construct($timezone);
281 281
     }
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
      */
369 369
     public function get_all_event_question_groups($EVT_ID = 0)
370 370
     {
371
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
371
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
372 372
             EE_Error::add_error(
373 373
                 esc_html__(
374 374
                     'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
      */
400 400
     public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
401 401
     {
402
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
402
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
403 403
             EE_Error::add_error(
404 404
                 esc_html__(
405 405
                     'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
      */
434 434
     public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
435 435
     {
436
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
436
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
437 437
             EE_Error::add_error(
438 438
                 esc_html__(
439 439
                     'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
@@ -845,11 +845,11 @@  discard block
 block discarded – undo
845 845
         $questions = array();
846 846
         // get all question groups for event
847 847
         $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
848
-        if (! empty($qgs)) {
848
+        if ( ! empty($qgs)) {
849 849
             foreach ($qgs as $qg) {
850 850
                 $qsts = $qg->questions();
851
-                $questions[ $qg->ID() ] = $qg->model_field_array();
852
-                $questions[ $qg->ID() ]['QSG_questions'] = array();
851
+                $questions[$qg->ID()] = $qg->model_field_array();
852
+                $questions[$qg->ID()]['QSG_questions'] = array();
853 853
                 foreach ($qsts as $qst) {
854 854
                     if ($qst->is_system_question()) {
855 855
                         continue;
@@ -863,26 +863,26 @@  discard block
 block discarded – undo
863 863
                     $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
864 864
                     $qst_name = $qstn_id = $qst->ID();
865 865
                     $ans_id = $answer->ID();
866
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
866
+                    $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']';
867 867
                     $input_name = '';
868 868
                     $input_id = sanitize_key($qst->display_text());
869 869
                     $input_class = '';
870
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
871
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
870
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array();
871
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
872 872
                                                                                            . $input_name
873 873
                                                                                            . $qst_name;
874
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
875
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
876
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
877
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
878
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
874
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id;
875
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
876
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
877
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
878
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer;
879 879
                     // leave responses as-is, don't convert stuff into html entities please!
880
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
880
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
881 881
                     if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
882 882
                         $QSOs = $qst->options(true, $answer->value());
883 883
                         if (is_array($QSOs)) {
884 884
                             foreach ($QSOs as $QSO_ID => $QSO) {
885
-                                $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
885
+                                $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array();
886 886
                             }
887 887
                         }
888 888
                     }
Please login to merge, or discard this patch.
core/db_models/EEM_Venue.model.php 2 patches
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -10,189 +10,189 @@
 block discarded – undo
10 10
 class EEM_Venue extends EEM_CPT_Base
11 11
 {
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 17
 
18
-    protected function __construct($timezone = null)
19
-    {
20
-        $this->singular_item = __('Venue', 'event_espresso');
21
-        $this->plural_item = __('Venues', 'event_espresso');
22
-        $this->_tables = array(
23
-            'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
24
-            'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
25
-        );
26
-        $this->_fields = array(
27
-            'Venue_CPT'  => array(
28
-                'VNU_ID'         => new EE_Primary_Key_Int_Field('ID', __("Venue ID", "event_espresso")),
29
-                'VNU_name'       => new EE_Plain_Text_Field(
30
-                    'post_title',
31
-                    __("Venue Name", "event_espresso"),
32
-                    false,
33
-                    ''
34
-                ),
35
-                'VNU_desc'       => new EE_Post_Content_Field(
36
-                    'post_content',
37
-                    __("Venue Description", "event_espresso"),
38
-                    false,
39
-                    ''
40
-                ),
41
-                'VNU_identifier' => new EE_Slug_Field('post_name', __("Venue Identifier", "event_espresso"), false, ''),
42
-                'VNU_created'    => new EE_Datetime_Field(
43
-                    'post_date',
44
-                    __("Date Venue Created", "event_espresso"),
45
-                    false,
46
-                    EE_Datetime_Field::now
47
-                ),
48
-                'VNU_short_desc' => new EE_Plain_Text_Field(
49
-                    'post_excerpt',
50
-                    __("Short Description of Venue", "event_espresso"),
51
-                    true,
52
-                    ''
53
-                ),
54
-                'VNU_modified'   => new EE_Datetime_Field(
55
-                    'post_modified',
56
-                    __("Venue Modified Date", "event_espresso"),
57
-                    false,
58
-                    EE_Datetime_Field::now
59
-                ),
60
-                'VNU_wp_user'    => new EE_WP_User_Field(
61
-                    'post_author',
62
-                    __("Venue Creator ID", "event_espresso"),
63
-                    false
64
-                ),
65
-                'parent'         => new EE_Integer_Field(
66
-                    'post_parent',
67
-                    __("Venue Parent ID", "event_espresso"),
68
-                    false,
69
-                    0
70
-                ),
71
-                'VNU_order'      => new EE_Integer_Field('menu_order', __("Venue order", "event_espresso"), false, 1),
72
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
73
-                'password' => new EE_Password_Field(
74
-                    'post_password',
75
-                    __('Password', 'event_espresso'),
76
-                    false,
77
-                    '',
78
-                    array(
79
-                        'VNU_desc',
80
-                        'VNU_short_desc',
81
-                        'VNU_address',
82
-                        'VNU_address2',
83
-                        'VNU_city',
84
-                        'STA_ID',
85
-                        'CNT_ISO',
86
-                        'VNU_zip',
87
-                        'VNU_phone',
88
-                        'VNU_capacity',
89
-                        'VNU_url',
90
-                        'VNU_virtual_phone',
91
-                        'VNU_virtual_url',
92
-                        'VNU_google_map_link',
93
-                        'VNU_enable_for_gmap',
94
-                    )
95
-                )
96
-            ),
97
-            'Venue_Meta' => array(
98
-                'VNUM_ID'             => new EE_DB_Only_Int_Field(
99
-                    'VNUM_ID',
100
-                    __("ID of Venue Meta Row", "event_espresso"),
101
-                    false
102
-                ),
103
-                'VNU_ID_fk'           => new EE_DB_Only_Int_Field(
104
-                    'VNU_ID',
105
-                    __("Foreign Key to Venue Post ", "event_espresso"),
106
-                    false
107
-                ),
108
-                'VNU_address'         => new EE_Plain_Text_Field(
109
-                    'VNU_address',
110
-                    __("Venue Address line 1", "event_espresso"),
111
-                    true,
112
-                    ''
113
-                ),
114
-                'VNU_address2'        => new EE_Plain_Text_Field(
115
-                    'VNU_address2',
116
-                    __("Venue Address line 2", "event_espresso"),
117
-                    true,
118
-                    ''
119
-                ),
120
-                'VNU_city'            => new EE_Plain_Text_Field(
121
-                    'VNU_city',
122
-                    __("Venue City", "event_espresso"),
123
-                    true,
124
-                    ''
125
-                ),
126
-                'STA_ID'              => new EE_Foreign_Key_Int_Field(
127
-                    'STA_ID',
128
-                    __("State ID", "event_espresso"),
129
-                    true,
130
-                    null,
131
-                    'State'
132
-                ),
133
-                'CNT_ISO'             => new EE_Foreign_Key_String_Field(
134
-                    'CNT_ISO',
135
-                    __("Country Code", "event_espresso"),
136
-                    true,
137
-                    null,
138
-                    'Country'
139
-                ),
140
-                'VNU_zip'             => new EE_Plain_Text_Field(
141
-                    'VNU_zip',
142
-                    __("Venue Zip/Postal Code", "event_espresso"),
143
-                    true
144
-                ),
145
-                'VNU_phone'           => new EE_Plain_Text_Field(
146
-                    'VNU_phone',
147
-                    __("Venue Phone", "event_espresso"),
148
-                    true
149
-                ),
150
-                'VNU_capacity'        => new EE_Infinite_Integer_Field(
151
-                    'VNU_capacity',
152
-                    __("Venue Capacity", "event_espresso"),
153
-                    true,
154
-                    EE_INF
155
-                ),
156
-                'VNU_url'             => new EE_Plain_Text_Field(
157
-                    'VNU_url',
158
-                    __('Venue Website', 'event_espresso'),
159
-                    true
160
-                ),
161
-                'VNU_virtual_phone'   => new EE_Plain_Text_Field(
162
-                    'VNU_virtual_phone',
163
-                    __('Call in Number', 'event_espresso'),
164
-                    true
165
-                ),
166
-                'VNU_virtual_url'     => new EE_Plain_Text_Field(
167
-                    'VNU_virtual_url',
168
-                    __('Virtual URL', 'event_espresso'),
169
-                    true
170
-                ),
171
-                'VNU_google_map_link' => new EE_Plain_Text_Field(
172
-                    'VNU_google_map_link',
173
-                    __('Google Map Link', 'event_espresso'),
174
-                    true
175
-                ),
176
-                'VNU_enable_for_gmap' => new EE_Boolean_Field(
177
-                    'VNU_enable_for_gmap',
178
-                    __('Show Google Map?', 'event_espresso'),
179
-                    false,
180
-                    false
181
-                ),
182
-            ),
183
-        );
184
-        $this->_model_relations = array(
185
-            'Event'             => new EE_HABTM_Relation('Event_Venue'),
186
-            'State'             => new EE_Belongs_To_Relation(),
187
-            'Country'           => new EE_Belongs_To_Relation(),
188
-            'Event_Venue'       => new EE_Has_Many_Relation(),
189
-            'WP_User'           => new EE_Belongs_To_Relation(),
190
-            'Term_Relationship' => new EE_Has_Many_Relation(),
191
-            'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
192
-        );
193
-        // this model is generally available for reading
194
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
195
-        $this->model_chain_to_password = '';
196
-        parent::__construct($timezone);
197
-    }
18
+	protected function __construct($timezone = null)
19
+	{
20
+		$this->singular_item = __('Venue', 'event_espresso');
21
+		$this->plural_item = __('Venues', 'event_espresso');
22
+		$this->_tables = array(
23
+			'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
24
+			'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
25
+		);
26
+		$this->_fields = array(
27
+			'Venue_CPT'  => array(
28
+				'VNU_ID'         => new EE_Primary_Key_Int_Field('ID', __("Venue ID", "event_espresso")),
29
+				'VNU_name'       => new EE_Plain_Text_Field(
30
+					'post_title',
31
+					__("Venue Name", "event_espresso"),
32
+					false,
33
+					''
34
+				),
35
+				'VNU_desc'       => new EE_Post_Content_Field(
36
+					'post_content',
37
+					__("Venue Description", "event_espresso"),
38
+					false,
39
+					''
40
+				),
41
+				'VNU_identifier' => new EE_Slug_Field('post_name', __("Venue Identifier", "event_espresso"), false, ''),
42
+				'VNU_created'    => new EE_Datetime_Field(
43
+					'post_date',
44
+					__("Date Venue Created", "event_espresso"),
45
+					false,
46
+					EE_Datetime_Field::now
47
+				),
48
+				'VNU_short_desc' => new EE_Plain_Text_Field(
49
+					'post_excerpt',
50
+					__("Short Description of Venue", "event_espresso"),
51
+					true,
52
+					''
53
+				),
54
+				'VNU_modified'   => new EE_Datetime_Field(
55
+					'post_modified',
56
+					__("Venue Modified Date", "event_espresso"),
57
+					false,
58
+					EE_Datetime_Field::now
59
+				),
60
+				'VNU_wp_user'    => new EE_WP_User_Field(
61
+					'post_author',
62
+					__("Venue Creator ID", "event_espresso"),
63
+					false
64
+				),
65
+				'parent'         => new EE_Integer_Field(
66
+					'post_parent',
67
+					__("Venue Parent ID", "event_espresso"),
68
+					false,
69
+					0
70
+				),
71
+				'VNU_order'      => new EE_Integer_Field('menu_order', __("Venue order", "event_espresso"), false, 1),
72
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
73
+				'password' => new EE_Password_Field(
74
+					'post_password',
75
+					__('Password', 'event_espresso'),
76
+					false,
77
+					'',
78
+					array(
79
+						'VNU_desc',
80
+						'VNU_short_desc',
81
+						'VNU_address',
82
+						'VNU_address2',
83
+						'VNU_city',
84
+						'STA_ID',
85
+						'CNT_ISO',
86
+						'VNU_zip',
87
+						'VNU_phone',
88
+						'VNU_capacity',
89
+						'VNU_url',
90
+						'VNU_virtual_phone',
91
+						'VNU_virtual_url',
92
+						'VNU_google_map_link',
93
+						'VNU_enable_for_gmap',
94
+					)
95
+				)
96
+			),
97
+			'Venue_Meta' => array(
98
+				'VNUM_ID'             => new EE_DB_Only_Int_Field(
99
+					'VNUM_ID',
100
+					__("ID of Venue Meta Row", "event_espresso"),
101
+					false
102
+				),
103
+				'VNU_ID_fk'           => new EE_DB_Only_Int_Field(
104
+					'VNU_ID',
105
+					__("Foreign Key to Venue Post ", "event_espresso"),
106
+					false
107
+				),
108
+				'VNU_address'         => new EE_Plain_Text_Field(
109
+					'VNU_address',
110
+					__("Venue Address line 1", "event_espresso"),
111
+					true,
112
+					''
113
+				),
114
+				'VNU_address2'        => new EE_Plain_Text_Field(
115
+					'VNU_address2',
116
+					__("Venue Address line 2", "event_espresso"),
117
+					true,
118
+					''
119
+				),
120
+				'VNU_city'            => new EE_Plain_Text_Field(
121
+					'VNU_city',
122
+					__("Venue City", "event_espresso"),
123
+					true,
124
+					''
125
+				),
126
+				'STA_ID'              => new EE_Foreign_Key_Int_Field(
127
+					'STA_ID',
128
+					__("State ID", "event_espresso"),
129
+					true,
130
+					null,
131
+					'State'
132
+				),
133
+				'CNT_ISO'             => new EE_Foreign_Key_String_Field(
134
+					'CNT_ISO',
135
+					__("Country Code", "event_espresso"),
136
+					true,
137
+					null,
138
+					'Country'
139
+				),
140
+				'VNU_zip'             => new EE_Plain_Text_Field(
141
+					'VNU_zip',
142
+					__("Venue Zip/Postal Code", "event_espresso"),
143
+					true
144
+				),
145
+				'VNU_phone'           => new EE_Plain_Text_Field(
146
+					'VNU_phone',
147
+					__("Venue Phone", "event_espresso"),
148
+					true
149
+				),
150
+				'VNU_capacity'        => new EE_Infinite_Integer_Field(
151
+					'VNU_capacity',
152
+					__("Venue Capacity", "event_espresso"),
153
+					true,
154
+					EE_INF
155
+				),
156
+				'VNU_url'             => new EE_Plain_Text_Field(
157
+					'VNU_url',
158
+					__('Venue Website', 'event_espresso'),
159
+					true
160
+				),
161
+				'VNU_virtual_phone'   => new EE_Plain_Text_Field(
162
+					'VNU_virtual_phone',
163
+					__('Call in Number', 'event_espresso'),
164
+					true
165
+				),
166
+				'VNU_virtual_url'     => new EE_Plain_Text_Field(
167
+					'VNU_virtual_url',
168
+					__('Virtual URL', 'event_espresso'),
169
+					true
170
+				),
171
+				'VNU_google_map_link' => new EE_Plain_Text_Field(
172
+					'VNU_google_map_link',
173
+					__('Google Map Link', 'event_espresso'),
174
+					true
175
+				),
176
+				'VNU_enable_for_gmap' => new EE_Boolean_Field(
177
+					'VNU_enable_for_gmap',
178
+					__('Show Google Map?', 'event_espresso'),
179
+					false,
180
+					false
181
+				),
182
+			),
183
+		);
184
+		$this->_model_relations = array(
185
+			'Event'             => new EE_HABTM_Relation('Event_Venue'),
186
+			'State'             => new EE_Belongs_To_Relation(),
187
+			'Country'           => new EE_Belongs_To_Relation(),
188
+			'Event_Venue'       => new EE_Has_Many_Relation(),
189
+			'WP_User'           => new EE_Belongs_To_Relation(),
190
+			'Term_Relationship' => new EE_Has_Many_Relation(),
191
+			'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
192
+		);
193
+		// this model is generally available for reading
194
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
195
+		$this->model_chain_to_password = '';
196
+		parent::__construct($timezone);
197
+	}
198 198
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -191,7 +191,7 @@
 block discarded – undo
191 191
             'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
192 192
         );
193 193
         // this model is generally available for reading
194
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
194
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
195 195
         $this->model_chain_to_password = '';
196 196
         parent::__construct($timezone);
197 197
     }
Please login to merge, or discard this patch.
core/db_models/EEM_Event_Question_Group.model.php 2 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -7,34 +7,34 @@
 block discarded – undo
7 7
  */
8 8
 class EEM_Event_Question_Group extends EEM_Base
9 9
 {
10
-    // private instance of the Attendee object
11
-    protected static $_instance = null;
10
+	// private instance of the Attendee object
11
+	protected static $_instance = null;
12 12
 
13
-    protected function __construct($timezone = null)
14
-    {
15
-        $this->singular_item = __('Event to Question Group Link', 'event_espresso');
16
-        $this->plural_item = __('Event to Question Group Links', 'event_espresso');
17
-        $this->_tables = array(
18
-            'Event_Question_Group'=>new EE_Primary_Table('esp_event_question_group', 'EQG_ID')
19
-        );
20
-        $this->_fields = array(
21
-            'Event_Question_Group'=>array(
22
-                'EQG_ID'=>new EE_Primary_Key_Int_Field('EQG_ID', __('Event to Question Group Link ID', 'event_espresso')),
23
-                'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'),
24
-                'QSG_ID'=>new EE_Foreign_Key_Int_Field('QSG_ID', __('Question Group Id', 'event_espresso'), false, 0, 'Question_Group'),
25
-                'EQG_primary'=>new EE_Boolean_Field('EQG_primary', __('Flag indicating question is only for primary attendees', 'event_espresso'), false, false)
26
-            )
27
-        );
28
-        $this->_model_relations = array(
29
-            'Event'=>new EE_Belongs_To_Relation(),
30
-            'Question_Group'=>new EE_Belongs_To_Relation()
31
-        );
32
-        // this model is generally available for reading
33
-        $path_to_event = 'Event';
34
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
35
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
36
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
38
-        parent::__construct($timezone);
39
-    }
13
+	protected function __construct($timezone = null)
14
+	{
15
+		$this->singular_item = __('Event to Question Group Link', 'event_espresso');
16
+		$this->plural_item = __('Event to Question Group Links', 'event_espresso');
17
+		$this->_tables = array(
18
+			'Event_Question_Group'=>new EE_Primary_Table('esp_event_question_group', 'EQG_ID')
19
+		);
20
+		$this->_fields = array(
21
+			'Event_Question_Group'=>array(
22
+				'EQG_ID'=>new EE_Primary_Key_Int_Field('EQG_ID', __('Event to Question Group Link ID', 'event_espresso')),
23
+				'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'),
24
+				'QSG_ID'=>new EE_Foreign_Key_Int_Field('QSG_ID', __('Question Group Id', 'event_espresso'), false, 0, 'Question_Group'),
25
+				'EQG_primary'=>new EE_Boolean_Field('EQG_primary', __('Flag indicating question is only for primary attendees', 'event_espresso'), false, false)
26
+			)
27
+		);
28
+		$this->_model_relations = array(
29
+			'Event'=>new EE_Belongs_To_Relation(),
30
+			'Question_Group'=>new EE_Belongs_To_Relation()
31
+		);
32
+		// this model is generally available for reading
33
+		$path_to_event = 'Event';
34
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
35
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
36
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
38
+		parent::__construct($timezone);
39
+	}
40 40
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -31,10 +31,10 @@
 block discarded – undo
31 31
         );
32 32
         // this model is generally available for reading
33 33
         $path_to_event = 'Event';
34
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
35
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
36
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
34
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
35
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
36
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
38 38
         parent::__construct($timezone);
39 39
     }
40 40
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Event_Message_Template.model.php 2 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -1,95 +1,95 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
  /**
4
- *  EEM_Event_Message_Template
5
- *  Model for relation table between EEM_Message_Template_Group and EEM_Event
6
- *
7
- * @package     Event Espresso
8
- * @subpackage  models
9
- * @since           4.3.0
10
- * @author           Darren Ethier
11
- *
12
- * ------------------------------------------------------------------------
13
- */
4
+  *  EEM_Event_Message_Template
5
+  *  Model for relation table between EEM_Message_Template_Group and EEM_Event
6
+  *
7
+  * @package     Event Espresso
8
+  * @subpackage  models
9
+  * @since           4.3.0
10
+  * @author           Darren Ethier
11
+  *
12
+  * ------------------------------------------------------------------------
13
+  */
14 14
 class EEM_Event_Message_Template extends EEM_Base
15 15
 {
16 16
 
17
-    // private instance of the EEM_Event_Message_Template object
18
-    protected static $_instance = null;
17
+	// private instance of the EEM_Event_Message_Template object
18
+	protected static $_instance = null;
19 19
 
20
-    /**
21
-     * private constructor to prevent direct creation
22
-     * @Constructor
23
-     * @access private
24
-     * @return void
25
-     */
26
-    protected function __construct($timezone = null)
27
-    {
28
-        $this->singlular_item = __('Event Message Template', 'event_espresso');
29
-        $this->plural_item = __('Event Message Templates', 'event_espresso');
20
+	/**
21
+	 * private constructor to prevent direct creation
22
+	 * @Constructor
23
+	 * @access private
24
+	 * @return void
25
+	 */
26
+	protected function __construct($timezone = null)
27
+	{
28
+		$this->singlular_item = __('Event Message Template', 'event_espresso');
29
+		$this->plural_item = __('Event Message Templates', 'event_espresso');
30 30
 
31
-        $this->_tables = array(
32
-            'Event_Message_Template'=> new EE_Primary_Table('esp_event_message_template', 'EMT_ID')
33
-        );
34
-        $this->_fields = array(
35
-            'Event_Message_Template'=>array(
36
-                'EMT_ID'=>new EE_Primary_Key_Int_Field('EMT_ID', __('Event Message Template ID', 'event_espresso')),
37
-                'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('The ID to the Event', 'event_espresso'), false, 0, 'Event'),
38
-                'GRP_ID'=>new EE_Foreign_Key_Int_Field('GRP_ID', __('The ID to the Message Template Group', 'event_espresso'), false, 0, 'Message_Template_Group')
39
-            ));
40
-        $this->_model_relations = array(
41
-            'Event'=>new EE_Belongs_To_Relation(),
42
-            'Message_Template_Group'=>new EE_Belongs_To_Relation()
43
-        );
44
-        $path_to_event = 'Event';
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
49
-        parent::__construct($timezone);
50
-    }
31
+		$this->_tables = array(
32
+			'Event_Message_Template'=> new EE_Primary_Table('esp_event_message_template', 'EMT_ID')
33
+		);
34
+		$this->_fields = array(
35
+			'Event_Message_Template'=>array(
36
+				'EMT_ID'=>new EE_Primary_Key_Int_Field('EMT_ID', __('Event Message Template ID', 'event_espresso')),
37
+				'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('The ID to the Event', 'event_espresso'), false, 0, 'Event'),
38
+				'GRP_ID'=>new EE_Foreign_Key_Int_Field('GRP_ID', __('The ID to the Message Template Group', 'event_espresso'), false, 0, 'Message_Template_Group')
39
+			));
40
+		$this->_model_relations = array(
41
+			'Event'=>new EE_Belongs_To_Relation(),
42
+			'Message_Template_Group'=>new EE_Belongs_To_Relation()
43
+		);
44
+		$path_to_event = 'Event';
45
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
49
+		parent::__construct($timezone);
50
+	}
51 51
 
52 52
 
53 53
 
54
-    /**
55
-     * helper method to simply return an array of event ids for events attached to the given
56
-     * message template group.
57
-     *
58
-     * @since 4.3.0
59
-     *
60
-     * @param  int    $GRP_ID The MTP group we want attached events for.
61
-     * @return  array               An array of event ids.
62
-     */
63
-    public function get_attached_event_ids($GRP_ID)
64
-    {
65
-        $event_ids = $this->_get_all_wpdb_results(array( array( 'GRP_ID' => $GRP_ID ) ), ARRAY_N, 'EVT_ID');
66
-        $event_ids = call_user_func_array('array_merge', $event_ids);
67
-        return $event_ids;
68
-    }
54
+	/**
55
+	 * helper method to simply return an array of event ids for events attached to the given
56
+	 * message template group.
57
+	 *
58
+	 * @since 4.3.0
59
+	 *
60
+	 * @param  int    $GRP_ID The MTP group we want attached events for.
61
+	 * @return  array               An array of event ids.
62
+	 */
63
+	public function get_attached_event_ids($GRP_ID)
64
+	{
65
+		$event_ids = $this->_get_all_wpdb_results(array( array( 'GRP_ID' => $GRP_ID ) ), ARRAY_N, 'EVT_ID');
66
+		$event_ids = call_user_func_array('array_merge', $event_ids);
67
+		return $event_ids;
68
+	}
69 69
 
70 70
 
71 71
 
72
-    /**
73
-     * helper method for clearing event/group relations for the given event ids and grp ids.
74
-     * @param  array $GRP_IDs  An array of GRP_IDs. Optional. If empty then there must be EVTIDs.
75
-     * @param  array $EVT_IDs  An array of EVT_IDs.  Optional. If empty then there must be
76
-     *                                 GRPIDs.
77
-     * @return int             How many rows were deleted.
78
-     */
79
-    public function delete_event_group_relations($GRP_IDs = array(), $EVT_IDs = array())
80
-    {
81
-        if (empty($GRP_IDs) && empty($EVT_IDs)) {
82
-            throw new EE_Error(sprintf(__('%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.', 'event_espresso'), __METHOD__));
83
-        }
72
+	/**
73
+	 * helper method for clearing event/group relations for the given event ids and grp ids.
74
+	 * @param  array $GRP_IDs  An array of GRP_IDs. Optional. If empty then there must be EVTIDs.
75
+	 * @param  array $EVT_IDs  An array of EVT_IDs.  Optional. If empty then there must be
76
+	 *                                 GRPIDs.
77
+	 * @return int             How many rows were deleted.
78
+	 */
79
+	public function delete_event_group_relations($GRP_IDs = array(), $EVT_IDs = array())
80
+	{
81
+		if (empty($GRP_IDs) && empty($EVT_IDs)) {
82
+			throw new EE_Error(sprintf(__('%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.', 'event_espresso'), __METHOD__));
83
+		}
84 84
 
85
-        if (!empty($GRP_IDs)) {
86
-            $where['GRP_ID'] = array( 'IN', (array) $GRP_IDs );
87
-        }
85
+		if (!empty($GRP_IDs)) {
86
+			$where['GRP_ID'] = array( 'IN', (array) $GRP_IDs );
87
+		}
88 88
 
89
-        if (!empty($EVT_IDs)) {
90
-            $where['EVT_ID'] = array( 'IN', (array) $EVT_IDs );
91
-        }
89
+		if (!empty($EVT_IDs)) {
90
+			$where['EVT_ID'] = array( 'IN', (array) $EVT_IDs );
91
+		}
92 92
 
93
-        return $this->delete(array( $where ), false);
94
-    }
93
+		return $this->delete(array( $where ), false);
94
+	}
95 95
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
             'Message_Template_Group'=>new EE_Belongs_To_Relation()
43 43
         );
44 44
         $path_to_event = 'Event';
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
45
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
46
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
47
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
49 49
         parent::__construct($timezone);
50 50
     }
51 51
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
      */
63 63
     public function get_attached_event_ids($GRP_ID)
64 64
     {
65
-        $event_ids = $this->_get_all_wpdb_results(array( array( 'GRP_ID' => $GRP_ID ) ), ARRAY_N, 'EVT_ID');
65
+        $event_ids = $this->_get_all_wpdb_results(array(array('GRP_ID' => $GRP_ID)), ARRAY_N, 'EVT_ID');
66 66
         $event_ids = call_user_func_array('array_merge', $event_ids);
67 67
         return $event_ids;
68 68
     }
@@ -82,14 +82,14 @@  discard block
 block discarded – undo
82 82
             throw new EE_Error(sprintf(__('%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.', 'event_espresso'), __METHOD__));
83 83
         }
84 84
 
85
-        if (!empty($GRP_IDs)) {
86
-            $where['GRP_ID'] = array( 'IN', (array) $GRP_IDs );
85
+        if ( ! empty($GRP_IDs)) {
86
+            $where['GRP_ID'] = array('IN', (array) $GRP_IDs);
87 87
         }
88 88
 
89
-        if (!empty($EVT_IDs)) {
90
-            $where['EVT_ID'] = array( 'IN', (array) $EVT_IDs );
89
+        if ( ! empty($EVT_IDs)) {
90
+            $where['EVT_ID'] = array('IN', (array) $EVT_IDs);
91 91
         }
92 92
 
93
-        return $this->delete(array( $where ), false);
93
+        return $this->delete(array($where), false);
94 94
     }
95 95
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Event_Venue.model.php 2 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -7,36 +7,36 @@
 block discarded – undo
7 7
  */
8 8
 class EEM_Event_Venue extends EEM_Base
9 9
 {
10
-    // private instance of the Attendee object
11
-    protected static $_instance = null;
10
+	// private instance of the Attendee object
11
+	protected static $_instance = null;
12 12
 
13
-    protected function __construct($timezone = null)
14
-    {
15
-        $this->singular_item = __('Event to Question Group Link', 'event_espresso');
16
-        $this->plural_item = __('Event to Question Group Links', 'event_espresso');
17
-        $this->_tables = array(
18
-            'Event_Venue'=>new EE_Primary_Table('esp_event_venue', 'EVV_ID')
19
-        );
20
-        $this->_fields = array(
21
-            'Event_Venue'=>array(
22
-                'EVV_ID'=>new EE_Primary_Key_Int_Field('EVV_ID', __('Event to Venue Link ID', 'event_espresso')),
23
-                'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'),
24
-                'VNU_ID'=>new EE_Foreign_Key_Int_Field('VNU_ID', __('Venue ID', 'event_espresso'), false, 0, 'Venue'),
25
-                'EVV_primary'=>new EE_Boolean_Field('EVV_primary', __("Flag indicating venue is primary one for event", "event_espresso"), false, true)
13
+	protected function __construct($timezone = null)
14
+	{
15
+		$this->singular_item = __('Event to Question Group Link', 'event_espresso');
16
+		$this->plural_item = __('Event to Question Group Links', 'event_espresso');
17
+		$this->_tables = array(
18
+			'Event_Venue'=>new EE_Primary_Table('esp_event_venue', 'EVV_ID')
19
+		);
20
+		$this->_fields = array(
21
+			'Event_Venue'=>array(
22
+				'EVV_ID'=>new EE_Primary_Key_Int_Field('EVV_ID', __('Event to Venue Link ID', 'event_espresso')),
23
+				'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'),
24
+				'VNU_ID'=>new EE_Foreign_Key_Int_Field('VNU_ID', __('Venue ID', 'event_espresso'), false, 0, 'Venue'),
25
+				'EVV_primary'=>new EE_Boolean_Field('EVV_primary', __("Flag indicating venue is primary one for event", "event_espresso"), false, true)
26 26
 
27
-            )
28
-        );
29
-        $this->_model_relations = array(
30
-            'Event'=>new EE_Belongs_To_Relation(),
31
-            'Venue'=>new EE_Belongs_To_Relation()
32
-        );
33
-        // this model is generally available for reading
34
-        $path_to_event = 'Event';
35
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
36
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
38
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
39
-        $this->model_chain_to_password = $path_to_event;
40
-        parent::__construct($timezone);
41
-    }
27
+			)
28
+		);
29
+		$this->_model_relations = array(
30
+			'Event'=>new EE_Belongs_To_Relation(),
31
+			'Venue'=>new EE_Belongs_To_Relation()
32
+		);
33
+		// this model is generally available for reading
34
+		$path_to_event = 'Event';
35
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
36
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
38
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
39
+		$this->model_chain_to_password = $path_to_event;
40
+		parent::__construct($timezone);
41
+	}
42 42
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@
 block discarded – undo
32 32
         );
33 33
         // this model is generally available for reading
34 34
         $path_to_event = 'Event';
35
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
36
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
38
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
35
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
36
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
38
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
39 39
         $this->model_chain_to_password = $path_to_event;
40 40
         parent::__construct($timezone);
41 41
     }
Please login to merge, or discard this patch.
core/db_models/EEM_Datetime.model.php 2 patches
Indentation   +657 added lines, -657 removed lines patch added patch discarded remove patch
@@ -9,661 +9,661 @@
 block discarded – undo
9 9
 class EEM_Datetime extends EEM_Soft_Delete_Base
10 10
 {
11 11
 
12
-    /**
13
-     * @var EEM_Datetime $_instance
14
-     */
15
-    protected static $_instance;
16
-
17
-
18
-    /**
19
-     * private constructor to prevent direct creation
20
-     *
21
-     * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings
22
-     *                         (and any incoming timezone data that gets saved).
23
-     *                         Note this just sends the timezone info to the date time model field objects.
24
-     *                         Default is NULL
25
-     *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
26
-     * @throws EE_Error
27
-     * @throws InvalidArgumentException
28
-     * @throws InvalidArgumentException
29
-     */
30
-    protected function __construct($timezone)
31
-    {
32
-        $this->singular_item           = esc_html__('Datetime', 'event_espresso');
33
-        $this->plural_item             = esc_html__('Datetimes', 'event_espresso');
34
-        $this->_tables                 = array(
35
-            'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
36
-        );
37
-        $this->_fields                 = array(
38
-            'Datetime' => array(
39
-                'DTT_ID'          => new EE_Primary_Key_Int_Field(
40
-                    'DTT_ID',
41
-                    esc_html__('Datetime ID', 'event_espresso')
42
-                ),
43
-                'EVT_ID'          => new EE_Foreign_Key_Int_Field(
44
-                    'EVT_ID',
45
-                    esc_html__('Event ID', 'event_espresso'),
46
-                    false,
47
-                    0,
48
-                    'Event'
49
-                ),
50
-                'DTT_name'        => new EE_Plain_Text_Field(
51
-                    'DTT_name',
52
-                    esc_html__('Datetime Name', 'event_espresso'),
53
-                    false,
54
-                    ''
55
-                ),
56
-                'DTT_description' => new EE_Post_Content_Field(
57
-                    'DTT_description',
58
-                    esc_html__('Description for Datetime', 'event_espresso'),
59
-                    false,
60
-                    ''
61
-                ),
62
-                'DTT_EVT_start'   => new EE_Datetime_Field(
63
-                    'DTT_EVT_start',
64
-                    esc_html__('Start time/date of Event', 'event_espresso'),
65
-                    false,
66
-                    EE_Datetime_Field::now,
67
-                    $timezone
68
-                ),
69
-                'DTT_EVT_end'     => new EE_Datetime_Field(
70
-                    'DTT_EVT_end',
71
-                    esc_html__('End time/date of Event', 'event_espresso'),
72
-                    false,
73
-                    EE_Datetime_Field::now,
74
-                    $timezone
75
-                ),
76
-                'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
77
-                    'DTT_reg_limit',
78
-                    esc_html__('Registration Limit for this time', 'event_espresso'),
79
-                    true,
80
-                    EE_INF
81
-                ),
82
-                'DTT_sold'        => new EE_Integer_Field(
83
-                    'DTT_sold',
84
-                    esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'),
85
-                    true,
86
-                    0
87
-                ),
88
-                'DTT_reserved'    => new EE_Integer_Field(
89
-                    'DTT_reserved',
90
-                    esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'),
91
-                    false,
92
-                    0
93
-                ),
94
-                'DTT_is_primary'  => new EE_Boolean_Field(
95
-                    'DTT_is_primary',
96
-                    esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'),
97
-                    false,
98
-                    false
99
-                ),
100
-                'DTT_order'       => new EE_Integer_Field(
101
-                    'DTT_order',
102
-                    esc_html__('The order in which the Datetime is displayed', 'event_espresso'),
103
-                    false,
104
-                    0
105
-                ),
106
-                'DTT_parent'      => new EE_Integer_Field(
107
-                    'DTT_parent',
108
-                    esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'),
109
-                    true,
110
-                    0
111
-                ),
112
-                'DTT_deleted'     => new EE_Trashed_Flag_Field(
113
-                    'DTT_deleted',
114
-                    esc_html__('Flag indicating datetime is archived', 'event_espresso'),
115
-                    false,
116
-                    false
117
-                ),
118
-            ),
119
-        );
120
-        $this->_model_relations        = array(
121
-            'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
122
-            'Event'   => new EE_Belongs_To_Relation(),
123
-            'Checkin' => new EE_Has_Many_Relation(),
124
-        );
125
-        $path_to_event_model = 'Event';
126
-        $this->model_chain_to_password = $path_to_event_model;
127
-        $this->_model_chain_to_wp_user = $path_to_event_model;
128
-        // this model is generally available for reading
129
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Event_Related_Public(
130
-            $path_to_event_model
131
-        );
132
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected(
133
-            $path_to_event_model
134
-        );
135
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       = new EE_Restriction_Generator_Event_Related_Protected(
136
-            $path_to_event_model
137
-        );
138
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     = new EE_Restriction_Generator_Event_Related_Protected(
139
-            $path_to_event_model,
140
-            EEM_Base::caps_edit
141
-        );
142
-        parent::__construct($timezone);
143
-    }
144
-
145
-
146
-    /**
147
-     * create new blank datetime
148
-     *
149
-     * @access public
150
-     * @return EE_Datetime[] array on success, FALSE on fail
151
-     * @throws EE_Error
152
-     */
153
-    public function create_new_blank_datetime()
154
-    {
155
-        // makes sure timezone is always set.
156
-        $timezone_string = $this->get_timezone();
157
-        $blank_datetime  = EE_Datetime::new_instance(
158
-            array(
159
-                'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS,
160
-                'DTT_EVT_end'   => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS,
161
-                'DTT_order'     => 1,
162
-                'DTT_reg_limit' => EE_INF,
163
-            ),
164
-            $timezone_string
165
-        );
166
-        $blank_datetime->set_start_time(
167
-            $this->convert_datetime_for_query(
168
-                'DTT_EVT_start',
169
-                '8am',
170
-                'ga',
171
-                $timezone_string
172
-            )
173
-        );
174
-        $blank_datetime->set_end_time(
175
-            $this->convert_datetime_for_query(
176
-                'DTT_EVT_end',
177
-                '5pm',
178
-                'ga',
179
-                $timezone_string
180
-            )
181
-        );
182
-        return array($blank_datetime);
183
-    }
184
-
185
-
186
-    /**
187
-     * get event start date from db
188
-     *
189
-     * @access public
190
-     * @param  int $EVT_ID
191
-     * @return EE_Datetime[] array on success, FALSE on fail
192
-     * @throws EE_Error
193
-     */
194
-    public function get_all_event_dates($EVT_ID = 0)
195
-    {
196
-        if (! $EVT_ID) { // on add_new_event event_id gets set to 0
197
-            return $this->create_new_blank_datetime();
198
-        }
199
-        $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
200
-        if (empty($results)) {
201
-            return $this->create_new_blank_datetime();
202
-        }
203
-        return $results;
204
-    }
205
-
206
-
207
-    /**
208
-     * get all datetimes attached to an event ordered by the DTT_order field
209
-     *
210
-     * @public
211
-     * @param  int    $EVT_ID     event id
212
-     * @param boolean $include_expired
213
-     * @param boolean $include_deleted
214
-     * @param  int    $limit      If included then limit the count of results by
215
-     *                            the given number
216
-     * @return EE_Datetime[]
217
-     * @throws EE_Error
218
-     */
219
-    public function get_datetimes_for_event_ordered_by_DTT_order(
220
-        $EVT_ID,
221
-        $include_expired = true,
222
-        $include_deleted = true,
223
-        $limit = null
224
-    ) {
225
-        // sanitize EVT_ID
226
-        $EVT_ID         = absint($EVT_ID);
227
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
228
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
229
-        $where_params = array('Event.EVT_ID' => $EVT_ID);
230
-        $query_params = ! empty($limit)
231
-            ? array(
232
-                $where_params,
233
-                'limit'                    => $limit,
234
-                'order_by'                 => array('DTT_order' => 'ASC'),
235
-                'default_where_conditions' => 'none',
236
-            )
237
-            : array(
238
-                $where_params,
239
-                'order_by'                 => array('DTT_order' => 'ASC'),
240
-                'default_where_conditions' => 'none',
241
-            );
242
-        if (! $include_expired) {
243
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
244
-        }
245
-        if ($include_deleted) {
246
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
247
-        }
248
-        /** @var EE_Datetime[] $result */
249
-        $result = $this->get_all($query_params);
250
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
251
-        return $result;
252
-    }
253
-
254
-
255
-    /**
256
-     * Gets the datetimes for the event (with the given limit), and orders them by "importance".
257
-     * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW),
258
-     * and then the earlier datetimes are the most important.
259
-     * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
260
-     *
261
-     * @param int $EVT_ID
262
-     * @param int $limit
263
-     * @return EE_Datetime[]|EE_Base_Class[]
264
-     * @throws EE_Error
265
-     */
266
-    public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
267
-    {
268
-        return $this->get_all(
269
-            array(
270
-                array('Event.EVT_ID' => $EVT_ID),
271
-                'limit'                    => $limit,
272
-                'order_by'                 => array('DTT_EVT_start' => 'ASC'),
273
-                'default_where_conditions' => 'none',
274
-            )
275
-        );
276
-    }
277
-
278
-
279
-    /**
280
-     * @param int     $EVT_ID
281
-     * @param boolean $include_expired
282
-     * @param boolean $include_deleted
283
-     * @return EE_Datetime
284
-     * @throws EE_Error
285
-     */
286
-    public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
287
-    {
288
-        $results = $this->get_datetimes_for_event_ordered_by_start_time(
289
-            $EVT_ID,
290
-            $include_expired,
291
-            $include_deleted,
292
-            1
293
-        );
294
-        if ($results) {
295
-            return array_shift($results);
296
-        }
297
-        return null;
298
-    }
299
-
300
-
301
-    /**
302
-     * Gets the 'primary' datetime for an event.
303
-     *
304
-     * @param int  $EVT_ID
305
-     * @param bool $try_to_exclude_expired
306
-     * @param bool $try_to_exclude_deleted
307
-     * @return \EE_Datetime
308
-     * @throws EE_Error
309
-     */
310
-    public function get_primary_datetime_for_event(
311
-        $EVT_ID,
312
-        $try_to_exclude_expired = true,
313
-        $try_to_exclude_deleted = true
314
-    ) {
315
-        if ($try_to_exclude_expired) {
316
-            $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
317
-            if ($non_expired) {
318
-                return $non_expired;
319
-            }
320
-        }
321
-        if ($try_to_exclude_deleted) {
322
-            $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
323
-            if ($expired_even) {
324
-                return $expired_even;
325
-            }
326
-        }
327
-        return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
328
-    }
329
-
330
-
331
-    /**
332
-     * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
333
-     * only by start date
334
-     *
335
-     * @param int     $EVT_ID
336
-     * @param boolean $include_expired
337
-     * @param boolean $include_deleted
338
-     * @param int     $limit
339
-     * @return EE_Datetime[]
340
-     * @throws EE_Error
341
-     */
342
-    public function get_datetimes_for_event_ordered_by_start_time(
343
-        $EVT_ID,
344
-        $include_expired = true,
345
-        $include_deleted = true,
346
-        $limit = null
347
-    ) {
348
-        // sanitize EVT_ID
349
-        $EVT_ID         = absint($EVT_ID);
350
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
351
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
352
-        $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
353
-        if (! $include_expired) {
354
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
355
-        }
356
-        if ($include_deleted) {
357
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
358
-        }
359
-        if ($limit) {
360
-            $query_params['limit'] = $limit;
361
-        }
362
-        /** @var EE_Datetime[] $result */
363
-        $result = $this->get_all($query_params);
364
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
365
-        return $result;
366
-    }
367
-
368
-
369
-    /**
370
-     * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
371
-     * only by start date
372
-     *
373
-     * @param int     $TKT_ID
374
-     * @param boolean $include_expired
375
-     * @param boolean $include_deleted
376
-     * @param int     $limit
377
-     * @return EE_Datetime[]
378
-     * @throws EE_Error
379
-     */
380
-    public function get_datetimes_for_ticket_ordered_by_start_time(
381
-        $TKT_ID,
382
-        $include_expired = true,
383
-        $include_deleted = true,
384
-        $limit = null
385
-    ) {
386
-        // sanitize TKT_ID
387
-        $TKT_ID         = absint($TKT_ID);
388
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
389
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
390
-        $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
391
-        if (! $include_expired) {
392
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
393
-        }
394
-        if ($include_deleted) {
395
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
396
-        }
397
-        if ($limit) {
398
-            $query_params['limit'] = $limit;
399
-        }
400
-        /** @var EE_Datetime[] $result */
401
-        $result = $this->get_all($query_params);
402
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
403
-        return $result;
404
-    }
405
-
406
-
407
-    /**
408
-     * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
409
-     * datetimes.
410
-     *
411
-     * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
412
-     * @param  boolean  $include_expired whether to include expired datetimes or not
413
-     * @param  boolean  $include_deleted whether to include trashed datetimes or not.
414
-     * @param  int|null $limit           if null, no limit, if int then limit results by
415
-     *                                   that number
416
-     * @return EE_Datetime[]
417
-     * @throws EE_Error
418
-     */
419
-    public function get_datetimes_for_ticket_ordered_by_DTT_order(
420
-        $TKT_ID,
421
-        $include_expired = true,
422
-        $include_deleted = true,
423
-        $limit = null
424
-    ) {
425
-        // sanitize id.
426
-        $TKT_ID         = absint($TKT_ID);
427
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
428
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
429
-        $where_params = array('Ticket.TKT_ID' => $TKT_ID);
430
-        $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
431
-        if (! $include_expired) {
432
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
433
-        }
434
-        if ($include_deleted) {
435
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
436
-        }
437
-        if ($limit) {
438
-            $query_params['limit'] = $limit;
439
-        }
440
-        /** @var EE_Datetime[] $result */
441
-        $result = $this->get_all($query_params);
442
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
443
-        return $result;
444
-    }
445
-
446
-
447
-    /**
448
-     * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
449
-     * reason it doesn't exist, we consider the earliest event the most important)
450
-     *
451
-     * @param int $EVT_ID
452
-     * @return EE_Datetime
453
-     * @throws EE_Error
454
-     */
455
-    public function get_most_important_datetime_for_event($EVT_ID)
456
-    {
457
-        $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
458
-        if ($results) {
459
-            return array_shift($results);
460
-        }
461
-        return null;
462
-    }
463
-
464
-
465
-    /**
466
-     * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
467
-     * grouped by month and year.
468
-     *
469
-     * @param  array  $where_params      @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
470
-     * @param  string $evt_active_status A string representing the evt active status to filter the months by.
471
-     *                                   Can be:
472
-     *                                   - '' = no filter
473
-     *                                   - upcoming = Published events with at least one upcoming datetime.
474
-     *                                   - expired = Events with all datetimes expired.
475
-     *                                   - active = Events that are published and have at least one datetime that
476
-     *                                   starts before now and ends after now.
477
-     *                                   - inactive = Events that are either not published.
478
-     * @return EE_Base_Class[]
479
-     * @throws EE_Error
480
-     * @throws InvalidArgumentException
481
-     * @throws InvalidArgumentException
482
-     */
483
-    public function get_dtt_months_and_years($where_params, $evt_active_status = '')
484
-    {
485
-        $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
486
-        $current_time_for_DTT_EVT_end   = $this->current_time_for_query('DTT_EVT_end');
487
-        switch ($evt_active_status) {
488
-            case 'upcoming':
489
-                $where_params['Event.status'] = 'publish';
490
-                // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
491
-                if (isset($where_params['DTT_EVT_start'])) {
492
-                    $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
493
-                }
494
-                $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
495
-                break;
496
-            case 'expired':
497
-                if (isset($where_params['Event.status'])) {
498
-                    unset($where_params['Event.status']);
499
-                }
500
-                // get events to exclude
501
-                $exclude_query[0] = array_merge(
502
-                    $where_params,
503
-                    array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end))
504
-                );
505
-                // first get all events that have datetimes where its not expired.
506
-                $event_ids = $this->_get_all_wpdb_results(
507
-                    $exclude_query,
508
-                    OBJECT_K,
509
-                    'Datetime.EVT_ID'
510
-                );
511
-                $event_ids = array_keys($event_ids);
512
-                if (isset($where_params['DTT_EVT_end'])) {
513
-                    $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
514
-                }
515
-                $where_params['DTT_EVT_end']  = array('<', $current_time_for_DTT_EVT_end);
516
-                $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
517
-                break;
518
-            case 'active':
519
-                $where_params['Event.status'] = 'publish';
520
-                if (isset($where_params['DTT_EVT_start'])) {
521
-                    $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
522
-                }
523
-                if (isset($where_params['Datetime.DTT_EVT_end'])) {
524
-                    $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
525
-                }
526
-                $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
527
-                $where_params['DTT_EVT_end']   = array('>', $current_time_for_DTT_EVT_end);
528
-                break;
529
-            case 'inactive':
530
-                if (isset($where_params['Event.status'])) {
531
-                    unset($where_params['Event.status']);
532
-                }
533
-                if (isset($where_params['OR'])) {
534
-                    $where_params['AND']['OR'] = $where_params['OR'];
535
-                }
536
-                if (isset($where_params['DTT_EVT_end'])) {
537
-                    $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
538
-                    unset($where_params['DTT_EVT_end']);
539
-                }
540
-                if (isset($where_params['DTT_EVT_start'])) {
541
-                    $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
542
-                    unset($where_params['DTT_EVT_start']);
543
-                }
544
-                $where_params['AND']['Event.status'] = array('!=', 'publish');
545
-                break;
546
-        }
547
-        $query_params[0]          = $where_params;
548
-        $query_params['group_by'] = array('dtt_year', 'dtt_month');
549
-        $query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
550
-        $query_interval           = EEH_DTT_Helper::get_sql_query_interval_for_offset(
551
-            $this->get_timezone(),
552
-            'DTT_EVT_start'
553
-        );
554
-        $columns_to_select        = array(
555
-            'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
556
-            'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
557
-            'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
558
-        );
559
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
560
-    }
561
-
562
-
563
-    /**
564
-     * Updates the DTT_sold attribute on each datetime (based on the registrations
565
-     * for the tickets for each datetime)
566
-     *
567
-     * @param EE_Base_Class[]|EE_Datetime[] $datetimes
568
-     * @throws EE_Error
569
-     */
570
-    public function update_sold($datetimes)
571
-    {
572
-        EE_Error::doing_it_wrong(
573
-            __FUNCTION__,
574
-            esc_html__(
575
-                'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
576
-                'event_espresso'
577
-            ),
578
-            '4.9.32.rc.005'
579
-        );
580
-        foreach ($datetimes as $datetime) {
581
-            $datetime->update_sold();
582
-        }
583
-    }
584
-
585
-
586
-    /**
587
-     *    Gets the total number of tickets available at a particular datetime
588
-     *    (does NOT take into account the datetime's spaces available)
589
-     *
590
-     * @param int   $DTT_ID
591
-     * @param array $query_params
592
-     * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
593
-     *             tickets attached to datetime then FALSE is returned.
594
-     */
595
-    public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
596
-    {
597
-        $datetime = $this->get_one_by_ID($DTT_ID);
598
-        if ($datetime instanceof EE_Datetime) {
599
-            return $datetime->tickets_remaining($query_params);
600
-        }
601
-        return 0;
602
-    }
603
-
604
-
605
-    /**
606
-     * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
607
-     *
608
-     * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
609
-     *                                 stati you want counts for as values in the array.  An empty array returns counts
610
-     *                                 for all valid stati.
611
-     * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
612
-     *                                 only for Datetimes connected to a specific event, or specific ticket.
613
-     * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
614
-     * @throws EE_Error
615
-     *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming
616
-     *                                 EE_Datetime::expired
617
-     */
618
-    public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
619
-    {
620
-        // only accept where conditions for this query.
621
-        $_where            = isset($query_params[0]) ? $query_params[0] : array();
622
-        $status_query_args = array(
623
-            EE_Datetime::active   => array_merge(
624
-                $_where,
625
-                array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
626
-            ),
627
-            EE_Datetime::upcoming => array_merge(
628
-                $_where,
629
-                array('DTT_EVT_start' => array('>', time()))
630
-            ),
631
-            EE_Datetime::expired  => array_merge(
632
-                $_where,
633
-                array('DTT_EVT_end' => array('<', time()))
634
-            ),
635
-        );
636
-        if (! empty($stati_to_include)) {
637
-            foreach (array_keys($status_query_args) as $status) {
638
-                if (! in_array($status, $stati_to_include, true)) {
639
-                    unset($status_query_args[ $status ]);
640
-                }
641
-            }
642
-        }
643
-        // loop through and query counts for each stati.
644
-        $status_query_results = array();
645
-        foreach ($status_query_args as $status => $status_where_conditions) {
646
-            $status_query_results[ $status ] = EEM_Datetime::count(
647
-                array($status_where_conditions),
648
-                'DTT_ID',
649
-                true
650
-            );
651
-        }
652
-        return $status_query_results;
653
-    }
654
-
655
-
656
-    /**
657
-     * Returns the specific count for a given Datetime status matching any given query_params.
658
-     *
659
-     * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
660
-     * @param array  $query_params
661
-     * @return int
662
-     * @throws EE_Error
663
-     */
664
-    public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
665
-    {
666
-        $count = $this->get_datetime_counts_by_status(array($status), $query_params);
667
-        return ! empty($count[ $status ]) ? $count[ $status ] : 0;
668
-    }
12
+	/**
13
+	 * @var EEM_Datetime $_instance
14
+	 */
15
+	protected static $_instance;
16
+
17
+
18
+	/**
19
+	 * private constructor to prevent direct creation
20
+	 *
21
+	 * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings
22
+	 *                         (and any incoming timezone data that gets saved).
23
+	 *                         Note this just sends the timezone info to the date time model field objects.
24
+	 *                         Default is NULL
25
+	 *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
26
+	 * @throws EE_Error
27
+	 * @throws InvalidArgumentException
28
+	 * @throws InvalidArgumentException
29
+	 */
30
+	protected function __construct($timezone)
31
+	{
32
+		$this->singular_item           = esc_html__('Datetime', 'event_espresso');
33
+		$this->plural_item             = esc_html__('Datetimes', 'event_espresso');
34
+		$this->_tables                 = array(
35
+			'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
36
+		);
37
+		$this->_fields                 = array(
38
+			'Datetime' => array(
39
+				'DTT_ID'          => new EE_Primary_Key_Int_Field(
40
+					'DTT_ID',
41
+					esc_html__('Datetime ID', 'event_espresso')
42
+				),
43
+				'EVT_ID'          => new EE_Foreign_Key_Int_Field(
44
+					'EVT_ID',
45
+					esc_html__('Event ID', 'event_espresso'),
46
+					false,
47
+					0,
48
+					'Event'
49
+				),
50
+				'DTT_name'        => new EE_Plain_Text_Field(
51
+					'DTT_name',
52
+					esc_html__('Datetime Name', 'event_espresso'),
53
+					false,
54
+					''
55
+				),
56
+				'DTT_description' => new EE_Post_Content_Field(
57
+					'DTT_description',
58
+					esc_html__('Description for Datetime', 'event_espresso'),
59
+					false,
60
+					''
61
+				),
62
+				'DTT_EVT_start'   => new EE_Datetime_Field(
63
+					'DTT_EVT_start',
64
+					esc_html__('Start time/date of Event', 'event_espresso'),
65
+					false,
66
+					EE_Datetime_Field::now,
67
+					$timezone
68
+				),
69
+				'DTT_EVT_end'     => new EE_Datetime_Field(
70
+					'DTT_EVT_end',
71
+					esc_html__('End time/date of Event', 'event_espresso'),
72
+					false,
73
+					EE_Datetime_Field::now,
74
+					$timezone
75
+				),
76
+				'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
77
+					'DTT_reg_limit',
78
+					esc_html__('Registration Limit for this time', 'event_espresso'),
79
+					true,
80
+					EE_INF
81
+				),
82
+				'DTT_sold'        => new EE_Integer_Field(
83
+					'DTT_sold',
84
+					esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'),
85
+					true,
86
+					0
87
+				),
88
+				'DTT_reserved'    => new EE_Integer_Field(
89
+					'DTT_reserved',
90
+					esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'),
91
+					false,
92
+					0
93
+				),
94
+				'DTT_is_primary'  => new EE_Boolean_Field(
95
+					'DTT_is_primary',
96
+					esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'),
97
+					false,
98
+					false
99
+				),
100
+				'DTT_order'       => new EE_Integer_Field(
101
+					'DTT_order',
102
+					esc_html__('The order in which the Datetime is displayed', 'event_espresso'),
103
+					false,
104
+					0
105
+				),
106
+				'DTT_parent'      => new EE_Integer_Field(
107
+					'DTT_parent',
108
+					esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'),
109
+					true,
110
+					0
111
+				),
112
+				'DTT_deleted'     => new EE_Trashed_Flag_Field(
113
+					'DTT_deleted',
114
+					esc_html__('Flag indicating datetime is archived', 'event_espresso'),
115
+					false,
116
+					false
117
+				),
118
+			),
119
+		);
120
+		$this->_model_relations        = array(
121
+			'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
122
+			'Event'   => new EE_Belongs_To_Relation(),
123
+			'Checkin' => new EE_Has_Many_Relation(),
124
+		);
125
+		$path_to_event_model = 'Event';
126
+		$this->model_chain_to_password = $path_to_event_model;
127
+		$this->_model_chain_to_wp_user = $path_to_event_model;
128
+		// this model is generally available for reading
129
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Event_Related_Public(
130
+			$path_to_event_model
131
+		);
132
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected(
133
+			$path_to_event_model
134
+		);
135
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       = new EE_Restriction_Generator_Event_Related_Protected(
136
+			$path_to_event_model
137
+		);
138
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     = new EE_Restriction_Generator_Event_Related_Protected(
139
+			$path_to_event_model,
140
+			EEM_Base::caps_edit
141
+		);
142
+		parent::__construct($timezone);
143
+	}
144
+
145
+
146
+	/**
147
+	 * create new blank datetime
148
+	 *
149
+	 * @access public
150
+	 * @return EE_Datetime[] array on success, FALSE on fail
151
+	 * @throws EE_Error
152
+	 */
153
+	public function create_new_blank_datetime()
154
+	{
155
+		// makes sure timezone is always set.
156
+		$timezone_string = $this->get_timezone();
157
+		$blank_datetime  = EE_Datetime::new_instance(
158
+			array(
159
+				'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS,
160
+				'DTT_EVT_end'   => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS,
161
+				'DTT_order'     => 1,
162
+				'DTT_reg_limit' => EE_INF,
163
+			),
164
+			$timezone_string
165
+		);
166
+		$blank_datetime->set_start_time(
167
+			$this->convert_datetime_for_query(
168
+				'DTT_EVT_start',
169
+				'8am',
170
+				'ga',
171
+				$timezone_string
172
+			)
173
+		);
174
+		$blank_datetime->set_end_time(
175
+			$this->convert_datetime_for_query(
176
+				'DTT_EVT_end',
177
+				'5pm',
178
+				'ga',
179
+				$timezone_string
180
+			)
181
+		);
182
+		return array($blank_datetime);
183
+	}
184
+
185
+
186
+	/**
187
+	 * get event start date from db
188
+	 *
189
+	 * @access public
190
+	 * @param  int $EVT_ID
191
+	 * @return EE_Datetime[] array on success, FALSE on fail
192
+	 * @throws EE_Error
193
+	 */
194
+	public function get_all_event_dates($EVT_ID = 0)
195
+	{
196
+		if (! $EVT_ID) { // on add_new_event event_id gets set to 0
197
+			return $this->create_new_blank_datetime();
198
+		}
199
+		$results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
200
+		if (empty($results)) {
201
+			return $this->create_new_blank_datetime();
202
+		}
203
+		return $results;
204
+	}
205
+
206
+
207
+	/**
208
+	 * get all datetimes attached to an event ordered by the DTT_order field
209
+	 *
210
+	 * @public
211
+	 * @param  int    $EVT_ID     event id
212
+	 * @param boolean $include_expired
213
+	 * @param boolean $include_deleted
214
+	 * @param  int    $limit      If included then limit the count of results by
215
+	 *                            the given number
216
+	 * @return EE_Datetime[]
217
+	 * @throws EE_Error
218
+	 */
219
+	public function get_datetimes_for_event_ordered_by_DTT_order(
220
+		$EVT_ID,
221
+		$include_expired = true,
222
+		$include_deleted = true,
223
+		$limit = null
224
+	) {
225
+		// sanitize EVT_ID
226
+		$EVT_ID         = absint($EVT_ID);
227
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
228
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
229
+		$where_params = array('Event.EVT_ID' => $EVT_ID);
230
+		$query_params = ! empty($limit)
231
+			? array(
232
+				$where_params,
233
+				'limit'                    => $limit,
234
+				'order_by'                 => array('DTT_order' => 'ASC'),
235
+				'default_where_conditions' => 'none',
236
+			)
237
+			: array(
238
+				$where_params,
239
+				'order_by'                 => array('DTT_order' => 'ASC'),
240
+				'default_where_conditions' => 'none',
241
+			);
242
+		if (! $include_expired) {
243
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
244
+		}
245
+		if ($include_deleted) {
246
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
247
+		}
248
+		/** @var EE_Datetime[] $result */
249
+		$result = $this->get_all($query_params);
250
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
251
+		return $result;
252
+	}
253
+
254
+
255
+	/**
256
+	 * Gets the datetimes for the event (with the given limit), and orders them by "importance".
257
+	 * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW),
258
+	 * and then the earlier datetimes are the most important.
259
+	 * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
260
+	 *
261
+	 * @param int $EVT_ID
262
+	 * @param int $limit
263
+	 * @return EE_Datetime[]|EE_Base_Class[]
264
+	 * @throws EE_Error
265
+	 */
266
+	public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
267
+	{
268
+		return $this->get_all(
269
+			array(
270
+				array('Event.EVT_ID' => $EVT_ID),
271
+				'limit'                    => $limit,
272
+				'order_by'                 => array('DTT_EVT_start' => 'ASC'),
273
+				'default_where_conditions' => 'none',
274
+			)
275
+		);
276
+	}
277
+
278
+
279
+	/**
280
+	 * @param int     $EVT_ID
281
+	 * @param boolean $include_expired
282
+	 * @param boolean $include_deleted
283
+	 * @return EE_Datetime
284
+	 * @throws EE_Error
285
+	 */
286
+	public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
287
+	{
288
+		$results = $this->get_datetimes_for_event_ordered_by_start_time(
289
+			$EVT_ID,
290
+			$include_expired,
291
+			$include_deleted,
292
+			1
293
+		);
294
+		if ($results) {
295
+			return array_shift($results);
296
+		}
297
+		return null;
298
+	}
299
+
300
+
301
+	/**
302
+	 * Gets the 'primary' datetime for an event.
303
+	 *
304
+	 * @param int  $EVT_ID
305
+	 * @param bool $try_to_exclude_expired
306
+	 * @param bool $try_to_exclude_deleted
307
+	 * @return \EE_Datetime
308
+	 * @throws EE_Error
309
+	 */
310
+	public function get_primary_datetime_for_event(
311
+		$EVT_ID,
312
+		$try_to_exclude_expired = true,
313
+		$try_to_exclude_deleted = true
314
+	) {
315
+		if ($try_to_exclude_expired) {
316
+			$non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
317
+			if ($non_expired) {
318
+				return $non_expired;
319
+			}
320
+		}
321
+		if ($try_to_exclude_deleted) {
322
+			$expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
323
+			if ($expired_even) {
324
+				return $expired_even;
325
+			}
326
+		}
327
+		return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
328
+	}
329
+
330
+
331
+	/**
332
+	 * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
333
+	 * only by start date
334
+	 *
335
+	 * @param int     $EVT_ID
336
+	 * @param boolean $include_expired
337
+	 * @param boolean $include_deleted
338
+	 * @param int     $limit
339
+	 * @return EE_Datetime[]
340
+	 * @throws EE_Error
341
+	 */
342
+	public function get_datetimes_for_event_ordered_by_start_time(
343
+		$EVT_ID,
344
+		$include_expired = true,
345
+		$include_deleted = true,
346
+		$limit = null
347
+	) {
348
+		// sanitize EVT_ID
349
+		$EVT_ID         = absint($EVT_ID);
350
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
351
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
352
+		$query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
353
+		if (! $include_expired) {
354
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
355
+		}
356
+		if ($include_deleted) {
357
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
358
+		}
359
+		if ($limit) {
360
+			$query_params['limit'] = $limit;
361
+		}
362
+		/** @var EE_Datetime[] $result */
363
+		$result = $this->get_all($query_params);
364
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
365
+		return $result;
366
+	}
367
+
368
+
369
+	/**
370
+	 * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
371
+	 * only by start date
372
+	 *
373
+	 * @param int     $TKT_ID
374
+	 * @param boolean $include_expired
375
+	 * @param boolean $include_deleted
376
+	 * @param int     $limit
377
+	 * @return EE_Datetime[]
378
+	 * @throws EE_Error
379
+	 */
380
+	public function get_datetimes_for_ticket_ordered_by_start_time(
381
+		$TKT_ID,
382
+		$include_expired = true,
383
+		$include_deleted = true,
384
+		$limit = null
385
+	) {
386
+		// sanitize TKT_ID
387
+		$TKT_ID         = absint($TKT_ID);
388
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
389
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
390
+		$query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
391
+		if (! $include_expired) {
392
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
393
+		}
394
+		if ($include_deleted) {
395
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
396
+		}
397
+		if ($limit) {
398
+			$query_params['limit'] = $limit;
399
+		}
400
+		/** @var EE_Datetime[] $result */
401
+		$result = $this->get_all($query_params);
402
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
403
+		return $result;
404
+	}
405
+
406
+
407
+	/**
408
+	 * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
409
+	 * datetimes.
410
+	 *
411
+	 * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
412
+	 * @param  boolean  $include_expired whether to include expired datetimes or not
413
+	 * @param  boolean  $include_deleted whether to include trashed datetimes or not.
414
+	 * @param  int|null $limit           if null, no limit, if int then limit results by
415
+	 *                                   that number
416
+	 * @return EE_Datetime[]
417
+	 * @throws EE_Error
418
+	 */
419
+	public function get_datetimes_for_ticket_ordered_by_DTT_order(
420
+		$TKT_ID,
421
+		$include_expired = true,
422
+		$include_deleted = true,
423
+		$limit = null
424
+	) {
425
+		// sanitize id.
426
+		$TKT_ID         = absint($TKT_ID);
427
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
428
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
429
+		$where_params = array('Ticket.TKT_ID' => $TKT_ID);
430
+		$query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
431
+		if (! $include_expired) {
432
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
433
+		}
434
+		if ($include_deleted) {
435
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
436
+		}
437
+		if ($limit) {
438
+			$query_params['limit'] = $limit;
439
+		}
440
+		/** @var EE_Datetime[] $result */
441
+		$result = $this->get_all($query_params);
442
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
443
+		return $result;
444
+	}
445
+
446
+
447
+	/**
448
+	 * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
449
+	 * reason it doesn't exist, we consider the earliest event the most important)
450
+	 *
451
+	 * @param int $EVT_ID
452
+	 * @return EE_Datetime
453
+	 * @throws EE_Error
454
+	 */
455
+	public function get_most_important_datetime_for_event($EVT_ID)
456
+	{
457
+		$results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
458
+		if ($results) {
459
+			return array_shift($results);
460
+		}
461
+		return null;
462
+	}
463
+
464
+
465
+	/**
466
+	 * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
467
+	 * grouped by month and year.
468
+	 *
469
+	 * @param  array  $where_params      @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
470
+	 * @param  string $evt_active_status A string representing the evt active status to filter the months by.
471
+	 *                                   Can be:
472
+	 *                                   - '' = no filter
473
+	 *                                   - upcoming = Published events with at least one upcoming datetime.
474
+	 *                                   - expired = Events with all datetimes expired.
475
+	 *                                   - active = Events that are published and have at least one datetime that
476
+	 *                                   starts before now and ends after now.
477
+	 *                                   - inactive = Events that are either not published.
478
+	 * @return EE_Base_Class[]
479
+	 * @throws EE_Error
480
+	 * @throws InvalidArgumentException
481
+	 * @throws InvalidArgumentException
482
+	 */
483
+	public function get_dtt_months_and_years($where_params, $evt_active_status = '')
484
+	{
485
+		$current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
486
+		$current_time_for_DTT_EVT_end   = $this->current_time_for_query('DTT_EVT_end');
487
+		switch ($evt_active_status) {
488
+			case 'upcoming':
489
+				$where_params['Event.status'] = 'publish';
490
+				// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
491
+				if (isset($where_params['DTT_EVT_start'])) {
492
+					$where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
493
+				}
494
+				$where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
495
+				break;
496
+			case 'expired':
497
+				if (isset($where_params['Event.status'])) {
498
+					unset($where_params['Event.status']);
499
+				}
500
+				// get events to exclude
501
+				$exclude_query[0] = array_merge(
502
+					$where_params,
503
+					array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end))
504
+				);
505
+				// first get all events that have datetimes where its not expired.
506
+				$event_ids = $this->_get_all_wpdb_results(
507
+					$exclude_query,
508
+					OBJECT_K,
509
+					'Datetime.EVT_ID'
510
+				);
511
+				$event_ids = array_keys($event_ids);
512
+				if (isset($where_params['DTT_EVT_end'])) {
513
+					$where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
514
+				}
515
+				$where_params['DTT_EVT_end']  = array('<', $current_time_for_DTT_EVT_end);
516
+				$where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
517
+				break;
518
+			case 'active':
519
+				$where_params['Event.status'] = 'publish';
520
+				if (isset($where_params['DTT_EVT_start'])) {
521
+					$where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
522
+				}
523
+				if (isset($where_params['Datetime.DTT_EVT_end'])) {
524
+					$where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
525
+				}
526
+				$where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
527
+				$where_params['DTT_EVT_end']   = array('>', $current_time_for_DTT_EVT_end);
528
+				break;
529
+			case 'inactive':
530
+				if (isset($where_params['Event.status'])) {
531
+					unset($where_params['Event.status']);
532
+				}
533
+				if (isset($where_params['OR'])) {
534
+					$where_params['AND']['OR'] = $where_params['OR'];
535
+				}
536
+				if (isset($where_params['DTT_EVT_end'])) {
537
+					$where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
538
+					unset($where_params['DTT_EVT_end']);
539
+				}
540
+				if (isset($where_params['DTT_EVT_start'])) {
541
+					$where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
542
+					unset($where_params['DTT_EVT_start']);
543
+				}
544
+				$where_params['AND']['Event.status'] = array('!=', 'publish');
545
+				break;
546
+		}
547
+		$query_params[0]          = $where_params;
548
+		$query_params['group_by'] = array('dtt_year', 'dtt_month');
549
+		$query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
550
+		$query_interval           = EEH_DTT_Helper::get_sql_query_interval_for_offset(
551
+			$this->get_timezone(),
552
+			'DTT_EVT_start'
553
+		);
554
+		$columns_to_select        = array(
555
+			'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
556
+			'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
557
+			'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
558
+		);
559
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
560
+	}
561
+
562
+
563
+	/**
564
+	 * Updates the DTT_sold attribute on each datetime (based on the registrations
565
+	 * for the tickets for each datetime)
566
+	 *
567
+	 * @param EE_Base_Class[]|EE_Datetime[] $datetimes
568
+	 * @throws EE_Error
569
+	 */
570
+	public function update_sold($datetimes)
571
+	{
572
+		EE_Error::doing_it_wrong(
573
+			__FUNCTION__,
574
+			esc_html__(
575
+				'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
576
+				'event_espresso'
577
+			),
578
+			'4.9.32.rc.005'
579
+		);
580
+		foreach ($datetimes as $datetime) {
581
+			$datetime->update_sold();
582
+		}
583
+	}
584
+
585
+
586
+	/**
587
+	 *    Gets the total number of tickets available at a particular datetime
588
+	 *    (does NOT take into account the datetime's spaces available)
589
+	 *
590
+	 * @param int   $DTT_ID
591
+	 * @param array $query_params
592
+	 * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
593
+	 *             tickets attached to datetime then FALSE is returned.
594
+	 */
595
+	public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
596
+	{
597
+		$datetime = $this->get_one_by_ID($DTT_ID);
598
+		if ($datetime instanceof EE_Datetime) {
599
+			return $datetime->tickets_remaining($query_params);
600
+		}
601
+		return 0;
602
+	}
603
+
604
+
605
+	/**
606
+	 * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
607
+	 *
608
+	 * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
609
+	 *                                 stati you want counts for as values in the array.  An empty array returns counts
610
+	 *                                 for all valid stati.
611
+	 * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
612
+	 *                                 only for Datetimes connected to a specific event, or specific ticket.
613
+	 * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
614
+	 * @throws EE_Error
615
+	 *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming
616
+	 *                                 EE_Datetime::expired
617
+	 */
618
+	public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
619
+	{
620
+		// only accept where conditions for this query.
621
+		$_where            = isset($query_params[0]) ? $query_params[0] : array();
622
+		$status_query_args = array(
623
+			EE_Datetime::active   => array_merge(
624
+				$_where,
625
+				array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
626
+			),
627
+			EE_Datetime::upcoming => array_merge(
628
+				$_where,
629
+				array('DTT_EVT_start' => array('>', time()))
630
+			),
631
+			EE_Datetime::expired  => array_merge(
632
+				$_where,
633
+				array('DTT_EVT_end' => array('<', time()))
634
+			),
635
+		);
636
+		if (! empty($stati_to_include)) {
637
+			foreach (array_keys($status_query_args) as $status) {
638
+				if (! in_array($status, $stati_to_include, true)) {
639
+					unset($status_query_args[ $status ]);
640
+				}
641
+			}
642
+		}
643
+		// loop through and query counts for each stati.
644
+		$status_query_results = array();
645
+		foreach ($status_query_args as $status => $status_where_conditions) {
646
+			$status_query_results[ $status ] = EEM_Datetime::count(
647
+				array($status_where_conditions),
648
+				'DTT_ID',
649
+				true
650
+			);
651
+		}
652
+		return $status_query_results;
653
+	}
654
+
655
+
656
+	/**
657
+	 * Returns the specific count for a given Datetime status matching any given query_params.
658
+	 *
659
+	 * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
660
+	 * @param array  $query_params
661
+	 * @return int
662
+	 * @throws EE_Error
663
+	 */
664
+	public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
665
+	{
666
+		$count = $this->get_datetime_counts_by_status(array($status), $query_params);
667
+		return ! empty($count[ $status ]) ? $count[ $status ] : 0;
668
+	}
669 669
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
                 ),
118 118
             ),
119 119
         );
120
-        $this->_model_relations        = array(
120
+        $this->_model_relations = array(
121 121
             'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
122 122
             'Event'   => new EE_Belongs_To_Relation(),
123 123
             'Checkin' => new EE_Has_Many_Relation(),
@@ -126,16 +126,16 @@  discard block
 block discarded – undo
126 126
         $this->model_chain_to_password = $path_to_event_model;
127 127
         $this->_model_chain_to_wp_user = $path_to_event_model;
128 128
         // this model is generally available for reading
129
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Event_Related_Public(
129
+        $this->_cap_restriction_generators[EEM_Base::caps_read]       = new EE_Restriction_Generator_Event_Related_Public(
130 130
             $path_to_event_model
131 131
         );
132
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected(
132
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected(
133 133
             $path_to_event_model
134 134
         );
135
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       = new EE_Restriction_Generator_Event_Related_Protected(
135
+        $this->_cap_restriction_generators[EEM_Base::caps_edit]       = new EE_Restriction_Generator_Event_Related_Protected(
136 136
             $path_to_event_model
137 137
         );
138
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     = new EE_Restriction_Generator_Event_Related_Protected(
138
+        $this->_cap_restriction_generators[EEM_Base::caps_delete]     = new EE_Restriction_Generator_Event_Related_Protected(
139 139
             $path_to_event_model,
140 140
             EEM_Base::caps_edit
141 141
         );
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      */
194 194
     public function get_all_event_dates($EVT_ID = 0)
195 195
     {
196
-        if (! $EVT_ID) { // on add_new_event event_id gets set to 0
196
+        if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
197 197
             return $this->create_new_blank_datetime();
198 198
         }
199 199
         $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
                 'order_by'                 => array('DTT_order' => 'ASC'),
240 240
                 'default_where_conditions' => 'none',
241 241
             );
242
-        if (! $include_expired) {
242
+        if ( ! $include_expired) {
243 243
             $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
244 244
         }
245 245
         if ($include_deleted) {
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
         $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
351 351
         $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
352 352
         $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
353
-        if (! $include_expired) {
353
+        if ( ! $include_expired) {
354 354
             $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
355 355
         }
356 356
         if ($include_deleted) {
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
         $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
389 389
         $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
390 390
         $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
391
-        if (! $include_expired) {
391
+        if ( ! $include_expired) {
392 392
             $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
393 393
         }
394 394
         if ($include_deleted) {
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
         $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
429 429
         $where_params = array('Ticket.TKT_ID' => $TKT_ID);
430 430
         $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
431
-        if (! $include_expired) {
431
+        if ( ! $include_expired) {
432 432
             $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
433 433
         }
434 434
         if ($include_deleted) {
@@ -551,10 +551,10 @@  discard block
 block discarded – undo
551 551
             $this->get_timezone(),
552 552
             'DTT_EVT_start'
553 553
         );
554
-        $columns_to_select        = array(
555
-            'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
556
-            'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
557
-            'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
554
+        $columns_to_select = array(
555
+            'dtt_year'      => array('YEAR('.$query_interval.')', '%s'),
556
+            'dtt_month'     => array('MONTHNAME('.$query_interval.')', '%s'),
557
+            'dtt_month_num' => array('MONTH('.$query_interval.')', '%s'),
558 558
         );
559 559
         return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
560 560
     }
@@ -633,17 +633,17 @@  discard block
 block discarded – undo
633 633
                 array('DTT_EVT_end' => array('<', time()))
634 634
             ),
635 635
         );
636
-        if (! empty($stati_to_include)) {
636
+        if ( ! empty($stati_to_include)) {
637 637
             foreach (array_keys($status_query_args) as $status) {
638
-                if (! in_array($status, $stati_to_include, true)) {
639
-                    unset($status_query_args[ $status ]);
638
+                if ( ! in_array($status, $stati_to_include, true)) {
639
+                    unset($status_query_args[$status]);
640 640
                 }
641 641
             }
642 642
         }
643 643
         // loop through and query counts for each stati.
644 644
         $status_query_results = array();
645 645
         foreach ($status_query_args as $status => $status_where_conditions) {
646
-            $status_query_results[ $status ] = EEM_Datetime::count(
646
+            $status_query_results[$status] = EEM_Datetime::count(
647 647
                 array($status_where_conditions),
648 648
                 'DTT_ID',
649 649
                 true
@@ -664,6 +664,6 @@  discard block
 block discarded – undo
664 664
     public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
665 665
     {
666 666
         $count = $this->get_datetime_counts_by_status(array($status), $query_params);
667
-        return ! empty($count[ $status ]) ? $count[ $status ] : 0;
667
+        return ! empty($count[$status]) ? $count[$status] : 0;
668 668
     }
669 669
 }
Please login to merge, or discard this patch.