| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
$meta_query = array( |
| 7 |
array( |
| 8 |
'key' => '_property_id', |
| 9 |
'value' => $post_id, |
| 10 |
), |
| 11 |
); |
| 12 |
|
| 13 |
if ( isset($selected_status) && !empty($selected_status) ) |
| 14 |
{ |
| 15 |
$meta_query = add_viewing_status_meta_query( $meta_query, $selected_status ); |
| 16 |
} |
| 17 |
|
| 18 |
$args = array( |
| 19 |
'post_type' => 'viewing', |
| 20 |
'nopaging' => true, |
| 21 |
'orderby' => 'meta_value', |
| 22 |
'order' => 'DESC', |
| 23 |
'meta_key' => '_start_date_time', |
| 24 |
'post_status' => 'publish', |
| 25 |
'meta_query' => $meta_query, |
| 26 |
); |
| 27 |
$viewings_query = new WP_Query( $args ); |
| 28 |
$viewings_count = $viewings_query->found_posts; |
| 29 |
|
| 30 |
$columns = array( |
| 31 |
'date_time' => __( 'Date', 'propertyhive' ) . ' / ' . __( 'Time', 'propertyhive' ), |
| 32 |
'applicants' => __( 'Applicant(s)', 'propertyhive' ), |
| 33 |
'negotiators' => __( 'Attending Negotiator(s)', 'propertyhive' ), |
| 34 |
'status' => __( 'Status', 'propertyhive' ), |
| 35 |
); |
| 36 |
|
| 37 |
$columns = apply_filters( 'propertyhive_property_viewings_columns', $columns ); |
| 38 |
?> |
| 39 |
|
| 40 |
<div class="tablenav top"> |
| 41 |
<div class="alignleft actions"> |
| 42 |
<select name="_status" id="_viewing_status_filter"> |
| 43 |
<option value=""><?php echo esc_html(__( 'All Statuses', 'propertyhive' )); ?></option> |
| 44 |
<?php |
| 45 |
$viewing_statuses = ph_get_viewing_statuses(); |
| 46 |
|
| 47 |
foreach ( $viewing_statuses as $status => $display_status ) |
| 48 |
{ |
| 49 |
?> |
| 50 |
<option value="<?php echo esc_attr($status); ?>" <?php selected( $status, $selected_status ); ?>><?php echo esc_html($display_status); ?></option> |
| 51 |
<?php |
| 52 |
} |
| 53 |
?> |
| 54 |
</select> |
| 55 |
<input type="button" name="filter_action" id="filter-property-viewings-grid" class="button" value="Filter"> |
| 56 |
<a href="" name="export_action" id="export-property-viewings-grid" class="button">Export</a> |
| 57 |
</div> |
| 58 |
<div class='tablenav-pages one-page'> |
| 59 |
<span class="displaying-num"><?php echo esc_attr($viewings_count); ?> item<?php echo $viewings_count != 1 ? 's' : ''; ?></span> |
| 60 |
</div> |
| 61 |
<br class="clear" /> |
| 62 |
</div> |
| 63 |
<table class="wp-list-table widefat fixed striped posts"> |
| 64 |
<thead> |
| 65 |
<tr> |
| 66 |
<?php |
| 67 |
$column_i = 0; |
| 68 |
foreach ( $columns as $column_key => $column ) |
| 69 |
{ |
| 70 |
?> |
| 71 |
<th scope="col" id='<?php echo esc_attr($column_key); ?>' class='manage-column column-<?php echo esc_attr($column_key); echo ($column_i == 0 ? ' column-primary' : ''); ?>'><?php echo esc_html($column); ?></th> |
| 72 |
<?php |
| 73 |
++$column_i; |
| 74 |
} |
| 75 |
?> |
| 76 |
</tr> |
| 77 |
</thead> |
| 78 |
<tbody id="the-list"> |
| 79 |
<?php |
| 80 |
if ( $viewings_query->have_posts() ) |
| 81 |
{ |
| 82 |
while ( $viewings_query->have_posts() ) |
| 83 |
{ |
| 84 |
$viewings_query->the_post(); |
| 85 |
$the_viewing = new PH_Viewing( get_the_ID() ); |
| 86 |
|
| 87 |
$edit_link = get_edit_post_link( get_the_ID() ); |
| 88 |
|
| 89 |
$column_data = array( |
| 90 |
'date_time' => '<a href="' . esc_url($edit_link) . '" target="' . esc_attr(apply_filters('propertyhive_subgrid_link_target', '')) . '" class="viewing-lightbox" data-viewing-id="' . esc_attr(get_the_ID()) . '">' . esc_html(date("H:i jS F Y", strtotime($the_viewing->_start_date_time))) . '</a>', |
| 91 |
'applicants' => $the_viewing->get_applicants( true, true ), |
| 92 |
'negotiators' => esc_html($the_viewing->get_negotiators()), |
| 93 |
'status' => $the_viewing->get_status(), |
| 94 |
); |
| 95 |
|
| 96 |
$row_classes = array( 'status-' . $the_viewing->_status ); |
| 97 |
if ( $the_viewing->_status == 'carried_out' ) |
| 98 |
{ |
| 99 |
$row_classes[] = 'applicant-feedback-status-' . $the_viewing->_feedback_status; |
| 100 |
} |
| 101 |
$row_classes = apply_filters( 'propertyhive_property_viewings_row_classes', $row_classes, get_the_ID(), $the_viewing ); |
| 102 |
$row_classes = is_array($row_classes) ? array_map( 'sanitize_html_class', array_map( 'strtolower', $row_classes ) ) : array(); |
| 103 |
?> |
| 104 |
<tr class="<?php echo esc_attr(implode(" ", $row_classes)); ?>" > |
| 105 |
<?php |
| 106 |
$column_i = 0; |
| 107 |
foreach ( $columns as $column_key => $column ) |
| 108 |
{ |
| 109 |
echo '<td class="' . esc_attr($column_key) . ' column-' . esc_attr($column_key) . ($column_i == 0 ? ' column-primary' : '') . '" data-colname="' . esc_attr($column) . '">'; |
| 110 |
|
| 111 |
if ( isset( $column_data[$column_key] ) ) |
| 112 |
{ |
| 113 |
echo $column_data[$column_key]; |
| 114 |
} |
| 115 |
|
| 116 |
do_action( 'propertyhive_property_viewings_custom_column', $column_key ); |
| 117 |
|
| 118 |
if ( $column_i == 0 ) { echo '<button type="button" class="toggle-row"><span class="screen-reader-text">' . esc_html(__('Show more details', 'propertyhive' )) . '</span></button>'; } |
| 119 |
|
| 120 |
echo '</td>'; |
| 121 |
++$column_i; |
| 122 |
} |
| 123 |
?> |
| 124 |
</tr> |
| 125 |
<?php |
| 126 |
} |
| 127 |
} |
| 128 |
else |
| 129 |
{ |
| 130 |
?> |
| 131 |
<tr class="no-items"> |
| 132 |
<td class="colspanchange" colspan="<?php echo esc_attr(count($columns)); ?>"><?php echo esc_html(__( 'No viewings found', 'propertyhive' )); ?></td> |
| 133 |
</tr> |
| 134 |
<?php |
| 135 |
} |
| 136 |
wp_reset_postdata(); |
| 137 |
?> |
| 138 |
</tbody> |
| 139 |
</table> |