Reply.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_profile_id_idx' => array('profile_id'),
  47. 'reply_replied_id_idx' => array('replied_id'),
  48. 'reply_profile_id_modified_notice_id_idx' => array('profile_id', 'modified', 'notice_id')
  49. ),
  50. );
  51. }
  52. /**
  53. * Wrapper for record insertion to update related caches
  54. */
  55. public function insert()
  56. {
  57. $result = parent::insert();
  58. if ($result) {
  59. self::blow('reply:stream:%d', $this->profile_id);
  60. }
  61. return $result;
  62. }
  63. public static function stream(
  64. $user_id,
  65. $offset = 0,
  66. $limit = NOTICES_PER_PAGE,
  67. $since_id = 0,
  68. $max_id = 0
  69. ) {
  70. // FIXME: Use some other method to get Profile::current() in order
  71. // to avoid confusion between background processing and session user.
  72. $stream = new ReplyNoticeStream($user_id, Profile::current());
  73. return $stream->getNotices($offset, $limit, $since_id, $max_id);
  74. }
  75. }