Search

Hi, I have an option in my site, users can vote each video and a option to see the most voted videos. For these i have given a button to vote that video. How is it possible?

No one will be willing to help you without examples of your code.

A single obscure sentence will get you nowhere.

Once again, you need to provide us with more context if we are to give you a genuinely useful answer. Help us to help you.

users can vote each video

How are you defining "users"? Website visitors, or registered, signed-in users through the Members extension? If the latter, then the Member Claims extension is exactly what you need. It will let a member stake a "claim" for an entry, in this instance a "vote" (claim) on a "video" (entry). Member Claims lets you sort by most-claimed (voted).

If you are not using Members and anybody can vote, then it is more complex. First define your constraints:

  • what is a user? how do you detect a unique user?
  • how often can a user vote, once or many times?

Then approach this as you would build it in a normal PHP/MySQL way — you're a developer — you'll have some idea of how to approach this if you weren't using Symphony. So apply the same concepts:

  • you need a way to identify a unique user: cookie, session, IP?
  • you need to store a "vote", so create a Votes section that links together a video entry and a user identifier
  • you need a way to insert an entry into this section, so use an event
  • you need a way to check whether a user has already voted for a video, so use a data source
  • you need to be able to sort videos by number of votes, so either sort these in XSLT by combining the result of data sources (videos and votes), or store a cache of the number of votes against a video as a number (use the Number field extension for numeric sorting)

Sorry for all, i had seen this now. @nickdunn, my users are Website visitors, the can be identify by using the ip address, let me try with this information given by you.

Thanks

@nickdunn

you need to be able to sort videos by number of votes, so either sort these in XSLT by combining the result of data sources (videos and votes), or store a cache of the number of votes against a video as a number (use the Number field extension for numeric sorting)

I cant understand above sentence what you mean it.

Say you have these sections:

  • Videos: Title (input), Video (file upload), Date Added (date)
  • Votes: User ID (input, stores IP address), Video (Select Box Link pointing to video title), Date (date)

This is all you need for voting. To add a vote, add an entry (using an event) into Votes with the user's IP, ID of the video entry, and the current date. To check if the user has already voted, use a data source to filter Votes by the user's IP and the video ID.

The problem is, the above structure won't let you easily sort videos by the number of votes. If you created a data source of Videos, and ticked the "Show count of related entries" in the data source editor, this will add the number of votes as an attribute to the entry element:

<entry id="123" votes="456">...</entry>

You can sort these in XSLT:

<xsl:sort select="@votes" ... />

But it means you have to select all of your videos in the data source. This is fine for up to a few hundred (max), but if you have thousands then you need a better method. That better method would be to add a Number field to the Videos section, and increment its value every time a vote is cast (or use the Increment Number field in a creative way). This would require a little custom code.

@nickdunn, thanks for your information

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