peopletagnoticestream.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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('GNUSOCIAL')) { exit(1); }
  31. /**
  32. * Stream of notices for a list
  33. *
  34. * @category Stream
  35. * @package StatusNet
  36. * @author Evan Prodromou <evan@status.net>
  37. * @author Shashi Gowda <connect2shashi@gmail.com>
  38. * @copyright 2011 StatusNet, Inc.
  39. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  40. * @link http://status.net/
  41. */
  42. class PeopletagNoticeStream extends ScopingNoticeStream
  43. {
  44. function __construct($plist, Profile $scoped=null)
  45. {
  46. parent::__construct(new CachingNoticeStream(new RawPeopletagNoticeStream($plist),
  47. 'profile_list:notice_ids:' . $plist->id),
  48. $scoped);
  49. }
  50. }
  51. /**
  52. * Stream of notices for a list
  53. *
  54. * @category Stream
  55. * @package StatusNet
  56. * @author Evan Prodromou <evan@status.net>
  57. * @author Shashi Gowda <connect2shashi@gmail.com>
  58. * @copyright 2011 StatusNet, Inc.
  59. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  60. * @link http://status.net/
  61. */
  62. class RawPeopletagNoticeStream extends NoticeStream
  63. {
  64. protected $profile_list;
  65. function __construct($profile_list)
  66. {
  67. $this->profile_list = $profile_list;
  68. }
  69. /**
  70. * Query notices by users associated with this tag from the database.
  71. *
  72. * @param integer $offset offset
  73. * @param integer $limit maximum no of results
  74. * @param integer $since_id=null since this id
  75. * @param integer $max_id=null maximum id in result
  76. *
  77. * @return array array of notice ids.
  78. */
  79. function getNoticeIds($offset, $limit, $since_id, $max_id)
  80. {
  81. $notice = new Notice();
  82. $notice->selectAdd();
  83. $notice->selectAdd('notice.id');
  84. $ptag = new Profile_tag();
  85. $ptag->tag = $this->profile_list->tag;
  86. $ptag->tagger = $this->profile_list->tagger;
  87. $notice->joinAdd(array('profile_id', 'profile_tag:tagged'));
  88. $notice->whereAdd('profile_tag.tagger = ' . $this->profile_list->tagger);
  89. $notice->whereAdd(sprintf('profile_tag.tag = "%s"', $this->profile_list->tag));
  90. if ($since_id != 0) {
  91. $notice->whereAdd('notice.id > ' . $since_id);
  92. }
  93. if ($max_id != 0) {
  94. $notice->whereAdd('notice.id <= ' . $max_id);
  95. }
  96. $notice->orderBy('notice.id DESC');
  97. if (!is_null($offset)) {
  98. $notice->limit($offset, $limit);
  99. }
  100. $ids = array();
  101. if ($notice->find()) {
  102. while ($notice->fetch()) {
  103. $ids[] = $notice->id;
  104. }
  105. }
  106. return $ids;
  107. }
  108. }