Completed
Push — master ( b11340...af41d1 )
by Zack
39:23 queued 35:10
created

View::offsetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 17 and the first side effect is on line 6.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace GV;
3
4
/** If this file is called directly, abort. */
5
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6
	die();
7
}
8
9
/**
10
 * The default GravityView View class.
11
 *
12
 * Houses all base View functionality.
13
 *
14
 * Can be accessed as an array for old compatibility's sake
15
 *  in line with the elements inside the \GravityView_View_Data::$views array.
16
 */
17
class View implements \ArrayAccess {
18
19
	/**
20
	 * @var \WP_Post The backing post instance.
21
	 */
22
	private $post;
23
24
	/**
25
	 * @var \GV\View_Settings The settings.
26
	 *
27
	 * @api
28
	 * @since 2.0
29
	 */
30
	public $settings;
31
32
	/**
33
	 * @var \GV\Widget_Collection The widets attached here.
34
	 *
35
	 * @api
36
	 * @since 2.0
37
	 */
38
	public $widgets;
39
40
	/**
41
	 * @var \GV\GF_Form|\GV\Form The backing form for this view.
42
	 *
43
	 * Contains the form that is sourced for entries in this view.
44
	 *
45
	 * @api
46
	 * @since 2.0
47
	 */
48
	public $form;
49
50
	/**
51
	 * @var \GV\Field_Collection The fields for this view.
52
	 *
53
	 * Contains all the fields that are attached to this view.
54
	 *
55
	 * @api
56
	 * @since 2.0
57
	 */
58
	public $fields;
59
60
	/**
61
	 * @var array
62
	 *
63
	 * Internal static cache for gets, and whatnot.
64
	 * This is not persistent, resets across requests.
65
66
	 * @internal
67
	 */
68
	private static $cache = array();
69
70
	/**
71
	 * @var \GV\Join[] The joins for all sources in this view.
72
	 *
73
	 * @api
74
	 * @since future
75
	 */
76
	public $joins = array();
77
78
	/**
79
	 * The constructor.
80
	 */
81 71
	public function __construct() {
82 71
		$this->settings = new View_Settings();
83 71
		$this->fields = new Field_Collection();
84 71
		$this->widgets = new Widget_Collection();
85 71
	}
86
87
	/**
88
	 * Register the gravityview WordPress Custom Post Type.
89
	 *
90
	 * @internal
91
	 * @return void
92
	 */
93
	public static function register_post_type() {
94
95
		/** Register only once */
96
		if ( post_type_exists( 'gravityview' ) ) {
97
			return;
98
		}
99
100
		/**
101
		 * @filter `gravityview_is_hierarchical` Make GravityView Views hierarchical by returning TRUE
102
		 * This will allow for Views to be nested with Parents and also allows for menu order to be set in the Page Attributes metabox
103
		 * @since 1.13
104
		 * @param boolean $is_hierarchical Default: false
105
		 */
106
		$is_hierarchical = (bool)apply_filters( 'gravityview_is_hierarchical', false );
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
107
108
		$supports = array( 'title', 'revisions' );
109
110
		if ( $is_hierarchical ) {
111
			$supports[] = 'page-attributes';
112
		}
113
114
		/**
115
		 * @filter  `gravityview_post_type_supports` Modify post type support values for `gravityview` post type
116
		 * @see add_post_type_support()
117
		 * @since 1.15.2
118
		 * @param array $supports Array of features associated with a functional area of the edit screen. Default: 'title', 'revisions'. If $is_hierarchical, also 'page-attributes'
119
		 * @param[in] boolean $is_hierarchical Do Views support parent/child relationships? See `gravityview_is_hierarchical` filter.
120
		 */
121
		$supports = apply_filters( 'gravityview_post_type_support', $supports, $is_hierarchical );
122
123
		/** Register Custom Post Type - gravityview */
124
		$labels = array(
125
			'name'                => _x( 'Views', 'Post Type General Name', 'gravityview' ),
126
			'singular_name'       => _x( 'View', 'Post Type Singular Name', 'gravityview' ),
127
			'menu_name'           => _x( 'Views', 'Menu name', 'gravityview' ),
128
			'parent_item_colon'   => __( 'Parent View:', 'gravityview' ),
129
			'all_items'           => __( 'All Views', 'gravityview' ),
130
			'view_item'           => _x( 'View', 'View Item', 'gravityview' ),
131
			'add_new_item'        => __( 'Add New View', 'gravityview' ),
132
			'add_new'             => __( 'New View', 'gravityview' ),
133
			'edit_item'           => __( 'Edit View', 'gravityview' ),
134
			'update_item'         => __( 'Update View', 'gravityview' ),
135
			'search_items'        => __( 'Search Views', 'gravityview' ),
136
			'not_found'           => \GravityView_Admin::no_views_text(),
137
			'not_found_in_trash'  => __( 'No Views found in Trash', 'gravityview' ),
138
			'filter_items_list'     => __( 'Filter Views list', 'gravityview' ),
139
			'items_list_navigation' => __( 'Views list navigation', 'gravityview' ),
140
			'items_list'            => __( 'Views list', 'gravityview' ),
141
			'view_items'            => __( 'See Views', 'gravityview' ),
142
			'attributes'            => __( 'View Attributes', 'gravityview' ),
143
		);
144
		$args = array(
145
			'label'               => __( 'view', 'gravityview' ),
146
			'description'         => __( 'Create views based on a Gravity Forms form', 'gravityview' ),
147
			'labels'              => $labels,
148
			'supports'            => $supports,
149
			'hierarchical'        => $is_hierarchical,
150
			/**
151
			 * @filter `gravityview_direct_access` Should Views be directly accessible, or only visible using the shortcode?
152
			 * @see https://codex.wordpress.org/Function_Reference/register_post_type#public
153
			 * @since 1.15.2
154
			 * @param[in,out] boolean `true`: allow Views to be accessible directly. `false`: Only allow Views to be embedded via shortcode. Default: `true`
155
			 * @param int $view_id The ID of the View currently being requested. `0` for general setting
156
			 */
157
			'public'              => apply_filters( 'gravityview_direct_access', gravityview()->plugin->is_compatible(), 0 ),
158
			'show_ui'             => gravityview()->plugin->is_compatible(),
159
			'show_in_menu'        => gravityview()->plugin->is_compatible(),
160
			'show_in_nav_menus'   => true,
161
			'show_in_admin_bar'   => true,
162
			'menu_position'       => 17,
163
			'menu_icon'           => '',
164
			'can_export'          => true,
165
			/**
166
			 * @filter `gravityview_has_archive` Enable Custom Post Type archive?
167
			 * @since 1.7.3
168
			 * @param boolean False: don't have frontend archive; True: yes, have archive. Default: false
169
			 */
170
			'has_archive'         => apply_filters( 'gravityview_has_archive', false ),
171
			'exclude_from_search' => true,
172
			'rewrite'             => array(
173
				/**
174
				 * @filter `gravityview_slug` Modify the url part for a View.
175
				 * @see https://docs.gravityview.co/article/62-changing-the-view-slug
176
				 * @param string $slug The slug shown in the URL
177
				 */
178
				'slug' => apply_filters( 'gravityview_slug', 'view' ),
179
180
				/**
181
				 * @filter `gravityview/post_type/with_front` Should the permalink structure
182
				 *  be prepended with the front base.
183
				 *  (example: if your permalink structure is /blog/, then your links will be: false->/view/, true->/blog/view/).
184
				 *  Defaults to true.
185
				 * @see https://codex.wordpress.org/Function_Reference/register_post_type
186
				 * @since 2.0
187
				 * @param bool $with_front
188
				 */
189
				'with_front' => apply_filters( 'gravityview/post_type/with_front', true ),
190
			),
191
			'capability_type'     => 'gravityview',
192
			'map_meta_cap'        => true,
193
		);
194
195
		register_post_type( 'gravityview', $args );
196
	}
197
198
	/**
199
	 * A renderer filter for the View post type content.
200
	 *
201
	 * @param string $content Should be empty, as we don't store anything there.
202
	 *
203
	 * @return string $content The view content as output by the renderers.
204
	 */
205 8
	public static function content( $content ) {
206 8
		$request = gravityview()->request;
207
208
		// Plugins may run through the content in the header. WP SEO does this for its OpenGraph functionality.
209 8
		if ( ! defined( 'DOING_GRAVITYVIEW_TESTS' ) ) {
210
			if ( ! did_action( 'loop_start' ) ) {
211
				gravityview()->log->debug( 'Not processing yet: loop_start hasn\'t run yet. Current action: {action}', array( 'action' => current_filter() ) );
212
				return $content;
213
			}
214
215
			//	We don't want this filter to run infinite loop on any post content fields
216
			remove_filter( 'the_content', array( __CLASS__, __METHOD__ ) );
217
		}
218
219
		/**
220
		 * This is not a View. Bail.
221
		 *
222
		 * Shortcodes and oEmbeds and whatnot will be handled
223
		 *  elsewhere.
224
		 */
225 8
		if ( ! $view = $request->is_view() ) {
226 5
			return $content;
227
		}
228
229
		/**
230
		 * This View is password protected. Nothing to do here.
231
		 */
232 3
		if ( post_password_required( $view->ID ) ) {
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
233 1
			gravityview()->log->notice( 'Post password is required for View #{view_id}', array( 'view_id' => $view->ID ) );
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
234 1
			return get_the_password_form( $view->ID );
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
235
		}
236
237 3
		if ( ! $view->form ) {
238
			gravityview()->log->notice( 'View #{id} has no form attached to it.', array( 'id' => $view->ID ) );
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
239
240
			/**
241
			 * This View has no data source. There's nothing to show really.
242
			 * ...apart from a nice message if the user can do anything about it.
243
			 */
244
			if ( \GVCommon::has_cap( array( 'edit_gravityviews', 'edit_gravityview' ), $view->ID ) ) {
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
245
				return __( sprintf( 'This View is not configured properly. Start by <a href="%s">selecting a form</a>.', esc_url( get_edit_post_link( $view->ID, false ) ) ), 'gravityview' );
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
246
			}
247
248
			return $content;
249
		}
250
251
		/**
252
		 * Is this View directly accessible via a post URL?
253
		 *
254
		 * @see https://codex.wordpress.org/Function_Reference/register_post_type#public
255
		 */
256
257
		/**
258
		 * @filter `gravityview_direct_access` Should Views be directly accessible, or only visible using the shortcode?
259
		 * @deprecated
260
		 * @param[in,out] boolean `true`: allow Views to be accessible directly. `false`: Only allow Views to be embedded. Default: `true`
261
		 * @param int $view_id The ID of the View currently being requested. `0` for general setting
262
		 */
263 3
		$direct_access = apply_filters( 'gravityview_direct_access', true, $view->ID );
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
264
265
		/**
266
		 * @filter `gravityview/request/output/direct` Should this View be directly accessbile?
267
		 * @since 2.0
268
		 * @param[in,out] boolean Accessible or not. Default: accessbile.
269
		 * @param \GV\View $view The View we're trying to directly render here.
270
		 * @param \GV\Request $request The current request.
271
		 */
272 3
		if ( ! apply_filters( 'gravityview/view/output/direct', $direct_access, $view, $request ) ) {
273
			return __( 'You are not allowed to view this content.', 'gravityview' );
274
		}
275
276
		/**
277
		 * Is this View an embed-only View? If so, don't allow rendering here,
278
		 *  as this is a direct request.
279
		 */
280 3
		if ( $view->settings->get( 'embed_only' ) && ! \GVCommon::has_cap( 'read_private_gravityviews' ) ) {
281 1
			return __( 'You are not allowed to view this content.', 'gravityview' );
282
		}
283
284
		/** Private, pending, draft, etc. */
285 3
		$public_states = get_post_stati( array( 'public' => true ) );
286 3
		if ( ! in_array( $view->post_status, $public_states ) && ! \GVCommon::has_cap( 'read_gravityview', $view->ID ) ) {
0 ignored issues
show
Documentation introduced by
The property post_status does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
287 1
			gravityview()->log->notice( 'The current user cannot access this View #{view_id}', array( 'view_id' => $view->ID ) );
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
288 1
			return __( 'You are not allowed to view this content.', 'gravityview' );
289
		}
290
291 3
		$is_admin_and_can_view = $view->settings->get( 'admin_show_all_statuses' ) && \GVCommon::has_cap('gravityview_moderate_entries', $view->ID );
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
292
293
		/**
294
		 * Editing a single entry.
295
		 */
296 3
		if ( $entry = $request->is_edit_entry() ) {
297
			if ( $entry['status'] != 'active' ) {
0 ignored issues
show
introduced by
Found "!= '". Use Yoda Condition checks, you must
Loading history...
298
				gravityview()->log->notice( 'Entry ID #{entry_id} is not active', array( 'entry_id' => $entry->ID ) );
299
				return __( 'You are not allowed to view this content.', 'gravityview' );
300
			}
301
302
			if ( apply_filters( 'gravityview_custom_entry_slug', false ) && $entry->slug != get_query_var( \GV\Entry::get_endpoint_name() ) ) {
303
				gravityview()->log->error( 'Entry ID #{entry_id} was accessed by a bad slug', array( 'entry_id' => $entry->ID ) );
304
				return __( 'You are not allowed to view this content.', 'gravityview' );
305
			}
306
307
			if ( $view->settings->get( 'show_only_approved' ) && ! $is_admin_and_can_view ) {
308
				if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $entry->ID, \GravityView_Entry_Approval::meta_key ) )  ) {
309
					gravityview()->log->error( 'Entry ID #{entry_id} is not approved for viewing', array( 'entry_id' => $entry->ID ) );
310
					return __( 'You are not allowed to view this content.', 'gravityview' );
311
				}
312
			}
