I have a series of pages (each one is the main page for a section of the site) that display a bunch of teasers, some of which are protected by premium, some are not. I would like to insert a small "premium content" icon before the title of each teaser that is protected. Is there any way I can tell which teasers lead to protected nodes and which don't? Maybe some variable that I can access?

I could hack the module but I'd rather keep it all in the template code if possible. A simple "str_replace" operation where I can replace a flag with the flag and an image tag would be ideal.

Many thanks,

D

BTW, premium is a great module, keep up the good work :-)

Comments

allie micka’s picture

Status: Active » Closed (fixed)

There is a flag called "premium" available on all nodes. The value of this flag will be 1 or 0. In your theme code, you could do something like:

<?php if ($node->premium) :?>
  <img src="fancy_premium_icon.png" alt="premium" />
<?php endif; ?>
dylanb’s picture

Thanks for the speedy response. Just to clarify, in case anyone else is having the same problem, I followed your advice and amended the code in `node.tpl.php` in my theme folder (I'm using a theme based on bluemarine) so now it reads...

  if($node->premium) print "<img src=\"/images/icons/icon_premium.gif\" border=\"0\" height=\"30\" width=\"30\" alt=\"premium content\" style=\"margin-right:5px;\">";
  print $title;
robobeau’s picture

Version: 4.7.x-1.x-dev » 5.x-1.0
Status: Closed (fixed) » Active

Hey, guys. This post helped to display an icon on the actual Node's page, and on Teaser/Node views, but can anyone help me do this on a Table view?

I already made an theme override function, it just doesn't detect $node->premium at all.

function zen_views_view_table($view, $nodes, $type) {
  $fields = _views_get_fields();

  foreach ($nodes as $node) {
  	if ($node->premium){
  		$ispremium = "premium-table";
  	}
    $row = array();
    foreach ($view->field as $field) {
      if ($fields[$field['id']]['visible'] !== FALSE) {
        $cell['data'] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
        $cell['class'] = "view-field ". $ispremium ." ". views_css_safe('view-field-'. $field['queryname']);
        $row[] = $cell;
      }
    }
    $rows[] = $row;
  }
  return theme('table', $view->table_header, $rows);
}

Is there any way I can detect wether a node is premium or not in Table View...? Changed the Version to reflect which module ver. I'm using.

robobeau’s picture

Status: Active » Closed (fixed)

I did a little searching around the module and found the code I needed :)

I'm basically altering the class so I can do it all in CSS. Best of all, I can add the class to all the fields, so I alter any of the fields if it's premium. :)

Just put this in my zen template.php. If anyone knows a better way to do this, then by all means correct me!

/** PREMIUM ICON ON TABLE VIEW **/
function zen_views_view_table($view, $nodes, $type) {
  $fields = _views_get_fields();

  foreach ($nodes as $node) {
  	// Attempt to find the value from the premium table.
    $ispremium = (int) db_result(db_query("SELECT 1 FROM {premium}  WHERE nid = %d
      AND (( start_ts = 0 and end_ts > %d)
      OR ( start_ts < %d AND end_ts = 0)
      OR ( start_ts = 0 AND end_ts = 0))", $node->nid, time(), time()));
  	
    $row = array();
    foreach ($view->field as $field) {
      if ($fields[$field['id']]['visible'] !== FALSE) {
        $cell['data'] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
        if($ispremium == 1){
        	$cell['class'] = "view-field ". views_css_safe('view-field-'. $field['queryname'] .'-premium');
        } else $cell['class'] = "view-field ". views_css_safe('view-field-'. $field['queryname']);
        $row[] = $cell;
      }
    }
    $rows[] = $row;
  }
  return theme('table', $view->table_header, $rows);
}