Hey everyone. I put together the mod for sorting by position, but have been busy for the last couple of years with kids and didn't upgrade to 1.4 until yesterday. Glad to see that position sorting made it from a mod to the release! Sorting isn't working as cleanly as it should though, so I'm offering a fix, but not recommending it as a mod yet on purpose. I'd prefer to see how people are using sort by position and to see if this will benefit everyone before saying the changes should be put into a mod. If this topic should be moved, please do so. I wasn't sure where it would fit best.
When I put the mod together for sorting by position, I was using xp_publish.php to upload pictures. Now, I need to get a ton of pics loaded and started using "batch add files". Very nice feature! But, batch loading doesn't work with position the way I intended. xp_publish was giving the newest pictures the next highest number. Batch loading just gives a position of 0 to all new files, which is breaking the order. I've been looking in the forum and see that other people are having this problem. The best fix, which people are doing, is to go in and resort every time you load pictures. That's an unnecessary hassle though.
I already put a fix in for myself, so wanted to share it. There is a catch though. As I said, the way I intended it, newest pictures were getting the next number assigned. If your last picture has a position of 300, it would give the next one 301. Thinking about it now, that's not a great way to do it. It requires that all new ways to get pictures loaded figure out the new position. Having a default value of 0 is more logical. That's what "batch add files" is doing.
I put in a couple of basic fixes and went into my table and set all positions to 0 to start over with the new method. It works very well now and will be easier for developers and users. That being said, I've only been on 1.4 for a day and may not have thought of everything. I also saw postings on linking pictures, which this doesn't address.
The changes:
picmgr.php - change
$result = cpg_db_query("SELECT aid, pid, filename FROM {$CONFIG['TABLE_PICTURES']} WHERE aid = $aid ORDER BY position ASC, pid");
to
$result = cpg_db_query("SELECT aid, pid, filename FROM {$CONFIG['TABLE_PICTURES']} WHERE aid = $aid ORDER BY position ASC, pid DESC");
include/functions.inc.php - change
'pa' => 'position ASC',
'pd' => 'position DESC',
to
'pa' => 'position ASC, pid DESC',
'pd' => 'position DESC, pid ASC',
xp_publish.php - remove and just let new pictures have 0
$position = 0;
// Get position
$result = db_query("SELECT position FROM {$CONFIG['TABLE_PICTURES']} WHERE aid='$album' order by position desc");
if (mysql_num_rows($result) == 0) {
$position = 1;
} else {
$row = mysql_fetch_array($result);
mysql_free_result($result);
if ($row['position']) {
$position = $row['position'];
$position++;
}
}
xp_publish.php - Change
$result = add_picture($album, $filepath, $picture_name, $position, $title, $caption, $keywords, $user1, $user2, $user3, $user4, $category);
back to:
$result = add_picture($album, $filepath, $picture_name, $title, $caption, $keywords, $user1, $user2, $user3, $user4, $category);
I'm curious to know what people think of sorting by position overall and if it being used. I'm also like to know if people are experiencing the issues that I'm addressing above.
-Brendan