Reply.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. public $is_mariadb;
  23. ###START_AUTOCODE
  24. /* the code below is auto generated do not remove the above tag */
  25. public $__table = 'reply'; // table name
  26. public $notice_id; // int(4) primary_key not_null
  27. public $profile_id; // int(4) primary_key not_null
  28. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  29. public $replied_id; // int(4)
  30. /* the code above is auto generated do not remove the tag below */
  31. ###END_AUTOCODE
  32. public static function schemaDef()
  33. {
  34. return array(
  35. 'fields' => array(
  36. 'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice that is the reply'),
  37. 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'profile replied to'),
  38. 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
  39. 'replied_id' => array('type' => 'int', 'description' => 'notice replied to (not used, see notice.reply_to)'),
  40. ),
  41. 'primary key' => array('notice_id', 'profile_id'),
  42. 'foreign keys' => array(
  43. 'reply_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
  44. 'reply_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
  45. ),
  46. 'indexes' => array(
  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. }