Changeset 3294
- Timestamp:
- 06/02/2016 08:50:41 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/reimbursement-requests-list-table.php
r2747 r3294 8 8 /** 9 9 * Define the table columns that will be rendered 10 * 11 * @return array 10 12 */ 11 13 public function get_columns() { … … 13 15 'request_title' => 'Request', 14 16 'wordcamp_name' => 'WordCamp', 17 'status' => 'Status', 18 'categories' => 'Categories', 15 19 'amount' => 'Amount', 20 'method' => 'Method', 21 'attachments' => 'Attachments', 16 22 ); 17 23 … … 75 81 76 82 /** 77 * Render the value for the Invoice column 83 * Output a single row in the list table. 84 * 85 * Holy cow, switch to blog! Please note that all the 86 * column_* methods are being run in a switched context. 87 * 88 * @param object $item 89 */ 90 public function single_row( $item ) { 91 switch_to_blog( $item->blog_id ); 92 93 $request = get_post( $item->request_id ); 94 parent::single_row( $request ); 95 96 restore_current_blog(); 97 } 98 99 /** 100 * Render the value for the Request column 101 * 102 * Note: Runs in a switch_to_blog() context. 78 103 * 79 104 * @param object $index_row 80 * /81 protected function column_request_title( $index_row ) {82 $blog_id = $index_row->blog_id;83 switch_to_blog( $blog_id );84 $ post = get_post( $index_row->request_id);105 * 106 * @return string 107 */ 108 protected function column_request_title( $post ) { 109 $blog_id = get_current_blog_id(); 85 110 $title = get_the_title( $post ); 86 111 $title = empty( $title ) ? '(no title)' : $title; … … 116 141 117 142 $output = ob_get_clean(); 118 restore_current_blog();119 143 return $output; 120 144 } 121 145 122 146 /** 123 * Render the value for the Due Date column 124 * 125 * @param object $index_row 126 */ 127 protected function column_amount( $index_row ) { 147 * Render the value for the WordCamp column 148 * 149 * Note: Runs in a switch_to_blog() context. 150 * 151 * @param \WP_Post $request 152 * 153 * @return string 154 */ 155 protected function column_wordcamp_name( $request ) { 156 return esc_html( $request->post_title ); 157 } 158 159 /** 160 * Render the value for the Status column 161 * 162 * Note: Runs in a switch_to_blog() context. 163 * 164 * @param \WP_Post $request 165 * 166 * @return string 167 */ 168 public function column_status( $request ) { 169 $status = get_post_status_object( $request->post_status ); 170 171 return esc_html( $status->label ); 172 } 173 174 /** 175 * Render the value for the Categories column 176 * 177 * Note: Runs in a switch_to_blog() context. 178 * 179 * @param \WP_Post $request 180 * 181 * @return string 182 */ 183 public function column_categories( $request ) { 184 require_once( WP_PLUGIN_DIR . '/wordcamp-payments/includes/payment-request.php' ); 185 186 $categories = \WordCamp_Budgets::get_payment_categories(); 187 $expenses = get_post_meta( $request->ID, '_wcbrr_expenses', true ); 188 $selected_categories = array(); 189 190 if ( is_array( $expenses ) ) { 191 foreach ( $expenses as $expense ) { 192 if ( isset( $categories[ $expense['_wcbrr_category'] ] ) ) { 193 $selected_categories[] = $categories[ $expense['_wcbrr_category'] ]; 194 } 195 } 196 } 197 198 return implode( '<br />', array_unique( $selected_categories ) ); 199 } 200 201 /** 202 * Render the value for the Amount column 203 * 204 * Note: Runs in a switch_to_blog() context. 205 * 206 * @param \WP_Post $request 207 * 208 * @return string 209 */ 210 protected function column_amount( $request ) { 211 $currency = get_post_meta( $request->ID, '_wcbrr_currency', true ); 212 $expenses = get_post_meta( $request->ID, '_wcbrr_expenses', true ); 213 $amount = 0; 214 215 if ( is_array( $expenses ) ) { 216 foreach ( $expenses as $expense ) { 217 $amount += $expense['_wcbrr_amount']; 218 } 219 } 220 128 221 return wp_kses( 129 \WordCamp\Budgets_Dashboard\format_amount( $ index_row->amount, $index_row->currency ),222 \WordCamp\Budgets_Dashboard\format_amount( $amount, $currency ), 130 223 array( 'br' => array() ) 131 224 ); … … 133 226 134 227 /** 135 * Render the value for columns that don't have a explicit handler 136 * 137 * @param object $index_row 138 * @param string $column_name 139 */ 140 protected function column_default( $index_row, $column_name ) { 141 echo esc_html( $index_row->$column_name ); 228 * Render the value for the Method column 229 * 230 * Note: Runs in a switch_to_blog() context. 231 * 232 * @param \WP_Post $request 233 * 234 * @return string 235 */ 236 public function column_method( $request ) { 237 $method = get_post_meta( $request->ID, '_wcbrr_payment_method', true ); 238 239 return esc_html( $method ); 240 } 241 242 /** 243 * Render the value for the Attachments column 244 * 245 * Note: Runs in a switch_to_blog() context. 246 * 247 * @param \WP_Post $request 248 * 249 * @return string 250 */ 251 public function column_attachments( $request ) { 252 $attachments = get_children( array( 'post_parent' => $request->ID ) ); 253 $attachments = array_map( 'wp_get_attachment_url', wp_list_pluck( $attachments, 'ID' ) ); 254 255 $output = array(); 256 foreach ( $attachments as $attachment ) { 257 $output[] = sprintf( '<a href="%s" target="_blank" class="dashicons dashicons-media-default" title="%s"></a>', 258 esc_url( $attachment ), esc_attr( $attachment ) ); 259 } 260 261 return implode( '', $output ); 142 262 } 143 263 }
Note: See TracChangeset
for help on using the changeset viewer.