I love the neat ordering capabilities of the nodeorder module, but I originally picked it up to be able to easily rearrange image nodes for galleries we do. Specifically, images galleries that will be filtered through the flash_gallery module. I can set the image_gallery "category" (taxo) to be orderable, and order the images within, but if I go ahead and actually View the gallery, they're in reverse chronological order, the way they always are. Same with the Flash Gallery.

Is this right? Did I skip a step? And is there anyway to hack something so it will carry through to the flash gallery?

Comments

marcp’s picture

What does the data look like in the term_node table for the tid that you are ordering within?

Offlein’s picture

Apologies, didn't see your response until now:

Here's what I get:

+------+------+---------------+
| nid | tid | weight_in_tid |
+------+------+---------------+
| 2939 | 2452 | 2940 |
| 2940 | 2452 | 2977 |
| 2974 | 2452 | 2976 |
| 2975 | 2452 | 2974 |
| 2976 | 2452 | 2939 |
| 2977 | 2452 | 2975 |
| 2978 | 2452 | 2978 |
| 2980 | 2452 | 2980 |
| 2982 | 2452 | 2982 |
| 2983 | 2452 | 2983 |
| 2984 | 2452 | 2984 |
| 2985 | 2452 | 2985 |
| 2989 | 2452 | 2989 |
| 2990 | 2452 | 2990 |
| 2991 | 2452 | 2991 |
| 2993 | 2452 | 2993 |
| 2994 | 2452 | 2994 |
| 2995 | 2452 | 2995 |
| 2997 | 2452 | 2997 |
| 2998 | 2452 | 2998 |
| 2999 | 2452 | 2999 |
| 3000 | 2452 | 3000 |
| 3002 | 2452 | 3002 |
| 3003 | 2452 | 3003 |
| 3004 | 2452 | 3004 |
| 3005 | 2452 | 3005 |
| 3006 | 2452 | 3006 |
| 3007 | 2452 | 3007 |
| 3008 | 2452 | 3008 |
+------+------+---------------+
29 rows in set (0.00 sec)

Weird, because I can see the weight changing as I move things up and down, but it doesn't affect how the actual listing. Perhaps I'm just viewing it in the wrong place?

Specifically, I am looking at /taxonomy/term/2452. Even on that page I am given the opportunity to move the nodes up and down, but it seems to simply not be organized by the weight.

If that's the issue, then I guess I need to somehow make /taxonomy/ term listings aware of how to organize these things. I hope that we can get that working it somehow ports easily to the image galleries, too.

marcp’s picture

You'll need to look at /nodeorder/term/2452 if you want to see the ordered nodes. Nodeorder implements hook_term_path() which should, assuming your other modules are playing nice, cause any Taxonomy links to link to /nodeorder/term/TID. I haven't looked at the Gallery/Flash Gallery code, but I bet they aren't calling taxonomy_term_path() when creating links to terms -- instead they are probably hardcoding '/taxonomy/term'. $tid or something like that...

Can you dig further into this?

Offlein’s picture

For you, anything. I'm swamped here right now, but I'll get to it hopefully tomorrow or the day after.

marcp’s picture

Thanks, Jewcy. I want to help with this, and I'll give you as much support as I can, but I'm slammed too...

Marc

halftone’s picture

Was any progress made on this please? I can't see any way to use image_gallery with nodeorder at present. As far as I can work out after a day of staring blankly at code I only slightly understand, it's the image module (and/or image_gallery component) that needs revision.

