Email_summary_status.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. * Data class for email summary status
  18. *
  19. * @category Data
  20. * @package GNUsocial
  21. * @author Evan Prodromou <evan@status.net>
  22. * @copyright 2010 StatusNet, Inc.
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. defined('GNUSOCIAL') || die();
  26. /**
  27. * Data class for email summaries
  28. *
  29. * Email summary information for users
  30. *
  31. * @category Action
  32. * @copyright 2010 StatusNet, Inc.
  33. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  34. *
  35. * @see DB_DataObject
  36. */
  37. class Email_summary_status extends Managed_DataObject
  38. {
  39. public $__table = 'email_summary_status'; // table name
  40. public $user_id; // int(4) primary_key not_null
  41. public $send_summary; // bool not_null default_true
  42. public $last_summary_id; // int(4) null
  43. public $created; // datetime not_null
  44. public $modified; // timestamp not_null
  45. public static function schemaDef()
  46. {
  47. return array(
  48. 'fields' => array(
  49. 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id'),
  50. 'send_summary' => array('type' => 'bool', 'default' => true, 'not null' => true, 'description' => 'whether to send a summary or not'),
  51. 'last_summary_id' => array('type' => 'int', 'description' => 'last summary id'),
  52. 'created' => array('type' => 'datetime', 'description' => 'date this record was created'),
  53. 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
  54. ),
  55. 'primary key' => array('user_id'),
  56. 'foreign keys' => array(
  57. 'email_summary_status_user_id_fkey' => array('user', array('user_id' => 'id')),
  58. ),
  59. );
  60. }
  61. /**
  62. * Helper function
  63. *
  64. * @param integer $user_id ID of the user to get a count for
  65. *
  66. * @return int flag for whether to send this user a summary email
  67. */
  68. public static function getSendSummary($user_id)
  69. {
  70. $ess = Email_summary_status::getKV('user_id', $user_id);
  71. if (!empty($ess)) {
  72. return $ess->send_summary;
  73. } else {
  74. return 1;
  75. }
  76. }
  77. /**
  78. * Get email summary status for a user
  79. *
  80. * @param integer $user_id ID of the user to get a count for
  81. *
  82. * @return Email_summary_status instance for this user, with count already incremented.
  83. */
  84. public static function getLastSummaryID($user_id)
  85. {
  86. $ess = Email_summary_status::getKV('user_id', $user_id);
  87. if (!empty($ess)) {
  88. return $ess->last_summary_id;
  89. } else {
  90. return null;
  91. }
  92. }
  93. }