Integrate with Views Module
rup3rt - February 1, 2008 - 14:32
| Project: | Similar By Terms |
| Version: | 5.x-1.x-dev |
| Component: | Miscellaneous |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
Great module, instant easy failsafe blocks that add tons to a site.
A views block would be exponentially awesome with map blocks of content similar by terms and image grids. Less mindbending than arguments, better than endless snippets.
There are probably many more uses and probably a few icebergs that I haven't seen. Would it take a lot to do it?
Thanks again for SBT and your many other drupal blessings
R3

#1
This is something that jeff wants to get done and I think it would be useful as well. Leaving it open.
#2
You might want to have a look at the Similar Nodes module.
#3
Thanks David,
I am looking!
R3
#4
Any timeplans? :)
#5
No time frame at this point. I am looking into what it takes to add views into a module but nothing at this point.
Thanks
#6
Similar Nodes does not work with blocks properly, there is a support request in, but according to another post, that projects has been abandoned.
#7
Meanwhile I was trying to get a related content block view going with this description here http://drupal.org/node/65375 but no luck yet
#8
I realise this module can show teasers, and we can define CCK teasers with contemplate oh jeah. Will try that out now
#9
The theme function is given a full node you can overide that display and make it look however you want. I am open to patches as well if you need added support.
Thanks
Robert
#10
Yes I saw that...Unfortunately the teaser for the CCK comes out as empty even with contemplate and the cck teaser module, so I am thinking of taking out the entire similarterms_list function, modding it so I get an array of node ids and passing it into a view as an argument handling code,
This way I can build a view on node ids as arguments...
I am not sure how to do patches,but this seems to be the quickest for me now :) I am a bit fed up with the cck teaser stuff.
#11
Well once you are done post the code I will look at it and see if I can incorpate what you wrote with Similar by Terms.
Thanks
Robert
#12
Hello Robert,
Here we go...
It is not a patch, more of a rip :) loller
I took this code straight from the module, modded the end so it shoves all the nodeids in an array and passed this as an argument handling code into a view.
I set the argument to Node ID with Display All Fields options...
Lo and behold, I got my related view block up in no second :D Sorry for ripping your code, but views is views after all :D
$nodes = array();
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
}
if ($nid != NULL) {
$full_node = node_load($nid);
if ($vocid == 0) {
$terms = array_keys(taxonomy_node_get_terms($full_node->nid));
}
else {
$terms = array_keys(taxonomy_node_get_terms_by_vocabulary($full_node->nid, $vocid));
}
// Filter out some terms
$terms_filter = variable_get('simterms_ignoreterms_'. $vocid, array());
for ($i = 0; $i < count($terms_filter); $i++) {
$idx = array_search($terms_filter[$i], $terms);
if ($idx >= 0) {
unset($terms[$idx]);
}
}
$terms = implode(',', $terms);
$count = variable_get('simterms_count_'. $vocid, 5);
if (!empty($terms)) {
//past events
$pasts = array();
$types = variable_get('simterms_sametype_'. $vocid, false);
if (($types !== false) && is_array($types) && ($types['0'] == NULL) ) {
if ($types[1]) {
$node_obj = node_load($nid);
$types[1] = $node_obj->type;
}
$str_types = "'". implode("','", $types) ."'"; // couldnt find a solutin for IN %s problem and \' substi
$sql = sprintf(
'SELECT n.nid, n.title, COUNT(n.nid) AS ncount '.
'FROM {node} n '.
'INNER JOIN {term_node} tn ON n.nid = tn.nid '.
'WHERE tn.tid IN (%s) '.
'AND n.type IN ('. $str_types .') '.
'AND n.nid != %d '.
'AND n.status = 1 '.
'AND n.moderate = 0 '.
'GROUP BY n.nid, n.title, n.created '.
'ORDER BY ncount DESC, n.created DESC '.
'LIMIT %d',
$terms, $nid, $count);
}
else {
$sql = sprintf(
'SELECT n.nid, n.title, COUNT(n.nid) AS ncount '.
'FROM {node} n '.
'INNER JOIN {term_node} tn ON n.nid = tn.nid '.
'WHERE tn.tid IN (%s) '.
'AND n.nid != %d '.
'AND n.status = 1 '.
'AND n.moderate = 0 '.
'GROUP BY n.nid, n.title, n.created '.
'ORDER BY ncount DESC, n.created DESC '.
'LIMIT %d',
$terms, $nid, $count);
}
$sql = db_rewrite_sql($sql);
$result = db_query($sql);
while ($r = db_fetch_object($result)) {
$nodes[] = $r->nid;
}
}
}
// print ('<pre>');
// print_r ($nodes);
// print ('<post>');
if($nodes){
return array(implode('+', $nodes)); //include current node, so we can skip it
}
#13
I have put this in production, and have been observing my mysql process from shell with "mysqladmin processlist -i 2" and can confirm that I get a massive amount of file write to dis by this query:
converting HEAP to MyISAM | SELECT n.nid, n.title, COUNT(n.nid) AS ncount FROM node n INNER JOIN term_node tn ON n .....Copying to tmp table | SELECT n.nid, n.title, COUNT(n.nid) AS ncount FROM node n INNER JOIN term_node tn ON n .....
Copying to tmp table on disk | SELECT n.nid, n.title, COUNT(n.nid) AS ncount FROM node n INNER JOIN term_node tn ON n .....
Probably this is not related to my solution, but the general query...
#14
giorgio79,
Sounds like it. The block gets cached when it displays and doesn't rerun the query it is possible that there is no caching happening with your mod.
Thanks
Robert
#15
Looking forward to this feature. subscribing