peopletagnoticestream.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * Stream of notices for a list
  7. *
  8. * PHP version 5
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @category Stream
  24. * @package StatusNet
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2011 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET')) {
  31. // This check helps protect against security problems;
  32. // your code file can't be executed directly from the web.
  33. exit(1);
  34. }
  35. /**
  36. * Stream of notices for a list
  37. *
  38. * @category Stream
  39. * @package StatusNet
  40. * @author Evan Prodromou <evan@status.net>
  41. * @author Shashi Gowda <connect2shashi@gmail.com>
  42. * @copyright 2011 StatusNet, Inc.
  43. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  44. * @link http://status.net/
  45. */
  46. class PeopletagNoticeStream extends ScopingNoticeStream
  47. {
  48. function __construct($plist, $profile = -1)
  49. {
  50. if (is_int($profile) && $profile == -1) {
  51. $profile = Profile::current();
  52. }
  53. parent::__construct(new CachingNoticeStream(new RawPeopletagNoticeStream($plist),
  54. 'profile_list:notice_ids:' . $plist->id),
  55. $profile);
  56. }
  57. }
  58. /**
  59. * Stream of notices for a list
  60. *
  61. * @category Stream
  62. * @package StatusNet
  63. * @author Evan Prodromou <evan@status.net>
  64. * @author Shashi Gowda <connect2shashi@gmail.com>
  65. * @copyright 2011 StatusNet, Inc.
  66. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  67. * @link http://status.net/
  68. */
  69. class RawPeopletagNoticeStream extends NoticeStream
  70. {
  71. protected $profile_list;
  72. function __construct($profile_list)
  73. {
  74. $this->profile_list = $profile_list;
  75. }
  76. /**
  77. * Query notices by users associated with this tag from the database.
  78. *
  79. * @param integer $offset offset
  80. * @param integer $limit maximum no of results
  81. * @param integer $since_id=null since this id
  82. * @param integer $max_id=null maximum id in result
  83. *
  84. * @return array array of notice ids.
  85. */
  86. function getNoticeIds($offset, $limit, $since_id, $max_id)
  87. {
  88. $notice = new Notice();
  89. $notice->selectAdd();
  90. $notice->selectAdd('notice.id');
  91. $ptag = new Profile_tag();
  92. $ptag->tag = $this->profile_list->tag;
  93. $ptag->tagger = $this->profile_list->tagger;
  94. $notice->joinAdd(array('profile_id', 'profile_tag:tagged'));
  95. $notice->whereAdd('profile_tag.tagger = ' . $this->profile_list->tagger);
  96. $notice->whereAdd(sprintf('profile_tag.tag = "%s"', $this->profile_list->tag));
  97. if ($since_id != 0) {
  98. $notice->whereAdd('notice.id > ' . $since_id);
  99. }
  100. if ($max_id != 0) {
  101. $notice->whereAdd('notice.id <= ' . $max_id);
  102. }
  103. $notice->orderBy('notice.id DESC');
  104. if (!is_null($offset)) {
  105. $notice->limit($offset, $limit);
  106. }
  107. $ids = array();
  108. if ($notice->find()) {
  109. while ($notice->fetch()) {
  110. $ids[] = $notice->id;
  111. }
  112. }
  113. return $ids;
  114. }
  115. }