PluginProbe
Property Hive / 1.4.54
Property Hive v1.4.54
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 1.4.54, at includes/admin/post-types/class-ph-admin-cpt-sale.php

330 lines 10.1 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( 'manage_edit-sale_sortable_columns', array( $this, 'custom_columns_sort' ) );
40 add_filter( 'request', array( $this, 'custom_columns_orderby' ) );
41
42 // Bulk / quick edit
43 add_filter( 'bulk_actions-edit-sale', array( $this, 'remove_bulk_actions') );
44 /*add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit' ), 10, 2 );
45 add_action( 'quick_edit_custom_box', array( $this, 'quick_edit' ), 10, 2 );
46 add_action( 'save_post', array( $this, 'bulk_and_quick_edit_save_post' ), 10, 2 );*/
47
48 // Call PH_Admin_CPT constructor
49 parent::__construct();
50 }
51
52 /**
53 * Check if we're editing or adding a sale
54 * @return boolean
55 */
56 private function is_editing_sale() {
57 if ( ! empty( $_GET['post_type'] ) && 'sale' == $_GET['post_type'] ) {
58 return true;
59 }
60 if ( ! empty( $_GET['post'] ) && 'sale' == get_post_type( (int)$_GET['post'] ) ) {
61 return true;
62 }
63 if ( ! empty( $_REQUEST['post_id'] ) && 'sale' == get_post_type( (int)$_REQUEST['post_id'] ) ) {
64 return true;
65 }
66 return false;
67 }
68
69 /**
70 * @param int $post_id
71 */
72 public function pre_post_update( $post_id ) {
73
74 }
75
76 /**
77 * @param array $data
78 * @return array
79 */
80 public function wp_insert_post_data( $data ) {
81
82
83 return $data;
84 }
85
86 /**
87 * Change the columns shown in admin.
88 */
89 public function edit_columns( $existing_columns ) {
90
91 if ( empty( $existing_columns ) && ! is_array( $existing_columns ) ) {
92 $existing_columns = array();
93 }
94
95 unset( $existing_columns['title'], $existing_columns['comments'], $existing_columns['date'] );
96
97 $columns = array();
98 $columns['cb'] = '<input type="checkbox" />';
99 $columns['sale_date_time'] = __( 'Sale Date', 'propertyhive' );
100 $columns['property'] = __( 'Property', 'propertyhive' );
101 $columns['property_owner'] = __( 'Property Owner', 'propertyhive' );
102 $columns['applicant'] = __( 'Applicant', 'propertyhive' );
103 $columns['amount'] = __( 'Amount', 'propertyhive' );
104 $columns['status'] = __( 'Status', 'propertyhive' );
105
106 return array_merge( $columns, $existing_columns );
107 }
108
109 /**
110 * Define our custom columns shown in admin.
111 * @param string $column
112 */
113 public function custom_columns( $column ) {
114 global $post, $propertyhive, $the_sale;
115
116 if ( empty( $the_sale ) || $the_sale->ID != $post->ID )
117 {
118 $the_sale = new PH_Sale( $post->ID );
119 }
120
121 switch ( $column ) {
122 case 'sale_date_time' :
123
124 $edit_link = get_edit_post_link( $post->ID );
125 //$title = _draft_or_post_title();
126 $title = date("jS F Y", strtotime($the_sale->sale_date_time));
127
128 $post_type_object = get_post_type_object( $post->post_type );
129 $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
130
131 echo '<strong><a class="row-title" href="' . esc_url( $edit_link ) .'">' . $title.'</a></strong>';
132
133 // Get actions
134 $actions = array();
135
136 if ( $can_edit_post && 'trash' != $post->post_status ) {
137 $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item', 'propertyhive' ) ) . '">' . __( 'Edit', 'propertyhive' ) . '</a>';
138 }
139 if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
140 if ( 'trash' == $post->post_status ) {
141 $actions['untrash'] = '<a title="' . esc_attr( __( 'Restore this item from the Trash', 'propertyhive' ) ) . '" href="' . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . '">' . __( 'Restore', 'propertyhive' ) . '</a>';
142 } elseif ( EMPTY_TRASH_DAYS ) {
143 //$actions['trash'] = '<a class="submitdelete" title="' . esc_attr( __( 'Move this item to the Trash', 'propertyhive' ) ) . '" href="' . get_delete_post_link( $post->ID ) . '">' . __( 'Trash', 'propertyhive' ) . '</a>';
144 }
145
146 if ( 'trash' == $post->post_status || ! EMPTY_TRASH_DAYS ) {
147 $actions['delete'] = '<a class="submitdelete" title="' . esc_attr( __( 'Delete this item permanently', 'propertyhive' ) ) . '" href="' . get_delete_post_link( $post->ID, '', true ) . '">' . __( 'Delete Permanently', 'propertyhive' ) . '</a>';
148 }
149 }
150 if ( $post_type_object->public ) {
151 if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
152 if ( $can_edit_post )
153 $actions['view'] = '<a href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) . '" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;', 'propertyhive' ), $title ) ) . '" rel="permalink">' . __( 'Preview', 'propertyhive' ) . '</a>';
154 } elseif ( 'trash' != $post->post_status ) {
155 $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'propertyhive' ), $title ) ) . '" rel="permalink">' . __( 'View', 'propertyhive' ) . '</a>';
156 }
157 }
158
159 $actions = apply_filters( 'post_row_actions', $actions, $post );
160
161 echo '<div class="row-actions">';
162
163 $i = 0;
164 $action_count = sizeof($actions);
165
166 foreach ( $actions as $action => $link ) {
167 ++$i;
168 ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
169 echo '<span class="' . $action . '">' . $link . $sep . '</span>';
170 }
171 echo '</div>';
172
173 break;
174 case 'property' :
175
176 if ( $the_sale->property_id != '' )
177 {
178 $property = new PH_Property((int)$the_sale->property_id);
179 echo $property->get_formatted_full_address();
180 }
181 else
182 {
183 echo '-';
184 }
185
186 break;
187 case 'property_owner' :
188
189 $the_property = new PH_Property((int)$the_sale->property_id);
190 $owner_contact_ids = $the_property->_owner_contact_id;
191 if (
192 ( !is_array($owner_contact_ids) && $owner_contact_ids != '' && $owner_contact_ids != 0 )
193 ||
194 ( is_array($owner_contact_ids) && !empty($owner_contact_ids) )
195 )
196 {
197 if ( !is_array($owner_contact_ids) )
198 {
199 $owner_contact_ids = array($owner_contact_ids);
200 }
201
202 foreach ( $owner_contact_ids as $owner_contact_id )
203 {
204 echo get_the_title($owner_contact_id) . '<br>';
205 if ( count($owner_contact_ids) == 1 )
206 {
207 echo '<div class="row-actions">';
208 echo 'T: ' . get_post_meta($owner_contact_id, '_telephone_number', TRUE) . '<br>';
209 echo 'E: ' . get_post_meta($owner_contact_id, '_email_address', TRUE);
210 echo '</div>';
211 }
212 }
213 }
214 else
215 {
216 echo '-';
217 }
218
219 break;
220 case 'applicant' :
221
222 if ( $the_sale->applicant_contact_id != '' )
223 {
224 echo get_the_title($the_sale->applicant_contact_id);
225 echo '<div class="row-actions">';
226 echo 'T: ' . get_post_meta($the_sale->applicant_contact_id, '_telephone_number', TRUE) . '<br>';
227 echo 'E: ' . get_post_meta($the_sale->applicant_contact_id, '_email_address', TRUE);
228 echo '</div>';
229 }
230 else
231 {
232 echo '-';
233 }
234
235 break;
236 case 'amount' :
237
238 echo $the_sale->get_formatted_amount();
239
240 break;
241 case 'status' :
242
243 echo ucwords(str_replace("_", " ", $the_sale->status));
244
245 break;
246 default :
247 break;
248 }
249 }
250
251 /**
252 * Make sale columns sortable
253 *
254 * @access public
255 * @param mixed $columns
256 * @return array
257 */
258 public function custom_columns_sort( $columns ) {
259 $custom = array(
260 'sale_date_time' => '_sale_date_time',
261 'status' => '_status',
262 );
263 return wp_parse_args( $custom, $columns );
264 }
265
266 /**
267 * Sale column orderby
268 *
269 * @access public
270 * @param mixed $vars
271 * @return array
272 */
273 public function custom_columns_orderby( $vars ) {
274 if ( isset( $vars['orderby'] ) ) {
275 if ( '_sale_date_time' == $vars['orderby'] ) {
276 $vars = array_merge( $vars, array(
277 'meta_key' => '_sale_date_time',
278 'orderby' => 'meta_value'
279 ) );
280 }
281 elseif ( '_status' == $vars['orderby'] ) {
282 $vars = array_merge( $vars, array(
283 'meta_key' => '_status',
284 'orderby' => 'meta_value'
285 ) );
286 }
287 }
288 return $vars;
289 }
290
291 /**
292 * Remove bulk edit option
293 * @param array $actions
294 */
295 public function remove_bulk_actions( $actions ) {
296 unset( $actions['edit'] );
297 return $actions;
298 }
299
300 /**
301 * Show a status filter box
302 */
303 public function propertyhive_filters() {
304 global $typenow, $wp_query;
305
306 if ( 'sale' != $typenow ) {
307 return;
308 }
309
310 echo apply_filters( 'propertyhive_sale_filters', $output );
311 }
312
313 /**
314 * Filter the sales in admin based on options
315 *
316 * @param mixed $query
317 */
318 public function sale_filters_query( $query ) {
319 global $typenow, $wp_query;
320
321 if ( 'sale' == $typenow ) {
322
323 }
324 }
325 }
326
327 endif;
328
329 return new PH_Admin_CPT_Sale();
330