how to show all the node props in a block view

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
lrocandio's picture

Hi,

I´m doing a module that attempt to show a bunch of nodes created programatically

All the node types have integrated fivestar rating

code is:

function pepe_block($op, $delta, $edit)  {
  case 'view':
    $qry = "SELECT n.nid, n.title, a.link FROM {node} n INNER JOIN {mytable} a ON n.nid=a.nid WHERE a.type = ......";
    $res = db_query($qry, $a, $b, $c);
    while ($algo = db_fetch_object($res)) {
      $node_load($algo->nid);
      $block_content .= l($algo->title, $algo->link, $options) . '<br>'. $node->body
    }
  return $block
}

Up to here everything works fine, But I'd like to programatically obtain the same results as the target of

l($algo->title, 'node/'. $algo->nid)

How to retrieve the fivestar rating? or the rest of the information shown by node-mytype.tpl.php?

Doing dpr($node) does not show any clue (for me at least)

regards
lr

Comments

Some comments

gomezbl's picture

Hi, first of all, you say that "$node_load($algo->nid)" works?, I think it should be:
$algo = node_load($algo->nid) ... to fullly load the node information.

Regarding to five star, this is a contrib module with its own repository tables, and node_load only "knows" about core node infrastructure supplied by Drupal.

Don't know if five start implements this hook: hook_node_load, called when a node is being loaded (as it does when you call node_load).

If you need to load rating information for an specific node, given its nid, then, try this:

. look at five star module looking for a function that tells you the rating info given a node ID

. look at tables created by five star and fetch in your code the information

The first method could be the best one because future updated of five star could change its table structure.

Tell me you found this useful somehow.

Regards

RafaBlanes
contacto@ellibronegrodelprogramador.com
Agile Drupal Development and more...

Hi Gomez Yes, you are

lrocandio's picture

Hi Gomez
Yes, you are right... It was just a typo error, in fact it is $node = node_load($algo->nid)

I´ll try to found something useful in the five star module, I know about the data stored in votingapi_vote and votingapi_cache but I don´t like to reinvent the wheel, just to change the shaft.

regards

Easy solution... after not an easy search

lrocandio's picture

The solution I found to access all the node content is:

$node = node_load($algo->nid);
$node = node_build_content($node, FALSE, 1); // Or any variation
$nArray = (array) $node;
// now you can do a
dpr($nArray);
// and select what are you interesd in, as an example
$myInterest = $nArray['content']['body']['#value'];

Hope it helps somebody