Permalink
Browse files

Rewrite SQL using entity.

  • Loading branch information...
1 parent 864e13d commit 378fbc0bb696e84ad5592ab846d23d0a324e5b06 Bèr Kessels committed Dec 31, 2012
Showing with 10 additions and 20 deletions.
  1. +10 −20 tagadelic_taxonomy.module
@@ -46,31 +46,21 @@ function tagadelic_taxonomy_theme($existing, $type, $theme, $path) {
function tagadelic_taxonomy_get_tags() {
$tags = array();
- /**
- see http://drupal.stackexchange.com/q/54483/787
- $query = db_select('taxonomy_term_data', 't');
+ $query = db_select('taxonomy_index', 'i');
- $query->addField('t', 'tid');
- $query->addField('t', 'name');
- $query->addField('t', 'description');
- $query->addField('COUNT(i.nid)', 'count');
+ $alias = $query->leftjoin('taxonomy_term_data', 't', '%alias.tid = i.tid');
- $query->leftjoin('taxonomy_index', 'i', 'i.nid = t.nid');
- $query->range(0, 60)
- ->groupBy('i.nid');
-
- print($query);
+ $query->addExpression('COUNT(i.nid)', 'count');
+ $query->addField($alias, 'tid');
+ $query->addField($alias, 'name');
+ $query->addField($alias, 'description');
- result = $query->execute();*/
+ $query->range(0, 60)
+ ->groupBy("i.tid");
- $result = db_query("SELECT t.tid, t.name, t.description, COUNT(i.nid) AS count
- FROM taxonomy_index AS i
- LEFT JOIN taxonomy_term_data AS t ON i.tid = t.tid
- GROUP BY i.tid
- LIMIT 60");
+ $result = $query->execute();
- /*foreach ($result as $term) {*/
- while($term = $result->fetchObject()) {
+ foreach ($result as $term) {
$tag = new TagadelicTag($term->tid, $term->name, $term->count);
$tag->set_link("taxonomy/term/{$term->tid}");
$tag->set_weight(1);

0 comments on commit 378fbc0

Please sign in to comment.