Being able to set an explicit order for images seems absolutely fundamental to me, for some purposes - a narrative exhibit or similar. With Drupal 4.6 I used a mess of hacks to order by name (http://drupal.org/node/119052 - never worked properly with multiple taxonomies), and having now upgraded to 4.7 was hoping nodeorder would finally help. Surely someone must have addressed this?

Or should I raise this as a feature request re image module, since as far as I can see nodeorder works exactly as designed, setting all the weight_of_tid values, but image can't use them.

TIA for any help or guidance.

Regards Tony
htttp://tonysleep.co.uk (but offline until I can work something out)

halftone’s picture

I have now made a feature request for image_gallery to support nodeorder http://drupal.org/node/126668

Offlein’s picture

I'm sorry, about a week and a half ago I delved a little deeper into this and sort of figured out what was going on. I made a little hack, actually, and now NodeOrder works with my Flash Galleries. It's amazing.

Of course, the reason is the Flash Gallery module is hard coded to order by n.sticky DESC and then n.created DESC... Meaning if the image is sticky it'll go to the top first, and then the rest of the list is ordered via creation time, descending.

I modified the line (line 131 in mine) from..
"ORDER BY n.sticky DESC, n.created DESC"

into this, which is sorted Ascending, just cause it was easier for me to have the images I uploaded last appear at the end of the gallery by default..
"ORDER BY t.weight_in_tid ASC"

And it worked, as long as the images had been uploaded while NodeOrder was installed and active (hence, if there is a value in nodeorder's Weight column).

I assume there is something very similar going on with the imagegallery module. Search it for "ORDER BY" and see if you can replace it with t.weight_in_tid.

Someone should probably make the Status of this "Won't Fix" if they can confirm that imagegallery can be hacked the same way. Although, I wonder if I should open a new ticket requesting a button to generate a list of weights for pre-existing Taxonomy, since in my case, I had NodeOrder set to disable on throttle, throttle got enabled, I uploaded a bunch of pictures, and nodeorder wouldn't order them correctly when I turned it back on...

halftone’s picture

Title: Ordering Images for Gallery / Flash Gallery » Sorted

Duh, this did indeed turn out to be easier than I thought, requiring just the following 2 changes:

Image_gallery module at line #87
$last = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN (%s) AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), implode(',', $descendant_tids), 0, 1));
replace with

// HACK to allow Nodeorder to work if present 
    if (module_exist ('nodeorder')) {
      $last = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN (%s) AND n.status = 1 ORDER BY t.weight_in_tid ASC'), implode(',', $descendant_tids), 0, 1));
    }  
    else {
      $last = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN (%s) AND n.status = 1 ORDER BY n.sticky DESC, n.nid DESC'), implode(',', $descendant_tids), 0, 1));
    }
// END HACK 

and at line #93
$result = pager_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"), variable_get('image_images_per_page', 6), 0, NULL, $tid);
replace with

// HACK to allow Nodeorder to work if present
    if (module_exist ('nodeorder')){
       $result = pager_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 t.weight_in_tid ASC"), variable_get('image_images_per_page', 6), 0, NULL, $tid);
     }
     else {
       $result = pager_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.nid DESC"), variable_get('image_images_per_page', 6), 0, NULL, $tid);
     }
// END HACK

Which works fine here and doesn't break if nodeorder is absent, so I am very happy :-) It could do with further tweaking to display the first image in a term in empty parent galleries (as sticky used to do), but it's now more urgent for me to fix the pager code I am using from http://drupal.org/node/119052. I have done a similar hack for that which I will post there, but haven't yet managed to stop the pager hopping around between multiple terms (it looks at the first TID of the current node and uses that).

Thanks for your help. Image module/gallery is now almost usable ;)

halftone’s picture

Title: Sorted » Sorry, here is the CORRECT code

Sorry, I hadn't noticed some Watchdog errors. Now fixed and this now allows the first weight_in_tid images in a term to stand in for sticky images in empty parent gallery categories.

Image_gallery module at line #87
$last = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN (%s) AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), implode(',', $descendant_tids), 0, 1));
replace with

// HACK TO ALLOW NODEORDER TO WORK
    if (module_exist ('nodeorder')) {
      $last = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN (%s) AND n.status = 1 ORDER BY tn.weight_in_tid ASC'), implode(',', $descendant_tids), 0, 1));
    }  
    else {
      $last = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN (%s) AND n.status = 1 ORDER BY n.sticky DESC, n.nid DESC'), implode(',', $descendant_tids), 0, 1));
    }
// END HACK

and at line #93
$result = pager_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"), variable_get('image_images_per_page', 6), 0, NULL, $tid);
replace with

// HACK TO ALLOW NODEORDER TO WORK
     if (module_exist ('nodeorder')) {
       $result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} tn INNER JOIN {node} n ON tn.nid=n.nid WHERE n.status=1 AND n.type='image' AND tn.tid=%d ORDER BY tn.weight_in_tid ASC"), variable_get('image_images_per_page', 6), 0, NULL, $tid);
     }
     else {
       $result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} tn INNER JOIN {node} n ON tn.nid=n.nid WHERE n.status=1 AND n.type='image' AND tn.tid=%d ORDER BY n.sticky DESC, n.nid DESC"), variable_get('image_images_per_page', 6), 0, NULL, $tid);
     }
