Subversion Repositories starrating

[/] [xajax/] [starrating.php] - Blame information for rev 1

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1 zabbie
<?php
2
include_once ('extension/starrating/classes/starrating.php');
3
 
4
function starrating( $contentobject_attribute_id, $version, $rate )
5
{
6
  $objResponse = new xajaxResponse();
7
  if (is_numeric($contentobject_attribute_id) and
8
      is_numeric($version) and
9
      is_numeric($rate) )
10
  {
11
    // Check to see if this person has voted before
12
    $votedBefore = starrating::fetchBySessionKey($contentobject_attribute_id);
13
    if (! $votedBefore)
14
    {
15
 
16
      $rating = starrating::rate($contentobject_attribute_id,$version,$rate);
17
      if ($rating)
18
      {
19
        $percent = $rating->attribute('rounded_average')/5*100;
20
        $objResponse->assign("total_$contentobject_attribute_id","innerHTML", $rating->attribute('number'));
21
        $objResponse->assign("average_$contentobject_attribute_id","innerHTML", $rating->attribute('rounded_average'));
22
        $objResponse->assign("rating_percent_$contentobject_attribute_id","style.width", $percent."%;");
23
      }
24
    }
25
    else
26
    {
27
      eZDebug::writeDebug( "User has previously voted", "starrating" );
28
    }
29
  }
30
  $objResponse->assign("has_rated_$contentobject_attribute_id","innerHTML", 'Thank you for your rating!');
31
  $objResponse->call("starrating_clear_$contentobject_attribute_id");
32
  for ($num = 1; $num <= 5; $num++)
33
  {
34
    $objResponse->remove("sr_".$contentobject_attribute_id."_".$num);
35
  }
36
  return $objResponse;
37
}
38
 
39
?>