313
314
			$renderer = new Edit_Entry_Renderer();
315
			return $renderer->render( $entry, $view, $request );
316
317
		/**
318
		 * Viewing a single entry.
319
		 */
320 3
		} else if ( $entry = $request->is_entry() ) {
321 1
			if ( $entry['status'] != 'active' ) {
0 ignored issues
show
introduced by
Found "!= '". Use Yoda Condition checks, you must
Loading history...
322 1
				gravityview()->log->notice( 'Entry ID #{entry_id} is not active', array( 'entry_id' => $entry->ID ) );
323 1
				return __( 'You are not allowed to view this content.', 'gravityview' );
324
			}
325
326 1
			if ( apply_filters( 'gravityview_custom_entry_slug', false ) && $entry->slug != get_query_var( \GV\Entry::get_endpoint_name() ) ) {
327 1
				gravityview()->log->error( 'Entry ID #{entry_id} was accessed by a bad slug', array( 'entry_id' => $entry->ID ) );
328 1
				return __( 'You are not allowed to view this content.', 'gravityview' );
329
			}
330
331 1
			if ( $view->settings->get( 'show_only_approved' ) && ! $is_admin_and_can_view ) {
332 1
				if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $entry->ID, \GravityView_Entry_Approval::meta_key ) )  ) {
333 1
					gravityview()->log->error( 'Entry ID #{entry_id} is not approved for viewing', array( 'entry_id' => $entry->ID ) );
334 1
					return __( 'You are not allowed to view this content.', 'gravityview' );
335
				}
