I'm looking for a way to build a simple gallery node type in Drupal, with vote (with Votingapi and Fivestar)per image enabled. (1 vote per image, per node, per user, and users are able to vote on any image in the node). As simple as it looks, I'm unable to build a simple proof of concept of what I'm trying to achieve.
Here's a mockup of how I see the thing, and here's how I see the thing in Drupal. A content type 'Gallery' these following fields:
- Title
- Body
- Field Collection (multiple):
- Image (single)
- Fivestar rating
I succeeded to do it and now, to compute the results, I would like to get the results per node. However, if you look into the votingapi_vote table, the only data for a vote are:
MariaDB [voting]> SELECT * FROM votingapi_vote;
+---------+-----------------------+-----------+-------+------------+------+-----+------------+-------------+
| vote_id | entity_type | entity_id | value | value_type | tag | uid | timestamp | vote_source |
+---------+-----------------------+-----------+-------+------------+------+-----+------------+-------------+
| 10 | field_collection_item | 2 | 80 | percent | vote | 1 | 1455270089 | 127.0.0.1 |
| 13 | field_collection_item | 3 | 60 | percent | vote | 1 | 1455271926 | 127.0.0.1 |
| 15 | field_collection_item | 1 | 80 | percent | vote | 1 | 1455272041 | 127.0.0.1 |
+---------+-----------------------+-----------+-------+------------+------+-----+------------+-------------+
It is impossible to retrieve data from the parent node because it simple doesn't exists in the DB.
It looks like we could change tags dynamically, so I hooked into fivestar to generate dynamic tags, but it gets blocked in _fivestar_cast_vote(), especially in fivestar_validate_target(), and I'm unable to generate tags dynamically.
I also tried to hook into Votingapi using hook_votingapi_preset_votes_alter() but if you're using Fivestar with the AJAX widget, it's impossible to get information on the current node using menu_get_object(). So I'm still stuck.
Now I'm trying to look for another solution, if you have ideas, please let me know.