User home galleries
Glooper
Joined: 2005-09-21
Posts: 225 |
Posted: Mon, 2009-07-13 00:22 |
Hi, Is there a way to give a user a home gallery. For instance, some of my clients are wedding photographers. They will make a gallery for each wedding they do and provide login details for that gallery. However when one of their clients comes to the site they would currently have to search for the appropriate gallery and login... a better way would be that they can login and be automatically directed to the right gallery. If this isn't currently available, would it be something that could be written as a add in module.. if so then I'll give it a go at implementing it myself (and of course I'll share the module!) Cheers http://www.gloopics.com Benjamin Albert Smith - Photography |
|
Posts: 7994
How would the flow work? They'd go to the site and have a login page, then after they log in they'd be sent to a specific album? Can they see the other albums? I'm guessing that you could write a module that traps the user_login event and registers a new shutdown event to redirect the user to a specific album. That would probably get you off the ground there. Your module (let's say it's called "xxx") would have a modules/xxx/helpers/xxx_event.php file that contained class Xxx_Event which has a user_login() function which would do something like:
then you create xxx.php in the helpers directory which contains a class called Xxx and a static function called redirect_user() which does:
Where you inject the id of the id you want to redirect to there, instead of 1.
Then your login page is:
http://example.com/index.php/login/html
(that page is unthemed, but we can work on that)
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git | help! vote!
Posts: 225
Hi,
I started work on this module today. So far so good, managed to get the install of the module working with it adding a column to the user database (and removing column when uninstalling). I then managed to add the user_login function as you mentioned. However I am struggling to understand which event too add my redirect_user method to. In the example you give you say show using the system.shutdown... which I don't think is right.
as far as I can tell.. when a user logins the user_login event is called... then after that the server returns some Ajax commands to the login dialog box which causes it to close and then the page underneath will refresh... so I need do the redirection when a user first loads a page... i.e if the page below the login box is a main root gallery. when that page is refreshed after logging in and the user will be redirected to their assigned home gallery.
Is there a gallery.load event or page load event that I can use to redirect only the first time after logging in?
Cheers
Ben
Posts: 7994
Ah, right. The ajax code does this:
Which triggers the dialog box to close and refresh the current page. Perhaps a better approach would be for you to store a value in the session, then subscribe to the gallery_ready() event and when that fires, check the session. If the value you stored is there, delete it from the session and do the url::redirect.
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git | help! vote!
Posts: 225
Cheers for the help bharat. Worked a treat
As promised the completed module is attached as a zip file. just unzip it into your modules directory and fingers crossed it should work!
I created a new menu option to edit the users home pages. I would have liked to have put the control to change the home page in the users edit page but I couldn't do that without changing the user module (which I didn't want to do). But I'm pleased with the way i finally got it to work anyway.
Anyway.. I hope of it's of use to someone else too....
Cheers
Ben
Posts: 7994
Awesome! It would be really great if you created a fork of the gallery3-contrib repo on GitHub and added it there.. that way we can use revision control on it and start getting others involved too. I installed it in my test G3 and it worked fine after I made one tweak. When you refer to database tables in SQL you should wrap it in {curly} braces so that it handles table prefixes properly. So the two database lines in your installer become:
Also in general, we don't want to modify tables from other modules because it can cause that module to break on upgrade. A better way is to create your own table instead and store the data there. You can listen for the user_deleted event to get rid of the rows in your table to keep it in sync.
Finally, I would be happy to create a way to let you get this into the user edit page. The way to do that is to generate an event when we create the form, and then generate an event when we successfully process it. For an example of how this works, look at modules/gallery/helpers/album.php in the get_edit_form() function. Towards the end we call:
Then the tags module in tag_event.php listens for that and has:
So it's adding its own element to the form right there, and then this gets displayed when you edit an album. In the form processing code we trigger a "item_edit_form_completed" event, and then the tag code processes the result of the form.
I've gone ahead and added these same events to the user code:
Try hooking in to those!
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git | help! vote!
Posts: 225
Sorted that out. However...
On those new events not all the required variables were passed in and I had to change the events used to add the information to the form, to call the event earlier so that I could add the user home above the submit button. Also added a user_edit_form_admin_completed which I think you missed out. We're getting there slowly..
I changed the following locally to get it working. Will you be able to update the main gallery repository
user.php - line 83ish? .. changed to pass in the form and moved above submit
user.php - line 60ish? -again moving before the submit and passing in the form
user.php - line 37ish? -again moving before the submit and passing in the form
also added the event
user_edit_form_admin_completed
which is added to line 144 of admin_users
If you are OK with those changes then I'll submit the module into the contribs area.
Cheers
Ben
<a href="http://www.gloopics.com">Benjamin Albert Smith - Photography</a>
Posts: 7994
I made all the changes you suggested.. let me know if there's anything else I missed. Let me know when you submit the code to your fork and I'll pull it into the main repo!
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git | help! vote!
Posts: 225
cool. I grabbed the latest code and tried against that.. seems to be working fine. Though I couldn't create galleries so couldn't test the redirect, though as this was working before it should still be OK. Will retest when the main gallery code is more stable.
I've submitted the code. let me know if there are any problems... I'd not used git before so I might have done something wrong!!
Cheers
Ben
Benjamin Albert Smith - Photography
Posts: 7994
I've pulled your code into the contrib repo-- great work, thanks! For bonus points, you can update your code to conform to our code style: http://codex.gallery2.org/Gallery3:Coding_Standards which will make it easier for me to help you keep the code up to date when I make API changes, etc.
Also.. what error were you getting when creating new albums? Start a new thread for that if you're having a general problem and we'll get to the bottom of it.
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git | help! vote!
Posts: 225
Updated to conform to standards . Must sort out my vim sometime to format tabs properly!
The error I was getting when attempting to add a new album was.
2009-08-02 19:21:46 +12:00 --- error: Uncaught Kohana_Database_Exception: There was an SQL error: Unknown column 'left_ptr' in 'where clause' - UPDATE items SET `left_ptr` = `left_ptr` + 2 WHERE `left_ptr` >= 2 in file C:/Users/User/websites/g3next2/system/libraries/drivers/Database/Mysqli.php on line 142
Cheers
Ben
Benjamin Albert Smith - Photography
Posts: 27300
you need to run the upgrader:
http://codex.gallery2.org/Gallery3:Upgrading
Windows is not supported.
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 7994
Windows isn't supported, but people who write modules for Gallery 3 are supported, so if you have problems I'll do what I can
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git | help! vote!
Posts: 225
Floridave - This was a fresh install from the tip of the trunk sometime last week, rather than an upgrade. Chances are I caught it whilst someone was still developing that module (I was just checking the new methods for my module)... but if not then there might be a bug in the initial table creations. I've been using Beta 2 (with no problems) instead for my client development and will probably wait for beta 3 until I download again.
Yeah, I know it's only supported on linux/unix, ... I'm fine with that .. all my live sites are linux/unix... just not my development box.
Ben
Benjamin Albert Smith - Photography
Posts: 7994
Ah yeah there was a bug in the initial install which I fixed soon thereafter.. you must have updated right in the middle of that. Sorry!
I've pulled in your style changes, thanks! I also made a couple more style tweaks and fixed a minor issue.. look over my additional changes and let me know if you have any questions.
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git | help! vote!
Posts: 225
All looks good to me.. cheers..
Ben
Benjamin Albert Smith - Photography