4 * Copyright (C) 2011, Free Software Foundation, Inc.
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.
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.
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/>.
23 * @author Ian Denhardt <ian@zenhack.net>
24 * @copyright 2011 Free Software Foundation, Inc.
25 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 if(!defined('STATUSNET')){
33 * Data class for photos.
36 class Photo extends Managed_DataObject
38 const OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/photo';
40 public $__table = 'photo'; // table name
41 public $id; // char (36) // UUID
42 public $uri; // varchar (191) // This is the corresponding notice's uri. not 255 because utf8mb4 takes more space
43 public $photo_uri; // varchar (191) not 255 because utf8mb4 takes more space
44 public $thumb_uri; // varchar (191) not 255 because utf8mb4 takes more space
45 public $title; // varchar (191) not 255 because utf8mb4 takes more space
46 public $description; // text
47 public $profile_id; // int
49 public static function getByNotice($notice)
51 return self::getKV('uri', $notice->uri);
54 public function getNotice()
56 return Notice::getKV('uri', $this->uri);
59 public static function schemaDef()
62 'description' => 'A photograph',
64 'id' => array('type' => 'char',
67 'description' => 'UUID'),
68 'uri' => array('type' => 'varchar',
71 'photo_uri' => array('type' => 'varchar',
74 'photo_uri' => array('type' => 'varchar',
77 'profile_id' => array('type' => 'int', 'not null' => true),
79 'primary key' => array('id'),
80 'foreign keys' => array('photo_profile_id__key' => array('profile' => array('profile_id' => 'id'))),
84 static function saveNew(Profile $profile, $photo_uri, $thumb_uri, $title, $description, $options=array())
88 $photo->id = UUID::gen();
89 $photo->profile_id = $profile->id;
90 $photo->photo_uri = $photo_uri;
91 $photo->thumb_uri = $thumb_uri;
94 $options['object_type'] = Photo::OBJECT_TYPE;
96 if (!array_key_exists('uri', $options)) {
97 $options['uri'] = common_local_url('showphoto', array('id' => $photo->id));
100 if (!array_key_exists('rendered', $options)) {
101 $options['rendered'] = sprintf("<img src=\"%s\" alt=\"%s\"></img>", $photo_uri,
105 $photo->uri = $options['uri'];
109 return Notice::saveNew($profile->id,