1 | <?php |
||
2 | /** |
||
3 | * Mollie customer query. |
||
4 | * |
||
5 | * @author Pronamic <[email protected]> |
||
6 | * @copyright 2005-2020 Pronamic |
||
7 | * @license GPL-3.0-or-later |
||
8 | * @package Pronamic\WordPress\Pay |
||
9 | */ |
||
10 | |||
11 | namespace Pronamic\WordPress\Pay\Gateways\Mollie; |
||
12 | |||
13 | /** |
||
14 | * Title: Mollie customer query |
||
15 | * Description: |
||
16 | * Copyright: 2005-2020 Pronamic |
||
17 | * Company: Pronamic |
||
18 | * |
||
19 | * @author Remco Tolsma |
||
20 | * @version 3.0.0 |
||
21 | * @since 3.0.0 |
||
22 | */ |
||
23 | class CustomerQuery { |
||
24 | /** |
||
25 | * Construct customer query. |
||
26 | * |
||
27 | * @param array $args Query arguments. |
||
28 | */ |
||
29 | public function __construct( $args = array() ) { |
||
30 | $this->args = \wp_parse_args( |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
31 | $args, |
||
32 | array( |
||
33 | 'user_id' => null, |
||
34 | 'organization_id' => null, |
||
35 | ) |
||
36 | ); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Get customers. |
||
41 | * |
||
42 | * @return array |
||
43 | */ |
||
44 | public function get_customers() { |
||
45 | global $wpdb; |
||
46 | |||
47 | $where = '1 = 1'; |
||
48 | |||
49 | if ( array_key_exists( 'user_id', $this->args ) ) { |
||
50 | $where .= $wpdb->prepare( ' AND mollie_customer_user.user_id = %d', $this->args['user_id'] ); |
||
51 | } |
||
52 | |||
53 | $query = " |
||
54 | SELECT |
||
55 | mollie_customer.mollie_id, |
||
56 | mollie_customer.test_mode, |
||
57 | mollie_customer.name, |
||
58 | mollie_customer.email |
||
59 | FROM |
||
60 | $wpdb->pronamic_pay_mollie_customer_users AS mollie_customer_user |
||
61 | INNER JOIN |
||
62 | $wpdb->pronamic_pay_mollie_customers AS mollie_customer |
||
63 | ON mollie_customer_user.customer_id = mollie_customer.id |
||
64 | WHERE |
||
65 | $where |
||
66 | ; |
||
67 | "; |
||
68 | |||
69 | return $wpdb->get_results( $query ); |
||
70 | } |
||
71 | } |
||
72 |