Posted by vistree on January 8, 2009 at 8:08pm
Jump to:
| Project: | Flash gallery |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
Hi, how is the order of the pictures defined?
I need an ascending order by filename inside the simpleviewer.
Is this possible? Or can I do it by uploading files in a special order?
Regards
vistree
Comments
#1
Did you ever find out how to reorder the images? They seem to be ordered by original post date.
#2
They are ordered by sticky and the node's created date.
You can see the SQL query in the flash_gallery_xml function.
I guess it would be nice to have the order as an option.
I'll look into adding this as a feature request.
cheers,
Dan
#3
That would be great. Thanks
#4
While this feature isn't implemented, you can help yourself by changing the SQL-query in the file flash_gallery.module: search for the function flash_gallery_xml and replace "
ORDER BY n.sticky DESC, n.created DESC" with the code you need (in my case "ORDER BY n.title ASC").Greetz
Jürgen
#5
I am trying to tweak the SQL-query found on line #172 of the flash_gallery.module (in the flash_gallery_xml function) where it orders the images by sticky and the node's created date.
I created a field called field_image_order in the image content type and would like to use this field to do a numerical sort.
My problem is that I am just learning MySQL and the syntax for the query doesn't seem to jive with what I'm learning. I know I need to do some sort of a JOIN but can't seem to figure out the proper syntax. I'm getting confused with n.nid, t.nid, n.status...
This is the existing query in the flash_gallery_xml function I want to change:
$result = db_query(db_rewrite_sql("SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d ORDER BY n.sticky DESC, n.created DESC"), $tid);
I would like to add the following table and field to the above query and use it to sort order on.
Table name: content_type_image
Field name: field_image_order_value
then ORDER BY field_image_order_value ASC
Any help with this would be GREATLY appreciated!!
Thanks,
Hal
#6
Hi Hal,
Great idea to use a CCK field to define the sort order... that makes good sense.
I decided to give this a try, even though I'm no expert at constructing complex SQL queries.
I realized that if one constructs the query they want with views, the views ui will show you the actual SQL it uses. I figured this would be a good place to start, and so I made a test view that incorporated my cck field for sorting (I called it field_image_sort_order) and setup all my sorting/filter options that I wanted to apply to my flash gallery (basically sort by my cck sort field first, and then changed date). This is the query views spit out:
SELECT node.nid AS nid, node_data_field_image_sort_order.field_image_sort_order_value AS node_data_field_image_sort_order_field_image_sort_order_value, node.changed AS node_changed FROM node node INNER JOIN term_node term_node ON node.vid = term_node.vid LEFT JOIN content_type_image node_data_field_image_sort_order ON node.vid = node_data_field_image_sort_order.vid WHERE (node.type in ('image')) AND (term_node.tid = %d) ORDER BY node_data_field_image_sort_order_field_image_sort_order_value ASC, node_changed DESC
It ain't pretty, and I don't necessarily understand it, but it does return the correctly sorted image set when %d is substituted with the image gallery term id.
Ok, so plugging this into the flash gallery module code (this took some trial and error) I finally got:
// RJMOD - Implement custom sort order
$result = db_query("SELECT node.nid AS nid, node_data_field_image_sort_order.field_image_sort_order_value AS node_data_field_image_sort_order_field_image_sort_order_value, node.changed AS node_changed FROM node node INNER JOIN term_node term_node ON node.vid = term_node.vid LEFT JOIN content_type_image node_data_field_image_sort_order ON node.vid = node_data_field_image_sort_order.vid WHERE (node.type in ('image')) AND (term_node.tid = %d) ORDER BY node_data_field_image_sort_order_field_image_sort_order_value ASC, node_changed DESC", $tid);
while ($nid = db_fetch_array($result)) {
$node = node_load($nid['nid']);
etc...
Note that I had to call the query from inside "db_query()" as opposed to "db_query(db_rewrite_sql())", otherwise weird things happened. Also, and this one threw me for a loop for a while, the line "$node = node_load($nid);" (just below the query) needed to be changed to "$node = node_load($nid['nid']);". I think this is because the new db_query has multiple selects, while the original query only had one... so we have to be specific about which part of the resulting array (from db_fetch_array()) to use to get the image node id.
So anyway... that's what I'm using. I've not really stress-tested it, but so far it *appears* to be working alright. Hope that's useful to someone.
Cheers,
Ryan
#7
With the help of Jay Matwichuk on the Module Development forum, this is the query I am currently using. It is a good temporary fix. I would love to see a feature incorporated into the module that would allow drag and drop sorting (like when reordering blocks etc).
$result = db_query
(
db_rewrite_sql
(
"SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid JOIN {content_type_image} AS cti ON cti.nid = t.nid
WHERE n.status=1 AND n.type='image' AND t.tid=%d ORDER BY cti.field_image_order_value ASC"), $tid);
Thanks for your input Ryan.
Hal
#8
can the images be ordered by weight in anyway? A drag and drop ordering system would only make sense.