[eluser]TheIgniter[/eluser]
Solution :
After some good time reading the mootools documentation, i found the solution to my problem and here the solution using the rabid rating widget (You can implement it to codeigniter easily :
This the widget :
Code:
http://msteigerwalt.com/widgets/ratings/v1.2/
First, i'm french
and here is a simple example (tuto) :
File to edit :
Code:
demo.php, ratings.php, rating.js
First we are going to add a new field to the rabid_ratings table called
user_id.
demo.php :
Put the user id in a hidden input :
Code:
<input type="hidden" id="userid" value="<?php echo $row->id ;?>" />
id="userid"
$row->id or wtv.
ratings.js:
Line 80 :
Code:
.post({vote:votePercent,id:el.ratableId});
we are going to add a new parameter to the ajax post method and select the input
id (id="userid") to grab it's value.
Code:
.post({vote:votePercent,id:el.ratableId,'someid': $('userid').value});
'someid'
If you want to check if the value is passed via ajax, add an alert to print the value :
After line 71 :
Code:
alert($('userid').value);
ratings.php :
Let's grab the value via the $_POST method in php :
Line 235 :
Code:
$r->doVote($_POST['id'], $_POST['vote']);
add :
Code:
$r->doVote($_POST['id'], $_POST['vote'],$_POST['someid']);
someid
add a new parameter to the doVote function :
Code:
function doVote($ratableId, $percent,$data)
...
$userid = $data;
...
$SQL_INSERT_VOTE = "INSERT INTO $this->ratings(ratable_id, ip_address, user_id, ".
"rating) VALUES ('$id', '$ip', '$userid' , '$rating');";
user_id
PLEASE CORRECT ME IF THERE IS SOMETHING WRONG
----------------------- That all -----------------------------------------------
Really easy
!
Hi there ,
I really need your help guys, im stuck stuck stuck!! I'm using rabidratings widget! I create a the library and everythings going smooth. Now i want to pass the user id to the doVote function to store the id of the voter :
Code:
/**
* RabidRatings::doVote
*
* This is the function in charge of handling a vote and saving it to the
* database.
*
* NOTE: This method is meant to be called as part of an AJAX request. As
* such, it unitlizes the die() function to display its errors. THIS
* WOULD BE A VERY BAD FUNCTION TO CALL FROM WITHIN ANOTHER PAGE.
*
* @param integer id - The id of key to register a rating for.
* @param integer percent - The rating in percentages.
*/
function doVote($ratableId, $percent) {
echo $this->profid ;
$ip = $_SERVER['REMOTE_ADDR'];
//Make sure that the ratable ID is a number and not something crazy.
if (is_numeric($ratableId)) {
$id = $ratableId;
} else {
die("ERROR: Id invalid.");
}
//Make sure the percent is a number and under 100.
if (is_numeric($percent) && $percent < 101) {
$rating = $percent;
} else {
die("ERROR: Rating percent invalid.");
}
//Insert the data.
$SQL_INSERT_VOTE = "INSERT INTO $this->ratings(ratable_id, ip_address, ".
"rating) VALUES ('$id', '$ip', '$rating');";
//Die with an error if the insert fails (duplicate IP for a vote).
if (!mysql_query($SQL_INSERT_VOTE)) {
die("ERROR: Duplicate votes not allowed.");
}
$rating = $this->loadRating($id);
echo $this->getStarMessage($rating);
}
I'm not really good in ajax (Im a newbie).. the dovote function is called like :
Code:
if (isset($_POST['vote']) && isset($_POST['id']))
{
$this->doVote($_POST['id'], $_POST['vote']);
}
In the js file :
Code:
window.addEvent('domready', function(e) {
var rating = new RabidRatings({url:'http://localhost/projectolearn/index.php/users/loadlib'});
HERE : I passed the user id in a var to the RabidRating class, but when the ajax call executed to store the vote, it reset the user id variable...
I get the user id from the view, samething goes to the call vote :
Code:
<?php echo $row->id; ?> //user id
<?php
$rr = new RabidRatings() ;
for ($i = 1; $i < 5; $i++) {
$rr->showStars("myArticle$i);
}
What i want is to pass the user id to the doVote function! I passed almost 5 hours to find a solution or a hack! But no way..
Please help me! sorry for my poor english
Thanks.