uc_coupon_handler_field_all_orders_value.inc 986 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. // $Id$
  3. /**
  4. * @file
  5. * Coupon order total field handler
  6. */
  7. class uc_coupon_handler_field_all_orders_value extends uc_coupon_handler_field_all_orders_total {
  8. /**
  9. * Here we add the aggregate field that will sum the value.
  10. */
  11. function query() {
  12. $this->ensure_my_table();
  13. $uco = $this->query->ensure_table('uc_coupons_orders');
  14. $uo = $this->query->ensure_table('uc_orders');
  15. $this->add_additional_fields();
  16. if (empty($this->options['statuses'])) {
  17. // If no status specified, then we show all.
  18. $in_status = "1";
  19. }
  20. else {
  21. // An array of statuses was specified.
  22. $in_status = "$uo.order_status IN('" . implode("', '", $this->options['statuses']) . "')";
  23. }
  24. $this->field_alias = $this->query->add_field(
  25. NULL,
  26. "CASE WHEN $in_status THEN $uco.value ELSE 0 END",
  27. $this->table_alias . '_' . $this->field . '_' . implode('_', $this->options['statuses']),
  28. array('function' => 'sum')
  29. );
  30. }
  31. }