/[drupal]/contributions/modules/taxonomy_dss/taxonomy_dss.module
ViewVC logotype

Diff of /contributions/modules/taxonomy_dss/taxonomy_dss.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.26, Wed Jan 9 18:25:08 2008 UTC revision 1.26.2.1, Wed Jan 16 21:34:49 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: taxonomy_dss.module,v 1.25 2007/08/31 17:17:59 moonray Exp $  // $Id: taxonomy_dss.module,v 1.26 2008/01/09 18:25:08 moonray Exp $
3    
4  /* Required patch to core (can we find a module specific workaround?):  /* Required patch to core (can we find a module specific workaround?):
5    
# Line 916  function taxonomy_dss_select_children($t Line 916  function taxonomy_dss_select_children($t
916        $joins  .= ' INNER JOIN {term_node} tn'. $index .' ON n.nid = tn'. $index .'.nid';        $joins  .= ' INNER JOIN {term_node} tn'. $index .' ON n.nid = tn'. $index .'.nid';
917        $wheres .= ' AND tn'. $index .'.tid = '. $tid;        $wheres .= ' AND tn'. $index .'.tid = '. $tid;
918      }      }
     $sql = "SELECT DISTINCT(n.nid) FROM {node} n {$joins} WHERE n.status = 1 {$wheres} AND (SELECT COUNT(DISTINCT td0.vid) FROM {term_node} t LEFT JOIN {term_data} td0 ON t.tid = td0.tid WHERE t.nid = n.nid) > ". count($tids);  
919    
920      $sql = "SELECT tn.nid, tn.tid, td.vid, td.name, td.description, td.weight, v.weight AS vweight FROM {term_node} tn LEFT JOIN {term_data} td ON td.tid = tn.tid LEFT JOIN {vocabulary} v ON td.vid = v.vid WHERE tn.nid IN ({$sql}) AND td.vid NOT IN (SELECT td1.vid FROM {term_data} td1 WHERE td1.tid IN (". implode(',', $tids) .")) ORDER BY v.weight DESC, td.weight DESC, td.name DESC";      // db_rewrite_sql() bugs out on a complex SELECT within a SELECT, so need to work around it
921        $sql_a = db_rewrite_sql("SELECT COUNT(DISTINCT(td0.vid)) FROM {term_node} t LEFT JOIN {term_data} td0 ON t.tid = td0.tid WHERE t.nid = n.nid", 'tn', 'tid');
922    
923        $sql_b = db_rewrite_sql("SELECT DISTINCT(n.nid) FROM {node} n {$joins} WHERE n.status = 1 {$wheres} AND (___PLACEHOLDER1___) > ". count($tids));
924        $sql_b = str_replace('___PLACEHOLDER1___', $sql_a, $sql_b);
925    
926      $sql = "SELECT DISTINCT r.tid, r.vid, r.name, r.description, r.weight, GROUP_CONCAT(DISTINCT r.tid ORDER BY r.vweight, r.weight, r.name SEPARATOR ',') AS tids FROM ({$sql}) r GROUP BY r.nid ORDER BY r.vweight, r.weight, r.name";      $sql_c = db_rewrite_sql("SELECT tn.nid, tn.tid, td.vid, td.name, td.description, td.weight, v.weight AS vweight FROM {term_node} tn LEFT JOIN {term_data} td ON td.tid = tn.tid LEFT JOIN {vocabulary} v ON td.vid = v.vid WHERE tn.nid IN (___PLACEHOLDER2___) AND td.vid NOT IN (SELECT td1.vid FROM {term_data} td1 WHERE td1.tid IN (". implode(',', $tids) .")) ORDER BY v.weight DESC, td.weight DESC, td.name DESC", 'tn', 'tid');
927        $sql_c = str_replace('___PLACEHOLDER2___', $sql_b, $sql_c);
928    
929      $result = db_query(db_rewrite_sql($sql, 'tn', 'randomfieldname'));      $sql = db_rewrite_sql("SELECT DISTINCT(r.tid), r.vid, r.name, r.description, r.weight, GROUP_CONCAT(DISTINCT(r.tid) ORDER BY r.vweight, r.weight, r.name SEPARATOR ',') AS tids FROM (___PLACEHOLDER3___) r GROUP BY r.nid ORDER BY r.vweight, r.weight, r.name", 'custom', 'tid');
930        $sql = str_replace('___PLACEHOLDER3___', $sql_c, $sql);
931    
932        $result = db_query($sql);
933    }    }
934    
935    return $result;    return $result;
# Line 1033  function taxonomy_dss_get_tree_children( Line 1040  function taxonomy_dss_get_tree_children(
1040    // Sort terms by weight: first by vocabulary weight, then by individual term weights    // Sort terms by weight: first by vocabulary weight, then by individual term weights
1041    _taxonomy_dss_sort_tree($children);    _taxonomy_dss_sort_tree($children);
1042    
1043      // Translate taxonomy if i18ntaxonomy.module exists
1044      _taxonomy_dss_translate_tree($children);
1045    
1046    return $children;    return $children;
1047  }  }
1048    
# Line 1073  function taxonomy_dss_select_nodes($tids Line 1083  function taxonomy_dss_select_nodes($tids
1083      if ($operator == 'or') {      if ($operator == 'or') {
1084        $str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids));        $str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids));
1085        $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .') '. $promote_sql .'AND n.status = 1 ORDER BY '. $order;        $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .') '. $promote_sql .'AND n.status = 1 ORDER BY '. $order;
1086    
1087        $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .') '. $promote_sql .'AND n.status = 1';        $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .') '. $promote_sql .'AND n.status = 1';
1088    
1089          $sql = db_rewrite_sql($sql);
1090          $sql_count = db_rewrite_sql($sql_count);
1091      }      }
1092      else {      else {
1093        $joins = '';        $joins = '';
# Line 1083  function taxonomy_dss_select_nodes($tids Line 1097  function taxonomy_dss_select_nodes($tids
1097          $wheres .= ' AND tn'. $index .'.tid IN ('. implode(',', $tids) .')';          $wheres .= ' AND tn'. $index .'.tid IN ('. implode(',', $tids) .')';
1098        }        }
1099        if ($exclusive) {        if ($exclusive) {
1100          $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '. $joins .' WHERE n.status = 1 '. $promote_sql . $wheres .' AND (SELECT COUNT(DISTINCT td0.vid) FROM {term_node} t LEFT JOIN {term_data} td0 ON t.tid = td0.tid WHERE t.nid = n.nid) = '. count($descendant_tids) .' ORDER BY '. $order;          $sql = db_rewrite_sql('SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '. $joins .' WHERE n.status = 1 '. $promote_sql . $wheres .' AND (___PLACEHOLDER___) = '. count($descendant_tids) .' ORDER BY '. $order);
1101          $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. $joins .' AND (SELECT COUNT(*) FROM {term_node} t WHERE t.nid = n.nid) = '. count($descendant_tids) .' WHERE n.status = 1 '. $promote_sql . $wheres;  
1102            // db_rewrite_sql() bugs out on a complex SELECT within a SELECT, so need to work around it
1103            $sql_sub = db_rewrite_sql('SELECT COUNT(DISTINCT(td0.vid)) FROM {term_node} tn LEFT JOIN {term_data} td0 ON tn.tid = td0.tid WHERE tn.nid = n.nid', 'tn', 'tid');
1104            $sql = str_replace('___PLACEHOLDER___', $sql_sub, $sql);
1105    
1106            // db_rewrite_sql() bugs out on a complex SELECT within a SELECT, so need to work around it
1107            $sql_count = db_rewrite_sql('SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. $joins .' AND (___PLACEHOLDER___) = '. count($descendant_tids) .' WHERE n.status = 1 '. $promote_sql . $wheres);
1108            $sql_count_sub = db_rewrite_sql('SELECT COUNT(*) FROM {term_node} t WHERE t.nid = n.nid', 'tn', 'tid');
1109            $sql_count = str_replace('___PLACEHOLDER___', $sql_count_sub, $sql_count);
1110        }        }
1111        else {        else {
1112          $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '. $joins .' WHERE n.status = 1 '. $promote_sql . $wheres .' ORDER BY '. $order;          $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '. $joins .' WHERE n.status = 1 '. $promote_sql . $wheres .' ORDER BY '. $order;
1113    
1114          $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. $joins .' WHERE n.status = 1 '. $promote_sql . $wheres;          $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. $joins .' WHERE n.status = 1 '. $promote_sql . $wheres;
1115    
1116            $sql = db_rewrite_sql($sql);
1117            $sql_count = db_rewrite_sql($sql_count);
1118        }        }
1119      }      }
     // Once Taxonomy Acccess Control or any other acces control module gets  
     // enabled, it tries to mess with the SQL unless you set the fieldname to  
     // something it doesn't recognize.  
     $sql = db_rewrite_sql($sql, 'tn', 'randomfieldname');  
     $sql_count = db_rewrite_sql($sql_count, 'tn', 'randomfieldname');  
1120    
1121      if ($pager) {      if ($pager) {
1122        if ($nodecount == 0) {        if ($nodecount == 0) {
# Line 1298  function _taxonomy_dss_sort_tree(&$tree) Line 1319  function _taxonomy_dss_sort_tree(&$tree)
1319    }    }
1320  }  }
1321    
1322    function _taxonomy_dss_translate_tree(&$tree) {
1323      if (module_exists('i18ntaxonomy')) {
1324        foreach(array_keys($tree) as $tid) {
1325          if(isset($tree[$tid]->children)) {
1326            _taxonomy_dss_translate_tree($tree[$tid]->children);
1327          }
1328        }
1329        _i18ntaxonomy_translate_terms(&$tree);
1330      }
1331    }
1332    
1333  function _taxonomy_dss_limit_depth(&$children, $depth) {  function _taxonomy_dss_limit_depth(&$children, $depth) {
1334    foreach ($children as $child) {    foreach ($children as $child) {
1335      if (count($children)) {      if (count($children)) {

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.26.2.1

  ViewVC Help
Powered by ViewVC 1.1.2