Profile_role.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. * Table Definition for profile_role
  18. *
  19. * @copyright 2009 StatusNet, Inc.
  20. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  21. */
  22. defined('GNUSOCIAL') || die();
  23. class Profile_role extends Managed_DataObject
  24. {
  25. ###START_AUTOCODE
  26. /* the code below is auto generated do not remove the above tag */
  27. public $__table = 'profile_role'; // table name
  28. public $profile_id; // int(4) primary_key not_null
  29. public $role; // varchar(32) primary_key not_null
  30. public $created; // datetime()
  31. /* the code above is auto generated do not remove the tag below */
  32. ###END_AUTOCODE
  33. public static function schemaDef()
  34. {
  35. return array(
  36. 'fields' => array(
  37. 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'account having the role'),
  38. 'role' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'string representing the role'),
  39. 'created' => array('type' => 'datetime', 'description' => 'date the role was granted'),
  40. ),
  41. 'primary key' => array('profile_id', 'role'),
  42. 'foreign keys' => array(
  43. 'profile_role_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
  44. ),
  45. 'indexes' => array('profile_role_role_created_profile_id_idx' => array('role', 'created', 'profile_id')),
  46. );
  47. }
  48. const OWNER = 'owner';
  49. const MODERATOR = 'moderator';
  50. const ADMINISTRATOR = 'administrator';
  51. const SANDBOXED = 'sandboxed';
  52. const SILENCED = 'silenced';
  53. const DELETED = 'deleted'; // Pending final deletion of notices...
  54. public static function isValid($role)
  55. {
  56. // @fixme could probably pull this from class constants
  57. $known = array(self::OWNER,
  58. self::MODERATOR,
  59. self::ADMINISTRATOR,
  60. self::SANDBOXED,
  61. self::SILENCED);
  62. return in_array($role, $known);
  63. }
  64. public static function isSettable($role)
  65. {
  66. $allowedRoles = array('administrator', 'moderator');
  67. return self::isValid($role) && in_array($role, $allowedRoles);
  68. }
  69. }