GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
Public Member Functions | Static Public Member Functions | Data Fields | Private Attributes | Static Private Attributes
View Class Reference

If this file is called directly, abort. More...

Inheritance diagram for View:

Public Member Functions

 __construct ()
 The constructor. More...
 
 __get ( $key)
 
 as_data ()
 Be compatible with the old data object. More...
 
 can_render ( $context=null, $request=null)
 Checks whether this view can be accessed or not. More...
 
 get_anchor_id ()
 Returns the anchor ID to be used in the View container HTML id attribute. More...
 
 get_entries ( $request=null)
 Retrieve the entries for the current view and request. More...
 
 get_post ()
 Return associated WP post. More...
 
 get_query_class ()
 Return the query class for this View. More...
 
 offsetExists ( $offset)
 ArrayAccess compatibility layer with GravityView_View_Data::$views. More...
 
 offsetGet ( $offset)
 ArrayAccess compatibility layer with GravityView_View_Data::$views. More...
 
 offsetSet ( $offset, $value)
 ArrayAccess compatibility layer with GravityView_View_Data::$views. More...
 
 offsetUnset ( $offset)
 ArrayAccess compatibility layer with GravityView_View_Data::$views. More...
 
 set_anchor_id ( $counter=1)
 Sets the anchor ID of a View, without the prefix. More...
 

Static Public Member Functions

static _flush_cache ( $view_id=null)
 Flush the view cache. More...
 
static add_rewrite_endpoint ()
 Add extra rewrite endpoints. More...
 
static by_id ( $post_id)
 Construct a instance from a post ID. More...
 
static content ( $content)
 A renderer filter for the View post type content. More...
 
static exists ( $view)
 Determines if a view exists to begin with. More...
 
static from_post ( $post)
 Construct a instance from a . More...
 
static get_joined_forms ( $post_id)
 Get joined forms associated with a view In no particular order. More...
 
static get_joins ( $post)
 Get joins associated with a view. More...
 
static get_unions ( $post)
 Get unions associated with a view. More...
 
static register_post_type ()
 Register the gravityview WordPress Custom Post Type. More...
 
static restrict ( $caps, $cap, $user_id, $args)
 Restrict View access to specific capabilities. More...
 
static template_redirect ()
 Last chance to configure the output. More...
 

Data Fields

 $fields
 
 $form
 
 $joins = array()
 
 $settings
 
 $unions = array()
 
 $widgets
 

Private Attributes

 $anchor_id
 
 $post
 

Static Private Attributes

static $cache = array()
 

Detailed Description

If this file is called directly, abort.

The default GravityView View class.

Houses all base View functionality.

Can be accessed as an array for old compatibility's sake in line with the elements inside the ::$views array.

Definition at line 17 of file class-gv-view.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

The constructor.

Definition at line 107 of file class-gv-view.php.

Member Function Documentation

◆ __get()

__get (   $key)

Definition at line 1633 of file class-gv-view.php.

◆ _flush_cache()

static _flush_cache (   $view_id = null)
static

Flush the view cache.

Parameters
int$view_idThe View to reset cache for. Optional. Default: resets everything.

Definition at line 801 of file class-gv-view.php.

References $view_id.

◆ add_rewrite_endpoint()

static add_rewrite_endpoint ( )
static

Add extra rewrite endpoints.

Returns
void

CSV.

Definition at line 234 of file class-gv-view.php.

◆ as_data()

as_data ( )

Be compatible with the old data object.

Some external code expects an array (doing things like foreach on this, or array_keys) so let's return an array in the old format for such cases. Do not use unless using for back-compatibility.

Definition at line 930 of file class-gv-view.php.

References gravityview_get_form().

◆ by_id()

static by_id (   $post_id)
static

◆ can_render()

can_render (   $context = null,
  $request = null 
)

Checks whether this view can be accessed or not.

Parameters
string[]$context The context we're asking for access from. Can any and as many of one of: edit An edit context. single A single context. cpt The custom post type single page accessed. shortcode Embedded as a shortcode. oembed Embedded as an oEmbed. rest A REST call.
\GV\Request$requestThe request
Returns
bool| An error if this View shouldn't be rendered here.
Runs Filter:
gravityview/view/can_render Whether the view can be rendered or not.
Parameters
bool | \WP_Error$resultThe result. Default: null.
\GV\View$viewThe view.
string[]$context See ::can_render
\GV\Request$requestThe request.

This View is password protected. Nothing to do here.

