class-report-factory.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Report Factory Class - Creates different types of reports
  4. *
  5. * @package StudiouWCCustomReports
  6. */
  7. if (!defined('ABSPATH')) {
  8. exit;
  9. }
  10. class StudiouWC_Report_Factory {
  11. private $db_manager;
  12. public function __construct($db_manager) {
  13. $this->db_manager = $db_manager;
  14. }
  15. public function create_report($type, $data) {
  16. switch ($type) {
  17. case 'product_categories_summary':
  18. return new StudiouWC_Product_Categories_Report($this->db_manager, $data);
  19. default:
  20. /* translators: %s: report type name */
  21. throw new InvalidArgumentException(sprintf(__('Unknown report type: %s', StudiouWC_Main::get_text_domain()), $type));
  22. }
  23. }
  24. public function get_available_report_types() {
  25. return array(
  26. 'product_categories_summary' => __('Product Categories and Variants Summary', StudiouWC_Main::get_text_domain())
  27. );
  28. }
  29. public function is_valid_report_type($type) {
  30. $available_types = array_keys($this->get_available_report_types());
  31. return in_array($type, $available_types);
  32. }
  33. }