User_flag_profile.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 profile flags
  18. *
  19. * @category Data
  20. * @package GNUsocial
  21. *
  22. * @author Evan Prodromou <evan@status.net>
  23. * @copyright 2009 StatusNet, Inc.
  24. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  25. */
  26. defined('GNUSOCIAL') || die();
  27. /**
  28. * Data class for profile flags
  29. *
  30. * A class representing a user flagging another profile for review.
  31. *
  32. * @category Action
  33. * @package GNUsocial
  34. *
  35. * @author Evan Prodromou <evan@status.net>
  36. * @copyright 2009 StatusNet, Inc.
  37. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  38. */
  39. class User_flag_profile extends Managed_DataObject
  40. {
  41. //##START_AUTOCODE
  42. // the code below is auto generated do not remove the above tag
  43. public $__table = 'user_flag_profile'; // table name
  44. public $profile_id; // int(11) primary_key not_null
  45. public $user_id; // int(11) primary_key not_null
  46. public $cleared; // datetime()
  47. public $created; // datetime()
  48. public $modified; // timestamp() not_null
  49. // the code above is auto generated do not remove the tag below
  50. //##END_AUTOCODE
  51. public static function schemaDef()
  52. {
  53. return [
  54. 'fields' => [
  55. 'profile_id' => ['type' => 'int', 'not null' => true, 'description' => 'profile id flagged'],
  56. 'user_id' => ['type' => 'int', 'not null' => true, 'description' => 'user id of the actor'],
  57. 'cleared' => ['type' => 'datetime', 'description' => 'when flag was removed'],
  58. 'created' => ['type' => 'datetime', 'description' => 'date this record was created'],
  59. 'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
  60. ],
  61. 'primary key' => ['profile_id', 'user_id'],
  62. 'indexes' => [
  63. 'user_flag_profile_cleared_idx' => ['cleared'],
  64. 'user_flag_profile_created_idx' => ['created'],
  65. ],
  66. ];
  67. }
  68. /**
  69. * Check if a flag exists for given profile and user
  70. *
  71. * @param int $profile_id Profile to check for
  72. * @param int $user_id User to check for
  73. *
  74. * @return bool true if exists, else false
  75. */
  76. public static function exists($profile_id, $user_id)
  77. {
  78. $ufp = self::pkeyGet(['profile_id' => $profile_id,
  79. 'user_id' => $user_id, ]);
  80. return !empty($ufp);
  81. }
  82. /**
  83. * Create a new flag
  84. *
  85. * @param int $user_id ID of user who's flagging
  86. * @param int $profile_id ID of profile being flagged
  87. *
  88. * @return bool success flag
  89. */
  90. public static function create($user_id, $profile_id)
  91. {
  92. $ufp = new self();
  93. $ufp->profile_id = $profile_id;
  94. $ufp->user_id = $user_id;
  95. $ufp->created = common_sql_now();
  96. if (!$ufp->insert()) {
  97. // TRANS: Server exception.
  98. // TRANS: %d is a profile ID (number).
  99. $msg = sprintf(
  100. _m('Could not flag profile "%d" for review.'),
  101. $profile_id
  102. );
  103. throw new ServerException($msg);
  104. }
  105. $ufp->free();
  106. return true;
  107. }
  108. }