The weight_in_tid value assigned to the nid/tid relationship is the new MAX number, so in other words if I have 5 nodes, and 1 is the top node on the drag n drop list, and 5 is the lowest, when publishing a new node, it is assigned weight_in_tid of 6, and on the drag n drop ordering page, goes to the bottom. Then I can drag it to the top.

I'm using Nodeorder extensively for a customer who wants to have automatically filled node views, but still be able to re-order the nodes manually. However, the customer wants new nodes to go to the 'top' of the list instead of the bottom. The MAX numbering should remain the same. Instead, an option to reverse the drag n drop and "move up/move down" sort orders would give my customer what it wants but not alter the numbering system.

This way new nodes could move to the "top" rather than to the "bottom" of a Node Order, same numbering system.

Views that display the sorted nodes are sorted by weight_in_tid asc, just like the drag n drop page, and with the reverse option all one would have to do is sort desc in the View.

I may hack at this for my own purposes but thought I'd suggest (along with the Node Type filtering - that too would rock) such a feature.

Comments

ccshannon’s picture

Title: Feature Request: Reverse Sort Drag n Drop Page View » Add to "top" of taxonomy instead of bottom
ccshannon’s picture

So, I've made a hack to do this for my current project, and I hate doing that because if I need to update to a newer Nodeorder, I will have to reimplement this hack - though it's not much code. Not sure how I could do it as a separate module.

I created a new admin setting that, when selected, changes the default behavior in the nodeapi hook for 'update'.

Instead of assigning the node_term relationship the MAX + 1 weight, it first increments the weight of all the nodes in that term, then gives itself a weight of '1'. So, new nodes go to the 'top' of the Nodeorder when published.

Turning off the option in settings, returns Nodeorder to default placement (bottom of list).

Still refining it.

marcp’s picture

Sounds interesting. Please post a patch so others can have a look.

pvanderspek’s picture

Although I guess the solution works in practice it doesn't sound very efficient, especially when a taxonomy has a lot of nodes associated to it. Wouldn't it be easier to change the sort order, i.e. DESC vs. ASC? You could probably make this configurable through settings on the taxonomy page and even set this per vocabulary.

ccshannon’s picture

I thought about that, but then the sorting page's functionality would have to be completely reversed - from its theme to the way the draggable tables work, and that would be much, much more complicated.

It's one call to the database. 'Set weight_in_tid = weight_in_tid + 1 where tid = %d' - the tid being the one your node is assigned to. If I add the ability to place the node at any position, then the call would be the same but I would add to the where clause 'and weight_in_tid >= %d' where that last number is the position I send to it.

Since the table is locked during operations, it won't get munged by another publish.

ccshannon’s picture

marcp,

I will definitely do that once I test it a bit more and feel it's doing things correctly.

Probably not next week, but the week after.

ccshannon’s picture

Okay, so I'm deep in this project which is set to launch in the next two weeks. I won't be able to get to this until mid-June at this point. But I will roll out the patch at that time. Just FYI. Thanks.

nkatt’s picture

Hi there,

I'm looking forward to this update - are you still anticipating a release in June?

Thanks!

nkatt

ccshannon’s picture

It's just a patch, but I've never created a patch before, and since I'm really busy working on this site launch, I just haven't the time to look at it. I really want to make sure it works before I release the patch.

The site has a soft launch Monday, so maybe I will get a breather before then and I can do it before July 1.

lucio.ferrari’s picture

Hallo,
this thread being quite old, I don't know whether someone will read this, but anyway...

What about just modifying the nodeapi hook in nodeorder.module:

<?php
function nodeorder_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {

[...]

    case 'update':
      // Set the weight_in_tid -- taxonomy probably stomped it because
      // we added the weight_in_tid column to term_node, and taxonomy
      // just wants to delete and re-insert rows when things change...
      
      // Note that we only want to set the weight_in_tid for tids that
      // are in orderable vocabularies...
      if (nodeorder_can_be_ordered($node)) {
        $tids = nodeorder_orderable_tids($node);
  
        if (count($tids) > 0) {
          $sql = "UPDATE {term_node} SET weight_in_tid = %d WHERE tid = %d AND nid = %d";
  
          foreach ($tids as $i => $tid) {
            db_lock_table('term_node');
            $weights = nodeorder_get_term_min_max($tid, FALSE); // get the cached weights
            db_query($sql, $weights["max"] + 1, $tid, $node->nid);
            nodeorder_get_term_min_max($tid, TRUE); // reinitialize the cache
            db_unlock_tables();
          } 
        }

[...]
        
  }
}?>

and replace the sql query as:

db_query($sql, $weights["min"] - 1, $tid, $node->nid);

This way a new post would be the lightest and float up in nodeorder/term/%.

lucio.ferrari’s picture

AND

the function nodeorder_orderable_tids is broken, returning nothing!!!
It's because it calls nodeorder_get_tids($key, $value) with $value being a taxonomy object, and the function does not parse objects at all. Just adding get_object_vars in the function call seems to do the trick.

/**
 * Returns an array of the node's tids that are in orderable vocabularies...
 */
function nodeorder_orderable_tids($node) {
  $tids = array();
  $orderable_tids = array();
  $cid = 'nodeorder:orderable_tids:'. $node->type;
  
  if (($cache = cache_get($cid)) && !empty($cache->data)) {
    $orderable_tids = $cache->data;
  } else {
    $sql = "SELECT v.vid AS vid FROM {vocabulary_node_types} vnt JOIN {vocabulary} v ON vnt.vid = v.vid WHERE vnt.type = '%s' AND v.module = 'nodeorder'";
    $result = db_query($sql, $node->type);
  
    while ($row = db_fetch_object($result)) {
      $tree = taxonomy_get_tree($row->vid);
      foreach ($tree as $term) {
        $orderable_tids[] = $term->tid;
      }
    }
	
    //permanently cache the value for easy reuse
    cache_set($cid, $orderable_tids, 'cache');
  }

  // Now select only those tids which are actually assigned to this term
  foreach ($node->taxonomy as $key => $value) {     // $node->taxonomy is an array of objects, 
    $list_of_tids = nodeorder_get_tids($key, get_object_vars($value)); // <-- add this to make it work
    
    $tids = array_merge($tids, array_intersect($list_of_tids, $orderable_tids));
  }

  return $tids;
}
dieuwe’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Closing as the Drupal 6 branch of this module (and Drupal 6 in general) has been discontinued.