1 | <?php |
||
26 | class CopyRegistrationService extends DomainService |
||
27 | { |
||
28 | |||
29 | |||
30 | /** |
||
31 | * @param EE_Registration $target_registration |
||
32 | * @param EE_Registration $registration_to_copy |
||
33 | * @return bool |
||
34 | * @throws UnexpectedEntityException |
||
35 | * @throws EntityNotFoundException |
||
36 | * @throws RuntimeException |
||
37 | * @throws EE_Error |
||
38 | */ |
||
39 | public function copyRegistrationDetails( |
||
40 | EE_Registration $target_registration, |
||
41 | EE_Registration $registration_to_copy |
||
42 | ) { |
||
43 | // copy attendee |
||
44 | $target_registration->set_attendee_id($registration_to_copy->attendee_ID()); |
||
45 | $target_registration->updateStatusBasedOnTotalPaid(false); |
||
46 | $target_registration->save(); |
||
47 | // get answers to previous reg questions |
||
48 | $answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers()); |
||
49 | // get questions to new event reg form |
||
50 | $new_event = $target_registration->event(); |
||
51 | $field_name = 'Event_Question_Group.' |
||
52 | . EEM_Event_Question_Group::instance()->field_name_for_category( |
||
53 | $registration_to_copy->is_primary_registrant() |
||
54 | ); |
||
55 | $question_groups = $new_event->question_groups([ |
||
56 | [ |
||
57 | 'Event.EVT_ID' => $new_event->ID(), |
||
58 | $field_name => true, |
||
59 | ], |
||
60 | 'order_by' => ['QSG_order' => 'ASC'], |
||
61 | ] |
||
62 | |||
63 | ); |
||
64 | foreach ($question_groups as $question_group) { |
||
65 | if ($question_group instanceof \EE_Question_Group) { |
||
66 | foreach ($question_group->questions() as $question) { |
||
67 | if ($question instanceof EE_Question) { |
||
68 | $this->generateNewAnswer( |
||
69 | $question, |
||
70 | $target_registration, |
||
71 | $answers |
||
72 | ); |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | } |
||
77 | return true; |
||
78 | } |
||
79 | |||
80 | |||
81 | /** |
||
82 | * @param EE_Answer[] $answers |
||
83 | * @return array |
||
84 | * @throws EE_Error |
||
85 | */ |
||
86 | protected function reindexAnswersByQuestionId(array $answers) |
||
96 | |||
97 | |||
98 | /** |
||
99 | * @param EE_Question $question |
||
100 | * @param EE_Registration $registration |
||
101 | * @param $previous_answers |
||
102 | * @return EE_Answer |
||
103 | * @throws UnexpectedEntityException |
||
104 | * @throws EE_Error |
||
105 | */ |
||
106 | protected function generateNewAnswer( |
||
127 | |||
128 | |||
129 | /** |
||
130 | * @param EE_Registration $target_registration |
||
131 | * @param EE_Registration $registration_to_copy |
||
132 | * @return bool |
||
133 | * @throws RuntimeException |
||
134 | * @throws UnexpectedEntityException |
||
135 | * @throws EE_Error |
||
136 | */ |
||
137 | public function copyPaymentDetails( |
||
179 | } |
||
180 |