User_flag_profile.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * Data class for profile flags
  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 profile flags
  35. *
  36. * A class representing a user flagging another profile for review.
  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. class User_flag_profile extends Managed_DataObject
  45. {
  46. ###START_AUTOCODE
  47. /* the code below is auto generated do not remove the above tag */
  48. public $__table = 'user_flag_profile'; // table name
  49. public $profile_id; // int(11) primary_key not_null
  50. public $user_id; // int(11) primary_key not_null
  51. public $cleared; // datetime default_0000-00-00%2000%3A00%3A00
  52. public $created; // datetime() not_null
  53. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  54. /* the code above is auto generated do not remove the tag below */
  55. ###END_AUTOCODE
  56. public static function schemaDef()
  57. {
  58. return array(
  59. 'fields' => array(
  60. 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'profile id flagged'),
  61. 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id of the actor'),
  62. 'cleared' => array('type' => 'datetime', 'description' => 'when flag was removed'),
  63. 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
  64. 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
  65. ),
  66. 'primary key' => array('profile_id', 'user_id'),
  67. 'indexes' => array(
  68. 'user_flag_profile_cleared_idx' => array('cleared'),
  69. 'user_flag_profile_created_idx' => array('created'),
  70. ),
  71. );
  72. }
  73. /**
  74. * Check if a flag exists for given profile and user
  75. *
  76. * @param integer $profile_id Profile to check for
  77. * @param integer $user_id User to check for
  78. *
  79. * @return boolean true if exists, else false
  80. */
  81. static function exists($profile_id, $user_id)
  82. {
  83. $ufp = User_flag_profile::pkeyGet(array('profile_id' => $profile_id,
  84. 'user_id' => $user_id));
  85. return !empty($ufp);
  86. }
  87. /**
  88. * Create a new flag
  89. *
  90. * @param integer $user_id ID of user who's flagging
  91. * @param integer $profile_id ID of profile being flagged
  92. *
  93. * @return boolean success flag
  94. */
  95. static function create($user_id, $profile_id)
  96. {
  97. $ufp = new User_flag_profile();
  98. $ufp->profile_id = $profile_id;
  99. $ufp->user_id = $user_id;
  100. $ufp->created = common_sql_now();
  101. if (!$ufp->insert()) {
  102. // TRANS: Server exception.
  103. // TRANS: %d is a profile ID (number).
  104. $msg = sprintf(_m('Could not flag profile "%d" for review.'),
  105. $profile_id);
  106. throw new ServerException($msg);
  107. }
  108. $ufp->free();
  109. return true;
  110. }
  111. }