From a9d62d90ad6b78618a8491d292d75ceced033f2b Mon Sep 17 00:00:00 2001 From: xue <> Date: Sun, 15 Jan 2006 19:46:50 +0000 Subject: Added column components of datagrid. --- framework/Web/UI/WebControls/TBoundColumn.php | 144 ++++++++++++++ framework/Web/UI/WebControls/TButtonColumn.php | 208 +++++++++++++++++++++ framework/Web/UI/WebControls/TDataGridColumn.php | 15 ++ .../Web/UI/WebControls/TEditCommandColumn.php | 182 ++++++++++++++++++ framework/Web/UI/WebControls/THyperLinkColumn.php | 203 ++++++++++++++++++++ framework/Web/UI/WebControls/TTemplateColumn.php | 185 ++++++++++++++++++ 6 files changed, 937 insertions(+) create mode 100644 framework/Web/UI/WebControls/TBoundColumn.php create mode 100644 framework/Web/UI/WebControls/TButtonColumn.php create mode 100644 framework/Web/UI/WebControls/TEditCommandColumn.php create mode 100644 framework/Web/UI/WebControls/THyperLinkColumn.php create mode 100644 framework/Web/UI/WebControls/TTemplateColumn.php (limited to 'framework') diff --git a/framework/Web/UI/WebControls/TBoundColumn.php b/framework/Web/UI/WebControls/TBoundColumn.php new file mode 100644 index 00000000..729f21fd --- /dev/null +++ b/framework/Web/UI/WebControls/TBoundColumn.php @@ -0,0 +1,144 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + */ + +/** + * TDataGridColumn class file + */ +Prado::using('System.Web.UI.WebControls.TDataGridColumn'); + +/** + * TBoundColumn class + * + * TBoundColumn represents a column that is bound to a field in a data source. + * The cells in the column will be displayed using the data indexed by + * DataField. You can customize the display by setting DataFormatString. + * + * If ReadOnly is false, TBoundColumn will display cells in edit mode + * with textboxes. Otherwise, a static text is displayed. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0 + */ +class TBoundColumn extends TDataGridColumn +{ + /** + * @return string the field name from the data source to bind to the column + */ + public function getDataField() + { + return $this->getViewState('DataField',''); + } + + /** + * @param string the field name from the data source to bind to the column + */ + public function setDataField($value) + { + $this->setViewState('DataField',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the formatting string used to control how the bound data will be displayed. + */ + public function getDataFormatString() + { + return $this->getViewState('DataFormatString',''); + } + + /** + * @param string the formatting string used to control how the bound data will be displayed. + */ + public function setDataFormatString($value) + { + $this->setViewState('DataFormatString',$value,''); + $this->onColumnChanged(); + } + + /** + * @return boolean whether the items in the column can be edited. Defaults to false. + */ + public function getReadOnly() + { + return $this->getViewState('ReadOnly',false); + } + + /** + * @param boolean whether the items in the column can be edited + */ + public function setReadOnly($value) + { + $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false); + $this->onColumnChanged(); + } + + /** + * Initializes the specified cell to its initial values. + * This method overrides the parent implementation. + * It creates a textbox for item in edit mode and the column is not read-only. + * Otherwise it displays a static text. + * The caption of the button and the static text are retrieved + * from the datasource. + * @param TTableCell the cell to be initialized. + * @param integer the index to the Columns property that the cell resides in. + * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem) + */ + public function initializeCell($cell,$columnIndex,$itemType) + { + parent::initializeCell($cell,$columnIndex,$itemType); + switch($itemType) + { + case 'EditItem': + $control=$cell; + if(!$this->getReadOnly()) + { + $textBox=Prado::createComponent('System.Web.UI.WebControls.TTextBox'); + $cell->getControls()->add($textBox); + $control=$textBox; + } + case 'Item': + case 'AlternatingItem': + case 'SelectedItem': + if(($dataField=$this->getDataField())!=='') + $control->attachEventHandler('DataBinding',array($this,'dataBindColumn')); + break; + } + } + + public function dataBindColumn($sender,$param) + { + $item=$sender->getNamingContainer(); + $data=$item->getDataItem(); + if(($field=$this->getDataField())!=='') + $value=$this->formatDataValue($this->getDataFieldValue($data,$field)); + else + $value=$this->formatDataValue($data); + if(($sender instanceof TTableCell) || ($sender instanceof TTextBox)) + $sender->setText($value); + } + + /** + * Formats the text value according to format string. + * This method is invoked when setting the text to a cell. + * This method can be overriden. + * @param mixed the data associated with the cell + * @return string the formatted result + */ + protected function formatDataValue($formatString,$value) + { + return $formatString===''?TPropertyValue::ensureString($value):sprintf($formatString,$value); + } +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TButtonColumn.php b/framework/Web/UI/WebControls/TButtonColumn.php new file mode 100644 index 00000000..34b4ba51 --- /dev/null +++ b/framework/Web/UI/WebControls/TButtonColumn.php @@ -0,0 +1,208 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + */ + +/** + * TDataGridColumn class file + */ +Prado::using('System.Web.UI.WebControls.TDataGridColumn'); + +/** + * TButtonColumn class + * + * TButtonColumn contains a user-defined command button, such as Add or Remove, + * that corresponds with each row in the column. + * + * The caption of the buttons in the column is determined by Text + * and DataTextField properties. If both are present, the latter takes + * precedence. The DataTextField refers to the name of the field in datasource + * whose value will be used as the button caption. If DataTextFormatString + * is not empty, the value will be formatted before rendering. + * + * The buttons in the column can be set to display as hyperlinks or push buttons + * by setting the ButtonType property. + * The CommandName will assign its value to all button's CommandName + * property. The datagrid will capture the command event where you can write event handlers + * based on different command names. + * + * Note, the command buttons created in the column will not cause validation. + * To enable validation, please use TTemplateColumn instead. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0 + */ +class TButtonColumn extends TDataGridColumn +{ + /** + * @return string the text caption of the button + */ + public function getText() + { + return $this->getViewState('Text',''); + } + + /** + * Sets the text caption of the button. + * @param string the text caption to be set + */ + public function setText($value) + { + $this->setViewState('Text',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the field name from the data source to bind to the button caption + */ + public function getDataTextField() + { + return $this->getViewState('DataTextField',''); + } + + /** + * @param string the field name from the data source to bind to the button caption + */ + public function setDataTextField($value) + { + $this->setViewState('DataTextField',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the formatting string used to control how the button caption will be displayed. + */ + public function getDataTextFormatString() + { + return $this->getViewState('DataTextFormatString',''); + } + + /** + * @param string the formatting string used to control how the button caption will be displayed. + */ + public function setDataTextFormatString($value) + { + $this->setViewState('DataTextFormatString',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the type of command button. Defaults to LinkButton. + */ + public function getButtonType() + { + return $this->getViewState('ButtonType','LinkButton'); + } + + /** + * @param string the type of command button, LinkButton or PushButton + */ + public function setButtonType($value) + { + $this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'LinkButton','PushButton'),'LinkButton'); + $this->onColumnChanged(); + } + + /** + * @return string the command name associated with the Command event. + */ + public function getCommandName() + { + return $this->getViewState('CommandName',''); + } + + /** + * Sets the command name associated with the Command event. + * @param string the text caption to be set + */ + public function setCommandName($value) + { + $this->setViewState('CommandName',$value,''); + $this->onColumnChanged(); + } + + /** + * @return boolean whether postback event trigger by this button will cause input validation, default is true + */ + public function getCausesValidation() + { + return $this->getViewState('CausesValidation',true); + } + + /** + * @param boolean whether postback event trigger by this button will cause input validation + */ + public function setCausesValidation($value) + { + $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true); + $this->onColumnChanged(); + } + + /** + * @return string the group of validators which the button causes validation upon postback + */ + public function getValidationGroup() + { + return $this->getViewState('ValidationGroup',''); + } + + /** + * @param string the group of validators which the button causes validation upon postback + */ + public function setValidationGroup($value) + { + $this->setViewState('ValidationGroup',$value,''); + $this->onColumnChanged(); + } + + /** + * Initializes the specified cell to its initial values. + * This method overrides the parent implementation. + * It creates a command button within the cell. + * @param TTableCell the cell to be initialized. + * @param integer the index to the Columns property that the cell resides in. + * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem) + */ + public function initializeCell($cell,$columnIndex,$itemType) + { + parent::initializeCell($cell,$columnIndex,$itemType); + if($itemType==='Item' || $itemType==='AlternatingItem' || $itemType==='SelectedItem' || $itemType==='EditItem') + { + if($this->getButtonType()==='LinkButton') + $button=Prado::createComponent('System.Web.UI.WebControls.TLinkButton'); + else + $button=Prado::createComponent('System.Web.UI.WebControls.TButton'); + $button->setText($this->getText()); + $button->setCommandName($this->getCommandName()); + $button->setCausesValidation($this->getCausesValidation()); + $button->setValidationGroup($this->getValidationGroup()); + if($this->getDataTextField()!=='') + $button->attachEventHandler('DataBinding',array($this,'dataBindColumn')); + $cell->getControls()->add($button); + } + } + + public function dataBindColumn($sender,$param) + { + if(($field=$this->getDataTextField())!=='') + { + $item=$sender->getNamingContainer(); + $data=$item->getDataItem(); + $value=$this->getDataFieldValue($data,$field); + $text=$this->formatDataValue($this->getDataTextFormatString(),$value); + if(($sender instanceof TLinkButton) || ($sender instanceof TButton)) + $sender->setText($text); + } + } +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TDataGridColumn.php b/framework/Web/UI/WebControls/TDataGridColumn.php index f78c636d..dc1d8521 100644 --- a/framework/Web/UI/WebControls/TDataGridColumn.php +++ b/framework/Web/UI/WebControls/TDataGridColumn.php @@ -226,6 +226,21 @@ abstract class TDataGridColumn extends TComponent { } + protected function getDataFieldValue($data,$field) + { + if(is_array($data)) + return $data[$field]; + else if($data instanceof TMap) + return $data->itemAt($field); + else if(($data instanceof TComponent) && $data->canGetProperty($field)) + { + $getter='get'.$field; + return $data->$getter(); + } + else + throw new TInvalidDataValueException('datagridcolumn_data_invalid'); + } + /** * Initializes the specified cell to its initial values. * The default implementation sets the content of header and footer cells. diff --git a/framework/Web/UI/WebControls/TEditCommandColumn.php b/framework/Web/UI/WebControls/TEditCommandColumn.php new file mode 100644 index 00000000..a51b703f --- /dev/null +++ b/framework/Web/UI/WebControls/TEditCommandColumn.php @@ -0,0 +1,182 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + */ + +/** + * TDataGridColumn class file + */ +Prado::using('System.Web.UI.WebControls.TDataGridColumn'); + +/** + * TEditCommandColumn class + * + * TEditCommandColumn contains the Edit command buttons for editing data items in each row. + * + * TEditCommandColumn will create an edit button if a cell is not in edit mode. + * Otherwise an update button and a cancel button will be created within the cell. + * The button captions are specified using EditText, UpdateText + * and CancelText. + * + * The buttons in the column can be set to display as hyperlinks or push buttons + * by setting the ButtonType property. + * + * When an edit button is clicked, the datagrid will generate an OnEditCommand + * event. When an update/cancel button is clicked, the datagrid will generate an + * OnUpdateCommand or an OnCancelCommand. You can write these event handlers + * to change the state of specific datagrid item. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0 + */ +class TEditCommandColumn extends TDataGridColumn +{ + /** + * @return string the type of command button. Defaults to LinkButton. + */ + public function getButtonType() + { + return $this->getViewState('ButtonType','LinkButton'); + } + + /** + * @param string the type of command button, LinkButton or PushButton + */ + public function setButtonType($value) + { + $this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'LinkButton','PushButton'),'LinkButton'); + $this->onColumnChanged(); + } + + /** + * @return string the caption of the edit button + */ + public function getEditText() + { + return $this->getViewState('EditText',''); + } + + /** + * @param string the caption of the edit button + */ + public function setEditText($value) + { + $this->setViewState('EditText',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the caption of the update button + */ + public function getUpdateText() + { + return $this->getViewState('UpdateText',''); + } + + /** + * @param string the caption of the update button + */ + public function setUpdateText($value) + { + $this->setViewState('UpdateText',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the caption of the cancel button + */ + public function getCancelText() + { + return $this->getViewState('CancelText',''); + } + + /** + * @param string the caption of the cancel button + */ + public function setCancelText($value) + { + $this->setViewState('CancelText',$value,''); + $this->onColumnChanged(); + } + + /** + * @return boolean whether postback event trigger by this button will cause input validation, default is true + */ + public function getCausesValidation() + { + return $this->getViewState('CausesValidation',true); + } + + /** + * @param boolean whether postback event trigger by this button will cause input validation + */ + public function setCausesValidation($value) + { + $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true); + $this->onColumnChanged(); + } + + /** + * @return string the group of validators which the button causes validation upon postback + */ + public function getValidationGroup() + { + return $this->getViewState('ValidationGroup',''); + } + + /** + * @param string the group of validators which the button causes validation upon postback + */ + public function setValidationGroup($value) + { + $this->setViewState('ValidationGroup',$value,''); + $this->onColumnChanged(); + } + + /** + * Initializes the specified cell to its initial values. + * This method overrides the parent implementation. + * It creates an update and a cancel button for cell in edit mode. + * Otherwise it creates an edit button. + * @param TTableCell the cell to be initialized. + * @param integer the index to the Columns property that the cell resides in. + * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem) + */ + public function initializeCell($cell,$columnIndex,$itemType) + { + parent::initializeCell($cell,$columnIndex,$itemType); + $buttonType=$this->getButtonType()=='LinkButton'?'TLinkButton':'TButton'; + if($itemType==='Item' || $itemType==='AlternatingItem' || $itemType==='SelectedItem') + $this->addButtonToCell($cell,'Edit',$this->getUpdateText(),false,''); + else if($itemType==='EditItem') + { + $this->addButtonToCell($cell,'Update',$this->getUpdateText(),$this->getCausesValidation(),$this->getValidationGroup()); + $cell->getControls()->add(' '); + $this->addButtonToCell($cell,'Cancel',$this->getUpdateText(),false,''); + } + } + + private function addButtonToCell($cell,$commandName,$text,$causesValidation,$validationGroup) + { + if($this->getButtonType()==='LinkButton') + $button=Prado::createComponent('System.Web.UI.WebControls.TLinkButton'); + else + $button=Prado::createComponent('System.Web.UI.WebControls.TButton'); + $button->setText($text); + $button->setCommandName($commandName); + $button->setCausesValidation($causesValidation); + $button->setValidationGroup($validationGroup); + $cell->getControls()->add($button); + } +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/THyperLinkColumn.php b/framework/Web/UI/WebControls/THyperLinkColumn.php new file mode 100644 index 00000000..34991845 --- /dev/null +++ b/framework/Web/UI/WebControls/THyperLinkColumn.php @@ -0,0 +1,203 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + */ + +/** + * TDataGridColumn class file + */ +Prado::using('System.Web.UI.WebControls.TDataGridColumn'); + +/** + * THyperLinkColumn class + * + * THyperLinkColumn contains a hyperlink for each item in the column. + * You can set the text and the url of the hyperlink by Text and NavigateUrl + * properties, respectively. You can also bind the text and url to specific + * data field in datasource by setting DataTextField and DataNavigateUrlField. + * Both can be formatted before rendering according to the DataTextFormatString + * and DataNavigateUrlFormatString properties, respectively. + * If both Text and DataTextField are present, the latter takes precedence. + * The same rule applies to NavigateUrl and DataNavigateUrlField properties. + * + * Namespace: System.Web.UI.WebControls + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0 + */ +class THyperLinkColumn extends TDataGridColumn +{ + /** + * @return string the text caption of the hyperlink + */ + public function getText() + { + return $this->getViewState('Text',''); + } + + /** + * Sets the text caption of the hyperlink. + * @param string the text caption to be set + */ + public function setText($value) + { + $this->setViewState('Text',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the field name from the data source to bind to the hyperlink caption + */ + public function getDataTextField() + { + return $this->getViewState('DataTextField',''); + } + + /** + * @param string the field name from the data source to bind to the hyperlink caption + */ + public function setDataTextField($value) + { + $this->setViewState('DataTextField',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the formatting string used to control how the hyperlink caption will be displayed. + */ + public function getDataTextFormatString() + { + return $this->getViewState('DataTextFormatString',''); + } + + /** + * @param string the formatting string used to control how the hyperlink caption will be displayed. + */ + public function setDataTextFormatString($value) + { + $this->setViewState('DataTextFormatString',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the URL to link to when the hyperlink is clicked. + */ + public function getNavigateUrl() + { + return $this->getViewState('NavigateUrl',''); + } + + /** + * Sets the URL to link to when the hyperlink is clicked. + * @param string the URL + */ + public function setNavigateUrl($value) + { + $this->setViewState('NavigateUrl',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the field name from the data source to bind to the navigate url of hyperlink + */ + public function getDataNavigateUrlField() + { + return $this->getViewState('DataNavigateUrlField',''); + } + + /** + * @param string the field name from the data source to bind to the navigate url of hyperlink + */ + public function setDataNavigateUrlField($value) + { + $this->setViewState('DataNavigateUrlField',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the formatting string used to control how the navigate url of hyperlink will be displayed. + */ + public function getDataNavigateUrlFormatString() + { + return $this->getViewState('DataNavigateUrlFormatString',''); + } + + /** + * @param string the formatting string used to control how the navigate url of hyperlink will be displayed. + */ + public function setDataNavigateUrlFormatString($value) + { + $this->setViewState('DataNavigateUrlFormatString',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the target window or frame to display the Web page content linked to when the hyperlink is clicked. + */ + public function getTarget() + { + return $this->getViewState('Target',''); + } + + /** + * Sets the target window or frame to display the Web page content linked to when the hyperlink is clicked. + * @param string the target window, valid values include '_blank', '_parent', '_self', '_top' and empty string. + */ + public function setTarget($value) + { + $this->setViewState('Target',$value,''); + $this->onColumnChanged(); + } + + /** + * Initializes the specified cell to its initial values. + * This method overrides the parent implementation. + * It creates a hyperlink within the cell. + * @param TTableCell the cell to be initialized. + * @param integer the index to the Columns property that the cell resides in. + * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem) + */ + public function initializeCell($cell,$columnIndex,$itemType) + { + parent::initializeCell($cell,$columnIndex,$itemType); + if($itemType==='Item' || $itemType==='AlternatingItem' || $itemType==='SelectedItem' || $itemType==='EditItem') + { + $link=Prado::createComponent('System.Web.UI.WebControls.THyperLink'); + $link->setText($this->getText()); + $link->setNavigateUrl($this->getNavigateUrl()); + $link->setTarget($this->getTarget()); + if($this->getDataTextField()!=='' || $this->getDataNavigateUrlField()!=='') + $link->attachEventHandler('DataBinding',array($this,'dataBindColumn')); + $cell->getControls()->add($link); + } + } + + public function dataBindColumn($sender,$param) + { + $item=$sender->getNamingContainer(); + $data=$item->getDataItem(); + if(($field=$this->getDataTextField())!=='') + { + $value=$this->getDataFieldValue($data,$field); + $text=$this->formatDataValue($this->getDataTextFormatString(),$value); + $sender->setText($text); + } + if(($field=$this->getDataNavigateUrlField())!=='') + { + $value=$this->getDataFieldValue($data,$field); + $url=$this->formatDataValue($this->getDataNavigateUrlFormatString(),$value); + $sender->setNavigateUrl($url); + } + } +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TTemplateColumn.php b/framework/Web/UI/WebControls/TTemplateColumn.php new file mode 100644 index 00000000..ec4f191d --- /dev/null +++ b/framework/Web/UI/WebControls/TTemplateColumn.php @@ -0,0 +1,185 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + */ + +/** + * TDataGridColumn class file + */ +Prado::using('System.Web.UI.WebControls.TDataGridColumn'); + +/** + * TTemplateColumn class + * + * TTemplateColumn customizes the layout of controls in the column with templates. + * In particular, you can specify ItemTemplate, EditItemTemplate + * HeaderTemplate and FooterTemplate to customize specific + * type of cells in the column. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0 + */ +class TTemplateColumn extends TDataGridColumn +{ + /** + * Number of seconds that a cached template will expire after + */ + const CACHE_EXPIRY=18000; + /** + * Various item templates + * @var string + */ + private $_itemTemplate=''; + private $_editItemTemplate=''; + private $_headerTemplate=''; + private $_footerTemplate=''; + private static $_templates=array(); + + /** + * @return string the edit item template string + */ + public function getEditItemTemplate() + { + return $this->_editItemTemplate; + } + + /** + * Sets the edit item template string + * @param string the edit item template + */ + public function setEditItemTemplate($value) + { + $this->_editItemTemplate=$value; + } + + /** + * @return string the template string for the item + */ + public function getItemTemplate() + { + return $this->_itemTemplate; + } + + /** + * Sets the template string for the item + * @param string the item template + */ + public function setItemTemplate($value) + { + $this->_itemTemplate=$value; + } + + /** + * @return string the header template string + */ + public function getHeaderTemplate() + { + return $this->_headerTemplate; + } + + /** + * Sets the header template. + * The template will be parsed immediately. + * @param string the header template + */ + public function setHeaderTemplate($value) + { + $this->_headerTemplate=$value; + } + + /** + * @return string the footer template string + */ + public function getFooterTemplate() + { + return $this->_footerTemplate; + } + + /** + * Sets the footer template. + * The template will be parsed immediately. + * @param string the footer template + */ + public function setFooterTemplate($value) + { + $this->_footerTemplate=$value; + } + + /** + * Initializes the specified cell to its initial values. + * This method overrides the parent implementation. + * It initializes the cell based on different templates + * (ItemTemplate, EditItemTemplate, HeaderTemplate, FooterTemplate). + * @param TTableCell the cell to be initialized. + * @param integer the index to the Columns property that the cell resides in. + * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem) + */ + public function initializeCell($cell,$columnIndex,$itemType) + { + parent::initializeCell($cell,$columnIndex,$itemType); + $tplContent=''; + switch($itemType) + { + case 'Header': + $tplContent=$this->_headerTemplate; + break; + case 'Footer': + $tplContent=$this->_footerTemplate; + break; + case 'Item': + case 'AlternatingItem': + case 'SelectedItem': + $tplContent=$this->_itemTemplate; + break; + case 'EditItem': + $tplContent=$this->_editItemTemplate===''?$this->_itemTemplate:$this->_editItemTemplate; + break; + } + if($tplContent!=='') + { + $cell->setText(''); + $cell->getControls()->clear(); + $this->createTemplate($tplContent)->instantiateIn($cell); + } + } + + /** + * Parses item template. + * This method uses caching technique to accelerate template parsing. + * @param string template string + * @return ITemplate parsed template object + */ + protected function createTemplate($str) + { + $key=md5($str); + if(isset(self::$_templates[$key])) + return self::$_templates[$key]; + else + { + $contextPath=$this->getOwner()->getTemplateControl()->getTemplate()->getContextPath(); + if(($cache=$this->getApplication()->getCache())!==null) + { + if(($template=$cache->get($key))===null) + { + $template=new TTemplate($str,$contextPath); + $cache->set($key,$template,self::CACHE_EXPIRY); + } + } + else + $template=new TTemplate($str,$contextPath); + self::$_templates[$key]=$template; + return $template; + } + } +} + +?> \ No newline at end of file -- cgit v1.2.3