336
			}
337
338 1
			$error = \GVCommon::check_entry_display( $entry->as_entry() );
339
340 1
			if( is_wp_error( $error ) ) {
341
				gravityview()->log->error( 'Entry ID #{entry_id} is not approved for viewing: {message}', array( 'entry_id' => $entry->ID, 'message' => $error->get_error_message() ) );
342
				return __( 'You are not allowed to view this content.', 'gravityview' );
343
			}
344
345 1
			$renderer = new Entry_Renderer();
346 1
			return $renderer->render( $entry, $view, $request );
347
348
		/**
349
		 * Plain old View.
350
		 */
351
		} else {
352 2
			$renderer = new View_Renderer();
353 2
			return $renderer->render( $view, $request );
354
		}
355
356
		return $content;
0 ignored issues
show
Unused Code introduced by
return $content; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
357
	}
358
359
	/**
360
	 * Get joins associated with a view
361
	 *
362
	 * @param \WP_Post $post GravityView CPT to get joins for
363
	 *
364
	 * @since 2.0.11
365
	 *
366
	 * @return \GV\Join[] Array of \GV\Join instances
367
	 */
368 71
	public static function get_joins( $post ) {
369
370 71
		if ( ! gravityview()->plugin->supports( Plugin::FEATURE_JOINS ) ) {
371
			gravityview()->log->error( 'Cannot get joined forms; joins feature not supported.' );
372
			return array();
373
		}
374
375 71
		if ( ! $post || 'gravityview' !== get_post_type( $post ) ) {
376
			gravityview()->log->error( 'Only "gravityview" post types can be \GV\View instances.' );
377
			return array();
378
		}
379
380 71
		$joins_meta = get_post_meta( $post->ID, '_gravityview_form_joins', true );
381
382 71
		if ( empty( $joins_meta ) ) {
383 67
			return array();
384
		}
385
386 4
		$joins = array();
387
388 4
		foreach ( $joins_meta as $meta ) {
389 4
			if ( ! is_array( $meta ) || count( $meta ) != 4 ) {
0 ignored issues
show
introduced by
Found "!= 4". Use Yoda Condition checks, you must
Loading history...
390
				continue;
391
			}
392
393 4
			list( $join, $join_column, $join_on, $join_on_column ) = $meta;
394
395 4
			$join    = GF_Form::by_id( $join );
396 4
			$join_on = GF_Form::by_id( $join_on );
397
398 4
			$join_column    = is_numeric( $join_column ) ? GF_Field::by_id( $join, $join_column ) : Internal_Field( $join_column );
399 4
			$join_on_column = is_numeric( $join_on_column ) ? GF_Field::by_id( $join_on, $join_on_column ) : Internal_Field( $join_on_column );
400
401 4
			$joins [] = new Join( $join, $join_column, $join_on, $join_on_column );
402
		}
403
404 4
		return $joins;
405
	}
