1 album per user...

skicrave

Joined: 2002-10-25
Posts: 89
Posted: Wed, 2003-01-08 07:15

I've been looking into this recently, but I'm stuck now. I want to limit each user to one gallery only. I have no idea what structure is used in the flat files, so it would be pretty tough to parse through and see if a user owns a gallery.

Can anyone think of an easier way of doing this (short of waiting for SQL in G2 :wink: )?

 
beckett
beckett's picture

Joined: 2002-08-16
Posts: 3474
Posted: Wed, 2003-01-08 07:41

Straightforward enough.

In classes/User.php (i.e. the Abstract_User object), just create yourself a new boolean variable up there at the top, call it whatever you like, say "$albumCreated" or something.

Now make two new functions thusly to get and set this value (to preserve the "black box").

function setAlbumCreated($albumCreated) {
$this->albumCreated = $albumCreated;
}

function getAlbumCreated() {
return $this->albumCreated;
}

Now add a line in create_user.php to the tune of:
$tmpUser->setAlbumCreated(FALSE);
to initialise this to no album created. (It'll be obvious where to put it).

Now, when the "new album" code is called, in do_command.php ("new-album"), you can check the $gallery->user->getAlbumCreated() to see if it's true or false, and don't proceed if it's true. Then set it to true after the album's created if it was initally false.

Then go to delete_album.php, and once it's deleted, set the value back to false.

In fact, you could probably automatically call the new album code when the user is created in create_user.php. And then only delete the album when the USER is deleted., and remove the functionality of the "new album" and "delete album" buttons entirely! But this is up to you.

Hope that gives you some ideas,
-Beckett (

)