In drupal 7 i have created a fivestar field and a user reference field in the comment form, enabled in the Organic Group Content type.

This field is supposed to reference 2 entities the group and the member/user to who the comment is referenced via User reference module.

Now i was able to reference one entity type i.e. the group where the comment is posted with help of this documentation ..... http://drupal.org/node/1308114

But am still searching for a way to reference the same vote to the user.

Example: Bill, Tim and Meena are members of Group Awesome.

Bill logins visits the content page (group page) and cast a vote referencing meena in the user reference field.

Then the vote is referenced to the group awesome as well as meena.

Thank's in advance for your time.....

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ericduran’s picture

Oh, Sadly this is not currently possible at least not without writing a custom fivestar target.

The problem is that right now the votes are only targeted at a single entity (it could be a node, group, user, etc..) but only one.

Sorry, I imagine this is not the answer you're looking for. That being said you might want to look at the fivestar.api.php file for examples on how to add new voting targets. Even thought at the time of writing it was not expected that people would want to vote to multiple targets so not really sure it even allows you to do that. But you should be able to extend it or at least cast the vote manually in the hook.

Hope this is somewhat helpful.

ericduran’s picture

Oh another solution could be to set up another Fivestar field, that references the group node. And have that field populated with the same value as the fivestar field that's referencing the user. And possible try to accomplish both of the fields being the same with rules, or using hook_node_presave. You could also hide one of the fields so they don't show up twice.

This would probably be the easier route, but still would require some code.

Energyblazar’s picture

"The problem is that right now the votes are only targeted at a single entity (it could be a node, group, user, etc..) but only one. "

as u said can be targeted to one entity......How do i target the votes to the users ?

ericduran’s picture

Title: referencing fivestar field to multiple entities » Allow targeting the Author of the Parent Node from Comments.
Version: 7.x-2.0-alpha1 » 7.x-2.x-dev
Category: support » feature

Ahh, I see what you want to do. You want to Target the author of the parent node from the comments. Is this correct?

Sadly this isn't possible but it's should be pretty easy to add.

I'll whip up a quick patch.

ericduran’s picture

Title: Allow targeting the Author of the Parent Node from Comments. » referencing fivestar field to multiple entities
Status: Active » Needs review
FileSize
825 bytes

Here's a patch that should add this functionality.

It also seems we're missing User referencing from a user_reference field.

If you don't mind testing this out. This will give you another option on the comment fivestar field, to let you reference the Parent Node : Author.

Let me know. Hope this helps.

Energyblazar’s picture

Energyblazar’s picture

Amazing u already created a patch !!!

Just one more thing i am using the fivestar module on a live site and being beginner r i am clueless how do i use this patch on a live site. I did google for possible solutions but all i could get was tutorials using drush to update a patch, but none on live site.

So i tried to manually

Here is what i did (code starting from line 741)

// Add comment module support.
  if ($instance['entity_type'] == 'comment') {
    $options['parent_node'] = array(
      'title' => t('Parent Node'),
      'callback' => '_fivestar_target_comment_parent_node'
    );
  }

  return $options;
}

 function fivestar_fivestar_target_info($field, $instance) {
       'title' => t('Parent Node'),
       'callback' => '_fivestar_target_comment_parent_node'
     );
    $options['parent_node_author'] = array(
      'title' => t('Parent Node: Author'),
      'callback' => '_fivestar_target_comment_parent_node_author'
    );
   }
  $node_reference = $instance['settings']['target'];
  if (isset($entity->{$node_reference}[$langcode][0]) && is_numeric($entity->{$node_reference}[$langcode][0]['nid'])) {
    $target['entity_id'] = $entity->{$node_reference}[$langcode][0]['nid'];
    $target['entity_type'] = 'node';
  }

  return $target;
}

function _fivestar_target_comment_parent_node($entity, $field, $instance, $langcode) {
  return array(
    'entity_id' => $entity->nid,
    'entity_type' => 'node',
  );
}

function _fivestar_target_comment_parent_node($entity, $field, $instance, $langc
     'entity_type' => 'node',
   );
 }

function _fivestar_target_comment_parent_node_author($entity, $field, $instance, $langcode) {
  return array(
    'entity_id' => $entity->uid,
    'entity_type' => 'user',
  );
}
Energyblazar’s picture

NO use getting this message after doing the above mentioned changes :- Parse error: syntax error, unexpected T_DOUBLE_ARROW in /home/nithin/public_html/drupaltest/sites/all/modules/fivestar/fivestar.module on line 753.

How do i use this patch on a live site .....???

and also in this code (i also suck @ coding so plz educate me)

function _fivestar_target_comment_parent_node($entity, $field, $instance, $langc //why is this empty?.
     'entity_type' => 'node',
   );
 } //where is the start?.
+
+function _fivestar_target_comment_parent_node_author($entity, $field, $instance, $langcode) {
+  return array(
+    'entity_id' => $entity->uid,
+    'entity_type' => 'user',
+  );
+}
Energyblazar’s picture

Also i have attached 2 screenshots ..... please have a look at them ......

I simply want to reference the vote to the user/member selected in the user reference field 9created using reference module) not the author of the content type (group)...

Thanks again for all your time and efforts.... :)

Energyblazar’s picture

Finally figured out how to apply the code manually here it is and its working right.

  // Add comment module support.
  if ($instance['entity_type'] == 'comment') {
    $options['parent_node'] = array(
      'title' => t('Parent Node'),
      'callback' => '_fivestar_target_comment_parent_node'
    );
    $options['parent_node_author'] = array(
      'title' => t('Parent Node: Author'),
      'callback' => '_fivestar_target_comment_parent_node_author'
    );
  }

  return $options;
}

/**
 *
 * @return (array) array('entity_type', 'entity_id')
 */
function _fivestar_target_node_reference($entity, $field, $instance, $langcode) {
  $target = array();

  $node_reference = $instance['settings']['target'];
  if (isset($entity->{$node_reference}[$langcode][0]) && is_numeric($entity->{$node_reference}[$langcode][0]['nid'])) {
    $target['entity_id'] = $entity->{$node_reference}[$langcode][0]['nid'];
    $target['entity_type'] = 'node';
  }

  return $target;
}

function _fivestar_target_comment_parent_node($entity, $field, $instance, $langcode) {
  return array(
    'entity_id' => $entity->nid,
    'entity_type' => 'node',
  );
}

function _fivestar_target_comment_parent_node_author($entity, $field, $instance, $langcode) {
  return array(
    'entity_id' => $entity->uid,
    'entity_type' => 'user',
  );
} 
Energyblazar’s picture

ok now there is one problem if user "Master" votes in another group his existing vote is over written. Thus if user "Master" is part of 2 groups "Group awesome" & "Group Superb", and he caste's vote in Group awesome & then comes and caste's vote in Group superb then his first vote is over written.

Energyblazar’s picture

hey @ ericduran your patch works perfect,(understood it by reading http://drupal.org/node/1274426#comment-4975152 ) but it links the vote to the voter i.e. comment author itself. Going to try out this patch http://drupal.org/node/1488914 named "fivestar-support_entityreference_1488914-6.patch"