406
407
	/**
408
	 * Get joined forms associated with a view
409
	 *
410
	 * @since 2.0.11
411
	 *
412
	 * @param int $post_id ID of the View
413
	 *
414
	 * @return \GV\GF_Form[] Array of \GV\GF_Form instances
415
	 */
416
	public static function get_joined_forms( $post_id = 0 ) {
417
418
		if ( ! gravityview()->plugin->supports( Plugin::FEATURE_JOINS ) ) {
419
			gravityview()->log->error( 'Cannot get joined forms; joins feature not supported.' );
420
			return array();
421
		}
422
423
		if ( empty( $post_id ) ) {
424
			gravityview()->log->error( 'Cannot get joined forms; $post_id was empty' );
425
			return array();
426
		}
427
428
		$joins_meta = get_post_meta( $post_id, '_gravityview_form_joins', true );
429
430
		if ( empty( $joins_meta ) ) {
431
			return array();
432
		}
433
434
		$forms_ids = array();
435
436
		foreach ( $joins_meta  as $meta ) {
437
			if ( ! is_array( $meta ) || count( $meta ) != 4 ) {
0 ignored issues
show
introduced by
Found "!= 4". Use Yoda Condition checks, you must
Loading history...
438
				continue;
439
			}
440
441
			list( $join, $join_column, $join_on, $join_on_column ) = $meta;
442
443
			$forms_ids [] = GF_Form::by_id( $join_on );
444
		}
445
446
		return ( !empty( $forms_ids) ) ? $forms_ids : null;
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
447
	}
