PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.4.7
JetFormBuilder — Dynamic Blocks Form Builder v3.4.7
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / gateways / query-views / payment-view.php
jetformbuilder / modules / gateways / query-views Last commit date
payer-view.php 2 years ago payment-by-record.php 2 years ago payment-count-view.php 2 years ago payment-for-export-view.php 2 years ago payment-view.php 2 years ago payment-with-record-view.php 2 years ago
payment-view.php
133 lines
1 <?php
2
3
4 namespace JFB_Modules\Gateways\Query_Views;
5
6 use Jet_Form_Builder\Classes\Tools;
7 use Jet_Form_Builder\Db_Queries\Query_Builder;
8 use Jet_Form_Builder\Db_Queries\Query_Conditions_Builder;
9 use Jet_Form_Builder\Db_Queries\Views\View_Base;
10 use JFB_Modules\Gateways\Db_Models\Payer_Model;
11 use JFB_Modules\Gateways\Db_Models\Payer_Shipping_Model;
12 use JFB_Modules\Gateways\Db_Models\Payment_Model;
13 use JFB_Modules\Gateways\Db_Models\Payment_To_Payer_Shipping_Model;
14 use JFB_Modules\Gateways\Db_Models\Payment_To_Record;
15
16 // If this file is called directly, abort.
17 if ( ! defined( 'WPINC' ) ) {
18 die;
19 }
20
21 class Payment_View extends View_Base {
22
23 /**
24 * @since 3.1.0
25 */
26 const AVAILABLE_STATUSES = array(
27 'COMPLETED',
28 'VOIDED',
29 );
30
31 protected $with_record = false;
32
33 public function __construct() {
34 $this->set_select(
35 array_merge(
36 Payment_Model::schema_columns(),
37 Payer_Shipping_Model::schema_columns( 'ship' ),
38 Payer_Model::schema_columns( 'payer' )
39 )
40 );
41 }
42
43 protected $order_by = array(
44 array(
45 'column' => 'id',
46 'sort' => self::FROM_HIGH_TO_LOW,
47 ),
48 );
49
50 public function set_filters( array $filters ) {
51 parent::set_filters( $filters );
52
53 $this->set_status_filter();
54
55 return $this;
56 }
57
58 protected function set_status_filter() {
59 $status = $this->filters['status'] ?? '';
60
61 if ( ! in_array( $status, self::AVAILABLE_STATUSES, true ) ) {
62 return;
63 }
64
65 $is_completed = 'COMPLETED' === $status;
66
67 $this->add_conditions(
68 array(
69 array(
70 'type' => $is_completed
71 ? Query_Conditions_Builder::TYPE_EQUAL
72 : Query_Conditions_Builder::TYPE_NOT_EQUAL,
73 'values' => array( 'status', 'COMPLETED' ),
74 ),
75 )
76 );
77 }
78
79 /**
80 * @param Query_Builder $builder
81 */
82 public function get_prepared_join( Query_Builder $builder ) {
83 $payments_to_p_ships = ( new Payment_To_Payer_Shipping_Model() )->create()::table();
84 $payers = ( new Payer_Model() )->create()::table();
85 $payments = Payment_Model::table();
86 $payers_ship = Payer_Shipping_Model::table();
87
88 $builder->join = "
89 LEFT JOIN `{$payments_to_p_ships}` ON 1=1
90 AND `{$payments}`.`id` = `{$payments_to_p_ships}`.`payment_id`
91
92 LEFT JOIN `{$payers_ship}` ON 1=1
93 AND {$payers_ship}.`id` = `{$payments_to_p_ships}`.`payer_shipping_id`
94
95 LEFT JOIN `{$payers}` ON 1=1
96 AND `{$payers}`.`id` = `{$payers_ship}`.`payer_id`
97 ";
98
99 if ( ! $this->with_record ) {
100 return;
101 }
102
103 $payment_to_record = ( new Payment_To_Record() )->create()::table();
104
105 $builder->join .= "
106 LEFT JOIN `{$payment_to_record}` ON 1=1
107 AND `$payment_to_record`.`payment_id` = `{$payments}`.`id`
108 ";
109 }
110
111 public function table(): string {
112 return Payment_Model::table();
113 }
114
115 public function set_payment_id( $payment_id ) {
116 $this->set_conditions(
117 static::prepare_columns(
118 array(
119 'id' => $payment_id,
120 )
121 )
122 );
123 }
124
125 /**
126 * @param bool $with_record
127 */
128 public function set_with_record( bool $with_record ) {
129 $this->with_record = $with_record;
130 }
131
132 }
133