You are here

function nodeorder_can_be_ordered in Node Order 7

Same name and namespace in other branches
  1. 5 nodeorder.module \nodeorder_can_be_ordered()
  2. 6 nodeorder.module \nodeorder_can_be_ordered()

Returns TRUE if the node has terms in any orderable vocabulary.

2 calls to nodeorder_can_be_ordered()
nodeorder_node_presave in ./nodeorder.module
Implements hook_node_presave().
nodeorder_node_update in ./nodeorder.module
Implements hook_node_update().

File

./nodeorder.module, line 579
Nodeorder module.

Code

function nodeorder_can_be_ordered($node) {
  $cid = 'nodeorder:can_be_ordered:' . $node->type;
  if (($cache = cache_get($cid)) && !empty($cache->data)) {
    return $cache->data;
  }
  else {
    $can_be_ordered = FALSE;
    $fields = field_info_fields();
    $nodeorder_vocabularies = array();
    foreach ($fields as $field_name => $field) {
      if ($field['type'] != 'taxonomy_term_reference' || empty($field['bundles']['node']) || !in_array($node->type, $field['bundles']['node'])) {
        continue;
      }
      foreach ($field['settings']['allowed_values'] as $allowed_values) {
        $nodeorder_vocabularies[] = $allowed_values['vocabulary'];
      }
    }
    if (!empty($nodeorder_vocabularies)) {
      $result = db_select('taxonomy_vocabulary', 'v')
        ->condition('v.module', 'nodeorder')
        ->condition('v.machine_name', $nodeorder_vocabularies, 'IN')
        ->fields('v', array(
        'vid',
      ))
        ->execute()
        ->fetchColumn();
      if ($result) {
        $can_be_ordered = TRUE;
      }
    }

    // Permanently cache the value for easy reuse.
    cache_set($cid, $can_be_ordered, 'cache');
    return $can_be_ordered;
  }
}