Reply.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Table Definition for reply
  4. */
  5. require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
  6. class Reply extends Managed_DataObject
  7. {
  8. ###START_AUTOCODE
  9. /* the code below is auto generated do not remove the above tag */
  10. public $__table = 'reply'; // table name
  11. public $notice_id; // int(4) primary_key not_null
  12. public $profile_id; // int(4) primary_key not_null
  13. public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
  14. public $replied_id; // int(4)
  15. /* the code above is auto generated do not remove the tag below */
  16. ###END_AUTOCODE
  17. public static function schemaDef()
  18. {
  19. return array(
  20. 'fields' => array(
  21. 'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice that is the reply'),
  22. 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'profile replied to'),
  23. 'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
  24. 'replied_id' => array('type' => 'int', 'description' => 'notice replied to (not used, see notice.reply_to)'),
  25. ),
  26. 'primary key' => array('notice_id', 'profile_id'),
  27. 'foreign keys' => array(
  28. 'reply_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
  29. 'reply_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
  30. ),
  31. 'indexes' => array(
  32. 'reply_notice_id_idx' => array('notice_id'),
  33. 'reply_profile_id_idx' => array('profile_id'),
  34. 'reply_replied_id_idx' => array('replied_id'),
  35. 'reply_profile_id_modified_notice_id_idx' => array('profile_id', 'modified', 'notice_id')
  36. ),
  37. );
  38. }
  39. /**
  40. * Wrapper for record insertion to update related caches
  41. */
  42. function insert()
  43. {
  44. $result = parent::insert();
  45. if ($result) {
  46. self::blow('reply:stream:%d', $this->profile_id);
  47. }
  48. return $result;
  49. }
  50. static function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
  51. {
  52. // FIXME: Use some other method to get Profile::current() in order
  53. // to avoid confusion between background processing and session user.
  54. $stream = new ReplyNoticeStream($user_id, Profile::current());
  55. return $stream->getNotices($offset, $limit, $since_id, $max_id);
  56. }
  57. }