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 * Creates a new callback control, sets the adapter to
30 * TActiveControlAdapter.
32 public function __construct() {
33 parent::__construct();
34 $this->setAdapter(new TActiveControlAdapter($this));
38 * @return TBaseActiveControl standard active control options.
40 public function getActiveControl() {
41 return $this->getAdapter()->getBaseActiveControl();
45 * Sets the data source object associated with the repeater control.
46 * In addition, the render method of all connected pagers is called so they
47 * get updated when the data source is changed. Also the repeater registers
48 * itself for rendering in order to get it's content replaced on client side.
49 * @param Traversable|array|string data source object
51 public function setDataSource($value) {
52 parent::setDataSource($value);
53 if($this->getActiveControl()->canUpdateClientSide()) {
55 $this->getPage()->getAdapter()->registerControlToRender($this,$this->getResponse()->createHtmlWriter());
60 * Returns the id of the surrounding container (span).
61 * @return string container id
63 public function getSurroundingTagID() {
64 return $this->ClientID.'_Container';
68 * Renders the repeater.
69 * If the repeater did not pass the prerender phase yet, it will register itself for rendering later.
70 * Else it will call the {@link renderRepeater()} method which will do the rendering of the repeater.
71 * @param THtmlWriter writer for the rendering purpose
73 public function render($writer) {
74 if($this->getHasPreRendered()) {
75 $this->renderRepeater($writer);
76 if($this->getActiveControl()->canUpdateClientSide()) $this->getPage()->getCallbackClient()->replaceContent($this->getSurroundingTagId(),$writer);
79 $this->getPage()->getAdapter()->registerControlToRender($this,$writer);
84 * Loops through all {@link TActivePager} on the page and registers the ones which are set to paginate
85 * the repeater for rendering. This is to ensure that the connected pagers are also rendered if the
86 * data source changed.
88 private function renderPager() {
89 $pager=$this->getPage()->findControlsByType('TActivePager', false);
90 foreach($pager as $item) {
91 if($item->ControlToPaginate==$this->ID) {
92 $writer=$this->getResponse()->createHtmlWriter();
93 $this->getPage()->getAdapter()->registerControlToRender($item,$writer);
99 * Renders the repeater by writing a span tag with the container id obtained from {@link getSurroundingTagID()}
100 * which will be called by the replacement method of the client script to update it's content.
101 * @param THtmlWriter writer for the rendering purpose
103 private function renderRepeater($writer) {
104 $writer->addAttribute('id',$this->getSurroundingTagID());
105 $writer->renderBeginTag('span');
106 parent::render($writer);
107 $writer->renderEndTag();