Yii Framework Forum: CStarRating Buggy - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CStarRating Buggy Rate Topic: ***** 1 Votes

#1 User is offline   dckurushin 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 392
  • Joined: 16-March 11
  • Location:Israel

Posted 17 October 2011 - 02:58 PM

'minRating' => 1,
		'maxRating' => 5,
		'value' => 0,
		'ratingStepSize' => 0.5,
		'starCount' => 4,

produce 4.5 stars

'minRating' => 1,
		'maxRating' => 5,
		'value' => 0,
		'ratingStepSize' => 0.5,
		'starCount' => 5,

produce 9 stars

'minRating' => 1,
		'maxRating' => 5,
		'value' => 0,
		'ratingStepSize' => 0.5,
		'starCount' => 2,

2.25

:o

class CStarRating extends CInputWidget
{
	/**
	 * @var integer the number of stars. Defaults to 5.
	 */
	public $starCount=5;

:D
0

#2 User is offline   dckurushin 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 392
  • Joined: 16-March 11
  • Location:Israel

Posted 17 October 2011 - 03:13 PM

this is the source of the problem

protected function renderStars($id,$name)
	{
		$inputCount=(int)(($this->maxRating-$this->minRating)/$this->ratingStepSize+1);
		$starSplit=(int)($inputCount/$this->starCount);
		if($this->hasModel())
		{
			$attr=$this->attribute;
			CHtml::resolveName($this->model,$attr);
			$selection=$this->model->$attr;
		}
		else
			$selection=$this->value;
		$options=$starSplit>1 ? array('class'=>"{split:{$starSplit}}") : array();
		for($value=$this->minRating, $i=0;$i<$inputCount; ++$i, $value+=$this->ratingStepSize)
		{
			$options['id']=$id.'_'.$i;
			$options['value']=$value;
			if(isset($this->titles[$value]))
				$options['title']=$this->titles[$value];
			else
				unset($options['title']);
			echo CHtml::radioButton($name,!strcmp($value,$selection),$options) . "\n";
		}
	}


I think the (int) casting does something bad to the rating... trying to figure it what exactly...

It seems like it ment to work only with integers...
But half rating is normal actually... :o
0

#3 User is offline   dckurushin 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 392
  • Joined: 16-March 11
  • Location:Israel

Posted 17 October 2011 - 03:33 PM

To make it show 5 stars with step 0.5 you should set

'minRating' => 0.5,
		'maxRating' => 5,
		'ratingStepSize' => 0.5,
		'starCount' => 5,


But in spite of that, starCount just not work as it should


Another issue I noticed

'minRating' => 0.5,
		'maxRating' => 5,
		'value' => 0.75,
		'ratingStepSize' => 0.5,
		'starCount' => 5,


will show nothing...

So to make it show something you should round to closest half... or ceil floor...
0

#4 User is offline   dckurushin 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 392
  • Joined: 16-March 11
  • Location:Israel

Posted 18 October 2011 - 03:45 PM

this issue also annoying bug

http://www.yiiframew...ng-remove-vote/

It interesting that it seems like no one give attention to the cancel button...

Need heavy hacking via try catch to manage do with it something...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users