PluginProbe
Property Hive / 2.2.4
Property Hive v2.2.4
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-offer.php

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

310 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 offer 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_Offer' ) ) :
20
21 /**
22 * PH_Admin_CPT_Offer Class
23 */
24 class PH_Admin_CPT_Offer extends PH_Admin_CPT {
25
26 /**
27 * Constructor
28 */
29 public function __construct() {
30 $this->type = 'offer';
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-offer_columns', array( $this, 'edit_columns' ) );
38 add_action( 'manage_offer_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-offer_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-offer', 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 offer
56 * @return boolean
57 */
58 private function is_editing_offer() {
59 if ( ! empty( $_GET['post_type'] ) && 'offer' == $_GET['post_type'] ) {
60 return true;
61 }
62 if ( ! empty( $_GET['post'] ) && 'offer' == get_post_type( (int)$_GET['post'] ) ) {
63 return true;
64 }
65 if ( ! empty( $_REQUEST['post_id'] ) && 'offer' == 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['offer_date_time'] = __( 'Offer Date / Time', '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_offer;
117
118 if ( empty( $the_offer ) || $the_offer->ID != $post->ID )
119 {
120 $the_offer = new PH_Offer( $post->ID );
121 }
122
123 switch ( $column ) {
124 case 'offer_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_offer->offer_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_offer->property_id != '' )
138 {
139 $property = new PH_Property((int)$the_offer->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_offer->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_offer->get_applicants( false, true, false );
184
185 break;
186 case 'amount' :
187
188 echo $the_offer->get_formatted_amount();
189
190 break;
191 case 'status' :
192 echo esc_html(__( ucwords(str_replace("_", " ", $the_offer->status)), 'propertyhive' ));
193 break;
194 default :
195 break;
196 }
197 }
198
199 public function set_primary_column( $default, $screen ) {
200
201 if ( 'edit-offer' === $screen )
202 {
203 $default = 'offer_date_time';
204 }
205
206 return $default;
207 }
208
209 public function remove_actions($actions, $post) {
210
211 if ( $post->post_type !== 'offer' )
212 {
213 return $actions;
214 }
215
216 // Remove 'Quick Edit' link
217 if ( isset($actions['inline hide-if-no-js']) )
218 {
219 unset($actions['inline hide-if-no-js']);
220 }
221
222 if ( isset($actions['trash']) )
223 {
224 unset($actions['trash']);
225 }
226
227 return $actions;
228 }
229
230 /**
231 * Make offer columns sortable
232 *
233 * @access public
234 * @param mixed $columns
235 * @return array
236 */
237 public function custom_columns_sort( $columns ) {
238 $custom = array(
239 'offer_date_time' => '_offer_date_time',
240 'status' => '_status',
241 );
242 return wp_parse_args( $custom, $columns );
243 }
244
245 /**
246 * Offer column orderby
247 *
248 * @access public
249 * @param mixed $vars
250 * @return array
251 */
252 public function custom_columns_orderby( $vars ) {
253 if ( isset( $vars['orderby'] ) ) {
254 if ( '_offer_date_time' == $vars['orderby'] ) {
255 $vars = array_merge( $vars, array(
256 'meta_key' => '_offer_date_time',
257 'orderby' => 'meta_value'
258 ) );
259 }
260 elseif ( '_status' == $vars['orderby'] ) {
261 $vars = array_merge( $vars, array(
262 'meta_key' => '_status',
263 'orderby' => 'meta_value'
264 ) );
265 }
266 }
267
268 return $vars;
269 }
270
271 /**
272 * Remove bulk edit option
273 * @param array $actions
274 */
275 public function remove_bulk_actions( $actions ) {
276 unset( $actions['edit'] );
277 return $actions;
278 }
279
280 /**
281 * Show a status filter box
282 */
283 public function propertyhive_filters() {
284 global $typenow, $wp_query;
285
286 if ( 'offer' != $typenow ) {
287 return;
288 }
289
290 echo apply_filters( 'propertyhive_offer_filters', $output );
291 }
292
293 /**
294 * Filter the offers in admin based on options
295 *
296 * @param mixed $query
297 */
298 public function offer_filters_query( $query ) {
299 global $typenow, $wp_query;
300
301 if ( 'offer' == $typenow ) {
302
303 }
304 }
305 }
306
307 endif;
308
309 return new PH_Admin_CPT_Offer();
310