5 if ( ! defined(
'GRAVITYVIEW_DIR' ) ) {
18 public static $slug =
'table';
32 add_filter(
'gravityview/template/field/label', array( __CLASS__,
'add_columns_sort_links' ), 100, 2 );
34 parent::__construct( $view, $entries, $request );
52 $sort_columns = $context->view->settings->get(
'sort_columns' );
54 if ( empty( $sort_columns ) ) {
64 $directions = $context->view->settings->get(
'sort_direction' );
66 $sorts = Utils::_GET(
'sort' );
69 if ( is_array( $sorts ) ) {
70 foreach ( (array)$sorts as $key => $direction ) {
71 if ( $key == $context->field->ID ) {
72 $sorting[
'key'] = $context->field->ID;
73 $sorting[
'direction'] = strtolower( $direction );
78 if ( $sorts == $context->field->ID ) {
79 $sorting[
'key'] = $context->field->ID;
80 $sorting[
'direction'] = strtolower( Utils::_GET(
'dir',
'' ) );
84 foreach ( (array)$context->view->settings->get(
'sort_field', array() ) as
$i => $sort_field ) {
85 if ( $sort_field == $context->field->ID ) {
86 $sorting[
'key'] = $sort_field;
87 $sorting[
'direction'] = strtolower( Utils::get( $directions, $i,
'' ) );
98 sprintf(
'sort[%s]', $context->field->ID ),
103 if ( ! empty( $sorting[
'key'] ) && (
string) $sort_field_id === (
string) $sorting[
'key'] ) {
105 switch( $sorting[
'direction'] ) {
108 $sort_args[1] =
'asc';
109 $class .=
' gv-icon-caret-up-down';
113 $class .=
' gv-icon-sort-asc';
117 $sort_args[1] =
'desc';
118 $class .=
' gv-icon-sort-desc';
123 $class .=
' gv-icon-caret-up-down';
126 $url = remove_query_arg( array(
'pagenum' ) );
127 $url = remove_query_arg(
'sort',
$url );
128 $multisort_url = self::_get_multisort_url(
$url, $sort_args, $context->field->ID );
130 $url = add_query_arg( $sort_args[0], $sort_args[1],
$url );
132 $return =
'<a href="'. esc_url_raw(
$url ) .
'"';
134 if ( ! empty( $multisort_url ) ) {
135 $return .=
' data-multisort-href="'. esc_url_raw( $multisort_url ) .
'"';
138 $return .=
' class="'.
$class .
'" ></a> '. $column_label;
159 $sorts = Utils::_GET(
'sort' );
161 if ( ! is_array( $sorts ) ) {
165 $multisort_url =
$url;
168 if ( ! in_array(
$field_id, $keys = array_keys( $sorts ) ) ) {
169 if ( count( $keys ) ) {
170 $multisort_url = add_query_arg( sprintf(
'sort[%s]', end( $keys ) ), $sorts[ end( $keys ) ], $multisort_url );
171 $multisort_url = add_query_arg( $sort_args[0], $sort_args[1], $multisort_url );
173 $multisort_url = add_query_arg( $sort_args[0], $sort_args[1], $multisort_url );
180 if(
'' === $sort_args[1] ) {
186 $multisort_url = add_query_arg( array(
'sort' => $sorts ), $multisort_url );
189 return $multisort_url;
198 $fields = $this->view->fields->by_position(
'directory_table-columns' );
200 foreach ( $fields->by_visible( $this->view )->all() as
$field ) {
201 $context = Template_Context::from_template( $this, compact(
'field' ) );
204 'field' => is_numeric(
$field->ID ) ?
$field->as_configuration() : null,
205 'hide_empty' =>
false,
206 'zone_id' =>
'directory_table-columns',
207 'markup' =>
'<th id="{{ field_id }}" class="{{ class }}" style="{{width:style}}" data-label="{{label_value:data-label}}">{{label}}</th>',
208 'label_markup' =>
'<span class="gv-field-label">{{ label }}</span>',
209 'label' => self::get_field_column_label(
$field, $context ),
226 $form =
$field->form_id ? GF_Form::by_id(
$field->form_id ) : $context->view->form;
231 $column_label = apply_filters(
'gravityview_render_after_label',
$field->get_label( $context->view,
$form ),
$field->as_configuration() );
232 $column_label = apply_filters(
'gravityview/template/field_label', $column_label,
$field->as_configuration(), (
$form &&
$form->form ) ?
$form->form : null, null );
240 $column_label = apply_filters(
'gravityview/template/field/label', $column_label, $context );
242 return $column_label;
255 $fields = $this->view->fields->by_position(
'directory_table-columns' )->by_visible( $this->view );
257 $context = Template_Context::from_template( $this, compact(
'entry',
'fields' ) );
273 $fields = Field_Collection::from_configuration( $fields );
281 $fields = apply_filters(
'gravityview/template/table/fields', $fields, $context );
283 $context = Template_Context::from_template( $this, compact(
'entry',
'fields' ) );
302 <tr<?php echo
$attributes ?
" $attributes" :
''; ?>>
310 do_action(
'gravityview/template/table/cells/before', $context );
320 foreach ( $fields->all() as
$field ) {
321 if ( isset( $this->view->unions[ $entry[
'form_id'] ] ) ) {
322 if ( isset( $this->view->unions[ $entry[
'form_id'] ][
$field->ID ] ) ) {
323 $field = $this->view->unions[ $entry[
'form_id'] ][
$field->ID ];
326 $field = Internal_Field::from_configuration( array(
'id' =>
'custom' ) );
330 $this->the_field(
$field, $entry );
338 do_action(
'gravityview/template/table/cells/after', $context );
362 $form = $this->view->form;
372 if ( $entry->is_multi() ) {
373 if ( ! $single_entry = $entry->from_field( $field ) ) {
377 $form = GF_Form::by_id( $field->form_id );
383 $value = $renderer->render( $field, $this->view, $source, $entry, $this->request );
385 $context = Template_Context::from_template( $this, compact(
'field' ) );
386 $context->entry = $single_entry;
389 'entry' => $entry->as_entry(),
390 'field' => is_numeric( $field->ID ) ? $field->as_configuration() : null,
392 'hide_empty' =>
false,
393 'zone_id' =>
'directory_table-columns',
394 'label' => self::get_field_column_label( $field, $context ),
395 'markup' =>
'<td id="{{ field_id }}" class="{{ class }}" data-label="{{label_value:data-label}}">{{ value }}</td>',
418 do_action(
'gravityview/template/table/body/before', $context );
444 do_action(
'gravityview/template/table/body/after', $context );
470 do_action(
'gravityview/template/table/tr/before', $context );
496 do_action(
'gravityview/template/table/tr/after', $context );
535 return apply_filters(
'gravityview/template/table/entry/class',
$class, Template_Context::from_template( $context->template, compact(
'entry' ) ) );
If this file is called directly, abort.
If this file is called directly, abort.
static body_before( $context)
gravityview_table_body_before and gravityview/template/table/body/before actions. ...
static getInstance( $passed_post=NULL)
static _override_sorting_id_by_field_type( $sort_field_id, $form_id)
Override sorting per field.
__construct(View $view, Entry_Collection $entries, Request $request)
Constructor.
static add_columns_sort_links( $column_label, $context=null)
Add sorting links to HTML columns that support sorting.
If this file is called directly, abort.
the_entry(\GV\Entry $entry, $attributes)
Output the entry row.
the_field(\GV\Field $field, \GV\Entry $entry)
Output a field cell.
static entry_class( $class, $entry, $context)
gravityview_entry_class and gravityview/template/table/entry/class filters.
if(gravityview() ->plugin->is_GF_25()) $form
static _get_multisort_url( $url, $sort_args, $field_id)
Get the multi-sort URL used in the sorting links.
static load( $configuration)
Hydrates the legacy context globals as needed.
If this file is called directly, abort.
static get_field_column_label( $field, $context=null)
Returns the label for a column, with support for all deprecated filters.
static tr_before( $context)
gravityview_table_tr_before and gravityview/template/table/tr/after actions.
If this file is called directly, abort.
If this file is called directly, abort.
static tr_after( $context)
gravityview_table_tr_after and gravityview/template/table/tr/after actions.
static body_after( $context)
gravityview_table_body_after and gravityview/template/table/body/after actions.
If this file is called directly, abort.
If this file is called directly, abort.
If this file is called directly, abort.
If this file is called directly, abort.
the_columns()
Output the table column names.
gravityview_field_output( $passed_args, $context=null)
Output field based on a certain html markup.
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed
static getInstance()
Get the one true instantiated self.