G2 Imbed: Adding user to Group

hjho

Joined: 2005-10-22
Posts: 15
Posted: Sun, 2007-02-11 02:02

I'm trying to do on-the-fly user creation via an external PHP script. At the same time I would like to add the user to a predefined G2 group (e.g. "TRIAL"). From the threads I've read so far my understanding is this:

1. We need to specificy an External Username (in addition to the G2UserName) for every G2 User that we create (which are identical in my case).
2. Likewise, we need to specificy an External Groupname mapping to an internal G2 Groupname, ONLY IF we intend to map my newly created user to that G2 Group. i.e. there is NO WAY for me to assign an externally created user (via the Embed API) to an existing G2 group, without going through this process.

Are these assumptions correct?

Assuming they are, I tried to create a external group ("TRIAL") mapping to an existing G2 group ("TRIAL"), but it returned me the following error:

Quote:
ERROR: Unable to create group [TRIAL]
Error (ERROR_COLLISION)

* in modules/core/classes/GalleryGroup.class at line 109 (GalleryGroup::error)
* in modules/core/classes/GalleryEmbed.class at line 495 (GalleryGroup::create)
* in www/g2api.php at line 107 (GalleryEmbed::createGroup)
* in www/g2groupcreate.php at line 5

My code looks like this:

Quote:
# CREATE EXT GROUP TO g2 Group mapping

function g2creategroup ($ext_groupname,$g2_groupname) {
$ret = GalleryEmbed::init(array('g2Uri' => '/var/www/myalbum.sg/gallery2',
'embedUri' => '/main.php',
'activeUserId' => '',
'fullInit' => true));

$ret = GalleryEmbed::createGroup($ext_groupname,$g2_groupname);

GalleryEmbed::done();

if ($ret) {
print "ERROR: Unable to create group [$ext_groupname] <br>";
print $ret->getAsHtml();
exit;
} else {
echo("creted group $ext_groupname <br>");
};
}

The fuction is basically called by :

g2creategroup('TRIAL','TRIAL');

Is there something I did wrong?

 
hjho

Joined: 2005-10-22
Posts: 15
Posted: Sun, 2007-02-11 13:42

I may have seem to have answered my own question. It seems that when I create an external group, the 'internal' G2 group name must not already exist. I could remove the internal group and recreate it from the Embed script. However this may be a problem is the existing g2group already has many members in it.

Is there another way to associate an exernally created user with an internal g2 group?

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sun, 2007-02-11 14:09
list( $ret, $user ) = GalleryCoreApi::loadEntityByExternalId( $GL_uid, 'GalleryUser' );
    $G2_uid = $user->getId(); 
    $res = GalleryCoreApi::addUserToGroup( $G2_uid, 3); //G2 admin groupid is 3

Hope this helps :)

-s

FlashYourWeb and Your Gallery

 
hjho

Joined: 2005-10-22
Posts: 15
Posted: Mon, 2007-02-12 14:52

Thanks. I will try that.

Is there a way to use the GroupName instead of the numeric group ID?

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Tue, 2007-02-13 00:52
 
hjho

Joined: 2005-10-22
Posts: 15
Posted: Sat, 2007-02-17 08:05

Thanks suprsidr. I've decided to just re-create my groups.