GNUsocialProfileExtensionResponse.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 GNUsocialProfileExtensionResponse extends Managed_DataObject
  33. {
  34. public $__table = 'gnusocialprofileextensionresponse';
  35. public $id; // int(11)
  36. public $extension_id; // int(11)
  37. public $profile_id; // int(11)
  38. public $value; // text
  39. public $created; // datetime() not_null
  40. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  41. public static function schemaDef()
  42. {
  43. return array(
  44. 'fields' => array(
  45. 'id' => array('type' => 'serial', 'not null' => true, 'description' => 'Unique ID for extension response'),
  46. 'extension_id' => array('type' => 'int', 'not null' => true, 'description' => 'The extension field ID'),
  47. 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'Profile id that made the response'),
  48. 'value' => array('type' => 'text', 'not null' => true, 'description' => 'response entry'),
  49. 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
  50. 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
  51. ),
  52. 'primary key' => array('id'),
  53. 'foreign keys' => array(
  54. 'gnusocialprofileextensionresponse_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
  55. 'gnusocialprofileextensionresponse_extension_id_fkey' => array('gnusocialprofileextensionfield', array('extension_id' => 'id')),
  56. ),
  57. 'indexes' => array(
  58. 'gnusocialprofileextensionresponse_extension_id_idx' => array('extension_id'),
  59. ),
  60. );
  61. }
  62. static function newResponse($extension_id, $profile_id, $value)
  63. {
  64. $response = new GNUsocialProfileExtensionResponse();
  65. $response->extension_id = $extension_id;
  66. $response->profile_id = $profile_id;
  67. $response->value = $value;
  68. $response->id = $response->insert();
  69. if (!$response->id){
  70. common_log_db_error($response, 'INSERT', __FILE__);
  71. throw new ServerException(_m('Error creating new response.'));
  72. }
  73. return $response;
  74. }
  75. static function findResponsesByProfile($id)
  76. {
  77. $extf = 'gnusocialprofileextensionfield';
  78. $extr = 'gnusocialprofileextensionresponse';
  79. $sql = "SELECT $extr.*, $extf.title, $extf.description, $extf.type, $extf.systemname FROM $extr JOIN $extf ON $extr.extension_id=$extf.id WHERE $extr.profile_id = $id";
  80. $response = new GNUsocialProfileExtensionResponse();
  81. $response->query($sql);
  82. $responses = array();
  83. while ($response->fetch()) {
  84. $responses[] = clone($response);
  85. }
  86. return $responses;
  87. }
  88. }