Default user album

buckrogers

Joined: 2007-04-05
Posts: 3
Posted: Thu, 2007-04-05 23:21

This was posted in the general troubleshooting forum, but I now think it is an integration question.

I have gallery integrated into a very customized CRE Loaded. The integration works fine for the most part. I use UserAlbums to create a new album when the user is added. My problem is, when the user logs in, he gets to the root album, not his own album.

I'm still stepping through the code, but can use some help. Accessing G2 directly works fine - after the login my user is redirected to his correct album. So it must be something in my integration code that I'm missing

Any pointers will be helpful. Thanks!

 
buckrogers

Joined: 2007-04-05
Posts: 3
Posted: Sat, 2007-04-07 23:03


Ok I figured this out. Hopefully it will help someone else cause I see many similar posts with no answer.

The integration code does not display the default user album when using the User Album module. I used two files, g2embed.php* and includes/g2embed_inc.php* (assuming you have the integration code setup already).
* Substitute with you own names.

This code may not be the best, but you'll get the idea...

In g2embed.php:

$data = galleryLogin(array('username' => $username));

In includes/g2embed_inc.php

function galleryLogin($args) {
  global $g2Uri, $embedUri, $gallery;
  $data = array();

  $ret = GalleryEmbed::init(array('g2Uri' => $g2Uri, 
			    'embedUri' => $embedUri,
			    'activeUserId' => $args['username']));
  if ($ret) {
    $data[error] = "An error occurred during user initialization <br>";
    $data[error] .= $ret->getAsHtml();
    return $data;
  } 
  
  // Before initializing the user session, let's get the user's default album:
  // First return array with all Gallery user data in Guser
  list ($ret, $user) = GalleryCoreApi::fetchUserByUsername($args['username']);
  if ($ret && !($ret->getErrorCode() & ERROR_MISSING_OBJECT)) {
    $data[error] = "An error occurred <br>";
    $data[error] .= $ret->getAsHtml();
    return $data;
  }
  // Now return the user's default albumID
  list ($ret, $userAlbumID) =
    GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $user->getId());
  if ($ret) {
    $data[error] = "An error occurred <br>";
    $data[error] .= $ret->getAsHtml();
    return $data;
  }
  //Now set the default userAlbumID
  $gallery->setConfig('defaultAlbumId', intval($userAlbumID));
  $gallery->setConfig('breadcrumbRootId', intval($userAlbumID));

  $data = GalleryEmbed::handleRequest();
  return $data;
}

 
buckrogers

Joined: 2007-04-05
Posts: 3
Posted: Sat, 2007-04-07 23:04

Looks better now, the PHP tags messed it up before. This is using the CODE tags...