New Package - Pod Ratings

0

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/

asked Mar 9 '10 at 6:38

sc0ttkclark

2936

add comment
enter at least 15 characters

10 Answers

0

Agreed, great work Miguel.

answered Mar 9 '10 at 6:38

logikal16

249

add comment
enter at least 15 characters
0

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

answered Apr 20 '10 at 11:18

Mike Van Winkle

219

I looked at your code, it appears that since your install is not at root, but the script is looking at the root directory, it is looking at http://174.132.114.188/rating/vote but should be looking at http://174.132.114.188/~freeman/edu/rating/vote – Thom Meredith Jul 28 '10 at 7:38
add comment
enter at least 15 characters
0

I just reverted to 2.9.2 and it still is not working. Which means it's likely something on my end.

answered Apr 20 '10 at 2:22

Mike Van Winkle

219

add comment
enter at least 15 characters
0

@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.

answered Apr 20 '10 at 3:48

logikal16

249

add comment
enter at least 15 characters
0

Still not working

answered May 25 '10 at 4:26

Mike Van Winkle

219

add comment
enter at least 15 characters
0

@tokyograph Are you planning on releasing a version of pod ratings for wordpress 3?

answered Sep 10 '10 at 9:31

Tobias Beuving

1

add comment
enter at least 15 characters
0

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?

answered Sep 15 '10 at 4:12

Thom Meredith

11

add comment
enter at least 15 characters
0

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...

answered Oct 7 '10 at 2:52

chriscarvache

73

add comment
enter at least 15 characters
0

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!');

answered Nov 7 '10 at 2:18

Thom Meredith

11

add comment
enter at least 15 characters
0

Hello Sir Thom

thanks for the mod! works perfectly!

Thank you guys

answered Jan 6 '11 at 12:39

jpx3m

1

edited Jan 8 '11 at 3:12

add comment
enter at least 15 characters