forked from GNUsocial/gnu-social
Creating albums and uploading to them
This commit is contained in:
parent
89d8c0c6f2
commit
22fe5d0215
@ -59,6 +59,7 @@ class PhotouploadAction extends Action
|
||||
|
||||
function showContent()
|
||||
{
|
||||
//Upload a photo
|
||||
if(empty($this->user)) {
|
||||
$this->element('p', array(), 'You are not logged in.');
|
||||
} else {
|
||||
@ -73,14 +74,34 @@ class PhotouploadAction extends Action
|
||||
$this->elementEnd('li');
|
||||
//$this->element('br');
|
||||
$this->elementStart('li');
|
||||
$this->input('phototitle', "Title", null, "The title of the photo. (Optional)");
|
||||
$this->input('phototitle', _("Title"), null, _("The title of the photo. (Optional)"));
|
||||
$this->elementEnd('li');
|
||||
$this->elementStart('li');
|
||||
$this->textarea('photo_description', "Description", null, "A description of the photo. (Optional)");
|
||||
$this->textarea('photo_description', _("Description"), null, _("A description of the photo. (Optional)"));
|
||||
$this->elementEnd('li');
|
||||
$this->elementStart('li');
|
||||
$this->dropdown('album', _("Album"), $this->albumList(), _("The album in which to place this photo"), false);
|
||||
$this->elementEnd('li');
|
||||
$this->elementEnd('ul');
|
||||
$this->submit('upload', _('Upload'));
|
||||
$this->elementEnd('form');
|
||||
$this->element('br');
|
||||
|
||||
//Create a new album
|
||||
$this->element('h3', array(), _("Create a new album"));
|
||||
$this->elementStart('form', array('method' => 'post',
|
||||
'action' =>common_local_url('photoupload')));
|
||||
$this->elementStart('ul', 'form_data');
|
||||
$this->elementStart('li');
|
||||
$this->input('album_name', _("Title"), null, _("The title of the album."));
|
||||
$this->elementEnd('li');
|
||||
$this->elementStart('li');
|
||||
$this->textarea('album_description', _("Description"), null, _("A description of the album. (Optional)"));
|
||||
$this->elementEnd('li');
|
||||
$this->elementEnd('ul');
|
||||
$this->submit('create', _('Create'));
|
||||
$this->elementEnd('form');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,6 +135,9 @@ class PhotouploadAction extends Action
|
||||
if ($this->arg('upload')) {
|
||||
$this->uploadPhoto();
|
||||
}
|
||||
if ($this->arg('create')) {
|
||||
$this->createAlbum();
|
||||
}
|
||||
}
|
||||
|
||||
function showForm($msg, $success=false)
|
||||
@ -124,6 +148,22 @@ class PhotouploadAction extends Action
|
||||
// $this->showPage();
|
||||
}
|
||||
|
||||
function albumList()
|
||||
{
|
||||
$cur = common_current_user();
|
||||
$album = new GNUsocialPhotoAlbum();
|
||||
$album->user_id = $cur->id;
|
||||
|
||||
$albumlist = array();
|
||||
if (!$album->find()) {
|
||||
GNUsocialPhotoAlbum::newAlbum($cur->id, 'Default');
|
||||
}
|
||||
while ($album->fetch()) {
|
||||
$albumlist[$album->album_id] = $album->album_name;
|
||||
}
|
||||
return $albumlist;
|
||||
}
|
||||
|
||||
function uploadPhoto()
|
||||
{
|
||||
$cur = common_current_user();
|
||||
@ -154,10 +194,24 @@ class PhotouploadAction extends Action
|
||||
$profile_id = $cur->id;
|
||||
|
||||
// TODO: proper multiple album support
|
||||
$album = GNUsocialPhotoAlbum::staticGet('profile_id', $profile_id);
|
||||
if(!$album)
|
||||
$album = GNUsocialPhotoAlbum::newAlbum($profile_id, 'Default');
|
||||
$album = GNUsocialPhotoAlbum::staticGet('album_id', $this->trimmed('album'));
|
||||
if ($album->profile_id != $profile_id) {
|
||||
$this->showForm(_('Error: This is not your album!'));
|
||||
return;
|
||||
}
|
||||
GNUsocialPhoto::saveNew($profile_id, $album->album_id, $thumb_uri, $uri, 'web', false, $title, $photo_description);
|
||||
}
|
||||
|
||||
function createAlbum()
|
||||
{
|
||||
$cur = common_current_user();
|
||||
if(empty($cur)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$album_name = $this->trimmed('album_name');
|
||||
$album_description = $this->trimmed('album_description');
|
||||
|
||||
GNUsocialPhotoAlbum::newAlbum($cur->id, $album_name, $album_description);
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ class GNUsocialPhotoAlbum extends Memcached_DataObject
|
||||
public $album_id; // int(11) -- Unique identifier for the album
|
||||
public $profile_id; // int(11) -- Profile ID for the owner of the album
|
||||
public $album_name; // varchar(256) -- Title for this album
|
||||
public $album_description; // text -- A description of the album
|
||||
|
||||
|
||||
function staticGet($k,$v=NULL)
|
||||
@ -52,7 +53,8 @@ class GNUsocialPhotoAlbum extends Memcached_DataObject
|
||||
{
|
||||
return array('album_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
|
||||
'profile_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
|
||||
'album_name' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
|
||||
'album_name' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
|
||||
'album_description' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
|
||||
}
|
||||
|
||||
function keys()
|
||||
@ -72,7 +74,7 @@ class GNUsocialPhotoAlbum extends Memcached_DataObject
|
||||
return array('album_id', true, false);
|
||||
}
|
||||
|
||||
static function newAlbum($profile_id, $album_name)
|
||||
static function newAlbum($profile_id, $album_name, $album_description)
|
||||
{
|
||||
//TODO: Should use foreign key instead...
|
||||
if (!Profile::staticGet('id', $profile_id)){
|
||||
@ -83,6 +85,7 @@ class GNUsocialPhotoAlbum extends Memcached_DataObject
|
||||
$album = new GNUsocialPhotoAlbum();
|
||||
$album->profile_id = $profile_id;
|
||||
$album->album_name = $album_name;
|
||||
$album->album_description = $album_description;
|
||||
|
||||
$album->album_id = $album->insert();
|
||||
if (!$album->album_id){
|
||||
|
Loading…
Reference in New Issue
Block a user