views_handler_argument_formula.inc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_argument_formula.
  5. */
  6. /**
  7. * Abstract argument handler for simple formulae.
  8. *
  9. * Child classes of this object should implement summary_argument, at least.
  10. *
  11. * Definition terms:
  12. * - formula: The formula to use for this handler.
  13. *
  14. * @ingroup views_argument_handlers
  15. */
  16. class views_handler_argument_formula extends views_handler_argument {
  17. /**
  18. *
  19. */
  20. public $formula = NULL;
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function construct() {
  25. parent::construct();
  26. if (!empty($this->definition['formula'])) {
  27. $this->formula = $this->definition['formula'];
  28. }
  29. }
  30. /**
  31. *
  32. */
  33. public function get_formula() {
  34. return str_replace('***table***', $this->table_alias, $this->formula);
  35. }
  36. /**
  37. * Build the summary query based on a formula
  38. */
  39. public function summary_query() {
  40. $this->ensure_my_table();
  41. // Now that our table is secure, get our formula.
  42. $formula = $this->get_formula();
  43. // Add the field.
  44. $this->base_alias = $this->name_alias = $this->query->add_field(NULL, $formula, $this->field);
  45. $this->query->set_count_field(NULL, $formula, $this->field);
  46. return $this->summary_basics(FALSE);
  47. }
  48. /**
  49. * Build the query based upon the formula
  50. */
  51. public function query($group_by = FALSE) {
  52. $this->ensure_my_table();
  53. // Now that our table is secure, get our formula.
  54. $placeholder = $this->placeholder();
  55. $formula = $this->get_formula() . ' = ' . $placeholder;
  56. $placeholders = array(
  57. $placeholder => $this->argument,
  58. );
  59. $this->query->add_where(0, $formula, $placeholders, 'formula');
  60. }
  61. }