eventsnoticestream.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. if (!defined('GNUSOCIAL')) { exit(1); }
  3. class RawEventsNoticeStream extends NoticeStream
  4. {
  5. function getNoticeIds($offset, $limit, $since_id, $max_id)
  6. {
  7. $notice = new Notice();
  8. $qry = null;
  9. $qry = 'SELECT notice.* FROM notice ';
  10. $qry .= 'INNER JOIN happening ON happening.uri = notice.uri ';
  11. $qry .= 'AND notice.is_local != ' . Notice::GATEWAY . ' ';
  12. if ($since_id != 0) {
  13. $qry .= 'AND notice.id > ' . $since_id . ' ';
  14. }
  15. if ($max_id != 0) {
  16. $qry .= 'AND notice.id <= ' . $max_id . ' ';
  17. }
  18. // NOTE: we sort by event time, not by notice time!
  19. $qry .= 'ORDER BY happening.created DESC ';
  20. if (!is_null($offset)) {
  21. $qry .= "LIMIT $limit OFFSET $offset";
  22. }
  23. $notice->query($qry);
  24. $ids = array();
  25. while ($notice->fetch()) {
  26. $ids[] = $notice->id;
  27. }
  28. $notice->free();
  29. unset($notice);
  30. return $ids;
  31. }
  32. }
  33. class EventsNoticeStream extends ScopingNoticeStream
  34. {
  35. // possible values of RSVP in our database
  36. protected $rsvp = ['Y', 'N', '?'];
  37. protected $target = null;
  38. function __construct(Profile $target, Profile $scoped=null, array $rsvp=array())
  39. {
  40. $stream = new RawEventsNoticeStream();
  41. if ($target->sameAs($scoped)) {
  42. $key = 'happening:ids_for_user_own:'.$target->getID();
  43. } else {
  44. $key = 'happening:ids_for_user:'.$target->getID();
  45. }
  46. // Match RSVP against our possible values, given in the class variable
  47. // and if no RSVPs are given is empty, assume we want all events, even
  48. // without RSVPs from this profile.
  49. $this->rsvp = array_intersect($this->rsvp, $rsvp);
  50. $this->target = $target;
  51. parent::__construct(new CachingNoticeStream($stream, $key), $scoped);
  52. }
  53. protected function filter(Notice $notice)
  54. {
  55. if (!parent::filter($notice)) {
  56. // if not in our scope, return false
  57. return false;
  58. }
  59. if (empty($this->rsvp)) {
  60. // Don't filter on RSVP (for only events with RSVP if no responses
  61. // are given (give ['Y', 'N', '?'] for only RSVP'd events!).
  62. return true;
  63. }
  64. $rsvp = new RSVP();
  65. $rsvp->profile_id = $this->target->getID();
  66. $rsvp->event_uri = $notice->getUri();
  67. $rsvp->whereAddIn('response', $this->rsvp, $rsvp->columnType('response'));
  68. // filter out if no RSVP match was found
  69. return $rsvp->N > 0;
  70. }
  71. }