Is this View directly accessible via a post URL?

See also
https://codex.wordpress.org/Function_Reference/register_post_type#public
Runs Filter:
gravityview_direct_access Should Views be directly accessible, or only visible using the shortcode?
Parameters
booleantrue: allow Views to be accessible directly. false: Only allow Views to be embedded. Default: true
int$view_idThe ID of the View currently being requested. 0 for general setting
Runs Filter:
gravityview/request/output/direct Should this View be directly accessbile?
Since
2.0
Parameters
booleanAccessible or not. Default: accessbile.
\GV\View$viewThe View we're trying to directly render here.
\GV\Request$requestThe current request.

Is this View an embed-only View? If so, don't allow rendering here, as this is a direct request.

Private, pending, draft, etc.

Definition at line 429 of file class-gv-view.php.

References gravityview(), and GVCommon\has_cap().

◆ content()

static content (   $content)
static

A renderer filter for the View post type content.

Parameters
string$contentShould be empty, as we don't store anything there.
Returns
string $content The view content as output by the renderers.

This is not a View. Bail.

Shortcodes and oEmbeds and whatnot will be handled elsewhere.

Check permissions.

This View has no data source. There's nothing to show really. ...apart from a nice message if the user can do anything about it.

Editing a single entry.

Viewing a single entry.

Plain old View.

Definition at line 264 of file class-gv-view.php.

References $content, $entry, $image, $title, GVCommon\check_entry_display(), gravityview(), GRAVITYVIEW_FILE, GVCommon\has_cap(), GravityView_Entry_Approval_Status\is_approved(), and GravityView_Entry_Approval\meta_key.

◆ exists()

static exists (   $view)
static

Determines if a view exists to begin with.

Parameters
int | \WP_Post | null$viewThe WordPress post ID, a object or null for global $post;
Since
2.0
Returns
bool Whether the post exists or not.

Definition at line 834 of file class-gv-view.php.

Referenced by GravityView_View_Data\maybe_get_view_id().

◆ from_post()

static from_post (   $post)
static

Construct a instance from a .

Parameters
\WP_Post$postThe instance to wrap.
Since
2.0
Returns
|null An instance around this if valid, null otherwise.
Runs Filter:
gravityview/view/get Override View.
Parameters
\GV\View$viewThe View instance pointer.
Since
2.1

Get connected form.

Runs Filter:
gravityview/configuration/fields Filter the View fields' configuration array.
Since
1.6.5
Parameters
$fieldsarray Multi-array of fields with first level being the field zones.
$view_idint The View the fields are being pulled for.
Runs Filter:
gravityview/view/configuration/fields Filter the View fields' configuration array.
Since
2.0
Parameters
array$fieldsMulti-array of fields with first level being the field zones.
\GV\View$viewThe View the fields are being pulled for.
Runs Filter:
gravityview/view/fields Filter the Field Collection for this View.
Since
2.0
Parameters
\GV\Field_Collection$fieldsA collection of fields.
\GV\View$viewThe View the fields are being pulled for.
Runs Filter:
gravityview/view/configuration/widgets Filter the View widgets' configuration array.
Since
2.0
Parameters
array$fieldsMulti-array of widgets with first level being the field zones.
\GV\View$viewThe View the widgets are being pulled for.
Runs Filter:
gravityview/view/widgets Filter the Widget Collection for this View.
Since
2.0
Parameters
\GV\Widget_Collection$widgetsA collection of widgets.
\GV\View$viewThe View the widgets are being pulled for.

View configuration.

Add the template name into the settings.

View basics.

Runs Filter:
gravityview/view/get Override View.
Parameters
\GV\View$viewThe View instance pointer.
Since
2.1

Definition at line 689 of file class-gv-view.php.

References $post, gravityview(), gravityview_get_template_id(), and gravityview_get_template_settings().

Referenced by Request\is_view(), oEmbed\parse_matches(), Views_Route\prepare_view_for_response(), GravityView_Admin_Views\render_active_areas(), and GravityView_Admin_Metaboxes\render_view_configuration_metabox().

◆ get_anchor_id()

get_anchor_id ( )

Returns the anchor ID to be used in the View container HTML id attribute.

Since
2.15
Returns
string Unsanitized anchor ID.
Runs Filter:
gravityview/view/anchor_id Modify the anchor ID.
Since
2.15
Parameters
string$anchor_idThe anchor ID.
\GV\View$thisThe View.

Definition at line 1623 of file class-gv-view.php.

