uc_coupon_handler_filter_product_type.inc 863 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * @file
  4. * Views handler: Coupon filter on "product-type".
  5. */
  6. /**
  7. * Filter coupons based on what product types they apply to
  8. */
  9. class uc_coupon_handler_filter_product_type extends views_handler_filter_in_operator {
  10. function get_value_options() {
  11. $this->value_options = array();
  12. foreach (module_invoke_all('uc_product_types') as $type) {
  13. $this->value_options[$type] = $type;
  14. }
  15. }
  16. function query() {
  17. $this->query->add_field('uc_coupons', 'data');
  18. if (is_array($this->value) && count($this->value)) {
  19. $search = implode("|", $this->value);
  20. $regexp = ".*product_types.*{[^}]*($search).*}";
  21. $this->query->add_where_expression($this->options['group'],
  22. "uc_coupons.data " . ($this->options['operator'] !== 'in' ? "NOT " : "") . "REGEXP :re",
  23. array(':re' => $regexp)
  24. );
  25. }
  26. }
  27. }