Suggestions for batch add drop down box Suggestions for batch add drop down box
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Suggestions for batch add drop down box

Started by SamBuca, September 25, 2009, 11:43:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SamBuca

This is for v1.4.x.

I added this to mine and figured it may have a chance at working its way into the official code.  It puts the 5 most recently created albums at the top of the drop down box for batch adding files.

In searchnew.php, insert before line 93 (after the array sort, but prior to the loop to print the select box):

$result = cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} ORDER BY aid DESC LIMIT 5");
        while ($row = mysql_fetch_array($result))
        array_unshift($listArray, array('cat' => 'Recent Albums','aid' => $row['aid'],'title' => $row['title']));
    mysql_free_result($result);


You'll notice 2 things which are hardcoded: the number of recent albums and the name of the "category".  It would need an addition to the language file and perhaps the config if you wanted to change the number of recent albums.

The sorting will reverse the query from the db, meaning that even though we retrieved the albums in descending order (most recent is first), the most recent will actually be at the bottom of the recent albums list.  You could easily remedy that by having a SQL subquery to reverse the results, but that would break it for older versions of mysql (or add another loop to reverse it inside of php).

Also, the alphabetical sorting of the drop down box is nice, but I would rather have it sorted by the album order:

Searchnew.php line 63:

$result = cpg_db_query("SELECT DISTINCT a.aid as aid, a.title as title, c.name as cname FROM {$CONFIG['TABLE_ALBUMS']} as a, {$CONFIG['TABLE_CATEGORIES']} as c WHERE a.category = c.cid AND a.category < '" . FIRST_USER_CAT . "'");

BECOMES

$result = cpg_db_query("SELECT DISTINCT a.aid as aid, a.title as title, c.name as cname FROM {$CONFIG['TABLE_ALBUMS']} as a, {$CONFIG['TABLE_CATEGORIES']} as c WHERE a.category = c.cid AND a.category < '" . FIRST_USER_CAT . "' ORDER BY c.cid,a.pos ASC");


To have it take effect, don't do the sort on line 93.  You could add a config option to sort by category/album or alphabetically and have that option choose whether to do the array sort on line 93.  Obviously the modified SQL statement does not affect the alphabetical listing because that will re-sort the array.

Another possibility is to sort by category name (c.name) rather than the category ID (c.cid), then you'd end up with the categories being alphabetical, but the albums themselves are in the proper order.

SamBuca

Typo in my post.  The second to last paragraph that talks about alphabetical or category/album sorting should say line 91.  I was looking at a modified version of the file.  This is line 91 that sorts the array alphabetically (which would become conditional if this was added to the config):

searchnew.php line 91

        // Sort the pulldown options by category and album name
        $listArray = array_csort($listArray,'cat','title');