◆ get_entries()

get_entries (   $request = null)

Retrieve the entries for the current view and request.

Parameters

Remove multiple sorting before calling legacy filters. This allows us to fake it till we make it.

Cleanup duplicate field_filter parameters to simplify the query.

$query

Apply multisort.

Merge time subfield sorts.

ORDER again.

Any joins?

This is a temporary stub filter, until GF_Query supports NULL conditions. Do not use! This filter will be removed.

Unions?

Parameters
\GF_Query_Condition$condition
array$fields
$recurse
Returns

| $q

Runs Actions:
gravityview/view/query Override the before the get() call.
Parameters
\GF_Query$queryThe current query object reference
\GV\View$thisThe current view object
\GV\Request$requestThe request object

Map from Gravity Forms entries arrays to an Entry_Collection.

Add total count callback.

Runs Filter:
gravityview/view/entries Modify the entry fetching filters, sorts, offsets, limits.
Parameters
\GV\Entry_Collection$entriesThe entries for this view.
\GV\View$viewThe view.
\GV\Request$requestThe request.

Definition at line 950 of file class-gv-view.php.

References $entries, $entry, $field, $form_id, GravityView_frontend\_override_sorting_id_by_field_type(), GravityView_Entry_Approval_Status\APPROVED, Entry_Sort\ASC, GVCommon\calculate_get_entries_criteria(), Entry_Sort\DESC, Utils\get(), gravityview(), GVCommon\has_cap(), GVCommon\is_field_numeric(), and GravityView_Entry_Approval\meta_key.

◆ get_joined_forms()

static get_joined_forms (   $post_id)
static

Get joined forms associated with a view In no particular order.

Since
2.0.11
2.0
Parameters
int$post_idID of the View
Returns
[] Array of instances

Definition at line 582 of file class-gv-view.php.

References GV\$form, $forms, and gravityview().

Referenced by GravityView_Admin_Views\render_field_pickers().

◆ get_joins()

static get_joins (   $post)
static

Get joins associated with a view.

Parameters
\WP_Post$postGravityView CPT to get joins for
Since
2.0.11
Returns
[] Array of instances

Definition at line 532 of file class-gv-view.php.

References $post, and gravityview().

◆ get_post()

get_post ( )

Return associated WP post.

Since
2.13.2
Returns
|null

Definition at line 1648 of file class-gv-view.php.

◆ get_query_class()

get_query_class ( )

Return the query class for this View.

Returns
string The class name.
Runs Filter:
gravityview/query/class
Parameters
stringThe query class. Default: GF_Query.
\GV\View$thisThe View.

Definition at line 1543 of file class-gv-view.php.

◆ get_unions()

static get_unions (   $post)
static

Get unions associated with a view.

Parameters
\WP_Post$postGravityView CPT to get unions for
Since
2.2.2
Returns
[][] Array of unions (see self::$unions)

Definition at line 634 of file class-gv-view.php.

References $field, $field_id, $form_id, $post, Internal_Field\by_id(), GF_Field\by_id(), and gravityview().

◆ offsetExists()

offsetExists (   $offset)

ArrayAccess compatibility layer with GravityView_View_Data::$views.

Definition at line 847 of file class-gv-view.php.

◆ offsetGet()

offsetGet (   $offset)

ArrayAccess compatibility layer with GravityView_View_Data::$views.

Maps the old keys to the new data;

Definition at line 864 of file class-gv-view.php.

References GV\$form, and gravityview().

◆ offsetSet()

offsetSet (   $offset,
  $value 
)

ArrayAccess compatibility layer with GravityView_View_Data::$views.

Definition at line 901 of file class-gv-view.php.

References gravityview().

◆ offsetUnset()

offsetUnset (   $offset)

ArrayAccess compatibility layer with GravityView_View_Data::$views.

Definition at line 914 of file class-gv-view.php.

References gravityview().

◆ register_post_type()

static register_post_type ( )
static

Register the gravityview WordPress Custom Post Type.

Register only once

Runs Filter:
gravityview_is_hierarchical Make GravityView Views hierarchical by returning TRUE This will allow for Views to be nested with Parents and also allows for menu order to be set in the Page Attributes metabox
Since
1.13
Parameters
boolean$is_hierarchicalDefault: false
Runs Filter:
gravityview_post_type_supports Modify post type support values for gravityview post type
See also
add_post_type_support()
Since
1.15.2
Parameters
array$supportsArray of features associated with a functional area of the edit screen. Default: 'title', 'revisions'. If $is_hierarchical, also 'page-attributes'
boolean$is_hierarchicalDo Views support parent/child relationships? See gravityview_is_hierarchical filter.

