Sort by Position Sort by Position
 

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

Sort by Position

Started by Brendan, February 11, 2007, 06:29:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brendan

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

choc-a-holic

I use sorting by position and I have found problems with sort by position as well.  I choose this option as we have more than one camera and therefore viewing by filename doesnt work.  I have found viewing by file date doesn't work either when you have a number of cameras taking photos which have different dates and times (this happened in the weekend with photos being taken by people from different countries and therefore different times set on their cameras)!  I have now got a program which allows me to sort and rename all the photos before uploading them.  I did think about changing back to sort by filename, however older albums will be impacted by this change I believe.  I would love to be able to set the sort order by album rather than the whole site.

My website host company sets cpu limits which I always reach with batch add.  This means that I have to do a batch add for around every 15 photos.  I have just added 183 photos into one album today in the correct order I want to view them.  Unfortunately when I view the album they are not in the order I uploaded them in.  The "batch add" option seems to randomly add the photos to the top or the bottom of the list.  I get so frustrated as it is such a slow process to sort them one by one using sort my pictures (would love to see a better sorting tool which allows you to move more than 1 photo at a time)! 

I am not sure how your fix will help me, and also not sure if it can fix the problem I have now or is only a fix for future uploads.  Your input would be greatly appreciated.

As a slight plus ... today I have found a way to increase the number of photos I can batch add to around 30!

Brendan

If you haven't sorted your pictures yet, then position is set to 0 for all your pics.  The current order is looking at only position.  The change that I recommend adds pic (picture ID) to address that.  If you had sorted, you'd have pics with 100, 101, .....  and so on.  All new pics get a 0 for position.  Instead of oldest to newest, you're getting just added, followed by oldest to newest previously sorted.  Added pid to the sort order adds pics with 0 to the mix. 

Put this code in and see if it helps you

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',


Change the album sort to position asc to get the newest first. 

What I really want to do is add sorting options to the sorting page.  Hard coding an order by in picmgr is limiting.  Idealy, there would be an option in the page to change that sort order on the fly.  I'll see what I can do with that.

Let me know how you make out.


Brendan

I finally made added the functionality that I wanted to put in originally. 

If you have ever used the page to sort your pictures or if you sort by position at all, you know that the order of the pictures is hard coded.  You can change the order of the pictures (that's the point of the page), but you start with a sort order that might cause you a lot of work.  In the first post in here, I gave a slightly better option to sort, but it still wasn't the right way.  I've had a couple of days write it up the way I wanted.  I don't know php, so it was a learning process and I'm sure any php developer here can make changes, but it works and that's what I was going for.

I made so many changes to picmgr.php that I'm just attaching a new one.   To try this out, you only have to add two lines to your language file (english.php in my case) and to copy in this picmgr.php.  SAVE A COPY OF YOUR picmgr.php BEFORE REPLACING IT WITH THIS ONE.  You can always get a new one from a fresh install, but save yourself the trouble.

The point of this "mod" is to be able to sort any of your albums however you want quickly and easily in the "sort my pictures" page and then to set your global sort order to sort by position.

Changes:
english.php
in the picmgr.php section under
  'select_album' => 'Select Album', //cpg1.4
add these two lines:
  'select_sort_order_primary' => 'Select Sort Order 1', //cpg1.4
  'select_sort_order_secondary' => 'Select Sort Order 2', //cpg1.4


Copy your picmgr.php and put one from the attached zip in its place.  For simplicity, english.php is also in there in case you want to just copy it in.  Backup your english.php first though.

Please recommend any changes that you'd like to see and general feedback. 

Hope you all find it useful!

noworyz

will this work if I have my default sort set to "Date Ascending" and I would like some albums to be "Date Descending"

Brendan

With this change, your default would change to sorting by position.  In the 'sort my pictures' page, I give you two sorting options.  Sort the albums the way you want them - date (really picture id) ascending, descending, title, filename or position and then when you update the album, the sort order you used is now the position.  The two sorting options are just a quick way to get the pictures in the right order so you don't have to mess with too many individual picture changes.  You still have that option though.