Profile_detail.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. * @copyright 1012 StatusNet, Inc.
  18. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  19. */
  20. defined('GNUSOCIAL') || die();
  21. /**
  22. * DataObject class to store extended profile fields. Allows for storing
  23. * multiple values per a "field_name" (field_name property is not unique).
  24. *
  25. * Example:
  26. *
  27. * Jed's Phone Numbers
  28. * home : 510-384-1992
  29. * mobile: 510-719-1139
  30. * work : 415-231-1121
  31. *
  32. * We can store these phone numbers in a "field" represented by three
  33. * Profile_detail objects, each named 'phone_number' like this:
  34. *
  35. * $phone1 = new Profile_detail();
  36. * $phone1->field_name = 'phone_number';
  37. * $phone1->rel = 'home';
  38. * $phone1->field_value = '510-384-1992';
  39. * $phone1->value_index = 1;
  40. *
  41. * $phone1 = new Profile_detail();
  42. * $phone1->field_name = 'phone_number';
  43. * $phone1->rel = 'mobile';
  44. * $phone1->field_value = '510-719-1139';
  45. * $phone1->value_index = 2;
  46. *
  47. * $phone1 = new Profile_detail();
  48. * $phone1->field_name = 'phone_number';
  49. * $phone1->rel = 'work';
  50. * $phone1->field_value = '415-231-1121';
  51. * $phone1->value_index = 3;
  52. *
  53. */
  54. class Profile_detail extends Managed_DataObject
  55. {
  56. public $__table = 'profile_detail';
  57. public $id;
  58. public $profile_id; // profile this is for
  59. public $rel; // detail for some field types; eg "home", "mobile", "work" for phones or "aim", "irc", "xmpp" for IM
  60. public $field_name; // name
  61. public $field_value; // primary text value
  62. public $value_index; // relative ordering of multiple values in the same field
  63. public $date; // related date
  64. public $ref_profile; // for people types, allows pointing to a known profile in the system
  65. public $created;
  66. public $modified;
  67. public static function schemaDef()
  68. {
  69. return [
  70. // No need for i18n. Table properties.
  71. 'description' => 'Additional profile details for the ExtendedProfile plugin',
  72. 'fields' => [
  73. 'id' => ['type' => 'serial', 'not null' => true],
  74. 'profile_id' => ['type' => 'int', 'not null' => true],
  75. 'field_name' => [
  76. 'type' => 'varchar',
  77. 'length' => 16,
  78. 'not null' => true,
  79. ],
  80. 'value_index' => ['type' => 'int'],
  81. 'field_value' => ['type' => 'text'],
  82. 'date' => ['type' => 'datetime'],
  83. 'rel' => ['type' => 'varchar', 'length' => 16],
  84. 'rel_profile' => ['type' => 'int'],
  85. 'created' => [
  86. 'type' => 'datetime',
  87. 'not null' => true,
  88. ],
  89. 'modified' => [
  90. 'type' => 'timestamp',
  91. 'not null' => true,
  92. ],
  93. ],
  94. 'primary key' => ['id'],
  95. 'unique keys' => [
  96. 'profile_detail_profile_id_field_name_value_index_key' => ['profile_id', 'field_name', 'value_index']
  97. ],
  98. ];
  99. }
  100. }