groupnoticestream.php 3.6 KB

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