Search

I am trying to build a charts voting system (for most popular wedding songs) where users can vote a track up or down.

There is no use login so I am defining a user as a vistor identified by a cookie.

There are multiple charts in the system (i.e. best first dance, best rock song, etc) and users can vote on more than one chart and of course a track can appear on more than one chart.

These are the sections I have defined so far:

Charts - Name

Chart Track - Artist - Track - Chart (selectbox link to name in charts section) - Thumbsup (number field) - Thumbsdown (number field) - Total (number field)

Votes - Chart (select box link to name in charts section) - Artist (select box link to artist in chart track section) - Track (select box link to track in chart track section) - User Cookie

I have a datasource that returns the chart tracks filtered by the chart and ordered by the total field. The total field is equal to thumbsup - thumbsdown

I have a custom event that increments either the thumbsup or thumbsdown field on the entry that is passed via $entry_id and then recalculates the total field

Where I am stumped now is how to implement the cookie system to prevent a user from voting more than once. This is what I think I need to do:

  • set a cookie when the custom event is triggered
  • if the cookie is already set then don't allow the rest of the event to run
  • trigger a second event to add the vote to the votes section

What I ideally want to be able to do is when the chart is displayed is to indicate which tracks the user has already voted for and how they have voted. I guess for that I need to store the thumbsup thumbsdown field in the votes section instead?

I can't see how to do this with a stanndard datasource.

With regard to the cookie, do I need to set a cookie for each vote or do I need a single cookie which records all the chart tracks a user has voted for?

I have read a couple of threads here and here but am stll getting this wrap round my head.

Can anyone suggest the best approach? Has anyone done something similar before?

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details