-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_dashboard_properties.php
211 lines (172 loc) · 7.06 KB
/
user_dashboard_properties.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
/**
* Template Name: User Dashboard Properties
* Created by PhpStorm.
* User: waqasriaz
* Date: 15/10/15
* Time: 3:33 PM
*/
if ( !is_user_logged_in() || !houzez_check_role() ) {
wp_redirect( home_url() );
}
global $houzez_local, $prop_featured, $current_user, $post;
wp_get_current_user();
$userID = get_current_user_id();
$user_login = $current_user->user_login;
$paid_submission_type = esc_html ( houzez_option('enable_paid_submission','') );
$packages_page_link = houzez_get_template_link('template/template-packages.php');
$dashboard_add_listing = houzez_get_template_link_2('template/user_dashboard_submit.php');
$dashboard_listings = houzez_get_template_link_2('template/user_dashboard_properties.php');
$all = add_query_arg( 'prop_status', 'all', $dashboard_listings );
$mine_link = add_query_arg( 'prop_status', 'mine', $dashboard_listings );
get_header();
// Get 'prop_status' parameter from URL and set 'qry_status' accordingly
$prop_status = isset($_GET['prop_status']) ? $_GET['prop_status'] : null;
switch ($prop_status) {
case 'approved':
$qry_status = 'publish';
break;
case 'pending':
case 'expired':
case 'disapproved':
case 'draft':
case 'on_hold':
$qry_status = $prop_status;
break;
default:
$qry_status = 'any';
}
// Get 'sortby' parameter if set
$sortby = isset($_GET['sortby']) ? $_GET['sortby'] : '';
// Default number of properties and page number
$no_of_prop = 12;
$paged = get_query_var('paged') ?: get_query_var('page') ?: 1;
// Define the initial args for the WP query
$args = [
'post_type' => 'property',
'paged' => $paged,
'posts_per_page' => $no_of_prop,
'post_status' => [$qry_status],
'suppress_filters' => false
];
$args = houzez_prop_sort ( $args );
if( houzez_is_admin() || houzez_is_editor() ) {
if( isset( $_GET['user'] ) && $_GET['user'] != '' ) {
$args['author'] = intval($_GET['user']);
} else if( isset( $_GET['prop_status'] ) && $_GET['prop_status'] == 'mine' ) {
$args['author'] = $userID;
}
} else if( houzez_is_agency() ) {
$agents = houzez_get_agency_agents($userID);
if( isset( $_GET['user'] ) && $_GET['user'] != '' ) {
$args['author'] = intval($_GET['user']);
} else if( isset( $_GET['prop_status'] ) && $_GET['prop_status'] == 'mine' ) {
$args['author'] = $userID;
} else if( $agents ) {
if (!in_array($userID, $agents)) {
$agents[] = $userID;
}
$args['author__in'] = $agents;
} else {
$args['author'] = $userID;
}
} else {
$args['author'] = $userID;
}
// Add keyword search to args if set
if (!empty($_GET['keyword'])) {
$args['s'] = trim($_GET['keyword']);
}
// Add property ID to meta query if set
if (!empty($_GET['property_id'])) {
$meta_query[] = array(
'key' => 'fave_property_id',
'value' => $_GET['property_id'],
'type' => 'CHAR',
'compare' => '=',
);
$meta_count = count($meta_query);
if( $meta_count > 1 ) {
$meta_query['relation'] = 'AND';
}
if ($meta_count > 0) {
$args['meta_query'] = $meta_query;
}
}
?>
<header class="header-main-wrap dashboard-header-main-wrap">
<div class="dashboard-header-wrap">
<div class="d-flex align-items-center">
<div class="dashboard-header-left flex-grow-1">
<h1><?php echo houzez_option('dsh_props', 'Properties'); ?></h1>
</div><!-- dashboard-header-left -->
<?php if(!empty($dashboard_add_listing)) { ?>
<div class="dashboard-header-right">
<a class="btn btn-primary" href="<?php echo esc_url($dashboard_add_listing); ?>"><?php echo houzez_option('dsh_create_listing', 'Create a Listing'); ?></a>
</div><!-- dashboard-header-right -->
<?php } ?>
</div><!-- d-flex -->
</div><!-- dashboard-header-wrap -->
</header><!-- .header-main-wrap -->
<section class="dashboard-content-wrap">
<div class="dashboard-content-inner-wrap">
<div class="dashboard-content-block-wrap">
<div class="dashboard-property-search-wrap">
<div class="d-flex">
<div class="flex-grow-1">
<div class="dashboard-property-search">
<?php get_template_part('template-parts/dashboard/property/search'); ?>
</div>
</div>
<div class="dashboard-property-sort-by">
<?php get_template_part('template-parts/listing/listing-sort-by'); ?>
</div>
</div>
</div><!-- dashboard-property-search -->
<?php
$prop_qry = new WP_Query($args);
if( $prop_qry->have_posts() ): ?>
<div id="dash-prop-msg"></div>
<table class="dashboard-table dashboard-table-properties table-lined table-hover responsive-table">
<thead>
<tr>
<th><?php echo esc_html__('Thumbnail', 'houzez'); ?></th>
<th><?php echo esc_html__('Title', 'houzez'); ?></th>
<th></th>
<th><?php echo esc_html__('Type', 'houzez'); ?></th>
<th><?php echo esc_html__('Status', 'houzez'); ?></th>
<th><?php echo esc_html__('Price', 'houzez'); ?></th>
<th><?php echo esc_html__('Featured', 'houzez'); ?></th>
<th><?php echo esc_html__('Posted', 'houzez'); ?></th>
<th class="action-col"><?php echo esc_html__('Actions', 'houzez'); ?></th>
</tr>
</thead>
<tbody>
<?php
while ($prop_qry->have_posts()): $prop_qry->the_post();
get_template_part('template-parts/dashboard/property/property-item');
endwhile;
?>
</tbody>
</table><!-- dashboard-table -->
<?php houzez_pagination( $prop_qry->max_num_pages ); ?>
<?php
else:
if(isset($_GET['keyword'])) {
echo '<div class="dashboard-content-block">
'.esc_html__("No results found", 'houzez').'
</div>';
} else {
echo '<div class="dashboard-content-block">
'.esc_html__("You don't have any property listed.", 'houzez').' <a href="'.esc_url($dashboard_add_listing).'"><strong>'.esc_html__('Create a listing', 'houzez').'</strong></a>
</div>';
}
endif;
?>
</div><!-- dashboard-content-block-wrap -->
</div><!-- dashboard-content-inner-wrap -->
</section><!-- dashboard-content-wrap -->
<section class="dashboard-side-wrap">
<?php get_template_part('template-parts/dashboard/side-wrap'); ?>
</section>
<?php get_footer(); ?>