Completed
Branch BUG-10381-asset-loading (7390a7)
by
unknown
39:00 queued 27:53
created
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/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.
core/domain/entities/RegUrlLink.php 2 patches
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 namespace EventEspresso\core\domain\entities;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -18,98 +18,98 @@  discard block
 block discarded – undo
18 18
 class RegUrlLink
19 19
 {
20 20
 
21
-    /*
21
+	/*
22 22
      * @var string $reg_url_link
23 23
      */
24
-    private $reg_url_link;
25
-
26
-
27
-
28
-    /**
29
-     * @param string $reg_url_link
30
-     * @return \EventEspresso\core\domain\entities\RegUrlLink
31
-     */
32
-    public static function fromRegUrlLinkString($reg_url_link)
33
-    {
34
-        if (empty($reg_url_link) || ! is_string($reg_url_link)) {
35
-            throw new \InvalidArgumentException(
36
-                __(
37
-                    'You must supply a valid non-empty string to generate a reg_url_link.',
38
-                    'event_espresso'
39
-                )
40
-            );
41
-        }
42
-        return new RegUrlLink(1, '', $reg_url_link);
43
-    }
44
-
45
-
46
-
47
-    /**
48
-     * @param \EE_Registration $registration
49
-     * @return \EventEspresso\core\domain\entities\RegUrlLink
50
-     */
51
-    public static function fromRegistration(\EE_Registration $registration)
52
-    {
53
-        return new RegUrlLink(
54
-            $registration->count(),
55
-            $registration->ticket_line_item()
56
-        );
57
-    }
58
-
59
-
60
-
61
-    /**
62
-     * CreateRegUrlLinkCommand constructor.
63
-     *
64
-     * @param int    $reg_count
65
-     * @param mixed  $base_code
66
-     * @param string $reg_url_link
67
-     */
68
-    public function __construct(
69
-        $reg_count = 1,
70
-        $base_code = '',
71
-        $reg_url_link = ''
72
-    ) {
73
-        if ( ! empty($reg_url_link) && is_string($reg_url_link)) {
74
-            $this->reg_url_link = apply_filters(
75
-                'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link',
76
-                $reg_url_link,
77
-                $reg_count,
78
-                $base_code,
79
-                $reg_url_link
80
-            );
81
-            return;
82
-        }
83
-        $reg_count = min(1, absint($reg_count));
84
-        $base_code = $base_code instanceof \EE_Line_Item ? $base_code->code() : $base_code;
85
-        if (empty($base_code) || ! is_string($base_code)) {
86
-            throw new \InvalidArgumentException(
87
-                __(
88
-                    'You must supply a valid EE_Line_Item or a non-empty string to generate a reg_url_link.',
89
-                    'event_espresso'
90
-                )
91
-            );
92
-        }
93
-        $this->reg_url_link = apply_filters(
94
-            'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link',
95
-            $reg_count . '-' . md5($base_code . microtime()),
96
-            $reg_count,
97
-            $base_code,
98
-            $reg_url_link
99
-        );
100
-    }
101
-
102
-
103
-
104
-    /**
105
-     * Return the object as a string
106
-     *
107
-     * @return string
108
-     */
109
-    public function __toString()
110
-    {
111
-        return $this->reg_url_link;
112
-    }
24
+	private $reg_url_link;
25
+
26
+
27
+
28
+	/**
29
+	 * @param string $reg_url_link
30
+	 * @return \EventEspresso\core\domain\entities\RegUrlLink
31
+	 */
32
+	public static function fromRegUrlLinkString($reg_url_link)
33
+	{
34
+		if (empty($reg_url_link) || ! is_string($reg_url_link)) {
35
+			throw new \InvalidArgumentException(
36
+				__(
37
+					'You must supply a valid non-empty string to generate a reg_url_link.',
38
+					'event_espresso'
39
+				)
40
+			);
41
+		}
42
+		return new RegUrlLink(1, '', $reg_url_link);
43
+	}
44
+
45
+
46
+
47
+	/**
48
+	 * @param \EE_Registration $registration
49
+	 * @return \EventEspresso\core\domain\entities\RegUrlLink
50
+	 */
51
+	public static function fromRegistration(\EE_Registration $registration)
52
+	{
53
+		return new RegUrlLink(
54
+			$registration->count(),
55
+			$registration->ticket_line_item()
56
+		);
57
+	}
58
+
59
+
60
+
61
+	/**
62
+	 * CreateRegUrlLinkCommand constructor.
63
+	 *
64
+	 * @param int    $reg_count
65
+	 * @param mixed  $base_code
66
+	 * @param string $reg_url_link
67
+	 */
68
+	public function __construct(
69
+		$reg_count = 1,
70
+		$base_code = '',
71
+		$reg_url_link = ''
72
+	) {
73
+		if ( ! empty($reg_url_link) && is_string($reg_url_link)) {
74
+			$this->reg_url_link = apply_filters(
75
+				'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link',
76
+				$reg_url_link,
77
+				$reg_count,
78
+				$base_code,
79
+				$reg_url_link
80
+			);
81
+			return;
82
+		}
83
+		$reg_count = min(1, absint($reg_count));
84
+		$base_code = $base_code instanceof \EE_Line_Item ? $base_code->code() : $base_code;
85
+		if (empty($base_code) || ! is_string($base_code)) {
86
+			throw new \InvalidArgumentException(
87
+				__(
88
+					'You must supply a valid EE_Line_Item or a non-empty string to generate a reg_url_link.',
89
+					'event_espresso'
90
+				)
91
+			);
92
+		}
93
+		$this->reg_url_link = apply_filters(
94
+			'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link',
95
+			$reg_count . '-' . md5($base_code . microtime()),
96
+			$reg_count,
97
+			$base_code,
98
+			$reg_url_link
99
+		);
100
+	}
101
+
102
+
103
+
104
+	/**
105
+	 * Return the object as a string
106
+	 *
107
+	 * @return string
108
+	 */
109
+	public function __toString()
110
+	{
111
+		return $this->reg_url_link;
112
+	}
113 113
 }
114 114
 // End of file RegUrlLink.php
115 115
 // Location: /RegUrlLink.php
116 116
\ No newline at end of file
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
         }
93 93
         $this->reg_url_link = apply_filters(
94 94
             'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link',
95
-            $reg_count . '-' . md5($base_code . microtime()),
95
+            $reg_count.'-'.md5($base_code.microtime()),
96 96
             $reg_count,
97 97
             $base_code,
98 98
             $reg_url_link
Please login to merge, or discard this patch.
core/domain/entities/RegCode.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\domain\entities;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -38,17 +38,17 @@  discard block
 block discarded – undo
38 38
 		\EE_Ticket $ticket
39 39
 	) {
40 40
 		// figure out where to start parsing the reg code
41
-		$chars = strpos( $reg_url_link, '-' ) + 5;
41
+		$chars = strpos($reg_url_link, '-') + 5;
42 42
 		// TXN_ID + TKT_ID + first 3 and last 3 chars of reg_url_link
43 43
 		$this->reg_code = array(
44 44
 			$transaction->ID(),
45 45
 			$ticket->ID(),
46
-			substr( $reg_url_link, 0, $chars )
46
+			substr($reg_url_link, 0, $chars)
47 47
 		);
48 48
 		// now put it all together
49 49
 		$this->reg_code = apply_filters(
50 50
 			'FHEE__Create__regCode__new_reg_code',
51
-			implode( '-', $this->reg_code ),
51
+			implode('-', $this->reg_code),
52 52
 			$transaction,
53 53
 			$ticket
54 54
 		);
Please login to merge, or discard this patch.
core/services/commands/middleware/InvalidCommandBusMiddlewareException.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\exceptions\InvalidDataTypeException;
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
 
@@ -23,35 +23,35 @@  discard block
 block discarded – undo
23 23
 {
24 24
 
25 25
 
26
-    /**
27
-     * @access public
28
-     * @param  mixed     $command_bus_middleware_object
29
-     * @param  string    $message
30
-     * @param int        $code
31
-     * @param \Exception $previous
32
-     */
33
-    public function __construct($command_bus_middleware_object, $message = '', $code = 0, \Exception $previous = null)
34
-    {
35
-        $command_bus_middleware = is_object($command_bus_middleware_object)
36
-            ? get_class($command_bus_middleware_object)
37
-            : gettype($command_bus_middleware_object);
38
-
39
-        if (empty($message)) {
40
-            $message = sprintf(
41
-                __('The supplied Command Bus Middleware "%1$s" does not have a valid name. It should be in the following format: "{CommandName}Handler" ',
42
-                    'event_espresso'),
43
-                $command_bus_middleware
44
-            );
45
-        }
46
-        parent::__construct(
47
-            '$command_bus_middleware',
48
-            $command_bus_middleware,
49
-            'CommandBusMiddlewareInterface',
50
-            $message,
51
-            $code,
52
-            $previous
53
-        );
54
-    }
26
+	/**
27
+	 * @access public
28
+	 * @param  mixed     $command_bus_middleware_object
29
+	 * @param  string    $message
30
+	 * @param int        $code
31
+	 * @param \Exception $previous
32
+	 */
33
+	public function __construct($command_bus_middleware_object, $message = '', $code = 0, \Exception $previous = null)
34
+	{
35
+		$command_bus_middleware = is_object($command_bus_middleware_object)
36
+			? get_class($command_bus_middleware_object)
37
+			: gettype($command_bus_middleware_object);
38
+
39
+		if (empty($message)) {
40
+			$message = sprintf(
41
+				__('The supplied Command Bus Middleware "%1$s" does not have a valid name. It should be in the following format: "{CommandName}Handler" ',
42
+					'event_espresso'),
43
+				$command_bus_middleware
44
+			);
45
+		}
46
+		parent::__construct(
47
+			'$command_bus_middleware',
48
+			$command_bus_middleware,
49
+			'CommandBusMiddlewareInterface',
50
+			$message,
51
+			$code,
52
+			$previous
53
+		);
54
+	}
55 55
 
56 56
 
57 57
 }
Please login to merge, or discard this patch.
core/services/commands/middleware/CapChecker.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use EventEspresso\core\services\commands\CommandRequiresCapCheckInterface;
7 7
 
8 8
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
9
-    exit('No direct script access allowed');
9
+	exit('No direct script access allowed');
10 10
 }
11 11
 
12 12
 
@@ -26,39 +26,39 @@  discard block
 block discarded – undo
26 26
 class CapChecker implements CommandBusMiddlewareInterface
27 27
 {
28 28
 
29
-    /**
30
-     * @type CapabilitiesChecker $capabilities_checker
31
-     */
32
-    private $capabilities_checker;
29
+	/**
30
+	 * @type CapabilitiesChecker $capabilities_checker
31
+	 */
32
+	private $capabilities_checker;
33 33
 
34 34
 
35 35
 
36
-    /**
37
-     * CapChecker constructor
38
-     *
39
-     * @param CapabilitiesChecker $capabilities_checker
40
-     */
41
-    public function __construct(CapabilitiesChecker $capabilities_checker)
42
-    {
43
-        $this->capabilities_checker = $capabilities_checker;
44
-    }
36
+	/**
37
+	 * CapChecker constructor
38
+	 *
39
+	 * @param CapabilitiesChecker $capabilities_checker
40
+	 */
41
+	public function __construct(CapabilitiesChecker $capabilities_checker)
42
+	{
43
+		$this->capabilities_checker = $capabilities_checker;
44
+	}
45 45
 
46 46
 
47 47
 
48
-    /**
49
-     * @param CommandInterface $command
50
-     * @param \Closure         $next
51
-     * @return mixed
52
-     */
53
-    public function handle(CommandInterface $command, \Closure $next)
54
-    {
55
-        if ( $command instanceof CommandRequiresCapCheckInterface) {
56
-            $this->capabilities_checker->processCapCheck(
57
-                $command->getCapCheck()
58
-            );
59
-        }
60
-        return $next($command);
61
-    }
48
+	/**
49
+	 * @param CommandInterface $command
50
+	 * @param \Closure         $next
51
+	 * @return mixed
52
+	 */
53
+	public function handle(CommandInterface $command, \Closure $next)
54
+	{
55
+		if ( $command instanceof CommandRequiresCapCheckInterface) {
56
+			$this->capabilities_checker->processCapCheck(
57
+				$command->getCapCheck()
58
+			);
59
+		}
60
+		return $next($command);
61
+	}
62 62
 
63 63
 
64 64
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@
 block discarded – undo
52 52
      */
53 53
     public function handle(CommandInterface $command, \Closure $next)
54 54
     {
55
-        if ( $command instanceof CommandRequiresCapCheckInterface) {
55
+        if ($command instanceof CommandRequiresCapCheckInterface) {
56 56
             $this->capabilities_checker->processCapCheck(
57 57
                 $command->getCapCheck()
58 58
             );
Please login to merge, or discard this patch.
core/services/commands/middleware/CommandBusMiddlewareInterface.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\commands\CommandInterface;
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
 
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
 interface CommandBusMiddlewareInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @param CommandInterface $command
22
-     * @param \Closure         $next
23
-     * @return mixed
24
-     */
25
-    public function handle(CommandInterface $command, \Closure $next);
20
+	/**
21
+	 * @param CommandInterface $command
22
+	 * @param \Closure         $next
23
+	 * @return mixed
24
+	 */
25
+	public function handle(CommandInterface $command, \Closure $next);
26 26
 
27 27
 }
28 28
 // End of file CommandBusMiddlewareInterface.php
Please login to merge, or discard this patch.