Email_summary_status.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Data class for email summary status
  4. *
  5. * PHP version 5
  6. *
  7. * @category Data
  8. * @package StatusNet
  9. * @author Evan Prodromou <evan@status.net>
  10. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  11. * @link http://status.net/
  12. *
  13. * StatusNet - the distributed open-source microblogging tool
  14. * Copyright (C) 2010, StatusNet, Inc.
  15. *
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License as published by
  18. * the Free Software Foundation, either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
  33. /**
  34. * Data class for email summaries
  35. *
  36. * Email summary information for users
  37. *
  38. * @category Action
  39. * @package StatusNet
  40. * @author Evan Prodromou <evan@status.net>
  41. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  42. * @link http://status.net/
  43. *
  44. * @see DB_DataObject
  45. */
  46. class Email_summary_status extends Managed_DataObject
  47. {
  48. public $__table = 'email_summary_status'; // table name
  49. public $user_id; // int(4) primary_key not_null
  50. public $send_summary; // tinyint not_null
  51. public $last_summary_id; // int(4) null
  52. public $created; // datetime not_null
  53. public $modified; // datetime not_null
  54. public static function schemaDef()
  55. {
  56. return array(
  57. 'fields' => array(
  58. 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id'),
  59. 'send_summary' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'not null' => true, 'description' => 'whether to send a summary or not'),
  60. 'last_summary_id' => array('type' => 'int', 'description' => 'last summary id'),
  61. 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
  62. 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
  63. ),
  64. 'primary key' => array('user_id'),
  65. 'foreign keys' => array(
  66. 'email_summary_status_user_id_fkey' => array('user', array('user_id' => 'id')),
  67. ),
  68. );
  69. }
  70. /**
  71. * Helper function
  72. *
  73. * @param integer $user_id ID of the user to get a count for
  74. *
  75. * @return int flag for whether to send this user a summary email
  76. */
  77. static function getSendSummary($user_id)
  78. {
  79. $ess = Email_summary_status::getKV('user_id', $user_id);
  80. if (!empty($ess)) {
  81. return $ess->send_summary;
  82. } else {
  83. return 1;
  84. }
  85. }
  86. /**
  87. * Get email summary status for a user
  88. *
  89. * @param integer $user_id ID of the user to get a count for
  90. *
  91. * @return Email_summary_status instance for this user, with count already incremented.
  92. */
  93. static function getLastSummaryID($user_id)
  94. {
  95. $ess = Email_summary_status::getKV('user_id', $user_id);
  96. if (!empty($ess)) {
  97. return $ess->last_summary_id;
  98. } else {
  99. return null;
  100. }
  101. }
  102. }