// END HACK
Offlein’s picture

Title: Sorry, here is the CORRECT code » Image Gallery, Flash Gallery with Nodeorder
Status: Active » Closed (won't fix)

Great work, halftone. I'm setting this to won't fix, then.. If that's not correct, someone can change it.

halftone’s picture

Title: Image Gallery, Flash Gallery with Nodeorder » Image Gallery with Nodeorder, Next|Prev links, multi taxonomy terms OK!

NB http://drupal.org/node/119052#comment-214489 for anyone looking for an image pager (next|prev links) custom module solution that works with the image module AND Nodeorder AND images that inhabit multiple taxonomy terms :-). That version of hacks to the image module also adds back Sticky for Nodeorder'ed images as suggested by Marc. I am so happy, thanks largely to Nodeorder and you guys this is the first time ever Drupal has seemed controllable (or even usable) for images :)

yngens’s picture

will this work for 5.x?

halftone’s picture

Yes, I have done it with 5.3. The code changes are a little different to those outlined in #10.

In the contrib/image_gallery.module modify the image_gallery_page function :-

/**
 * Image gallery callback, displays an image gallery
 */
function image_gallery_page($type = NULL, $tid = 0) {
  $galleries = taxonomy_get_tree(_image_gallery_get_vid(), $tid, -1, 1);
  for ($i=0; $i < count($galleries); $i++) {
    $galleries[$i]->count = taxonomy_term_count_nodes($galleries[$i]->tid, 'image');
    $tree = taxonomy_get_tree(_image_gallery_get_vid(), $galleries[$i]->tid, -1);
    $descendant_tids = array_merge(array($galleries[$i]->tid), array_map('_taxonomy_get_tid_from_term', $tree));
    // The values of $descendant_tids should be safe for raw inclusion in the
    // SQL since they're all loaded from integer fields in the database.
// HACK TO ALLOW NODEORDER TO WORK IF USED TO SET IMAGE SEQUENCE (weight_in_tid)
    if (module_exists ('nodeorder')) {
      $sql = 'SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. implode(',', $descendant_tids) .') AND n.status = 1 ORDER BY n.sticky DESC, tn.weight_in_tid ASC';
    }
    else {
          $sql = 'SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. implode(',', $descendant_tids) .') AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC';
    }
// END HACK
    if ($nid = db_result(db_query_range(db_rewrite_sql($sql), 0, 1))) {
      $galleries[$i]->latest = node_load(array('nid' => $nid));
    }
  }

  $images = array();
  if ($tid) {
// HACK TO PASS CURRENT TERM FOR CUSTOM IMAGE_PAGE_PAGER MULTI-TAXONOMY BREADCRUMB MODULE
     $_SESSION['current_tid'] = $tid;
// HACK TO ALLOW NODEORDER TO WORK
     if (module_exists ('nodeorder')) {
       $result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} tn INNER JOIN {node} n ON tn.nid=n.nid WHERE n.status=1 AND n.type='image' AND tn.tid=%d ORDER BY tn.weight_in_tid ASC"), variable_get('image_images_per_page', 6), 0, NULL, $tid);
     }
     else {
       $result = pager_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"), variable_get('image_images_per_page', 6), 0, NULL, $tid);
     }
// END HACK
    while ($node = db_fetch_object($result)) {
      $images[] = node_load(array('nid' => $node->nid));
    }

    $gallery = taxonomy_get_term($tid);
    $parents = taxonomy_get_parents($tid);
    foreach ($parents as $parent) {
      $breadcrumb[] = array('path' => 'image/tid/'. $parent->tid, 'title' => $parent->name);
    }
    $breadcrumb[] = array('path' => 'image', 'title' => t('Image galleries'));
    $breadcrumb = array_reverse($breadcrumb);
    drupal_set_title($gallery->name);
  }

  $breadcrumb[] = array('path' => $_GET['q']);
  menu_set_location($breadcrumb);
  $content = theme('image_gallery', $galleries, $images);
  return $content;
}

NB that if Nodorder is not installed image gallery reverts to normal reverse-chronology Drupal ordering. This really needs to be submitted as a patch to the image_gallery module so it can become official code, but I am not competent enough to do it. Nevertheless, this works fine - can be seen doing so at http://threadscape.co.uk galleries