Reply.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. * Table Definition for reply
  18. */
  19. defined('GNUSOCIAL') || die();
  20. class Reply extends Managed_DataObject
  21. {
  22. ###START_AUTOCODE
  23. /* the code below is auto generated do not remove the above tag */
  24. public $__table = 'reply'; // table name
  25. public $notice_id; // int(4) primary_key not_null
  26. public $profile_id; // int(4) primary_key not_null
  27. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  28. public $replied_id; // int(4)
  29. /* the code above is auto generated do not remove the tag below */
  30. ###END_AUTOCODE
  31. public static function schemaDef()
  32. {
  33. return array(
  34. 'fields' => array(
  35. 'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice that is the reply'),
  36. 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'profile replied to'),
  37. 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
  38. 'replied_id' => array('type' => 'int', 'description' => 'notice replied to (not used, see notice.reply_to)'),
  39. ),
  40. 'primary key' => array('notice_id', 'profile_id'),
  41. 'foreign keys' => array(
  42. 'reply_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
  43. 'reply_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
  44. ),
  45. 'indexes' => array(
  46. 'reply_notice_id_idx' => array('notice_id'),
  47. 'reply_profile_id_idx' => array('profile_id'),
  48. 'reply_replied_id_idx' => array('replied_id'),
  49. 'reply_profile_id_modified_notice_id_idx' => array('profile_id', 'modified', 'notice_id')
  50. ),
  51. );
  52. }
  53. /**
  54. * Wrapper for record insertion to update related caches
  55. */
  56. public function insert()
  57. {
  58. $result = parent::insert();
  59. if ($result) {
  60. self::blow('reply:stream:%d', $this->profile_id);
  61. }
  62. return $result;
  63. }
  64. public static function stream(
  65. $user_id,
  66. $offset = 0,
  67. $limit = NOTICES_PER_PAGE,
  68. $since_id = 0,
  69. $max_id = 0
  70. ) {
  71. // FIXME: Use some other method to get Profile::current() in order
  72. // to avoid confusion between background processing and session user.
  73. $stream = new ReplyNoticeStream($user_id, Profile::current());
  74. return $stream->getNotices($offset, $limit, $since_id, $max_id);
  75. }
  76. }