PluginProbe
Property Hive / 2.2.5
Property Hive v2.2.5
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-appraisal.php

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

331 lines 9.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 appraisal 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_Appraisal' ) ) :
20
21 /**
22 * PH_Admin_CPT_Appraisal Class
23 */
24 class PH_Admin_CPT_Appraisal extends PH_Admin_CPT {
25
26 /**
27 * Constructor
28 */
29 public function __construct() {
30 $this->type = 'appraisal';
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-appraisal_columns', array( $this, 'edit_columns' ) );
38 add_action( 'manage_appraisal_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-appraisal_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-appraisal', 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 appraisal
56 * @return boolean
57 */
58 private function is_editing_appraisal() {
59 if ( ! empty( $_GET['post_type'] ) && 'appraisal' == $_GET['post_type'] ) {
60 return true;
61 }
62 if ( ! empty( $_GET['post'] ) && 'appraisal' == get_post_type( (int)$_GET['post'] ) ) {
63 return true;
64 }
65 if ( ! empty( $_REQUEST['post_id'] ) && 'appraisal' == 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['start_date_time'] = __( 'Appraisal Date / Time', 'propertyhive' );
102 $columns['property'] = __( 'Property', 'propertyhive' );
103 $columns['owner'] = __( 'Owner / Landlord', 'propertyhive' );
104 $columns['price'] = __( 'Valued Price', 'propertyhive' );
105 $columns['status'] = __( 'Status', 'propertyhive' );
106 $columns['negotiators'] = __( 'Attending Negotiators', '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_appraisal;
117
118 if ( empty( $the_appraisal ) || $the_appraisal->ID != $post->ID )
119 {
120 $the_appraisal = new PH_Appraisal( $post->ID );
121 }
122
123 switch ( $column ) {
124 case 'start_date_time' :
125
126 $edit_link = get_edit_post_link( $post->ID );
127 //$title = _draft_or_post_title();
128 $title = date("H:i jS F Y", strtotime($the_appraisal->start_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 echo esc_html($the_appraisal->get_formatted_full_address());
138 break;
139 case 'owner' :
140
141 $owner_contact_ids = $the_appraisal->_property_owner_contact_id;
142 if (
143 ( !is_array($owner_contact_ids) && $owner_contact_ids != '' && $owner_contact_ids != 0 )
144 ||
145 ( is_array($owner_contact_ids) && !empty($owner_contact_ids) )
146 )
147 {
148 if ( !is_array($owner_contact_ids) )
149 {
150 $owner_contact_ids = array($owner_contact_ids);
151 }
152
153 foreach ( $owner_contact_ids as $owner_contact_id )
154 {
155 echo esc_html(get_the_title($owner_contact_id)) . '<br>';
156 if ( count($owner_contact_ids) == 1 )
157 {
158 echo '<div class="row-actions">';
159 echo 'T: ' . esc_html(get_post_meta($owner_contact_id, '_telephone_number', TRUE)) . '<br>';
160 echo 'E: ' . esc_html(get_post_meta($owner_contact_id, '_email_address', TRUE));
161 echo '</div>';
162 }
163 }
164 }
165 else
166 {
167 echo '-';
168 }
169 break;
170 case 'price' :
171
172 if ( $the_appraisal->status == 'carried_out' )
173 {
174 echo $the_appraisal->get_formatted_price();
175 }
176 else
177 {
178 echo '-';
179 }
180 break;
181 case 'status' :
182
183 echo esc_html(ucwords(str_replace("_", " ", $the_appraisal->status)));
184
185 if ( $the_appraisal->status == 'pending' )
186 {
187 echo '<br>';
188 // confirmation status
189 if ( $the_appraisal->all_confirmed == 'yes' )
190 {
191 echo esc_html(__( 'All Parties Confirmed', 'propertyhive' ));
192 }
193 else
194 {
195 echo esc_html(__( 'Awaiting Confirmation', 'propertyhive' ));
196 }
197 }
198
199 break;
200 case 'negotiators' :
201 $negotiator_ids = get_post_meta( $post->ID, '_negotiator_id' );
202 if ( is_array($negotiator_ids) && !empty($negotiator_ids) )
203 {
204 $negotiators = array();
205 foreach ( $negotiator_ids as $negotiator_id )
206 {
207 $user_info = get_userdata($negotiator_id);
208 if ( $user_info === false )
209 {
210 $negotiators[] = __( 'Unknown negotiator', 'propertyhive' );
211 }
212 else
213 {
214 $negotiators[] = $user_info->display_name;
215 }
216 }
217 echo esc_html(implode(", ", $negotiators));
218 }
219 else
220 {
221 echo '<em>- ' . esc_html(__( 'None Set', 'propertyhive' )) . ' -</em>';
222 }
223 break;
224 default :
225 break;
226 }
227 }
228
229 public function set_primary_column( $default, $screen ) {
230
231 if ( 'edit-appraisal' === $screen )
232 {
233 $default = 'start_date_time';
234 }
235
236 return $default;
237 }
238
239 public function remove_actions($actions, $post) {
240
241 if ( $post->post_type !== 'appraisal' )
242 {
243 return $actions;
244 }
245
246 // Remove 'Quick Edit' link
247 if ( isset($actions['inline hide-if-no-js']) )
248 {
249 unset($actions['inline hide-if-no-js']);
250 }
251
252 if ( isset($actions['trash']) )
253 {
254 unset($actions['trash']);
255 }
256
257 return $actions;
258 }
259
260 /**
261 * Make appraisal columns sortable
262 *
263 * @access public
264 * @param mixed $columns
265 * @return array
266 */
267 public function custom_columns_sort( $columns ) {
268 $custom = array(
269 'start_date_time' => '_start_date_time',
270 );
271 return wp_parse_args( $custom, $columns );
272 }
273
274 /**
275 * Appraisal column orderby
276 *
277 * @access public
278 * @param mixed $vars
279 * @return array
280 */
281 public function custom_columns_orderby( $vars ) {
282 if ( is_admin() && $vars['post_type'] == 'appraisal' )
283 {
284 $vars = array_merge( $vars, array(
285 'meta_key' => '_start_date_time',
286 'orderby' => 'meta_value'
287 ) );
288 }
289 return $vars;
290 }
291
292 /**
293 * Remove bulk edit option
294 * @param array $actions
295 */
296 public function remove_bulk_actions( $actions ) {
297 unset( $actions['edit'] );
298 return $actions;
299 }
300
301 /**
302 * Show a status filter box
303 */
304 public function propertyhive_filters() {
305 global $typenow, $wp_query;
306
307 if ( 'appraisal' != $typenow ) {
308 return;
309 }
310
311 echo apply_filters( 'propertyhive_appraisal_filters', $output );
312 }
313
314 /**
315 * Filter the appraisal in admin based on options
316 *
317 * @param mixed $query
318 */
319 public function appraisal_filters_query( $query ) {
320 global $typenow, $wp_query;
321
322 if ( 'appraisal' == $typenow ) {
323
324 }
325 }
326 }
327
328 endif;
329
330 return new PH_Admin_CPT_Appraisal();
331