gnusocialphotoalbum.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 Ian Denhardt <ian@zenhack.net>
  25. * @author Sean Corbett <sean@gnu.org>
  26. * @copyright 2010 Free Software Foundation, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
  33. class GNUsocialPhotoAlbum extends Managed_DataObject
  34. {
  35. public $__table = 'GNUsocialPhotoAlbum';
  36. public $album_id; // int(11) -- Unique identifier for the album
  37. public $profile_id; // int(11) -- Profile ID for the owner of the album
  38. public $album_name; // varchar(191) -- Title for this album not 255 because utf8mb4 takes more space
  39. public $album_description; // text -- A description of the album
  40. public $created; // datetime() not_null
  41. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  42. /* TODO: Primary key on both album_id, profile_id / foriegn key on profile_id */
  43. public static function schemaDef()
  44. {
  45. return array(
  46. 'fields' => array(
  47. 'album_id' => array('type' => 'serial', 'not null' => true, 'description' => 'Unique identifier for the album'),
  48. 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'Profile ID for the owner of the album'),
  49. 'album_name' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'Title for this album'),
  50. 'album_description' => array('type' => 'text', 'not null' => true, 'description' => 'A description for this album'),
  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('user_id'),
  55. 'foreign keys' => array(
  56. 'gnusocialphotoalbum_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
  57. ),
  58. 'indexes' => array(
  59. 'gnusocialphotoalbum_album_name_idx' => array('album_name'),
  60. ),
  61. );
  62. }
  63. function getPageLink()
  64. {
  65. $profile = Profile::getKV('id', $this->profile_id);
  66. return '/' . $profile->nickname . '/photos/' . $this->album_id;
  67. }
  68. function getThumbUri()
  69. {
  70. $photo = GNUsocialPhoto::getKV('album_id', $this->album_id);
  71. if (empty($photo))
  72. return '/theme/default/default-avatar-profile.png'; //For now...
  73. return $photo->thumb_uri;
  74. }
  75. static function newAlbum($profile_id, $album_name, $album_description)
  76. {
  77. //TODO: Should use foreign key instead...
  78. if (!Profile::getKV('id', $profile_id)){
  79. //Is this a bit extreme?
  80. throw new ServerException(_m('No such user exists with id ' . $profile_id . ', couldn\'t create album.'));
  81. }
  82. $album = new GNUsocialPhotoAlbum();
  83. $album->profile_id = $profile_id;
  84. $album->album_name = $album_name;
  85. $album->album_description = $album_description;
  86. $album->album_id = $album->insert();
  87. if (!$album->album_id){
  88. common_log_db_error($album, 'INSERT', __FILE__);
  89. throw new ServerException(_m('Error creating new album.'));
  90. }
  91. common_log(LOG_INFO, 'album_id : ' . $album->album_id);
  92. return $album;
  93. }
  94. }