Five Stars Rating System
Author: Leandro Iriarte
Lenguage: ActionScript / Flash (Adobe Flex)
Downloads: 474
Download! ![]()
| Rate this project: |
Small component to rate any article or item. Similar to youtube. The download includes everything ready to install (the SWF file, the database schema, 2 php files that are getRating.php and addRating.php, and also the JavaScript library swfobject.js).
Instructions:
1) Embed the SWF file using swfobject (for example). It needs 3 mandatory parameters and one optional to indicate if we want to use Spanish. The code will be:
<div id="appcontent"></div> <script type="text/javascript" language="javascript">
var app = new SWFObject("../swf/Rating.swf", "Rating", 220, 20, 8, "#ffffff");
<?php
$rater_ip = getenv("REMOTE_ADDR");
echo "app.addVariable('remoteIp','$rater_ip');";
?>
app.addVariable("articleId","5");
app.addVariable("getRatingUrl","http://www.mydomain.com/getRating.php");
app.addVariable("addRatingUrl","http://www.mydomain.com/addRating.php");
app.write("appcontent");
</script>
Parameters:
- remoteIp= client ip address. The example above has the code in php
- articleId= article or item id
- getRatingUrl= url where the component will call in order to obtain the article current rating and to know if there was already a vote from the ip
- addRatingUrl= url where the component will call to register a new vote
- locale= (optional) ES for Spanish, english by default
2) Implement the controllers to communicate with SWF:
a) getRating: recieves id and ip parameters from a GET request and returns an XML like:
<rating> <avg>$avg</avg> <votes>$count</votes> <hasVote>$hasRate</hasVote> </rating>
b) addRating: recieves id, ip and rate parameters from a GET request and returns an XML like (after recording the vote):
<rating> <avg>$avg</avg> <votes>$count</votes> </rating>
Where avg is the current average, votes is the current total ratings and hasVote is 'true' or 'false' to indicate if a rate from the ip was registered before.
All the SQL queries and a COMPLETE implementation as an example in php is included in the download.
3) Finally, we only have to define where the information is stored. In the instance included with the files to download I 've used MySql database with the following schedule:
CREATE TABLE `articles` (
`ID` int(11) NOT NULL auto_increment,
`a_title` varchar(255),
`a_subtitle` tinytext,
`a_content` text,
PRIMARY KEY (`ID`)
)
CREATE TABLE `articles_ratings` (
`ID` int(11) NOT NULL auto_increment,
`article_id` int(11) NOT NULL,
`rating_value` tinyint(2) NOT NULL,
`rater_ip` varchar(20) NOT NULL,
)
And that's all ...
Please contact me for any questions.

