views_handler_argument_comment_user_uid.inc

  1. 3.x modules/comment/views_handler_argument_comment_user_uid.inc
  2. 2.x modules/comment/views_handler_argument_comment_user_uid.inc

File

modules/comment/views_handler_argument_comment_user_uid.inc
View source
  1. <?php
  2. /**
  3. * Argument handler to accept a user id to check for nodes that
  4. * user posted or commented on.
  5. */
  6. class views_handler_argument_comment_user_uid extends views_handler_argument {
  7. function title() {
  8. if (!$this->argument) {
  9. $title = variable_get('anonymous', t('Anonymous'));
  10. }
  11. else {
  12. $title = db_result(db_query("SELECT u.name FROM {users} u WHERE u.uid = %d", $this->argument));
  13. }
  14. if (empty($title)) {
  15. return t('No user');
  16. }
  17. return check_plain($title);
  18. }
  19. function default_actions($which = NULL) {
  20. // Disallow summary views on this argument.
  21. if (!$which) {
  22. $actions = parent::default_actions();
  23. unset($actions['summary asc']);
  24. unset($actions['summary desc']);
  25. return $actions;
  26. }
  27. if ($which != 'summary asc' && $which != 'summary desc') {
  28. return parent::default_actions($which);
  29. }
  30. }
  31. function query() {
  32. $this->ensure_my_table();
  33. $this->query->add_where(0, "$this->table_alias.uid = %d OR ((SELECT COUNT(*) FROM {comments} c WHERE c.uid = %d AND c.nid = $this->table_alias.nid) > 0)", $this->argument, $this->argument);
  34. }
  35. }