448
449
	/**
450
	 * Construct a \GV\View instance from a \WP_Post.
451
	 *
452
	 * @param \WP_Post $post The \WP_Post instance to wrap.
453
	 *
454
	 * @api
455
	 * @since 2.0
456
	 * @return \GV\View|null An instance around this \WP_Post if valid, null otherwise.
457
	 */
458 72
	public static function from_post( $post ) {
459
460 72
		if ( ! $post || 'gravityview' !== get_post_type( $post ) ) {
461 2
			gravityview()->log->error( 'Only gravityview post types can be \GV\View instances.' );
462 2
			return null;
463
		}
464
465 72
		if ( $view = Utils::get( self::$cache, "View::from_post:{$post->ID}" ) ) {
466 33
			return $view;
467
		}
468
469 72
		$view = new self();
470 72
		$view->post = $post;
471
472
		/** Get connected form. */
473 72
		$view->form = GF_Form::by_id( $view->_gravityview_form_id );
0 ignored issues
show
Documentation introduced by
The property _gravityview_form_id does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
474 72
		if ( ! $view->form ) {
475
			gravityview()->log->error( 'View #{view_id} tried attaching non-existent Form #{form_id} to it.', array(
476
				'view_id' => $view->ID,
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
477
				'form_id' => $view->_gravityview_form_id ? : 0,
0 ignored issues
show
Documentation introduced by
The property _gravityview_form_id does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
478
			) );
479
		}
480
481 72
		$view->joins = $view->get_joins( $post );
482
483
		/**
484
		 * @filter `gravityview/configuration/fields` Filter the View fields' configuration array.
485
		 * @since 1.6.5
486
		 *
487
		 * @deprecated Use `gravityview/view/configuration/fields` or `gravityview/view/fields` filters.
488
		 *
489
		 * @param $fields array Multi-array of fields with first level being the field zones.
490
		 * @param $view_id int The View the fields are being pulled for.
491
		 */
492 72
		$configuration = apply_filters( 'gravityview/configuration/fields', (array)$view->_gravityview_directory_fields, $view->ID );
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
493
494
		/**
495
		 * @filter `gravityview/view/configuration/fields` Filter the View fields' configuration array.
496
		 * @since 2.0
497
		 *
498
		 * @param array $fields Multi-array of fields with first level being the field zones.
499
		 * @param \GV\View $view The View the fields are being pulled for.
500
		 */
501 72
		$configuration = apply_filters( 'gravityview/view/configuration/fields', $configuration, $view );
502
503
		/**
504
		 * @filter `gravityview/view/fields` Filter the Field Collection for this View.
505
		 * @since 2.0
506
		 *
507
		 * @param \GV\Field_Collection $fields A collection of fields.
508
		 * @param \GV\View $view The View the fields are being pulled for.
509
		 */
510 72
		$view->fields = apply_filters( 'gravityview/view/fields', Field_Collection::from_configuration( $configuration ), $view );
511
512
		/**
513
		 * @filter `gravityview/view/configuration/widgets` Filter the View widgets' configuration array.
514
		 * @since 2.0
515
		 *
516
		 * @param array $fields Multi-array of widgets with first level being the field zones.
517
		 * @param \GV\View $view The View the widgets are being pulled for.
518
		 */
519 72
		$configuration = apply_filters( 'gravityview/view/configuration/widgets', (array)$view->_gravityview_directory_widgets, $view );
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
520
521
		/**
522
		 * @filter `gravityview/view/widgets` Filter the Widget Collection for this View.
523
		 * @since 2.0
524
		 *
525
		 * @param \GV\Widget_Collection $widgets A collection of widgets.
526
		 * @param \GV\View $view The View the widgets are being pulled for.
527
		 */
528 72
		$view->widgets = apply_filters( 'gravityview/view/widgets', Widget_Collection::from_configuration( $configuration ), $view );
529
530
		/** View configuration. */
531 72
		$view->settings->update( gravityview_get_template_settings( $view->ID ) );
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
532
533
		/** Add the template name into the settings. */
534 72
		$view->settings->update( array( 'template' => gravityview_get_template_id( $view->ID ) ) );
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
535
536
		/** View basics. */
537 72
		$view->settings->update( array(
538 72
			'id' => $view->ID,
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
539
		) );
540
541 72
		self::$cache[ "View::from_post:{$post->ID}" ] = &$view;
542
543 72
		return $view;
544
	}
