New Package - Pod Ratings
I want to personally thank community member @tokyograph for releasing his package "Pod Ratings". For all of you who are interested in releasing packages for Pods, consider taking a look at how this package works. Though the files should eventually be separated (JS / CSS) once we have support for a Package w/ Files release system, this is an amazing example of an easy to use Package with clearly written information on how to set it up and what it does.
GREAT JOB!
Everyone go check it out: http://podscms.org/packages/pod-ratings/
10 Answers
Agreed, great work Miguel.
Anyone had any trouble running the ratings package? I've installed it successfully on several sites, but am having trouble on a Wordpress 3.0 install. I've tried the default and classic themes with no luck, so I'm suspecting it may have something to do with jquery 1.4 and the wordpress admin.
http://174.132.114.188/~freeman/edu/books/the-fatal-conceit-the-errors-of-socialism
If you go to the page above you'll see that the mouse-over stars work, but the votes do not register.
Cheers,
Mike
I just reverted to 2.9.2 and it still is not working. Which means it's likely something on my end.
@mpvanwinkle - Go into your "rating/vote" Pod Page. In the Precode area, replace all instances of
<pre>__podsdb__</pre>
with
<pre>wp_</pre>
Let me know if it works for you.
Still not working
@tokyograph Are you planning on releasing a version of pod ratings for wordpress 3?
I have fixed the table prefix issue, but am getting this error:
<pre>Warning: Invalid argument supplied for foreach() in html/wp-content/plugins/pods/classes/PodAPI.php on line 505</pre>
Is this a WP 3.0 issue?
I just tried this with Matt's suggestion of changing the table prefixes... I am using
WP 3.01
Pods 1.9.3.1
Pods Ratings 1.1.0
All seems well...
This is what I ended up revising to make this work for my project:
$require_mflm_user = false;
$allow_vote_change = true;
$vote_min = 1;
$vote_max = 5;
global $current_user;
get_currentuserinfo();
if ($require_mflm_user && $current_user->id == 0) {
die("Error: You are not logged in.");
}
$pod_type = pods_url_variable('pod', 'post');
$tbl_row_id = (int) pods_url_variable('id', 'post');
$field_name = pods_url_variable('field', 'post');
$vote = (int) pods_url_variable('vote', 'post');
if ($vote < $vote_min || $vote > $vote_max) {
die('Error: Your rating was invalid.');
}
// verify that the pod exists
$sql = "SELECT id FROM @wp_pod_types WHERE name = '$pod_type'";
$pod_exists = pod_query($sql);
if (mysql_num_rows($pod_exists) == 0) {
die('Error: Invalid item.');
}
$pod = new Pod($pod_type, $tbl_row_id);
if (empty($pod->id)) {
die('Error: That item does not exist.');
}
$datatype = $pod->datatype_id;
// verify that this field is a PICK pod_rating and belongs to this pod
$sql = "SELECT id, coltype, pickval FROM @wp_pod_fields WHERE datatype = $datatype AND name = '$field_name' LIMIT 1";
$field_exists = pod_query($sql);
if (mysql_num_rows($field_exists) == 0) {
die('Error: Invalid field.');
}
$field_data = mysql_fetch_assoc($field_exists);
if ($field_data['coltype'] != 'pick' || $field_data['pickval'] != 'pod_rating') {
die('Error: Invalid field.');
}
$api = new PodAPI();
// if this pod does not have a pod_rating associated with it, create one
echo $field_name;
echo $rating_exists = $pod->get_field($field_name);
if (!$rating_exists) {
// create a new pod_rating
$rating_name = 'rating-pod-' . $pod->get_pod_id() . '-field-' . $field_data['id'];
$params = array(
'datatype' => 'pod_rating',
'columns' => array('name'=>$rating_name, 'count' => 0, 'sum' => 0, 'average' => 0)
);
$api->save_pod_item($params);
// get the pod_rating id and attach it to the pod
$sql = "SELECT id FROM @wp_pod_tbl_pod_rating WHERE name = '$rating_name' LIMIT 1";
$rating_query = pod_query($sql);
if (mysql_num_rows($rating_query) == 0) {
die('Error 72: The rating could not be saved. //Rating query.');
}
$rating_exists = mysql_fetch_assoc($rating_query);
$rating_id = $rating_exists['id'];
$sql = "INSERT INTO @wp_pod_rel SET
pod_id = '" . $pod->get_pod_id() . "',
sister_pod_id = 0,
field_id = '" . $field_data['id'] . "',
tbl_row_id = '" . $rating_id . "',
weight = 0
";
pod_query($sql);
} else {
$rating_id = $rating_exists[0]['id'];
}
// find user's current vote
$voted = new Pod('pod_rating_vote');
$where = "pod_rating.id = $rating_id AND ip = '{$_SERVER['REMOTE_ADDR']}'";
$voted->findRecords('vote_time DESC', 1, $where);
if ($voted->getTotalRows() > 0) {
if (!$allow_vote_change) {
die("Error: You have already rated this.");
}
$voted->fetchRecord();
$current_vote = $voted->get_field('vote');
$calc = "sum = sum + " . ($vote - $current_vote);
}
else {
$calc = "count = count + 1, sum = sum + $vote";
}
$calc .= ", average = sum / count";
//$calc = "count = count + 1, sum = sum + $vote, average = sum / count";
$params2 = array(
'datatype' => 'pod_rating_vote',
'columns' => array(
'name' => 'vote-' . time(),
'pod_rating' => $rating_id,
'vote' => $vote,
'vote_time' => current_time('mysql'),
'user' => $current_user->id,
'ip' => $_SERVER['REMOTE_ADDR']
)
);
$params2 = pods_sanitize($params2);
print_r($params2);
$api->save_pod_item($params2);
pod_query("UPDATE @wp_pod_tbl_pod_rating SET $calc WHERE id = $rating_id");
die('Thank you for your rating!');
Hello Sir Thom
thanks for the mod! works perfectly!
Thank you guys
edited Jan 8 '11 at 3:12


