Versions
Look up a class, method, property or event

CStarRating

Package system.web.widgets
Inheritance class CStarRating » CInputWidget » CWidget » CBaseController » CComponent
Since 1.0
Version $Id: CStarRating.php 1516 2009-11-10 22:33:52Z qiang.xue $
CStarRating displays a star rating control that can collect user rating input.

CStarRating is based on jQuery Star Rating Plugin. It displays a list of stars indicating the rating values. Users can toggle these stars to indicate their rating input. On the server side, when the rating input is submitted, the value can be retrieved in the same way as working with a normal HTML input. For example, using
$this->widget('CStarRating',array('name'=>'rating'));
we can retrieve the rating value via $_POST['rating'].

CStarRating allows customization of its appearance. It also supports empty rating as well as read-only rating.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
actionPrefix string the prefix to the IDs of the actions. CWidget
allowEmpty boolean whether the rating value can be empty (not set). CStarRating
attribute string the attribute associated with this widget. CInputWidget
blur string Callback when the stars are not focused. CStarRating
callback string Callback when the stars are clicked. CStarRating
controller CController the controller that this widget belongs to. CWidget
cssFile mixed the CSS file used for the widget. CStarRating
focus string Callback when the stars are focused. CStarRating
htmlOptions array additional HTML options to be rendered in the input tag CInputWidget
id string id of the widget. CWidget
maxRating mixed the maximum rating allowed. CStarRating
minRating mixed the minimum rating allowed. CStarRating
model CModel the data model associated with this widget. CInputWidget
name string the input name. CInputWidget
owner CBaseController owner/creator of this widget. CWidget
ratingStepSize mixed the step size of rating. CStarRating
readOnly boolean whether the rating value is read-only or not. CStarRating
resetText string the hint text for the reset button. CStarRating
resetValue string the value taken when the rating is cleared. CStarRating
starCount integer the number of stars. CStarRating
starWidth integer the width of star image. CStarRating
titles array the titles associated with the rating options. CStarRating
value string the input value CInputWidget
viewPath string Returns the directory containing the view files for this widget. CWidget

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
clientOptions array the javascript options for the star rating CStarRating

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CWidget
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
actions() Returns a list of actions that are used by this widget. CWidget
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
beginCache() Begins fragment caching. CBaseController
beginClip() Begins recording a clip. CBaseController
beginContent() Begins the rendering of content that is to be decorated by the specified view. CBaseController
beginWidget() Creates a widget and executes it. CBaseController
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
createWidget() Creates a widget and initializes it. CBaseController
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
endCache() Ends fragment caching. CBaseController
endClip() Ends recording a clip. CBaseController
endContent() Ends the rendering of content. CBaseController
endWidget() Ends the execution of the named widget. CBaseController
getController() CWidget
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getId() CWidget
getOwner() CWidget
getViewFile() Looks for the view script file according to the view name. CWidget
getViewPath() Returns the directory containing the view files for this widget. CWidget
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
init() Initializes the widget. CWidget
raiseEvent() Raises an event. CComponent
registerClientScript() Registers the necessary javascript and css scripts. CStarRating
registerCssFile() Registers the needed CSS file. CStarRating
render() Renders a view. CWidget
renderFile() Renders a view file. CBaseController
renderInternal() Renders a view file. CBaseController
run() Executes the widget. CStarRating
setId() CWidget
widget() Creates a widget and executes it. CBaseController

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
getClientOptions() CStarRating
hasModel() CInputWidget
renderStars() Renders the stars. CStarRating
resolveNameID() CInputWidget

Property Details

allowEmpty property
public boolean $allowEmpty;

whether the rating value can be empty (not set). Defaults to true. When this is true, a reset button will be displayed in front of stars.

blur property
public string $blur;

Callback when the stars are not focused.

callback property
public string $callback;

Callback when the stars are clicked.

clientOptions property read-only
protected array getClientOptions()

the javascript options for the star rating

cssFile property
public mixed $cssFile;

the CSS file used for the widget. Defaults to null, meaning using the default CSS file included together with the widget. If false, no CSS file will be used. Otherwise, the specified CSS file will be included when using this widget.

focus property
public string $focus;

Callback when the stars are focused.

maxRating property
public mixed $maxRating;

the maximum rating allowed. This can be either an integer or a double value. Defaults to 1.

minRating property
public mixed $minRating;

the minimum rating allowed. This can be either an integer or a double value. Defaults to 1.

ratingStepSize property
public mixed $ratingStepSize;

the step size of rating. This is the minimum difference between two rating values. Defaults to 1.

readOnly property
public boolean $readOnly;

whether the rating value is read-only or not. Defaults to false. When this is true, the rating cannot be changed.

resetText property
public string $resetText;

the hint text for the reset button. Defaults to null, meaning using the system-defined text (which is 'Cancel Rating').

resetValue property
public string $resetValue;

the value taken when the rating is cleared. Defaults to null, meaning using the system-defined value (which is '').

starCount property
public integer $starCount;

the number of stars. Defaults to 5.

starWidth property
public integer $starWidth;

the width of star image. Defaults to null, meaning using the system-defined value (which is 16).

titles property
public array $titles;

the titles associated with the rating options. The keys are ratings and the values are the corresponding titles. Defaults to null, meaning using the rating value as the title.

Method Details

getClientOptions() method
protected array getClientOptions()
{return} array the javascript options for the star rating

registerClientScript() method
public void registerClientScript(string $id)
$id string the ID of the container

Registers the necessary javascript and css scripts.

registerCssFile() method (available since v1.0.2)
public static void registerCssFile(string $url=NULL)
$url string the CSS URL. If null, a default CSS URL will be used.

Registers the needed CSS file.

renderStars() method
protected void renderStars(string $id, string $name)
$id string the ID of the container
$name string the name of the input

Renders the stars.

run() method
public void run()

Executes the widget. This method registers all needed client scripts and renders the text field.

Be the first person to leave a comment

Please to leave your comment.