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
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!
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
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.
`
$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.
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