Adding another album with useralbum module

nmahlin

Joined: 2005-09-26
Posts: 19
Posted: Tue, 2005-10-25 17:13

I am currently using the user album module to gives users there own private album. I also would like to be able to give users another album that is viewable by everyone. Looking at the code in UserAlbumHelperClass.class:

Quote:
/* Create album.. */
$albumTitle = trim($user->getFullName());
if (empty($albumTitle)) {
$albumTitle = $user->getUserName();
}
$albumName = $user->getUserName();
while (true) {
list ($ret, $album) = GalleryCoreApi::createAlbum(
$module['targetLocation'], $albumName, $albumTitle, '', '', '');
if ($ret->isSuccess()) {
break;
}
if ($ret->getErrorCode() & ERROR_COLLISION) {
$albumName .= '_';
} else {
return $ret->wrap(__FILE__, __LINE__);
}
}

list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($album->getId());
if ($ret->isError()) {
return $ret->wrap(__FILE__, __LINE__);
}

At this point in the function I have the album id of the newly created album. So after the function finishes adding permissions / setting owner / ect. Do I just need to call createAlbum($parentAlbumId, $name, $title, $summary, $description, $keywords) with the $parentAlbumId=$album->getID() being the id of the newly created album? so the code would look something like:

Quote:
$name = 'Your Public Album';
list ($ret,$pub_album)=GalleryCoreApi::createAlbum($album->getID(), $name, '', 'This album is viewable by Everyone','', '')
if ($ret->getErrorCode() & ERROR_COLLISION) {
$albumName .= '_';
} else {
return $ret->wrap(__FILE__, __LINE__);
}
list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($pub_album->getId());
if ($ret->isError()) {
return $ret->wrap(__FILE__, __LINE__);
}

/* Set owner.. */
$pub_album->setOwnerId($user->getId());
$ret = $pub_album->save();
if ($ret->isError()) {
GalleryCoreApi::releaseLocks($lockId);
return $ret->wrap(__FILE__, __LINE__);
}
$albumId = $pub_album->getId();

/* Set permissions.. */
$ret = GalleryCoreApi::removeItemPermissions($albumId);
if ($ret->isError()) {
GalleryCoreApi::releaseLocks($lockId);
return $ret->wrap(__FILE__, __LINE__);
}
$ret = GalleryCoreApi::addGroupPermission($albumId, $core['id.adminGroup'], 'core.viewAll');
if ($ret->isError()) {
GalleryCoreApi::releaseLocks($lockId);
return $ret->wrap(__FILE__, __LINE__);
}
ect....

In the long run I also want to add some pictures to users albums when it is created. If there is a more efficient way then hacking the useralbum module I am all ears.

Thanks in advance

 
elzorro

Joined: 2006-06-28
Posts: 14
Posted: Fri, 2007-01-12 21:18

Hey, Did you ever come up with a solution for this? This is something Im looking to do. Hope you can point me in the right direction.

Thanks in Advance

 
nmahlin

Joined: 2005-09-26
Posts: 19
Posted: Thu, 2007-01-18 18:16

Have a look at http://gallery.menalto.com/node/26165. To add items to existing albums you can use a function like:

Quote:
function addItemToAlbum($userId,$fileName, $itemName, $title, $summary,$description, $mimeType, $albumId, $symlink)
{
//passing in an album id lets make sure it exists
list ($ret, $album) = GalleryCoreApi::loadEntitiesById($albumId);
if ($ret && !($ret->getErrorCode() & ERROR_MISSING_OBJECT)) {
$msg = $ret->getAsText();
exit;
}
//write lock on album so we can add item
list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($albumId);
//check for error
if ($ret) {
$msg = $ret->getAsText();
exit;
}
//using gallery core api to add the item
list($ret,$item) = GalleryCoreApi::addItemToAlbum($fileName,$itemName, $title, $summary,$description, $mimeType, $albumId);
if ($ret) {
$msg = $ret->getAsText();
exit;
}
//if item name exists add _ to it
if ($ret && $ret->getErrorCode() & ERROR_COLLISION) {
$itemName .= '_';
}
//save and release lock
$ret = $album->save();
if($ret) {
exit

}
//dont forget to release the lock on the album!
$ret = GalleryCoreApi::releaseLocks($lockId);
if ($ret) {
$msg = $ret->getAsText();
exit;
}

list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($item->getId());
if ($ret) {
$msg = $ret->getAsText();
exit;
}

/* Set owner for item and permissions I just want users to comment and simple edit do whatever you want.. */
$item->setOwnerId($userId->getID());
if ($ret) {
$msg = $ret->getAsText();
exit;
}
//add whatever permissions
$ret = GalleryCoreApi::addUserPermission($item->getId(), $userId->getID(), array('comment.view', 'comment.add', 'core.viewAll','simple.delete','simple.edit_all'));
if ($ret) {
//if error release the lock
GalleryCoreApi::releaseLocks($lockId);
$msg = $ret->getAsText();
exit;
}

$ret = $item->save();
if ($ret) {
GalleryCoreApi::releaseLocks($lockId);
$msg = $ret->getAsText();
exit;
}
//i want to return the item id to do other things with it
$itemId = $item->getId();
$ret = GalleryCoreApi::releaseLocks($lockId);

if ($ret) {
$msg = $ret->getAsText();
exit;
}
$itemId = $item->getId();
return $itemId;
}

Hope that answered your question. What do you want to do exactly?

 
nmahlin

Joined: 2005-09-26
Posts: 19
Posted: Thu, 2007-01-18 18:34

This thread is recently active and the code is better.

http://gallery.menalto.com/node/32529