Completed
Pull Request — develop (#1487)
by Gennady
07:46
created

View_Table_Template   B

Complexity

Total Complexity 49

Size/Duplication

Total Lines 539
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 12

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
dl 0
loc 539
ccs 143
cts 165
cp 0.8667
rs 8.48
c 0
b 0
f 0
wmc 49
lcom 1
cbo 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
F add_columns_sort_links() 0 101 18
B _get_multisort_url() 0 40 6
A the_columns() 0 18 3
A get_field_column_label() 0 20 4
B the_entry() 0 99 7
B the_field() 0 41 5
A body_before() 0 16 1
A body_after() 0 16 1
A tr_before() 0 16 1
A tr_after() 0 16 1
A entry_class() 0 19 1

How to fix   Complexity   

Complex Class

Complex classes like View_Table_Template often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use View_Table_Template, and based on these observations, apply Extract Interface, too.

1
<?php
2
namespace GV;
3
4
/** If this file is called directly, abort. */
5
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6
	die();
7
}
8
9
/**
10
 * The View Table Template class .
11
 *
12
 * Renders a \GV\View and a \GV\Entry_Collection via a \GV\View_Renderer.
13
 */
14
class View_Table_Template extends View_Template {
15
	/**
16
	 * @var string The template slug to be loaded (like "table", "list")
17
	 */
18
	public static $slug = 'table';
19
20
21
	/**
22
     * Constructor. Add filters to modify output.
23
     *
24
	 * @since 2.0.4
25
	 *
26
	 * @param View $view
27
	 * @param Entry_Collection $entries
28
	 * @param Request $request
29
	 */
30 20
	public function __construct( View $view, Entry_Collection $entries, Request $request ) {
31
32 20
	    add_filter( 'gravityview/template/field/label', array( __CLASS__, 'add_columns_sort_links' ), 100, 2 );
33
34 20
		parent::__construct( $view, $entries, $request );
35 20
	}
36
37
	/**
38
     * Add sorting links to HTML columns that support sorting
39
     *
40
     * @since 2.0.4
41
     * @since 2.0.5 Made static
42
     *
43
     * @static
44
     *
45
	 * @param string $column_label Label for the table column
46
	 * @param \GV\Template_Context $context
47
	 *
48
	 * @return string
49
	 */
50 30
	static public function add_columns_sort_links( $column_label, $context = null ) {
51
52 30
		$sort_columns = $context->view->settings->get( 'sort_columns' );
53
54 30
		if ( empty( $sort_columns ) ) {
55 29
            return $column_label;
56
		}
57
58 1
		if ( 'custom' === $context->field->type ) {
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<GV\Field>. 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...
59
			$field_id = 'custom_' . $context->field->UID;
60
		} else {
61 1
			$field_id = $context->field->ID;
62
		}
63
64 1
		if ( ! \GravityView_frontend::getInstance()->is_field_sortable( $context->field->ID, $context->view->form->form ) ) {
65
			return $column_label;
66
		}
67
68 1
		$sorting = array();
69
70 1
		$directions = $context->view->settings->get( 'sort_direction' );
71
72 1
		$sorts = Utils::_GET( 'sort' );
73
74 1
		if ( $sorts ) {
75 1
			if ( is_array( $sorts ) ) {
76 1
				foreach ( (array)$sorts as $key => $direction ) {
77 1
					if ( $key == $field_id ) {
78 1
						$sorting['key'] = $field_id;
79 1
						$sorting['direction'] = strtolower( $direction );
80 1
						break;
81
					}
82
				}
83
			} else {
84
				if ( $sorts == $field_id ) {
85
					$sorting['key'] = $context_id;
0 ignored issues
show
Bug introduced by
The variable $context_id does not exist. Did you mean $context?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
86 1
					$sorting['direction'] = strtolower( Utils::_GET( 'dir', '' ) );
87
				}
88
			}
89
		} else {
90
			foreach ( (array)$context->view->settings->get( 'sort_field', array() ) as $i => $sort_field ) {
91
				if ( $sort_field == $field_id ) {
92
					$sorting['key'] = $sort_field;
93
					$sorting['direction'] = strtolower( Utils::get( $directions, $i, '' ) );
94
					break; // Only get the first sort
95
				}
96
			}
97
		}
98
99 1
		$class = 'gv-sort';
100
101 1
		$sort_field_id = \GravityView_frontend::_override_sorting_id_by_field_type( $context->field->ID, $context->view->form->ID );
102 1
		if ( 'custom' === $context->field->type ) {
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<GV\Field>. 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...
103
			$sort_field_id = 'custom_' . $context->field->UID;
104
		}
105
106
		$sort_args = array(
107 1
			sprintf( 'sort[%s]', $field_id ),
108 1
			'asc'
109
		);
110
111
		// If we are already sorting by the current field...
112 1
		if ( ! empty( $sorting['key'] ) && (string) $sort_field_id === (string) $sorting['key'] ) {
113
114 1
		    switch( $sorting['direction'] ) {
115
		        // No sort
116 1
                case '':
117 1
	                $sort_args[1] = 'asc';
118 1
	                $class .= ' gv-icon-caret-up-down';
119 1
                    break;
120 1
                case 'desc':
121 1
	                $sort_args[1] = '';
122 1
	                $class .= ' gv-icon-sort-asc';
123 1
	                break;
124 1
                case 'asc':
125
                default:
126 1
                    $sort_args[1] = 'desc';
127 1
                    $class .= ' gv-icon-sort-desc';
128 1
                    break;
129
            }
130
131
		} else {
132
			$class .= ' gv-icon-caret-up-down';
133
		}
134
135 1
		$url = remove_query_arg( array( 'pagenum' ) );
136 1
		$url = remove_query_arg( 'sort', $url );
137 1
		$multisort_url = self::_get_multisort_url( $url, $sort_args, $context->field );
138
139 1
    	$url = add_query_arg( $sort_args[0], $sort_args[1], $url );
140
141 1
		$return = '<a href="'. esc_url_raw( $url ) .'"';
142
143 1
		if ( ! empty( $multisort_url ) ) {
144 1
			$return .= ' data-multisort-href="'. esc_url_raw( $multisort_url ) . '"';
145
		}
146
147 1
		$return .= ' class="'. $class .'" ></a>&nbsp;'. $column_label;
148
149 1
		return $return;
150
	}
151
152
	/**
153
     * Get the multi-sort URL used in the sorting links
154
     *
155
     * @todo Consider moving to Utils?
156
     *
157
     * @since 2.3
158
     *
159
     * @see add_columns_sort_links
160
	 * @param string $url Single-sort URL
161
	 * @param array $sort_args Single sorting for rules, in [ field_id, dir ] format
162
     * @param \GV\Field $field The current field
163
     *
164
     * @return string Multisort URL, if there are multiple sorts. Otherwise, existing $url
165
	 */
166 2
	static public function _get_multisort_url( $url, $sort_args, $field ) {
167
168 2
		$sorts = Utils::_GET( 'sort' );
169
170 2
		if ( ! is_array( $sorts ) ) {
171 1
            return $url;
172
		}
173
174 2
        $multisort_url = $url;
175
176 2
		if ( 'custom' === $field->type ) {
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<GV\Field>. 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...
177
			$field_id = 'custom_' . $field->UID;
178
		} else {
179 1
			$field_id = $field->ID;
180
		}
181
182
		// If the field has already been sorted by, add the field to the URL
183 1
        if ( ! in_array( $field_id, $keys = array_keys( $sorts ) ) ) {
184
            if ( count( $keys ) ) {
185
                $multisort_url = add_query_arg( sprintf( 'sort[%s]', end( $keys ) ), $sorts[ end( $keys ) ], $multisort_url );
186
                $multisort_url = add_query_arg( $sort_args[0], $sort_args[1], $multisort_url );
187
            } else {
188
                $multisort_url = add_query_arg( $sort_args[0], $sort_args[1], $multisort_url );
189
            }
190
        }
191
        // Otherwise, we are just updating the sort order
192
        else {
193
194
            // Pass empty value to unset
195 1
            if( '' === $sort_args[1] ) {
196 1
	            unset( $sorts[ $field_id ] );
197
            } else {
198 1
	            $sorts[ $field_id ] = $sort_args[1];
199
            }
200
201 1
            $multisort_url = add_query_arg( array( 'sort' => $sorts ), $multisort_url );
202
        }
203
204 1
		return $multisort_url;
205
	}
206
207
	/**
208
	 * Output the table column names.
209
	 *
210
	 * @return void
211
	 */
212 21
	public function the_columns() {
213 21
		$fields = $this->view->fields->by_position( 'directory_table-columns' );
214
215 21
		foreach ( $fields->by_visible( $this->view )->all() as $field ) {
216 21
			$context = Template_Context::from_template( $this, compact( 'field' ) );
217
218
			$args = array(
219 21
				'field' => is_numeric( $field->ID ) ? $field->as_configuration() : null,
220
				'hide_empty' => false,
221 21
				'zone_id' => 'directory_table-columns',
222 21
				'markup' => '<th id="{{ field_id }}" class="{{ class }}" style="{{width:style}}" data-label="{{label_value:data-label}}">{{label}}</th>',
223 21
				'label_markup' => '<span class="gv-field-label">{{ label }}</span>',
224 21
				'label' => self::get_field_column_label( $field, $context ),
225
			);
226
227 21
			echo \gravityview_field_output( $args, $context );
228
		}
229 21
	}
230
231
	/**
232
     * Returns the label for a column, with support for all deprecated filters
233
     *
234
     * @since 2.1
235
     *
236
	 * @param \GV\Field $field
237
	 * @param \GV\Template_Context $context
238
	 */
239 20
	protected static function get_field_column_label( $field, $context = null ) {
240
241 20
		$form = $field->form_id ? GF_Form::by_id( $field->form_id ) : $context->view->form;
0 ignored issues
show
Documentation introduced by
The property form_id does not exist on object<GV\Field>. 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...
242
243
		/**
244
		 * @deprecated Here for back-compatibility.
245
		 */
246 20
		$column_label = apply_filters( 'gravityview_render_after_label', $field->get_label( $context->view, $form ), $field->as_configuration() );
247 20
		$column_label = apply_filters( 'gravityview/template/field_label', $column_label, $field->as_configuration(), ( $form && $form->form ) ? $form->form : null, null );
248
249
		/**
250
		 * @filter `gravityview/template/field/label` Override the field label.
251
		 * @since 2.0
252
		 * @param[in,out] string $column_label The label to override.
253
		 * @param \GV\Template_Context $context The context. Does not have entry set here.
254
		 */
255 20
		$column_label = apply_filters( 'gravityview/template/field/label', $column_label, $context );
256
257 20
		return $column_label;
258
    }
259
260
	/**
261
	 * Output the entry row.
262
	 *
263
	 * @param \GV\Entry $entry The entry to be rendered.
264
	 * @param array $attributes The attributes for the <tr> tag
265
	 *
266
	 * @return void
267
	 */
268 17
	public function the_entry( \GV\Entry $entry, $attributes ) {
269
270 17
		$fields = $this->view->fields->by_position( 'directory_table-columns' )->by_visible( $this->view );
271
272 17
		$context = Template_Context::from_template( $this, compact( 'entry', 'fields' ) );
273
274
		/**
275
		 * Push legacy entry context.
276
		 */
277 17
		\GV\Mocks\Legacy_Context::load( array(
278 17
			'entry' => $entry,
279
		) );
280
281
		/**
282
		 * @filter `gravityview_table_cells` Modify the fields displayed in a table
283
		 * @param array $fields
284
		 * @param \GravityView_View $this
285
		 * @deprecated Use `gravityview/template/table/fields`
286
		 */
287 17
		$fields = apply_filters( 'gravityview_table_cells', $fields->as_configuration(), \GravityView_View::getInstance() );
288 17
		$fields = Field_Collection::from_configuration( $fields );
289
290
		/**
291
		 * @filter `gravityview/template/table/fields` Modify the fields displayed in this tables.
292
		 * @param \GV\Field_Collection $fields The fields.
293
		 * @param \GV\Template_Context $context The context.
294
		 * @since 2.0
295
		 */
296 17
		$fields = apply_filters( 'gravityview/template/table/fields', $fields, $context );
297
298 17
		$context = Template_Context::from_template( $this, compact( 'entry', 'fields' ) );
299
300
		/**
301
		 * @filter `gravityview/template/table/entry/row/attributes` Filter the row attributes for the row in table view.
302
		 *
303
		 * @param array $attributes The HTML attributes.
304
		 * @param \GV\Template_Context The context.
305
		 *
306
		 * @since 2.0
307
		 */
308 17
		$attributes = apply_filters( 'gravityview/template/table/entry/row/attributes', $attributes, $context );
309
310
		/** Glue the attributes together. */
311 17
		foreach ( $attributes as $attribute => $value ) {
312 17
			$attributes[ $attribute ] = sprintf( "$attribute=\"%s\"", esc_attr( $value ) );
313
		}
314 17
		$attributes = implode( ' ', $attributes );
315
316
		?>
317
			<tr<?php echo $attributes ? " $attributes" : ''; ?>>
318
                <?php
319
320
				/**
321
				 * @action `gravityview/template/table/cells/before` Inside the `tr` while rendering each entry in the loop. Can be used to insert additional table cells.
322
				 * @since 2.0
323
				 * @param \GV\Template_Context The context.
324
				 */
325 17
				do_action( 'gravityview/template/table/cells/before', $context );
326
327
                /**
328
                 * @action `gravityview_table_cells_before` Inside the `tr` while rendering each entry in the loop. Can be used to insert additional table cells.
329
                 * @since 1.0.7
330
				 * @param \GravityView_View $this Current GravityView_View object
331
				 * @deprecated Use `gravityview/template/table/cells/before`
332
                 */
333 17
                do_action( 'gravityview_table_cells_before', \GravityView_View::getInstance() );
334
335 17
                foreach ( $fields->all() as $field ) {
336 17
					if ( isset( $this->view->unions[ $entry['form_id'] ] ) ) {
337
						if ( isset( $this->view->unions[ $entry['form_id'] ][ $field->ID ] ) ) {
338
							$field = $this->view->unions[ $entry['form_id'] ][ $field->ID ];
339
						} else {
340
							if ( ! $field instanceof Internal_Field ) {
341
								$field = Internal_Field::from_configuration( array( 'id' => 'custom' ) );
342
							}
343
						}
344
					}
345 17
					$this->the_field( $field, $entry );
346
				}
347
348
				/**
349
				 * @action `gravityview/template/table/cells/after` Inside the `tr` while rendering each entry in the loop. Can be used to insert additional table cells.
350
				 * @since 2.0
351
				 * @param \GV\Template_Context The context.
352
				 */
353 17
				do_action( 'gravityview/template/table/cells/after', $context );
354
355
                /**
356
                 * @action `gravityview_table_cells_after` Inside the `tr` while rendering each entry in the loop. Can be used to insert additional table cells.
357
                 * @since 1.0.7
358
				 * @param \GravityView_View $this Current GravityView_View object
359
				 * @deprecated Use `gravityview/template/table/cells/after`
360
                 */
361 17
                do_action( 'gravityview_table_cells_after', \GravityView_View::getInstance() );
362
363
				?>
364 17
			</tr>
365
		<?php
366 17
	}
367
368
	/**
369
	 * Output a field cell.
370
	 *
371
	 * @param \GV\Field $field The field to be ouput.
372
	 * @param \GV\Field $entry The entry this field is for.
373
	 *
374
	 * @return void
375
	 */
376 16
	public function the_field( \GV\Field $field, \GV\Entry $entry ) {
377 16
		$form = $this->view->form;
378 16
		$single_entry = $entry;
379
380
		/**
381
		 * Push legacy entry context.
382
		 */
383 16
		\GV\Mocks\Legacy_Context::load( array(
384 16
			'field' => $field,
385
		) );
386
387 16
		if ( $entry->is_multi() ) {
388 3
			if ( ! $single_entry = $entry->from_field( $field ) ) {
389
				echo '<td></td>';
390
				return;
391
			}
392 3
			$form = GF_Form::by_id( $field->form_id );
0 ignored issues
show
Documentation introduced by
The property form_id does not exist on object<GV\Field>. 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...
393
		}
394
395 16
		$renderer = new Field_Renderer();
396 16
		$source = is_numeric( $field->ID ) ? $form : new Internal_Source();
397
398 16
		$value = $renderer->render( $field, $this->view, $source, $entry, $this->request );
399
400 16
		$context = Template_Context::from_template( $this, compact( 'field' ) );
401 16
		$context->entry = $single_entry;
402
403
		$args = array(
404 16
			'entry' => $entry->as_entry(),
405 16
			'field' => is_numeric( $field->ID ) ? $field->as_configuration() : null,
406 16
			'value' => $value,
407
			'hide_empty' => false,
408 16
			'zone_id' => 'directory_table-columns',
409 16
            'label' => self::get_field_column_label( $field, $context ),
410 16
			'markup' => '<td id="{{ field_id }}" class="{{ class }}" data-label="{{label_value:data-label}}">{{ value }}</td>',
411 16
            'form' => $form,
412
		);
413
414
		/** Output. */
415 16
		echo \gravityview_field_output( $args, $context );
416 16
	}
417
418
	/**
419
	 * `gravityview_table_body_before` and `gravityview/template/table/body/before` actions.
420
	 *
421
	 * Output inside the `tbody` of the table.
422
	 *
423
	 * @param $context \GV\Template_Context The 2.0 context.
424
	 *
425
	 * @return void
426
	 */
427 20
	public static function body_before( $context ) {
428
		/**
429
		 * @action `gravityview/template/table/body/before` Output inside the `tbody` of the table.
430
		 * @since 2.0
431
		 * @param \GV\Template_Context $context The template context.
432
		 */
433 20
		do_action( 'gravityview/template/table/body/before', $context );
434
435
		/**
436
		* @action `gravityview_table_body_before` Inside the `tbody`, before any rows are rendered. Can be used to insert additional rows.
437
		* @deprecated Use `gravityview/template/table/body/before`
438
		* @since 1.0.7
439
		* @param \GravityView_View $gravityview_view Current GravityView_View object.
440
		*/
441 20
		do_action( 'gravityview_table_body_before', \GravityView_View::getInstance() /** ugh! */ );
442 20
	}
443
444
	/**
445
	 * `gravityview_table_body_after` and `gravityview/template/table/body/after` actions.
446
	 *
447
	 * Output inside the `tbody` of the table.
448
	 *
449
	 * @param $context \GV\Template_Context The 2.0 context.
450
	 *
451
	 * @return void
452
	 */
453 20
	public static function body_after( $context ) {
454
		/**
455
		 * @action `gravityview/template/table/body/after` Output inside the `tbody` of the table at the end.
456
		 * @since 2.0
457
		 * @param \GV\Template_Context $context The template context.
458
		 */
459 20
		do_action( 'gravityview/template/table/body/after', $context );
460
461
		/**
462
		* @action `gravityview_table_body_after` Inside the `tbody`, after any rows are rendered. Can be used to insert additional rows.
463
		* @deprecated Use `gravityview/template/table/body/after`
464
		* @since 1.0.7
465
		* @param \GravityView_View $gravityview_view Current GravityView_View object.
466
		*/
467 20
		do_action( 'gravityview_table_body_after', \GravityView_View::getInstance() /** ugh! */ );
468 20
	}
469
470
	/**
471
	 * `gravityview_table_tr_before` and `gravityview/template/table/tr/after` actions.
472
	 *
473
	 * Output inside the `tr` of the table.
474
	 *
475
	 * @param $context \GV\Template_Context The 2.0 context.
476
	 *
477
	 * @return void
478
	 */
479 7
	public static function tr_before( $context ) {
480
		/**
481
		 * @action `gravityview/template/table/tr/before` Output inside the `tr` of the table when there are no results.
482
		 * @since 2.0
483
		 * @param \GV\Template_Context $context The template context.
484
		 */
485 7
		do_action( 'gravityview/template/table/tr/before', $context );
486
487
		/**
488
		 * @action `gravityview_table_tr_before` Before the `tr` while rendering each entry in the loop. Can be used to insert additional table rows.
489
		 * @since 1.0.7
490
		 * @deprecated USe `gravityview/template/table/tr/before`
491
		 * @param \GravityView_View $gravityview_view Current GraivtyView_View object.
492
		 */
493 7
		do_action( 'gravityview_table_tr_before', \GravityView_View::getInstance() /** ugh! */ );
494 7
	}
495
496
	/**
497
	 * `gravityview_table_tr_after` and `gravityview/template/table/tr/after` actions.
498
	 *
499
	 * Output inside the `tr` of the table.
500
	 *
501
	 * @param $context \GV\Template_Context The 2.0 context.
502
	 *
503
	 * @return void
504
	 */
505 7
	public static function tr_after( $context ) {
506
		/**
507
		 * @action `gravityview/template/table/tr/after` Output inside the `tr` of the table when there are no results.
508
		 * @since 2.0
509
		 * @param \GV\Template_Context $context The template context.
510
		 */
511 7
		do_action( 'gravityview/template/table/tr/after', $context );
512
513
		/**
514
		 * @action `gravityview_table_tr_after` Inside the `tr` while rendering each entry in the loop. Can be used to insert additional table cells.
515
		 * @since 1.0.7
516
		 * @deprecated USe `gravityview/template/table/tr/after`
517
		 * @param \GravityView_View $gravityview_view Current GravityView_View object.
518
		 */
519 7
		do_action( 'gravityview_table_tr_after', \GravityView_View::getInstance() /** ugh! */ );
520 7
	}
521
522
	/**
523
	 * `gravityview_entry_class` and `gravityview/template/table/entry/class` filters.
524
	 *
525
	 * Modify of the class of a row.
526
	 *
527
	 * @param string $class The class.
528
	 * @param \GV\Entry $entry The entry.
529
	 * @param \GV\Template_Context The context.
530
	 *
531
	 * @return string The classes.
532
	 */
533 16
	public static function entry_class( $class, $entry, $context ) {
534
		/**
535
		 * @filter `gravityview_entry_class` Modify the class applied to the entry row.
536
		 * @param string $class Existing class.
537
		 * @param array $entry Current entry being displayed
538
		 * @param \GravityView_View $this Current GravityView_View object
539
		 * @deprecated Use `gravityview/template/table/entry/class`
540
		 * @return string The modified class.
541
		 */
542 16
		$class = apply_filters( 'gravityview_entry_class', $class, $entry->as_entry(), \GravityView_View::getInstance() );
543
544
		/**
545
		 * @filter `gravityview/template/table/entry/class` Modify the class aplied to the entry row.
546
		 * @param string $class The existing class.
547
		 * @param \GV\Template_Context The context.
548
		 * @return string The modified class.
549
		 */
550 16
		return apply_filters( 'gravityview/template/table/entry/class', $class, Template_Context::from_template( $context->template, compact( 'entry' ) ) );
551
	}
552
}
553