views_handler_argument_comment_user_uid.inc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_argument_comment_user_uid.
  5. */
  6. /**
  7. * Argument handler to accept a user id to check for nodes that
  8. * user posted or commented on.
  9. *
  10. * @ingroup views_argument_handlers
  11. */
  12. class views_handler_argument_comment_user_uid extends views_handler_argument {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public function title() {
  17. if (!$this->argument) {
  18. $title = variable_get('anonymous', t('Anonymous'));
  19. }
  20. else {
  21. $title = db_query('SELECT u.name FROM {users} u WHERE u.uid = :uid', array(':uid' => $this->argument))->fetchField();
  22. }
  23. if (empty($title)) {
  24. return t('No user');
  25. }
  26. return check_plain($title);
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function default_actions($which = NULL) {
  32. // Disallow summary views on this argument.
  33. if (!$which) {
  34. $actions = parent::default_actions();
  35. unset($actions['summary asc']);
  36. unset($actions['summary desc']);
  37. return $actions;
  38. }
  39. if ($which != 'summary asc' && $which != 'summary desc') {
  40. return parent::default_actions($which);
  41. }
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function query($group_by = FALSE) {
  47. $this->ensure_my_table();
  48. $subselect = db_select('comment', 'c');
  49. $subselect->addField('c', 'cid');
  50. $subselect->condition('c.uid', $this->argument);
  51. $subselect->where("c.nid = $this->table_alias.nid");
  52. $condition = db_or()
  53. ->condition("$this->table_alias.uid", $this->argument, '=')
  54. ->exists($subselect);
  55. $this->query->add_where(0, $condition);
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public function get_sort_name() {
  61. return t('Numerical', array(), array('context' => 'Sort order'));
  62. }
  63. }