Last active
August 29, 2015 14:13
-
-
Save dtbaker/2b3057483567c9acfa7a to your computer and use it in GitHub Desktop.
Add this to UCM in includes/plugin_custom_table_hooks/custom_table_hooks.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class module_custom_table_hooks extends module_base{ | |
public function init(){ | |
hook_add('table_process_data','module_custom_table_hooks::hook_table_process_data'); | |
} | |
public static function hook_table_process_data($callback, $table_manager){ | |
switch($table_manager->table_id){ | |
case 'customer_list': | |
// This will add new columns to the main "Customer" listing page. | |
if ( ! is_closure( $table_manager->row_callback ) ) { | |
$table_manager->row_callback = function () { | |
return array(); | |
}; | |
} | |
$old_row_callback = $table_manager->row_callback; | |
$new_row_callback = function ( $row_data ) use ( $old_row_callback ) { | |
$result = $old_row_callback( $row_data ); | |
if ( ! is_array( $result ) ) { | |
$result = $row_data; | |
} | |
// populate data to display in the new rows defined below. | |
// 'extra_column_1' here is to match the 'extra_column_1' further down | |
$result['extra_column_1'] = "Some Data Here"; | |
$result['extra_column_2'] = "Customer ID: " . $row_data['customer_id']; | |
// grab a list of all the customers invoicse and do some calculations. | |
$customer_invoices = module_invoice::get_invoices(array('customer_id'=>$row_data['customer_id'])); | |
$total_due = 0; | |
$total_paid = 0; | |
foreach($customer_invoices as $invoice){ | |
$invoice = module_invoice::get_invoice($invoice['invoice_id']); | |
$total_due += $invoice['total_amount_due']; | |
$total_paid += $invoice['total_amount_paid']; | |
} | |
$result['extra_column_3'] = "Paid: ".dollar($total_paid).", Due: ".dollar($total_due); | |
return $result; | |
}; | |
$table_manager->row_callback = $new_row_callback; | |
$table_manager->columns['extra_column_1'] = array( | |
'title' => 'Col 1', | |
); | |
$table_manager->columns['extra_column_2'] = array( | |
'title' => 'Col 2', | |
); | |
$table_manager->columns['extra_column_3'] = array( | |
'title' => 'Col 3', | |
); | |
break; | |
case 'job_list': | |
// This will add new columns to the main "Jobs" listing page. | |
if ( ! is_closure( $table_manager->row_callback ) ) { | |
$table_manager->row_callback = function () { | |
return array(); | |
}; | |
} | |
$old_row_callback = $table_manager->row_callback; | |
$new_row_callback = function ( $row_data ) use ( $old_row_callback ) { | |
$result = $old_row_callback( $row_data ); | |
if ( ! is_array( $result ) ) { | |
$result = $row_data; | |
} | |
// populate data to display in the new rows defined below. | |
// 'extra_column_1' here is to match the 'extra_column_1' further down | |
$result['extra_column_1'] = "Some Data Here"; | |
$result['extra_column_2'] = "Customer/Job ID: " . $row_data['customer_id'].'/'.$row_data['job_id']; | |
// grab a list of all the customers invoicse and do some calculations. | |
$customer_invoices = module_invoice::get_invoices(array('job_id'=>$row_data['job_id'])); | |
$total_due = 0; | |
$total_paid = 0; | |
foreach($customer_invoices as $invoice){ | |
$invoice = module_invoice::get_invoice($invoice['invoice_id']); | |
$total_due += $invoice['total_amount_due']; | |
$total_paid += $invoice['total_amount_paid']; | |
} | |
$result['extra_column_3'] = "Paid: ".dollar($total_paid).", Due: ".dollar($total_due); | |
return $result; | |
}; | |
$table_manager->row_callback = $new_row_callback; | |
$table_manager->columns['extra_column_1'] = array( | |
'title' => 'Col 1', | |
); | |
$table_manager->columns['extra_column_2'] = array( | |
'title' => 'Col 2', | |
); | |
$table_manager->columns['extra_column_3'] = array( | |
'title' => 'Col 3', | |
); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment