peopletagnoticestream.php 3.4 KB

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