User_followeveryone_prefs.php 3.7 KB

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