Profile_detail.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. if (!defined('STATUSNET')) {
  20. exit(1);
  21. }
  22. /**
  23. * DataObject class to store extended profile fields. Allows for storing
  24. * multiple values per a "field_name" (field_name property is not unique).
  25. *
  26. * Example:
  27. *
  28. * Jed's Phone Numbers
  29. * home : 510-384-1992
  30. * mobile: 510-719-1139
  31. * work : 415-231-1121
  32. *
  33. * We can store these phone numbers in a "field" represented by three
  34. * Profile_detail objects, each named 'phone_number' like this:
  35. *
  36. * $phone1 = new Profile_detail();
  37. * $phone1->field_name = 'phone_number';
  38. * $phone1->rel = 'home';
  39. * $phone1->field_value = '510-384-1992';
  40. * $phone1->value_index = 1;
  41. *
  42. * $phone1 = new Profile_detail();
  43. * $phone1->field_name = 'phone_number';
  44. * $phone1->rel = 'mobile';
  45. * $phone1->field_value = '510-719-1139';
  46. * $phone1->value_index = 2;
  47. *
  48. * $phone1 = new Profile_detail();
  49. * $phone1->field_name = 'phone_number';
  50. * $phone1->rel = 'work';
  51. * $phone1->field_value = '415-231-1121';
  52. * $phone1->value_index = 3;
  53. *
  54. */
  55. class Profile_detail extends Managed_DataObject
  56. {
  57. public $__table = 'profile_detail';
  58. public $id;
  59. public $profile_id; // profile this is for
  60. public $rel; // detail for some field types; eg "home", "mobile", "work" for phones or "aim", "irc", "xmpp" for IM
  61. public $field_name; // name
  62. public $field_value; // primary text value
  63. public $value_index; // relative ordering of multiple values in the same field
  64. public $date; // related date
  65. public $ref_profile; // for people types, allows pointing to a known profile in the system
  66. public $created;
  67. public $modified;
  68. public static function schemaDef()
  69. {
  70. return [
  71. // No need for i18n. Table properties.
  72. 'description' => 'Additional profile details for the ExtendedProfile plugin',
  73. 'fields' => [
  74. 'id' => ['type' => 'serial', 'not null' => true],
  75. 'profile_id' => ['type' => 'int', 'not null' => true],
  76. 'field_name' => [
  77. 'type' => 'varchar',
  78. 'length' => 16,
  79. 'not null' => true,
  80. ],
  81. 'value_index' => ['type' => 'int'],
  82. 'field_value' => ['type' => 'text'],
  83. 'date' => ['type' => 'datetime'],
  84. 'rel' => ['type' => 'varchar', 'length' => 16],
  85. 'rel_profile' => ['type' => 'int'],
  86. 'created' => [
  87. 'type' => 'datetime',
  88. 'not null' => true,
  89. ],
  90. 'modified' => [
  91. 'type' => 'timestamp',
  92. 'not null' => true,
  93. ],
  94. ],
  95. 'primary key' => ['id'],
  96. 'unique keys' => [
  97. 'profile_detail_profile_id_field_name_value_index' => ['profile_id', 'field_name', 'value_index']
  98. ],
  99. ];
  100. }
  101. }