545
546
	/**
547
	 * Flush the view cache.
548
	 *
549
	 * @param int $view_id The View to reset cache for. Optional. Default: resets everything.
550
	 *
551
	 * @internal
552
	 */
553 83
	public static function _flush_cache( $view_id = null ) {
554 83
		if ( $view_id ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $view_id of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
555 76
			unset( self::$cache[ "View::from_post:$view_id" ] );
556 76
			return;
557
		}
558 65
		self::$cache = array();
559 65
	}
560
561
	/**
562
	 * Construct a \GV\View instance from a post ID.
563
	 *
564
	 * @param int|string $post_id The post ID.
565
	 *
566
	 * @api
567
	 * @since 2.0
568
	 * @return \GV\View|null An instance around this \WP_Post or null if not found.
569
	 */
570 34
	public static function by_id( $post_id ) {
571 34
		if ( ! $post_id || ! $post = get_post( $post_id ) ) {
572 3
			return null;
573
		}
574 34
		return self::from_post( $post );
575
	}
576
577
	/**
578
	 * Determines if a view exists to begin with.
579
	 *
580
	 * @param int|\WP_Post|null $view The WordPress post ID, a \WP_Post object or null for global $post;
581
	 *
582
	 * @api
583
	 * @since 2.0
584
	 * @return bool Whether the post exists or not.
585
	 */
586 4
	public static function exists( $view ) {
587 4
		return get_post_type( $view ) == 'gravityview';
588
	}
589
590
	/**
591
	 * ArrayAccess compatibility layer with GravityView_View_Data::$views
592
	 *
593
	 * @internal
594
	 * @deprecated
595
	 * @since 2.0
596
	 * @return bool Whether the offset exists or not, limited to GravityView_View_Data::$views element keys.
597
	 */
598 9
	public function offsetExists( $offset ) {
0 ignored issues
show
Coding Style introduced by
The function name offsetExists is in camel caps, but expected offset_exists instead as per the coding standard.
Loading history...
599 9
		$data_keys = array( 'id', 'view_id', 'form_id', 'template_id', 'atts', 'fields', 'widgets', 'form' );
600 9
		return in_array( $offset, $data_keys );
601
	}
602
603
	/**
604
	 * ArrayAccess compatibility layer with GravityView_View_Data::$views
605
	 *
606
	 * Maps the old keys to the new data;
607
	 *
608
	 * @internal
609
	 * @deprecated
610
	 * @since 2.0
611
	 *
612
	 * @return mixed The value of the requested view data key limited to GravityView_View_Data::$views element keys.
613
	 */
