| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace EventEspresso\core\domain\services\admin\privacy\export; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use EE_Error; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use EE_Form_Section_Proper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use EEM_Attendee; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use EEM_Payment_Method; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use EventEspresso\core\services\privacy\export\PersonalDataExporterInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * Class ExportAttendeeBillingData | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * Returns all the billing data we have stored on users of that email address | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @package        Event Espresso | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @author         Mike Nelson | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @since          $VID:$ | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 18 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  | class ExportAttendeeBillingData implements PersonalDataExporterInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |      * @var EEM_Attendee | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     protected $attendee_model; | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |      * @var EEM_Payment_Method | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     protected $payment_method_model; | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      * ExportAttendeeBillingData constructor. | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |      * @param EEM_Attendee $attendee_model | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     public function __construct(EEM_Attendee $attendee_model, EEM_Payment_Method $payment_method_model) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $this->attendee_model = $attendee_model; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $this->payment_method_model = $payment_method_model; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 40 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      * Returns data for export. | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |      * @param string    $email_address , | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |      * @param int       $page          starts at 1, not 0 | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |      * @return array { | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |      * @type array      $data          { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |      * @type array { | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |      * @type string     $group_id      (not translated, same for all exports) | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      * @type string     $group_label   (translated string) | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      * @type string|int $item_id | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      * @type array      $data          { | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      * @type array { | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |      * @type string     $name          what's shown in the left-column of the export row | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |      * @type string     $value         what's showin the right-column of the export row | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |      *                                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |      *                                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |      *                                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      *                                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      *                                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     public function export($email_address, $page = 1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $page_size = 10; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $attendees = $this->attendee_model->get_all( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                 array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                     'ATT_email' => $email_address, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                 'limit' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                     ($page - 1) * $page_size, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                     $page_size, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         // get all payment methods, even inactive ones | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $payment_methods = $this->payment_method_model->get_all( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                 'group_by' => array('PMD_type'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $export_items = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $found_something = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         foreach ($attendees as $attendee) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             foreach ($payment_methods as $payment_method) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                 try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                     $billing_info = $attendee->billing_info_for_payment_method($payment_method); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                 } catch (EE_Error $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                     $billing_info = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                 if (! $billing_info instanceof EE_Form_Section_Proper) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                     continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                 $found_something = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                 $data = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                 foreach ($billing_info->input_pretty_values(true, true) as $input_name => $display_value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                     try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                         $input = $billing_info->get_input($input_name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                         $input_display_name = $input->html_label_text(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                     } catch (EE_Error $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                         $input_display_name = $input_name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                     $data[] = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                         'name'  => strip_tags($input_display_name), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |                         'value' => $display_value, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                 $export_items[] = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |                     'group_id'    => 'billing_data', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |                     'group_label' => esc_html__('Billing Data', 'event_espresso'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |                     'item_id'     => $attendee->ID() . '-' . $payment_method->ID(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |                     'data'        => $data, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             'data' => $export_items, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |             'done' => ! $found_something, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 121 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |      * Gets the Translated name of this exporter | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     public function name() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         return esc_html__('Event Espresso Attendee Billing Data Exporter', 'event_espresso'); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 131 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | // End of file ExportAttendeeBillingData.php | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 134 |  |  | // Location: EventEspresso\core\domain\services\admin\privacy\export/ExportAttendeeBillingData.php | 
            
                                                        
            
                                    
            
            
                | 135 |  |  |  |