summaryrefslogtreecommitdiff
path: root/framework/Web/UI/ActiveControls/TActiveRatingList.php
diff options
context:
space:
mode:
authorwei <>2006-10-08 05:11:23 +0000
committerwei <>2006-10-08 05:11:23 +0000
commit9e2820e98640f4ca262db7279a514826341df3e0 (patch)
tree82184c36e9b82ae57303b7841266cbec23151c5c /framework/Web/UI/ActiveControls/TActiveRatingList.php
parentfe60cc221f922ea362826e2d00431c5df28fe85f (diff)
Fixed #414, #411, #415
Diffstat (limited to 'framework/Web/UI/ActiveControls/TActiveRatingList.php')
-rw-r--r--framework/Web/UI/ActiveControls/TActiveRatingList.php62
1 files changed, 54 insertions, 8 deletions
diff --git a/framework/Web/UI/ActiveControls/TActiveRatingList.php b/framework/Web/UI/ActiveControls/TActiveRatingList.php
index ec8eee46..c8ed524f 100644
--- a/framework/Web/UI/ActiveControls/TActiveRatingList.php
+++ b/framework/Web/UI/ActiveControls/TActiveRatingList.php
@@ -66,19 +66,38 @@ class TActiveRatingList extends TActiveRadioButtonList
}
/**
- * @return float rating value for read-only display.
+ * @return float rating value.
*/
public function getRating()
{
- return $this->getViewState('Rating',0);
+ return $this->getViewState('Rating',0.0);
}
/**
- * @param float rating value for read-only display.
+ * @param float rating value, also sets the selected Index
*/
public function setRating($value)
{
- $this->setViewState('Rating', TPropertyValue::ensureFloat($value),0);
+ $rating = TPropertyValue::ensureFloat($value);
+ $this->setViewState('Rating', $rating);
+ $canUpdate = $this->getActiveControl()->getEnableUpdate();
+ $this->getActiveControl()->setEnableUpdate(false);
+ parent::setSelectedIndex($this->getRatingIndex($rating));
+ $this->getActiveControl()->setEnableUpdate($canUpdate);
+ if($this->getActiveControl()->canUpdateClientSide())
+ $this->callClientFunction('setRating',$rating);
+ }
+
+ /**
+ * @param float rating value
+ * @return int rating as integer
+ */
+ protected function getRatingIndex($rating)
+ {
+ $interval = $this->getHalfRatingInterval();
+ $base = intval($rating)-1;
+ $remainder = $rating-$base-1;
+ return $remainder > $interval[1] ? $base+1 : $base;
}
/**
@@ -86,12 +105,13 @@ class TActiveRatingList extends TActiveRadioButtonList
*/
public function setSelectedIndex($value)
{
+ $value = TPropertyValue::ensureInteger($value);
$canUpdate = $this->getActiveControl()->getEnableUpdate();
$this->getActiveControl()->setEnableUpdate(false);
parent::setSelectedIndex($value);
$this->getActiveControl()->setEnableUpdate($canUpdate);
if($this->getActiveControl()->canUpdateClientSide())
- $this->callClientFunction('setRating',$value);
+ $this->callClientFunction('setRating',$value+1);
}
/**
@@ -122,11 +142,35 @@ class TActiveRatingList extends TActiveRadioButtonList
$this->setViewState('CaptionID', $value, '');
}
+ protected function getCaptionControl()
+ {
+ if(($id=$this->getCaptionID())!=='')
+ {
+ if($control=$this->getParent()->findControl($id))
+ return $control;
+ }
+ throw new TInvalidDataValueException(
+ 'ratinglist_invalid_caption_id',$id,$this->getID());
+ }
+
+ public function setCaption($value)
+ {
+ $this->getCaptionControl()->setText($value);
+ if($this->getActiveControl()->canUpdateClientSide())
+ $this->callClientFunction('setCaption',$value);
+ }
+
+ public function getCaption()
+ {
+ return $this->getCaptionControl()->getText();
+ }
+
/**
* @param boolean true to enable the rating to be changed.
*/
public function setEnabled($value)
{
+ $value = TPropertyValue::ensureBoolean($value);
parent::setEnabled($value);
if($this->getActiveControl()->canUpdateClientSide())
$this->callClientFunction('setEnabled',$value);
@@ -182,8 +226,10 @@ class TActiveRatingList extends TActiveRadioButtonList
{
$options = parent::getPostBackOptions();
$options['Style'] = $this->getRatingStyleCssClass();
- $options['CaptionID'] = $this->getCaptionControl();
+ $options['CaptionID'] = $this->getCaptionControlID();
$options['SelectedIndex'] = $this->getSelectedIndex();
+ $options['Rating'] = $this->getRating();
+ $options['HalfRating'] = $this->getHalfRatingInterval();
return $options;
}
@@ -200,7 +246,7 @@ class TActiveRatingList extends TActiveRadioButtonList
/**
* @return string find the client ID of the caption control.
*/
- protected function getCaptionControl()
+ protected function getCaptionControlID()
{
if(($id=$this->getCaptionID())!=='')
{
@@ -326,4 +372,4 @@ class TActiveRatingList extends TActiveRadioButtonList
}
}
-?> \ No newline at end of file
+?>