Skip to content

dynamicalbum: let the sort field be configured per album type - #186

Open
martinbogo wants to merge 1 commit into
gregstoll:mainfrom
martinbogo:fix/dynamicalbum-configurable-sort
Open

dynamicalbum: let the sort field be configured per album type#186
martinbogo wants to merge 1 commit into
gregstoll:mainfrom
martinbogo:fix/dynamicalbum-configurable-sort

Conversation

@martinbogo

Copy link
Copy Markdown
Contributor

The date album sorts by creationTimestamp, which is when an item was
added to the gallery rather than when the photo was taken. Those are the
same thing for a gallery filled in one photo at a time, and very different
for one filled by import: bulk-imported items commonly share a single
creation timestamp across thousands of items, which leaves the date album
in no meaningful order at all.

This adds an orderBy.<type> parameter for each dynamic album type,
selectable in Site Admin, so the date album can be pointed at
originationTimestamp (when the photo was taken) where that is the useful
key.

Choices offered: Date added, Date taken, Date modified, Title, Name, View
count, Random.

Backward compatible. The new parameters default to exactly the current
behaviour (creationTimestamp, viewCount, random), and UpdatesAlbum
only overrides its sort when the parameter is set and non-empty, so a
subclass passing an explicit sort is unaffected and an existing install
sees no change until someone changes the setting.

Module version bumped 1.0.3 -> 1.0.4.

Tested on a ~4,300-item gallery built entirely by import, where the date
album was previously in arbitrary order and now sorts by capture date.

🤖 Generated with Claude Code

https://claude.ai/code/session_015pPeWCa9ToJFseWqbPrDH4

UpdatesAlbumView::getChildIds() accepts an $orderBy argument but is only
ever called without one, so the "Latest Updates" album is always sorted
by creationTimestamp - when an item was added to Gallery.

For a gallery built by import that field is close to useless: every item
lands within the same import run, so they share a timestamp and the album
comes back in no meaningful order. On the install this was found on, all
2195 photos carry a 2007 creationTimestamp while their originationTimestamp
- when the photo was actually taken - spans 1999 to 2007.

Add an orderBy.<type> parameter alongside the existing size.<type> and
type.<type>, exposed in the site admin as "Sort By" with the same choices
core already offers for ordinary albums. Defaults preserve today's
behaviour exactly (creationTimestamp / viewCount / random), and an unset
or empty value leaves the caller's argument alone, so the Popular and
Random subclasses that pass an explicit sort are unaffected.

Verified on 2.3.2 / PHP 8.2: with orderBy.date = originationTimestamp the
album returns items in descending date-taken order across every album.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015pPeWCa9ToJFseWqbPrDH4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant