Drupal:带有投票轴的 Fivestar 块

发布于 2024-08-18 15:18:29 字数 1991 浏览 1 评论 0原文

我正在使用带有投票轴的 Fivestar 1.19。我相信默认的五星级块/五星级功能仅使用默认的“投票”标签。

Fivestar_widget_form($node)

我需要将自定义五星标签传递给该函数。

尝试遵循以下答案: 对我来说 $object 是 $node。

  <?php 
function custom_fivestar_widget ($object) {
  global $user;

  $star_display = variable_get('fivestar_style_'. $object->type, 'average');
  $text_display = variable_get('fivestar_text_'. $object->type, 'dual');

  if ($star_display == 'average' && ($text_display == 'average' || $text_display == 'none')) {
    // Save a query and don't retrieve the user vote unnecessarily.
    $votes = fivestar_get_votes($object->type, $object->nid, 'score', 0);
  }
  else {
    $votes = fivestar_get_votes($object->type, $object->nid);
  }

  $values = array(
    'user' => isset($votes['user']['value']) ? $votes['user']['value'] : 0,
    'average' => isset($votes['average']['value']) ? $votes['average']['value'] : 0,
    'count' => isset($votes['count']['value']) ? $votes['count']['value'] : 0,
  );

  $settings = array(
    'stars' => variable_get('fivestar_stars_'. $object->type, 10),
    'allow_clear' => variable_get('fivestar_unvote_'. $object->type, FALSE),
    'style' => $star_display,
    'text' => $text_display,
    'content_type' => $object->type,
    'content_id' => $object->nid,
    'tag' => 'score',
    'autosubmit' => TRUE,
    'title' => variable_get('fivestar_title_'. $object->type, 1) ? NULL : FALSE,
    'feedback_enable' => variable_get('fivestar_feedback_'. $object->type, 1),
    'labels_enable' => variable_get('fivestar_labels_enable_'. $object->type, 1),
    'labels' => variable_get('fivestar_labels_'. $object->type, array()),
  );

  return fivestar_custom_widget($form_state, $values, $settings);
}

print drupal_get_form('custom_fivestar_widget', $object);

?>

这会打印我的小部件,我相信使用我的分数。然而,文本显示都是错误的,平均分数也是如此。它给所有东西永久的 10 颗星。 :(

I'm using fivestar 1.19 with voting axis. I believe the default fivestar block/fivestar function uses only the default 'vote' tag.

fivestar_widget_form($node)

I need to pass my custom fivestar tag to the function.

Attempting to follow the answer below:
For me $object is $node.

  <?php 
function custom_fivestar_widget ($object) {
  global $user;

  $star_display = variable_get('fivestar_style_'. $object->type, 'average');
  $text_display = variable_get('fivestar_text_'. $object->type, 'dual');

  if ($star_display == 'average' && ($text_display == 'average' || $text_display == 'none')) {
    // Save a query and don't retrieve the user vote unnecessarily.
    $votes = fivestar_get_votes($object->type, $object->nid, 'score', 0);
  }
  else {
    $votes = fivestar_get_votes($object->type, $object->nid);
  }

  $values = array(
    'user' => isset($votes['user']['value']) ? $votes['user']['value'] : 0,
    'average' => isset($votes['average']['value']) ? $votes['average']['value'] : 0,
    'count' => isset($votes['count']['value']) ? $votes['count']['value'] : 0,
  );

  $settings = array(
    'stars' => variable_get('fivestar_stars_'. $object->type, 10),
    'allow_clear' => variable_get('fivestar_unvote_'. $object->type, FALSE),
    'style' => $star_display,
    'text' => $text_display,
    'content_type' => $object->type,
    'content_id' => $object->nid,
    'tag' => 'score',
    'autosubmit' => TRUE,
    'title' => variable_get('fivestar_title_'. $object->type, 1) ? NULL : FALSE,
    'feedback_enable' => variable_get('fivestar_feedback_'. $object->type, 1),
    'labels_enable' => variable_get('fivestar_labels_enable_'. $object->type, 1),
    'labels' => variable_get('fivestar_labels_'. $object->type, array()),
  );

  return fivestar_custom_widget($form_state, $values, $settings);
}

print drupal_get_form('custom_fivestar_widget', $object);

?>

This prints me the widget, I believe using my score. However the text display is all wrong, as is the average score. And it gives everything a permanent 10 stars. :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜声 2024-08-25 15:18:29

您可以在 Fivestar.module 中重现 Fivestar_form 函数。请参阅 $settings 变量。
因此,只需复制该函数的内部,删除一些变量检查并手动设置一些变量即可。在 $settings 数组中根据需要设置为“标签”值。

You can reproduce fivestar_form function in fivestar.module. See there $settings variable.
So just copy inner of this function, remove some variables checking and set manually some variables. In $settings array set to 'tag' value as you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文