PluginProbe
Property Hive / 2.2.6
Property Hive v2.2.6
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / admin / post-types / class-ph-admin-cpt-sale.php

class-ph-admin-cpt-sale.php in Property Hive 2.2.6, at includes/admin/post-types/class-ph-admin-cpt-sale.php

311 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin functions for the sale post type
4 *
5 * @author PropertyHive
6 * @category Admin
7 * @package PropertyHive/Admin/Post Types
8 * @version 1.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14
15 if ( ! class_exists( 'PH_Admin_CPT' ) ) {
16 include( 'class-ph-admin-cpt.php' );
17 }
18
19 if ( ! class_exists( 'PH_Admin_CPT_Sale' ) ) :
20
21 /**
22 * PH_Admin_CPT_Sale Class
23 */
24 class PH_Admin_CPT_Sale extends PH_Admin_CPT {
25
26 /**
27 * Constructor
28 */
29 public function __construct() {
30 $this->type = 'sale';
31
32 // Before data updates
33 add_action( 'pre_post_update', array( $this, 'pre_post_update' ) );
34 add_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ) );
35
36 // Admin Columns
37 add_filter( 'manage_edit-sale_columns', array( $this, 'edit_columns' ) );
38 add_action( 'manage_sale_posts_custom_column', array( $this, 'custom_columns' ), 2 );
39 add_filter( 'list_table_primary_column', array( $this, 'set_primary_column' ), 10, 2 );
40 add_filter( 'post_row_actions', array( $this, 'remove_actions' ), 10, 2 );
41 add_filter( 'manage_edit-sale_sortable_columns', array( $this, 'custom_columns_sort' ) );
42 add_filter( 'request', array( $this, 'custom_columns_orderby' ) );
43
44 // Bulk / quick edit
45 add_filter( 'bulk_actions-edit-sale', array( $this, 'remove_bulk_actions') );
46 /*add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit' ), 10, 2 );
47 add_action( 'quick_edit_custom_box', array( $this, 'quick_edit' ), 10, 2 );
48 add_action( 'save_post', array( $this, 'bulk_and_quick_edit_save_post' ), 10, 2 );*/
49
50 // Call PH_Admin_CPT constructor
51 parent::__construct();
52 }
53
54 /**
55 * Check if we're editing or adding a sale
56 * @return boolean
57 */
58 private function is_editing_sale() {
59 if ( ! empty( $_GET['post_type'] ) && 'sale' == $_GET['post_type'] ) {
60 return true;
61 }
62 if ( ! empty( $_GET['post'] ) && 'sale' == get_post_type( (int)$_GET['post'] ) ) {
63 return true;
64 }
65 if ( ! empty( $_REQUEST['post_id'] ) && 'sale' == get_post_type( (int)$_REQUEST['post_id'] ) ) {
66 return true;
67 }
68 return false;
69 }
70
71 /**
72 * @param int $post_id
73 */
74 public function pre_post_update( $post_id ) {
75
76 }
77
78 /**
79 * @param array $data
80 * @return array
81 */
82 public function wp_insert_post_data( $data ) {
83
84
85 return $data;
86 }
87
88 /**
89 * Change the columns shown in admin.
90 */
91 public function edit_columns( $existing_columns ) {
92
93 if ( empty( $existing_columns ) && ! is_array( $existing_columns ) ) {
94 $existing_columns = array();
95 }
96
97 unset( $existing_columns['title'], $existing_columns['comments'], $existing_columns['date'] );
98
99 $columns = array();
100 $columns['cb'] = '<input type="checkbox" />';
101 $columns['sale_date_time'] = __( 'Sale Date', 'propertyhive' );
102 $columns['property'] = __( 'Property', 'propertyhive' );
103 $columns['property_owner'] = __( 'Property Owner', 'propertyhive' );
104 $columns['applicant'] = __( 'Applicant(s)', 'propertyhive' );
105 $columns['amount'] = __( 'Amount', 'propertyhive' );
106 $columns['status'] = __( 'Status', 'propertyhive' );
107
108 return array_merge( $columns, $existing_columns );
109 }
110
111 /**
112 * Define our custom columns shown in admin.
113 * @param string $column
114 */
115 public function custom_columns( $column ) {
116 global $post, $propertyhive, $the_sale;
117
118 if ( empty( $the_sale ) || $the_sale->ID != $post->ID )
119 {
120 $the_sale = new PH_Sale( $post->ID );
121 }
122
123 switch ( $column ) {
124 case 'sale_date_time' :
125
126 $edit_link = get_edit_post_link( $post->ID );
127 //$title = _draft_or_post_title();
128 $title = date("jS F Y", strtotime($the_sale->sale_date_time));
129
130 $post_type_object = get_post_type_object( $post->post_type );
131 $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
132
133 echo '<strong><a class="row-title" href="' . esc_url( $edit_link ) .'">' . esc_html($title) . '</a></strong>';
134 break;
135 case 'property' :
136
137 if ( $the_sale->property_id != '' )
138 {
139 $property = new PH_Property((int)$the_sale->property_id);
140 echo esc_html($property->get_formatted_full_address());
141 }
142 else
143 {
144 echo '-';
145 }
146
147 break;
148 case 'property_owner' :
149
150 $the_property = new PH_Property((int)$the_sale->property_id);
151 $owner_contact_ids = $the_property->_owner_contact_id;
152 if (
153 ( !is_array($owner_contact_ids) && $owner_contact_ids != '' && $owner_contact_ids != 0 )
154 ||
155 ( is_array($owner_contact_ids) && !empty($owner_contact_ids) )
156 )
157 {
158 if ( !is_array($owner_contact_ids) )
159 {
160 $owner_contact_ids = array($owner_contact_ids);
161 }
162
163 foreach ( $owner_contact_ids as $owner_contact_id )
164 {
165 echo esc_html(get_the_title($owner_contact_id)) . '<br>';
166 if ( count($owner_contact_ids) == 1 )
167 {
168 echo '<div class="row-actions">';
169 echo 'T: ' . esc_html(get_post_meta($owner_contact_id, '_telephone_number', TRUE)) . '<br>';
170 echo 'E: ' . esc_html(get_post_meta($owner_contact_id, '_email_address', TRUE));
171 echo '</div>';
172 }
173 }
174 }
175 else
176 {
177 echo '-';
178 }
179
180 break;
181 case 'applicant' :
182
183 echo $the_sale->get_applicants( false, true, false );
184
185 break;
186 case 'amount' :
187
188 echo $the_sale->get_formatted_amount();
189
190 break;
191 case 'status' :
192
193 echo esc_html(__( ucwords(str_replace("_", " ", $the_sale->status)), 'propertyhive' ));
194
195 break;
196 default :
197 break;
198 }
199 }
200
201 public function set_primary_column( $default, $screen ) {
202
203 if ( 'edit-sale' === $screen )
204 {
205 $default = 'sale_date_time';
206 }
207
208 return $default;
209 }
210
211 public function remove_actions($actions, $post) {
212
213 if ( $post->post_type !== 'sale' )
214 {
215 return $actions;
216 }
217
218 // Remove 'Quick Edit' link
219 if ( isset($actions['inline hide-if-no-js']) )
220 {
221 unset($actions['inline hide-if-no-js']);
222 }
223
224 if ( isset($actions['trash']) )
225 {
226 unset($actions['trash']);
227 }
228
229 return $actions;
230 }
231
232 /**
233 * Make sale columns sortable
234 *
235 * @access public
236 * @param mixed $columns
237 * @return array
238 */
239 public function custom_columns_sort( $columns ) {
240 $custom = array(
241 'sale_date_time' => '_sale_date_time',
242 'status' => '_status',
243 );
244 return wp_parse_args( $custom, $columns );
245 }
246
247 /**
248 * Sale column orderby
249 *
250 * @access public
251 * @param mixed $vars
252 * @return array
253 */
254 public function custom_columns_orderby( $vars ) {
255 if ( isset( $vars['orderby'] ) ) {
256 if ( '_sale_date_time' == $vars['orderby'] ) {
257 $vars = array_merge( $vars, array(
258 'meta_key' => '_sale_date_time',
259 'orderby' => 'meta_value'
260 ) );
261 }
262 elseif ( '_status' == $vars['orderby'] ) {
263 $vars = array_merge( $vars, array(
264 'meta_key' => '_status',
265 'orderby' => 'meta_value'
266 ) );
267 }
268 }
269 return $vars;
270 }
271
272 /**
273 * Remove bulk edit option
274 * @param array $actions
275 */
276 public function remove_bulk_actions( $actions ) {
277 unset( $actions['edit'] );
278 return $actions;
279 }
280
281 /**
282 * Show a status filter box
283 */
284 public function propertyhive_filters() {
285 global $typenow, $wp_query;
286
287 if ( 'sale' != $typenow ) {
288 return;
289 }
290
291 echo apply_filters( 'propertyhive_sale_filters', $output );
292 }
293
294 /**
295 * Filter the sales in admin based on options
296 *
297 * @param mixed $query
298 */
299 public function sale_filters_query( $query ) {
300 global $typenow, $wp_query;
301
302 if ( 'sale' == $typenow ) {
303
304 }
305 }
306 }
307
308 endif;
309
310 return new PH_Admin_CPT_Sale();
311