| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 | 
							- <?php
 
- namespace cx_newsletter;
 
- class customers_export_page 
 
- extends service 
 
- implements service_interface {
 
-     public function process() : self {
 
-         return $this;
 
-     }
 
-     public function prepare() : self {
 
-         \add_rewrite_rule(
 
-             'cx-newsletter/customers-export$',
 
-             'index.php?'.$this->param.'=1',
 
-             'top'
 
-         );
 
-         global $wp_rewrite;
 
-         $wp_rewrite->flush_rules(true);
 
-         \add_filter('query_vars', [$this, 'add_query_var']);
 
-         \add_action('parse_request', [$this, 'parse_request']);
 
-         return $this;
 
-     }
 
-     public function add_query_var(array $vars) : array {
 
-         array_push($vars, $this->param);
 
-         return $vars;
 
-     }
 
-     public function parse_request($request) : void {
 
-         if (!array_key_exists($this->param, $request->query_vars)) {
 
-             return;
 
-         }
 
-         if (!\current_user_can('export')) {
 
-             echo('You must login as user that could export content.');
 
-             exit();
 
-         }   
 
-         
 
-         $mapper = new customers_mapper(
 
-             $this->get_database(),
 
-             $this->get_tables()
 
-         );
 
-         $converter = new customers_converter();
 
-         $all = [];
 
-         foreach ($mapper->load_all() as $customer) {
 
-             $customer = $converter->load_object($customer)->get_array();
 
-             unset($customer['id']);
 
-             array_push($all, $customer);
 
-         }
 
-         echo(json_encode($all));
 
-         header("Content-Type: application/json");
 
-         
 
-         exit();
 
-     }
 
-     private string $param = 'cx_newsletter_must_export_customers_now';
 
- }   
 
 
  |