I'm not sure if I didn't use the right search terms, but I couldn't find anything about this kind of task.
A little background information first:
I plan to create a cutom(izable) voting component for an actual project. The existing Polls extra is very limited and thus not working for me in this case. I need to be able to add Images, Descriptons, Audiofiles, Video and maybe even more (should also be extendable for future feature requests) for every Answer (on an optional basis...). Also the case can occur, that users first have to input Names/Email before being able to submit their vote (to make the voting as "safe" [ie. not influenceable by users] without blocking whole companies [with the same IP] from voting) .
Just startet thinking about it but basically I'm planning to handle the whole thing via FormIt and custom hooks for voting and getImageList to output the different voting options. Every voting would be a separate resource in a container, let's be creative, called "Votings". These resources would have a MIGX grid for the options. Like this I think I could be very flexible in creating different kinds of (extensible) votings and ease the managing for the editors (because they don't have to learn a custom cmp, and creating cmps is currently not really in my skillset bc of lacking extjs knowledge).
Question
I don't see any problems in creating the votings itself, as MIGX is very flexible in input/output by nature but I actually cannot think of a way to save the actual votes for the options from frontend when the voting is active (publish/unpublish through native document variables)...maybe I'm just not thinking in the right direction but how can I manipulate the JSON of a MIGX grid in an elegant way through a snippet (custom hook)?
I don't think it's possible to just set the TV value (hidden TV for MIGX grid) via
$votingresource = $modx->getObject('modResource', 123);
$newnumberofvotes = $votingresource->getTVValue('migx.voting.votes') + 1;
$votingresource->setTVValue('migx.voting.votes', $newnumberofvotes);
because that probably would not be reflected in the MIGX TV JSON itself and it needs to be individual for every option (because no saving through manager would occur, so how should the JSON be updated and from where should the grid "know" for which option a vote was given...).
This would actually be the easier part for the "simple" votings with no names/mailaddress/ip/activationmail etc.
The harder part are these safe votings where I would need to save every single vote as a custom row (probably another MIGX grid, just for the votes). So to say create complete MIGX grid rows from the frontend via snippet...
The only possible way I can think of doing this (=manipulating the content of a MIGX TV) is to parse the MIGX JSON in PHP via something like:
$votingresource = $modx->getObject('modResource', 123);
$migxjson = $modx->fromJSON($votingresource->getTVValue('migx.grid.voting.votes')); // get migx json from votes grid and parse it to array
// get data from form and create new MIGX grid row by pushing the new vote to the end of the above parsed JSON string and converting it back to JSON
$fields = array('date' => '1359744625', 'names' => 'Firstname Lastname', 'optionid' => 2, 'optiontitle' => 'Option X', 'IP' => '192.168.100.30', 'mailhash' => 'YW5pdGFoQGJsdWV3aW4uY2g=', 'active' => 0);
$newmigxjson = $modx->toJSON(array_push($migxjson, $fields));
// save it back to the db
$votingresource->setTVValue('migx.grid.voting.votes', $newmigxjson);
// does this actually save the value or just set it and it needs to be saved separately?
but I'm definitely not sure if this is the way to go or if there is a much better approach for doing this? Any suggestions?
Thanks in advance!
[ed. note: exside last edited this post 11 years, 2 months ago.]