deleteAlbum help

Hi,
I am trying to delete all albums (dyn only) in toplevel album called 'gallery'
in a function in a while loop, but I do not seem to be able to get it to work.
Can someone help me ?

I try this:

$_zp_current_album = new Album($_zp_gallery, "/gallery");
while (next_album()):
$_zp_current_album->deleteAlbum() ;
endwhile;

It does seem to clear the content of gallery but leave gallery itself alone
Help anyone ?

Thanks

Comments


  • $_zp_current_album = new Album($_zp_gallery, "/gallery");

    This is going to attempt to make an album named "gallery". Unless you actually have a folder of that name in your albums folder the instantiation will fail. The result of this will be NULL so that the next_album() link you have following will do nothing.

    I don't know where you have put this code. Generally the $_zp_current_album variable and the next_album() loop are used only on the front end. I am not so sure it is a good idea to put such deletion code on your font end pages--no telling who might visit that URL and zap your gallery (presuming the code actually worked.)

    So probably what you want is:
    `
    $gallery = new Gallery();
    $albums = $gallery->getAlbums();
    foreach ($albums as $album) {
    $albumobj = new Album($gallery, $album);
    $albumobj->deleteAlbum();
    }
    `
    Of course, this will clean out your entire gallery. So if that is not what you wish to do, don't try this at home!
  • acrylian Administrator, Developer
    Why don't you just use FTP to delete the required albums?
  • thanks, but it is actually a subgallery called 'gallery' I would like to clean out
    not the entire Gallery. How would that work ?
    I am using FTP at the moment, but unless I die DB refresh inbetween the deletion and recreation of my random dyn galleries the shuffle of the order doesnt work but everything stays the same.
    But I would like the order of my dyn album to shuffle every 24h
  • Are you wanting the gallery to be deleted just so it gets re-created in a different order? Surely there must be a more efficient way to do this. Are you trying to change the order that the dynamic sub-albums are displayed in, or the order of the images in each dynamic album?

    I wouldn't think re-creating the albums would actually change the order. Perhaps adding an Image Display Order option for "Random" would be a better, more efficient route to take. Especially if you want to preserve database information on those images, such as descriptions, ratings, and comments.
  • Deleting the albums and recreating them will likely have no impact on the order that they appear in. If it is just ordering that you are concerned with, set the sort order to what you want. You can even set it to manual and change the `sort_order` field in the database with simple query statements.

    `
    $target = new Album)$_zp_gallery, 'gallery');
    $id = $target->get('id'));
    $sql = 'UPDATE '.prefix('albums').' SET sort_order=RAND(9999) WHERE id='.$id;
    query($sql);
    `
    Note, the database fields must be encased in "peck" marks, the same ones used to indicate code on this forum (thus I can't show them.)

    Absolutely no need to delete anythign unless you really want it gone. In that case it would make no sense to recreate it.

    BTW, the moral of this thread--always ask about what you want to accomplish, not some substep in the process you have come up with.
  • Looks like this might become a feature request for a random gallery order, or a gallery shuffling plugin :-) Though if breglis wants it only changed every 24 hours, that would have to be implemented as well - perhaps allowing some keywords in a configurable random seed field, such as the current date, so the random number generator sequence would be the same for that period. Of course, that would require not using the newer, crypto-safe RNGs or hardware RNGs. Alternately, an options table value could store the date of the last reordering.
  • yea this is partly of what I am trying to do.
    I actually raised a request to have a random gallery order some months back.
    Next to that I have build functionality to auto generate dyn albums based on tags I set on image import. To give a quick and varied choice to the viewer I query my DB for all combinations of tag (total max of 2 tags) searches that turn 9 or more images and then create dynalbums for that

    check out my breadcrum select box here : http://www.bregler.net/gallery and then choose 'CHINA' this will then show all images with China but then the breadcrumb select also offers all remaining tags to further limit

    I created this SQL :

    SELECT count( * ) AS hitcount, t3.name, t4.name
    FROM (
    SELECT DISTINCT t1.objectid, t1.tagid AS tag1, t2.tagid AS tag2
    FROM zp_obj_to_tag AS t1
    LEFT JOIN `zp_obj_to_tag` AS t2 ON t1.objectid = t2.objectid
    AND t2.type = 'images'
    WHERE t1.type = 'images'
    )dbr
    LEFT JOIN zp_tags t3 ON dbr.tag1 = t3.id and ascii(t3.name) < 95
    LEFT JOIN zp_tags t4 ON dbr.tag2 = t4.id and ascii(t4.name) > 95
    LEFT JOIN zp_images AS i ON dbr.objectid = i.id
    WHERE title IS NOT NULL
    GROUP BY t3.name, t4.name
    having hitcount > 9 order by RAND()

    this will create a random order if DB the old album is deleted from DB first. Otherwise
    china_portraits.alb which got deleted via FTP just got replaced by a new china_portraits.alb without that the database 'noticed'
    I have also created a 'cronjob'-ish function to run every 24h to do the above
  • acrylian Administrator, Developer
    Please open always a ticket if you really want to make a feature suggestion, otherwise we really forget about such things even for consideration.
Sign In or Register to comment.