]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialPhotos/classes/gnusocialphotoalbum.php
Creating albums and uploading to them
[quix0rs-gnu-social.git] / plugins / GNUsocialPhotos / classes / gnusocialphotoalbum.php
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
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
35
36 class GNUsocialPhotoAlbum extends Memcached_DataObject
37 {
38     public $__table = 'GNUsocialPhotoAlbum';
39     public $album_id;          // int(11) -- Unique identifier for the album
40     public $profile_id;        // int(11) -- Profile ID for the owner of the album
41     public $album_name;        // varchar(256) -- Title for this album
42     public $album_description; // text -- A description of the album
43     
44
45     function staticGet($k,$v=NULL)
46     {
47         return Memcached_DataObject::staticGet('GNUsocialPhotoAlbum',$k,$v);
48     }
49
50
51     /* TODO: Primary key on both album_id, profile_id / foriegn key on profile_id */
52     function table()
53     {
54         return array('album_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
55                      'profile_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
56                      'album_name' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
57                      'album_description' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
58     }
59     
60     function keys()
61     {
62         return array_keys($this->keyTypes());
63     }
64
65     
66     /* Using album_id as the primary key for now.. */
67     function keyTypes()
68     {
69         return array('album_id' => 'K');
70     }
71
72     function sequenceKey()
73     {
74         return array('album_id', true, false);
75     }
76
77     static function newAlbum($profile_id, $album_name, $album_description)
78     {
79         //TODO: Should use foreign key instead...
80         if (!Profile::staticGet('id', $profile_id)){
81             //Is this a bit extreme?
82             throw new ServerException(_m('No such user exists with id ' . $profile_id . ', couldn\'t create album.'));
83         }
84         
85         $album = new GNUsocialPhotoAlbum();
86         $album->profile_id = $profile_id;
87         $album->album_name = $album_name;
88         $album->album_description = $album_description;
89        
90         $album->album_id = $album->insert();
91         if (!$album->album_id){
92             common_log_db_error($album, 'INSERT', __FILE__);
93             throw new ServerException(_m('Error creating new album.'));
94         }
95         common_log(LOG_INFO, 'album_id : ' . $album->album_id);
96         return $album;
97     } 
98
99 }