Commit b9ad291a authored by Michael Iseard's avatar Michael Iseard
Browse files

Add checks to array keys

parent 42ebc0a8
......@@ -98,12 +98,11 @@ class CampaignsTable extends WP_List_Table {
$campaign_total = $this->campaigns::get_campaign_stats( $id );
$campaigns[ $key ]['date'] = $campaign_total['last_donation'];
$campaigns[ $key ]['goal'] = !empty($campaign['campaign_goal']) ? $campaign['campaign_goal'] : null;
$campaigns[ $key ]['total'] = 0;
$campaigns[ $key ]['currency'] = 'EUR';
$campaigns[ $key ]['total'] = $campaign_total['total'];
$campaigns[ $key ]['transactions'] = $campaign_total['count'];
$campaigns[ $key ]['currency'] = 'EUR';
$campaigns[ $key ]['date'] = isset( $campaign_total['last_donation'] ) ? $campaign_total['last_donation'] : null;
$campaigns[ $key ]['goal'] = isset( $campaign['campaign_goal'] ) ? $campaign['campaign_goal'] : null;
$campaigns[ $key ]['total'] = isset( $campaign_total['total'] ) ? $campaign_total['total'] : null;
$campaigns[ $key ]['transactions'] = isset( $campaign_total['count'] ) ? $campaign_total['count'] : null;
}
return $campaigns;
......@@ -117,11 +116,11 @@ class CampaignsTable extends WP_List_Table {
*/
public function column_names(): array {
return [
'name' => __( 'Name', 'kudos-donations' ),
'transactions' => __( 'Transactions', 'kudos-donations' ),
'total' => __( 'Total', 'kudos-donations' ),
'goal' => __( 'Goal', 'kudos-donations' ),
'date' => __( 'Last donation', 'kudos-donations' ),
'name' => __( 'Name', 'kudos-donations' ),
'transactions' => __( 'Transactions', 'kudos-donations' ),
'total' => __( 'Total', 'kudos-donations' ),
'goal' => __( 'Goal', 'kudos-donations' ),
'date' => __( 'Last donation', 'kudos-donations' ),
];
}
......@@ -146,11 +145,11 @@ class CampaignsTable extends WP_List_Table {
*/
public function get_sortable_columns(): array {
return [
'date' => [
'date' => [
'date',
false,
],
'total' => [
'total' => [
'total',
false,
],
......@@ -182,7 +181,7 @@ class CampaignsTable extends WP_List_Table {
*/
protected function column_date( array $item ): string {
return isset( $item['date'] ) ? wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ),
return $item['date'] ? wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ),
strtotime( $item['date'] ) ) : sprintf( "<i>%s</i>", __( 'None yet', 'kudos-donations' ) );
}
......
......@@ -44,7 +44,7 @@ class DonorsTable extends WP_List_Table {
'postcode' => __( 'Postcode', 'kudos-donations' ),
'city' => __( 'City', 'kudos-donations' ),
'country' => __( 'Country', 'kudos-donations' ),
'mode' => __( 'Mode', 'kudos-donations' )
'mode' => __( 'Mode', 'kudos-donations' ),
];
parent::__construct(
......@@ -80,9 +80,9 @@ class DonorsTable extends WP_List_Table {
public function fetch_table_data(): array {
$search = $this->get_search_data();
$search_field = isset( $search['field'] ) ? $search['field'] : null;
$search_term = isset( $search['term'] ) ? $search['term'] : null;
$donors = $this->mapper->get_all_by( [ $search_field => $search_term ], 'AND' );
$search_field = ! empty( $search['field'] ) ? $search['field'] : null;
$search_term = ! empty( $search['term'] ) ? $search['term'] : null;
$donors = $this->mapper->get_all_by( [ $search_field => $search_term ] );
return array_map( function ( $donor ) {
return $donor->to_array();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment