views_handler_sort_ip_user_count.inc 651 B

1234567891011121314151617181920
  1. <?php
  2. /**
  3. * @file
  4. * User Stats user count by IP address.
  5. */
  6. /**
  7. * Users by IP address count handler.
  8. */
  9. class views_handler_sort_ip_user_count extends views_handler_sort {
  10. function query() {
  11. $this->table_alias = $this->ensure_my_table();
  12. // We need another subquery here to extract DISTINCT values
  13. $sql = "SELECT COUNT(usi.uid)
  14. FROM (SELECT DISTINCT(uid), ip_address FROM {user_stats_ips}) usi
  15. WHERE usi.ip_address = " . check_plain($this->table_alias) . ".ip_address";
  16. $this->field_alias = $this->query->add_orderby(NULL, "(" . $sql . ")", $this->options['order'], $this->table_alias . '_' . $this->field);
  17. }
  18. }