3 * TActiveRepeater class file
5 * @author LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
6 * @package System.Web.UI.ActiveControls
11 * TActiveRepeater class
13 * TActiveRepeater represents a data bound and updatable grid control which is the
14 * active counterpart to the original {@link TRepeater} control.
16 * This component can be used in the same way as the regular datagrid, the only
17 * difference is that the active repeater uses callbacks instead of postbacks
20 * Please refer to the original documentation of the regular counterparts for usage.
22 * @author LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
23 * @package System.Web.UI.ActiveControls
26 class TActiveRepeater extends TRepeater implements IActiveControl, ISurroundable {
29 * @var string the tag used to render the surrounding container
31 protected $_surroundingTag='div';
34 * Creates a new callback control, sets the adapter to
35 * TActiveControlAdapter.
37 public function __construct() {
38 parent::__construct();
39 $this->setAdapter(new TActiveControlAdapter($this));
43 * @return TBaseActiveControl standard active control options.
45 public function getActiveControl() {
46 return $this->getAdapter()->getBaseActiveControl();
50 * Sets the data source object associated with the repeater control.
51 * In addition, the render method of all connected pagers is called so they
52 * get updated when the data source is changed. Also the repeater registers
53 * itself for rendering in order to get it's content replaced on client side.
54 * @param Traversable|array|string data source object
56 public function setDataSource($value) {
57 parent::setDataSource($value);
58 if($this->getActiveControl()->canUpdateClientSide()) {
60 $this->getPage()->getAdapter()->registerControlToRender($this,$this->getResponse()->createHtmlWriter());
65 * Gets the tag used to render the surrounding container. Defaults to 'div'.
66 * @return string container tag
68 public function getSurroundingTag() {
69 return $this->_surroundingTag;
73 * Sets the tag used to render the surrounding container.
74 * @param string $value container tag
76 public function setSurroundingTag($value) {
77 $this->_surroundingTag=TPropertyValue::ensureString($value);
81 * Returns the id of the surrounding container.
82 * @return string container id
84 public function getSurroundingTagID() {
85 return $this->getClientID().'_Container';
89 * Renders the repeater.
90 * If the repeater did not pass the prerender phase yet, it will register itself for rendering later.
91 * Else it will call the {@link renderRepeater()} method which will do the rendering of the repeater.
92 * @param THtmlWriter writer for the rendering purpose
94 public function render($writer) {
95 if($this->getHasPreRendered()) {
96 $this->renderRepeater($writer);
97 if($this->getActiveControl()->canUpdateClientSide()) $this->getPage()->getCallbackClient()->replaceContent($this->getSurroundingTagId(),$writer);
100 $this->getPage()->getAdapter()->registerControlToRender($this,$writer);
105 * Loops through all {@link TActivePager} on the page and registers the ones which are set to paginate
106 * the repeater for rendering. This is to ensure that the connected pagers are also rendered if the
107 * data source changed.
109 private function renderPager() {
110 $pager=$this->getPage()->findControlsByType('TActivePager', false);
111 foreach($pager as $item) {
112 if($item->ControlToPaginate==$this->ID) {
113 $writer=$this->getResponse()->createHtmlWriter();
114 $this->getPage()->getAdapter()->registerControlToRender($item,$writer);
120 * Renders the repeater by writing a {@link getSurroundingTag()} with the container id obtained
121 * from {@link getSurroundingTagID()} which will be called by the replacement method of the client
122 * script to update it's content.
123 * @param THtmlWriter writer for the rendering purpose
125 private function renderRepeater($writer) {
126 $writer->addAttribute('id',$this->getSurroundingTagID());
127 $writer->renderBeginTag($this->getSurroundingTag());
128 parent::render($writer);
129 $writer->renderEndTag();