Register Custom Post Type - gravityview

Runs Filter:
gravityview_direct_access Should Views be directly accessible, or only visible using the shortcode?
See also
https://codex.wordpress.org/Function_Reference/register_post_type#public
Since
1.15.2
Parameters
booleantrue: allow Views to be accessible directly. false: Only allow Views to be embedded via shortcode. Default: true
int$view_idThe ID of the View currently being requested. 0 for general setting
Runs Filter:
gravityview_has_archive Enable Custom Post Type archive?
Since
1.7.3
Parameters
booleanFalse: don't have frontend archive; True: yes, have archive. Default: false
Runs Filter:
gravityview_slug Modify the url part for a View.
See also
https://docs.gravityview.co/article/62-changing-the-view-slug
Parameters
string$slugThe slug shown in the URL
Runs Filter:
gravityview/post_type/with_front Should the permalink structure be prepended with the front base. (example: if your permalink structure is /blog/, then your links will be: false->/view/, true->/blog/view/). Defaults to true.
See also
https://codex.wordpress.org/Function_Reference/register_post_type
Since
2.0
Parameters
bool$with_front

Definition at line 119 of file class-gv-view.php.

References $args, $labels, gravityview(), and GravityView_Admin\no_views_text().

Referenced by GravityView_Post_Types\init_post_types().

◆ restrict()

static restrict (   $caps,
  $cap,
  $user_id,
  $args 
)
static

Restrict View access to specific capabilities.

Hooked into map_meta_cap WordPress filter.

Since
develop
Parameters
$capsarray The output capabilities.
$capstring The cap that is being checked.
$user_idint The User ID.
$argsarray Additional arguments to the capability.
Returns
array The resulting capabilities.
Runs Filter:
gravityview/security/require_unfiltered_html Bypass restrictions on Views that require unfiltered_html.
Parameters
boolean
Since
develop
Parameters
string$capThe capability requested.
int$user_idThe user ID.
array$argsAny additional args to map_meta_cap

Definition at line 1567 of file class-gv-view.php.

References $args, and endswitch.

◆ set_anchor_id()

set_anchor_id (   $counter = 1)

Sets the anchor ID of a View, without the prefix.

Since
2.15
Parameters
int$counterAn incremental counter reflecting how many times this View has been rendered.
Returns
void

Definition at line 1612 of file class-gv-view.php.

◆ template_redirect()

static template_redirect ( )
static

Last chance to configure the output.

Used for CSV output, for example.

Returns
void

CSV output.

Runs Filter:
gravityview/output/{csv|tsv}/filename Modify the name of the generated CSV or TSV file. Name will be sanitized using sanitize_file_name() before output.
See also
sanitize_file_name()
Since
2.1
Parameters
string$filenameFile name used when downloading a CSV or TSV. Default is "{View title}.csv" or "{View title}.tsv"
\GV\View$viewCurrent View being rendered

Add da' BOM if GF uses it

See also
GFExport::start_export()
Runs Filter:
gravityview/csv/entry/fields Allowlist more entry fields by ID that are output in CSV requests.
Parameters
array$allowedThe allowed ones, default by_visible, by_position( "context_*" ), i.e. as set in the View.
\GV\View$viewThe view.
\GV\Entry$entryWordPress representation of the item.

Definition at line 1420 of file class-gv-view.php.

References $entries, $entry, $field, $field_id, $label, Internal_Field\by_id(), GF_Field\by_id(), and gravityview().

Field Documentation

◆ $anchor_id

$anchor_id
private

Definition at line 67 of file class-gv-view.php.

◆ $cache

$cache = array()
staticprivate

Definition at line 77 of file class-gv-view.php.

◆ $fields

$fields

Definition at line 58 of file class-gv-view.php.

◆ $form

$form

Definition at line 48 of file class-gv-view.php.

◆ $joins

$joins = array()

Definition at line 85 of file class-gv-view.php.

◆ $post

$post
private

Definition at line 22 of file class-gv-view.php.

◆ $settings

$settings

Definition at line 30 of file class-gv-view.php.

◆ $unions

$unions = array()

Definition at line 102 of file class-gv-view.php.

◆ $widgets

$widgets

Definition at line 38 of file class-gv-view.php.


The documentation for this class was generated from the following file: