You are here

function i18npoll_nodeapi in Internationalization 6

Implementation of hook_nodeapi().

Replaces poll results with aggregated translations.

We don't add all language results on loading to avoid the data being trashed when editing and saving nodes again.

File

i18npoll/i18npoll.module, line 36
Multilingual poll - Aggregates poll results for all translations.

Code

function i18npoll_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  global $user;
  if ($node->type == 'poll' && !empty($node->tnid)) {

    // Replace results for node view
    if ($op == 'view' && (empty($node->allowvotes) || !empty($node->show_results))) {
      $node->content['body'] = array(
        '#value' => i18npoll_view_results($node, $teaser, $page, FALSE),
      );
    }

    // Check again whether or not this user is allowed to vote.
    // User may have voted for any of the translations
    if ($op == 'load' && $node->allowvotes) {
      $result = i18npoll_get_vote($node->tnid);
      if (isset($result->chorder)) {
        $node->vote = $result->chorder;
        $node->allowvotes = FALSE;
      }
    }
  }
}