peopletagnoticestream.php 3.3 KB

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