Ordering file sets?
Permalink
Hey,
Is it possible to sort the order of files in a file set yet? Will this be coming soon?
Otherwise, I'm guessing that file sets are currently sorted in code, by title, date, or other information?
Thank you!
Is it possible to sort the order of files in a file set yet? Will this be coming soon?
Otherwise, I'm guessing that file sets are currently sorted in code, by title, date, or other information?
Thank you!
I have exactly the same question. But it's a bit boring to edit each file. So i'm developping a single page where you can sort your file with the jquery sorting grid (http://jqueryui.com/demos/sortable/#display-grid). I have some problem now but if you have some tips i will happy to know because i need to recreate a table with :
fileID | filesetID | filePlace
and i don't know if it's a right way.
I don't know too if it's a project of the core team to develop that.
fileID | filesetID | filePlace
and i don't know if it's a right way.
I don't know too if it's a project of the core team to develop that.
You should go for it -- Concrete5 is an open source project, so anyone is welcome to contribute. I'm not sure if it would be integrated into the core system, but it could at least be made available to people through the marketplace or as a download right here from the forum.
I'd be happy to help you out if you'd like. In answer to your question about the database table, I think those are the fields you want, but I'd call them "fID", "fsID", and "position" so as to be consistent (fID and fsID are how those fields are referred to in the core system and in most blocks, and position seems to be a standard name for a sorting field).
-Jordan
I'd be happy to help you out if you'd like. In answer to your question about the database table, I think those are the fields you want, but I'd call them "fID", "fsID", and "position" so as to be consistent (fID and fsID are how those fields are referred to in the core system and in most blocks, and position seems to be a standard name for a sorting field).
-Jordan
Just been having this exact issue.. so hacked it a bit. This is by no means an ideal solution but it works well..
So, say you've loaded your files into an array called $filelist - for this I used the code from the slideshow block.. In my controller it looks more or less like this..
Then in view.php I put this in (the site I got the subval_sort code from said it's not really good to use this on large arrays but I've not seen an issue up to 100 elements yet..
for descending sorts change the asort($b) to arsort() or whatever sorting function you need.
Hope this makes sense.
hugo
So, say you've loaded your files into an array called $filelist - for this I used the code from the slideshow block.. In my controller it looks more or less like this..
$fs = FileSet::getByID($this->fsID); $fileList = new FileList(); $fileList->filterBySet($fs); //$fileList->sortByAttributeKey("fID"); $files = $fileList->get(1000,0); $filelist = array(); $filelist['groupSet'] = 0; $filelist['url'] = ''; $filelists = array(); $count = 0; foreach ($files as $f) { $fp = new Permissions($f); if(!$fp->canRead()) { continue; } $filelist['id'] = $count; $filelist['fID'] = $f->getFileID();
Viewing 15 lines of 23 lines. View entire code block.
Then in view.php I put this in (the site I got the subval_sort code from said it's not really good to use this on large arrays but I've not seen an issue up to 100 elements yet..
function subval_sort($a,$subkey) { foreach($a as $k=>$v) { $b[$k] = strtolower($v[$subkey]); } asort($b); foreach($b as $k=>$v) { $c[] = $a[$k]; } return $c; } $filelist = subval_sort($filelist, 'fileName');
for descending sorts change the asort($b) to arsort() or whatever sorting function you need.
Hope this makes sense.
hugo
I would love for this feature to be added (a user-friendly interface in the File Manager for sorting photos within a set).
In the meantime, I've figured out a way to kinda-sorta achieve this in a hacky way for my own blocks (won't work for other blocks like Slideshow or any gallery add-ons):
Create a file attribute called "file_sort" (or whatever), make it the "number" type, then in your block's controller code you can retrieve the files from the set in that order by doing this:
From the file manager, you will need to click on each image in a set and choose "Properties", then set a number for each file. Unfortunately this is kind of clunky and not very user-friendly (although in my case it was better than having to manually place a bunch of image blocks on each page). The other big downside to this is that there is only one number for each file, so it only really works when the file is only in 1 file set.
Another idea I had that would address these drawbacks, but haven't actually implemented yet (because it would be rather time-consuming and I haven't had the need) is to code your block's add/edit form so that the user chooses a file set, then all of the files from that set are displayed in your add/edit form, and you provide a UI to sort them (text boxes with numbers or drag-n-drop), then save the positions on a per-block basis to a database table. If new files were added to the set after sorting was saved, they could just be put at the end I suppose.
Good luck!
-Jordan Lev