User_followeveryone_prefs.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 counting greetings
  18. *
  19. * @category Data
  20. * @package GNUsocial
  21. * @author Evan Prodromou <evan@status.net>
  22. * @copyright 2009, 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 counting greetings
  29. *
  30. * We use the DB_DataObject framework for data classes in StatusNet. Each
  31. * table maps to a particular data class, making it easier to manipulate
  32. * data.
  33. *
  34. * Data classes should extend Memcached_DataObject, the (slightly misnamed)
  35. * extension of DB_DataObject that provides caching, internationalization,
  36. * and other bits of good functionality to StatusNet-specific data classes.
  37. *
  38. * @category Action
  39. * @copyright 2009, StatusNet, Inc.
  40. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  41. *
  42. * @see DB_DataObject
  43. */
  44. class User_followeveryone_prefs extends Managed_DataObject
  45. {
  46. public $__table = 'user_followeveryone_prefs'; // table name
  47. public $user_id; // int(4) primary_key not_null
  48. public $followeveryone; // bool default_true
  49. public $created; // datetime() not_null
  50. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  51. public static function schemaDef()
  52. {
  53. return array(
  54. 'fields' => array(
  55. 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id'),
  56. 'followeveryone' => array('type' => 'bool', 'default' => true, 'description' => 'whether to follow everyone'),
  57. 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
  58. 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
  59. ),
  60. 'primary key' => array('user_id'),
  61. 'foreign keys' => array(
  62. 'user_followeveryone_prefs_user_id_fkey' => array('user', array('user_id' => 'id')),
  63. ),
  64. );
  65. }
  66. public static function followEveryone($user_id)
  67. {
  68. $ufep = self::getKV('user_id', $user_id);
  69. if (empty($ufep)) {
  70. return true;
  71. } else {
  72. return (bool)$ufep->followeveryone;
  73. }
  74. }
  75. public static function savePref($user_id, $followEveryone)
  76. {
  77. $ufep = self::getKV('user_id', $user_id);
  78. if (empty($ufep)) {
  79. $ufep = new User_followeveryone_prefs();
  80. $ufep->user_id = $user_id;
  81. $ufep->followeveryone = $followEveryone;
  82. $ufep->insert();
  83. } else {
  84. $orig = clone($ufep);
  85. $ufep->followeveryone = $followEveryone;
  86. $ufep->update();
  87. }
  88. return true;
  89. }
  90. }