Profile_detail.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. static function schemaDef()
  69. {
  70. return array(
  71. // No need for i18n. Table properties.
  72. 'description'
  73. => 'Additional profile details for the ExtendedProfile plugin',
  74. 'fields' => array(
  75. 'id' => array('type' => 'serial', 'not null' => true),
  76. 'profile_id' => array('type' => 'int', 'not null' => true),
  77. 'field_name' => array(
  78. 'type' => 'varchar',
  79. 'length' => 16,
  80. 'not null' => true
  81. ),
  82. 'value_index' => array('type' => 'int'),
  83. 'field_value' => array('type' => 'text'),
  84. 'date' => array('type' => 'datetime'),
  85. 'rel' => array('type' => 'varchar', 'length' => 16),
  86. 'rel_profile' => array('type' => 'int'),
  87. 'created' => array(
  88. 'type' => 'datetime',
  89. 'not null' => true
  90. ),
  91. 'modified' => array(
  92. 'type' => 'timestamp',
  93. 'not null' => true
  94. ),
  95. ),
  96. 'primary key' => array('id'),
  97. 'unique keys' => array(
  98. 'profile_detail_profile_id_field_name_value_index'
  99. => array('profile_id', 'field_name', 'value_index'),
  100. )
  101. );
  102. }
  103. }