Email_summary_status.php 3.6 KB

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