User Albums: Create a personal album for new users

rhunt6562
rhunt6562's picture

Joined: 2013-12-08
Posts: 10
Posted: Thu, 2014-01-09 03:21

Can anyone tell me how to script this to a sub-directory of the root.

SCRIPT: ->where("parent_id", "=", item::root()->id)

ACTUAL PATH: /index.php/User-Photo-Galleries/*

"If a smile were a virus, no vaccine could suffice to relinquish its speed of travel around the globe of humanity." - Robert Hunt

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Thu, 2014-01-09 03:49
 
rhunt6562
rhunt6562's picture

Joined: 2013-12-08
Posts: 10
Posted: Thu, 2014-01-09 05:57

sorry for the confusion. I already use the module you are suggesting and it works very well. I am now trying to install the User Albums Module so when a user registers it automatically creates an album for them. The module works fine and creates an album on the main page of my gallery, but I want it to create a gallery in an existing gallery (not on the main page.)

My website is http://grandpasspace.com and the gallery I want to have the gallery created in is the "User Photo Galleries." The User Albums script is:

class user_albums_event_Core {
/**
* Create an album for the newly created user and give him view and edit permissions.
*/
static function user_created($user) {
// Create a group with the same name, if necessary
$group_name = "auto: {$user->name}";
$group = identity::lookup_group_by_name($group_name);
if (!$group) {
$group = identity::create_group($group_name);
identity::add_user_to_group($user, $group);
}

// Create an album for the user, if it doesn't exist
$album = ORM::factory("item")
->where("parent_id", "=", item::root()->id)
->where("name", "=", $user->name)
->find();
if (!$album->loaded()) {
$album->type = "album";
$album->name = $user->name;
$album->title = "{$user->name}'s Gallery";
$album->parent_id = item::root()->id;
$album->sort_column = "weight";
$album->sort_order = "asc";
$album->save();

access::allow($group, "view", item::root());
access::allow($group, "view_full", $album);
access::allow($group, "edit", $album);
access::allow($group, "add", $album);
}
}
}

Bob

"If a smile were a virus, no vaccine could suffice to relinquish its speed of travel around the globe of humanity." - Robert Hunt

 
spags

Joined: 2010-03-26
Posts: 120
Posted: Thu, 2014-01-09 07:28

I don't think you don't want $album->parent_id = item::root()->id because that it going to create your new album in the root album (just like you describe). If all you need is a quick hack of code, you would want to replace the item::root()->id part with whatever the album id of your User-Photos-Gallery is.

If you really really want to script it, you are going to need to use ORM to return all the items where the parent_id = item::root()->id and where the item name/stub is User-Photos-Gallery. Then pass the id of the (hopefully) only matching ORM entry into the $album->parent_id part of the code. In the Calendar Import module, I used some code to return a listing of those top-level albums into an array so that should give you a good example to start with. But I suspect you are only after a quick hack.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Thu, 2014-01-09 19:40

just use the id of the album you want to have the album created in.
->where("parent_id", "=", "xx")
where xx is the id of the album you want the albums to be created in.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
rhunt6562
rhunt6562's picture

Joined: 2013-12-08
Posts: 10
Posted: Fri, 2014-01-10 00:44

I tried your suggestion two different ways:

->where("parent_id", "=", "User-Photo-Galleries")

->where("parent_id", "=", User-Photo-Galleries->id)

and neither one created a gallery. The original:

->where("parent_id", "=", item::root()->id)

Does create a gallery, just in the wrong place.

Bob

"If a smile were a virus, no vaccine could suffice to relinquish its speed of travel around the globe of humanity." - Robert Hunt

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Fri, 2014-01-10 01:01

You need to get the ID of the album not the album name.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
rhunt6562
rhunt6562's picture

Joined: 2013-12-08
Posts: 10
Posted: Fri, 2014-01-10 04:09

I thought I had the album ID (g-item-id-4885) but it doesn't work so I must not. Where do I find the correct album id?

Bob

"If a smile were a virus, no vaccine could suffice to relinquish its speed of travel around the globe of humanity." - Robert Hunt

 
spags

Joined: 2010-03-26
Posts: 120
Posted: Fri, 2014-01-10 07:16

Parent_id is an integer representing the album. So in your case use:

->where("parent_id", "=", "4885")

If that doesn't work, then remove the quotes surrounding 4885, but I think the above will do the trick.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Fri, 2014-01-10 10:51

The easy way to find the ID of the album is to go into the album, mouse over the admin dropdown to the edit permissions or organize option and the ID will be the last number on the URL on botom of the browser. So for example I mouse over the 'album options'->organize album and the url is:
http://EXAMPLE.com/gallery3/index.php/organize/dialog/3
the ID of the album is 3.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
rhunt6562
rhunt6562's picture

Joined: 2013-12-08
Posts: 10
Posted: Sat, 2014-01-11 03:11

this did the trick! Thank you very much for your help.

the last thing I have left to do is I'd like to change the Welcome message a new user gets when returning to the site via email link. I found the welcome_message.html.php file and changed it to what I want, but a new registration still gets the original message. Any idea whats going on, or do I have the wrong file?

"If a smile were a virus, no vaccine could suffice to relinquish its speed of travel around the globe of humanity." - Robert Hunt

 
spags

Joined: 2010-03-26
Posts: 120
Posted: Sat, 2014-01-11 08:19

I'm guessing you are using the Register module. If its the email I think you are talking about, I suspect you need to modify register_welcome.html.php