Completed
Branch FET-9795-new-interfaces (ea072c)
by
unknown
51:56 queued 35:16
created
caffeinated/payment_methods/Paypal_Pro/EE_PMT_Paypal_Pro.pm.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (!defined('EVENT_ESPRESSO_VERSION'))
3
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
4 4
 	exit('No direct script access allowed');
5 5
 
6 6
 /**
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  *
26 26
  * ------------------------------------------------------------------------
27 27
  */
28
-class EE_PMT_Paypal_Pro extends EE_PMT_Base{
28
+class EE_PMT_Paypal_Pro extends EE_PMT_Base {
29 29
 
30 30
 	/**
31 31
 	 * @param EE_Payment_Method $pm_instance
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 		require_once($this->file_folder().'EEG_Paypal_Pro.gateway.php');
36 36
 		$this->_gateway = new EEG_Paypal_Pro();
37 37
 		$this->_pretty_name = __("Paypal Pro", 'event_espresso');
38
-		$this->_default_description = __( 'Please provide the following billing information.', 'event_espresso' );
38
+		$this->_default_description = __('Please provide the following billing information.', 'event_espresso');
39 39
 		$this->_requires_https = true;
40 40
 		parent::__construct($pm_instance);
41 41
 	}
@@ -51,21 +51,21 @@  discard block
 block discarded – undo
51 51
 			'extra_meta_inputs'=>array(
52 52
 //				'paypal_email'=>new EE_Email_Input(), not actually used
53 53
 				'username'=>new EE_Text_Input(array(
54
-					'html_label_text'=>  sprintf(__("Paypal API Username %s", "event_espresso"),$this->get_help_tab_link()),
54
+					'html_label_text'=>  sprintf(__("Paypal API Username %s", "event_espresso"), $this->get_help_tab_link()),
55 55
 					'required' => true
56 56
 				)),
57 57
 				'password'=>new EE_Text_Input(array(
58
-					'html_label_text'=>  sprintf(__("Paypal API Password %s", "event_espresso"),$this->get_help_tab_link()),
58
+					'html_label_text'=>  sprintf(__("Paypal API Password %s", "event_espresso"), $this->get_help_tab_link()),
59 59
 					'required' => true
60 60
 				)),
61 61
 				'signature'=>new EE_Text_Input(array(
62
-					'html_label_text'=>  sprintf(__("Paypal API Signature %s", "event_espresso"),$this->get_help_tab_link()),
62
+					'html_label_text'=>  sprintf(__("Paypal API Signature %s", "event_espresso"), $this->get_help_tab_link()),
63 63
 					'required' => true
64 64
 				)),
65 65
 				'credit_card_types'=>new EE_Checkbox_Multi_Input(
66 66
 						$this->card_types_supported(),
67 67
 						array(
68
-							'html_label_text' => __( 'Card Types Supported', 'event_espresso' ),
68
+							'html_label_text' => __('Card Types Supported', 'event_espresso'),
69 69
 							'required' => true )),
70 70
 				)
71 71
 			)
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
 	 * @throws \EE_Error
80 80
 	 * @return EE_Billing_Info_Form
81 81
 	 */
82
-	public function generate_new_billing_form( EE_Transaction $transaction = NULL ) {
83
-		$allowed_types = $this->_pm_instance->get_extra_meta( 'credit_card_types', TRUE );
82
+	public function generate_new_billing_form(EE_Transaction $transaction = NULL) {
83
+		$allowed_types = $this->_pm_instance->get_extra_meta('credit_card_types', TRUE);
84 84
 		//if allowed types is a string or empty array or null...
85
-		if( empty( $allowed_types )) {
85
+		if (empty($allowed_types)) {
86 86
 			$allowed_types = array();
87 87
 		}
88 88
 
@@ -93,26 +93,26 @@  discard block
 block discarded – undo
93 93
 //				'html_id'=> 'ee-Paypal_Pro-billing-form',
94 94
 				'subsections'=>array(
95 95
 					'credit_card'=>new EE_Credit_Card_Input(
96
-						array( 'required'=>TRUE, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __( 'Card Number', 'event_espresso' ))
96
+						array('required'=>TRUE, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Number', 'event_espresso'))
97 97
 					),
98 98
 					'credit_card_type'=>new EE_Select_Input(
99 99
 						//the options are set dynamically
100
-						array_intersect_key( EE_PMT_Paypal_Pro::card_types_supported(), array_flip( $allowed_types )),
101
-						array( 'required'=>TRUE, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __( 'Card Type', 'event_espresso' ))
100
+						array_intersect_key(EE_PMT_Paypal_Pro::card_types_supported(), array_flip($allowed_types)),
101
+						array('required'=>TRUE, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Type', 'event_espresso'))
102 102
 					),
103 103
 					'exp_month'=>new EE_Credit_Card_Month_Input(
104
-						TRUE, array( 'required'=>TRUE, 'html_class' => 'ee-billing-qstn', 'html_label_text' =>  __( 'Expiry Month', 'event_espresso' )  )
104
+						TRUE, array('required'=>TRUE, 'html_class' => 'ee-billing-qstn', 'html_label_text' =>  __('Expiry Month', 'event_espresso'))
105 105
 					),
106 106
 					'exp_year'=>new EE_Credit_Card_Year_Input(
107
-						array( 'required'=>TRUE, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __( 'Expiry Year', 'event_espresso' )  )
107
+						array('required'=>TRUE, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Year', 'event_espresso'))
108 108
 					),
109 109
 					'cvv'=>new EE_CVV_Input(
110
-						array( 'required'=>TRUE, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __( 'CVV', 'event_espresso' ) )
110
+						array('required'=>TRUE, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('CVV', 'event_espresso'))
111 111
 					),
112 112
 				)
113 113
 			)
114 114
 		);
115
-		return $this->apply_billing_form_debug_settings( $billing_form );
115
+		return $this->apply_billing_form_debug_settings($billing_form);
116 116
 	}
117 117
 
118 118
 
@@ -124,19 +124,19 @@  discard block
 block discarded – undo
124 124
 	 * @param \EE_Billing_Info_Form $billing_form
125 125
 	 * @return \EE_Billing_Info_Form
126 126
 	 */
127
-	public function apply_billing_form_debug_settings( EE_Billing_Info_Form $billing_form ) {
128
-		if ( $this->_pm_instance->debug_mode() ) {
127
+	public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) {
128
+		if ($this->_pm_instance->debug_mode()) {
129 129
 			$billing_form->add_subsections(
130
-				array( 'fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html() ),
130
+				array('fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html()),
131 131
 				'credit_card'
132 132
 			);
133 133
 			$billing_form->add_subsections(
134
-				array( 'debug_content' => new EE_Form_Section_HTML_From_Template( dirname(__FILE__).DS.'templates'.DS.'paypal_pro_debug_info.template.php' )),
134
+				array('debug_content' => new EE_Form_Section_HTML_From_Template(dirname(__FILE__).DS.'templates'.DS.'paypal_pro_debug_info.template.php')),
135 135
 				'first_name'
136 136
 			);
137
-			$billing_form->get_input( 'credit_card_type' )->set_default( 'Visa' );
138
-			$billing_form->get_input( 'exp_year' )->set_default( 2018);
139
-			$billing_form->get_input( 'cvv' )->set_default( '115' );
137
+			$billing_form->get_input('credit_card_type')->set_default('Visa');
138
+			$billing_form->get_input('exp_year')->set_default(2018);
139
+			$billing_form->get_input('cvv')->set_default('115');
140 140
 		}
141 141
 		return $billing_form;
142 142
 	}
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	 * Keys are their values, values are their pretty names.
149 149
 	 * @return array
150 150
 	 */
151
-	public static function card_types_supported(){
151
+	public static function card_types_supported() {
152 152
 		return array(
153 153
 			'Visa'=>  __("Visa", 'event_espresso'),
154 154
 			'MasterCard'=>  __("MasterCard", 'event_espresso'),
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	 * @see EE_PMT_Base::help_tabs_config()
165 165
 	 * @return array
166 166
 	 */
167
-	public function help_tabs_config(){
167
+	public function help_tabs_config() {
168 168
 		return array(
169 169
 			$this->get_help_tab_name() => array(
170 170
 						'title' => __('PayPal Pro Settings', 'event_espresso'),
@@ -179,10 +179,10 @@  discard block
 block discarded – undo
179 179
 	 * @param EE_Billing_Info_Form $billing_form
180 180
 	 * @return array
181 181
 	 */
182
-	protected function _get_billing_values_from_form( $billing_form ){
183
-		$billing_values = parent::_get_billing_values_from_form( $billing_form );
184
-		$billing_values[ 'country' ] = $billing_form->get_input_value( 'country' );
185
-		$billing_values[ 'credit_card_type' ] = $billing_form->get_input_value( 'credit_card_type' );
182
+	protected function _get_billing_values_from_form($billing_form) {
183
+		$billing_values = parent::_get_billing_values_from_form($billing_form);
184
+		$billing_values['country'] = $billing_form->get_input_value('country');
185
+		$billing_values['credit_card_type'] = $billing_form->get_input_value('credit_card_type');
186 186
 		return $billing_values;
187 187
 	}
188 188
 
Please login to merge, or discard this patch.
core/domain/services/registration/CreateRegistrationService.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@
 block discarded – undo
29 29
      * @param \EE_Transaction $transaction
30 30
      * @param \EE_Ticket      $ticket
31 31
      * @param \EE_Line_Item   $ticket_line_item
32
-     * @param                 $reg_count
33
-     * @param                 $reg_group_size
32
+     * @param                 integer $reg_count
33
+     * @param                 integer $reg_group_size
34 34
      * @return \EE_Registration
35 35
      * @throws \EE_Error
36 36
      * @throws UnexpectedEntityException
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@
 block discarded – undo
92 92
             $ticket_line_item
93 93
         );
94 94
         $final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes();
95
-        return (float)$final_price;
95
+        return (float) $final_price;
96 96
     }
97 97
 
98 98
 
Please login to merge, or discard this patch.
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use EventEspresso\core\exceptions\UnexpectedEntityException;
8 8
 
9 9
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
10
-    exit('No direct script access allowed');
10
+	exit('No direct script access allowed');
11 11
 }
12 12
 
13 13
 
@@ -24,97 +24,97 @@  discard block
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * @param \EE_Event       $event
29
-     * @param \EE_Transaction $transaction
30
-     * @param \EE_Ticket      $ticket
31
-     * @param \EE_Line_Item   $ticket_line_item
32
-     * @param                 $reg_count
33
-     * @param                 $reg_group_size
34
-     * @return \EE_Registration
35
-     * @throws \EE_Error
36
-     * @throws UnexpectedEntityException
37
-     */
38
-    public function create(
39
-        \EE_Event $event,
40
-        \EE_Transaction $transaction,
41
-        \EE_Ticket $ticket,
42
-        \EE_Line_Item $ticket_line_item,
43
-        $reg_count,
44
-        $reg_group_size
45
-    ) {
46
-        $registrations = $transaction->registrations();
47
-        $reg_count = $reg_count ? $reg_count : count($registrations) + 1;
48
-        $reg_url_link = new RegUrlLink($reg_count, $ticket_line_item);
49
-        $reg_code = new RegCode($reg_url_link, $transaction, $ticket);
50
-        // generate new EE_Registration
51
-        $registration = \EE_Registration::new_instance(
52
-            array(
53
-                'EVT_ID'          => $event->ID(),
54
-                'TXN_ID'          => $transaction->ID(),
55
-                'TKT_ID'          => $ticket->ID(),
56
-                'STS_ID'          => \EEM_Registration::status_id_incomplete,
57
-                'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item),
58
-                'REG_session'     => \EE_Registry::instance()->SSN->id(),
59
-                'REG_count'       => $reg_count,
60
-                'REG_group_size'  => $reg_group_size ? $reg_group_size : $this->incrementRegCount($registrations),
61
-                'REG_url_link'    => $reg_url_link,
62
-                'REG_code'        => $reg_code,
63
-            )
64
-        );
65
-        if ( ! $registration instanceof \EE_Registration) {
66
-            throw new UnexpectedEntityException($registration, 'EE_Registration');
67
-        }
68
-        $registration->save();
69
-        $registration->_add_relation_to($event, 'Event', array(), $event->ID());
70
-        $registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID());
71
-        $transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID());
72
-        $registration->save();
73
-        return $registration;
74
-    }
27
+	/**
28
+	 * @param \EE_Event       $event
29
+	 * @param \EE_Transaction $transaction
30
+	 * @param \EE_Ticket      $ticket
31
+	 * @param \EE_Line_Item   $ticket_line_item
32
+	 * @param                 $reg_count
33
+	 * @param                 $reg_group_size
34
+	 * @return \EE_Registration
35
+	 * @throws \EE_Error
36
+	 * @throws UnexpectedEntityException
37
+	 */
38
+	public function create(
39
+		\EE_Event $event,
40
+		\EE_Transaction $transaction,
41
+		\EE_Ticket $ticket,
42
+		\EE_Line_Item $ticket_line_item,
43
+		$reg_count,
44
+		$reg_group_size
45
+	) {
46
+		$registrations = $transaction->registrations();
47
+		$reg_count = $reg_count ? $reg_count : count($registrations) + 1;
48
+		$reg_url_link = new RegUrlLink($reg_count, $ticket_line_item);
49
+		$reg_code = new RegCode($reg_url_link, $transaction, $ticket);
50
+		// generate new EE_Registration
51
+		$registration = \EE_Registration::new_instance(
52
+			array(
53
+				'EVT_ID'          => $event->ID(),
54
+				'TXN_ID'          => $transaction->ID(),
55
+				'TKT_ID'          => $ticket->ID(),
56
+				'STS_ID'          => \EEM_Registration::status_id_incomplete,
57
+				'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item),
58
+				'REG_session'     => \EE_Registry::instance()->SSN->id(),
59
+				'REG_count'       => $reg_count,
60
+				'REG_group_size'  => $reg_group_size ? $reg_group_size : $this->incrementRegCount($registrations),
61
+				'REG_url_link'    => $reg_url_link,
62
+				'REG_code'        => $reg_code,
63
+			)
64
+		);
65
+		if ( ! $registration instanceof \EE_Registration) {
66
+			throw new UnexpectedEntityException($registration, 'EE_Registration');
67
+		}
68
+		$registration->save();
69
+		$registration->_add_relation_to($event, 'Event', array(), $event->ID());
70
+		$registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID());
71
+		$transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID());
72
+		$registration->save();
73
+		return $registration;
74
+	}
75 75
 
76 76
 
77 77
 
78
-    /**
79
-     * @param \EE_Transaction $transaction
80
-     * @param \EE_Ticket      $ticket
81
-     * @param \EE_Line_Item   $ticket_line_item
82
-     * @return float
83
-     */
84
-    protected function resolveFinalPrice(
85
-        \EE_Transaction $transaction,
86
-        \EE_Ticket $ticket,
87
-        \EE_Line_Item $ticket_line_item
88
-    ) {
89
-        $final_price = \EEH_Line_Item::calculate_final_price_for_ticket_line_item(
90
-            $transaction->total_line_item(),
91
-            $ticket_line_item
92
-        );
93
-        $final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes();
94
-        return (float)$final_price;
95
-    }
78
+	/**
79
+	 * @param \EE_Transaction $transaction
80
+	 * @param \EE_Ticket      $ticket
81
+	 * @param \EE_Line_Item   $ticket_line_item
82
+	 * @return float
83
+	 */
84
+	protected function resolveFinalPrice(
85
+		\EE_Transaction $transaction,
86
+		\EE_Ticket $ticket,
87
+		\EE_Line_Item $ticket_line_item
88
+	) {
89
+		$final_price = \EEH_Line_Item::calculate_final_price_for_ticket_line_item(
90
+			$transaction->total_line_item(),
91
+			$ticket_line_item
92
+		);
93
+		$final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes();
94
+		return (float)$final_price;
95
+	}
96 96
 
97 97
 
98 98
 
99
-    /**
100
-     * @param  \EE_Registration[] $registrations
101
-     * @param  boolean            $update_existing_registrations
102
-     * @return int
103
-     * @throws \EE_Error
104
-     */
105
-    protected function incrementRegCount(array $registrations, $update_existing_registrations = true)
106
-    {
107
-        $new_reg_count = count($registrations) + 1;
108
-        if ($update_existing_registrations) {
109
-            foreach ($registrations as $registration) {
110
-                if ($registration instanceof \EE_Registration) {
111
-                    $registration->set_count($new_reg_count);
112
-                    $registration->save();
113
-                }
114
-            }
115
-        }
116
-        return $new_reg_count;
117
-    }
99
+	/**
100
+	 * @param  \EE_Registration[] $registrations
101
+	 * @param  boolean            $update_existing_registrations
102
+	 * @return int
103
+	 * @throws \EE_Error
104
+	 */
105
+	protected function incrementRegCount(array $registrations, $update_existing_registrations = true)
106
+	{
107
+		$new_reg_count = count($registrations) + 1;
108
+		if ($update_existing_registrations) {
109
+			foreach ($registrations as $registration) {
110
+				if ($registration instanceof \EE_Registration) {
111
+					$registration->set_count($new_reg_count);
112
+					$registration->save();
113
+				}
114
+			}
115
+		}
116
+		return $new_reg_count;
117
+	}
118 118
 
119 119
 
120 120
 }
Please login to merge, or discard this patch.
core/domain/services/DomainService.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
3
-	exit( 'No direct script access allowed' );
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 /**
6 6
  * Class EE_Line_Item_Filter_Collection
Please login to merge, or discard this patch.
core/domain/services/ticket/CreateTicketLineItemService.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\UnexpectedEntityException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('No direct script access allowed');
8
+	exit('No direct script access allowed');
9 9
 }
10 10
 
11 11
 
@@ -21,39 +21,39 @@  discard block
 block discarded – undo
21 21
 class CreateTicketLineItemService extends DomainService
22 22
 {
23 23
 
24
-    /**
25
-     * @param \EE_Transaction $transaction
26
-     * @param \EE_Ticket      $ticket
27
-     * @param int             $quantity
28
-     * @return \EE_Line_Item
29
-     * @throws \EE_Error
30
-     * @throws UnexpectedEntityException
31
-     */
32
-    public function create(
33
-        \EE_Transaction $transaction,
34
-        \EE_Ticket $ticket,
35
-        $quantity = 1
36
-    )
37
-    {
38
-        // create new line item for ticket
39
-        $ticket_line_item = \EEH_Line_Item::add_ticket_purchase(
40
-            $transaction->total_line_item(),
41
-            $ticket,
42
-            $quantity
43
-        );
44
-        if ( ! $ticket_line_item instanceof \EE_Line_Item) {
45
-            throw new UnexpectedEntityException($ticket_line_item, 'EE_Line_Item');
46
-        }
47
-        // apply any applicable promotions that were initially used during registration to new line items
48
-        do_action(
49
-            'AHEE__\EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler__handle__new_ticket_line_item_added',
50
-            $transaction->total_line_item(),
51
-            $ticket,
52
-            $transaction,
53
-            $quantity
54
-        );
55
-        return $ticket_line_item;
56
-    }
24
+	/**
25
+	 * @param \EE_Transaction $transaction
26
+	 * @param \EE_Ticket      $ticket
27
+	 * @param int             $quantity
28
+	 * @return \EE_Line_Item
29
+	 * @throws \EE_Error
30
+	 * @throws UnexpectedEntityException
31
+	 */
32
+	public function create(
33
+		\EE_Transaction $transaction,
34
+		\EE_Ticket $ticket,
35
+		$quantity = 1
36
+	)
37
+	{
38
+		// create new line item for ticket
39
+		$ticket_line_item = \EEH_Line_Item::add_ticket_purchase(
40
+			$transaction->total_line_item(),
41
+			$ticket,
42
+			$quantity
43
+		);
44
+		if ( ! $ticket_line_item instanceof \EE_Line_Item) {
45
+			throw new UnexpectedEntityException($ticket_line_item, 'EE_Line_Item');
46
+		}
47
+		// apply any applicable promotions that were initially used during registration to new line items
48
+		do_action(
49
+			'AHEE__\EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler__handle__new_ticket_line_item_added',
50
+			$transaction->total_line_item(),
51
+			$ticket,
52
+			$transaction,
53
+			$quantity
54
+		);
55
+		return $ticket_line_item;
56
+	}
57 57
 
58 58
 
59 59
 
Please login to merge, or discard this patch.
core/domain/services/ticket/CancelTicketLineItemService.php 2 patches
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\EntityNotFoundException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('No direct script access allowed');
8
+	exit('No direct script access allowed');
9 9
 }
10 10
 
11 11
 
@@ -25,116 +25,116 @@  discard block
 block discarded – undo
25 25
 {
26 26
 
27 27
 
28
-    /**
29
-     * @param \EE_Registration $registration
30
-     * @param int              $quantity
31
-     * @return bool|int
32
-     */
33
-    public function forRegistration(\EE_Registration $registration,$quantity = 1) {
34
-        return $this->cancel(
35
-            $registration->transaction(),
36
-            $registration->ticket(),
37
-            $quantity,
38
-            $registration->ticket_line_item()
39
-        );
40
-    }
28
+	/**
29
+	 * @param \EE_Registration $registration
30
+	 * @param int              $quantity
31
+	 * @return bool|int
32
+	 */
33
+	public function forRegistration(\EE_Registration $registration,$quantity = 1) {
34
+		return $this->cancel(
35
+			$registration->transaction(),
36
+			$registration->ticket(),
37
+			$quantity,
38
+			$registration->ticket_line_item()
39
+		);
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * @param \EE_Transaction $transaction
45
-     * @param \EE_Ticket      $ticket
46
-     * @param int             $quantity
47
-     * @param \EE_Line_Item   $ticket_line_item
48
-     * @return bool|int
49
-     */
50
-    public function cancel(
51
-        \EE_Transaction $transaction,
52
-        \EE_Ticket $ticket,
53
-        $quantity = 1,
54
-        \EE_Line_Item $ticket_line_item = null
55
-    ) {
56
-        $ticket_line_item = $ticket_line_item instanceof \EE_Line_Item
57
-            ? $ticket_line_item
58
-            : $this->getTicketLineItem($transaction, $ticket);
59
-        // first we need to decrement the ticket quantity
60
-        \EEH_Line_Item::decrement_quantity($ticket_line_item, $quantity);
61
-        // no tickets left for this line item ?
62
-        if ((int)$ticket_line_item->quantity() === 0) {
63
-            // then just set this line item as cancelled, save, and get out
64
-            $ticket_line_item->set_type(\EEM_Line_Item::type_cancellation);
65
-            $success = $ticket_line_item->save();
66
-        } else {
67
-            // otherwise create a new cancelled line item, so that we have a record of the cancellation
68
-            $items_subtotal = \EEH_Line_Item::get_pre_tax_subtotal(
69
-                \EEH_Line_Item::get_event_line_item_for_ticket(
70
-                    $transaction->total_line_item(),
71
-                    $ticket
72
-                )
73
-            );
74
-            $cancelled_line_item = \EE_Line_Item::new_instance(
75
-                array(
76
-                    'LIN_name'       => $ticket_line_item->name(),
77
-                    'LIN_desc'       => sprintf(
78
-                        __('%1$s Cancelled: %2$s', 'event_espresso'),
79
-                        $ticket_line_item->desc(),
80
-                        date('Y-m-d h:i a')
81
-                    ),
82
-                    'LIN_unit_price' => (float)$ticket_line_item->unit_price(),
83
-                    'LIN_quantity'   => $quantity,
84
-                    'LIN_percent'    => null,
85
-                    'LIN_is_taxable' => false,
86
-                    'LIN_order'      => $items_subtotal instanceof \EE_Line_Item
87
-                        ? count($items_subtotal->children())
88
-                        : 0,
89
-                    'LIN_total'      => (float)$ticket_line_item->unit_price(),
90
-                    'LIN_type'       => \EEM_Line_Item::type_cancellation
91
-                )
92
-            );
93
-            $success = \EEH_Line_Item::add_item($transaction->total_line_item(), $cancelled_line_item);
94
-        }
95
-        if ( ! $success) {
96
-            throw new \RuntimeException(
97
-                sprintf(
98
-                    __('An error occurred while attempting to cancel ticket line item %1$s', 'event_espresso'),
99
-                    $ticket_line_item->ID()
100
-                )
101
-            );
102
-        }
103
-        return $success;
104
-    }
43
+	/**
44
+	 * @param \EE_Transaction $transaction
45
+	 * @param \EE_Ticket      $ticket
46
+	 * @param int             $quantity
47
+	 * @param \EE_Line_Item   $ticket_line_item
48
+	 * @return bool|int
49
+	 */
50
+	public function cancel(
51
+		\EE_Transaction $transaction,
52
+		\EE_Ticket $ticket,
53
+		$quantity = 1,
54
+		\EE_Line_Item $ticket_line_item = null
55
+	) {
56
+		$ticket_line_item = $ticket_line_item instanceof \EE_Line_Item
57
+			? $ticket_line_item
58
+			: $this->getTicketLineItem($transaction, $ticket);
59
+		// first we need to decrement the ticket quantity
60
+		\EEH_Line_Item::decrement_quantity($ticket_line_item, $quantity);
61
+		// no tickets left for this line item ?
62
+		if ((int)$ticket_line_item->quantity() === 0) {
63
+			// then just set this line item as cancelled, save, and get out
64
+			$ticket_line_item->set_type(\EEM_Line_Item::type_cancellation);
65
+			$success = $ticket_line_item->save();
66
+		} else {
67
+			// otherwise create a new cancelled line item, so that we have a record of the cancellation
68
+			$items_subtotal = \EEH_Line_Item::get_pre_tax_subtotal(
69
+				\EEH_Line_Item::get_event_line_item_for_ticket(
70
+					$transaction->total_line_item(),
71
+					$ticket
72
+				)
73
+			);
74
+			$cancelled_line_item = \EE_Line_Item::new_instance(
75
+				array(
76
+					'LIN_name'       => $ticket_line_item->name(),
77
+					'LIN_desc'       => sprintf(
78
+						__('%1$s Cancelled: %2$s', 'event_espresso'),
79
+						$ticket_line_item->desc(),
80
+						date('Y-m-d h:i a')
81
+					),
82
+					'LIN_unit_price' => (float)$ticket_line_item->unit_price(),
83
+					'LIN_quantity'   => $quantity,
84
+					'LIN_percent'    => null,
85
+					'LIN_is_taxable' => false,
86
+					'LIN_order'      => $items_subtotal instanceof \EE_Line_Item
87
+						? count($items_subtotal->children())
88
+						: 0,
89
+					'LIN_total'      => (float)$ticket_line_item->unit_price(),
90
+					'LIN_type'       => \EEM_Line_Item::type_cancellation
91
+				)
92
+			);
93
+			$success = \EEH_Line_Item::add_item($transaction->total_line_item(), $cancelled_line_item);
94
+		}
95
+		if ( ! $success) {
96
+			throw new \RuntimeException(
97
+				sprintf(
98
+					__('An error occurred while attempting to cancel ticket line item %1$s', 'event_espresso'),
99
+					$ticket_line_item->ID()
100
+				)
101
+			);
102
+		}
103
+		return $success;
104
+	}
105 105
 
106 106
 
107 107
 
108
-    /**
109
-     * @param \EE_Transaction $transaction
110
-     * @param \EE_Ticket      $ticket
111
-     * @return \EE_Line_Item
112
-     * @throws EntityNotFoundException
113
-     * @throws \EE_Error
114
-     */
115
-    protected static function getTicketLineItem(\EE_Transaction $transaction, \EE_Ticket $ticket)
116
-    {
117
-        $line_item = null;
118
-        $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
119
-            $transaction->total_line_item(),
120
-            'Ticket',
121
-            array($ticket->ID())
122
-        );
123
-        foreach ($ticket_line_items as $ticket_line_item) {
124
-            if (
125
-                $ticket_line_item instanceof \EE_Line_Item
126
-                && $ticket_line_item->OBJ_type() === 'Ticket'
127
-                && $ticket_line_item->OBJ_ID() === $ticket->ID()
128
-            ) {
129
-                $line_item = $ticket_line_item;
130
-                break;
131
-            }
132
-        }
133
-        if ( ! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
134
-            throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
135
-        }
136
-        return $line_item;
137
-    }
108
+	/**
109
+	 * @param \EE_Transaction $transaction
110
+	 * @param \EE_Ticket      $ticket
111
+	 * @return \EE_Line_Item
112
+	 * @throws EntityNotFoundException
113
+	 * @throws \EE_Error
114
+	 */
115
+	protected static function getTicketLineItem(\EE_Transaction $transaction, \EE_Ticket $ticket)
116
+	{
117
+		$line_item = null;
118
+		$ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
119
+			$transaction->total_line_item(),
120
+			'Ticket',
121
+			array($ticket->ID())
122
+		);
123
+		foreach ($ticket_line_items as $ticket_line_item) {
124
+			if (
125
+				$ticket_line_item instanceof \EE_Line_Item
126
+				&& $ticket_line_item->OBJ_type() === 'Ticket'
127
+				&& $ticket_line_item->OBJ_ID() === $ticket->ID()
128
+			) {
129
+				$line_item = $ticket_line_item;
130
+				break;
131
+			}
132
+		}
133
+		if ( ! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
134
+			throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
135
+		}
136
+		return $line_item;
137
+	}
138 138
 
139 139
 
140 140
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      * @param int              $quantity
31 31
      * @return bool|int
32 32
      */
33
-    public function forRegistration(\EE_Registration $registration,$quantity = 1) {
33
+    public function forRegistration(\EE_Registration $registration, $quantity = 1) {
34 34
         return $this->cancel(
35 35
             $registration->transaction(),
36 36
             $registration->ticket(),
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
         // first we need to decrement the ticket quantity
60 60
         \EEH_Line_Item::decrement_quantity($ticket_line_item, $quantity);
61 61
         // no tickets left for this line item ?
62
-        if ((int)$ticket_line_item->quantity() === 0) {
62
+        if ((int) $ticket_line_item->quantity() === 0) {
63 63
             // then just set this line item as cancelled, save, and get out
64 64
             $ticket_line_item->set_type(\EEM_Line_Item::type_cancellation);
65 65
             $success = $ticket_line_item->save();
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
                         $ticket_line_item->desc(),
80 80
                         date('Y-m-d h:i a')
81 81
                     ),
82
-                    'LIN_unit_price' => (float)$ticket_line_item->unit_price(),
82
+                    'LIN_unit_price' => (float) $ticket_line_item->unit_price(),
83 83
                     'LIN_quantity'   => $quantity,
84 84
                     'LIN_percent'    => null,
85 85
                     'LIN_is_taxable' => false,
86 86
                     'LIN_order'      => $items_subtotal instanceof \EE_Line_Item
87 87
                         ? count($items_subtotal->children())
88 88
                         : 0,
89
-                    'LIN_total'      => (float)$ticket_line_item->unit_price(),
89
+                    'LIN_total'      => (float) $ticket_line_item->unit_price(),
90 90
                     'LIN_type'       => \EEM_Line_Item::type_cancellation
91 91
                 )
92 92
             );
Please login to merge, or discard this patch.
core/domain/services/DomainServiceInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
3
-	exit( 'No direct script access allowed' );
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 /**
6 6
  * Class EE_Line_Item_Filter_Collection
Please login to merge, or discard this patch.
core/domain/services/registration/CancelRegistrationService.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\domain\services\ticket\CancelTicketLineItemService;
5 5
 
6 6
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -21,48 +21,48 @@  discard block
 block discarded – undo
21 21
 class CancelRegistrationService
22 22
 {
23 23
 
24
-    /**
25
-     * @var CancelTicketLineItemService $cancel_ticket_line_item_service
26
-     */
27
-    private $cancel_ticket_line_item_service;
24
+	/**
25
+	 * @var CancelTicketLineItemService $cancel_ticket_line_item_service
26
+	 */
27
+	private $cancel_ticket_line_item_service;
28 28
 
29 29
 
30 30
 
31
-    /**
32
-     * Command constructor
33
-     *
34
-     * @param CancelTicketLineItemService $cancel_ticket_line_item_service
35
-     */
36
-    public function __construct(CancelTicketLineItemService $cancel_ticket_line_item_service)
37
-    {
38
-        $this->cancel_ticket_line_item_service = $cancel_ticket_line_item_service;
39
-    }
31
+	/**
32
+	 * Command constructor
33
+	 *
34
+	 * @param CancelTicketLineItemService $cancel_ticket_line_item_service
35
+	 */
36
+	public function __construct(CancelTicketLineItemService $cancel_ticket_line_item_service)
37
+	{
38
+		$this->cancel_ticket_line_item_service = $cancel_ticket_line_item_service;
39
+	}
40 40
 
41 41
 
42 42
 
43
-    /**
44
-     * @param \EE_Registration $registration
45
-     * @throws \EE_Error
46
-     */
47
-    public function cancelRegistrationAndTicketLineItem(\EE_Registration $registration)
48
-    {
49
-        // first cancel the original line item for the registration's ticket
50
-        $this->cancel_ticket_line_item_service->forRegistration($registration);
51
-        $this->cancelRegistrationOnly($registration);
52
-    }
43
+	/**
44
+	 * @param \EE_Registration $registration
45
+	 * @throws \EE_Error
46
+	 */
47
+	public function cancelRegistrationAndTicketLineItem(\EE_Registration $registration)
48
+	{
49
+		// first cancel the original line item for the registration's ticket
50
+		$this->cancel_ticket_line_item_service->forRegistration($registration);
51
+		$this->cancelRegistrationOnly($registration);
52
+	}
53 53
 
54 54
 
55 55
 
56
-    /**
57
-     * @param \EE_Registration $registration
58
-     * @throws \EE_Error
59
-     */
60
-    public function cancelRegistrationOnly(\EE_Registration $registration)
61
-    {
62
-        // now cancel the registration itself
63
-        $registration->set_status(\EEM_Registration::status_id_cancelled);
64
-        $registration->save();
65
-    }
56
+	/**
57
+	 * @param \EE_Registration $registration
58
+	 * @throws \EE_Error
59
+	 */
60
+	public function cancelRegistrationOnly(\EE_Registration $registration)
61
+	{
62
+		// now cancel the registration itself
63
+		$registration->set_status(\EEM_Registration::status_id_cancelled);
64
+		$registration->save();
65
+	}
66 66
 
67 67
 
68 68
 
Please login to merge, or discard this patch.
core/domain/services/registration/UpdateRegistrationService.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\domain\services\DomainService;
5 5
 
6 6
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -20,24 +20,24 @@  discard block
 block discarded – undo
20 20
 class UpdateRegistrationService extends DomainService
21 21
 {
22 22
 
23
-    /**
24
-     * @param \EE_Registration $registration
25
-     * @return bool
26
-     */
27
-    public function updateRegistrationAndTransaction(\EE_Registration $registration)
28
-    {
29
-        $transaction = $registration->transaction();
30
-        // reset transaction status back to incomplete
31
-        $transaction->set_status(\EEM_Transaction::incomplete_status_code);
32
-        // update transaction and all line item totals and subtotals
33
-        $transaction->total_line_item()->recalculate_total_including_taxes();
34
-        // maybe update status, but don't save transaction just yet
35
-        $transaction->update_status_based_on_total_paid();
36
-        /** @type \EE_Registration_Processor $registration_processor */
37
-        $registration_processor = \EE_Registry::instance()->load_class('Registration_Processor');
38
-        $registration_processor->update_registration_status_and_trigger_notifications($registration);
39
-        return true;
40
-    }
23
+	/**
24
+	 * @param \EE_Registration $registration
25
+	 * @return bool
26
+	 */
27
+	public function updateRegistrationAndTransaction(\EE_Registration $registration)
28
+	{
29
+		$transaction = $registration->transaction();
30
+		// reset transaction status back to incomplete
31
+		$transaction->set_status(\EEM_Transaction::incomplete_status_code);
32
+		// update transaction and all line item totals and subtotals
33
+		$transaction->total_line_item()->recalculate_total_including_taxes();
34
+		// maybe update status, but don't save transaction just yet
35
+		$transaction->update_status_based_on_total_paid();
36
+		/** @type \EE_Registration_Processor $registration_processor */
37
+		$registration_processor = \EE_Registry::instance()->load_class('Registration_Processor');
38
+		$registration_processor->update_registration_status_and_trigger_notifications($registration);
39
+		return true;
40
+	}
41 41
 
42 42
 }
43 43
 // End of file UpdateRegistrationService.php
Please login to merge, or discard this patch.
core/domain/services/registration/CopyRegistrationService.php 2 patches
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\UnexpectedEntityException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('No direct script access allowed');
8
+	exit('No direct script access allowed');
9 9
 }
10 10
 
11 11
 
@@ -23,140 +23,140 @@  discard block
 block discarded – undo
23 23
 {
24 24
 
25 25
 
26
-    /**
27
-     * @param \EE_Registration $target_registration
28
-     * @param \EE_Registration $registration_to_copy
29
-     * @return bool
30
-     * @throws \EE_Error
31
-     */
32
-    public function copyRegistrationDetails(
33
-        \EE_Registration $target_registration,
34
-        \EE_Registration $registration_to_copy
35
-    ) {
36
-        // copy attendee
37
-        $target_registration->set_attendee_id($registration_to_copy->attendee_ID());
38
-        $target_registration->set_status( $registration_to_copy->status_ID() );
39
-        $target_registration->save();
40
-        // get answers to previous reg questions
41
-        $answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers());
42
-        // get questions to new event reg form
43
-        $new_event = $target_registration->event();
44
-        $question_groups = $new_event->question_groups(
45
-            array(
46
-                array(
47
-                    'Event.EVT_ID'                     => $new_event->ID(),
48
-                    'Event_Question_Group.EQG_primary' => $registration_to_copy->is_primary_registrant()
49
-                ),
50
-                'order_by' => array('QSG_order' => 'ASC')
51
-            )
52
-        );
53
-        foreach ($question_groups as $question_group) {
54
-            if ($question_group instanceof \EE_Question_Group) {
55
-                foreach ($question_group->questions() as $question) {
56
-                    if ($question instanceof \EE_Question) {
57
-                        $this->generateNewAnswer(
58
-                            $question,
59
-                            $target_registration,
60
-                            $answers
61
-                        );
62
-                    }
63
-                }
64
-            }
65
-        }
66
-        return true;
67
-    }
68
-
69
-
70
-
71
-    /**
72
-     * @param \EE_Answer[] $answers
73
-     * @return array
74
-     * @throws \EE_Error
75
-     */
76
-    protected static function reindexAnswersByQuestionId(array $answers)
77
-    {
78
-        $reindexed_answers = array();
79
-        foreach ($answers as $answer) {
80
-            if ($answer instanceof \EE_Answer) {
81
-                $reindexed_answers[$answer->question_ID()] = $answer->value();
82
-            }
83
-        }
84
-        return $reindexed_answers;
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     * @param \EE_Question     $question
91
-     * @param \EE_Registration $registration
92
-     * @param                  $previous_answers
93
-     * @return \EE_Answer
94
-     * @throws \EventEspresso\core\exceptions\UnexpectedEntityException
95
-     * @throws \EE_Error
96
-     */
97
-    protected static function generateNewAnswer(
98
-        \EE_Question $question,
99
-        \EE_Registration $registration,
100
-        $previous_answers
101
-    ) {
102
-        $old_answer_value = isset($previous_answers[$question->ID()])
103
-            ? $previous_answers[$question->ID()]
104
-            : '';
105
-        $new_answer = \EE_Answer::new_instance(
106
-            array(
107
-                'QST_ID'    => $question->ID(),
108
-                'REG_ID'    => $registration->ID(),
109
-                'ANS_value' => $old_answer_value,
110
-            )
111
-        );
112
-        if ( ! $new_answer instanceof \EE_Answer) {
113
-            throw new UnexpectedEntityException($new_answer, 'EE_Answer');
114
-        }
115
-        $new_answer->save();
116
-        return $new_answer;
117
-    }
118
-
119
-
120
-
121
-    /**
122
-     * @param \EE_Registration $target_registration
123
-     * @param \EE_Registration $registration_to_copy
124
-     * @return bool
125
-     * @throws \EE_Error
126
-     */
127
-    public function copyPaymentDetails(
128
-        \EE_Registration $target_registration,
129
-        \EE_Registration $registration_to_copy
130
-    ) {
131
-        $previous_payments = $registration_to_copy->registration_payments();
132
-        foreach ($previous_payments as $previous_payment) {
133
-            if (
134
-                $previous_payment instanceof \EE_Registration_Payment
135
-                && $previous_payment->payment() instanceof \EE_Payment
136
-                && $previous_payment->payment()->is_approved()
137
-            ) {
138
-                $new_registration_payment = \EE_Registration_Payment::new_instance(
139
-                    array(
140
-                        'REG_ID'     => $target_registration->ID(),
141
-                        'PAY_ID'     => $previous_payment->ID(),
142
-                        'RPY_amount' => $previous_payment->amount(),
143
-                    )
144
-                );
145
-                if ( ! $new_registration_payment instanceof \EE_Registration_Payment) {
146
-                    throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment');
147
-                }
148
-                $new_registration_payment->save();
149
-                $target_registration->set_paid($previous_payment->amount());
150
-                $target_registration->save();
151
-                // if new reg payment is good, then set old reg payment amount to zero
152
-                $previous_payment->set_amount(0);
153
-                $previous_payment->save();
154
-                $registration_to_copy->set_paid(0);
155
-                $registration_to_copy->save();
156
-            }
157
-        }
158
-        return true;
159
-    }
26
+	/**
27
+	 * @param \EE_Registration $target_registration
28
+	 * @param \EE_Registration $registration_to_copy
29
+	 * @return bool
30
+	 * @throws \EE_Error
31
+	 */
32
+	public function copyRegistrationDetails(
33
+		\EE_Registration $target_registration,
34
+		\EE_Registration $registration_to_copy
35
+	) {
36
+		// copy attendee
37
+		$target_registration->set_attendee_id($registration_to_copy->attendee_ID());
38
+		$target_registration->set_status( $registration_to_copy->status_ID() );
39
+		$target_registration->save();
40
+		// get answers to previous reg questions
41
+		$answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers());
42
+		// get questions to new event reg form
43
+		$new_event = $target_registration->event();
44
+		$question_groups = $new_event->question_groups(
45
+			array(
46
+				array(
47
+					'Event.EVT_ID'                     => $new_event->ID(),
48
+					'Event_Question_Group.EQG_primary' => $registration_to_copy->is_primary_registrant()
49
+				),
50
+				'order_by' => array('QSG_order' => 'ASC')
51
+			)
52
+		);
53
+		foreach ($question_groups as $question_group) {
54
+			if ($question_group instanceof \EE_Question_Group) {
55
+				foreach ($question_group->questions() as $question) {
56
+					if ($question instanceof \EE_Question) {
57
+						$this->generateNewAnswer(
58
+							$question,
59
+							$target_registration,
60
+							$answers
61
+						);
62
+					}
63
+				}
64
+			}
65
+		}
66
+		return true;
67
+	}
68
+
69
+
70
+
71
+	/**
72
+	 * @param \EE_Answer[] $answers
73
+	 * @return array
74
+	 * @throws \EE_Error
75
+	 */
76
+	protected static function reindexAnswersByQuestionId(array $answers)
77
+	{
78
+		$reindexed_answers = array();
79
+		foreach ($answers as $answer) {
80
+			if ($answer instanceof \EE_Answer) {
81
+				$reindexed_answers[$answer->question_ID()] = $answer->value();
82
+			}
83
+		}
84
+		return $reindexed_answers;
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 * @param \EE_Question     $question
91
+	 * @param \EE_Registration $registration
92
+	 * @param                  $previous_answers
93
+	 * @return \EE_Answer
94
+	 * @throws \EventEspresso\core\exceptions\UnexpectedEntityException
95
+	 * @throws \EE_Error
96
+	 */
97
+	protected static function generateNewAnswer(
98
+		\EE_Question $question,
99
+		\EE_Registration $registration,
100
+		$previous_answers
101
+	) {
102
+		$old_answer_value = isset($previous_answers[$question->ID()])
103
+			? $previous_answers[$question->ID()]
104
+			: '';
105
+		$new_answer = \EE_Answer::new_instance(
106
+			array(
107
+				'QST_ID'    => $question->ID(),
108
+				'REG_ID'    => $registration->ID(),
109
+				'ANS_value' => $old_answer_value,
110
+			)
111
+		);
112
+		if ( ! $new_answer instanceof \EE_Answer) {
113
+			throw new UnexpectedEntityException($new_answer, 'EE_Answer');
114
+		}
115
+		$new_answer->save();
116
+		return $new_answer;
117
+	}
118
+
119
+
120
+
121
+	/**
122
+	 * @param \EE_Registration $target_registration
123
+	 * @param \EE_Registration $registration_to_copy
124
+	 * @return bool
125
+	 * @throws \EE_Error
126
+	 */
127
+	public function copyPaymentDetails(
128
+		\EE_Registration $target_registration,
129
+		\EE_Registration $registration_to_copy
130
+	) {
131
+		$previous_payments = $registration_to_copy->registration_payments();
132
+		foreach ($previous_payments as $previous_payment) {
133
+			if (
134
+				$previous_payment instanceof \EE_Registration_Payment
135
+				&& $previous_payment->payment() instanceof \EE_Payment
136
+				&& $previous_payment->payment()->is_approved()
137
+			) {
138
+				$new_registration_payment = \EE_Registration_Payment::new_instance(
139
+					array(
140
+						'REG_ID'     => $target_registration->ID(),
141
+						'PAY_ID'     => $previous_payment->ID(),
142
+						'RPY_amount' => $previous_payment->amount(),
143
+					)
144
+				);
145
+				if ( ! $new_registration_payment instanceof \EE_Registration_Payment) {
146
+					throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment');
147
+				}
148
+				$new_registration_payment->save();
149
+				$target_registration->set_paid($previous_payment->amount());
150
+				$target_registration->save();
151
+				// if new reg payment is good, then set old reg payment amount to zero
152
+				$previous_payment->set_amount(0);
153
+				$previous_payment->save();
154
+				$registration_to_copy->set_paid(0);
155
+				$registration_to_copy->save();
156
+			}
157
+		}
158
+		return true;
159
+	}
160 160
 
161 161
 
162 162
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
     ) {
36 36
         // copy attendee
37 37
         $target_registration->set_attendee_id($registration_to_copy->attendee_ID());
38
-        $target_registration->set_status( $registration_to_copy->status_ID() );
38
+        $target_registration->set_status($registration_to_copy->status_ID());
39 39
         $target_registration->save();
40 40
         // get answers to previous reg questions
41 41
         $answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers());
Please login to merge, or discard this patch.