614 9
	public function offsetGet( $offset ) {
0 ignored issues
show
Coding Style introduced by
The function name offsetGet is in camel caps, but expected offset_get instead as per the coding standard.
Loading history...
615
616 9
		gravityview()->log->notice( 'This is a \GV\View object should not be accessed as an array.' );
617
618 9
		if ( ! isset( $this[ $offset ] ) ) {
619
			return null;
620
		}
621
622 9
		switch ( $offset ) {
623 9
			case 'id':
624 9
			case 'view_id':
625 1
				return $this->ID;
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
626 9
			case 'form':
627 9
				return $this->form;
628 1
			case 'form_id':
629 1
				return $this->form ? $this->form->ID : null;
630 1
			case 'atts':
631
				return $this->settings->as_atts();
0 ignored issues
show
Deprecated Code introduced by
The method GV\View_Settings::as_atts() has been deprecated.

This method has been deprecated.

Loading history...
632 1
			case 'template_id':
633 1
				return $this->settings->get( 'template' );
634
			case 'widgets':
635
				return $this->widgets->as_configuration();
636
		}
637
	}
638
639
	/**
640
	 * ArrayAccess compatibility layer with GravityView_View_Data::$views
641
	 *
642
	 * @internal
643
	 * @deprecated
644
	 * @since 2.0
645
	 *
646
	 * @return void
647
	 */
648 1
	public function offsetSet( $offset, $value ) {
0 ignored issues
show
Coding Style introduced by
The function name offsetSet is in camel caps, but expected offset_set instead as per the coding standard.
Loading history...
649 1
		gravityview()->log->error( 'The old view data is no longer mutable. This is a \GV\View object should not be accessed as an array.' );
650 1
	}
651
652
	/**
653
	 * ArrayAccess compatibility layer with GravityView_View_Data::$views
654
	 *
655
	 * @internal
656
	 * @deprecated
657
	 * @since 2.0
658
	 * @return void
659
	 */
660 1
	public function offsetUnset( $offset ) {
0 ignored issues
show
Coding Style introduced by
The function name offsetUnset is in camel caps, but expected offset_unset instead as per the coding standard.
Loading history...
661 1
		gravityview()->log->error( 'The old view data is no longer mutable. This is a \GV\View object should not be accessed as an array.' );
662 1
	}
663
664
	/**
665
	 * Be compatible with the old data object.
666
	 *
667
	 * Some external code expects an array (doing things like foreach on this, or array_keys)
668
	 *  so let's return an array in the old format for such cases. Do not use unless using
669
	 *  for back-compatibility.
670
	 *
671
	 * @internal
672
	 * @deprecated
673
	 * @since 2.0
674
	 * @return array
675
	 */
676 5
	public function as_data() {
677
		return array(
678 5
			'id' => $this->ID,
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
679 5
			'view_id' => $this->ID,
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
680 5
			'form_id' => $this->form ? $this->form->ID : null,
681 5
			'form' => $this->form ? gravityview_get_form( $this->form->ID ) : null,
682 5
			'atts' => $this->settings->as_atts(),
0 ignored issues
show
Deprecated Code introduced by
The method GV\View_Settings::as_atts() has been deprecated.

This method has been deprecated.

Loading history...
683 5
			'fields' => $this->fields->by_visible()->as_configuration(),
684 5
			'template_id' => $this->settings->get( 'template' ),
685 5
			'widgets' => $this->widgets->as_configuration(),
686
		);
687
	}
688
689
	/**
690
	 * Retrieve the entries for the current view and request.
691
	 *
692
	 * @param \GV\Request The request. Usued for now.
693
	 *
694
	 * @return \GV\Entry_Collection The entries.
695
	 */
