GNUsocialProfileExtensionField.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * GNU Social
  4. * Copyright (C) 2010, Free Software Foundation, Inc.
  5. *
  6. * PHP version 5
  7. *
  8. * LICENCE:
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Widget
  23. * @package GNU Social
  24. * @author Max Shinn <trombonechamp@gmail.com>
  25. * @copyright 2010 Free Software Foundation, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  27. */
  28. if (!defined('STATUSNET')) {
  29. exit(1);
  30. }
  31. require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
  32. class GNUsocialProfileExtensionField extends Managed_DataObject
  33. {
  34. public $__table = 'gnusocialprofileextensionfield';
  35. public $id; // int(11)
  36. public $systemname; // varchar(64)
  37. public $title; // varchar(255)
  38. public $description; // text
  39. public $type; // varchar(255)
  40. public $created; // datetime() not_null
  41. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  42. public static function schemaDef()
  43. {
  44. return array(
  45. 'fields' => array(
  46. 'id' => array('type' => 'serial', 'not null' => true, 'description' => 'Unique ID for extension field'),
  47. 'systemname' => array('type' => 'varchar', 'not null' => true, 'length' => 64, 'description' => 'field systemname'),
  48. 'title' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'field title'),
  49. 'description' => array('type' => 'text', 'not null' => true, 'description' => 'field description'),
  50. 'type' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'field type'),
  51. 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
  52. 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
  53. ),
  54. 'primary key' => array('id'),
  55. 'indexes' => array(
  56. 'gnusocialprofileextensionfield_title_idx' => array('title'),
  57. ),
  58. );
  59. }
  60. static function newField($title, $description=null, $type='str', $systemname=null)
  61. {
  62. $field = new GNUsocialProfileExtensionField();
  63. $field->title = $title;
  64. $field->description = $description;
  65. $field->type = $type;
  66. if (empty($systemname))
  67. $field->systemname = 'field' + $field->id;
  68. else
  69. $field->systemname = $systemname;
  70. $field->id = $field->insert();
  71. if (!$field->id){
  72. common_log_db_error($field, 'INSERT', __FILE__);
  73. throw new ServerException(_m('Error creating new field.'));
  74. }
  75. return $field;
  76. }
  77. static function allFields()
  78. {
  79. $field = new GNUsocialProfileExtensionField();
  80. $fields = array();
  81. if ($field->find()) {
  82. while($field->fetch()) {
  83. $fields[] = clone($field);
  84. }
  85. }
  86. return $fields;
  87. }
  88. }