Hello,
I want to display the signup status of current nodes in the views template. Refering to the signup_handler_field_signup_node_link.inc file, I tried this :

 <?php print $node->$signup_handler_field_signup_status; ?>

but it doesn't work.
What's the solution?
Thanks

Comments

dww’s picture

Component: Code » Views integration
Assigned: Unassigned » dww
Status: Active » Fixed

I think you're looking for the "Signup: Status: Open/Closed" views field. Add that to your view, and then theme it however you want.

spasmody’s picture

Status: Fixed » Active

Sorry my request was not clear. I want to add the signup status in a preprocess script (mytheme_preprocess_views_view_unformatted) in order to theme rows with something like this :

 <div class="views-row-1 views-row-odd status-enabled">

So to achieve this I tried

function garland_preprocess_views_view_unformatted(&$vars) {
  $view     = $vars['view'];
  $rows     = $vars['rows'];

  if ($view->base_table == 'node') {
    foreach ($view->result as $id => $item) {
      $node = node_load($item->nid);
      $terms = array_keys($node->signup);
           if (isset($node->signup_enabled)) {
              if ($node->signup_enabled == 1) {
                  $classes .= " signup_enabled";
                  }
              else {
                  $classes .= " signup_disabled";
                  }
        $vars['classes'][$id] .= $classes;
      }
    }
  }
}

but it doesn't work.

How can I proceed?

Thanks

dww’s picture

Category: feature » support
Status: Active » Fixed

A) You realize that's potentially very inefficient, right? You're calling node_load() on every single node returned from your view. If you do that, you might as well make your view as trivial as possible and just have a nid field, instead of doing complicated JOINs to get other fields.

B) If you're doing a full node_load(), the signup status of a node is stored in $node->signup_status.

C) It might not be hurting anything, but I don't think you want this: $terms = array_keys($node->signup);

D) You never clear $classes, you just keep appending to it.

Something like this should be closer to what you need:

function garland_preprocess_views_view_unformatted(&$vars) {
  $view     = $vars['view'];
  $rows     = $vars['rows'];

  if ($view->base_table == 'node') {
    foreach ($view->result as $id => $item) {
      $node = node_load($item->nid);
      if (empty($node->signup_status)) {
        $class = " signup_disabled";
      }
      else {
        $class = " signup_enabled";
      }
      $vars['classes'][$id] .= $class;
    }
  }
}

However, the more efficient solution would be to include the field as I explained in #1, and then look at $item->whatever_it_is to see the value of this field, use that to append to the classes, and don't actually display the field itself. Getting that right is left as an exercise for the interested reader. I strongly recommend learning how to use a debugger or setting messages with the output of var_export() to figure out what's going on. devel.module can be very helpful, too.

Good luck,
-Derek

spasmody’s picture

Status: Fixed » Active

This script makes exactly what I want, and I actually get the expected result. Unfortunately I don't have the right class, I mean I obtain

class="signup_disabled"

in ALL nodes, including nodes with enabled signup.
What's wrong?

dww’s picture

Status: Active » Postponed (maintainer needs more info)

Are you talking about "signups enabled" (as in, this was at some point a signup-enabled node) or "signups open" (as in, users can currently sign up for this node)?

spasmody’s picture

I'm talking about "signups enabled". I also tried to clear class after $node = node_load($item->nid); but it doesn't work.

spasmody’s picture

Status: Postponed (maintainer needs more info) » Active
dww’s picture

Status: Active » Fixed

That wasn't clear. If you just want to see if signups are enabled on the node at all, you want this:

if (!empty($node->signup)) {
  $class = ' signup-enabled';
}
else {
  $class = ' signup-disabled';
}
spasmody’s picture

Status: Fixed » Active

It doesn't work. I added this

$node = node_load($item->nid);
print '<pre>'. print_r($node->signup, TRUE) .'</pre>';

and for my 4 events from value 0 1 0 1 respectively, I always obtain 'signup-disabled'

I don't understand why.

dww’s picture

Assigned: dww » Unassigned

I don't either. You must have a typo or something, since it's impossible my code would do that given what you're saying. Please debug this yourself. I've given you plenty of help.

spasmody’s picture

Status: Closed (won't fix) » Fixed

I totally rebuilded my view and I finally found the origin of problem. When I specify a field by which to group the records, the preprocess script doesn't work but if I leave blank to not group, the script works fine. I think the preprocess script is incompatible with grouping field option in views. It is a bit exasperating. Can I add something at the script to solve the problem?

spasmody’s picture

Status: Active » Closed (won't fix)
spasmody’s picture

Status: Fixed » Active