groupnoticestream.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * Stream of notices for a group
  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 group
  33. *
  34. * @category Stream
  35. * @package StatusNet
  36. * @author Evan Prodromou <evan@status.net>
  37. * @copyright 2011 StatusNet, Inc.
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  39. * @link http://status.net/
  40. */
  41. class GroupNoticeStream extends ScopingNoticeStream
  42. {
  43. var $group;
  44. function __construct($group, Profile $scoped=null)
  45. {
  46. $this->group = $group;
  47. parent::__construct(new CachingNoticeStream(new RawGroupNoticeStream($group),
  48. 'user_group:notice_ids:' . $group->id),
  49. $scoped);
  50. }
  51. function getNoticeIds($offset, $limit, $since_id, $max_id)
  52. {
  53. if ($this->impossibleStream()) {
  54. return array();
  55. } else {
  56. return parent::getNoticeIds($offset, $limit, $since_id, $max_id);
  57. }
  58. }
  59. function getNotices($offset, $limit, $sinceId = null, $maxId = null)
  60. {
  61. if ($this->impossibleStream()) {
  62. return new ArrayWrapper(array());
  63. } else {
  64. return parent::getNotices($offset, $limit, $sinceId, $maxId);
  65. }
  66. }
  67. function impossibleStream()
  68. {
  69. if ($this->group->force_scope &&
  70. (!$this->scoped instanceof Profile || $this->scoped->isMember($this->group))) {
  71. return true;
  72. }
  73. return false;
  74. }
  75. }
  76. /**
  77. * Stream of notices for a group
  78. *
  79. * @category Stream
  80. * @package StatusNet
  81. * @author Evan Prodromou <evan@status.net>
  82. * @copyright 2011 StatusNet, Inc.
  83. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  84. * @link http://status.net/
  85. */
  86. class RawGroupNoticeStream extends NoticeStream
  87. {
  88. protected $group;
  89. function __construct($group)
  90. {
  91. $this->group = $group;
  92. }
  93. function getNoticeIds($offset, $limit, $since_id, $max_id)
  94. {
  95. $inbox = new Group_inbox();
  96. $inbox->group_id = $this->group->id;
  97. $inbox->selectAdd();
  98. $inbox->selectAdd('notice_id');
  99. Notice::addWhereSinceId($inbox, $since_id, 'notice_id');
  100. Notice::addWhereMaxId($inbox, $max_id, 'notice_id');
  101. $inbox->orderBy('created DESC, notice_id DESC');
  102. if (!is_null($offset)) {
  103. $inbox->limit($offset, $limit);
  104. }
  105. $ids = array();
  106. if ($inbox->find()) {
  107. while ($inbox->fetch()) {
  108. $ids[] = $inbox->notice_id;
  109. }
  110. }
  111. return $ids;
  112. }
  113. }