696 23
	public function get_entries( $request ) {
697 23
		$entries = new \GV\Entry_Collection();
698 23
		if ( $this->form ) {
699
			/**
700
			 * @todo: Stop using _frontend and use something like $request->get_search_criteria() instead
701
			 */
702 23
			$parameters = \GravityView_frontend::get_view_entries_parameters( $this->settings->as_atts(), $this->form->ID );
0 ignored issues
show
Deprecated Code introduced by
The method GV\View_Settings::as_atts() has been deprecated.

This method has been deprecated.

Loading history...
703 23
			$parameters['context_view_id'] = $this->ID;
0 ignored issues
show
Bug introduced by
The property ID does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
704 23
			$parameters = \GVCommon::calculate_get_entries_criteria( $parameters, $this->form->ID );
705
706 23
			if ( $request instanceof REST\Request ) {
707 3
				$atts = $this->settings->as_atts();
0 ignored issues
show
Deprecated Code introduced by
The method GV\View_Settings::as_atts() has been deprecated.

This method has been deprecated.

Loading history...
708 3
				$paging_parameters = wp_parse_args( $request->get_paging(), array(
709 3
						'paging' => array( 'page_size' => $atts['page_size'] ),
710
					) );
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
711 3
				$parameters['paging'] = $paging_parameters['paging'];
712
			}
713
714 23
			$page = Utils::get( $parameters['paging'], 'current_page' ) ?
715 23
				: ( ( ( $parameters['paging']['offset'] - $this->settings->get( 'offset' ) ) / $parameters['paging']['page_size'] ) + 1 );
716
717 23
			if ( gravityview()->plugin->supports( Plugin::FEATURE_GFQUERY ) ) {
718
				/**
719
				 * New \GF_Query stuff :)
720
				 */
721 23
				$query = new \GF_Query( $this->form->ID, $parameters['search_criteria'], $parameters['sorting'] );
722
723 23
				$query->limit( $parameters['paging']['page_size'] )
724 23
					->offset( ( ( $page - 1 ) * $parameters['paging']['page_size'] ) + $this->settings->get( 'offset' ) );
725
726
				/**
727
				 * Any joins?
728
				 */
729 23
				if ( Plugin::FEATURE_JOINS && count( $this->joins ) ) {
730 4
					foreach ( $this->joins as $join ) {
731 4
						$query = $join->as_query_join( $query );
732
					}
733
				}
734
735
				/**
736
				 * @action `gravityview/view/query` Override the \GF_Query before the get() call.
737
				 * @param \GF_Query $query The current query object
738
				 * @param \GV\View $this The current view object
739
				 * @param \GV\Request $request The request object
740
				 */
741 23
				do_action( 'gravityview/view/query', $query, $this, $request );
742
743
				/**
744
				 * Map from Gravity Forms entries arrays to an Entry_Collection.
745
				 */
746 23
				if ( count( $this->joins ) ) {
747 4
					foreach ( $query->get() as $entry ) {
748 4
						$entries->add(
749 4
							Multi_Entry::from_entries( array_map( '\GV\GF_Entry::from_entry', $entry ) )
750
						);
751
					}
752
				} else {
753 19
					array_map( array( $entries, 'add' ), array_map( '\GV\GF_Entry::from_entry', $query->get() ) );
754
				}
755
756
				/**
757
				 * Add total count callback.
758
				 */
759 23
				$entries->add_count_callback( function() use ( $query ) {
760 18
					return $query->total_found;
761 23
				} );
762
			} else {
763
				$entries = $this->form->entries
0 ignored issues
show
Documentation introduced by
The property entries does not exist on object<GV\Form>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
764
					->filter( \GV\GF_Entry_Filter::from_search_criteria( $parameters['search_criteria'] ) )
765
					->offset( $this->settings->get( 'offset' ) )
766
					->limit( $parameters['paging']['page_size'] )
767
					->page( $page );
768
769
				if ( ! empty( $parameters['sorting'] ) && ! empty( $parameters['sorting']['key'] ) ) {
770
					$field = new \GV\Field();
771
					$field->ID = $parameters['sorting']['key'];
772
					$direction = strtolower( $parameters['sorting']['direction'] ) == 'asc' ? \GV\Entry_Sort::ASC : \GV\Entry_Sort::DESC;
773
					$entries = $entries->sort( new \GV\Entry_Sort( $field, $direction ) );
774
				}
775
			}
776
		}
777
778
		/**
779
		 * @filter `gravityview/view/entries` Modify the entry fetching filters, sorts, offsets, limits.
780
		 * @param \GV\Entry_Collection $entries The entries for this view.
781
		 * @param \GV\View $view The view.
782
		 * @param \GV\Request $request The request.
783
		 */
784 23
		return apply_filters( 'gravityview/view/entries', $entries, $this, $request );
785
	}
786
787 71
	public function __get( $key ) {
788 71
		if ( $this->post ) {
789 71
			$raw_post = $this->post->filter( 'raw' );
790 71
			return $raw_post->{$key};
791
		}
792
		return isset( $this->{$key} ) ? $this->{$key} : null;
793
	}
794
}
795