views_handler_argument_formula.inc

  1. 3.x handlers/views_handler_argument_formula.inc
  2. 2.x handlers/views_handler_argument_formula.inc

Definition of views_handler_argument_formula.

File

handlers/views_handler_argument_formula.inc
View source
  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. var $formula = NULL;
  18. /**
  19. * Constructor
  20. */
  21. function construct() {
  22. parent::construct();
  23. if (!empty($this->definition['formula'])) {
  24. $this->formula = $this->definition['formula'];
  25. }
  26. }
  27. function get_formula() {
  28. return str_replace('***table***', $this->table_alias, $this->formula);
  29. }
  30. /**
  31. * Build the summary query based on a formula
  32. */
  33. function summary_query() {
  34. $this->ensure_my_table();
  35. // Now that our table is secure, get our formula.
  36. $formula = $this->get_formula();
  37. // Add the field.
  38. $this->base_alias = $this->name_alias = $this->query->add_field(NULL, $formula, $this->field);
  39. $this->query->set_count_field(NULL, $formula, $this->field);
  40. return $this->summary_basics(FALSE);
  41. }
  42. /**
  43. * Build the query based upon the formula
  44. */
  45. function query($group_by = FALSE) {
  46. $this->ensure_my_table();
  47. // Now that our table is secure, get our formula.
  48. $placeholder = $this->placeholder();
  49. $formula = $this->get_formula() .' = ' . $placeholder;
  50. $placeholders = array(
  51. $placeholder => $this->argument,
  52. );
  53. $this->query->add_where(0, $formula, $placeholders, 'formula');
  54. }
  55. }