view = $params['view'] ?? 'product_categories_summary'; $this->date_from = $params['date_from'] ?? ''; $this->date_to = $params['date_to'] ?? date('Y-m-d'); $this->statuses = $params['statuses'] ?? array(); $this->per_page = intval($params['per_page'] ?? 20); $this->paged = intval($params['paged'] ?? 1); $this->orderby = $params['orderby'] ?? 'category'; $this->order = $params['order'] ?? 'ASC'; $this->validate_params(); } private function validate_params() { // Validate date format if (!empty($this->date_from) && !$this->is_valid_date($this->date_from)) { $this->date_from = date('Y-m-d', strtotime('-1 month')); } if (!empty($this->date_to) && !$this->is_valid_date($this->date_to)) { $this->date_to = date('Y-m-d'); } // Validate order direction if (!in_array(strtoupper($this->order), array('ASC', 'DESC'))) { $this->order = 'ASC'; } // Validate orderby column $valid_orderby = array('category', 'orders_count', 'total_price', 'customer_name', 'customer_email'); if (!in_array($this->orderby, $valid_orderby)) { $this->orderby = 'category'; } // Validate per_page limits if ($this->per_page < 1 || $this->per_page > 1000) { $this->per_page = 20; } // Validate paged if ($this->paged < 1) { $this->paged = 1; } } private function is_valid_date($date) { $d = DateTime::createFromFormat('Y-m-d', $date); return $d && $d->format('Y-m-d') === $date; } // Getters public function get_view() { return $this->view; } public function get_date_from() { return $this->date_from; } public function get_date_to() { return $this->date_to; } public function get_statuses() { return $this->statuses; } public function get_per_page() { return $this->per_page; } public function get_paged() { return $this->paged; } public function get_orderby() { return $this->orderby; } public function get_order() { return $this->order; } public function to_array() { return array( 'view' => $this->view, 'date_from' => $this->date_from, 'date_to' => $this->date_to, 'statuses' => $this->statuses, 'per_page' => $this->per_page, 'paged' => $this->paged, 'orderby' => $this->orderby, 'order' => $this->order ); } }