0

I'm trying to make some kind of contest site, in which users can publish random old stuff, which will be raffled later between the users that have marked that content. I crated a specific content type for this, let's call it "kiwi", with a winner field. Then created a flag for that content, so, every content created has the button saying "I want this", when you click, you are kind of "subscribed" to that content. I want to create a rule, which chooses a random user from the list of user that have flagged the content.

I've been struggling with this for a lot of time, I don't have any more ideas on how to solve this.

Thank you very much

  • 1
    You could use Views to pull in all the users who have flagged the content, limit it's display to 1 and set the sort to random. You should be able to pull the result in with Rules. – J. Reynolds Sep 24 '15 at 3:40
  • Note that views will randomize every time you refresh the page. – No Sssweat Sep 26 '15 at 0:19
1

Well I finally did it. The modules used were:

  • Rules
  • Flags
  • Views
  • Views rules (This one was the key, allows to execute a view inside a rule, even as loops.)

Two thins were done, first, a component which would be executed every hour, and second, inside that component, every hour, a winner would be chosen for every content that had a contest date matching the hour.

Creating scheduled component

  1. Create a rule set component, which receives a parameter of type date. First step
  2. Add a rule action schedule component evaluation, in this component created, and set as the value, the component you are editing, this will program this component to be executed one hour after it is executed.
  3. Save everything, and go to Settings > Rules > Components and press "execute", with the value "now".
  4. Component now is being executed every hour.

Selecting random winner

  1. Install all the modules listed above.
  2. Create a simple component that receives a user, and a node as parameters, then add the conditions you need, and finally add an action which sets the winner field inside the node as the user given.
  3. Create a view and add a "Rule" display, this will be like the first query.
  4. Lets call it "Select content programmed for now", and filter it by a given date, then add the fields that will display, "nid" is the most important.
  5. Change the section "edit field info", inside "Rules settings", setting the type of the output, choose "Node" type for the nid (this gives the reference to the node instead of a number).
  6. Create another view, called "choose random winner", make it receive a "nid" and return the list of flagged user "uid", sort it with a global random criteria, and set max results with 1.
  7. Repeat 4 for this view, but with "User" type.
  8. Go to the component which executes every hour, add a view loop action in your rule.
  9. Select the view that filters the content for the current date.
  10. Add a view loop inside that loop, with the new rule.
  11. Add an action containing the component created at the beginning with the parameters you now have available.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.