Completed
Push — develop ( 43115e...aad3f3 )
by Zack
09:31
created

connector-functions.php ➔ gravityview_get_joined_forms()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Set of functions to separate main plugin from Gravity Forms API and other methods
4
 *
5
 * @package   GravityView
6
 * @license   GPL2+
7
 * @author    Katz Web Services, Inc.
8
 * @link      http://gravityview.co
9
 * @copyright Copyright 2014, Katz Web Services, Inc.
10
 *
11
 * @since 1.0.0
12
 */
13
14
use GV\View;
15
16
/**
17
 * Returns the form object for a given Form ID.
18
 * @see GVCommon::get_form()
19
 * @access public
20
 * @param mixed $form_id
21
 * @return mixed False: no form ID specified or Gravity Forms isn't active. Array: Form returned from Gravity Forms
22
 */
23
function gravityview_get_form( $form_id ) {
24 23
	return GVCommon::get_form( $form_id );
25
}
26
27
28
/**
29
 * Get the form array for an entry based only on the entry ID
30
 * @see GVCommon::get_form_from_entry_id
31
 * @param  int|string $entry_slug Entry slug
32
 * @return array           Gravity Forms form array
33
 */
34
function gravityview_get_form_from_entry_id( $entry_slug ) {
35
	return GVCommon::get_form_from_entry_id( $entry_slug );
36
}
37
38
39
/**
40
 * Alias of GFAPI::get_forms()
41
 *
42
 * @see GFAPI::get_forms()
43
 *
44
 * @since 1.19 Allow "any" $active status option
45
 *
46
 * @param bool|string $active Status of forms. Use `any` to get array of forms with any status. Default: `true`
47
 * @param bool $trash Include forms in trash? Default: `false`
48
 *
49
 * @return array Empty array if GFAPI class isn't available or no forms. Otherwise, the array of Forms
50
 */
51
function gravityview_get_forms( $active = true, $trash = false ) {
52
	return GVCommon::get_forms( $active, $trash );
53
}
54
55
/**
56
 * Return array of fields' id and label, for a given Form ID
57
 *
58
 * @see GVCommon::get_form_fields()
59
 * @access public
60
 * @param string|array $form_id (default: '') or $form object
0 ignored issues
show
Bug introduced by
There is no parameter named $form_id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
61
 * @return array
62
 */
63
function gravityview_get_form_fields( $form = '', $add_default_properties = false, $include_parent_field = true ) {
64
	return GVCommon::get_form_fields( $form, $add_default_properties, $include_parent_field );
65
}
66
67
/**
68
 * get extra fields from entry meta
69
 * @param  string $form_id (default: '')
70
 * @return array
71
 */
72
function gravityview_get_entry_meta( $form_id, $only_default_column = true ) {
73
	return GVCommon::get_entry_meta( $form_id, $only_default_column );
74
}
75
76
/**
77
 * Wrapper for the Gravity Forms GFFormsModel::search_lead_ids() method
78
 *
79
 * @see  GFEntryList::leads_page()
80
 * @param  int $form_id ID of the Gravity Forms form
81
 * @since  1.1.6
82
 * @return array          Array of entry IDs
83
 */
84
function gravityview_get_entry_ids( $form_id, $search_criteria = array() ) {
85
	return GVCommon::get_entry_ids( $form_id, $search_criteria );
86
}
87
88
89
/**
90
 * Retrieve entries given search, sort, paging criteria
91
 *
92
 * @see  GFAPI::get_entries()
93
 * @see GFFormsModel::get_field_filters_where()
94
 * @access public
95
 * @param int|array $form_ids The ID of the form or an array IDs of the Forms. Zero for all forms.
96
 * @param mixed $passed_criteria (default: null)
97
 * @param mixed &$total (default: null)
98
 * @return mixed False: Error fetching entries. Array: Multi-dimensional array of Gravity Forms entry arrays
99
 */
