User_flag_profile.php 4.1 KB

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