summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/TRatingList.php
diff options
context:
space:
mode:
authorwei <>2006-02-19 22:25:23 +0000
committerwei <>2006-02-19 22:25:23 +0000
commit54572d1e4a5914e44bcd35fa9406ea72a8f2066f (patch)
tree3a8fc184f27cf06a3c1a768160579c6f26b3d599 /framework/Web/UI/WebControls/TRatingList.php
parentad8fced1af4eb8e6d57f8610273490aec0ac8cba (diff)
Update TRatingList and date picker.
Diffstat (limited to 'framework/Web/UI/WebControls/TRatingList.php')
-rw-r--r--framework/Web/UI/WebControls/TRatingList.php173
1 files changed, 96 insertions, 77 deletions
diff --git a/framework/Web/UI/WebControls/TRatingList.php b/framework/Web/UI/WebControls/TRatingList.php
index 006391f7..b2861f2b 100644
--- a/framework/Web/UI/WebControls/TRatingList.php
+++ b/framework/Web/UI/WebControls/TRatingList.php
@@ -12,6 +12,7 @@ Prado::using('System.Web.UI.WebControls.TRadioButtonList');
*/
class TRatingList extends TRadioButtonList
{
+ private $_ratingImages = array();
public function __construct()
{
@@ -19,12 +20,30 @@ class TRatingList extends TRadioButtonList
$this->getRepeatInfo()->setRepeatDirection('Horizontal');
}
- /**
- * @param string the direction (Vertical, Horizontal) of traversing the list
- */
- public function setRepeatDirection($value)
+ public function getAllowInput()
+ {
+ return $this->getViewState('AllowInput', true);
+ }
+
+ public function setAllowInput($value)
+ {
+ $this->setViewState('AllowInput', TPropertyValue::ensureBoolean($value), true);
+ }
+
+ public function getRating()
+ {
+ if($this->getAllowInput())
+ return $this->getSelectedIndex();
+ else
+ return $this->getViewState('Rating',0);
+ }
+
+ public function setRating($value)
{
- throw new TNotSupportedException('ratinglits_repeatdirection_unsupported');
+ if($this->getAllowInput())
+ $this->setSelectedIndex($value);
+ else
+ return $this->setViewState('Rating', TPropertyValue::ensureFloat($value),0);
}
/**
@@ -40,19 +59,13 @@ class TRatingList extends TRadioButtonList
*/
public function getRatingStyle()
{
- $style = $this->getViewState('RatingStyle', 'default');
- return is_string($style) ? $this->createRatingStyle($style) : $style;
- }
-
- protected function createRatingStyle($type)
- {
- return new TRatingListDefaultStyle;
+ return $this->getViewState('RatingStyle', 'default');
}
/**
* @return string caption text. Default is "Rate It:".
*/
- public function getCaptionText()
+ public function getCaption()
{
return $this->getViewState('Caption', 'Rate It:');
}
@@ -60,40 +73,60 @@ class TRatingList extends TRadioButtonList
/**
* @param string caption text
*/
- public function setCaptionText($value)
+ public function setCaption($value)
{
$this->setViewState('Caption', $value, 'Rate It:');
}
+
+ public function setHalfRatingLimit($value)
+ {
+ $this->setViewState('HalfRating',
+ TPropertyValue::ensureArray($value), array(0.3, 0.7));
+ }
+
+ public function getHalfRatingLimit()
+ {
+ return $this->getViewState('HalfRating', array(0.3, 0.7));
+ }
+
public function getRatingClientOptions()
{
- $options = $this->getRatingStyle()->getOptions();
+ $options['cssClass'] = 'TRatingList_'.$this->getRatingStyle();
$options['ID'] = $this->getClientID();
- $options['caption'] = $this->getCaptionText();
+ $options['caption'] = $this->getCaption();
$options['field'] = $this->getUniqueID();
- $options['total'] = $this->getItems()->getCount();
- $options['pos'] = $this->getSelectedIndex();
+ $options['selectedIndex'] = $this->getSelectedIndex();
return $options;
}
- protected function publishRatingListStyle()
+ protected function publishRatingListStyle($style)
{
$cs = $this->getPage()->getClientScript();
- $style = $this->getRatingStyle()->getStyleSheet();
- $url = $this->publishFilePath($style);
+ $stylesheet = 'System.Web.Javascripts.ratings.'.$style;
+ if(($cssFile=Prado::getPathOfNamespace($stylesheet,'.css'))===null)
+ throw new TConfigurationException('ratinglist_stylesheet_not_found',$style);
+ $url = $this->publishFilePath($cssFile);
if(!$cs->isStyleSheetFileRegistered($style))
$cs->registerStyleSheetFile($style, $url);
return $url;
}
- protected function publishRatingListAssets()
+ protected function publishRatingListImages($style, $fileExt='.gif')
{
$cs = $this->getPage()->getClientScript();
- $assets = $this->getRatingStyle()->getAssets();
- $list = array();
- foreach($assets as $file)
- $list[] = $this->publishFilePath($file);
- return $list;
+ $images['blank'] = "System.Web.Javascripts.ratings.{$style}_blank";
+ $images['hover'] = "System.Web.Javascripts.ratings.{$style}_hover";
+ $images['selected'] = "System.Web.Javascripts.ratings.{$style}_selected";
+ $images['half'] = "System.Web.Javascripts.ratings.{$style}_half";
+ $files = array();
+ foreach($images as $type => $image)
+ {
+ if(($file=Prado::getPathOfNamespace($image, $fileExt))===null)
+ throw TConfigurationException('ratinglist_image_not_found',$image);
+ $files[$type] = $this->publishFilePath($file);
+ }
+ return $files;
}
/**
@@ -102,8 +135,21 @@ class TRatingList extends TRadioButtonList
public function onPreRender($param)
{
parent::onPreRender($param);
- $this->publishRatingListStyle();
- $this->publishRatingListAssets();
+
+ $this->publishRatingListStyle($this->getRatingStyle());
+ $this->_ratingImages = $this->publishRatingListImages($this->getRatingStyle());
+
+ if($this->getAllowInput())
+ $this->registerRatingListClientScript();
+ else
+ {
+ $this->getRepeatInfo()->setCaption($this->getCaption());
+ $this->setAttribute('title', $this->getRating());
+ }
+ }
+
+ protected function registerRatingListClientScript()
+ {
$id = $this->getClientID();
$scripts = $this->getPage()->getClientScript();
$scripts->registerPradoScript('prado');
@@ -111,65 +157,38 @@ class TRatingList extends TRadioButtonList
$code = "new Prado.WebUI.TRatingList($options);";
$scripts->registerEndScript("prado:$id", $code);
}
-}
-abstract class TRatingListStyle
-{
- private $_options = array();
-
- public function __construct()
+ public function renderItem($writer,$repeatInfo,$itemType,$index)
{
- $options['pos'] = -1;
- $options['dx'] = 22;
- $options['dy'] = 30;
- $options['ix'] = 4;
- $options['iy'] = 4;
- $options['hx'] = 240;
- $options['total'] = -1;
- $this->_options = $options;
+ if($this->getAllowInput())
+ parent::renderItem($writer, $repeatInfo, $itemType, $index);
+ else
+ $this->renderRatingListItem($writer, $repeatInfo, $itemType, $index);
}
- public function getOptions()
+ protected function renderRatingListItem($writer, $repeatInfo, $itemType, $index)
{
- return $this->_options;
- }
-
- public function setOptions($options)
- {
- $this->_options = $options;
- }
-
- abstract function getStyleSheet();
-
- abstract function getAssets();
-}
-
-class TRatingListDefaultStyle extends TRatingListStyle
-{
- public function __construct()
- {
- parent::__construct();
- $options = $this->getOptions();
- $options['cssClass'] = 'TRatingList_default';
- $this->setOptions($options);
+ $image = new TImage;
+ $image->setImageUrl($this->_ratingImages[$this->getRatingImageType($index)]);
+ $image->setAlternateText($this->getRating());
+ $image->render($writer);
}
- public function getStyleSheet()
+ protected function getRatingImageType($index)
{
- $style = 'System.Web.Javascripts.ratings.default';
- if(($cssFile=Prado::getPathOfNamespace($style,'.css'))===null)
- throw new TConfigurationException('ratinglist_stylesheet_invalid',$style);
- return $cssFile;
+ $rating = floatval($this->getRating());
+ $int = intval($rating);
+ $limit = $this->getHalfRatingLimit();
+ if($index < $int || ($rating < $index + 1 && $rating > $index +$limit[1]))
+ return 'selected';
+ if($rating >= $index+$limit[0] && $rating <= $index+$limit[1])
+ return 'half';
+ return 'blank';
}
- public function getAssets()
+ public function generateItemStyle($itemType,$index)
{
- $assets = array();
- $image = 'System.Web.Javascripts.ratings.10star_white';
- if(($file=Prado::getPathOfNamespace($image, '.gif'))===null)
- throw TConfigurationException('ratinglist_asset_invalid',$image);
- $assets[] = $file;
- return $assets;
+ return new TStyle;
}
}