ID = $ID; $this->db = $wpdb; $this->date_format = get_option('date_format'); $this->time_format = get_option('time_format'); } public function get() { $table = esc_sql( DB::get_table_name( 'submission' ) ); $ID = esc_sql( $this->ID ); $discount_query = /** @lang sql */ "SELECT SUM(`discount`) FROM `{$table}_partner` WHERE `submission_ID` = {$ID}"; $query = /** @lang sql */ "SELECT *, ({$discount_query}) as `discount` FROM `{$table}` WHERE `ID` = {$ID}"; $submission = $this->db->get_row( $query, ARRAY_A ); if ( $submission ) { $submission['added'] = date( "{$this->date_format} {$this->time_format}", strtotime( $submission['added'] ) ); $submission['name'] = "{$submission['prefix']} {$submission['first_name']} {$submission['last_name']}"; $submission['zip_city'] = implode( ' ', array_filter( [ $submission['zip'], $submission['city'] ] ) ); $submission['company_zip_city'] = implode( ' ', array_filter( [ $submission['company_zip'], $submission['company_city'] ] ) ); $submission['email_subscription'] = ( 'y' === $submission['email_subscription'] ) ? 'Yes' : 'No'; $submission['agree'] = ( 'y' === $submission['agree'] ) ? 'Yes' : 'No'; $query = /** @lang sql */ "SELECT * FROM `{$table}_partner` WHERE `submission_ID` = $ID ORDER BY `ID`"; $submission['partners'] = $this->db->get_results( $query, ARRAY_A ); $query = /** @lang sql */ "SELECT * FROM `{$table}_product` WHERE `submission_ID` = $ID ORDER BY `ID`"; $submission['products'] = $this->db->get_results( $query, ARRAY_A ); $query = /** @lang sql */ "SELECT * FROM `{$table}_person` WHERE `submission_ID` = $ID ORDER BY `ID`"; $submission['persons'] = $this->db->get_results( $query, ARRAY_A ); if ( $submission['persons'] ) { foreach ( $submission['persons'] as &$person ) { $person['name'] = "{$person['prefix']} {$person['first_name']} {$person['last_name']}"; $person['zip_city'] = "{$person['zip']} {$person['city']}"; $person['birth_date'] = date( $this->date_format, strtotime( $person['birth_date'] ) ); if ( 'company' == $person['type'] ) { $person['company_zip_city'] = "{$person['company_zip']} {$person['company_city']}"; } } unset( $person ); } } return $submission; } }