100
function gravityview_get_entries( $form_ids = null, $passed_criteria = null, &$total = null ) {
101
	return GVCommon::get_entries( $form_ids, $passed_criteria, $total );
102
}
103
104
/**
105
 * Return a single entry object
106
 *
107
 * Since 1.4, supports custom entry slugs. The way that GravityView fetches an entry based on the custom slug is by searching `gravityview_unique_id` meta. The `$entry_slug` is fetched by getting the current query var set by `is_single_entry()`
108
 *
109
 * @access public
110
 * @param mixed $entry_id
0 ignored issues
show
Bug introduced by
There is no parameter named $entry_id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
111
 * @param boolean $force_allow_ids Force the get_entry() method to allow passed entry IDs, even if the `gravityview_custom_entry_slug_allow_id` filter returns false.
112
 * @param boolean $check_entry_display Check whether the entry is visible for the current View configuration. Default: true {@since 1.14}
113
 * @return array|boolean
114
 */
115
function gravityview_get_entry( $entry_slug, $force_allow_ids = false, $check_entry_display = true ) {
116 1
	return GVCommon::get_entry( $entry_slug, $force_allow_ids, $check_entry_display );
117
}
118
119
/**
120
 * Retrieve the label of a given field id (for a specific form)
121
 *
122
 * @access public
123
 * @param mixed $form
124
 * @param mixed $field_id
125
 * @return string
126
 */
127
function gravityview_get_field_label( $form, $field_id, $field_value = '' ) {
128 1
	return GVCommon::get_field_label( $form, $field_id, $field_value );
129
}
130
131
132
/**
133
 * Returns the field details array of a specific form given the field id
134
 *
135
 * Alias of GFFormsModel::get_field
136
 *
137
 * @since 1.19 Allow passing form ID as well as form array
138
 *
139
 * @uses GVCommon::get_field
140
 * @see GFFormsModel::get_field
141
 * @access public
142
 * @param array|int $form Form array or ID
143
 * @param string|int $field_id
144
 * @return GF_Field|null Returns NULL if field with ID $field_id doesn't exist.
145
 */
146
function gravityview_get_field( $form, $field_id ) {
147
	return GVCommon::get_field( $form, $field_id );
148
}
149
150
151
/**
152
 * Check whether the post is GravityView
153
 *
154
 * - Check post type. Is it `gravityview`?
155
 * - Check shortcode
156
 *
157
 * @param  WP_Post      $post WordPress post object
158
 * @return boolean           True: yep, GravityView; No: not!
159
 */
160
function has_gravityview_shortcode( $post = NULL ) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
161 1
	return GVCommon::has_gravityview_shortcode( $post );
162
}
163
164
/**
165
 * Placeholder until the recursive has_shortcode() patch is merged
166
 * @see https://core.trac.wordpress.org/ticket/26343#comment:10
167
 */
168
function gravityview_has_shortcode_r( $content, $tag = 'gravityview' ) {
169 1
	return GVCommon::has_shortcode_r( $content, $tag );
170
}
171
172
/**
173
 * Get the views for a particular form
174
 *
175
 * @since 1.22.1 Added $args param
176
 *
177
 * @param  int $form_id Gravity Forms form ID
178
 * @param  array $args Pass args sent to get_posts()
179
 *
180
 * @return array          Array with view details
181
 */
182
function gravityview_get_connected_views( $form_id, $args = array() ) {
183
	return GVCommon::get_connected_views( $form_id, $args );
184
}
185
186
/**
187
 * Get the connected form ID from a View ID
188
 *
189
 * @see GVCommon::get_meta_form_id
190
 *
191
 * @param int $view_id ID of the View you want the form of
192
 *
193
 * @return false|string ID of the connected Form, if exists. Empty string if not. False if not the View ID isn't valid.
194
 */
195
function gravityview_get_form_id( $view_id ) {
196
	return GVCommon::get_meta_form_id( $view_id );
197
}
198
199
/**
200
 * Get joined forms associated with a view
201
 *
202
 * @param $view_id
203
 *
204
 * @return \GV\GF_Form[]|null Array of \GV\GF_Form instances
205
 */
206
function gravityview_get_joined_forms( $view_id ) {
207
	return View::get_joined_forms( $view_id );
208
}
209
210
/**
211
 * Get the template ID (`list`, `table`, `datatables`, `map`) for a View
212
 *
213
 * @see GravityView_Template::template_id
214
 *
215
 * @param int $view_id The ID of the View to get the layout of
0 ignored issues
show
Bug introduced by
There is no parameter named $view_id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
216
 *
217
 * @return string GravityView_Template::template_id value. Empty string if not.
218
 */
219
function gravityview_get_template_id( $post_id ) {
220 71
	return GVCommon::get_meta_template_id( $post_id );
221
}
222
223
/**
224
 * Get all the settings for a View
225
 *
226
 * @uses  \GV\View_Settings::defaults() Parses the settings with the plugin defaults as backups.
227
 * @param  int $post_id View ID
228
 * @return array          Associative array of settings with plugin defaults used if not set by the View
229
 */
230
function gravityview_get_template_settings( $post_id ) {
231 71
	return GVCommon::get_template_settings( $post_id );
232
}
233
234
/**
235
 * Get the setting for a View
236
 *
237
 * If the setting isn't set by the View, it returns the plugin default.
238
 *
239
 * @param  int $post_id View ID
240
 * @param  string $key     Key for the setting
241
 * @return mixed|null          Setting value, or NULL if not set.
242
 */
243
function gravityview_get_template_setting( $post_id, $key ) {
244
	return GVCommon::get_template_setting( $post_id, $key );
245
}
246
247
/**
248
 * Get all available preset templates
249
 * @since 1.13.2
250
 * @return array Templates
251
 */
252
function gravityview_get_registered_templates() {
253
254
	/**
255
	 * @filter `gravityview_register_directory_template` Fetch available View templates
256
	 * @param array $templates Templates to show
257
	 */
258
	$templates = apply_filters( 'gravityview_register_directory_template', array() );
259
260
	return $templates;
261
}
262
263
/**
264
 * Get the field configuration for the View
265
 *
266
 * array(
267
 *
268
 * 	[other zones]
269
 *
270
 * 	'directory_list-title' => array(
271
 *
272
 *   	[other fields]
273
 *
274
 *  	'5372653f25d44' => array(
275
 *  		'id' => string '9' (length=1)
276
 *  		'label' => string 'Screenshots' (length=11)
277
 *			'show_label' => string '1' (length=1)
278
 *			'custom_label' => string '' (length=0)
279
 *			'custom_class' => string 'gv-gallery' (length=10)
280
 * 			'only_loggedin' => string '0' (length=1)
281
 *			'only_loggedin_cap' => string 'read' (length=4)
282
 *  	)
283
 *
284
 * 		[other fields]
285
 *  )
286
 *
287
 * 	[other zones]
288
 * )
289
 *
290
 * @since 1.17.4 Added $apply_filter parameter
291
 *
292
 * @param  int $post_id View ID
293
 * @param  bool $apply_filter Whether to apply the `gravityview/configuration/fields` filter [Default: true]
294
 * @return array          Multi-array of fields with first level being the field zones. See code comment.
295
 */
296
function gravityview_get_directory_fields( $post_id, $apply_filter = true ) {
297 1
	return GVCommon::get_directory_fields( $post_id, $apply_filter );
298
}
299
300
/**
301
 * Get the widgets, as configured for a View
302
 *
303
 * @since 1.17.4
304
 *
305
 * @param int $post_id
306
 *
307
 * @return array
308
 */
309
function gravityview_get_directory_widgets( $post_id ) {
310
	return get_post_meta( $post_id, '_gravityview_directory_widgets', true );
311
}
312
313
/**
314
 * Set the widgets, as configured for a View
315
 *
316
 * @since 1.17.4
317
 *
318
 * @param int $post_id
319
 * @param array $widgets array of widgets
320
 *
321
 * @return int|bool
322
 */
323
function gravityview_set_directory_widgets( $post_id, $widgets = array() ) {
324
	return update_post_meta( $post_id, '_gravityview_directory_widgets', $widgets );
325
}
326
327
/**
328
 * Render dropdown (select) with the list of sortable fields from a form ID
329
 *
330
 * @access public
331
 * @param  int $formid Form ID
332
 * @param string $current Field ID of field used to sort
333
 * @return string         html
334
 */
335
function gravityview_get_sortable_fields( $formid, $current = '' ) {
336
	return GVCommon::get_sortable_fields( $formid, $current );
337
}
338
339
340
/**
341
 * Returns the GF Form field type for a certain field(id) of a form
342
 * @param  object $form     Gravity Forms form
343
 * @param  mixed $field_id Field ID or Field array
344
 * @return string field type
345
 */
346
function gravityview_get_field_type(  $form = null , $field_id = '' ) {
0 ignored issues
show
introduced by
Expected 0 spaces between argument "$form" and comma; 1 found
Loading history...
347
	return GVCommon::get_field_type(  $form, $field_id );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 2 found
Loading history...
348
}
349
350
351
/**
352
 * Theme function to get a GravityView view
353
 *
354
 * @access public
355
 * @param string $view_id (default: '')
356
 * @param array $atts (default: array())
357
 * @return string HTML of the output. Empty string if $view_id is empty.
358
 */
359
function get_gravityview( $view_id = '', $atts = array() ) {
360
	if( !empty( $view_id ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
361
		$atts['id'] = $view_id;
362
		$args = wp_parse_args( $atts, \GV\View_Settings::defaults() );
363
		$GravityView_frontend = GravityView_frontend::getInstance();
364
		$GravityView_frontend->setGvOutputData( GravityView_View_Data::getInstance( $view_id ) );
365
		$GravityView_frontend->set_context_view_id( $view_id );
366
		$GravityView_frontend->set_entry_data();
367
		return $GravityView_frontend->render_view( $args );
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_frontend::render_view() has been deprecated with message: Use \GV\View_Renderer

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
368
	}
369
	return '';
370
}
371
372
/**
373
 * Theme function to render a GravityView view
374
 *
375
 * @access public
376
 * @param string $view_id (default: '')
377
 * @param array $atts (default: array())
378
 * @return void
379
 */
380
function the_gravityview( $view_id = '', $atts = array() ) {
381
	echo get_gravityview( $view_id, $atts );
382
}
383
384
385
/**
386
 * Theme function to identify if it is a Single Entry View
387
 *
388
 * @since  1.5.4
389
 * @return bool|string False if not, single entry slug if true
390
 */
391
function gravityview_is_single_entry() {
392
	return GravityView_frontend::is_single_entry();
393
}
394
395
/**
396
 * Determine whether a View has a single checkbox or single radio input
397
 * @see GravityView_frontend::add_scripts_and_styles()
398
 * @since 1.15
399
 * @param array $form Gravity Forms form
400
 * @param array $view_fields GravityView fields array
401
 */
402
function gravityview_view_has_single_checkbox_or_radio( $form, $view_fields ) {
403
404
	if( class_exists('GFFormsModel') && $form_fields = GFFormsModel::get_fields_by_type( $form, array( 'checkbox', 'radio' ) ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
405
406
		/** @var GF_Field_Radio|GF_Field_Checkbox $form_field */
407
		foreach( $form_fields as $form_field ) {
408
			$field_id = $form_field->id;
409
			foreach( $view_fields as $zone ) {
410
411
				// ACF compatibility; ACF-added fields aren't arrays
412
				if ( ! is_array( $zone ) ) { continue; }
413
414
				foreach( $zone as $field ) {
415
					// If it's an input, not the parent and the parent ID matches a checkbox or radio
416
					if( ( strpos( $field['id'], '.' ) > 0 ) && floor( $field['id'] ) === floor( $field_id ) ) {
417
						return true;
418
					}
419
				}
420
			}
421
		}
422
	}
423
424
	return false;
425
}